Last active
February 7, 2020 22:45
-
-
Save 3lpsy/6bf716d98dfd178840909d25c372777b to your computer and use it in GitHub Desktop.
Simple Flask File Server For Simple Exfil (Read Comments Before Running)
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
#!/usr/bin/env python3 | |
# Before running, generate certs: | |
# $ openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365 | |
# | |
# Install dependencies: | |
# $ python3 -m venv venv | |
# $ source venv/bin/activate | |
# $ pip install pyopenssl flask | |
# $ python3 fileserver.py | |
import os | |
from flask import Flask, request, render_template, url_for, redirect | |
app = Flask(__name__) | |
FILE_FORM = """ | |
<html> | |
<head> | |
<title>Simple file upload using Python Flask</title> | |
</head> | |
<body> | |
<form action="/upload" method="post" enctype="multipart/form-data"> | |
Choose the file: <input type="file" name="file"/><BR> | |
<input type="submit" value="Upload"/> | |
</form> | |
</body> | |
</html> | |
""" | |
@app.route("/") | |
def home(): | |
return FILE_FORM | |
@app.route("/upload", methods=['POST']) | |
def upload(): | |
if 'file' in request.files: | |
file = request.files['file'] | |
if file.filename != '': | |
file.save(os.path.join(os.getcwd(), file.filename)) | |
return "File Uploaded Successfully" | |
return redirect(url_for('home')) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=8443, ssl_context=('cert.pem', 'key.pem')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment