Created
March 19, 2019 16:50
-
-
Save kevit/29958a93780f267e3c3a75a330fde565 to your computer and use it in GitHub Desktop.
This file contains 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
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