-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmitm-guard.py
137 lines (128 loc) · 6.47 KB
/
mitm-guard.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
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
import datetime
import http
import os
import re
import time
from urllib.request import urlopen
class MitmDefence:
def __init__(self, ip_addr, message, headers):
self.connection = http.client.HTTPConnection(ip_addr)
self.message = message
self.headers = headers
def scan(self):
curr_time = datetime.datetime.now().time()
print("\033[1;37mReading ARP table ...")
arp_table = os.popen("arp -a").read()
time.sleep(1)
mac_list = []
print("\033[1;37mComparing for MAC Addresses ...")
attack_detected = False
for line in arp_table.split("\n"):
if "dynamic" in line:
ip = line.split()[0]
mac_addr = line.split()[1]
if mac_addr not in mac_list:
mac_list.append(mac_addr)
else:
attack_detected = True
print("\033[1;31mMITM Attack detected!")
self.connection.request("POST", "", self.message.encode('utf-8'), self.headers)
response = self.connection.getresponse()
print("\033[1;37mFake HTTP requests sent!")
print("""\033[1;37m
Time = {}
IP Address = {}
Status = {}
Reason = {}
""".format(curr_time, ip, response.status, response.reason))
self.connection.close()
break
if not attack_detected:
print("\033[1;32mSystem is safe and protecting")
def get_ip():
destination = "http://checkip.dyndns.com/"
print("\033[1;37mSearching for Public IP Address ...")
result = str(urlopen(destination).read())
time.sleep(2)
print("\033[1;36mPublic IP Address found")
return re.compile(r"Address: (\d+\.\d+\.\d+\.\d+)").search(result).group(1)
text_art = """
=========== GOOD JOB. HERE'S YOUR GIFT ===========
_________________¶¶111111¶11111111111111¶¶111¶____
_________________¶¶11111¶111111111111111¶¶111¶____
________________¶¶111111¶11111111¶¶11¶¶¶¶1111¶____
_______________¶¶1111111111111111¶¶¶¶¶¶¶11111¶____
_____________1¶¶11111111111111111¶¶___¶¶11111¶____
___________¶¶¶¶11111¶1111111¶¶1111¶¶¶11¶11111¶____
_________¶¶¶111111111111111111111111¶¶¶¶11111¶____
_______1¶¶11111111111111111111111111111¶¶¶111¶____
______¶¶111111111111111111111111111111111¶¶¶1¶____
_____¶¶1111111111111111¶11¶¶111111111111111¶¶¶____
____¶¶11111111111111111¶¶¶¶11111111111111111¶¶____
___¶¶1111111111111111111¶¶1111111111111111111¶¶___
__¶¶11111111111111111111¶¶11111111111111111111¶¶__
__¶111111111111111111111¶1111111111111111111111¶__
_¶¶11111111111111111111¶¶1111111111111111111111¶¶_
_¶111111111111111111111¶¶1111111111111111111111¶¶_
_¶111111111111111111111¶¶1111111111111111111111¶¶_
1¶111111111111111111111¶¶1111111111111111111111¶¶_
1¶111111111111111111111¶¶1111111111111111111111¶¶_
1¶111111111111111111111¶¶1111111111111111111111¶1_
_¶1111111111111111111111¶¶11111111111111111111¶¶__
_¶1111111111111111111111¶¶11111111111111111111¶1__
_¶111111111111111111111¶¶¶¶111111111111111111¶¶___
_¶¶1111111111111111111¶¶1¶¶¶¶111111111111111¶¶____
_1¶1111111111111111¶¶¶¶¶¶¶¶¶¶¶¶111111111111¶¶1____
__¶11111111111¶¶¶¶¶¶¶¶¶¶¶_¶¶¶¶¶¶¶¶¶¶¶11111¶¶¶1____
__¶¶1111111111¶¶¶¶11111¶¶_¶¶1111¶¶¶¶1111¶¶¶1¶¶____
__1¶¶¶11111111111111111¶¶_¶1¶1111111111¶¶¶11¶¶____
___¶¶¶¶¶1111111111111111¶¶¶¶1111111111¶¶_¶_1¶¶____
___1¶111¶¶¶11111111111111¶¶¶¶111111¶1¶¶_1¶_11¶____
____¶¶1111¶¶¶111111111111¶¶¶1111111¶¶¶_¶¶1111¶____
____1¶111111¶¶¶1111111111¶1¶¶1111111¶¶¶11¶11¶¶____
_____¶¶1111111¶¶¶¶1111111¶¶¶¶111111111¶1¶¶_1¶¶____
_____1¶1111111111¶¶¶¶1111¶¶1¶¶11111111¶¶¶¶_1¶1____
______¶¶11111111111¶¶¶¶111¶1¶¶111111111¶¶¶__¶1____
______1¶11111111111111¶¶¶¶¶_1¶1111111111¶¶111¶____
_______¶¶111111111111111¶¶¶1¶¶1111111111¶¶¶¶¶¶1___
________¶111111111111111¶¶__1¶¶¶11111111¶¶¶1¶¶¶___
________¶¶111111111111111¶1__1¶1¶¶¶¶¶1111¶¶¶¶¶¶1__
_________¶111111111111111¶¶___¶111¶¶¶¶¶¶¶¶¶¶_1¶___
_________¶¶11111111111111¶¶___¶¶1111111¶¶¶____¶___
__________¶1111111111111¶¶_____¶111111111¶________
__________¶¶111111111111¶¶_____¶¶1111111¶¶________
___________¶111111111111¶1______¶1111111¶¶________
___________¶¶11111111111¶_______¶¶111111¶¶________
____________¶1111111111¶¶________¶111111¶¶________
____________¶¶111111111¶¶________¶¶11111¶¶________
____________1¶111111111¶¶_________¶11111¶¶________
_____________¶¶11111111¶1_________¶¶1111¶¶________
_____________¶¶111¶1111¶__________1¶1111¶¶________
______________¶111¶¶111¶¶__________¶¶1111¶________
______________¶111¶¶111¶¶__________¶¶1111¶________
______________¶11111111¶1__________1¶1¶¶1¶¶_______
_____________¶¶11111111¶____________¶1¶¶11¶_______
____________1¶111111111¶____________¶11__1¶_______
____________¶¶11111111¶¶____________¶¶¶¶¶¶¶_______
____________¶111111111¶¶____________¶¶¶¶¶¶¶_______
____________¶1111111111¶____________¶¶¶¶¶¶¶¶______
___________1¶1111111111¶____________¶¶¶¶¶¶¶¶______
___________1¶1111111111¶1___________¶¶¶¶¶¶¶¶1_____
____________¶1111111111¶¶___________1¶¶¶¶¶¶¶______
____________¶1111111111¶¶____________¶¶¶¶¶¶¶______
____________¶¶111111111¶¶____________¶¶¶¶¶¶¶¶_____
____________1¶1111111111¶_____________¶¶¶¶¶¶¶_____
_____________¶1111111111¶_____________¶¶¶¶¶¶¶¶____
_____________¶¶111111111¶_____________1¶¶¶¶¶¶¶¶___
______________¶111111111¶1____________¶¶¶¶¶¶¶¶¶¶__
______________¶¶11111111¶1____________¶¶¶¶¶¶¶¶¶¶__
_______________¶11111111¶¶___________¶¶¶¶¶¶¶¶¶¶1__
_______________¶¶1111111¶¶___________¶¶¶¶¶¶¶¶¶¶___
________________¶¶111111¶¶____________¶¶¶¶¶¶¶¶____
_________________¶111111¶¶_____________¶¶¶¶¶¶_____
"""
print("\033[1;37mProgram started. Use CTRL+X keyboard combination when you want to finish scanning")
defence_system = MitmDefence(get_ip(), text_art, {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
while True:
defence_system.scan()
time.sleep(4)