SECURITY ENGINEERING · PART 2 · NETWORKING FOR SECURITY · SNIFFING · 22 OF 229

Packet Sniffing With Wireshark and tcpdump

See what an attacker on the network sees, using your own traffic in your own lab: how packet capture works, promiscuous and monitor mode, tcpdump on a server and Wireshark on a desktop, the filters worth knowing, a login captured over HTTP in plain text and the same login over HTTPS as unreadable bytes, what still leaks under TLS, and how defenders use captures.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 12

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Capture is passive
  • HTTP shows everything
  • TLS leaves only metadata
  • filters find the signal
  • only capture what you may

Notes

How capture works

Everything you send is cut into packets, each with source and destination addresses and a payload. Normally a network card keeps only the packets addressed to it and ignores the rest. In promiscuous mode it keeps everything it can see, and on Wi-Fi, monitor mode captures raw radio frames from the air. A sniffer is simply a program that records those packets. It sends nothing, which is why sniffing is so hard to detect.

Packets and network cards
  • data is cut into packets, each with addresses and a payload
  • normally a card keeps only packets addressed to it
  • promiscuous mode: keep everything it can see
  • monitor mode (Wi-Fi): capture radio frames from the air
  • a sniffer just records them

Two tools

There are two tools to know. tcpdump runs in a terminal and is on almost every server, so it is what you use during an incident. Wireshark is the graphical one, with colour, decoding of hundreds of protocols, and powerful search. The usual workflow combines them: capture with tcpdump into a file, here on the loopback interface for traffic to a local lab server, then open that file in Wireshark to study it.

Capture on your own machine
# list interfaces
tcpdump -D
# capture web traffic to a file
sudo tcpdump -i lo -w lab.pcap \
  port 8080
# read it back, show payload
tcpdump -r lab.pcap -A | less
# or open lab.pcap in Wireshark

HTTP: plain text

Log in to your lab copy of ShopRung over plain HTTP and look at the capture. There it is: the request line, the headers, and the body with the email and password in readable text. In Wireshark, right-click any packet and choose follow HTTP stream to see the whole conversation, including the session cookie the server sends back. Anyone on the path who captured this now has the password, and the cookie that proves you are logged in.

What the capture shows
POST /api/login HTTP/1.1
Host: localhost:8080
Content-Type: application/json

{"email":"test@lab.test",
 "password":"lab-pass-123"}

Wireshark: right-click a packet,
  Follow > HTTP Stream

HTTPS: ciphertext

Now repeat the login over HTTPS. The capture shows a TLS handshake, the client hello, the server hello and the certificate, and after that only records labelled application data. No path, no headers, no password, no cookie. The sniffer still captured every byte, and can read none of them. This single comparison is the best argument you will ever see for encrypting everything, and it takes five minutes to run.

The same login over TLS
  • TLS handshake: Client Hello, Server Hello, certificate
  • then "Application Data": encrypted records
  • no path, no headers, no password, no cookie
  • the sniffer captures every byte and can read none of it

What still leaks

TLS hides the content, but not everything. An observer still sees the addresses of both sides, the DNS lookup that came first unless DNS is encrypted too, the server name sent in the handshake, and the timing and size of every message. That is metadata: who talked to whom, when and how much. It matters for privacy, and defenders use exactly this metadata to spot malware calling home, even when they cannot read the payload.

Visible even with TLS
  • IP addresses of both sides
  • the DNS lookup, unless DNS is also encrypted
  • the server name in the handshake (SNI)
  • timing and sizes of messages
  • this is metadata: who talked to whom, when, how much

Filters

A real capture has thousands of packets, so filters matter. In Wireshark you can show only HTTP posts, only traffic to one address, only one port, only DNS, or only TLS client hellos. A filter for packets with the SYN flag and no ACK shows new connection attempts, which is how a port scan looks. And searching frames for a word like password quickly proves whether anything sensitive is crossing in plain text.

Wireshark display filters
http.request.method == "POST"
ip.addr == 10.0.0.5
tcp.port == 443
dns
tls.handshake.type == 1
tcp.flags.syn == 1 &&
  tcp.flags.ack == 0
