Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 37 ยท Dynamic Analysis

Network Behaviour Analysis

Analyze malware network behaviour safely: parse DNS packets, spot generated domains and beaconing, read HTTP requests and use a simulated internet to collect indicators.

Almost every piece of malware talks to the network: to download more code, to report to an operator, to steal data or to spread. That makes network behaviour one of the richest sources of indicators (domains, IP addresses, URLs, user agents) and patterns (how often, how much, in what format). Defenders can block and hunt for them across a whole organization.

In the lab you capture traffic from a sample that thinks it is online while a helper machine plays the internet (Building a Safe Analysis Lab). Here you will practise the analysis side with synthetic data: you build and parse a DNS packet yourself, then analyze lookups, intervals and HTTP requests. Nothing in this lesson sends a single byte to a network.

What to capture

Layer Look for Typical finding
DNS Names the sample looks up C2 domains, generated names, failed lookups
HTTP / HTTPS Methods, hosts, paths, user agents, bodies Beacons, downloads, stolen-data uploads
TLS Server name (SNI), certificate details, JA3-style fingerprints Destination even when encrypted
Raw TCP/UDP Odd ports, custom protocols Custom C2
Timing Interval and jitter between connections Beaconing
Volume Bytes sent and received Exfiltration or download

Tools: Wireshark and tcpdump record and show packets; fake-internet tools such as INetSim or FakeNet-NG answer requests with fake responses; a proxy can decrypt HTTPS from the lab's own sample if you install the proxy's certificate (only in the lab).

Anatomy of a DNS message

DNS is usually the first thing a sample does: it must find the server's address. A query packet starts with a 12-byte header (ID, flags, counts) followed by the question: the domain as length-prefixed labels, a type (A = 1 for IPv4) and a class (IN = 1). Building one shows how simple the protocol is.

Python Build and parse a DNS query

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You will see this structure in a Wireshark capture: Wireshark simply parses what we just parsed. Note that TXT queries are sometimes abused to smuggle data, so unusual record types are worth noting.

Spotting generated domains (DGA)

Some malware computes many pseudo-random domain names each day (a domain generation algorithm). The operator registers one of them; the bots try all until one answers. In a capture you see lots of lookups for strange, random-looking names that mostly fail with NXDOMAIN ("no such domain"). A rough detector scores how random a name looks, using character entropy and the lack of vowels.

Python Score domain names for randomness

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Real detectors use language models and dictionaries, because short random-looking brand names exist, and some DGAs join real words to look normal. Treat this as the idea, not a production rule.

Beaconing

A sample that checks in on a timer produces connections at regular intervals. People browse irregularly, so very even intervals stand out. Jitter (random variation added by the malware) blurs it, but the spread is still small compared with people. A common measure is the coefficient of variation (standard deviation divided by mean).

Python Find the beacon among the hosts

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A host with a coefficient of variation near zero is almost mechanical. The 10.0.0.37 example shows that even 10 percent jitter keeps the CV low.

Reading HTTP requests

Plain HTTP makes everything visible. Look at:

  • Method and path: POST /gate.php is a very classic C2 style path.
  • Host header: the domain.
  • User-Agent: malware often uses fixed or odd strings, which make good detection rules.
  • Body: encoded or encrypted data (base64, hex), victim identifiers, system information.
  • Response: commands, configuration or a second-stage file.

With HTTPS you cannot read the content from outside, but you still see the destination name (from DNS and SNI), the certificate, the volume and the timing. In the lab, a proxy with your own certificate can show the plaintext for samples that do not pin certificates.

Python Extract indicators from HTTP requests

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A browser from 2001 on a Windows 10 machine is a strong detection candidate: the combination of path, user agent and body format makes a signature that rarely matches normal traffic.

Turning traffic into indicators

  1. List every domain and IP contacted, with counts and first and last seen times.
  2. Separate noise (Windows update, time sync, the lab's own tools).
  3. Note ports and protocols, even if they look ordinary.
  4. Capture full request samples for the notes.
  5. Defang for reporting: update[.]example[.]test.
  6. Add timing: interval, jitter, active hours.

Common mistakes

  • Treating a successful DNS lookup as proof the server is real: the lab's fake internet answers everything.
  • Ignoring failed lookups, which can reveal domain generation.
  • Missing traffic because the sample used a different port or protocol.
  • Contacting the attacker's real server "just to see": do not.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a DNS query for update.example.test tell an analyst?

    DNS lookups reveal which hosts a sample tries to contact, even if the actual connection is later blocked or faked.
  2. 2. A host makes connections every 300 seconds with only 10 percent variation. What does that suggest?

    Very regular intervals are typical of programs checking in with an operator.
  3. 3. Many lookups for random-looking names that mostly return NXDOMAIN suggest what?

    DGA malware tries lists of generated names until it finds the one the operator registered.
  4. 4. What can you still observe when malware uses HTTPS?

    Metadata remains visible. Content needs a lab proxy that can decrypt it.

Summary

  • Capture DNS, HTTP(S), timing and volume in the lab with a simulated internet.
  • DNS packets are simple structures you can parse; generated names look random and fail often.
  • Beaconing shows as regular intervals with low variation.
  • HTTP details such as paths, user agents and bodies become detection signatures.
  • Record, defang and share indicators; never contact the real attacker infrastructure.

Next: Sandbox Reports and Automation