From af93ecb85b86fea7cb1eb762f84d58c293da6c75 Mon Sep 17 00:00:00 2001 From: Roy Date: Thu, 30 Mar 2023 00:45:41 +0200 Subject: [PATCH] Kijk wat LWP::UserAgent mij kan bieden. --- senicup.pl | 148 +++++++++++++++++++++-------------------------------- 1 file changed, 59 insertions(+), 89 deletions(-) diff --git a/senicup.pl b/senicup.pl index 5b15120..55dae33 100755 --- a/senicup.pl +++ b/senicup.pl @@ -8,82 +8,44 @@ use Net::Ping; use Net::DNS; use Selenium::Firefox; use Selenium::Firefox::Profile; +#use LWP::UserAgent; -#eval { -my ($continue_from, $ii1, $ii2, $ii3, $ii4, $iii1, $iii2, $iii3, $initvar); +my ($continue_from, $ii1, $ii2, $ii3, $ii4, $iii1, $iii2, $iii3, $initvar, $alpha, $beta, $delta, $gamma, $retry_i); 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, $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. -my $profile = Selenium::Firefox::Profile->new(%args2); +# Ghacks user.js is a good start. +my $profile = Selenium::Firefox::Profile->new(profile_dir => '/home/miami/.Mozilla3/Firefox/ud8j40yn.default/'); +#$profile->new('/home/miami/.Mozilla3/Firefox/ud8j40yn.default/'); +#foreach (%{%$profile{'user_prefs'}}) {print $_, "\n"} +#exit; +#my $ua = LWP::UserAgent->new(agent => 'ojffkfldnnnnsdvf'); my $driver = Selenium::Firefox->new('firefox_profile' => $profile); +$driver->debug_on; $driver->set_timeout('script', 10000); $driver->set_timeout('implicit', 20000); $driver->set_timeout('page load', 15000); my $p = Net::Ping->new("syn", 3); +$driver->set_user_agent('efjnvgjkdnl'); #window.navigator.userAgent +$driver->get("https://xn--eekf.net"); +#eval {print $driver->get_current_url()} or print "hereitis: https://i.redd.it/2nynaq6qwcb91.jpg\n"; +#print $driver->screenshot({'full' => 1}); +#print $driver->get_page_source(); +print $driver->get_user_agent(); +exit; 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 $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 $i1 (1..9,11..126,128..254) { -$args{'host'} = $i1.'.'.$_[0]; -$p->ping($args{'host'}); -$host[$i1] = $args{'host'}; +eval open my $TMP_FH, '<', (glob '/sys/class/net/wl*/carrier')[0]; +unless ($connectivity =~ m/^[0-9]+([.][0-9]+){3}$/ and <$TMP_FH> == 1) { +$retry_i = 1; +if (defined($_[0])) {unlink "$_[0]"; $_[0] =~ s,/[^/]+$,,; unlink "$_[0]/title.txt"; rmdir "$_[0]/"} # Delete potentially incomplete items from the last ipv4 address/domain, for redoing. } -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'); -&syn_ping_elmn(443, 'tcp'); - -open my $FILEH_A, '>>', "./data/domains.txt"; # Here, we'll store all the domains from all ipv4 addresses. -foreach my $host (@{$hoa{'80'}}) { - next unless defined($host); - &connectivity_check($_[0]); - print $FILEH_A $host.':80'."\n"; - 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)/(rand(10)+1); - print $FILEH_A $_.','; &double_80_screenshot($_, $_[0])} - print $FILEH_A "\n"} - print $FILEH_A "\n"} -foreach my $host (@{$hoa{'443'}}) { - next unless defined($host); - &connectivity_check($_[0]); - print $FILEH_A $host.':443'."\n"; - 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)/(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; -while (3 > $delta) {print "$delta < 3. Retrying.\n"; $alpha = time; my $returni = &connectivity_check($_[0]); $beta = time; last if $returni == 5} -close $FILEH_A; -}} -last} -return 5; } sub double_80_screenshot { -if ($#_ > 1) {die "$!: Too much arguments: \"$_[1]\"...\"$_[$#_]\"."} +if ($#_ > 0) {die "$!: Too much arguments: \"$_[0]\"...\"$_[$#_]\"."} &connectivity_check; my $time_in_s = time; eval {$driver->get("http://$_[0]")}; # Fetch the eye-candy. @@ -97,13 +59,13 @@ open my $FILEH_B, '>', "./data/$_[0]/$current_url/screenshot-$time_in_s.png.base open my $FILEH_C, '>', "./data/$_[0]/$current_url/title.txt"; eval {print $FILEH_B $driver->screenshot({'full' => 1})}; print $FILEH_C $driver->get_title(); -&connectivity_check($_[1], "./data/$_[0]/$current_url/screenshot-$time_in_s.png.base64"); +&connectivity_check("./data/$_[0]/$current_url/screenshot-$time_in_s.png.base64"); } else {eval {make_path("./data/$_[0]/-/")}; open my $FILEH_B, '>', "./data/$_[0]/-/screenshot-$time_in_s.png.base64"; open my $FILEH_C, '>', "./data/$_[0]/-/title.txt"; eval {print $FILEH_B $driver->screenshot({'full' => 1})}; print $FILEH_C $driver->get_title(); -&connectivity_check($_[1], "./data/$_[0]/-/screenshot-$time_in_s.png.base64"); +&connectivity_check("./data/$_[0]/-/screenshot-$time_in_s.png.base64"); } $time_in_s = time; eval {$driver->get("view-source:http://$_[0]")}; # Fetch the page source for (partly) reproduction. @@ -115,18 +77,18 @@ open my $FILEH_B, '>', "./data/$_[0]/$current_url/screenshot-$time_in_s.png.base open my $FILEH_C, '>', "./data/$_[0]/$current_url/title.txt"; eval {print $FILEH_B $driver->screenshot({'full' => 1})}; print $FILEH_C $driver->get_title(); -&connectivity_check($_[1], "./data/$_[0]/$current_url/screenshot-$time_in_s.png.base64"); +&connectivity_check("./data/$_[0]/$current_url/screenshot-$time_in_s.png.base64"); } else {eval {make_path("./data/$_[0]/-/")}; open my $FILEH_B, '>', "./data/$_[0]/-/screenshot-$time_in_s.png.base64"; open my $FILEH_C, '>', "./data/$_[0]/-/title.txt"; eval {print $FILEH_B $driver->screenshot({'full' => 1})}; print $FILEH_C $driver->get_title(); -&connectivity_check($_[1], "./data/$_[0]/-/screenshot-$time_in_s.png.base64"); +&connectivity_check("./data/$_[0]/-/screenshot-$time_in_s.png.base64"); } } sub double_443_screenshot { -if ($#_ > 1) {die "$!: Too much arguments: \"$_[1]\"...\"$_[$#_]\"."} +if ($#_ > 0) {die "$!: Too much arguments: \"$_[0]\"...\"$_[$#_]\"."} &connectivity_check; my $time_in_s = time; eval {$driver->get("https://$_[0]")}; @@ -140,13 +102,13 @@ open my $FILEH_B, '>', "./data/$_[0]/$current_url/screenshot-$time_in_s.png.base open my $FILEH_C, '>', "./data/$_[0]/$current_url/title.txt"; eval {print $FILEH_B $driver->screenshot({'full' => 1})}; print $FILEH_C $driver->get_title(); -&connectivity_check($_[1], "./data/$_[0]/$current_url/screenshot-$time_in_s.png.base64"); +&connectivity_check("./data/$_[0]/$current_url/screenshot-$time_in_s.png.base64"); } else {eval {make_path("./data/$_[0]/-/")}; open my $FILEH_B, '>', "./data/$_[0]/-/screenshot-$time_in_s.png.base64"; open my $FILEH_C, '>', "./data/$_[0]/-/title.txt"; eval {print $FILEH_B $driver->screenshot({'full' => 1})}; print $FILEH_C $driver->get_title(); -&connectivity_check($_[1], "./data/$_[0]/-/screenshot-$time_in_s.png.base64"); +&connectivity_check("./data/$_[0]/-/screenshot-$time_in_s.png.base64"); } $time_in_s = time; eval {$driver->get("view-source:https://$_[0]")}; @@ -158,19 +120,20 @@ open my $FILEH_B, '>', "./data/$_[0]/$current_url/screenshot-$time_in_s.png.base open my $FILEH_C, '>', "./data/$_[0]/$current_url/title.txt"; eval {print $FILEH_B $driver->screenshot({'full' => 1})}; print $FILEH_C $driver->get_title(); -&connectivity_check($_[1], "./data/$_[0]/$current_url/screenshot-$time_in_s.png.base64"); +&connectivity_check("./data/$_[0]/$current_url/screenshot-$time_in_s.png.base64"); } else {eval {make_path("./data/$_[0]/-/")}; open my $FILEH_B, '>', "./data/$_[0]/-/screenshot-$time_in_s.png.base64"; open my $FILEH_C, '>', "./data/$_[0]/-/title.txt"; eval {print $FILEH_B $driver->screenshot({'full' => 1})}; print $FILEH_C $driver->get_title(); -&connectivity_check($_[1], "./data/$_[0]/-/screenshot-$time_in_s.png.base64"); +&connectivity_check("./data/$_[0]/-/screenshot-$time_in_s.png.base64"); } } sub reverse_dns_doms { my (@obj); my $res = Net::DNS::Resolver->new; +&connectivity_check; my $reply = $res->search("$_[0]", "PTR"); if ($reply) { foreach my $rr (grep { $_->type eq "PTR" } $reply->answer) { # Do not assume rr-objects are of the same type as requested. @@ -184,11 +147,6 @@ sub syn_ping_elmn { $p->port_number($_[0]); foreach my $host (@host) { next unless defined($host); -(my $check = $host) =~ s/^[0-9]+[.]//; -&connectivity_check($check); -last} -foreach my $host (@host) { -next unless defined($host); $args{'host'} = $host; $p->ping($args{'host'}); $host =~ s/[.][0-9.]+$//; @@ -215,18 +173,19 @@ 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; +$alpha = time; splice @host, 0, $#host; undef %hoa; $args{'port'} = '80'; $args{'proto'} = 'tcp'; $p->port_number($args{'port'}); -&connectivity_check; foreach my $i1 ($iii1..9,$iii2..126,$iii3..254) { # Skip large private blocks. $args{'host'} = $i1.'.'.$i2.'.'.$i3.'.'.$i4; $p->ping($args{'host'}); $host[$i1] = $args{'host'}; } +&connectivity_check; while (my ($host) = $p->ack) {push @{$hoa{'80'}}, $host; $host =~ s/[.][0-9.]+$//; splice @host, $host} +&connectivity_check; &syn_ping_elmn(80, 'udp'); &syn_ping_elmn(443, 'udp'); @@ -235,31 +194,43 @@ 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($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, $i2.'.'.$i3.'.'.$i4)} else { - foreach (@rray) {if (-d "./data/$_/view-source:http:/$_/" or -d "./data/$_/view-source:https:/$_/") {print $FILEH_A "\n"; next}; + if ($#rray == 0 and $rray[0] eq '') {&double_80_screenshot($host)} else { + foreach (@rray) {if ((-d "./data/$_/view-source:http:/$_/" or -d "./data/$_/view-source:https:/$_/") and (-d "./data/$_/http:/$_/" or -d "./data/$_/https:/$_/")) {print $FILEH_A "\n"; next}; sleep rand(1)/(rand(10)+1); - print $FILEH_A $_.','; &double_80_screenshot($_, $i2.'.'.$i3.'.'.$i4)} + print $FILEH_A $_.','; &double_80_screenshot($_)} print $FILEH_A "\n"} print $FILEH_A "\n"} foreach my $host (@{$hoa{'443'}}) { next unless defined($host); - &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, $i2.'.'.$i3.'.'.$i4)} else { - foreach (@rray) {if (-d "./data/$_/view-source:http:/$_/" or -d "./data/$_/view-source:https:/$_/") {print $FILEH_A "\n"; next}; + if ($#rray == 0 and $rray[0] eq '') {&double_443_screenshot($host)} else { + foreach (@rray) {if (-d "./data/$_/view-source:http:/$_/" or -d "./data/$_/view-source:https:/$_/" and (-d "./data/$_/http:/$_/" or -d "./data/$_/https:/$_/")) {print $FILEH_A "\n"; next}; sleep rand(1)/(rand(10)+1); - print $FILEH_A $_.','; &double_443_screenshot($_, $i2.'.'.$i3.'.'.$i4)} + print $FILEH_A $_.','; &double_443_screenshot($_)} print $FILEH_A "\n"} print $FILEH_A "\n"} -&connectivity_check($i2.'.'.$i3.'.'.$i4); -my $beta = time; -my $delta = $beta-$alpha; -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} +&connectivity_check; +$p->close(); +$beta = time; +$delta = $beta-$alpha; +$gamma = $i4*255**2+$i3*255**1+$i2; +if (3 > $delta or defined($retry_i)) { +$retry_i = undef; +print "$delta < 3.\n"; +my $exp = 0; +my $connectivity; +while (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/'`); +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."; if ($exp >= 10) {$exp -= int(rand(11))}} else {last}} +print "Retrying.\n"; +$p = Net::Ping->new("syn", 3); +redo LABEL2; +} +$p = Net::Ping->new("syn", 3); print 'Progress: ', $gamma/255**3*100, "%\n", 'ETA: ', (255**3-$gamma)*$delta, "s\n"; close $FILEH_A; print "\n", 'To continue after quitting, provide ', '1.'.$i2.'.'.$i3.'.'.$i4, ' as first argument.', "\n\n"; @@ -268,4 +239,3 @@ print "\n", 'To continue after quitting, provide ', '1.'.$i2.'.'.$i3.'.'.$i4, ' print 'Cleaning up...'."\n"; $driver->quit(); `killall geckodriver` and print 'Done!'."\n"; -#}