forked from advanced-security-demo/demo-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvulnerable_command_injection.py
More file actions
40 lines (27 loc) · 922 Bytes
/
Copy pathvulnerable_command_injection.py
File metadata and controls
40 lines (27 loc) · 922 Bytes
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
37
38
39
40
import os
import subprocess
from flask import Flask, request
app = Flask(__name__)
@app.route('/ping')
def ping():
host = request.args.get('host', 'localhost')
command = "ping -c 4 " + host
result = os.system(command)
return f"Ping result: {result}"
@app.route('/execute')
def execute_command():
filename = request.args.get('file', '')
os.system(f"cat {filename}")
return "Command executed"
@app.route('/backup')
def backup():
backup_path = request.form.get('path', '/default/backup')
subprocess.call("tar -czf backup.tar.gz " + backup_path, shell=True)
return "Backup completed"
def process_file(user_input):
cmd = f"grep 'pattern' {user_input}"
subprocess.run(cmd, shell=True, capture_output=True)
def convert_file(input_file):
os.popen(f"convert {input_file} output.pdf").read()
if __name__ == '__main__':
app.run(debug=True)