Spaces:
Paused
Paused
File size: 2,372 Bytes
b968a2c | 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 | from flask import Flask, request, jsonify
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
import time
app = Flask(__name__)
def get_hidden_code(url):
# Setup Selenium headless Chrome
chrome_options = Options()
chrome_options.add_argument("--headless=new")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Chrome(options=chrome_options)
token_found = []
try:
driver.get(url)
time.sleep(3) # wait for page load
# Click the Start Challenge button if present
try:
start_button = driver.find_element(By.XPATH, "//button[contains(text(), 'Start Challenge')]")
start_button.click()
time.sleep(3) # wait for challenge to load
except Exception as e:
print("⚠️ Could not click Start Challenge button:", e)
# Get updated HTML after interaction
html = driver.page_source
soup = BeautifulSoup(html, "html.parser")
# Look for hidden elements
for tag in soup.find_all(True):
if tag.has_attr("style") and "display:none" in tag["style"]:
token_found.append(tag.get_text(strip=True))
# Look for hidden inputs
for hidden in soup.find_all("input", {"type": "hidden"}):
if hidden.get("value"):
token_found.append(hidden["value"])
# Try regex / text search for "Hidden Code"
if "hidden code" in html.lower():
start = html.lower().find("hidden code")
token_found.append(html[start:start+100])
driver.quit()
return list(set(token_found)) or ["No hidden code found"]
except Exception as e:
driver.quit()
return [f"Error: {str(e)}"]
@app.route("/mission", methods=["POST"])
def mission():
data = request.json
url = data.get("url")
questions = data.get("questions", [])
if not url:
return jsonify({"error": "URL is required"}), 400
tokens = get_hidden_code(url)
return jsonify({
"url_received": url,
"questions_received": questions,
"token_found": tokens
})
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=5000)
|