Forensic file extraction from network captures
During incident response, analysts often need to extract files that were transferred over the network. Malware downloads, exfiltrated data, and lateral movement artifacts can all be recovered from packet captures. Per NIST SP 800-86, network forensics provides critical evidence that may not exist on the endpoint (especially if the attacker wiped the disk).
Extract malicious executables downloaded via HTTP/HTTPS for analysis in sandbox. Look for PE files (MZ header) in HTTP responses with suspicious content-disposition headers or non-standard content types.
Recover files sent to external servers to assess breach scope. Look for large HTTP POST bodies, base64-encoded data, or files uploaded via WebDAV/FTP. Determines exactly what data left the organization.
Extract attachments from SMTP traffic for phishing analysis. MIME-encoded attachments can be decoded and analyzed for malicious content, macros, or embedded exploits. Critical for initial access vector determination.
Recover files transferred via SMB during internal propagation. PsExec, WMI, and PowerShell remoting all leave artifacts in network traffic. SMB file transfers between workstations are almost always malicious.
Extracted files are forensic evidence. Always maintain chain of custody: document who captured the pcap, when, from what interface, using what tool and version. Hash the pcap immediately (SHA-256) before any analysis. Store original pcap on write-protected media.
Follow this systematic workflow when extracting files from packet captures. Each step builds on the previous one to maintain forensic integrity.
Filter traffic to find the file transfer. Look for HTTP 200 responses with large content-length, specific MIME types (application/octet-stream, application/x-executable), or destination IPs flagged by threat intelligence. Use display filters like http.response.code == 200 && http.content_length_header > 100000.
Right-click the packet, select Follow, then TCP Stream. This reassembles the entire conversation, showing request and response in order. Check both directions -- the request may reveal what triggered the download (e.g., a malicious URL parameter or POST payload).
Look for magic bytes (file signatures) at the start of the response payload. The HTTP Content-Length header indicates expected file size. For non-HTTP protocols, use the magic bytes table below to find where the file data begins and ends within the raw stream.
For HTTP: File, Export Objects, HTTP -- this auto-extracts all transferred files. For raw streams: change the stream display to "Raw" format, then "Save As" to disk. For SMB: File, Export Objects, SMB. For TFTP (common in firmware exfil): File, Export Objects, TFTP.
Calculate the hash (SHA-256) of the extracted file. Query the hash against VirusTotal, MalwareBazaar, and internal threat intel. If the file is an executable, analyze in an isolated sandbox (e.g., Joe Sandbox, ANY.RUN, Cuckoo). Never execute on production systems.
Magic bytes are the first few bytes of a file that identify its format. Forensic tools and analysts use these to determine file type regardless of extension:
| File Type | Hex Bytes | ASCII | Forensic Significance |
|---|---|---|---|
| 25 50 44 46 | Document exfil, malicious PDFs with JS exploits | ||
| ZIP/DOCX/XLSX | 50 4B 03 04 | PK.. | Archives, Office docs (OOXML), password-protected exfil |
| EXE/DLL (PE) | 4D 5A | MZ | Windows executables -- malware, backdoors, RATs |
| ELF (Linux) | 7F 45 4C 46 | .ELF | Linux malware, coinminers, reverse shells |
| PNG | 89 50 4E 47 | .PNG | Steganography -- data hidden in image pixels |
| JPEG | FF D8 FF | --- | Steganography, screenshot exfil, surveillance |
| GZIP | 1F 8B 08 | --- | Compressed exfil data, tar.gz archives |
| RAR | 52 61 72 21 | Rar! | Password-protected archives (common in ransomware exfil) |
| 7-Zip | 37 7A BC AF | 7z.. | High-compression archives used for staging data |
| SQLite | 53 51 4C 69 | SQLi | Browser databases, credential stores |
The MZ bytes (4D 5A) at offset 0x3B mark the beginning of a Windows PE executable embedded in the HTTP response. Everything before it is the HTTP header. A forensic analyst would carve the file starting at the MZ signature.
VirusTotal Upload Warning: Hash the file and search VirusTotal by hash first. Uploading the actual file to VirusTotal makes it available to all VT subscribers, including the attacker. If the file is unique to your incident, uploading it tells the adversary you found their malware. Use private sandboxes for sensitive files.
File, Export Objects, HTTP/SMB/TFTP. Automatic extraction of transferred files. Shows filename, hostname, content-type, and size. Best for quick extraction of HTTP-transferred files. Handles chunked transfer encoding automatically.
Automated file extraction. Reconstructs files from pcap. Shows thumbnails for images. Also extracts credentials, DNS queries, and session data. Open-source version available (limited features).
File carving tools that extract files based on headers and footers. Work on raw data -- do not require protocol understanding. Useful when the stream is corrupted or non-standard protocol is used. Originally developed for disk forensics, equally useful on raw TCP streams.
Scriptable extraction for automation. Process large pcap collections in batch. Integrates with SOAR playbooks for automated malware extraction and sandboxing. Syntax: tshark -r capture.pcap --export-objects http,./extracted/
| Protocol | Extraction Method | Complications |
|---|---|---|
| HTTP | Export Objects, Follow TCP Stream | Chunked encoding, gzip compression -- Wireshark handles both |
| HTTPS/TLS | Requires TLS keys (SSLKEYLOGFILE) or SSL inspection proxy | Without keys, only metadata is visible -- cannot extract files |
| SMB | Export Objects -> SMB | SMB3 encryption, multi-fragment transfers |
| FTP | Follow TCP Stream on data channel (port 20 or passive port) | Passive mode uses random ports -- filter by IP pair |
| SMTP | Follow TCP Stream, decode base64 MIME attachments | Multi-part MIME, quoted-printable encoding |
| DNS | Reassemble TXT record payloads, decode base32/base64 | Data split across many queries -- manual reassembly needed |
Hash Before Analysis: Always calculate MD5/SHA256 of extracted files before opening them. Submit the hash (not the file) to VirusTotal first. This documents the artifact, checks against known malware, and avoids tipping off the adversary that you found their tools.
In this exercise, you will match file signatures (magic bytes) to their file types. This is a fundamental forensics skill -- when you see hex data in a TCP stream, you need to instantly recognize what file type is being transferred.
Click a hex signature on the left, then click the matching file type on the right. Complete all pairs, then check your answers.
Examine the following hex dump extracted from a TCP stream and answer the questions below:
What file type is being transferred?
Based on the filename visible in the hex dump, what is the security concern?
1. What is the magic byte signature for Windows executables (EXE/DLL)?
2. In Wireshark, how do you export HTTP transferred files?
3. What should you do FIRST after extracting a suspicious file?
4. Which tool performs automated file carving from raw data?
5. Why should extracted executables never run on production systems?
6. Why should you search VirusTotal by hash instead of uploading the file?
7. What protocol is most difficult to extract files from without decryption keys?