Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from flask import Flask, jsonify
from flask import request
from flask import abort
import random
import string
import docker
app = Flask(__name__)
#curl -X POST http://127.0.0.1:5000
#curl -X DELETE http://127.0.0.1:5000
ports = ['4200','4201','4202']
@app.route('/', methods=['GET','PUT'])
def notimp():
abort(501)
@app.route('/', methods=['POST'])
def post():
if len(ports) == 0:
return 'no more', 429
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
p = "".join(random.sample(s,8))
b = ports.pop()
client = docker.from_env()
container = client.containers.run("sspreitzer/shellinabox", environment=dict([("SIAB_PASSWORD", p)]),ports=dict([("4200/tcp", b)]), detach=True)
return 'password: ' + p + ' port:' + b, 201
@app.route('/', methods=['DELETE'])
def delete():
client = docker.from_env()
for container in client.containers.list():
container.stop()
return 'deleted', 201
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.