import socket
import json
import re
HOST = 'tasks.duckerz.ru'
PORT = 30009
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(300.0) # 5 минут
s.connect((HOST, PORT))
data = b""
try:
while b"Send to Bob:" not in data:
chunk = s.recv(4096)
if not chunk:
break
data += chunk
except socket.timeout:
pass
text = data.decode('utf-8', errors='ignore')
match = re.search(r'\{.*\}', text)
alice = json.loads(match.group())
p = int(alice['p'], 16)
g = int(alice['g'], 16)
A = int(alice['A'], 16)
print(f"[*] p = {p} ({p.bit_length()} бит)")
print(f"[*] g = {g}")
print(f"[*] A = {A}")
print("[*] Перебираем a...")
found_a = None
for a in range(1, 100_000_001): # 100 миллионов
if pow(g, a, p) == A:
found_a = a
print(f"[!!!] НАЙДЕНО! a = {a}")
break
if a % 5_000_000 == 0:
print(f"[*] Проверено {a}...")
if found_a is None:
print("[-] a не найдено. Пробуем A.")
found_a = A
# Отправляем
payload = json.dumps({"answer": found_a})
print(f"[*] Отправляем: {payload[:100]}...")
s.sendall((payload + "\n").encode())
# Читаем ответ
s.settimeout(60.0)
try:
while True:
resp = s.recv(4096)
if not resp:
print("[-] Соединение закрыто")
break
decoded = resp.decode('utf-8', errors='ignore')
print(f"[+] Ответ: {decoded}")
if "DUCKERZ{" in decoded:
print(f"\n[!!!] ФЛАГ: {decoded}\n")
break
except socket.timeout:
print("[-] Таймаут")
s.close()