quantumbit commited on
Commit
b968a2c
·
verified ·
1 Parent(s): 4346d52

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from selenium import webdriver
3
+ from selenium.webdriver.chrome.options import Options
4
+ from selenium.webdriver.common.by import By
5
+ from bs4 import BeautifulSoup
6
+ import time
7
+
8
+ app = Flask(__name__)
9
+
10
+ def get_hidden_code(url):
11
+ # Setup Selenium headless Chrome
12
+ chrome_options = Options()
13
+ chrome_options.add_argument("--headless=new")
14
+ chrome_options.add_argument("--disable-gpu")
15
+ chrome_options.add_argument("--no-sandbox")
16
+ driver = webdriver.Chrome(options=chrome_options)
17
+
18
+ token_found = []
19
+
20
+ try:
21
+ driver.get(url)
22
+ time.sleep(3) # wait for page load
23
+
24
+ # Click the Start Challenge button if present
25
+ try:
26
+ start_button = driver.find_element(By.XPATH, "//button[contains(text(), 'Start Challenge')]")
27
+ start_button.click()
28
+ time.sleep(3) # wait for challenge to load
29
+ except Exception as e:
30
+ print("⚠️ Could not click Start Challenge button:", e)
31
+
32
+ # Get updated HTML after interaction
33
+ html = driver.page_source
34
+ soup = BeautifulSoup(html, "html.parser")
35
+
36
+ # Look for hidden elements
37
+ for tag in soup.find_all(True):
38
+ if tag.has_attr("style") and "display:none" in tag["style"]:
39
+ token_found.append(tag.get_text(strip=True))
40
+
41
+ # Look for hidden inputs
42
+ for hidden in soup.find_all("input", {"type": "hidden"}):
43
+ if hidden.get("value"):
44
+ token_found.append(hidden["value"])
45
+
46
+ # Try regex / text search for "Hidden Code"
47
+ if "hidden code" in html.lower():
48
+ start = html.lower().find("hidden code")
49
+ token_found.append(html[start:start+100])
50
+
51
+ driver.quit()
52
+
53
+ return list(set(token_found)) or ["No hidden code found"]
54
+
55
+ except Exception as e:
56
+ driver.quit()
57
+ return [f"Error: {str(e)}"]
58
+
59
+
60
+ @app.route("/mission", methods=["POST"])
61
+ def mission():
62
+ data = request.json
63
+ url = data.get("url")
64
+ questions = data.get("questions", [])
65
+
66
+ if not url:
67
+ return jsonify({"error": "URL is required"}), 400
68
+
69
+ tokens = get_hidden_code(url)
70
+
71
+ return jsonify({
72
+ "url_received": url,
73
+ "questions_received": questions,
74
+ "token_found": tokens
75
+ })
76
+
77
+
78
+ if __name__ == "__main__":
79
+ app.run(debug=True, host="0.0.0.0", port=5000)