Latest / CyberCode Academy / Course 13 - Network Forensics | Episode 5: TCP/IP Layers, Data Flow, and Network Tools
Transcript
- 0:00Speaker 1: Welcome back to the deep Dive. Today, we're peeling back
- 0:03Speaker 1: the layers on the very architecture of the Internet. We
- 0:06Speaker 1: are We're going to take a hard look at network
- 0:08Speaker 1: protocol analysis. How all that data from a simple email
- 0:13Speaker 1: to a complex video feed travels across.
- 0:16Speaker 2: The globe in these tiny, meticulously structured packages.
- 0:20Speaker 1: And understanding this layered journey isn't just theory, right, It's
- 0:24Speaker 1: absolutely fundamental to being effective in cybersecurity programming, really any
- 0:29Speaker 1: kind of large scale tech analysis.
- 0:31Speaker 2: Yeah, our mission here is to turn this, this dense,
- 0:34Speaker 2: layered structure of network communication into something you can actually
- 0:38Speaker 2: grasp and use. We're focusing on the core mechanisms and
- 0:41Speaker 2: for analysts, you have to remember this, the network protocols
- 0:44Speaker 2: are the evidence. To duplicate and verify that evidence in
- 0:47Speaker 2: a forensically sound way, you first have to understand the
- 0:50Speaker 2: mechanics of the packet itself.
- 0:52Speaker 1: So let's start with what feels like the central mystery.
- 0:54Speaker 1: How does a simple application request, say an HTTP get
- 0:58Speaker 1: request for a web page, How does that become this
- 1:00Speaker 1: highly structured unit of data, a packet that can navigate
- 1:03Speaker 1: this huge, complex network of switches and routers, only to
- 1:08Speaker 1: arrive perfectly at its destination. It really feels like magic.
- 1:12Speaker 2: It does, but it's just precise layered engineering, and the
- 1:16Speaker 2: process that defines it all is encapsulation, the digital onion,
- 1:19Speaker 2: the digital onion exactly. Think of it like that. We
- 1:21Speaker 2: start at the top where your original data lives, and
- 1:24Speaker 2: as it moves down the network stack on the sending device,
- 1:27Speaker 2: each layer adds its own specialized wrap a header.
- 1:31Speaker 1: Okay, so before we start wrapping, we often hear about
- 1:34Speaker 1: two different models. There's the seven layer OSI model and
- 1:37Speaker 1: the four layered PCPIP model. Can we just quickly clarify
- 1:41Speaker 1: why we pretty much always focus on the four layer
- 1:44Speaker 1: one in the real world.
- 1:45Speaker 2: That's a great point. The seven layer OSI model is
- 1:48Speaker 2: it's fantastic for academic discussion. It really separates concepts like
- 1:51Speaker 2: presentation and session managers.
- 1:52Speaker 1: It's very granular, very But the four.
- 1:54Speaker 2: Layer TCPIP model Application Transport, Internet and network access it
- 1:59Speaker 2: simplifies that. It collapses some of those layers because it's
- 2:02Speaker 2: a much better reflection of how modern operating systems and
- 2:05Speaker 2: networking gear actually implement these functions.
- 2:08Speaker 1: So we use the four layer model because.
- 2:10Speaker 2: It's practical, it's what's really happening under the hood perfect.
- 2:14Speaker 1: So let's start with the core of our onion, the
- 2:16Speaker 1: application layer. That's our raw data, the http g E
- 2:20Speaker 1: two request. What's the first wrap as we move down.
- 2:23Speaker 2: The stack, that takes us to the transport layer Layer four.
- 2:26Speaker 2: This header is critical because it introduces the concept of
- 2:29Speaker 2: the application port number.
- 2:31Speaker 1: Okay, so that's telling the destination machine which program gets the.
- 2:34Speaker 2: Data exactly, which process needs it and if we're using TCP.
- 2:39Speaker 2: This header also adds the control flags that manage the
- 2:42Speaker 2: session state, you know, things like syn ack and FIM Okay.
- 2:47Speaker 1: So Layer four handles the application. Then Layer three, the
- 2:50Speaker 1: internet layer that takes over the job of what global.
- 2:54Speaker 2: Routing precisely, The internet layer adds the IP header. The
- 2:57Speaker 2: wrap contains the sorts and destination IP addresses. It's like
- 3:00Speaker 2: the global positioning system for the data packet.
- 3:02Speaker 1: This is what routers look at.
- 3:04Speaker 2: This is what routers use to move the data between
- 3:06Speaker 2: different networks all across the Internet and.
- 3:08Speaker 1: Before it actually hits the wire. What's the last.
- 3:11Speaker 2: Step we hit the network access layer, which is layer
- 3:14Speaker 2: two or the data link layer. This adds the final
- 3:19Speaker 2: localized wrap, the physical addressing information the MC address, THEMEC address,
- 3:24Speaker 2: and This is essential for local communication, for talking to
- 3:28Speaker 2: devices like switches within the same little neighborhood the same
- 3:31Speaker 2: broadcast domain. And you need to remember, switches only care
- 3:36Speaker 2: about layer two and mass the addresses.
- 3:38Speaker 1: You don't care about the IP address at all.
- 3:40Speaker 2: Nope, they don't look that deep.
- 3:41Speaker 1: That distinction is so key. The M and A F
- 3:44Speaker 1: address gets the data to the right physical device locally,
- 3:48Speaker 1: and the IP address gets to the right network globally.
- 3:51Speaker 1: You got it. So what happens when the destination machine
- 3:54Speaker 1: gets this fully wrapped.
- 3:55Speaker 2: Packet the exact reverse process. We call it decapsulation, unpeeling
- 3:59Speaker 2: the onion. That's as the data moves up the stack,
- 4:01Speaker 2: each layer reads and then just rips off its corresponding header.
- 4:04Speaker 2: The network access layer processes the MSc address and removes
- 4:08Speaker 2: the frame. The internet layer reads the IP, removes its header.
- 4:11Speaker 1: Transport layer reads the port number.
- 4:13Speaker 2: Uses the port number in flags, removes its header, and finally,
- 4:17Speaker 2: the raw application layer data is delivered right to the
- 4:20Speaker 2: web server process.
- 4:21Speaker 1: So the headers are what let the data be process
- 4:24Speaker 1: correctly up and down the stack. That structure is really
- 4:27Speaker 1: everything it is, And.
- 4:28Speaker 2: Let's focus on layer three for a moment. IP we
- 4:31Speaker 2: know it manages routing with IP addresses. But let's skip
- 4:33Speaker 2: the binary math and dive into the practical addressing concepts
- 4:36Speaker 2: that are really relevant for say, reconnaissance and analysis.
- 4:40Speaker 1: Great idea, What about IP addressing is most critical for
- 4:44Speaker 1: an analyst to know?
- 4:45Speaker 2: First just understanding the private reserved ranges. That is crucial
- 4:48Speaker 2: for knowing when traffic is internal versus xter.
- 4:51Speaker 1: You're talking about the ten dot network one ninety two
- 4:53Speaker 1: point one six eight.
- 4:54Speaker 2: YEP, the ten dot x dot XOTX, the one seventy
- 4:56Speaker 2: two point one six through one seventy two point three
- 4:58Speaker 2: to one range, and the one ninety two point one
- 5:01Speaker 2: sixty eight dot x dot x networks. If you see
- 5:03Speaker 2: those ips and external logs, you know something's being masked
- 5:06Speaker 2: by a net network address translation or you're looking at
- 5:09Speaker 2: internal recon and.
- 5:10Speaker 1: The thing that defines the size of these networks the
- 5:12Speaker 1: subnetmask that's represented much more efficiently by CIDR notation.
- 5:16Speaker 2: Right absolutely. CIDR, which is classless interdomain routing, uses that
- 5:21Speaker 2: slash notation like twenty four or eight, much cleaner, so
- 5:25Speaker 2: much it just counts how many bits are turned on
- 5:27Speaker 2: to define the network part of the address. A twenty
- 5:30Speaker 2: four means twenty four bits for the network ID, which
- 5:33Speaker 2: leaves only eight bits or two hundred and fifty four
- 5:36Speaker 2: usable addresses for hosts and.
- 5:38Speaker 1: Tools like nmap just live and breathe this notation constantly.
- 5:41Speaker 2: It's the most efficient way to tell a tool to
- 5:44Speaker 2: scan a huge range or just a tiny segment of
- 5:46Speaker 2: a network.
- 5:46Speaker 1: Okay, so that's a structural concept. What about a specific
- 5:50Speaker 1: forensic detail inside the IP header itself? Something they can
- 5:54Speaker 1: give us tangible.
- 5:55Speaker 2: Evidence the time to live or TTL field. It's a
- 5:58Speaker 2: fantastic forensic example.
- 5:59Speaker 1: I love this one.
- 6:00Speaker 2: The TTL is just a counter. It usually starts as
- 6:02Speaker 2: something like sixty four or one twenty eight, and every
- 6:04Speaker 2: time that packet crosses a router, every hop, the TTL
- 6:07Speaker 2: decreases by one.
- 6:08Speaker 1: You can work backward.
- 6:09Speaker 2: You can if an analyst sees a packet arrive with
- 6:12Speaker 2: the TTL of say one twenty, and they know the source,
- 6:14Speaker 2: so S typically starts its TTL at one twenty eight,
- 6:17Speaker 2: they can immediately deduce that the packet has crossed eight
- 6:19Speaker 2: network ops.
- 6:20Speaker 1: That is invaluable for tracing a network path or just
- 6:24Speaker 1: figuring out how close an attacker might be to your target.
- 6:26Speaker 2: It gives you a sense of distance on the network.
- 6:29Speaker 1: That's a perfect example of a header providing clues beyond
- 6:32Speaker 1: just the address. Now, if IP is best effort and
- 6:36Speaker 1: connection less meaning and just sends packets and.
- 6:38Speaker 2: Hopes for the best right no guarantees.
- 6:40Speaker 1: Then the responsibility for all the reliability must fall entirely
- 6:44Speaker 1: on the layer above it, on layer.
- 6:46Speaker 2: Four precisely, we move back up to the transport layer
- 6:49Speaker 2: where we manage data transfer reliability with the twin protocols
- 6:53Speaker 2: TCP and UDP. This is where we decide if we
- 6:56Speaker 2: want meticulous guaranteed service or just blistering speed.
- 7:01Speaker 1: And TCP the transmission control protocol, that's the meticulous one.
- 7:04Speaker 1: We use it for guaranteed connections, web pages, file transfers,
- 7:08Speaker 1: anything where every single bit has to arrive correctly and in.
- 7:11Speaker 2: Order, and that guarantee comes at a cost. There's overhead,
- 7:14Speaker 2: there's complexity. TCP is connection oriented, so it requires a
- 7:17Speaker 2: formal setup, the three way handshake, the three way handshake
- 7:21Speaker 2: s y n s y nack ack. No data gets
- 7:25Speaker 2: exchanged until that sequence confirms both sides are ready. But
- 7:29Speaker 2: the real magic of TCP's reliability lies inside the header fields,
- 7:33Speaker 2: the sequence number and the acknowledgment number tell us.
- 7:36Speaker 1: How those two numbers work together to enforce that order.
- 7:39Speaker 2: Okay, so the sequence number essentially puts a label on
- 7:42Speaker 2: every single byte of data that's sent. The acknowledgement number
- 7:45Speaker 2: is the crucial feedback loop. The receiver sends back an
- 7:48Speaker 2: ACK number that says, this is the next sequence number
- 7:51Speaker 2: I expect to receive.
- 7:52Speaker 1: I see, So it's a constant check in.
- 7:54Speaker 2: It's a constant check in. If the sender doesn't get
- 7:56Speaker 2: the ACK it was expecting, it knows that data segment
- 7:59Speaker 2: was lost, and it automatically retransmits it. This guarantees order
- 8:03Speaker 2: and prevents packet loss, all on top of the best
- 8:05Speaker 2: effort IP layer below it.
- 8:07Speaker 1: So reliability isn't just about the handshake at the beginning.
- 8:10Speaker 1: It's this constant, detailed negotiation based on these numbered segments.
- 8:14Speaker 1: What about preventing a fast sender from overwhelming a flow receiver?
- 8:18Speaker 2: Flow control that's managed by the sliding window protocol. Inside
- 8:22Speaker 2: the TCP header, there's also a window size field. This
- 8:26Speaker 2: is how the receiver tells the sender exactly how much
- 8:29Speaker 2: buffer space it has available right now.
- 8:31Speaker 1: So it can say, hey, slow down, I'm busy.
- 8:34Speaker 2: Exactly if the receiver is busy, it shrinks the window size,
- 8:37Speaker 2: which forces the sender to slow down. It prevents the
- 8:40Speaker 2: network from just drowning the host.
- 8:42Speaker 1: That level of detail really explains the overhead. But the
- 8:46Speaker 1: process of shutting down the connection is equally complex, isn't
- 8:49Speaker 1: it It is.
- 8:50Speaker 2: It's a four way tear down the fin ack process.
- 8:54Speaker 2: It's lengthy because both sides have to individually agree to
- 8:57Speaker 2: terminate their stream of communication, and if you don't do that,
- 9:00Speaker 2: you can end up with dangling or ghost connections. These
- 9:03Speaker 2: things called time weight states, and they tie up resources unnecessarily.
- 9:06Speaker 2: That can be a real problem on high volume web servers.
- 9:09Speaker 1: Okay, now let's contrast all that complexity with DP, the
- 9:12Speaker 1: User Data Gram protocol. If TCP is a long, verified
- 9:16Speaker 1: registered letter, UDP is a quick shout across the room.
- 9:20Speaker 2: It's send and forget. That's the perfect way to put it.
- 9:23Speaker 2: UDP requires no handshake, no sequence numbers, no acknowledgments. Its
- 9:27Speaker 2: header is symmetric and much much simpler. Just source port, destination,
- 9:32Speaker 2: port length and.
- 9:33Speaker 1: A checksum, which makes it incredibly fast.
- 9:35Speaker 2: Incredibly fast to process. This is what you want for
- 9:37Speaker 2: applications where latency is everything and losing a few packets
- 9:41Speaker 2: is okay, think DNS lookups real time gaming or streaming
- 9:45Speaker 2: video and voice.
- 9:47Speaker 1: When we look at both of these headers, the common
- 9:49Speaker 1: factor is the port number. How do we distinguish between
- 9:53Speaker 1: the different types of ports?
- 9:54Speaker 2: Right? So, port numbers are basically logical addresses for services
- 9:57Speaker 2: running on the host IP. They're the communication and endpoints
- 10:00Speaker 2: for your applications. We classify them into ranges.
- 10:03Speaker 1: Okay.
- 10:03Speaker 2: Ports zero to ten twenty three are the well known
- 10:06Speaker 2: ports HTTP on eighty, SSH on twenty two, you know
- 10:09Speaker 2: the famous ones. Then you have registered ports, and finally
- 10:11Speaker 2: the dynamic or ephemeral ports usually above four nine, one, five, two,
- 10:15Speaker 2: which are what your computer uses as a client to
- 10:17Speaker 2: start a connection.
- 10:18Speaker 1: And the connection itself. The whole path is defined by
- 10:21Speaker 1: something called a socket.
- 10:22Speaker 2: A socket is the full definition of that communication path.
- 10:25Speaker 2: It's the unique combination of the IP address and the
- 10:28Speaker 2: port number. That pair identifies one specific virtual end to
- 10:33Speaker 2: end connection.
- 10:34Speaker 1: So one server it can handle thousands of.
- 10:36Speaker 2: These at once, thousands of simultaneous socket connections, each one
- 10:40Speaker 2: maintaining its own state and data flow.
- 10:42Speaker 1: Okay, so we've established the complex theory of encapsulation and
- 10:46Speaker 1: state management. Now how do we as analysts and programmers
- 10:51Speaker 1: actually look inside this digital onion? How do we use
- 10:55Speaker 1: protocol analysis tools?
- 10:56Speaker 2: The premier tool for this, without question is wire Shark.
- 11:00Speaker 2: It allows for deep, granular inspection of network. You see
- 11:07Speaker 2: three core areas. There's the summary of all the packets,
- 11:10Speaker 2: the protocol tree that maps directly to the layered model
- 11:12Speaker 2: we just discussed, and then the raw hex stump at
- 11:15Speaker 2: the bottom, which is what the data looks like right
- 11:17Speaker 2: before it becomes binary on the wire.
- 11:19Speaker 1: Just seeing the layout is one thing, but how does
- 11:21Speaker 1: an analyst use wire Shark to quickly find, say, suspicious
- 11:25Speaker 1: activity in a sea of traffic.
- 11:27Speaker 2: The power really comes from display filters. If you want
- 11:31Speaker 2: to see all new connection attempts, you can use a
- 11:33Speaker 2: filter like TCP dot flags, dot ec N one. Okay,
- 11:37Speaker 2: if you suspect a rogue application is communicating on a
- 11:40Speaker 2: weird port, you filter for that port. But crucially, wire
- 11:44Speaker 2: Shark lets you right click any packet and follow its
- 11:47Speaker 2: TCP stream.
- 11:48Speaker 1: Ah, so you can pull out the entire conversation.
- 11:50Speaker 2: The entire conversation, It pulls out every single packet related
- 11:54Speaker 2: to that one session. You can literally carve out files
- 11:57Speaker 2: or messages that we're hidden inside the stream. It's absol
- 12:00Speaker 2: essential for forensic examination.
- 12:02Speaker 1: That's a massive step up from just seeing IP addresses
- 12:05Speaker 1: back and forth. Pulling out a full stream is game changing.
- 12:07Speaker 2: It is now Another heavy hitter for reconnaissance is end map,
- 12:11Speaker 2: the network mapper, right, but.
- 12:12Speaker 1: End map is different. It's active, not passive exactly.
- 12:15Speaker 2: Unlike wire shark, which just listens to existing traffic, end
- 12:19Speaker 2: map uses raw IP packets to actively probe a target.
- 12:23Speaker 2: It's designed to figure out which ports are open, what
- 12:25Speaker 2: services are running, and it even makes intelligent guesses about
- 12:28Speaker 2: the target's operating system.
- 12:29Speaker 1: And as we mentioned earlier, end maps efficiency is directly
- 12:33Speaker 1: tied to its understanding of that layer.
- 12:34Speaker 2: Three map YEP, and map relies heavily on that CIDR notation,
- 12:39Speaker 2: the twenty fours and the sixteens to define its scanning
- 12:42Speaker 2: boundaries efficiently. By sending out these custom raw packets and
- 12:46Speaker 2: analyzing the precise responses it gets back, end map can
- 12:49Speaker 2: map thousands of hosts in a very short time. It's
- 12:52Speaker 2: the go to utility for any initial network security assessment.
- 12:56Speaker 1: It all just comes back to that meticulous process of
- 12:59Speaker 1: wrapping an unwrapping information. Whether you're writing application code, and
- 13:03Speaker 1: you need to minimize TCP overhead or your security analyst
- 13:06Speaker 1: hunting your threats. Mastering these underlying layers is mastering the
- 13:10Speaker 1: very mechanism of the Internet, and.
- 13:12Speaker 2: This mastery is more critical now than it's ever been
- 13:15Speaker 2: in modern cybersecurity. Attackers don't always use obvious malware ports.
- 13:19Speaker 2: They often engage in what's called protocol tunneling, hiding in
- 13:22Speaker 2: plain sight, hiding their command and control traffic inside seemingly
- 13:26Speaker 2: normal protocols like DNS or even low level protocols like ICMP.
- 13:30Speaker 2: When traffic looks normal on ports eighty or four to
- 13:33Speaker 2: forty three, protocol analysis inspecting those headers, analyzing sequence patterns.
- 13:38Speaker 2: That is the only way to tell the difference between
- 13:40Speaker 2: a regular HTTP get request and a sophisticated malicious tunnel.
- 13:45Speaker 1: That puts a powerful modern context on why understanding sequence
- 13:49Speaker 1: numbers and TTL values still matters so much.
- 13:52Speaker 2: Indeed, it's the difference between being reactive and being proactive
- 13:56Speaker 2: when it comes to threat detection.
- 13:57Speaker 1: So, as a final review exercise for you to think about,
- 14:00Speaker 1: imagine you are tasked with designing a system for a
- 14:03Speaker 1: high frequency trading platform. You need absolute, verifiable correctness for
- 14:07Speaker 1: every single transaction, you need to minimize any risk of
- 14:10Speaker 1: financial loss due to a dropped data segment. Given the
- 14:12Speaker 1: trade off we just detailed between speed and reliability, would
- 14:15Speaker 1: you primarily rely on TCP or UDP for sending those
- 14:18Speaker 1: critical transaction records? And why? Think specifically about the function
- 14:22Speaker 1: of sequence numbers and acknowledgments.