Skip to content

Instantly share code, notes, and snippets.

@3lpsy
Last active February 7, 2020 22:45
Show Gist options
  • Save 3lpsy/6bf716d98dfd178840909d25c372777b to your computer and use it in GitHub Desktop.
Save 3lpsy/6bf716d98dfd178840909d25c372777b to your computer and use it in GitHub Desktop.
Simple Flask File Server For Simple Exfil (Read Comments Before Running)
#!/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