Latest / CyberCode Academy / Course 44 - RH Security Specialist | Episode 11: System Tracking and Port Reconnaissance
Transcript
- 0:00Speaker 1: You know, you lock your front door when you leave
- 0:02Speaker 1: the house. It's like pure muscle memory at this point.
- 0:05Speaker 2: Right. You just turn the key and walk away.
- 0:06Speaker 1: Exactly. You turn the key, you hear that physical click,
- 0:09Speaker 1: and you just walk away feeling secure. But, I mean,
- 0:13Speaker 1: here's a slightly unsettling question for you. How would you
- 0:16Speaker 1: actually know if someone came by and, you know, jiggled
- 0:20Speaker 1: the handle while you were gone?
- 0:21Speaker 2: Well, realistically, you wouldn't. I mean, unless you were physically
- 0:24Speaker 2: sitting inside just staring at the door.
- 0:26Speaker 1: Which would be weird.
- 0:27Speaker 2: Right. Highly weird. Right. Or unless you had like a
- 0:30Speaker 2: dedicated security camera pointed right at the lock. Otherwise, that
- 0:34Speaker 2: physical test of your perimeter defenses, it goes completely unrecorded.
- 0:38Speaker 1: And see, in the digital world, if you're running a server,
- 0:40Speaker 1: that server is constantly having its handle jiggled. Like 247. Oh, absolutely.
- 0:45Speaker 2: Every single second.
- 0:46Speaker 1: Yeah, you've got unseen forces, automated bots, opportunistic scripts. They
- 0:51Speaker 1: are out there right now just twisting the knob to
- 0:53Speaker 1: see if you forgot to lock up.
- 0:55Speaker 2: Yeah.
- 0:55Speaker 1: So today's deep dive is all about Achieving, well, ultimate
- 1:00Speaker 1: visibility into your tech.
- 1:01Speaker 2: Which is so critical.
- 1:03Speaker 1: It really is. Looking at our pile of research and
- 1:06Speaker 1: lab notes today, we're going to explore how to track
- 1:09Speaker 1: exactly what's happening inside a system at like a granular level.
- 1:14Speaker 1: And then we're going to completely flip the script to
- 1:16Speaker 1: see how your system looks from the outside to a
- 1:18Speaker 1: potential hacker.
- 1:19Speaker 2: Because security isn't just about building higher walls, you know.
- 1:23Speaker 2: It's about knowing your environment intimately. We're going to walk
- 1:26Speaker 2: through the exact tools that professionals use to secure and
- 1:29Speaker 2: scan their networks.
- 1:30Speaker 1: Okay, let's unpack this.
- 1:31Speaker 2: Yeah.
- 1:31Speaker 1: I think we should start on the inside. So our
- 1:33Speaker 1: primary mechanism for internal visibility is the Linux audit daemon,
- 1:38Speaker 1: which is commonly known as audit.
- 1:41Speaker 2: Right, audit. It's basically the internal security camera for your server,
- 1:44Speaker 2: like just quietly recording events in the background.
- 1:48Speaker 1: But it's different from standard logs, right? Like it operates
- 1:50Speaker 1: way deeper.
- 1:51Speaker 2: Yeah, much deeper. It doesn't just read application log files.
- 1:55Speaker 2: Audit actually integrates directly into the Linux kernel itself.
- 1:58Speaker 1: So at the very foundation of the operating system.
- 2:01Speaker 2: Exactly. When a user or even a program requests access
- 2:05Speaker 2: to a file, that request has to pass through the kernel.
- 2:09Speaker 2: And the audit daemon intercepts that system call in real time.
- 2:11Speaker 2: Like before the file is even opened, it logs the intent.
- 2:15Speaker 1: That is incredibly powerful. But I mean, if it's logging
- 2:18Speaker 1: every single tiny thing, what happens if the server runs
- 2:21Speaker 1: out of space?
- 2:22Speaker 2: Yes.
- 2:23Speaker 1: Looking at our notes on system failstakes, there's a really
- 2:25Speaker 1: cool feature for this.
- 2:26Speaker 2: Oh, the resume command. Yeah, this is such a critical feature.
- 2:29Speaker 2: So think about a scenario where your server is running
- 2:32Speaker 2: dangerously low on disk space, right? Right. If Audit just
- 2:35Speaker 2: blindly kept writing these massively detailed logs, it would chew
- 2:39Speaker 2: up the last remaining megabytes. And when a server hits
- 2:42Speaker 2: zero disk space, everything crashes. Database is corrupt. The whole
- 2:47Speaker 2: system just halts.
- 2:48Speaker 1: And a crash server is way worse than missing a
- 2:50Speaker 1: couple of log events. 100%.
- 2:52Speaker 2: So to prevent a self-inflicted crash, Audit monitors your disk
- 2:56Speaker 2: space thresholds. When space gets too tight, it just pauses logging.
- 2:59Speaker 2: It suspends those write operations.
- 3:01Speaker 1: Just puts itself on timeout.
- 3:02Speaker 2: Basically, yeah. And then once you've gone in and cleared
- 3:05Speaker 2: up some space, you don't even have to restart the
- 3:07Speaker 2: whole service or reboot the server. You just issue a
- 3:09Speaker 2: single resume command, and it immediately hooks back into the
- 3:12Speaker 2: kernel and starts recording again.
- 3:14Speaker 1: That's super smart.
- 3:15Speaker 2: Yeah.
- 3:16Speaker 1: But let's talk about the actual footage this system is capturing.
- 3:19Speaker 1: By default, these go to a specific folder, right? Like var, log, audit.
- 3:25Speaker 2: Yep, the audit.log file.
- 3:26Speaker 1: And looking at the raw output of this file on
- 3:29Speaker 1: a busy system is just overwhelming. Even if you just
- 3:32Speaker 1: spin up a brand new server, you get megabytes of
- 3:35Speaker 1: incredibly dense text.
- 3:37Speaker 2: Oh, it's a nightmare to read raw.
- 3:38Speaker 1: Right, because the system is executing thousands of background tasks
- 3:43Speaker 1: every second. So it's basically like a digital hoarder, just
- 3:46Speaker 1: collecting everything indiscriminately. If it's just a giant text file
- 3:50Speaker 1: full of everything, isn't that useless to a human?
- 3:52Speaker 2: Oh, completely useless. If you try to read the raw feed,
- 3:55Speaker 2: you're going to get alert fatigue in about five minutes.
- 3:57Speaker 2: The demon captures everything by design, but you aren't supposed
- 4:00Speaker 2: to read the raw feed. That's where audit trail comes in.
- 4:02Speaker 1: The audit control utility.
- 4:04Speaker 2: Exactly. This is the command line interface we use to
- 4:07Speaker 2: give the kernel specific instructions. We tell it what actually
- 4:09Speaker 2: matters to us.
- 4:10Speaker 1: So we shift from, like, watch literally everything to... Hey,
- 4:14Speaker 1: just watch this specific pathway.
- 4:16Speaker 2: Right. We set specific rules and watches. So let's take
- 4:19Speaker 2: a really sensitive file, like shot config.
- 4:21Speaker 1: Okay, the file that controls remote secure shell logins.
- 4:25Speaker 2: Yeah, that file is a prime target. You need absolute
- 4:27Speaker 2: certainty about who is touching it. So use audit tl
- 4:31Speaker 2: with the dash w flag, which stands for watch.
- 4:34Speaker 1: And you just point it at that file. Yep.
- 4:36Speaker 2: You append the path, the file, and you tell the
- 4:38Speaker 2: kernel to monitor it for specific changes. Reads, writes, execution, whatever.
- 4:43Speaker 2: The very millisecond a process even opens that text file,
- 4:47Speaker 2: the system flags it.
- 4:48Speaker 1: Wow. But wait, there is a catch here with how
- 4:51Speaker 1: these rules are saved, right? Like if you just type
- 4:53Speaker 1: it into the command line.
- 4:55Speaker 2: It's ephemeral. Yeah. It gets injected into the running kernel memory,
- 4:58Speaker 2: so it works instantly. But the moment you reboot the
- 5:00Speaker 2: server for maintenance.
- 5:01Speaker 1: The memory clears and your trap is just gone.
- 5:04Speaker 2: Poof. Gone. So for permanent enforcement, you have to save
- 5:09Speaker 2: those rules into a dedicated file, usually audit.rules. That way,
- 5:14Speaker 2: when the server boots up, the daemon parses that file
- 5:17Speaker 2: and loads your watches back into the kernel automatically.
- 5:19Speaker 1: So you're never flying blind. I love that. Okay, so
- 5:22Speaker 1: you've set this watch on a critical file and someone
- 5:25Speaker 1: changes it. The trap is sprung. But the raw log
- 5:28Speaker 1: entry is still like a total mess.
- 5:30Speaker 2: It's basically matrix code. Timestamps, serial numbers, e-nodes, user IDs.
- 5:35Speaker 2: It's machine language.
- 5:36Speaker 1: So how do we translate this matrix code into plain English?
- 5:40Speaker 2: Well, Linux gives us a tool called Ausearch, the audit
- 5:42Speaker 2: search utility.
- 5:43Speaker 1: Which is way smarter than just hitting control dash F
- 5:46Speaker 1: in a text file.
- 5:47Speaker 2: Exactly. Say we're hunting for failed login attempts. Maybe some
- 5:50Speaker 2: automated script is brute forcing our server. We don't just
- 5:53Speaker 2: search for the word fail. We tell Ausearch to specifically
- 5:56Speaker 2: filter for the message type user login and where the
- 6:00Speaker 2: success parameter equals no.
- 6:02Speaker 1: So it pulls up all the failures. But the output
- 6:04Speaker 1: is still kind of cryptic, right? Because the operating system
- 6:06Speaker 1: doesn't know names. It just knows numbers.
- 6:08Speaker 2: Right. The kernel has no idea who root is. It
- 6:12Speaker 2: only knows user ID zero.
- 6:13Speaker 1: And this is where my favorite trick comes in. The
- 6:16Speaker 1: dash I flag.
- 6:17Speaker 2: The interpret flag. It's basically a magic wand. Yeah.
- 6:19Speaker 1: You add dash I to your ostrich command and it
- 6:23Speaker 1: forces the tool to cross reference those numeric IDs and
- 6:26Speaker 1: translate them into human readable text before printing it to
- 6:29Speaker 1: your screen. So user ID zero instantly just says root zero.
- 6:34Speaker 2: It makes a massive difference, and it actually reveals something
- 6:36Speaker 2: really interesting about external attacks. When you look at these
- 6:40Speaker 2: interpreted logs during a brute force attack, you'll see scripts
- 6:44Speaker 2: trying to log in with random names.
- 6:46Speaker 1: Like trying to guess user accounts.
- 6:47Speaker 2: Right. They'll try Bob or Frank or even something weird
- 6:50Speaker 2: like printer. But since those aren't valid accounts, they don't
- 6:54Speaker 2: have a numeric ID. So when you use the interpret flag,
- 6:57Speaker 2: they show up as unset or invalid.
- 6:59Speaker 1: Which instantly tells you, hey, this is a bot just
- 7:02Speaker 1: throwing words at the wall, not a real admin who
- 7:04Speaker 1: forgot their password.
- 7:06Speaker 2: Exactly. It's great for hunting down specific events. But sometimes
- 7:09Speaker 2: you need the big picture, right? Which is why we
- 7:12Speaker 2: use our report.
- 7:12Speaker 1: Right. Here's where it gets really interesting. So if off-search
- 7:16Speaker 1: is the magnifying glass you use at a specific crime scene,
- 7:20Speaker 1: our report is like the monthly crime statistics report you
- 7:23Speaker 1: hand to the mayor.
- 7:24Speaker 2: That is a perfect way to conceptualize it. It's all
- 7:27Speaker 2: about summaries. If you hand the mayor the dash X
- 7:30Speaker 2: summary report, they get a clean list of every single
- 7:33Speaker 2: executable program run on the system.
- 7:35Speaker 1: Just took away all the noise.
- 7:36Speaker 2: Yep. Or you can layer the tools. You could run
- 7:39Speaker 2: a summary for failed logins and add that interpret flag.
- 7:43Speaker 2: So dash L summary dash I and boom, you get
- 7:45Speaker 2: a clean table.
- 7:46Speaker 1: Oh, like 293 failed tries for root.
- 7:50Speaker 2: Exactly. It takes five seconds to see a coordinated attack.
- 7:53Speaker 2: You can even run a network anomaly report with the
- 7:55Speaker 2: dash dash network flag to see historical network drop.
- 7:58Speaker 1: Okay, so we've totally mastered looking at the inside of
- 8:00Speaker 1: the system. We know who's touching files. We know the
- 8:03Speaker 1: failed logins. But to truly protect our digital house, we
- 8:06Speaker 1: need to walk outside, stand on the sidewalk, and see
- 8:09Speaker 1: what a hacker sees when they look at our server.
- 8:11Speaker 2: Flipping the script. I love this part. This is network
- 8:14Speaker 2: invulnerability scanning. Right.
- 8:16Speaker 1: And we need to differentiate between the tools here because
- 8:18Speaker 1: they aren't all the same.
- 8:19Speaker 2: Definitely not. You've got vulnerability scanners like Nessus, which are massive.
- 8:23Speaker 2: You have to download them, get a license key, maintain
- 8:26Speaker 2: a giant database of known bugs.
- 8:28Speaker 1: They're heavy. But then you have port scanners like Nmap.
- 8:31Speaker 2: Right. Nmap is tiny. It's open source. It's like 2.8 megabytes.
- 8:34Speaker 2: You just install it via your package manager in seconds.
- 8:37Speaker 2: It doesn't care if your web server has a specific
- 8:39Speaker 2: software bug. Its whole job is just to sweep the
- 8:42Speaker 2: network and see what doors are open.
- 8:44Speaker 1: So what happens if you run Nmap on your own
- 8:46Speaker 1: local machine, like scanning local host?
- 8:49Speaker 2: Well, it's going to reveal every port that's listening. It
- 8:51Speaker 2: might show port 22 open for SSH, port 25 for
- 8:55Speaker 2: SMTP email, maybe port 80 for web traffic. It maps
- 8:59Speaker 2: the terrain.
- 9:00Speaker 1: But the most wild feature of NMAP has to be
- 9:02Speaker 1: the OS detection, the dash O flag. Right. Because it
- 9:05Speaker 1: literally guesses your operating system, right? How does it do
- 9:08Speaker 1: that without just asking?
- 9:09Speaker 2: It uses TCP IP fingerprinting. It's so clever. Because if
- 9:14Speaker 2: it just asked, a secure server would lie or ignore it.
- 9:18Speaker 2: So instead, Nmap analyzes how the server's network stack responds to, well,
- 9:23Speaker 2: abnormal stimuli.
- 9:25Speaker 1: Abnormal stimuli. Like what? Poking it with a stick?
- 9:27Speaker 2: Kind of. Every operating system handles network traffic slightly differently. Normally,
- 9:32Speaker 2: computers do a standard three-way handshake to connect. It's very
- 9:36Speaker 2: polite and standardized. Nmap intentionally breaks those rules. It sends
- 9:41Speaker 2: nonsense packets.
- 9:42Speaker 1: Like a packet that contradicts itself.
- 9:43Speaker 2: Exactly. A packet with a bunch of conflicting flags turned
- 9:46Speaker 2: on at the same time. And this is where the
- 9:48Speaker 2: fingerprinting happens. A Windows server might panic and immediately send
- 9:52Speaker 2: back a reset packet to tear down the connection.
- 9:54Speaker 1: The Linux server.
- 9:55Speaker 2: A Linux kernel might just drop it silently. A router
- 9:59Speaker 2: might send a specific error message. Nmap sends dozens of
- 10:02Speaker 2: these weird anomalies, measures the exact quirks of the responses,
- 10:06Speaker 2: and compares it to a database.
- 10:08Speaker 1: That is wild. It's like listening to an accent to
- 10:10Speaker 1: guess where someone is from.
- 10:11Speaker 2: Exactly. And it's incredibly accurate. It'll spit out something like,
- 10:15Speaker 2: there is an 87% probability this is Red Hat Linux.
- 10:18Speaker 1: But here's a practical question for the learner. If I
- 10:21Speaker 1: run Nmap against a server, is it stealthy or is
- 10:23Speaker 1: it going to eat up all the server CPU and
- 10:25Speaker 1: like crash it?
- 10:27Speaker 2: It's definitely not stealthy and it can be highly resource
- 10:30Speaker 2: intensive on the target because it is actively poking and
- 10:34Speaker 2: prodding thousands of ports. If it does a half open scan,
- 10:37Speaker 2: it initiates a connection. The server allocates memory for it
- 10:41Speaker 2: and then Nmap just walks away.
- 10:43Speaker 1: Leaving the server hanging. Holding the door open.
- 10:45Speaker 2: Right. And if it does that thousands of times a second,
- 10:48Speaker 2: the server's state tables fill up. It literally can't accept
- 10:52Speaker 2: legitimate traffic anymore because it's waiting on all these ghost connections.
- 10:55Speaker 1: So you could cause a crash just by scanning.
- 10:57Speaker 2: Oh, easily.
- 10:58Speaker 1: Okay, so if Nmap can so easily see all our
- 11:01Speaker 1: open doors and guess our operating system and chew up
- 11:05Speaker 1: our memory, how do we become invisible?
- 11:08Speaker 2: Firewalls. Specifically, local software firewalls.
- 11:11Speaker 1: So we're talking about tools like Iptables. Because if you
- 11:13Speaker 1: scan a server without a firewall, it just lights up
- 11:16Speaker 1: with all these open ports.
- 11:17Speaker 2: Right. It looks like a Christmas tree. But if you
- 11:19Speaker 2: have Iptables running and correctly configured, you can tell it
- 11:23Speaker 2: to explicitly block everything except, say, port 22 for your
- 11:28Speaker 2: admin login.
- 11:29Speaker 1: So when Nmap scans that firewalled server, it only sees
- 11:33Speaker 1: the one port. Exactly.
- 11:35Speaker 2: But here is the really fun trick with Iptables. You
- 11:38Speaker 2: have a choice in how you block the traffic. You
- 11:40Speaker 2: can reject it or you can drop it.
- 11:43Speaker 1: Okay, what's the difference?
- 11:43Speaker 2: If you reject a packet, the firewall politely replies to
- 11:47Speaker 2: the scanner and says, sorry, this port is closed.
- 11:49Speaker 1: Which is nice, but it still tells the scanner that
- 11:51Speaker 1: a server exists there.
- 11:53Speaker 2: Right. But if you set the rule to ddrawp, it
- 11:56Speaker 2: acts like a black hole. It silently discards the packet
- 11:59Speaker 2: and sends absolutely nothing back.
- 12:00Speaker 1: Oh, I love that.
- 12:02Speaker 2: It's brutal for the scanner because nmap gets no response.
- 12:05Speaker 2: So it has to wait for a timeout period on
- 12:07Speaker 2: every single port it tries. The scan takes exponentially longer
- 12:10Speaker 2: and it gets zero information. It just stalls out.
- 12:13Speaker 1: You're just actively frustrating the hacker.
- 12:15Speaker 2: Exactly.
- 12:15Speaker 1: But wait, let me push back on this for a second.
- 12:18Speaker 1: External firewalls handle the perimeter, right? They sit at the
- 12:21Speaker 1: edge of the network. So why are we configuring Iptables
- 12:24Speaker 1: locally on the individual server? Like if my laptop is
- 12:27Speaker 1: already on the company Wi-Fi, the perimeter is bypassed. I
- 12:30Speaker 1: can just pull up my terminal and run a nap
- 12:32Speaker 1: against the internal HR server right now. Basically, the call
- 12:36Speaker 1: is coming from inside the house.
- 12:38Speaker 2: And that right there is exactly why we use local firewalls.
- 12:41Speaker 2: You cannot trust the inside of your network. We call
- 12:43Speaker 2: it defending against targets of opportunity.
- 12:45Speaker 1: Because an insider threat is just as dangerous.
- 12:49Speaker 2: Often more dangerous. An internal firewall protects that specific server
- 12:53Speaker 2: from disgruntled employees or, you know, maybe a co-worker's laptop
- 12:57Speaker 2: got compromised by malware or just curious insiders poking around
- 13:01Speaker 2: where they shouldn't be.
- 13:02Speaker 1: So you operate under the assumption that the inside of
- 13:04Speaker 1: your network is just as hostile as the public Internet.
- 13:07Speaker 2: You have to. If your database only ever talks to
- 13:10Speaker 2: your app server, you use Iptables to block literally every
- 13:14Speaker 2: other internal IP address in the building.
- 13:17Speaker 1: Wow. Okay, we have covered a massive amount of technical
- 13:20Speaker 1: ground today. Let's kind of trace the full journey here.
- 13:23Speaker 1: We started deep inside the Linux kernel, turning on our
- 13:26Speaker 1: internal security cameras with Audit.
- 13:28Speaker 2: Yep, establishing that baseline visibility.
- 13:31Speaker 1: Right. And then we used Audictil to set precision traps
- 13:34Speaker 1: on critical files. We learned how to translate all that
- 13:37Speaker 1: dense server speak into plain English using Ausurge. And then
- 13:41Speaker 1: we stepped outside to pressure test our own perimeter using
- 13:44Speaker 1: Nmap and Imptables.
- 13:45Speaker 2: It's a complete 360-degree view.
- 13:48Speaker 1: It really is. So to reinforce this knowledge, I want you,
- 13:51Speaker 1: the listener, to do a quick mental exercise. Imagine you
- 13:54Speaker 1: open your own command line right now to look for
- 13:57Speaker 1: failed logins on your machine. What usernames do you think
- 14:00Speaker 1: a bot might try to guess? And more importantly, what
- 14:03Speaker 1: single-letter flag must you add to your command to make
- 14:05Speaker 1: sure the results are actually readable to you.
- 14:07Speaker 2: Give it a second.
- 14:08Speaker 1: It's the dash I flag for interpret.
- 14:12Speaker 2: The magic wand.
- 14:13Speaker 1: Exactly. But before we go, I want to leave everyone
- 14:16Speaker 1: with a final thought to ponder. Now that you know
- 14:18Speaker 1: how rich this audit data is and how these scanners work,
- 14:21Speaker 1: imagine if an artificial intelligence was constantly reading those or
- 14:25Speaker 1: report summaries in real time.
- 14:26Speaker 2: Oh, that is the future. Right.
- 14:28Speaker 1: Like, could an AI theoretically identify a port scan happening
- 14:32Speaker 1: and dynamically rewrite your Iptible's firewall rules on the fly
- 14:36Speaker 1: to drop the hacker's IP into a black hole before
- 14:38Speaker 1: they even finish their scan?
- 14:40Speaker 2: Automated self-healing networks. When AI fully meets cybersecurity, that's exactly
- 14:45Speaker 2: where we're heading. It's fascinating.
- 14:47Speaker 1: It really is. Well, thank you for taking this deep
- 14:49Speaker 1: dive into system security with us. Go check your digital
- 14:52Speaker 1: door handles, make sure your local firewalls are dropping packets,
- 14:55Speaker 1: and we will catch you on the next one.