frame contains "password"

The defender side

Defenders use the same skill constantly. To prove that an internal service sends secrets in plain text, which gets it fixed faster than any policy document. To investigate an incident and see what left the network and where it went. To find malware by the regular rhythm of its calls home. To check that TLS versions are modern. And to keep capture files as evidence. Network captures do not lie and do not forget.

Why defenders capture
  • prove a service sends secrets in plain text, then fix it
  • investigate an incident: what left the network, to where
  • find malware beaconing by its regular timing
  • check that TLS versions and ciphers are modern
  • keep pcaps as evidence

Rules

One rule before you practise. Capturing traffic on your own machine and your own lab network is fine. Capturing on a network you do not own or operate, a cafe, a college, an office, without written permission is interception, and it is illegal in most countries. Even at work, a capture contains other people's data, so follow the monitoring policy, capture the minimum you need, and store the file as sensitive.

Stay legal
  • your own machine and your own lab: fine
  • a network you do not own or run: needs written permission
  • captures hold other people's data: handle as sensitive
  • at work: follow the monitoring policy, capture the minimum

Common mistakes

Mistakes. Assuming nobody is listening on the network. Leaving internal tools on plain HTTP because they are internal. Still running old plain-text protocols like FTP, Telnet, and unencrypted mail and directory traffic. Capturing with no filter and drowning in packets. Sharing a capture file that contains real passwords and cookies. And the one that ends careers: sniffing a network you do not own.

Avoid these
  • "nobody is listening"
  • HTTP for internal tools
  • old protocols: FTP, Telnet, plain SMTP and LDAP
  • capturing with no filter and drowning in packets
  • sharing pcaps with secrets
  • sniffing networks you do not own

Say it like this

In the interview: over plain HTTP an attacker on the same network sees everything, including paths, headers, passwords and session cookies. Over TLS they see only metadata: addresses, DNS lookups, the server name, sizes and timing. So I encrypt all traffic, including internal traffic, retire plain-text protocols, and I use packet captures myself to verify that nothing sensitive crosses the network unencrypted.

In the interview
  • "Over plain HTTP, everything: paths, headers, passwords and session cookies. Over TLS only metadata: IP addresses, DNS
  • lookups, the server name, sizes
  • and timing. So I encrypt all traffic, internal too, and use
  • captures to verify it."

Interview questions

Q1What is packet sniffing?

Passively capturing network packets as they cross a network interface, using tools such as tcpdump or Wireshark. Because the sniffer only listens and sends nothing, it is very hard to detect, which is why encryption rather than detection is the main defense.

Q2What is the difference between promiscuous mode and monitor mode?

In promiscuous mode a network card accepts all frames it sees on the network it is joined to, not just those addressed to it. Monitor mode applies to Wi-Fi and captures raw radio frames from the air without joining any network.

Q3What can an attacker see when traffic uses plain HTTP?

Everything: URLs, headers, form fields such as usernames and passwords, the response body, and session cookies, which can be replayed to take over the session without knowing the password.

Q4What remains visible when traffic is encrypted with TLS?

Metadata: source and destination IP addresses and ports, DNS lookups unless DNS is encrypted, the server name indication (SNI) in the handshake, and the size and timing of messages. The content itself is not readable.

Q5When would you use tcpdump instead of Wireshark?

On servers and remote machines with no graphical interface, during incident response, or for long captures to a file. A common workflow is capturing with tcpdump into a pcap and analysing it in Wireshark.

Q6How would a port scan look in a packet capture?

As many TCP SYN packets from one source to many ports or hosts in a short time, mostly answered by resets. A Wireshark filter such as tcp.flags.syn == 1 && tcp.flags.ack == 0 isolates the connection attempts.

Q7How do defenders use packet captures?

To prove sensitive data is crossing in plain text, to reconstruct what left the network during an incident, to spot malware beaconing by its regular timing and destinations, to verify TLS versions, and to preserve evidence.

Q8Is it legal to sniff traffic on a public Wi-Fi network?

Capturing other people’s traffic without authorisation is interception and is illegal in most jurisdictions. Practise only on your own devices and lab network, or with written permission from the network owner.