defextract_net(file_path): ips = set() withopen(file_path, 'r', encoding='utf-8') as file: data = json.load(file) for entry in data: src_ip = entry.get('SrcHost') dest_ip = entry.get('DestHost') if src_ip: ips.add(src_ip) if dest_ip: ips.add(dest_ip) return ips
defextract_ioc(file_path): ips = set() withopen(file_path, 'r', encoding='utf-8') as file: data = json.load(file) for entry in data: if entry.get('type') == 'ip': ips.add(entry.get('ioc')) return ips
import binascii import socketserver import random import os import time
classMyServer(socketserver.BaseRequestHandler): defhandle(self): conn = self.request cli = str(self.client_address) print("Connected..." + cli) tmp = binascii.crc32(self.client_address[0].encode()) tmp = str(tmp) print("debug: " + tmp) math = '' starttime = time.time() whileTrue: try: out = str(random.randint(1, 100)) out = out + self.randchar() out = out + str(random.randint(1, 100)) out = out + self.randchar() out = out + str(random.randint(1, 100)) out = out + self.randchar() out = out + str(random.randint(1, 100)) math = tmp + ' + ' + out math = math.replace('X', '*') out = 'Answer my question:\nn = ' + tmp + '\nn + ' + out + ' = ?\nInput your answer in 3 seconds:' conn.send(out.encode()) data = conn.recv(128) if (time.time() - starttime) > 3: conn.sendall('Too late! Too slow! Try again.\n'.encode()) break iflen(data) == 0: print(cli + " closed.") break data = data.decode('utf-8') print(cli + ":" + data) if'\n'in data: data = data[0:data.find('\n')] an = eval(math) ifstr(an) == data: out = 'OK!\nI will answer your question (example: 2X2+2-1):\n' conn.send(out.encode()) data = conn.recv(128) iflen(data) == 0: print(cli + " closed.") break data = data.decode('utf-8') print(cli + ":" + data) data = data.replace('X', '*') data = data.replace(' x ', '*') data = data.replace('?', ' ') data = data.replace('=', ' ') out = str(eval(data)) if out == '': out = 'Finish, but output nothing.' out = out + '\n\n' conn.send(out.encode()) else: conn.sendall('Wrong!\n'.encode()) print(cli + " closed.") break
except Exception as e: print(cli + " closed.") conn.sendall('Error!\n'.encode()) break
defserve_forever(self, poll_interval=0.5): """ Handle one request at a time until shutdown. Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread. """
if __name__ == "__main__": server = socketserver.ThreadingTCPServer(('0.0.0.0', 8080), MyServer) print('ready...') server.serve_forever()
nc 连上发现要求三秒内计算出答案,回答正确后需要给他出道题,猜测后端使用了 eval(),直接通过 open() 读取 flag 即可