diff --git a/snmpcheck-1.8.pl b/snmpcheck-1.8.pl new file mode 100644 index 0000000..cbfa753 --- /dev/null +++ b/snmpcheck-1.8.pl @@ -0,0 +1,1078 @@ +#!/usr/bin/env perl + +# +# Copyright (c) 2005-2010 by Matteo Cantoni (www.nothink.org) +# +# Like to snmpwalk, snmpcheck permits to enumerate information via SNMP protocol. +# It allows enumeration (hardware, software, network) of any devices with SNMP protocol support. +# It could be useful for penetration testing or systems monitoring. +# +# Distributed under GPL license and based on "Athena-2k" script by jshaw. +# More informations available from http://www.nothink.org. +# +# License: (http://www.gnu.org/licenses/gpl.txt) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +use strict; + +$|=1; + +use threads; +use Getopt::Std; +use Net::SNMP qw(ticks_to_time OCTET_STRING DEBUG_ALL); +use Number::Bytes::Human qw(format_bytes); +use Time::HiRes qw(gettimeofday tv_interval); + +my $name = "snmpcheck.pl"; +my $version = "v1.8"; +my $description = "SNMP enumerator"; +my $copyright = "Copyright (c) 2005-2011"; +my $author = "Matteo Cantoni (www.nothink.org)"; + +# MIBs Involved +# +# System +my $mibDescr = "1.3.6.1.2.1.1.1.0"; # System Description +my $mibNTDomain = "1.3.6.1.4.1.77.1.4.1.0"; # NT Primary Domain +my $mibUptimeInstance = "1.3.6.1.2.1.1.3.0"; # Uptime Instance +my $mibSystemUptime = "1.3.6.1.2.1.25.1.1.0"; # System Uptime +my $mibSystemDate = "1.3.6.1.2.1.25.1.2.0"; # System Date +my $mibContact = "1.3.6.1.2.1.1.4.0"; # System Contact +my $mibName = "1.3.6.1.2.1.1.5.0"; # System Name +my $mibLocation = "1.3.6.1.2.1.1.6.0"; # System Location +my $mibServices = "1.3.6.1.4.1.77.1.2.3.1.1"; # Services (add to it) +my $mibAccounts = "1.3.6.1.4.1.77.1.2.25"; # User Accounts +my $mibMemSize = "1.3.6.1.2.1.25.2.2.0"; # Total System Memory +my $mibMotd = "1.3.6.1.4.1.42.3.1.3.0"; # Motd (Solaris) +# Devices +my $mibDevIndex = "1.3.6.1.2.1.25.3.2.1.1"; # Devices Index +my $mibDevType = "1.3.6.1.2.1.25.3.2.1.2"; # Devices Type +my $mibDevList = "1.3.6.1.2.1.25.3.2.1.3"; # Devices List +my $mibDevStatus = "1.3.6.1.2.1.25.3.2.1.5"; # Devices Status +# Processs +my $mibProcesses = "1.3.6.1.2.1.25.1.6.0"; # System Processes +my $mibRunIndex = "1.3.6.1.2.1.25.4.2.1.1"; # Running PIDs +my $mibRunName = "1.3.6.1.2.1.25.4.2.1.2"; # Running Programs +my $mibRunPath = "1.3.6.1.2.1.25.4.2.1.4"; # Processes Path +my $mibRunParameters = "1.3.6.1.2.1.25.4.2.1.5"; # Processes Parameters +my $mibRunType = "1.3.6.1.2.1.25.4.2.1.6"; # Processes Type +my $mibRunStatus = "1.3.6.1.2.1.25.4.2.1.7"; # Processes Status +my $mibProName = "1.3.6.1.4.1.42.3.12.1.1.10"; # Running Process Name (Solaris) +my $mibProPid = "1.3.6.1.4.1.42.3.12.1.1.1"; # Running Process Pid (Solaris) +my $mibProUser = "1.3.6.1.4.1.42.3.12.1.1.8"; # Running Process User (Solaris) +# Storage +my $mibStorIndex = "1.3.6.1.2.1.25.2.3.1.1"; # Storage Device Index +my $mibStorType = "1.3.6.1.2.1.25.2.3.1.2"; # Storage Device Type +my $mibStorDescr = "1.3.6.1.2.1.25.2.3.1.3"; # Storage Description +my $mibStorUnits = "1.3.6.1.2.1.25.2.3.1.4"; # Storage Units +my $mibStorSize = "1.3.6.1.2.1.25.2.3.1.5"; # Storage Total Size +my $mibStorUsed = "1.3.6.1.2.1.25.2.3.1.6"; # Storage Used +my $mibPtype = "1.3.6.1.2.1.25.3.8.1.4"; # Partition Type +# Network +my $mibInt = "1.3.6.1.2.1.2.2.1.2"; # Network Interfaces +my $mibIntMTU = "1.3.6.1.2.1.2.2.1.4"; # Net Int MTU Size +my $mibIntSpeed = "1.3.6.1.2.1.2.2.1.5"; # Net Int Speed +my $mibIntBytesIn = "1.3.6.1.2.1.2.2.1.10"; # Net Int Octets In +my $mibIntBytesOut = "1.3.6.1.2.1.2.2.1.16"; # Net Int Octects Out +my $mibIntPhys = "1.3.6.1.2.1.2.2.1.6"; # Int MAC addr +my $mibAdminStat = "1.3.6.1.2.1.2.2.1.7"; # Int up/down? +my $mibIPForward = "1.3.6.1.2.1.4.1.0"; # IP Forwarding? +my $mibIPAddr = "1.3.6.1.2.1.4.20.1.1"; # Int IP Address +my $mibNetmask = "1.3.6.1.2.1.4.20.1.3"; # Int IP Netmask +# Software +my $mibSoftIndex = "1.3.6.1.2.1.25.6.3.1.1"; # Software Index +my $mibSoftName = "1.3.6.1.2.1.25.6.3.1.2"; # Software Name +# Shares +my $mibShareName = "1.3.6.1.4.1.77.1.2.27.1.1"; # Reports Share Names +my $mibSharePath = "1.3.6.1.4.1.77.1.2.27.1.2"; # Reports Share Path +my $mibShareComm = "1.3.6.1.4.1.77.1.2.27.1.3"; # Reports Share Comments +# Routing Info +my $mibRouteDest = "1.3.6.1.2.1.4.21.1.1"; # Route Destinations +my $mibRouteMetric = "1.3.6.1.2.1.4.21.1.3"; # Route Metric +my $mibRouteNHop = "1.3.6.1.2.1.4.21.1.7"; # Route Next Hop +my $mibRouteMask = "1.3.6.1.2.1.4.21.1.11"; # Route Mask +# IP +my $mibDefaultTTL = "1.3.6.1.2.1.4.2.0"; # IP Default TTL +my $mibInReceives = "1.3.6.1.2.1.4.3.0"; # IP In Receives +my $mibInDelivers = "1.3.6.1.2.1.4.9.0"; # IP In Delivers +my $mibOutRequests = "1.3.6.1.2.1.4.10.0"; # IP Out Requests +# TCP +my $mibTCPInSegs = "1.3.6.1.2.1.6.10.0"; # TCP In Segs +my $mibTCPOutSegs = "1.3.6.1.2.1.6.11.0"; # TCP Out Segs +my $mibTCPRetransSegs = "1.3.6.1.2.1.6.12.0"; # TCP Retrans Segs +my $mibTCPState = "1.3.6.1.2.1.6.13.1.1"; # TCP Connect State +my $mibTCPLAddr = "1.3.6.1.2.1.6.13.1.2"; # TCP Local Address +my $mibTCPLPort = "1.3.6.1.2.1.6.13.1.3"; # TCP Local Port +my $mibTCPRAddr = "1.3.6.1.2.1.6.13.1.4"; # TCP Remote Address +my $mibTCPRPort = "1.3.6.1.2.1.6.13.1.5"; # TCP Remote Port +# UDP +my $mibUDPLAddr = "1.3.6.1.2.1.7.5.1.1"; # UDP Local Address +my $mibUDPLPort = "1.3.6.1.2.1.7.5.1.2"; # UDP Local Port +# IIS +my $http_totalBytesSentLowWord = "1.3.6.1.4.1.311.1.7.3.1.2.0"; # IIStotalBytesSentLowWord +my $http_totalBytesReceivedLowWord = "1.3.6.1.4.1.311.1.7.3.1.4.0"; # IIStotalBytesReceivedLowWord +my $http_totalFilesSent = "1.3.6.1.4.1.311.1.7.3.1.5.0"; # IIStotalFilesSent +my $http_currentAnonymousUsers = "1.3.6.1.4.1.311.1.7.3.1.6.0"; # IIScurrentAnonymousUsers +my $http_currentNonAnonymousUsers = "1.3.6.1.4.1.311.1.7.3.1.7.0"; # IIScurrentNonAnonymousUsers +my $http_totalAnonymousUsers = "1.3.6.1.4.1.311.1.7.3.1.8.0"; # IIStotalAnonymousUsers +my $http_totalNonAnonymousUsers = "1.3.6.1.4.1.311.1.7.3.1.9.0"; # IIStotalNonAnonymousUsers +my $http_maxAnonymousUsers = "1.3.6.1.4.1.311.1.7.3.1.10.0"; # IISmaxAnonymousUsers +my $http_maxNonAnonymousUsers = "1.3.6.1.4.1.311.1.7.3.1.11.0"; # IISmaxNonAnonymousUsers +my $http_currentConnections = "1.3.6.1.4.1.311.1.7.3.1.12.0"; # IIScurrentConnections +my $http_maxConnections = "1.3.6.1.4.1.311.1.7.3.1.13.0"; # IISmaxConnections +my $http_connectionAttempts = "1.3.6.1.4.1.311.1.7.3.1.14.0"; # IISconnectionAttempts +my $http_logonAttempts = "1.3.6.1.4.1.311.1.7.3.1.15.0"; # IISlogonAttempts +my $http_totalGets = "1.3.6.1.4.1.311.1.7.3.1.16.0"; # IIStotalGets +my $http_totalPosts = "1.3.6.1.4.1.311.1.7.3.1.17.0"; # IIStotalPosts +my $http_totalHeads = "1.3.6.1.4.1.311.1.7.3.1.18.0"; # IIStotalHeads +my $http_totalOthers = "1.3.6.1.4.1.311.1.7.3.1.19.0"; # IIStotalOthers +my $http_totalCGIRequests = "1.3.6.1.4.1.311.1.7.3.1.20.0"; # IIStotalCGIRequests +my $http_totalBGIRequests = "1.3.6.1.4.1.311.1.7.3.1.21.0"; # IIStotalBGIRequests +my $http_totalNotFoundErrors = "1.3.6.1.4.1.311.1.7.3.1.22.0"; # IIStotalNotFoundErrors + +our ($opt_t,$opt_p,$opt_c,$opt_v,$opt_r,$opt_w,$opt_d,$opt_T,$opt_D,$opt_h); +getopts("t:p:c:v:r:wdT:Dh"); + +my $community = $opt_c || "public"; +my $port = $opt_p || 161; +my $snmpver = $opt_v || 1; +my $retries = $opt_r || 0; +my $timeout = $opt_T || 20; + +my $usage = "$name $version - $description\n$copyright by $author\n + Usage ./$name -t \n +\t-t : target host; + +\t-p : SNMP port; default port is $port; +\t-c : SNMP community; default is $community; +\t-v : SNMP version (1,2); default is $snmpver; +\t-r : request retries; default is $retries; + +\t-w : detect write access (separate action by enumeration); + +\t-d : disable 'TCP connections' enumeration! +\t-T : force timeout in seconds; default is $timeout. Max is 60; +\t-D : enable debug; +\t-h : show help menu;\n\n"; + +die $usage if $opt_h; +die $usage unless $opt_t; + +my ($target,$session,$error,$debug,$thr); + +if ($opt_t !~ /^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$/){ + die " [*] Error: target is not a valid IP address!\n"; +} else { + $target = $opt_t; +} + +if (($opt_T) and ($opt_T !~ /^(\d+)$/) or ($timeout < 0 or $timeout > 60)){ + die " [*] Error: max timeout value is 60 seconds!\n"; +} + +if ($opt_v and $opt_v !~ /1|2/){ + die " [*] Error: currently only SNMPv1 and SNMPv2c permitted!\n"; +} + +if ($opt_D){ + $debug = "0x02"; +} else{ + $debug = "0"; +} + +if (!$opt_T){ + $thr = threads->new(\&WaitProcess,30); + $thr->detach(); +} + +$SIG{INT} = sub { + if ($session){ + print " [*] Closing connection...\n"; + $session->close; + } + + $thr->kill('SIGUSR1'); + threads->exit(); + + exit(1); +}; + +print "$name $version - $description\n$copyright by $author\n\n"; + +print " [*] Try to connect to $target\n"; + +local $SIG{ALRM} = sub { + if ($session){ + print " [*] Timeout while connecting to host $target\n\n"; + $session->close; + } + exit(0); +}; + +alarm $timeout if $opt_T; + +Connection($target); + +if (!$opt_T){ + $thr->kill('SIGUSR1'); + threads->exit(); +} + +print "\n"; + +exit(0); + +sub Connection { + my $target = shift; + + ($session,$error) = Net::SNMP->session( + Hostname => $target, + Community => $community, + Domain => 'udp', + Port => $port, + Version => $snmpver, + Timeout => $timeout, + Retries => $retries, + Debug => $debug, + Translate => [ + -timeticks => 0x0 + ] + ); + + if (!$session){ + printf " [*] Error: %s.\n", $session->error(); + $session->close(); + if (!$opt_T){ + $thr->kill('SIGUSR1'); + threads->exit(); + } + exit(1); + } + + my $start_time = [gettimeofday]; + + print " [*] Connected to $target\n"; + + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + printf " [*] Starting enumeration at %4d-%02d-%02d %02d:%02d:%02d\n",$year+1900,$mon+1,$mday,$hour,$min,$sec; + + # Write access check + if ($opt_w){ + + my $contact = $session->get_request( + -varbindlist => [ $mibContact ] + ); + + if (!$contact){ + printf " [*] Error: %s.\n", $session->error(); + $session->close(); + if (!$opt_T){ + $thr->kill('SIGUSR1'); + threads->exit(); + } + exit(1); + } + + my $check = $session->set_request( + -varbindlist => [$mibContact, OCTET_STRING ,'testwriteaccess'] + ); + + if ($check){ + print " [*] Write access enabled!\n"; + $session->set_request( + -varbindlist => [$mibContact, OCTET_STRING ,$contact] + ); + } else { + print " [*] No write access enabled.\n"; + } + + $session->close; + + my $end_time = [gettimeofday]; + my $elapsed = tv_interval($start_time,$end_time); + + printf " [*] Checked $target in %.2f seconds\n",$elapsed; + + exit(0); + } + + my $hostname = $session->get_request( + -varbindlist => [ $mibName ] + ); + + if (!$hostname){ + printf " [*] Error: %s.\n", $session->error(); + $session->close(); + if (!$opt_T){ + $thr->kill('SIGUSR1'); + threads->exit(); + } + exit(1); + } else { + $hostname = $hostname->{$mibName}; + } + + my $descr = SNMPSystem($hostname); + + SNMPDevices() if $descr !~ /^-|^Cisco|^Fibre|^Sun/; + SNMPStorage() if $descr !~ /^-|^Cisco|^Fibre|^Sun/; + SNMPAccounts() if $descr !~ /^-|^Cisco|^Fibre|^Sun|^Linux/; + SNMPProcesses($descr) if $descr !~ /^-|^Cisco|^Fibre|^Sun/; + SNMPNetInfo(); + SNMPRoutingInfo(); + SNMPNetServices(); + SNMPTCPConnections() if !$opt_d; + SNMPUDPPorts(); + SNMPSoftware() if $descr !~ /^-|^Cisco|^Fibre|^Sun/; + SNMPShares() if $descr !~ /^-|^Cisco|^Fibre|^Linux/; + SNMPMountPoints() if $descr !~ /^-|^Cisco|^Fibre|^Hardware/; + SNMPIIS() if $descr =~ /^Hardware/; + + $session->close; + + my $end_time = [gettimeofday]; + my $elapsed = tv_interval($start_time,$end_time); + + printf "\n [*] Enumerated $target in %.2f seconds\n",$elapsed; +} + +sub SNMPSystem { + + my $hostname = shift; + my $descr = GetRequest($mibDescr); + my $uptimeinstance = GetRequest($mibUptimeInstance); + my $systemuptime = GetRequest($mibSystemUptime); + my $contact = GetRequest($mibContact); + my $location = GetRequest($mibLocation); + my $motd = GetRequest($mibMotd); + my $ntdomain = GetRequest($mibNTDomain) if $descr =~ /^Hardware/; + + $descr = Sanitize($descr); + $motd = Sanitize($motd); + + PrintTitle("System information"); + + $uptimeinstance = ticks_to_time($uptimeinstance); + $systemuptime = ticks_to_time($systemuptime); + + print " Hostname : $hostname\n" if $hostname; + print " Description : $descr\n" if $descr; + print " Uptime system : $systemuptime\n" if $systemuptime; + print " Uptime SNMP daemon : $uptimeinstance\n" if $uptimeinstance; + print " Contact : $contact\n" if $contact; + print " Location : $location\n" if $location; + print " Motd : $motd\n" if $motd; + print " Domain (NT) : $ntdomain\n" if $ntdomain; + + return $descr; +} + +sub SNMPStorage { + + my @storindex = GetTable($mibStorIndex); + my @stortype = GetTable($mibStorType); + my @stordescr = GetTable($mibStorDescr); + my @storsize = GetTable($mibStorSize); + my @storused = GetTable($mibStorUsed); + my @storunits = GetTable($mibStorUnits); + my @ptype = GetTable($mibPtype); + + if ($#stordescr > 0){ + + PrintTitle("Storage information"); + + my $a = 0; + + foreach (@stordescr){ + + my %storagetypes = ( + '1.3.6.1.2.1.25.2.1.1' => 'Other', + '1.3.6.1.2.1.25.2.1.2' => 'Ram', + '1.3.6.1.2.1.25.2.1.3' => 'Virtual Memory', + '1.3.6.1.2.1.25.2.1.4' => 'Fixed Disk', + '1.3.6.1.2.1.25.2.1.5' => 'Removable Disk', + '1.3.6.1.2.1.25.2.1.6' => 'Floppy Disk', + '1.3.6.1.2.1.25.2.1.7' => 'Compact Disc', + '1.3.6.1.2.1.25.2.1.8' => 'Ram Disk', + '1.3.6.1.2.1.25.2.1.9' => 'Flash Memory', + '1.3.6.1.2.1.25.2.1.10' => 'Network Disk' + ); + + my %fstypes = ( + '1.3.6.1.2.1.25.3.9.1' => 'Other', + '1.3.6.1.2.1.25.3.9.2' => 'Unknown', + '1.3.6.1.2.1.25.3.9.3' => 'BerkeleyFFS', + '1.3.6.1.2.1.25.3.9.4' => 'Sys5FS', + '1.3.6.1.2.1.25.3.9.5' => 'Fat', + '1.3.6.1.2.1.25.3.9.6' => 'HPFS', + '1.3.6.1.2.1.25.3.9.7' => 'HFS', + '1.3.6.1.2.1.25.3.9.8' => 'MFS', + '1.3.6.1.2.1.25.3.9.9' => 'NTFS', + '1.3.6.1.2.1.25.3.9.10' => 'VNode', + '1.3.6.1.2.1.25.3.9.11' => 'Journaled', + '1.3.6.1.2.1.25.3.9.12' => 'iso9660', + '1.3.6.1.2.1.25.3.9.13' => 'RockRidge', + '1.3.6.1.2.1.25.3.9.14' => 'NFS', + '1.3.6.1.2.1.25.3.9.15' => 'Netware', + '1.3.6.1.2.1.25.3.9.16' => 'AFS', + '1.3.6.1.2.1.25.3.9.17' => 'DFS', + '1.3.6.1.2.1.25.3.9.18' => 'Appleshare', + '1.3.6.1.2.1.25.3.9.19' => 'RFS', + '1.3.6.1.2.1.25.3.9.20' => 'DGCFS', + '1.3.6.1.2.1.25.3.9.21' => 'BFS', + '1.3.6.1.2.1.25.3.9.22' => 'FAT32', + '1.3.6.1.2.1.25.3.9.23' => 'LinuxExt2' + ); + + print " $_\n"; + + print "\tDevice id : $storindex[$a]\n" if $storindex[$a]; + print "\tDevice type : $storagetypes{$stortype[$a]}\n" if $storagetypes{$stortype[$a]}; + + if ($ptype[$a]){ + if ($fstypes{$ptype[$a]}){ + print "\tFilesystem type : $fstypes{$ptype[$a]}\n"; + } else{ + print "\tFilesystem type : Unknown\n"; + } + } else{ + print "\tFilesystem type : Unknown\n"; + } + + if ($storunits[$a]){ + print "\tDevice units : $storunits[$a]\n"; + + if ($storsize[$a]){ + $storsize[$a] = ($storsize[$a] * $storunits[$a]); + my $s = format_bytes($storsize[$a]); + print "\tMemory size : $s\n"; + } + + if ($storused[$a]){ + $storused[$a] = $storused[$a] * $storunits[$a]; + my $s = format_bytes($storused[$a]); + print "\tMemory used : $s\n"; + } + + if ($storsize[$a] and $storused[$a]){ + my $free = $storsize[$a] - $storused[$a]; + $free = format_bytes($free); + print "\tMemory free : $free\n"; + } + } + + print "\n"; + + $a++; + } + } +} + +sub SNMPDevices { + + my @devicesindex = GetTable($mibDevIndex); + my @devicestype = GetTable($mibDevType); + my @deviceslist = GetTable($mibDevList); + my @devicestatus = GetTable($mibDevStatus); + + if ($#deviceslist > 0){ + + PrintTitle("Devices information"); + + my %devicetype = ( + '1.3.6.1.2.1.25.3.1.1' => 'Other', + '1.3.6.1.2.1.25.3.1.2' => 'Unknown', + '1.3.6.1.2.1.25.3.1.3' => 'Processor', + '1.3.6.1.2.1.25.3.1.4' => 'Network', + '1.3.6.1.2.1.25.3.1.5' => 'Printer', + '1.3.6.1.2.1.25.3.1.6' => 'Disk Storage', + '1.3.6.1.2.1.25.3.1.10' => 'Video', + '1.3.6.1.2.1.25.3.1.11' => 'Audio', + '1.3.6.1.2.1.25.3.1.12' => 'Coprocessor', + '1.3.6.1.2.1.25.3.1.13' => 'Keyboard', + '1.3.6.1.2.1.25.3.1.14' => 'Modem', + '1.3.6.1.2.1.25.3.1.15' => 'Parallel Port', + '1.3.6.1.2.1.25.3.1.16' => 'Pointing', + '1.3.6.1.2.1.25.3.1.17' => 'Serial Port', + '1.3.6.1.2.1.25.3.1.18' => 'Tape', + '1.3.6.1.2.1.25.3.1.19' => 'Clock', + '1.3.6.1.2.1.25.3.1.20' => 'Volatile Memory', + '1.3.6.1.2.1.25.3.1.21' => 'Non Volatile Memory' + ); + + printf " %5s %20s %7s %s\n\n","Id","Type","Status","Description"; + + my $a = 0; + + foreach (@deviceslist){ + + my $id = '-'; + my $type = '-'; + my $status = 'Unknown'; + my $descr = $_; + + $type = $devicetype{$devicestype[$a]}; + + if ($devicestatus[$a]){ + if ($devicestatus[$a] eq '1'){ + $status = "Unknown"; + }elsif($devicestatus[$a] eq '2'){ + $status = "Running"; + }elsif($devicestatus[$a] eq '3'){ + $status = "Warning"; + }elsif($devicestatus[$a] eq '4'){ + $status = "Testing"; + }elsif($devicestatus[$a] eq '5'){ + $status = "Down"; + } + } + + printf " %5s %20s %7s %s\n",$devicesindex[$a],$type,$status,$descr; + + $a++; + } + } +} + +sub SNMPAccounts { + + my @accounts = GetTable($mibAccounts); + + if ($#accounts > 0){ + + PrintTitle("User accounts"); + + @accounts = sort @accounts; + foreach(@accounts){ + print " $_\n"; + } + } +} + +sub SNMPProcesses { + + my $descr = shift; + + if ($descr =~ /^Sun/){ + + # Solaris + my @runproid = GetTable("1.3.6.1.4.1.42.3.12.1.1.1"); # psProcessID + my @runparid = GetTable("1.3.6.1.4.1.42.3.12.1.1.2"); # psParentProcessID + my @runprosize = GetTable("1.3.6.1.4.1.42.3.12.1.1.3"); # psProcessSize + my @runcputime = GetTable("1.3.6.1.4.1.42.3.12.1.1.4"); # psProcessCpuTime + my @runstate = GetTable("1.3.6.1.4.1.42.3.12.1.1.5"); # psProcessState + my @runtty = GetTable("1.3.6.1.4.1.42.3.12.1.1.7"); # psProcessTTY + my @runusername = GetTable("1.3.6.1.4.1.42.3.12.1.1.8"); # psProcessUserName + my @runuserid = GetTable("1.3.6.1.4.1.42.3.12.1.1.9"); # psProcessUserID + my @runname = GetTable("1.3.6.1.4.1.42.3.12.1.1.10"); # psProcessName + my @runstatus = GetTable("1.3.6.1.4.1.42.3.12.1.1.11"); # psProcessStatus + + if ($#runproid > 0){ + + PrintTitle("Processes"); + + print " Pid Ppid Size Cputime State TTY Username Uid Name Status\n\n"; + + for (my $a = 0; $a < $#runproid; $a++){ + printf " %6s %6s %6s %6s %6s %10s %10s %6s %15s %6s\n", $runproid[$a],$runparid[$a],$runprosize[$a],$runcputime[$a],$runstate[$a],$runtty[$a],$runusername[$a],$runuserid[$a],$runname[$a],$runstatus[$a]; + } + } + + } else{ + # Other + my $processes = GetRequest($mibProcesses); + my @runindex = GetTable($mibRunIndex); + my @runname = GetTable($mibRunName); + my @runpath = GetTable($mibRunPath); + my @runtype = GetTable($mibRunType); + my @runstatus = GetTable($mibRunStatus); + + if ($#runindex > 0){ + + PrintTitle("Processes"); + + print " Total processes : $processes\n\n" if $processes; + print " Process type : 1 unknown, 2 operating system, 3 device driver, 4 application\n"; + print " Process status : 1 running, 2 runnable, 3 not runnable, 4 invalid\n\n"; + + printf " %10s %25s %13s %15s Process path\n\n", "Process id","Process name","Process type","Process status"; + + for (my $a = 0; $a < $#runindex; $a++){ + if ($runname[$a] ne " System Idle Process"){ + printf " %10s %25s %13s %15s $runpath[$a]\n", $runindex[$a],$runname[$a],$runtype[$a],$runstatus[$a]; + } + } + } + } +} + +sub SNMPNetInfo { + + PrintTitle("Network information"); + + my $ipforward = GetRequest($mibIPForward); + my $DefaultTTL = GetRequest($mibDefaultTTL); + my $TCPInSegs = GetRequest($mibTCPInSegs); + my $TCPOutSegs = GetRequest($mibTCPOutSegs); + my $TCPRetransSegs = GetRequest($mibTCPRetransSegs); + my $InReceives = GetRequest($mibInReceives); + my $InDelivers = GetRequest($mibInDelivers); + my $OutRequests = GetRequest($mibOutRequests); + + if ($ipforward eq "0" || $ipforward eq "2") { $ipforward = "no"; } + + print " IP forwarding enabled : $ipforward\n"; + print " Default TTL : $DefaultTTL\n"; + print " TCP segments received : $TCPInSegs\n"; + print " TCP segments sent : $TCPOutSegs\n"; + print " TCP segments retrans. : $TCPRetransSegs\n"; + print " Input datagrams : $InReceives\n"; + print " Delivered datagrams : $InDelivers\n"; + print " Output datagrams : $OutRequests\n"; + + my @int = GetTable($mibInt); + my @mtu = GetTable($mibIntMTU); + my @intspeed = GetTable($mibIntSpeed); + my @intbytesin = GetTable($mibIntBytesIn); + my @intbytesout = GetTable($mibIntBytesOut); + my @intphys = GetTable($mibIntPhys); + my @ipaddr = GetTable($mibIPAddr); + my @netmask = GetTable($mibNetmask); + my @adminstat = GetTable($mibAdminStat); + + if ($#int > 0){ + + PrintTitle("Network interfaces"); + + $#int++; + for (my $a = 0; $a < $#int; $a++){ + + chomp $int[$a]; + + if (@adminstat){ + if ($adminstat[$a] eq "0"){ + $adminstat[$a] = "down"; + } else { + $adminstat[$a] = "up"; + } + } else { + $adminstat[$a] = '-'; + } + + if ($intspeed[$a] !~ /-/){ + + $intspeed[$a] = $intspeed[$a] / 1000000; + + if ($intphys[$a]){ + $intphys[$a] =~ s/\A..//xms; # remove the 0x + $intphys[$a] =~ s/(..)/$1:/g; # add a colon between bytes + $intphys[$a] =~ s/:$//; # remove the trailing : + } + + print " Interface : [ $adminstat[$a] ] $int[$a]\n\n"; + print "\tHardware Address : $intphys[$a]\n" if $intphys[$a]; + print "\tInterface Speed : $intspeed[$a] Mbps\n" if $intspeed[$a]; + print "\tIP Address : $ipaddr[$a]\n" if $ipaddr[$a]; + print "\tNetmask : $netmask[$a]\n" if $ipaddr[$a]; + print "\tMTU : $mtu[$a]\n" if $mtu[$a]; + + if ($intbytesin[$a]){ + print "\tBytes In : $intbytesin[$a]"; + $intbytesin[$a] = format_bytes($intbytesin[$a]); + print " ($intbytesin[$a])\n"; + } + + if ($intbytesout[$a]){ + print "\tBytes Out : $intbytesout[$a]"; + if ($intbytesout[$a] =~ /(\d+)/){ + $intbytesout[$a] = format_bytes($intbytesout[$a]); + } + print " ($intbytesout[$a])\n"; + } + + print "\n"; + } + } + } +} + +sub SNMPNetServices { + + my @services = GetTable($mibServices); + + if ($#services > 0){ + + PrintTitle("Network services"); + + @services = sort @services; + foreach(@services){ + print " $_\n"; + } + } +} + +sub SNMPRoutingInfo { + + my @routedest = GetTable($mibRouteDest); + my @routenhop = GetTable($mibRouteNHop); + my @routemask = GetTable($mibRouteMask); + my @routemetric = GetTable($mibRouteMetric); + + if ($#routedest > 0){ + + PrintTitle("Routing information"); + + print " Destination\t Next Hop\t Mask\tMetric\n\n"; + + for (my $a = 0; $a < $#routedest; $a++){ + + $routedest[$a] = '-' if !$routedest[$a]; + $routenhop[$a] = '-' if !$routenhop[$a]; + $routemask[$a] = '-' if !$routemask[$a]; + $routemetric[$a] = '-' if !$routemetric[$a]; + + printf "%17s%17s%17s%9s\n", $routedest[$a], $routenhop[$a], $routemask[$a], $routemetric[$a]; + } + } +} + +sub SNMPTCPConnections { + + my @tcpstate = GetTable($mibTCPState); + my @tcpladdr = GetTable($mibTCPLAddr); + my @tcplport = GetTable($mibTCPLPort); + my @tcpraddr = GetTable($mibTCPRAddr); + my @tcprport = GetTable($mibTCPRPort); + + if ($#tcpstate > 0){ + + PrintTitle("Listening TCP ports and connections"); + + print " Local Address Port Remote Address Port State\n\n"; + + for (my $a = 0; $a < $#tcpstate; $a++){ + if ($tcpstate[$a] eq "1") { $tcpstate[$a] = "Closed"; } + if ($tcpstate[$a] eq "2") { $tcpstate[$a] = "Listening"; } + if ($tcpstate[$a] eq "3") { $tcpstate[$a] = "SYN sent"; } + if ($tcpstate[$a] eq "4") { $tcpstate[$a] = "SYN received"; } + if ($tcpstate[$a] eq "5") { $tcpstate[$a] = "Established"; } + if ($tcpstate[$a] eq "6") { $tcpstate[$a] = "FIN wait1"; } + if ($tcpstate[$a] eq "7") { $tcpstate[$a] = "FIN wait2"; } + if ($tcpstate[$a] eq "8") { $tcpstate[$a] = "Close wait"; } + if ($tcpstate[$a] eq "9") { $tcpstate[$a] = "Last ack"; } + if ($tcpstate[$a] eq "10") { $tcpstate[$a] = "Closing"; } + if ($tcpstate[$a] eq "11") { $tcpstate[$a] = "Time wait"; } + if ($tcpstate[$a] eq "12") { $tcpstate[$a] = "Delete tcb"; } + + $tcpladdr[$a] = '-' if !$tcpladdr[$a]; + $tcplport[$a] = '-' if !$tcplport[$a]; + $tcpraddr[$a] = '-' if !$tcpraddr[$a]; + $tcprport[$a] = '-' if !$tcprport[$a]; + $tcpstate[$a] = '-' if !$tcpstate[$a]; + + printf " %15s %6s %17s %6s %15s\n", $tcpladdr[$a], $tcplport[$a], $tcpraddr[$a], $tcprport[$a], $tcpstate[$a]; + } + } +} + +sub SNMPUDPPorts { + + my @udpladdr = GetTable($mibUDPLAddr); + my @udplport = GetTable($mibUDPLPort); + + if ($#udpladdr > 0){ + + PrintTitle("Listening UDP ports"); + + print " Local Address Port\n\n"; + + for (my $a = 0; $a < $#udpladdr; $a++){ + $udpladdr[$a] = '-' if !$udpladdr[$a]; + $udplport[$a] = '-' if !$udplport[$a]; + + printf " %15s %6s\n", $udpladdr[$a], $udplport[$a]; + } + } +} + +sub SNMPSoftware { + + my @softindex = GetTable($mibSoftIndex); + my @softname = GetTable($mibSoftName); + + if ($#softname > 0){ + + PrintTitle("Software components"); + + my @soft; + for (my $a = 0; $a < $#softname; $a++){ + push @soft,"$softindex[$a]. $softname[$a]"; + } + + @soft = sort @soft; + foreach(@soft){ + print " $_\n"; + } + } +} + +sub SNMPIIS { + + my $http_totalBytesSentLowWord = GetRequest($http_totalBytesSentLowWord); + my $http_totalBytesReceivedLowWord = GetRequest($http_totalBytesReceivedLowWord); + my $http_totalFilesSent = GetRequest($http_totalFilesSent); + my $http_currentAnonymousUsers = GetRequest($http_currentAnonymousUsers); + my $http_currentNonAnonymousUsers = GetRequest($http_currentNonAnonymousUsers); + my $http_totalAnonymousUsers = GetRequest($http_totalAnonymousUsers); + my $http_totalNonAnonymousUsers = GetRequest($http_totalNonAnonymousUsers); + my $http_maxAnonymousUsers = GetRequest($http_maxAnonymousUsers); + my $http_maxNonAnonymousUsers = GetRequest($http_maxNonAnonymousUsers); + my $http_currentConnections = GetRequest($http_currentConnections); + my $http_maxConnections = GetRequest($http_maxConnections); + my $http_connectionAttempts = GetRequest($http_connectionAttempts); + my $http_logonAttempts = GetRequest($http_logonAttempts); + my $http_totalGets = GetRequest($http_totalGets); + my $http_totalPosts = GetRequest($http_totalPosts); + my $http_totalHeads = GetRequest($http_totalHeads); + my $http_totalOthers = GetRequest($http_totalOthers); + my $http_totalCGIRequests = GetRequest($http_totalCGIRequests); + my $http_totalBGIRequests = GetRequest($http_totalBGIRequests ); + my $http_totalNotFoundErrors = GetRequest($http_totalNotFoundErrors); + + if ($http_totalFilesSent){ + PrintTitle("Web server information"); + } + + if ($http_totalBytesSentLowWord){ + if ($http_totalBytesSentLowWord =~ /\d+/){ + $http_totalBytesSentLowWord = format_bytes($http_totalBytesSentLowWord); + print " Total bytes sent low word : $http_totalBytesSentLowWord\n"; + } else { + print " Total bytes sent low word : -\n"; + } + } + + if ($http_totalBytesReceivedLowWord){ + if ($http_totalBytesReceivedLowWord =~ /\d+/){ + $http_totalBytesReceivedLowWord = format_bytes($http_totalBytesReceivedLowWord); + print " Total bytes received low word : $http_totalBytesReceivedLowWord\n"; + } else { + print " Total bytes received low word : -\n"; + } + } + + print " Total files sent : $http_totalFilesSent\n" if $http_totalFilesSent; + print " Current anonymous users : $http_currentAnonymousUsers\n" if $http_currentAnonymousUsers; + print " Current non anonymous users : $http_currentNonAnonymousUsers\n" if $http_currentNonAnonymousUsers; + print " Total anonymous users : $http_totalAnonymousUsers\n" if $http_totalAnonymousUsers; + print " Total non anonymous users : $http_totalNonAnonymousUsers\n" if $http_totalNonAnonymousUsers; + print " Max anonymous users : $http_maxAnonymousUsers\n" if $http_maxAnonymousUsers; + print " Max non anonymous users : $http_maxNonAnonymousUsers\n" if $http_maxNonAnonymousUsers; + print " Current connections : $http_currentConnections\n" if $http_currentConnections; + print " Max connections : $http_maxConnections\n" if $http_maxConnections; + print " Connection attempts : $http_connectionAttempts\n" if $http_connectionAttempts; + print " Logon attempts : $http_logonAttempts\n" if $http_logonAttempts; + print " Total gets : $http_totalGets\n" if $http_totalGets; + print " Total posts : $http_totalPosts\n" if $http_totalPosts; + print " Total heads : $http_totalHeads\n" if $http_totalHeads; + print " Total others : $http_totalOthers\n" if $http_totalOthers; + print " Total CGI requests : $http_totalCGIRequests\n" if $http_totalCGIRequests; + print " Total BGI requests : $http_totalBGIRequests\n" if $http_totalBGIRequests; + print " Total not found errors : $http_totalNotFoundErrors\n" if $http_totalNotFoundErrors; +} + +sub SNMPMountPoints { + + my @StorDescr = GetTable($mibStorDescr); + + if ($#StorDescr > 0){ + + PrintTitle("Mountpoints"); + + my $x = 0; + + for (my $a = 0; $a < $#StorDescr; $a++){ + if ($StorDescr[$a] =~ /\//){ + print " $StorDescr[$a]\n"; + $x++; + } + } + + if ($x == 0){ + print " Not available\n"; + } + } +} + +sub SNMPShares { + + my @ShareName = GetTable($mibShareName); + my @SharePath = GetTable($mibSharePath); + my @ShareComm = GetTable($mibShareComm); + + if ($#ShareName > 0){ + + PrintTitle("Non-administrative shares"); + + for (my $a = 0; $a < $#ShareName; $a++){ + print " Share Name : $ShareName[$a]\n"; + print " Path : $SharePath[$a]\n"; + print " Comments : $ShareComm[$a]\n\n"; + } + } +} + +sub GetRequest { + + my $oid = shift; + + my $result = $session->get_request( + -varbindlist => [ $oid ] + ); + + if ($result){ + return $result->{$oid}; + } else { + return '-'; + } +} + +sub GetTable { + + my $oid = shift; + + my @return; + my $response = ''; + my $x = 0; + + if ($response = $session->get_table(-baseoid => $oid)){ + foreach my $key (sort keys %$response){ + if ($$response{$key} ne " Virtual Memory"){ + $return[$x] = $$response{$key}; + $x++; + } + } + + return @return; + } else{ + return '-'; + } +} + +sub PrintTitle { + + my $title = shift; + + print "\n [*] $title\n"; + print " "; print "-" x 95; print "\n\n"; +} + +sub Sanitize { + + my $string = shift; + + if ($string){ + chomp $string; + $string =~ s/^\s+$|^\s+$|\n+|\r+//g; + } + + return $string; +} + +sub WaitProcess { + + my $timeout = shift; + + while(1){ + sleep $timeout; + print " [*] Wait...don't stop $name...\n"; + } +} + +__END__ + +=head1 NAME + +snmpcheck - Perl script to enumerate information via SNMP protocol + +=head1 SYNOPSIS + +./snmpcheck.pl -t + +-t : target host; + +-p : SNMP port; default port is 161; + +-c : SNMP community; default is public; + +-v : SNMP version (1,2); default is 1; + +-r : request retries; default is 2; + +-w : detect write access (separate action by enumeration); + +-d : disable 'TCP connections' enumeration! + +-T : force timeout in seconds; default is 60. Max is 60; + +-D : enable debug; + +-h : show help menu; + +=head1 DESCRIPTION + +Like to snmpwalk, snmpcheck permits to enumerate information via SNMP protocol. +It allows enumeration (hardware, software, network) of any devices with SNMP protocol support. +It could be useful for penetration testing or systems monitoring. + +Tested on GNU/Linux, *BSD and Windows (Cygwin and ActivePerl) systems. +Distributed under GPL license and based on "Athena-2k" script by jshaw. + +=head1 NOTE + +"TCP connections enumeration" can be very long. Use -d flag to disable it. + +=head1 BUGS + +You can help sending bug reports or writing patches. + +=head1 SEE ALSO + +http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol +http://net-snmp.sourceforge.net/docs/man/snmpwalk.html + +=head1 AUTHOR + +Matteo Cantoni, Ematteo.cantoni@nothink.org + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2005-2010 by Matteo Cantoni + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +=cut diff --git a/snmpcheck-1.9.rb b/snmpcheck-1.9.rb deleted file mode 100644 index 5b8eece..0000000 --- a/snmpcheck-1.9.rb +++ /dev/null @@ -1,1128 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright (c) 2005-2015 by Matteo Cantoni (www.nothink.org) -# -# Snmpcheck is an open source tool distributed under GPL license. -# Its goal is to automate the process of gathering information of -# any devices with SNMP protocol support (Windows, Unix-like, -# network appliances, printers...). -# Like to snmpwalk, snmpcheck allows you to enumerate the SNMP devices -# and places the output in a very human readable friendly format. -# It could be useful for penetration testing or systems monitoring. -# More informations available from http://www.nothink.org. -# -# Install Ruby SNMP library using RubyGems: 'gem install snmp' -# -# --- -# -# License: (http://www.gnu.org/licenses/gpl.txt) -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Thanks to Metasploit contributors! -# http://www.rapid7.com/db/modules/auxiliary/scanner/snmp/snmp_enum -# - -# ruby version check -if RUBY_VERSION < "1.9.0" -abort <<-end_message -[!] snmpcheck requires Ruby version >= 1.9.0 -end_message -end - -require 'getoptlong' -require 'rubygems' -require 'snmp' -require 'timeout' - -include SNMP - -# catching Ctrl+C -trap("SIGINT") { exit! } - -# disable verbose -$VERBOSE = nil - -script_name = 'snmpcheck.rb'; -script_version = 'v1.9'; -script_description = 'SNMP enumerator'; -script_copyright = 'Copyright (c) 2005-2015'; -script_author = 'Matteo Cantoni (www.nothink.org)'; - -script_usage = " Usage: #{script_name} [OPTIONS] \n - -p --port : SNMP port. Default port is 161; - -c --community : SNMP community. Default is public; - -v --version : SNMP version (1,2c). Default is 1;\n - -w --write : detect write access (separate action by enumeration);\n - -d --disable_tcp : disable TCP connections enumeration! - -t --timeout : timeout in seconds. Default is 5; - -r --retries : request retries. Default is 1; - -i --info : show script version; - -h --help : show help menu;\n\n" - -def print_banner(script_name,script_version,script_description,script_copyright,script_author) - puts "#{script_name} #{script_version} - #{script_description}\n#{script_copyright} by #{script_author}\n\n" -end - -def print_things(msg='',prefix) - case prefix - when 'error' - puts "[!] #{msg}" - when 'info' - puts "[+] #{msg}" - when 'result' - puts "[*] #{msg}" - end -end - -def truncate_to_twidth(string,twidth) - string.slice(0..twidth-2) -end - -def number_to_human_size(size,unit) - size = size.first.to_i * unit.first.to_i - - if size < 1024 - "#{size} bytes" - elsif size < 1024.0 * 1024.0 - "%.02f KB" % (size / 1024.0) - elsif size < 1024.0 * 1024.0 * 1024.0 - "%.02f MB" % (size / 1024.0 / 1024.0) - else - "%.02f GB" % (size / 1024.0 / 1024.0 / 1024.0) - end -end - -target = nil -port = 161 -community = 'public' -version = '1' -check_write = nil -disable_tcp = nil -timeout = 5 -retries = 1 - -begin - - opts = GetoptLong.new( - [ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT ], - [ '--community', '-c', GetoptLong::REQUIRED_ARGUMENT ], - [ '--version', '-v', GetoptLong::REQUIRED_ARGUMENT ], - [ '--write', '-w', GetoptLong::NO_ARGUMENT ], - [ '--disable_tcp', '-d', GetoptLong::NO_ARGUMENT ], - [ '--timeout', '-t', GetoptLong::REQUIRED_ARGUMENT ], - [ '--retries', '-r', GetoptLong::REQUIRED_ARGUMENT ], - [ '--info', '-i', GetoptLong::NO_ARGUMENT ], - [ '--help', '-h', GetoptLong::NO_ARGUMENT ] - ) - - opts.each do |opt, arg| - case opt - when '--port' - port = arg.to_i - when '--community' - community = arg.to_s - when '--version' - version = arg.to_s - when '--write' - check_write = 1 - when '--disable_tcp' - disable_tcp = 1 - when '--timeout' - timeout = arg.to_i - when '--retries' - retries = arg.to_i - when '--info' - print_banner(script_name,script_version,script_description,script_copyright,script_author) - exit 0 - when '--help' - print_banner(script_name,script_version,script_description,script_copyright,script_author) - puts script_usage - exit 0 - end - end - -rescue GetoptLong::InvalidOption, GetoptLong::MissingArgument, GetoptLong::NeedlessArgument - exit 1; -end - -if ARGV.length != 1 - print_things("You need specify a IP address target!","error") - exit 0 -end - -target = ARGV.shift - -if target !~ /^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$/ - print_things("Invalid IP address!","error") - exit 0 -end - -# is there a community length limit? -if community.length >= 25 - print_things("Invalid community length!","error") - exit 0 -end - -if port < 0 or port > 65535 - print_things("Invalid port!","error") - exit 0 -end - -if retries < 0 or retries > 10 - print_things("Invalid 'retries' value!","error") - exit 0 -end - -if version == '1' - version = :SNMPv1 -elsif version == '2c' - version = :SNMPv2c -else - print_things("SNMP version invalid! We'll use 1 version!","error") - version = :SNMPv1 -end - -fields_order = [ - "Host IP address","Hostname","Description","Contact","Location","Uptime snmp","Uptime system", - "System date","Domain","User accounts","Network information","Network interfaces", - "Network IP","Routing information","TCP connections and listening ports","Listening UDP ports", - "Network services","Processes","Storage information","File system information","Device information", - "Software components","IIS server information","Share","HP LaserJet printer enumeration" -] - -output_data = {} -output_data = {"Host IP address" => target} - -print_banner(script_name,script_version,script_description,script_copyright,script_author) -print_things("Try to connect to #{target}:#{port} using #{version} and community '#{community}'","info") -print_things("Write access check enabled\n","info") unless check_write.nil? -print_things("TCP connections enumeration disabled","info") unless disable_tcp.nil? -puts - -begin - - SNMP::Manager.open( - :Host => target, - :Port => port, - :Community => community, - :Version => version, - :Timeout => timeout, - :Retries => retries - ) do |manager| - - sysName = manager.get_value('1.3.6.1.2.1.1.5.0').to_s - output_data["Hostname"] = sysName.strip - - # check write access - if check_write and sysName - # 1.3.6.1.2.1.1.5.0 - sysName - varbind = VarBind.new("1.3.6.1.2.1.1.5.0",OctetString.new(sysName.strip)) - resp = manager.set(varbind) - - if resp.error_status == :noError - print_things("Write access permitted!\n\n","result") - else - print_things("Write access not permitted!\n","result") - end - end - - sysDesc = manager.get_value('1.3.6.1.2.1.1.1.0').to_s - sysDesc.gsub!(/^\s+|\s+$|\n+|\r+/, ' ') - output_data["Description"] = sysDesc.strip - - sysContact = manager.get_value('1.3.6.1.2.1.1.4.0').to_s - output_data["Contact"] = sysContact.strip - - sysLocation = manager.get_value('1.3.6.1.2.1.1.6.0').to_s - output_data["Location"] = sysLocation.strip - - sysUpTimeInstance = manager.get_value('1.3.6.1.2.1.1.3.0').to_s - output_data["Uptime system"] = sysUpTimeInstance.strip - - hrSystemUptime = manager.get_value('1.3.6.1.2.1.25.1.1.0').to_s - output_data["Uptime snmp"] = hrSystemUptime.strip - hrSystemUptime = '-' if hrSystemUptime.to_s =~ /Null/ - - year = month = day = hour = minutes = seconds = tenths = 0 - - systemDate = manager.get_value('1.3.6.1.2.1.25.1.2.0') - str = systemDate.to_s - if (str.empty? or str =~ /Null/ or str =~ /^noSuch/) - output_data["System date"] = '-' - else - # RFC 2579 - Textual Conventions for SMIv2 - # http://www.faqs.org/rfcs/rfc2579.html - - systemDate = systemDate.unpack('C*') - - year = systemDate[0] * 256 + systemDate[1] - month = systemDate[2] || 0 - day = systemDate[3] || 0 - hour = systemDate[4] || 0 - minutes = systemDate[5] || 0 - seconds = systemDate[6] || 0 - tenths = systemDate[7] || 0 - output_data["System date"] = sprintf("%d-%d-%d %02d:%02d:%02d.%d", year, month, day, hour, minutes, seconds, tenths) - end - - if (sysDesc =~ /Windows/) - - domPrimaryDomain = manager.get_value('1.3.6.1.4.1.77.1.4.1.0').to_s - output_data["Domain"] = domPrimaryDomain.strip - - users = [] - - manager.walk(["1.3.6.1.4.1.77.1.2.25.1.1","1.3.6.1.4.1.77.1.2.25.1"]) do |user,entry| - users.push([user.value]) - end - - if not users.empty? - output_data["User accounts"] = users - end - end - - network_information = {} - - ipForwarding = manager.get_value('1.3.6.1.2.1.4.1.0') - - if ipForwarding == 0 || ipForwarding == 2 - ipForwarding = "no" - network_information["IP forwarding enabled"] = ipForwarding - elsif ipForwarding == 1 - ipForwarding = "yes" - network_information["IP forwarding enabled"] = ipForwarding - end - - ipDefaultTTL = manager.get_value('1.3.6.1.2.1.4.2.0') - if ipDefaultTTL.to_s !~ /Null/ - network_information["Default TTL"] = ipDefaultTTL - end - - tcpInSegs = manager.get_value('1.3.6.1.2.1.6.10.0') - if tcpInSegs.to_s !~ /Null/ - network_information["TCP segments received"] = tcpInSegs - end - - tcpOutSegs = manager.get_value('1.3.6.1.2.1.6.11.0') - if tcpOutSegs.to_s !~ /Null/ - network_information["TCP segments sent"] = tcpOutSegs - end - - tcpRetransSegs = manager.get_value('1.3.6.1.2.1.6.12.0') - if tcpRetransSegs.to_s !~ /Null/ - network_information["TCP segments retrans"] = tcpRetransSegs - end - - ipInReceives = manager.get_value('1.3.6.1.2.1.4.3.0') - if ipInReceives.to_s !~ /Null/ - network_information["Input datagrams"] = ipInReceives - end - - ipInDelivers = manager.get_value('1.3.6.1.2.1.4.9.0') - if ipInDelivers.to_s !~ /Null/ - network_information["Delivered datagrams"] = ipInDelivers - end - - ipOutRequests = manager.get_value('1.3.6.1.2.1.4.10.0') - if ipOutRequests.to_s !~ /Null/ - network_information["Output datagrams"] = ipOutRequests - end - - if not network_information.empty? - output_data["Network information"] = network_information - end - - network_interfaces = [] - - manager.walk([ - "1.3.6.1.2.1.2.2.1.1","1.3.6.1.2.1.2.2.1.2","1.3.6.1.2.1.2.2.1.6", - "1.3.6.1.2.1.2.2.1.3","1.3.6.1.2.1.2.2.1.4","1.3.6.1.2.1.2.2.1.5", - "1.3.6.1.2.1.2.2.1.10","1.3.6.1.2.1.2.2.1.16","1.3.6.1.2.1.2.2.1.7" - ]) do |index,descr,mac,type,mtu,speed,inoc,outoc,status| - - ifindex = index.value - ifdescr = descr.value - ifmac = mac.value.unpack("H2H2H2H2H2H2").join(":") - iftype = type.value - ifmtu = mtu.value - ifspeed = speed.value.to_i - ifinoc = inoc.value - ifoutoc = outoc.value - ifstatus = status.value - - case iftype - when 1 - iftype = "other" - when 2 - iftype = "regular1822" - when 3 - iftype = "hdh1822" - when 4 - iftype = "ddn-x25" - when 5 - iftype = "rfc877-x25" - when 6 - iftype = "ethernet-csmacd" - when 7 - iftype = "iso88023-csmacd" - when 8 - iftype = "iso88024-tokenBus" - when 9 - iftype = "iso88025-tokenRing" - when 10 - iftype = "iso88026-man" - when 11 - iftype = "starLan" - when 12 - iftype = "proteon-10Mbit" - when 13 - iftype = "proteon-80Mbit" - when 14 - iftype = "hyperchannel" - when 15 - iftype = "fddi" - when 16 - iftype = "lapb" - when 17 - iftype = "sdlc" - when 18 - iftype = "ds1" - when 19 - iftype = "e1" - when 20 - iftype = "basicISDN" - when 21 - iftype = "primaryISDN" - when 22 - iftype = "propPointToPointSerial" - when 23 - iftype = "ppp" - when 24 - iftype = "softwareLoopback" - when 25 - iftype = "eon" - when 26 - iftype = "ethernet-3Mbit" - when 27 - iftype = "nsip" - when 28 - iftype = "slip" - when 29 - iftype = "ultra" - when 30 - iftype = "ds3" - when 31 - iftype = "sip" - when 32 - iftype = "frame-relay" - else - iftype = "unknown" - end - - case ifstatus - when 1 - ifstatus = "up" - when 2 - ifstatus = "down" - when 3 - ifstatus = "testing" - else - ifstatus = "unknown" - end - - ifspeed = ifspeed / 1000000 - - network_interfaces.push({ - "Interface" => "[ #{ifstatus} ] #{ifdescr}", - "Id" => ifindex, - "Mac Address" => ifmac, - "Type" => iftype, - "Speed" => "#{ifspeed} Mbps", - "MTU" => ifmtu, - "In octets" => ifinoc, - "Out octets" => ifoutoc - }) - end - - if not network_interfaces.empty? - output_data["Network interfaces"] = network_interfaces - end - - network_ip = [] - - manager.walk([ - "1.3.6.1.2.1.4.20.1.2","1.3.6.1.2.1.4.20.1.1", - "1.3.6.1.2.1.4.20.1.3","1.3.6.1.2.1.4.20.1.4" - ]) do |ifid,ipaddr,netmask,bcast| - network_ip.push([ifid.value, ipaddr.value, netmask.value, bcast.value]) - end - - if not network_ip.empty? - output_data["Network IP"] = [["Id","IP Address","Netmask","Broadcast"]] + network_ip - end - - routing = [] - - manager.walk([ - "1.3.6.1.2.1.4.21.1.1","1.3.6.1.2.1.4.21.1.7", - "1.3.6.1.2.1.4.21.1.11","1.3.6.1.2.1.4.21.1.3" - ]) do |dest,hop,mask,metric| - if (metric.value.to_s.empty?) - metric.value = '-' - end - routing.push([dest.value, hop.value, mask.value, metric.value]) - end - - if not routing.empty? - output_data["Routing information"] = [["Destination","Next hop","Mask","Metric"]] + routing - end - - if disable_tcp.nil? - - tcp = [] - - manager.walk([ - "1.3.6.1.2.1.6.13.1.2","1.3.6.1.2.1.6.13.1.3","1.3.6.1.2.1.6.13.1.4", - "1.3.6.1.2.1.6.13.1.5","1.3.6.1.2.1.6.13.1.1" - ]) do |ladd,lport,radd,rport,state| - - if (ladd.value.to_s.empty? or ladd.value.to_s =~ /noSuchInstance/) - ladd = "-" - else - ladd = ladd.value - end - - if (lport.value.to_s.empty? or lport.value.to_s =~ /noSuchInstance/) - lport = "-" - else - lport = lport.value - end - - if (radd.value.to_s.empty? or radd.value.to_s =~ /noSuchInstance/) - radd = "-" - else - radd = radd.value - end - - if (rport.value.to_s.empty? or rport.value.to_s =~ /noSuchInstance/) - rport = "-" - else - rport = rport.value - end - - case state.value - when 1 - state = "closed" - when 2 - state = "listen" - when 3 - state = "synSent" - when 4 - state = "synReceived" - when 5 - state = "established" - when 6 - state = "finWait1" - when 7 - state = "finWait2" - when 8 - state = "closeWait" - when 9 - state = "lastAck" - when 10 - state = "closing" - when 11 - state = "timeWait" - when 12 - state = "deleteTCB" - else - state = "unknown" - end - - tcp.push([ladd, lport, radd, rport, state]) - end - - if not tcp.empty? - output_data["TCP connections and listening ports"] = [["Local address","Local port","Remote address","Remote port","State"]] + tcp - end - end - - udp = [] - - manager.walk(["1.3.6.1.2.1.7.5.1.1","1.3.6.1.2.1.7.5.1.2"]) do |ladd,lport| - udp.push([ladd.value, lport.value]) - end - - if not udp.empty? - output_data["Listening UDP ports"] = [["Local address","Local port"]] + udp - end - - if (sysDesc =~ /Windows/) - - network_services = [] - - n = 0 - - manager.walk(["1.3.6.1.4.1.77.1.2.3.1.1","1.3.6.1.4.1.77.1.2.3.1.2"]) do |name,installed| - network_services.push([n,name.value]) - n+=1 - end - - if not network_services.empty? - output_data["Network services"] = [["Index","Name"]] + network_services - end - - share = [] - - manager.walk([ - "1.3.6.1.4.1.77.1.2.27.1.1","1.3.6.1.4.1.77.1.2.27.1.2","1.3.6.1.4.1.77.1.2.27.1.3" - ]) do |name,path,comment| - share.push({" Name"=>name.value, " Path"=>path.value, " Comment"=>comment.value}) - end - - if not share.empty? - output_data["Share"] = share - end - - iis = {} - - http_totalBytesSentLowWord = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.2.0') - if http_totalBytesSentLowWord.to_s !~ /Null/ - iis["TotalBytesSentLowWord"] = http_totalBytesSentLowWord - end - - http_totalBytesReceivedLowWord = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.4.0') - if http_totalBytesReceivedLowWord.to_s !~ /Null/ - iis["TotalBytesReceivedLowWord"] = http_totalBytesReceivedLowWord - end - - http_totalFilesSent = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.5.0') - if http_totalFilesSent.to_s !~ /Null/ - iis["TotalFilesSent"] = http_totalFilesSent - end - - http_currentAnonymousUsers = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.6.0') - if http_currentAnonymousUsers.to_s !~ /Null/ - iis["CurrentAnonymousUsers"] = http_currentAnonymousUsers - end - - http_currentNonAnonymousUsers = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.7.0') - if http_currentNonAnonymousUsers.to_s !~ /Null/ - iis["CurrentNonAnonymousUsers"] = http_currentNonAnonymousUsers - end - - http_totalAnonymousUsers = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.8.0') - if http_totalAnonymousUsers.to_s !~ /Null/ - iis["TotalAnonymousUsers"] = http_totalAnonymousUsers - end - - http_totalNonAnonymousUsers = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.9.0') - if http_totalNonAnonymousUsers.to_s !~ /Null/ - iis["TotalNonAnonymousUsers"] = http_totalNonAnonymousUsers - end - - http_maxAnonymousUsers = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.10.0') - if http_maxAnonymousUsers.to_s !~ /Null/ - iis["MaxAnonymousUsers"] = http_maxAnonymousUsers - end - - http_maxNonAnonymousUsers = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.11.0') - if http_maxNonAnonymousUsers.to_s !~ /Null/ - iis["MaxNonAnonymousUsers"] = http_maxNonAnonymousUsers - end - - http_currentConnections = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.12.0') - if http_currentConnections.to_s !~ /Null/ - iis["CurrentConnections"] = http_currentConnections - end - - http_maxConnections = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.13.0') - if http_maxConnections.to_s !~ /Null/ - iis["MaxConnections"] = http_maxConnections - end - - http_connectionAttempts = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.14.0') - if http_connectionAttempts.to_s !~ /Null/ - iis["ConnectionAttempts"] = http_connectionAttempts - end - - http_logonAttempts = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.15.0') - if http_logonAttempts.to_s !~ /Null/ - iis["LogonAttempts"] = http_logonAttempts - end - - http_totalGets = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.16.0') - if http_totalGets.to_s !~ /Null/ - iis["Gets"] = http_totalGets - end - - http_totalPosts = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.17.0') - if http_totalPosts.to_s !~ /Null/ - iis["Posts"] = http_totalPosts - end - - http_totalHeads = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.18.0') - if http_totalHeads.to_s !~ /Null/ - iis["Heads"] = http_totalHeads - end - - http_totalOthers = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.19.0') - if http_totalOthers.to_s !~ /Null/ - iis["Others"] = http_totalOthers - end - - http_totalCGIRequests = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.20.0') - if http_totalCGIRequests.to_s !~ /Null/ - iis["CGIRequests"] = http_totalCGIRequests - end - - http_totalBGIRequests = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.21.0') - if http_totalBGIRequests.to_s !~ /Null/ - iis["BGIRequests"] = http_totalBGIRequests - end - - http_totalNotFoundErrors = manager.get_value('1.3.6.1.4.1.311.1.7.3.1.22.0') - if http_totalNotFoundErrors.to_s !~ /Null/ - iis["NotFoundErrors"] = http_totalNotFoundErrors - end - - if not iis.empty? - output_data["IIS server information"] = iis - end - end - - storage_information = [] - - manager.walk([ - "1.3.6.1.2.1.25.2.3.1.1","1.3.6.1.2.1.25.2.3.1.2","1.3.6.1.2.1.25.2.3.1.3", - "1.3.6.1.2.1.25.2.3.1.4","1.3.6.1.2.1.25.2.3.1.5","1.3.6.1.2.1.25.2.3.1.6" - ]) do |index,type,descr,allocation,size,used| - - case type.value.to_s - when /^1.3.6.1.2.1.25.2.1.1$/ - type.value = "Other" - when /^1.3.6.1.2.1.25.2.1.2$/ - type.value = "Ram" - when /^1.3.6.1.2.1.25.2.1.3$/ - type.value = "Virtual Memory" - when /^1.3.6.1.2.1.25.2.1.4$/ - type.value = "Fixed Disk" - when /^1.3.6.1.2.1.25.2.1.5$/ - type.value = "Removable Disk" - when /^1.3.6.1.2.1.25.2.1.6$/ - type.value = "Floppy Disk" - when /^1.3.6.1.2.1.25.2.1.7$/ - type.value = "Compact Disc" - when /^1.3.6.1.2.1.25.2.1.8$/ - type.value = "RamDisk" - when /^1.3.6.1.2.1.25.2.1.9$/ - type.value = "Flash Memory" - when /^1.3.6.1.2.1.25.2.1.10$/ - type.value = "Network Disk" - else - type.value = "unknown" - end - - allocation.value = "unknown" if allocation.value.to_s =~ /noSuchInstance/ - size.value = "unknown" if size.value.to_s =~ /noSuchInstance/ - used.value = "unknown" if used.value.to_s =~ /noSuchInstance/ - - storage_information.push([[descr.value],[index.value],[type.value],[allocation.value],[size.value],[used.value]]) - end - - if not storage_information.empty? - storage = [] - storage_information.each {|a,b,c,d,e,f| - s = {} - - e = number_to_human_size(e,d) - f = number_to_human_size(f,d) - - s["Description"]= a - s["Device id"] = b - s["Filesystem type"] = c - s["Device unit"] = d - s["Memory size"] = e - s["Memory used"] = f - - storage.push(s) - } - output_data["Storage information"] = storage - end - - file_system = {} - - hrFSIndex = manager.get_value('1.3.6.1.2.1.25.3.8.1.1.1') - if hrFSIndex.to_s !~ /Null/ - file_system["Index"] = hrFSIndex - end - - hrFSMountPoint = manager.get_value('1.3.6.1.2.1.25.3.8.1.2.1') - if hrFSMountPoint.to_s !~ /Null/ - file_system["Mount point"] = hrFSMountPoint - end - - hrFSRemoteMountPoint = manager.get_value('1.3.6.1.2.1.25.3.8.1.3.1') - if hrFSRemoteMountPoint.to_s !~ /Null/ and hrFSRemoteMountPoint.to_s !~ /^noSuch/ - if hrFSRemoteMountPoint.empty? - hrFSRemoteMountPoint = '-' - end - file_system["Remote mount point"] = hrFSRemoteMountPoint - end - - hrFSType = manager.get_value('1.3.6.1.2.1.25.3.8.1.4.1') - - case hrFSType.to_s - when /^1.3.6.1.2.1.25.3.9.1$/ - hrFSType = "Other" - when /^1.3.6.1.2.1.25.3.9.2$/ - hrFSType = "Unknown" - when /^1.3.6.1.2.1.25.3.9.3$/ - hrFSType = "BerkeleyFFS" - when /^1.3.6.1.2.1.25.3.9.4$/ - hrFSType = "Sys5FS" - when /^1.3.6.1.2.1.25.3.9.5$/ - hrFSType = "Fat" - when /^1.3.6.1.2.1.25.3.9.6$/ - hrFSType = "HPFS" - when /^1.3.6.1.2.1.25.3.9.7$/ - hrFSType = "HFS" - when /^1.3.6.1.2.1.25.3.9.8$/ - hrFSType = "MFS" - when /^1.3.6.1.2.1.25.3.9.9$/ - hrFSType = "NTFS" - when /^1.3.6.1.2.1.25.3.9.10$/ - hrFSType = "VNode" - when /^1.3.6.1.2.1.25.3.9.11$/ - hrFSType = "Journaled" - when /^1.3.6.1.2.1.25.3.9.12$/ - hrFSType = "iso9660" - when /^1.3.6.1.2.1.25.3.9.13$/ - hrFSType = "RockRidge" - when /^1.3.6.1.2.1.25.3.9.14$/ - hrFSType = "NFS" - when /^1.3.6.1.2.1.25.3.9.15$/ - hrFSType = "Netware" - when /^1.3.6.1.2.1.25.3.9.16$/ - hrFSType = "AFS" - when /^1.3.6.1.2.1.25.3.9.17$/ - hrFSType = "DFS" - when /^1.3.6.1.2.1.25.3.9.18$/ - hrFSType = "Appleshare" - when /^1.3.6.1.2.1.25.3.9.19$/ - hrFSType = "RFS" - when /^1.3.6.1.2.1.25.3.9.20$/ - hrFSType = "DGCFS" - when /^1.3.6.1.2.1.25.3.9.21$/ - hrFSType = "BFS" - when /^1.3.6.1.2.1.25.3.9.22$/ - hrFSType = "FAT32" - when /^1.3.6.1.2.1.25.3.9.23$/ - hrFSType = "LinuxExt2" - else - hrFSType = "Null" - end - - if hrFSType.to_s !~ /Null/ - file_system["Type"] = hrFSType - end - - hrFSAccess = manager.get_value('1.3.6.1.2.1.25.3.8.1.5.1') - if hrFSAccess.to_s !~ /Null/ - file_system["Access"] = hrFSAccess - end - - hrFSBootable = manager.get_value('1.3.6.1.2.1.25.3.8.1.6.1') - if hrFSBootable.to_s !~ /Null/ - file_system["Bootable"] = hrFSBootable - end - - if not file_system.empty? - output_data["File system information"] = file_system - end - - device_information = [] - - manager.walk([ - "1.3.6.1.2.1.25.3.2.1.1","1.3.6.1.2.1.25.3.2.1.2", - "1.3.6.1.2.1.25.3.2.1.5","1.3.6.1.2.1.25.3.2.1.3" - ]) do |index,type,status,descr| - - case type.value.to_s - when /^1.3.6.1.2.1.25.3.1.1$/ - type.value = "Other" - when /^1.3.6.1.2.1.25.3.1.2$/ - type.value = "Unknown" - when /^1.3.6.1.2.1.25.3.1.3$/ - type.value = "Processor" - when /^1.3.6.1.2.1.25.3.1.4$/ - type.value = "Network" - when /^1.3.6.1.2.1.25.3.1.5$/ - type.value = "Printer" - when /^1.3.6.1.2.1.25.3.1.6$/ - type.value = "Disk Storage" - when /^1.3.6.1.2.1.25.3.1.10$/ - type.value = "Video" - when /^1.3.6.1.2.1.25.3.1.11$/ - type.value = "Audio" - when /^1.3.6.1.2.1.25.3.1.12$/ - type.value = "Coprocessor" - when /^1.3.6.1.2.1.25.3.1.13$/ - type.value = "Keyboard" - when /^1.3.6.1.2.1.25.3.1.14$/ - type.value = "Modem" - when /^1.3.6.1.2.1.25.3.1.15$/ - type.value = "Parallel Port" - when /^1.3.6.1.2.1.25.3.1.16$/ - type.value = "Pointing" - when /^1.3.6.1.2.1.25.3.1.17$/ - type.value = "Serial Port" - when /^1.3.6.1.2.1.25.3.1.18$/ - type.value = "Tape" - when /^1.3.6.1.2.1.25.3.1.19$/ - type.value = "Clock" - when /^1.3.6.1.2.1.25.3.1.20$/ - type.value = "Volatile Memory" - when /^1.3.6.1.2.1.25.3.1.21$/ - type.value = "Non Volatile Memory" - else - type.value = "unknown" - end - - case status.value - when 1 - status.value = "unknown" - when 2 - status.value = "running" - when 3 - status.value = "warning" - when 4 - status.value = "testing" - when 5 - status.value = "down" - else - status.value = "unknown" - end - - descr.value = "unknown" if descr.value.to_s =~ /noSuchInstance/ - - device_information.push([index.value, type.value, status.value, descr.value]) - end - - if not device_information.empty? - output_data["Device information"] = [["Id","Type","Status","Descr"]] + device_information - end - - software_list = [] - - manager.walk(["1.3.6.1.2.1.25.6.3.1.1","1.3.6.1.2.1.25.6.3.1.2"]) do |index,name| - software_list.push([index.value,name.value]) - end - - if not software_list.empty? - output_data["Software components"] = [["Index","Name"]] + software_list - end - - process_interfaces = [] - - manager.walk([ - "1.3.6.1.2.1.25.4.2.1.1","1.3.6.1.2.1.25.4.2.1.2","1.3.6.1.2.1.25.4.2.1.4", - "1.3.6.1.2.1.25.4.2.1.5","1.3.6.1.2.1.25.4.2.1.7" - ]) do |id,name,path,param,status| - - if status.value == 1 - status.value = "running" - elsif status.value == 2 - status.value = "runnable" - else - status.value = "unknown" - end - - process_interfaces.push([id.value, status.value, name.value, path.value, param.value]) - end - - if not process_interfaces.empty? - output_data["Processes"] = [["Id","Status","Name","Path","Parameters"]] + process_interfaces - end - - hp_laserjet_printer_enumeration = [] - - manager.walk([ - "1.3.6.1.4.1.11.2.3.9.4.2.1.1.6.5.1", # job-info-name1 - document name1 - "1.3.6.1.4.1.11.2.3.9.4.2.1.1.6.5.2", # job-info-name2 - document name2 - "1.3.6.1.4.1.11.2.3.9.4.2.1.1.6.5.23.1", # job-info-attr-1 - username - "1.3.6.1.4.1.11.2.3.9.4.2.1.1.6.5.23.2", # job-info-attr-2 - machine name - "1.3.6.1.4.1.11.2.3.9.4.2.1.1.6.5.23.3", # job-info-attr-3 - domain (?) - "1.3.6.1.4.1.11.2.3.9.4.2.1.1.6.5.23.4", # job-info-attr-4 - timestamp - "1.3.6.1.4.1.11.2.3.9.4.2.1.1.6.5.23.6", # job-info-attr-6 - application name - "1.3.6.1.4.1.11.2.3.9.4.2.1.1.6.5.23.7", # job-info-attr-7 - application command - ]) do |name1,name2,username,client,domain,timestamp,app_name,app_command| - - filename = name1.value.to_s + name2.value.to_s - - if (username.value.to_s !~ /noSuchInstance/) - if username.value.to_s =~ /^JobAcct(\d+)=(.*)/ - username = $2 - else - username = '-' - end - else - username = '-' - end - - if (client.value.to_s !~ /noSuchInstance/) - if client.value.to_s =~ /^JobAcct(\d+)=(.*)/ - client = $2 - else - client = '-' - end - else - client = '-' - end - - if (domain.value.to_s !~ /noSuchInstance/) - if domain.value.to_s =~ /^JobAcct(\d+)=(.*)/ - domain = $2 - domain = '-' if domain.empty? - else - domain = '-' - end - else - domain = '-' - end - - if timestamp.value.to_s !~ /noSuchInstance/ - if timestamp.value.to_s =~ /^JobAcct(\d+)=(.*)/ - timestamp = $2 - else - timestamp = '-' - end - else - timestamp = nil - end - - if (app_name.value.to_s !~ /noSuchInstance/) - if app_name.value.to_s =~ /^JobAcct(\d+)=(.*)/ - app_name = $2 - end - else - app_name = '-' - end - - if (app_command.value.to_s !~ /noSuchInstance/) - if app_command.value.to_s =~ /^JobAcct(\d+)=(.*)/ - app_command = $2 - end - else - app_command = '-' - end - - if not timestamp.nil? - hp_laserjet_printer_enumeration.push({ - "Filename" => filename + "#{filename.length}", - "Username" => username, - "Client" => client, - "Timestamp" => timestamp, - "Domain" => domain, - "Application name" => app_name, - "Application command" => app_command - }) - end - end - - if not hp_laserjet_printer_enumeration.empty? - output_data["HP LaserJet printer enumeration"] = hp_laserjet_printer_enumeration - end - - print_things("System information:","result") - puts - - line = "" - width = 30 # name field width - twidth = 32 # table like display cell width - - fields_order.each {|k| - if not output_data.has_key?(k) - next - end - - v = output_data[k] - - case v - when Array - content = "" - - v.each{ |a| - case a - when Hash - a.each{ |sk, sv| - sk = truncate_to_twidth(sk, twidth) - content << sprintf(" %s%s: %s\n", sk, " "*([0,width-sk.length].max), sv) - } - content << "\n" - when Array - a.each { |sv| - sv = sv.to_s.strip - content << sprintf(" %-20s", sv) - } - content << "\n" - else - content << sprintf(" %s\n", a) - content << "\n" - end - } - - line << "\n[*] #{k}:\n\n#{content}" - - when Hash - content = "" - v.each{ |sk, sv| - sk = truncate_to_twidth(sk,twidth) - content << sprintf(" %s%s: %s\n", sk, " "*([0,width-sk.length].max), sv) - } - - line << "\n[*] #{k}:\n\n#{content}" - content << "\n" - else - if (v.nil? or v.empty? or v =~ /Null/) - v = '-' - end - - k = truncate_to_twidth(k,twidth) - line << sprintf(" %s%s: %s\n", k, " "*([0,width-k.length].max), v) - end - } - - puts(line) - - end - - puts - - rescue SNMP::RequestTimeout - print_things("#{target}:#{port} SNMP request timeout","error") - rescue SNMP::ConnectionError - print_things("#{target}:#{port} Connection refused","error") - rescue SNMP::InvalidIpAddress - print_things("#{target}:#{port} Invalid IP Address. Check it with 'snmpwalk tool'","error") - rescue SNMP::UnsupportedVersion - print_things("#{target}:#{port} Unsupported SNMP version specified. Select from '1' or '2c'","error") - rescue ::Interrupt - raise $! - rescue ::Exception => e - print_things("Unknown error: #{e.class} #{e}","error") - print_things("Call stack:\n#{e.backtrace.join "\n"}","error") -end diff --git a/snmpcheck.spec b/snmpcheck.spec index 768378c..9861a03 100644 --- a/snmpcheck.spec +++ b/snmpcheck.spec @@ -1,18 +1,18 @@ Name: snmpcheck -Version: 1.9 -Release: 21%{?dist} +Version: 1.8 +Release: 6%{?dist} Summary: An utility to get information via SNMP protocols -# Automatically converted from old format: GPLv3+ - review is highly recommended. -License: GPL-3.0-or-later -URL: https://www.nothink.org/codes/snmpcheck/ -Source0: https://www.nothink.org/codes/snmpcheck/%{name}-%{version}.rb +Group: Applications/Internet +License: GPLv3+ +URL: http://www.nothink.org/perl/snmpcheck/ +Source0: http://www.nothink.org/perl/snmpcheck/downloads/%{name}-%{version}.pl #Manual page Source1: snmpcheck.1 +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch -Requires: ruby(release) -Requires: rubygem(snmp) +Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version)) %description @@ -56,100 +56,17 @@ install -d %{buildroot}%{_mandir}/man1 install -p -m 0644 %{SOURCE1} %{buildroot}%{_mandir}/man1/%{name}.1 +%clean +rm -rf %{buildroot} + %files +%defattr(-,root,root,-) %{_bindir}/%{name} %{_mandir}/man1/%{name}.1.* %changelog -* Fri Jul 25 2025 Fedora Release Engineering - 1.9-21 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_43_Mass_Rebuild - -* Sun Jan 19 2025 Fedora Release Engineering - 1.9-20 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild - -* Thu Jul 25 2024 Miroslav Suchý - 1.9-19 -- convert license to SPDX - -* Sat Jul 20 2024 Fedora Release Engineering - 1.9-18 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild - -* Sat Jan 27 2024 Fedora Release Engineering - 1.9-17 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild - -* Sat Jul 22 2023 Fedora Release Engineering - 1.9-16 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild - -* Sat Jan 21 2023 Fedora Release Engineering - 1.9-15 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild - -* Sat Jul 23 2022 Fedora Release Engineering - 1.9-14 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild - -* Sat Jan 22 2022 Fedora Release Engineering - 1.9-13 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild - -* Fri Jul 23 2021 Fedora Release Engineering - 1.9-12 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild - -* Wed Jan 27 2021 Fedora Release Engineering - 1.9-11 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild - -* Wed Jul 29 2020 Fedora Release Engineering - 1.9-10 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild - -* Thu Jan 30 2020 Fedora Release Engineering - 1.9-9 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild - -* Fri Jul 26 2019 Fedora Release Engineering - 1.9-8 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild - -* Sun Feb 03 2019 Fedora Release Engineering - 1.9-7 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild - -* Sat Jul 14 2018 Fedora Release Engineering - 1.9-6 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild - -* Fri Feb 09 2018 Fedora Release Engineering - 1.9-5 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild - -* Thu Jul 27 2017 Fedora Release Engineering - 1.9-4 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild - -* Sat Feb 11 2017 Fedora Release Engineering - 1.9-3 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild - -* Sun May 15 2016 Jitka Plesnikova - 1.9-2 -- Perl 5.24 rebuild - -* Fri Apr 29 2016 Michal Ambroz - 1.9-1 -- bump to version 1.9 - -* Fri Feb 05 2016 Fedora Release Engineering - 1.8-14 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild - -* Fri Jun 19 2015 Fedora Release Engineering - 1.8-13 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild - -* Wed Jun 03 2015 Jitka Plesnikova - 1.8-12 -- Perl 5.22 rebuild - -* Wed Aug 27 2014 Jitka Plesnikova - 1.8-11 -- Perl 5.20 rebuild - -* Sun Jun 08 2014 Fedora Release Engineering - 1.8-10 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild - -* Sun Aug 04 2013 Fedora Release Engineering - 1.8-9 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild - -* Wed Jul 17 2013 Petr Pisar - 1.8-8 -- Perl 5.18 rebuild - -* Fri Feb 15 2013 Fedora Release Engineering - 1.8-7 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild - * Sat Jul 21 2012 Fedora Release Engineering - 1.8-6 - Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild