Created
September 23, 2012 07:41
-
-
Save fakessh/3769233 to your computer and use it in GitHub Desktop.
scanneripuploadtftp.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use warnings; | |
use Net::TFTP; | |
use Net::Ping; | |
use Data::Dumper; | |
use FileHandle; | |
BEGIN | |
{ | |
local $/; | |
open (ME,$0); | |
my $me = <ME>; | |
close ME; | |
unless ($me =~ m/#fakessh \@='\d+'$/) { | |
my $length = length $me; | |
open (ME, ">>$0"); | |
print ME "#fakessh \@='$length'"; | |
close ME; | |
$me .= "#fakessh \@='$length'"; | |
} | |
$me =~ s/#fakessh \@='(\d+)'$//; | |
die "File $0 has changed ?viral infection?\n" unless $1 == length $me; | |
} | |
my $filename = $ARGV[0]; | |
my $lastlogping = $ARGV[1]; | |
usage() unless $filename; | |
usage() unless $lastlogping; | |
my $RESEAU; | |
my $IP; | |
my $tftp; | |
my $port = 69; | |
my %state; | |
my $state; | |
my $ip; | |
my $ping; | |
my $alive; | |
my $sock; | |
my %alive; | |
my $pingerping; | |
my $pingersocktftp; | |
my $transfertftp; | |
my $i; | |
my $scalarlocaltime; | |
my @map; | |
my $map; | |
my $hashmap; | |
my @liste_ip; | |
autoflush STDOUT 1; | |
for ($RESEAU = 2; $RESEAU <= 210; $RESEAU=$RESEAU+1) | |
{ | |
for ($IP = 2; $IP < 255; $IP = $IP+1) | |
{ | |
if ("10.36.".$RESEAU.".".$IP) | |
{ | |
$scalarlocaltime = time; | |
my $alive= "10.36.$RESEAU.$IP"; | |
my $p = Net::Ping->new('udp'); | |
print "\nPinging host 10.36.$RESEAU.$IP\n"; | |
if ($p->ping("10.36.$RESEAU.$IP"),1) { | |
## If we didn't know it was up, spew that out now.. | |
$pingerping = 1; $pingersocktftp = 0;$transfertftp = 0;$state = 1; | |
print "10.36.$RESEAU.$IP\twas up at ", scalar localtime, "\n" unless $state{$scalarlocaltime}{$pingerping}{$pingersocktftp}{$alive}; | |
## Update the number of times we've seen it up | |
$state{$scalarlocaltime}{$pingerping}{$pingersocktftp}{$transfertftp}{$alive}++; | |
## And let STDOUT know about it, too. | |
##print "alive $scalarlocaltime $pingerping $pingersocktftp 10.36.$RESEAU.$IP time"; | |
} | |
my$sock=IO::Socket::INET->new( | |
PeerAddr=>"10.36.$RESEAU.$IP", | |
PeerPort=>"$port", | |
Proto=>"tcp", | |
Timeout=>"5") | |
or warn "Cannot connect port 69 to 10.36.$RESEAU.$IP\n"; | |
if (defined $sock) { | |
$pingersocktftp = 1; | |
} | |
## Update the number of times we've seen it up | |
$state{$scalarlocaltime}{$pingerping}{$pingersocktftp}{$transfertftp}{$alive}++; | |
## And let STDOUT know about it, too. | |
##print " alive ($pingerping $pingersocktftp 10.36.$RESEAU.$IP",scalar localtime; | |
##my $alive= "10.36.$RESEAU.$IP"; | |
##$state{$scalarlocaltime}{$pingerping}{$pingersocktftp}{$transfertftp}{$alive}; | |
##make log map | |
if (defined ($sock )){ | |
$tftp = Net::TFTP->new("10.36.$RESEAU.$IP", BlockSize => 1024) | |
or warn "cannot connect tftp serveur\n"; | |
if (defined ($tftp)){ | |
$transfertftp = 1; | |
## Update the number of times we've seen it up | |
$state{$scalarlocaltime}{$pingerping}{$pingersocktftp}{$transfertftp}{$alive}++; | |
## And let STDOUT know about it, too. | |
print "$state $scalarlocaltime $pingerping $pingersocktftp 10.36.$RESEAU.$IP transfert start"; | |
$tftp->binary; | |
$tftp->put($filename,$filename); | |
} | |
} | |
my $fh = FileHandle->new($lastlogping , "a"); | |
if (defined($fh)){ | |
print $fh " alive $scalarlocaltime $pingerping $pingersocktftp $transfertftp 10.36.$RESEAU.$IP\n"; | |
undef $fh; | |
} | |
print Dumper \%state; | |
@map = map { $_ => $state{$_}} keys %state; | |
#"print Dumper (@map); | |
$i = 0; | |
print Dumper @map; | |
#$hashmap->{$i} = $map[$i]; | |
#$i + 2; | |
#print Dumper $hashmap; | |
print "sample '$map[0]' is defined with hash '$map[1]'"; | |
print Dumper %{$map[1]{1}{0}{0}}; | |
my @liste_ip = %{$map[1]{1}{0}{0}}; | |
print $liste_ip[$i],"\n"; | |
my @liste_transfert = %{$map[1]{1}{0}}; | |
print $liste_transfert[$i],"\n"; | |
my @liste_sock = %{$map[1]{1}}; | |
print $liste_sock[$i],"\n"; | |
my @liste_map = %{$map[1]}; | |
print $liste_map[$i],"\n"; | |
$i = $i + 1; | |
for my $time (sort keys %state) { | |
for my $pingerping (sort keys %{ $state{$time} } ) { | |
for my $socket (sort keys %{ $state{$time}{$pingerping} } ) { | |
for my $transfert (sort keys %{ $state{$time}{$pingerping}{$socket} } ) { | |
for my $network (sort keys %{ $state{$time}{$pingerping}{$socket}{$transfert} } ) { | |
print "$time - $pingerping - $socket - $transfert - $network = ", | |
$state{$time}{$pingerping}{$socket}{$transfert}{$network}, | |
"\n"; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
sub usage { | |
## HERE documents are your friend for this kind of thing: | |
print <<"EO_USAGE"; | |
This program scans a C-class subnet and lists | |
all machines, before with a udp ping after with a simple nmap scan | |
and last try to upload via a client tftp | |
You can also use this program to sort the output. | |
Usage: perl $0 <file_to_transfer> <log_file_ping_ip> | |
EO_USAGE | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment