hch-dev commited on
Commit
6cd52fb
·
verified ·
1 Parent(s): 58bf5e2

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +29 -7
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
- if redirect_chain:
368
- indicators.append(f"Redirected {len(redirect_chain)} time(s): {[r['url'] for r in redirect_chain]}")
 
 
 
369
 
 
370
  for form in forms:
371
- if form and target_url and not form.startswith(target_url):
 
 
 
372
  indicators.append(f"Form posts to external domain: {form}")
373
- if form and any(kw in form.lower() for kw in ["login", "verify", "secure", "account", "update"]):
374
  indicators.append(f"Form action contains suspicious keyword: {form}")
375
 
 
376
  for script in scripts:
377
- if script and target_url and not script.startswith(target_url):
378
- indicators.append(f"External script loaded: {script}")
379
- if script and "cookie" in script.lower():
 
 
 
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 ──────────────────────────────