From 9455c6e0d0b37e5ebc3c67b2dee17b9fc56285c8 Mon Sep 17 00:00:00 2001 From: Roy Date: Thu, 30 Mar 2023 00:44:26 +0200 Subject: [PATCH] Update 256^4 loops en wat probeer wat uit met eval blocks. --- senicup.pl | 92 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/senicup.pl b/senicup.pl index ddefdeb..5b15120 100755 --- a/senicup.pl +++ b/senicup.pl @@ -9,14 +9,14 @@ use Net::DNS; use Selenium::Firefox; use Selenium::Firefox::Profile; -my ($continue_from, $ii1, $ii2, $ii3, $initvar); +#eval { +my ($continue_from, $ii1, $ii2, $ii3, $ii4, $iii1, $iii2, $iii3, $initvar); if ($ARGV[0]) { chomp($continue_from = $ARGV[0]); if ($continue_from !~ m/^[0-9]+([.][0-9]+){3}$/) {die $!, "\"$continue_from\" is not a valid ipv4 address:" -} else {($ii1, $ii2, $ii3) = split /\./, $continue_from; print 'Continuing from ipv4 address ', $continue_from, "\n"}} else {print "\n\n"; foreach (0..4) {print 'Starting a new tcp/udp 80/443 ipv4 scan in ', (5-${_}), "s.\n"; sleep 1}; print 'Starting...', "\n"} -my $ii = 0; +} else {($ii1, $ii2, $ii3, $ii4) = split /\./, $continue_from; print 'Continuing from ipv4 address ', $continue_from, "\n"}} else {print "\n\n"; foreach (0..4) {print 'Starting a new tcp/udp 80/443 ipv4 scan in ', (5-${_}), "s.\n"; sleep 1}; print 'Starting...', "\n"} my (%args, %args2, %hoa, @host); -$args2{'profile_dir'} = '/home/miami/.Mozilla3/Firefox/ud8j40yn.default'; # Ghacks user.js is a good start. +$args2{'profile_dir'} = '/home/miami/.Mozilla3/Firefox/ud8j40yn.default/'; # Ghacks user.js is a good start. my $profile = Selenium::Firefox::Profile->new(%args2); my $driver = Selenium::Firefox->new('firefox_profile' => $profile); $driver->set_timeout('script', 10000); @@ -27,22 +27,23 @@ sub connectivity_check { my $flag = 0; my $exp = 0; chomp(my $connectivity = `ip a | grep -A 2 -Ei '^[0-9]+: wl[^:]+:' | grep -E '\\s+?inet\\b' | sed -E 's/^\\s+?inet\\s+?([^/]+).*\$/\\1/'`); # Will do for now. +#if (eval open my $TMP_FH, '<', (glob '/sys/class/net/wl*/carrier')[0] and $connectivity =~ m/^[0-9]+([.][0-9]+){3}$/) {if (<$TMP_FH> == 1) {return 5}}; while (1) {eval open my $TMP_FH, '<', (glob '/sys/class/net/wl*/carrier')[0]; unless ($connectivity =~ m/^[0-9]+([.][0-9]+){3}$/ and <$TMP_FH> == 1) {warn "$!: No wireless connectivity on (lexicographically) first wireless network."; $flag = 1; sleep 2**$exp; $exp++; chomp($connectivity = `ip a | grep -A 2 -Ei '^[0-9]+: wl[^:]+:' | grep -E '\\s+?inet\\b' | sed -E 's/^\\s+?inet\\s+?([^/]+).*\$/\\1/'`); if ($exp >= 10) {$exp -= int(rand(11))}; next}; if ($flag == 1) { if (defined($_[1])) {unlink "$_[1]"; $_[1] =~ s,/[^/]+$,,; unlink "$_[1]/title.txt"; rmdir "$_[1]/"} # Delete potentially incomplete items from the last ipv4 address/domain, for unskipping. -if (defined($_[0])) { # If true, assume everything in $i4 failed before detection of the connectivity issue (i.e., redo /24). +if (defined($_[0])) { # If true, assume everything in $i1 failed before detection of the connectivity issue (i.e., redo /24). my $alpha = time; splice @host, 0, $#host; undef %hoa; $args{'port'} = '80'; $args{'proto'} = 'tcp'; $p->port_number($args{'port'}); &connectivity_check; -foreach my $i4 (0..254) { -$args{'host'} = $_[0].'.'.$i4; +foreach my $i1 (1..9,11..126,128..254) { +$args{'host'} = $i1.'.'.$_[0]; $p->ping($args{'host'}); -$host[$i4] = $args{'host'}; +$host[$i1] = $args{'host'}; } -while (my ($host) = $p->ack) {push @{$hoa{'80'}}, $host; $host =~ s/^[0-9.]+[.]//; splice @host, $host} +while (my ($host) = $p->ack) {push @{$hoa{'80'}}, $host; $host =~ s/[.][0-9.]+$//; splice @host, $host} &syn_ping_elmn(80, 'udp'); &syn_ping_elmn(443, 'udp'); @@ -56,7 +57,7 @@ foreach my $host (@{$hoa{'80'}}) { my @rray = &reverse_dns_doms($host); if ($#rray == 0 and $rray[0] eq '') {&double_80_screenshot($host, $_[0])} else { foreach (@rray) {if (-d "./data/$_/view-source:http:/$_/" or -d "./data/$_/view-source:https:/$_/") {print $FILEH_A "\n"; next}; - sleep rand(1)/10; + sleep rand(1)/(rand(10)+1); print $FILEH_A $_.','; &double_80_screenshot($_, $_[0])} print $FILEH_A "\n"} print $FILEH_A "\n"} @@ -67,20 +68,18 @@ foreach my $host (@{$hoa{'443'}}) { my @rray = &reverse_dns_doms($host); if ($#rray == 0 and $rray[0] eq '') {&double_443_screenshot($host, $_[0])} else { foreach (@rray) {if (-d "./data/$_/view-source:http:/$_/" or -d "./data/$_/view-source:https:/$_/") {print $FILEH_A "\n"; next}; - sleep rand(1)/10; + sleep rand(1)/(rand(10)+1); print $FILEH_A $_.','; &double_443_screenshot($_, $_[0])} print $FILEH_A "\n"} print $FILEH_A "\n"} &connectivity_check($_[0]); # TODO: Potential infinite recursion on __very__ unstable networks with parameter? my $beta = time; my $delta = $beta-$alpha; -my $gamma = $delta*255**3-255*$ii; -while (0 > $gamma) {$alpha = time; &connectivity_check($_[0]); $beta = time; $delta = $beta-$alpha; $gamma = $delta*255**3-255*$ii;} -$ii++; print 'Progress: ', 0.00000603*$ii, "%\n", 'ETA: ', $gamma, "s\n"; +while (3 > $delta) {print "$delta < 3. Retrying.\n"; $alpha = time; my $returni = &connectivity_check($_[0]); $beta = time; last if $returni == 5} close $FILEH_A; -print "\n", 'To continue after quitting, provide', $_[0].'.0', 'as first argument.', "\n"; }} last} +return 5; } sub double_80_screenshot { @@ -174,9 +173,8 @@ my (@obj); my $res = Net::DNS::Resolver->new; my $reply = $res->search("$_[0]", "PTR"); if ($reply) { -foreach my $rr ($reply->answer) { -print $rr->ptrdname, ' <--- This shouldn', "'", 't happen.', "\n" if $rr->ptrdname !~ m/^[a-z0-9.-]+$/; -eval {push @obj, $rr->ptrdname}; # Looped over a CNAME for 1.9.30.40? +foreach my $rr (grep { $_->type eq "PTR" } $reply->answer) { # Do not assume rr-objects are of the same type as requested. +eval {push @obj, $rr->ptrdname}; } } return @obj; @@ -186,33 +184,36 @@ sub syn_ping_elmn { $p->port_number($_[0]); foreach my $host (@host) { next unless defined($host); -(my $check = $host) =~ s/[.][0-9]+$//; +(my $check = $host) =~ s/^[0-9]+[.]//; &connectivity_check($check); last} foreach my $host (@host) { -#next unless defined($host); +next unless defined($host); $args{'host'} = $host; $p->ping($args{'host'}); -$host =~ s/^[0-9.]+[.]//; +$host =~ s/[.][0-9.]+$//; $host[$host] = $args{'host'}; } -while (my ($host) = $p->ack) {push @{$hoa{$_[0]}}, $host; $host =~ s/^[0-9.]+[.]//; splice @host, $host} +while (my ($host) = $p->ack) {push @{$hoa{$_[0]}}, $host; $host =~ s/[.][0-9.]+$//; splice @host, $host} } $initvar=1; -unless (defined($continue_from)) {($ii1, $ii2, $ii3) = (1, 0, 0)} -LABEL1: foreach my $i1 (1..9,11..126,128..254) { # Skip large private blocks. +unless (defined($continue_from)) {($ii1, $ii2, $ii3, $ii4) = (1, 0, 0, 0)} +LABEL4: foreach my $i4 (0..254) { if ($initvar == 1) { -until ($i1 >= $ii1) {next LABEL1} +until ($i4 >= $ii4) {next LABEL4} } -LABEL2: foreach my $i2 (0..254) { +LABEL3: foreach my $i3 (0..254) { if ($initvar == 1) { -until (int($i1*255**3+$i2*255**2) >= int($ii1*255**3+$ii2*255**2)) {next LABEL2} +until (int($i4*255**3+$i3*255**2) >= int($ii4*255**3+$ii3*255**2)) {next LABEL3} } -LABEL3: foreach my $i3 (0..254) { +LABEL2: foreach my $i2 (0..254) { if ($initvar == 1) { -until (int($i1*255**3+$i2*255**2+$i3*255) >= int($ii1*255**3+$ii2*255**2+$ii3*255)) {next LABEL3} +until (int($i4*255**3+$i3*255**2+$i2*255) >= int($ii4*255**3+$ii3*255**2+$ii2*255)) {next LABEL2} } +if ($initvar == 1) { +if ($ii1 > 127) {$iii1 = 1; $iii2 = 11; $iii3 = $ii1} elsif ($ii1 > 10) {$iii1 = 1; $iii2 = $ii1; $iii3 = 128} elsif ($ii1 > 0) {$iii1 = $ii1; $iii2 = 11; $iii3 = 128} +} else {$iii1 = 1; $iii2 = 11; $iii3 = 128} $initvar=0; my $alpha = time; splice @host, 0, $#host; @@ -220,12 +221,12 @@ undef %hoa; $args{'port'} = '80'; $args{'proto'} = 'tcp'; $p->port_number($args{'port'}); &connectivity_check; -foreach my $i4 (0..254) { +foreach my $i1 ($iii1..9,$iii2..126,$iii3..254) { # Skip large private blocks. $args{'host'} = $i1.'.'.$i2.'.'.$i3.'.'.$i4; $p->ping($args{'host'}); -$host[$i4] = $args{'host'}; +$host[$i1] = $args{'host'}; } -while (my ($host) = $p->ack) {push @{$hoa{'80'}}, $host; $host =~ s/^[0-9.]+[.]//; splice @host, $host} +while (my ($host) = $p->ack) {push @{$hoa{'80'}}, $host; $host =~ s/[.][0-9.]+$//; splice @host, $host} &syn_ping_elmn(80, 'udp'); &syn_ping_elmn(443, 'udp'); @@ -234,36 +235,37 @@ while (my ($host) = $p->ack) {push @{$hoa{'80'}}, $host; $host =~ s/^[0-9.]+[.]/ open my $FILEH_A, '>>', "./data/domains.txt"; # Here, we'll store all the domains from the ipv4 addresses. foreach my $host (@{$hoa{'80'}}) { next unless defined($host); - &connectivity_check($i1.'.'.$i2.'.'.$i3); + &connectivity_check($i2.'.'.$i3.'.'.$i4); print $FILEH_A $host.':80'."\n"; my @rray = &reverse_dns_doms($host); - if ($#rray == 0 and $rray[0] eq '') {&double_80_screenshot($host, $i1.'.'.$i2.'.'.$i3)} else { + if ($#rray == 0 and $rray[0] eq '') {&double_80_screenshot($host, $i2.'.'.$i3.'.'.$i4)} else { foreach (@rray) {if (-d "./data/$_/view-source:http:/$_/" or -d "./data/$_/view-source:https:/$_/") {print $FILEH_A "\n"; next}; - sleep rand(1)/10; - print $FILEH_A $_.','; &double_80_screenshot($_, $i1.'.'.$i2.'.'.$i3)} + sleep rand(1)/(rand(10)+1); + print $FILEH_A $_.','; &double_80_screenshot($_, $i2.'.'.$i3.'.'.$i4)} print $FILEH_A "\n"} print $FILEH_A "\n"} foreach my $host (@{$hoa{'443'}}) { next unless defined($host); - &connectivity_check($i1.'.'.$i2.'.'.$i3); + &connectivity_check($i2.'.'.$i3.'.'.$i4); print $FILEH_A $host.':443'."\n"; my @rray = &reverse_dns_doms($host); - if ($#rray == 0 and $rray[0] eq '') {&double_443_screenshot($host, $i1.'.'.$i2.'.'.$i3)} else { + if ($#rray == 0 and $rray[0] eq '') {&double_443_screenshot($host, $i2.'.'.$i3.'.'.$i4)} else { foreach (@rray) {if (-d "./data/$_/view-source:http:/$_/" or -d "./data/$_/view-source:https:/$_/") {print $FILEH_A "\n"; next}; - sleep rand(1)/10; - print $FILEH_A $_.','; &double_443_screenshot($_, $i1.'.'.$i2.'.'.$i3)} + sleep rand(1)/(rand(10)+1); + print $FILEH_A $_.','; &double_443_screenshot($_, $i2.'.'.$i3.'.'.$i4)} print $FILEH_A "\n"} print $FILEH_A "\n"} -&connectivity_check($i1.'.'.$i2.'.'.$i3); +&connectivity_check($i2.'.'.$i3.'.'.$i4); my $beta = time; my $delta = $beta-$alpha; -my $gamma = $delta*255**3-255*$ii; -while (0 > $gamma) {print $gamma, ' ETA shouldn', "'", 't be negative. Retrying from ', $i1.'.'.$i2.'.'.$i3.'.'.0; $alpha = time; &connectivity_check($_[0]); $beta = time; $delta = $beta-$alpha; $gamma = $delta*255**3-255*$ii;} -$ii++; print 'Progress: ', 0.00000603*$ii, "%\n", 'ETA: ', $gamma, "s\n"; +my $gamma = $i4*255**2+$i3*255**1+$i2; +while (3 > $delta) {print "$delta < 3. Retrying.\n"; $alpha = time; my $returni = &connectivity_check($i2.'.'.$i3.'.'.$i4); $beta = time; last if $returni == 5} +print 'Progress: ', $gamma/255**3*100, "%\n", 'ETA: ', (255**3-$gamma)*$delta, "s\n"; close $FILEH_A; -print "\n", 'To continue after quitting, provide ', $i1.'.'.$i2.'.'.$i3.'.'.'0', ' as first argument.', "\n\n"; +print "\n", 'To continue after quitting, provide ', '1.'.$i2.'.'.$i3.'.'.$i4, ' as first argument.', "\n\n"; }}} print 'Cleaning up...'."\n"; $driver->quit(); `killall geckodriver` and print 'Done!'."\n"; +#}