#!/usr/local/groundwork/perl/bin/perl -- #!/usr/local/groundwork/perl/bin/perl -w -- # FIX THIS: put back the perl -w flag once we get a clean copy of # /usr/local/groundwork/perl/lib/site_perl/5.8.8/Nmap/Scanner/Host.pm # that doesn't generate warnings ############################################################################ # Release 3.3 # July 2010 ############################################################################ # # Original author: Scott Parris # # Copyright (C) 2007-2010 Groundwork Open Source, Inc. (GroundWork) # All rights reserved. This program is free software; you can redistribute # it and/or modify it under the terms of the GNU General Public License # version 2 as published by the Free Software Foundation. # # 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, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # use strict; use Nmap::Scanner; # Become a process group leader, so we can easily terminate all of our descendants. setpgrp(0,0); sub kill_process_group { kill 'TERM', -$$; } sub terminate { exit 15; } # The SIGHUP processing mirrors what the system should be doing should we # end up as an orphaned process group -- effectively, trying to terminate # the entire group, so it doesn't outlast the process that spawned us. # But this lets us do the same thing in a simple manner even when the # process group has not yet been orphaned. # Doing the same with SIGCONT is an abuse of the signal, but we use it # because it's the only signal we can send from our parent process, # given that we will be running setuid. $SIG{HUP} = \&kill_process_group; $SIG{CONT} = \&kill_process_group; $SIG{TERM} = \&terminate; $ENV{'PATH'} = $ENV{'PATH'}.':/usr/local/groundwork/common/bin'; if ( scalar @ARGV != 1 ) { print "usage: $0 {IP address or scan specification}\n"; exit 1; } my $args = $ARGV[0]; if ($args =~ /^\d+\.\d+\.\d+\.\d+$/) { my $scanner = new Nmap::Scanner; $scanner->tcp_syn_scan(); $scanner->add_scan_port('21,25,80,443,3306,8080,22,79,13,11,7,10'); $scanner->guess_os(); $scanner->add_target($args); $scanner->max_rtt_timeout(200); my $results = $scanner->scan(); my $data = $results->as_xml(); print $data; } else { # args = host:-:scan_type:-:timeout:-:ports my @args = split(/:-:/, $args); my $scanner = new Nmap::Scanner; if ($args[1] eq 'udp_scan') { $scanner->udp_scan(); } elsif ($args[1] eq 'tcp_connect_scan') { $scanner->tcp_connect_scan(); } else { $scanner->tcp_syn_scan(); } if ($args[2] eq 'Insane') { $scanner->insane_timing(); } elsif ($args[2] eq 'Sneaky') { $scanner->sneaky_timing(); } elsif ($args[2] eq 'Paranoid') { $scanner->paranoid_timing(); } elsif ($args[2] eq 'Polite') { $scanner->polite_timing(); } elsif ($args[2] eq 'Aggressive') { $scanner->aggressive_timing(); } else { $scanner->normal_timing(); } $scanner->add_scan_port($args[3]); $scanner->guess_os(); $scanner->add_target($args[0]); my $results = $scanner->scan(); my $data = $results->as_xml(); print $data; }