Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -362,21 +362,43 @@ async def run_sandbox_endpoint(payload: SandboxRequest):
|
|
| 362 |
scripts = await page.evaluate("() => Array.from(document.querySelectorAll('script[src]')).map(e => e.src)")
|
| 363 |
|
| 364 |
# ── Indicator Analysis ──────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
indicators = []
|
| 366 |
|
| 367 |
-
|
| 368 |
-
|
|
|
|
|
|
|
|
|
|
| 369 |
|
|
|
|
| 370 |
for form in forms:
|
| 371 |
-
if
|
|
|
|
|
|
|
|
|
|
| 372 |
indicators.append(f"Form posts to external domain: {form}")
|
| 373 |
-
if
|
| 374 |
indicators.append(f"Form action contains suspicious keyword: {form}")
|
| 375 |
|
|
|
|
| 376 |
for script in scripts:
|
| 377 |
-
if
|
| 378 |
-
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
| 380 |
indicators.append(f"Script references cookies: {script}")
|
| 381 |
|
| 382 |
# ── Verdict Derivation ──────────────────────────────
|
|
|
|
| 362 |
scripts = await page.evaluate("() => Array.from(document.querySelectorAll('script[src]')).map(e => e.src)")
|
| 363 |
|
| 364 |
# ── Indicator Analysis ──────────────────────────────
|
| 365 |
+
from urllib.parse import urlparse
|
| 366 |
+
|
| 367 |
+
def get_base_domain(url):
|
| 368 |
+
try:
|
| 369 |
+
netloc = urlparse(url).netloc.lower().replace('www.', '')
|
| 370 |
+
parts = netloc.split('.')
|
| 371 |
+
return '.'.join(parts[-2:]) if len(parts) >= 2 else netloc
|
| 372 |
+
except:
|
| 373 |
+
return ''
|
| 374 |
+
|
| 375 |
+
target_base = get_base_domain(target_url)
|
| 376 |
indicators = []
|
| 377 |
|
| 378 |
+
# Only flag redirects that go to a DIFFERENT base domain
|
| 379 |
+
for r in redirect_chain:
|
| 380 |
+
r_base = get_base_domain(r['url'])
|
| 381 |
+
if r_base and r_base != target_base:
|
| 382 |
+
indicators.append(f"Redirected to different domain: {r['url']}")
|
| 383 |
|
| 384 |
+
# Only flag forms posting to a completely different domain
|
| 385 |
for form in forms:
|
| 386 |
+
if not form:
|
| 387 |
+
continue
|
| 388 |
+
form_base = get_base_domain(form)
|
| 389 |
+
if form_base and form_base != target_base:
|
| 390 |
indicators.append(f"Form posts to external domain: {form}")
|
| 391 |
+
if any(kw in form.lower() for kw in ["login", "verify", "secure", "account", "update"]):
|
| 392 |
indicators.append(f"Form action contains suspicious keyword: {form}")
|
| 393 |
|
| 394 |
+
# Only flag scripts from a completely different domain
|
| 395 |
for script in scripts:
|
| 396 |
+
if not script:
|
| 397 |
+
continue
|
| 398 |
+
script_base = get_base_domain(script)
|
| 399 |
+
if script_base and script_base != target_base:
|
| 400 |
+
indicators.append(f"External script from unrelated domain: {script}")
|
| 401 |
+
if "cookie" in script.lower():
|
| 402 |
indicators.append(f"Script references cookies: {script}")
|
| 403 |
|
| 404 |
# ── Verdict Derivation ──────────────────────────────
|