Skip to content

network: fix behavior-derived WinHTTP requests missing domain/port - #3263

Merged
doomedraven merged 4 commits into
masterfrom
winhttp-behavior-url-fix
Sep 30, 2026
Merged

doomedraven merged 4 commits into
masterfrom
winhttp-behavior-url-fix

Conversation

@doomedraven

Copy link
Copy Markdown
Collaborator

Behavior-derived WinHTTP requests showed only the path (e.g. /eZJDZ5AC?Q=...) in the network HTTP table, without scheme/host, even though WinHttpConnect had ServerName/ServerPort logged.

Root causes

  • _merge_behavior_network stored only the path in uri. The network.http template renders only request.uri; PCAP-derived entries store the full URL there.
  • dport was read from s0.get("port"), but the event key is dport -> always None.
  • Only sessions[0] per host was merged; remaining requests were dropped.
  • winhttp_finalize_sessions reached connects only via sessions[*].connections. If WinHttpOpen was not captured (hooked late / failed), the connect and all its requests were orphaned.
  • Scheme was derived only from port == 443; TLS on non-443 ports was labelled http.

Changes

  • lib/cuckoo/common/network_utils.py
    • Iterate connects directly; session is looked up only for UA/proxy fields.
    • https if WINHTTP_FLAG_SECURE (0x00800000) is set in WinHttpOpenRequest flags or port is 443.
    • INTERNET_DEFAULT_PORT (0) resolved to 80/443; non-default port included in URL.
    • Events now carry url and a resolved dport.
  • modules/processing/network.py
    • Emit every WinHTTP request per host (deduped by URL).
    • uri = full URL, path = object name, port/dport populated, user_agent added.

Tested in production by reprocessing an affected task: entry now renders as https://<host>/<object> with the behavior badge.

- winhttp_finalize_sessions: iterate connects instead of sessions so requests
  survive when WinHttpOpen was not captured; derive https from
  WINHTTP_FLAG_SECURE or port 443; handle INTERNET_DEFAULT_PORT (0); emit full
  url and dport.
- _merge_behavior_network: put full URL in uri (network.http template renders
  only uri, matching PCAP entries), fix dport read from wrong key, emit all
  requests per host instead of only the first.
@doomedraven
doomedraven merged commit b9cb24f into master Sep 30, 2026
7 checks passed
@doomedraven
doomedraven deleted the winhttp-behavior-url-fix branch September 30, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant