1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| import random, string from flask import Flask, request, render_template, abort from flask_socketio import SocketIO from threading import Thread
app = Flask(__name__)
socketio = SocketIO(app)
registered_emails, socket_clients = [], {}
generate = lambda x: "".join([random.choice(string.hexdigits) for _ in range(x)]) BOT_TOKEN = generate(16)
def blacklist_pass(email): email = email.lower()
if "script" in email: return False
return True
def send_flag(user_ip): for id, ip in socket_clients.items(): if ip == user_ip: socketio.emit("flag", {"flag": open("flag.txt").read()}, room=id)
def start_bot(user_ip): from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC
host, port = "localhost", 1337 HOST = f"http://{host}:{port}"
options = Options()
options.add_argument("--headless") options.add_argument("--no-sandbox") options.add_argument("--disable-dev-shm-usage") options.add_argument("--disable-infobars") options.add_argument("--disable-background-networking") options.add_argument("--disable-default-apps") options.add_argument("--disable-extensions") options.add_argument("--disable-gpu") options.add_argument("--disable-sync") options.add_argument("--disable-translate") options.add_argument("--hide-scrollbars") options.add_argument("--metrics-recording-only") options.add_argument("--mute-audio") options.add_argument("--no-first-run") options.add_argument("--dns-prefetch-disable") options.add_argument("--safebrowsing-disable-auto-update") options.add_argument("--media-cache-size=1") options.add_argument("--disk-cache-size=1") options.add_argument("--user-agent=HTB/1.0")
service = Service(executable_path="/usr/bin/chromedriver") browser = webdriver.Chrome(service=service, options=options)
try: browser.get(f"{HOST}/bot?token={BOT_TOKEN}")
WebDriverWait(browser, 3).until(EC.alert_is_present())
alert = browser.switch_to.alert alert.accept() send_flag(user_ip) except Exception as e: pass finally: registered_emails.clear() browser.quit()
@app.route("/") def index(): return render_template("index.html")
@app.route("/api/register", methods=["POST"]) def register(): if not request.is_json or not request.json["email"]: return abort(400)
if not blacklist_pass(request.json["email"]): return abort(401)
registered_emails.append(request.json["email"]) Thread(target=start_bot, args=(request.remote_addr,)).start() return {"success":True}
@app.route("/bot") def bot(): if request.args.get("token", "") != BOT_TOKEN: return abort(404) return render_template("bot.html", emails=registered_emails)
@socketio.on("connect") def on_connect(): socket_clients[request.sid] = request.remote_addr
@socketio.on("disconnect") def on_disconnect(): del socket_clients[request.sid]
if __name__ == "__main__": app.run(host="0.0.0.0", port=1337, debug=False)
|