Skip to content

Instantly share code, notes, and snippets.

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
#curl -X DELETE
ports = ['4200','4201','4202']
@app.route('/', methods=['GET','PUT'])
def notimp():
@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 ="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():
return 'deleted', 201
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment