Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ jh
cdsav
kjhbvljhv
wfewqfd
acWDSCV
21 changes: 21 additions & 0 deletions sample-vuln/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

@app.route("/ping")
from flask import request

@app.route("/ping")
def ping():
ip = request.args.get("ip", "127.0.0.1")
import ipaddress, subprocess
try:
# PRECOGS_FIX: validate the IP address strictly using ipaddress
ip_obj = ipaddress.ip_address(ip)
except Exception:
return {"error": "invalid ip"}, 400

# PRECOGS_FIX: call ping without invoking a shell, pass arguments as a list
try:
subprocess.run(["ping", "-c", "1", str(ip_obj)], check=False)
except FileNotFoundError:
return {"error": "ping command not available"}, 500

return {"status": "ok"}