Skip to content

Instantly share code, notes, and snippets.

@RiccardoBiosas
Last active June 22, 2024 13:59
Show Gist options
  • Select an option

  • Save RiccardoBiosas/e5a43cdd58699d6c2e9f3372281f3a05 to your computer and use it in GitHub Desktop.

Select an option

Save RiccardoBiosas/e5a43cdd58699d6c2e9f3372281f3a05 to your computer and use it in GitHub Desktop.
Web API Remote Code Execution (RCE) example
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/hack-me', methods=['POST'])
def evaluate_expression():
try:
user_input = request.json.get('expression')
## UNSAFE
result = eval(user_input)
return jsonify({'result': result})
except Exception as e:
return jsonify({'error': str(e)}), 400
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment