-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo-aggressive.py
131 lines (112 loc) · 3.6 KB
/
go-aggressive.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
#!/usr/bin/python3
import socket
import time
import re
import random
# https://stackoverflow.com/a/17697651/13197635
def recvall(sock):
BUFF_SIZE = 4096 # 4 KiB
data = b''
while True:
part = sock.recv(BUFF_SIZE)
data += part
if len(part) < BUFF_SIZE:
# either 0 or end of data
break
return data
killerPorts = []
daniel = ""
pid = -1
def findKillers(secs=10):
global killerPorts
global daniel
global pid
print("Finding killer ports ({}s)...".format(secs))
try:
s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2.settimeout(1.0)
s2.connect(("mpg-r2.hitcon.org", 29272))
time.sleep(secs)
msg = recvall(s2).decode().split("\n")
except Exception:
return
for i in range(len(msg)):
line = msg[i]
if "SYSTEM: Process " in line:
continue
if "daniellin" in line:
if i + 1 != len(msg) and ("You need to cool down." in msg[i + 1] or "Too bad! Door is closed!" in msg[i + 1]):
continue
killerPorts = [x for x in killerPorts if x != daniel]
daniel = line.split("grep -v ")[-1].split(" | ")[0]
killerPorts.append(daniel)
print(line)
print("daniellin fingerprint: " + daniel)
print()
elif "Process Created: PID=" in line and "HUP TERM INT" in line:
if i + 1 != len(msg) and ("You need to cool down." in msg[i + 1] or "Too bad! Door is closed!" in msg[i + 1]):
continue
killerPorts = [x for x in killerPorts if x != pid]
pid = line.split("Process Created: PID=")[-1].split(" ")[0]
killerPorts.append(pid)
print(line)
print("Dans PID: " + daniel)
print()
elif "kill" in line:
if "#" in line:
line = "".join(line.split("#")[:-1])
for killerPort in [s for s in re.findall(r'\b\d+\b', line) if int(s) >= 30000 and int(s) < 40000]:
if killerPort not in killerPorts:
killerPorts.append(killerPort)
print(line)
print("Found " + killerPort)
print()
random.shuffle(killerPorts)
print(killerPorts)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1.0)
s.connect(("mpg-r2.hitcon.org", 29271))
s.send(b"Nick NyanCat2021 [REDACTED]\n")
print(recvall(s).decode())
curTime = 0
prevScore = 0
while True:
findKillers(2)
while True:
try:
s.send(b"CurrentGame\n")
stats = recvall(s).decode().split("\n")
status = stats[1].split(": ")[-1]
except Exception:
status = "WTF"
if status == "GAME_RUNNING":
try:
if killerPorts == []:
findKillers()
findKillers(0.5)
s.send(b"PlayerInfo\n")
recvall(s)
except Exception:
pass
break
else:
if "GAME_STARTING" in status:
killerPorts = []
print("Game is not running...")
time.sleep(0.1)
while True:
try:
s.send(b"PlayerInfo\n")
port = recvall(s).decode().split("=")[-1][:-1].strip()
break
except Exception:
findKillers(0.5)
continue
findKillers(0.5)
cmd1 = """Cmd socat -lf/tmp/{1} TCP-LISTEN:{0} -\n""".format(port, "".join(killerPorts))
print(cmd1)
s.send(cmd1.encode())
try:
recvall(s)
except socket.timeout:
break