Latest / CyberCode Academy / Course 39 - NodeJS Security Pentesting and Exploitation | Episode 2: Mitigating RCE, OS Injection, and Path Traversal Vulnerabilities
Transcript
- 0:00Speaker 1: Welcome to today's deep dive. Imagine you have just finished
- 0:04Speaker 1: building an impenetrable digital fortress.
- 0:06Speaker 2: Right like, totally locked down exactly.
- 0:08Speaker 1: You've got state of the art firewalls, complex authentication protocols,
- 0:12Speaker 1: I mean, the works. It's practically a titanium vault.
- 0:15Speaker 2: It sounds pretty secure, you'd think so.
- 0:18Speaker 1: But just to let legitimate users communicate with the people
- 0:22Speaker 1: inside the vault, you leave this tiny, seemingly harmless mail
- 0:26Speaker 1: slot open in the front door.
- 0:28Speaker 2: Okay, I see where this is going.
- 0:30Speaker 1: Yeah, and here's the catch. What if the guards inside
- 0:34Speaker 1: that fortress have been trained to blindly obey absolutely any
- 0:38Speaker 1: instructions slip through that slot.
- 0:40Speaker 2: Oh wow, that's a huge problem.
- 0:42Speaker 1: Right, someone just slides in a note that says, unlock
- 0:44Speaker 1: the vault, turn off the alarms, and throw the keys outside.
- 0:47Speaker 1: If the guard just does it without questioning who wrote
- 0:49Speaker 1: the note, your entire titanium fortress falls in seconds.
- 0:52Speaker 2: In seconds, yea.
- 0:53Speaker 1: And in the digital world, that mail slot is basically
- 0:56Speaker 1: user input. So today we are doing a deep diving
- 0:59Speaker 1: to why trusting what users type into your web applications,
- 1:03Speaker 1: especially node environments, yes, specifically node environments. Why trusting that
- 1:09Speaker 1: is just a recipe for a catastrophic hack. We're gonna
- 1:11Speaker 1: break down exactly how these vulnerabilities work step by step.
- 1:15Speaker 3: You know that mail slot analogy is exactly the problem
- 1:17Speaker 3: with modern software development. I mean, we spend massive amounts
- 1:20Speaker 3: of time building these complex, highly secure architectures, but the
- 1:24Speaker 3: failure point is often astonishingly.
- 1:26Speaker 1: Simple just taking the data at phase value.
- 1:29Speaker 3: Exactly taking user data at face value. So today we
- 1:33Speaker 3: are really looking closely at the mechanics of these cyber attacks.
- 1:37Speaker 3: We aren't just going to catalog what happens when systems fail.
- 1:40Speaker 3: We need to understand the underlying logic of why trusting
- 1:43Speaker 3: user input is inherently flawed, because it's.
- 1:46Speaker 1: Not just a checklist, right, No, not at all.
- 1:48Speaker 3: When you understand the actual mechanisms at play, you stop
- 1:51Speaker 3: seeing security as just a compliance checklist and you start
- 1:56Speaker 3: seeing it as a fundamental engineering mindset.
- 1:58Speaker 1: Okay, let's look at how this actually plays out on
- 2:00Speaker 1: a server. Then where do we even start, Like, what's
- 2:03Speaker 1: the most direct way a developer might accidentally tell that
- 2:06Speaker 1: guard to just blindly read the note.
- 2:08Speaker 3: Well, the most direct, and I'd argue the most devastating
- 2:12Speaker 3: way is by taking whatever the user types in and
- 2:15Speaker 3: instantly executing it as raw code, just running it, just
- 2:18Speaker 3: running it. In JavaScript and note environments, this usually happens
- 2:21Speaker 3: through a built in function called Evil. You know, it's
- 2:24Speaker 3: short for.
- 2:25Speaker 2: Evaluate, right.
- 2:26Speaker 3: It basically takes a standard string of text and runs
- 2:29Speaker 3: it as if it were actual programmed JavaScript code.
- 2:33Speaker 1: Okay, I've seen Evil use before, mostly in code that
- 2:36Speaker 1: runs on the client side, like right in a user's
- 2:39Speaker 1: web browser. If a hacker puts malicious code into a
- 2:42Speaker 1: browser's evil function, what's the actual blast radius there?
- 2:47Speaker 3: So if untrusted input gets into a client side Evil,
- 2:50Speaker 3: it's definitely bad. But the browser has built in sandboxes.
- 2:53Speaker 1: Oh okay, so it's contained.
- 2:55Speaker 3: The damage is largely contained. It's kind of like someone
- 2:57Speaker 3: trashing their own hotel rooms. Bad for them, and it's
- 3:00Speaker 3: bad for that specific room, but the rest of the
- 3:02Speaker 3: hotel is perfectly fine. The attacker can really only manipulate
- 3:05Speaker 3: that specific user session on that specific web page.
- 3:08Speaker 1: So if they just trash their own hotel room in
- 3:10Speaker 1: the browser, what happens if we move that exact same
- 3:14Speaker 1: scenario to the server, Like say a developer uses Evil
- 3:18Speaker 1: on their node back end to process some incoming data.
- 3:20Speaker 3: Oh, man, if a piece of untrusted input passes through
- 3:24Speaker 3: the evil function on your node server, you are done. Really, Yeah,
- 3:28Speaker 3: that sandboxing of the browser does not exist there. The
- 3:31Speaker 3: attacker essentially owns the server.
- 3:33Speaker 1: Wow.
- 3:33Speaker 3: And it's really critical to note that it's not just
- 3:36Speaker 3: the literal word evil you have to watch out for.
- 3:39Speaker 3: There are related functions in node that pose the exact
- 3:42Speaker 3: same threat if you feed user input into them, like
- 3:45Speaker 3: what things like set interval, set time out, and creating
- 3:48Speaker 3: a new function. If untrusted strings get evaluated through any
- 3:52Speaker 3: of those mechanisms, you're handing them the keys to the kingdom.
- 3:55Speaker 1: Okay, let's make this concrete for everyone listening. Imagine we're
- 3:59Speaker 1: looking at the code for a basic node server running locally,
- 4:01Speaker 1: maybe on port eight thousand using express sure, and the
- 4:05Speaker 1: server has a root that reads a web parameter from
- 4:07Speaker 1: the URL. Let's just call it the name parameter, and
- 4:10Speaker 1: the developer maybe they're just testing something.
- 4:12Speaker 2: Quickly, right right, happens all the time they.
- 4:15Speaker 1: Pass that name parameter directly into the evil function. What
- 4:18Speaker 1: is the very first thing an attacker does when they
- 4:21Speaker 1: find a mail slot like that?
- 4:23Speaker 3: So their first goal might just be sheer disruption, like
- 4:26Speaker 3: a denial of service or dos attack, and they don't
- 4:30Speaker 3: need complex hacking tools for this. They could simply put
- 4:33Speaker 3: while one into that name parameter.
- 4:35Speaker 1: Wait while one, that's just an infinite loop. Why does
- 4:38Speaker 1: an infinite loop from one user crash the whole server?
- 4:41Speaker 1: I mean, shouldn't it just freeze that one person's request
- 4:44Speaker 1: while everyone else keeps using the site.
- 4:45Speaker 3: In a lot of programming languages, yes, it would just
- 4:48Speaker 3: tie up one thread. But JavaScript and by extension, Node
- 4:52Speaker 3: is single threaded.
- 4:54Speaker 1: Oh right.
- 4:54Speaker 3: Think of a single threaded server like a coffee shop
- 4:57Speaker 3: with exactly one incredibly fast barista. Okay, this barista can
- 5:02Speaker 3: serve thousands of customers a minute because they switch between
- 5:05Speaker 3: tasks instantly. But if one customer orders a drink that
- 5:08Speaker 3: takes infinite.
- 5:09Speaker 1: Time to make, which is what while one.
- 5:12Speaker 3: Is exactly the barista just stands there, spinning in circles forever,
- 5:17Speaker 3: the line behind them stops moving Entirely, the server freezes.
- 5:21Speaker 3: It literally cannot process any other user's requests.
- 5:24Speaker 1: That is terrifyingly simple. Or I suppose if the attacker
- 5:28Speaker 1: doesn't want to just freeze the server, they could just
- 5:30Speaker 1: turn it off.
- 5:30Speaker 2: Oh easily.
- 5:31Speaker 3: NOE has a global object called process, which controls the
- 5:34Speaker 3: running application, right, so the attacker could just send process
- 5:37Speaker 3: dot kill or process dot exit boom. Instantly, the server
- 5:41Speaker 3: process terminates, the website goes down, all from someone typing
- 5:45Speaker 3: a few words into the web address.
- 5:46Speaker 1: Bar Crashing a server is bad, But I mean, if
- 5:50Speaker 1: I'm a hacker, crashing the server means I can't play
- 5:52Speaker 1: with it anymore. I don't want to break the toy,
- 5:54Speaker 1: I want to control it exactly. So how do we
- 5:56Speaker 1: go from a barista spinning in circles to the attacker
- 6:00Speaker 1: totally taking over the machine.
- 6:02Speaker 3: Well, that leads us to remote code execution or RCEE.
- 6:05Speaker 3: An attacker who finds an evil vulnerability really wants a
- 6:09Speaker 3: command prompt on your server. But there's a hurdle, which
- 6:12Speaker 3: is firewalls. Usually, if you want to control a server,
- 6:15Speaker 3: you connect to it. You type in the server's IP address,
- 6:18Speaker 3: provide credentials, and the server gives you a.
- 6:20Speaker 1: Shell right normal access.
- 6:22Speaker 3: But firewalls are like bouncers looking out the front door.
- 6:25Speaker 3: They are specifically designed to block unauthorized incoming connections. They
- 6:30Speaker 3: stop the attacker from reaching in, so.
- 6:32Speaker 1: The attacker can't just knock on the front door and
- 6:34Speaker 1: ask for a command prompt. How do they get around
- 6:37Speaker 1: the bouncer?
- 6:38Speaker 3: They use something called a reverse shell or reverse shell. Yeah,
- 6:40Speaker 3: it completely flips the script. Instead of the attacker connecting
- 6:44Speaker 3: to the victim's server, the attacker tricks the victims server
- 6:47Speaker 3: into connecting out to them.
- 6:49Speaker 1: Wait, tricking the server into calling out. How does the
- 6:52Speaker 1: attacker actually set up that trap?
- 6:54Speaker 2: First?
- 6:54Speaker 3: The attacker needs to be ready to receive the call,
- 6:56Speaker 3: so on their own machine, they open a terminal and
- 6:59Speaker 3: run a network utility.
- 7:01Speaker 2: Often its tool.
- 7:01Speaker 1: Called netcat okay netcit.
- 7:03Speaker 3: The command might look like ankdash L four three four three.
- 7:07Speaker 3: This simply tells the attacker's own computer, Hey, listen on
- 7:11Speaker 3: port four three four three and wait for an incoming connection.
- 7:14Speaker 1: So they're just sitting there with the phone off the hook,
- 7:16Speaker 1: basically waiting for it to ring.
- 7:18Speaker 2: Exactly, just waiting.
- 7:20Speaker 3: Next, they need the victim to actually make the call,
- 7:23Speaker 3: so the attacker uses a script to generate a payload.
- 7:26Speaker 1: What's a payload look like? This?
- 7:28Speaker 3: Paiload is essentially a block of node code that says,
- 7:31Speaker 3: open a network connection to the attacker's IP address on
- 7:34Speaker 3: port four three four to three, and pipe my system's
- 7:37Speaker 3: internal command prompt through that connection.
- 7:39Speaker 1: Oh wow. Yeah.
- 7:41Speaker 3: They take this payload, which usually looks like a long
- 7:43Speaker 3: string of encoded characters, and they slide it right into
- 7:47Speaker 3: that vulnerable name parameter in the weburl And.
- 7:51Speaker 1: Because our node server is running evil on whatever comes through.
- 7:54Speaker 2: That parameter, it executes it immediately.
- 7:56Speaker 1: It just reads the payload and runs it. Yep.
- 7:59Speaker 3: Suddenly on the attackers screen, they're waiting. Netcat listener lights up.
- 8:04Speaker 3: The connection is established. The attacker now has a live
- 8:07Speaker 3: command prompt running on the victims server just like that.
- 8:10Speaker 3: Just like that, they can type one me to see
- 8:13Speaker 3: what user account they are operating under. They can type
- 8:16Speaker 3: l's dash l to browse the server's.
- 8:19Speaker 1: Directories, and the firewall doesn't stop this because from the
- 8:23Speaker 1: firewalls perspective, the server itself initiated an outbound connection right
- 8:28Speaker 1: which is usually loud for things like you know, downloading
- 8:31Speaker 1: updates or connecting the databases.
- 8:33Speaker 2: You've got it.
- 8:34Speaker 3: The attacker completely bypassed the firewall and they now control
- 8:38Speaker 3: the victim's machine, limited really only by the permissions of
- 8:42Speaker 3: the account running the node process.
- 8:44Speaker 1: Okay, so any developer listening to this is probably getting
- 8:46Speaker 1: spooked right now and saying, fine, I will never use email,
- 8:49Speaker 1: I will never evaluate raw code.
- 8:51Speaker 2: Which is a good reaction.
- 8:52Speaker 1: Yeah, but what if they aren't trying to evaluate JavaScript
- 8:56Speaker 1: at all. Let's see a developer is building a network
- 8:59Speaker 1: dashboard and they legitimately need the server to run a
- 9:02Speaker 1: basic operating system command, like they want the server to
- 9:06Speaker 1: ping an IP address to see if a router is online.
- 9:09Speaker 1: Totally normal feature, right, that's totally normal. Is that safe?
- 9:13Speaker 3: It's a very common requirement, but it is entirely unsafe
- 9:15Speaker 3: if you don't handle the user's input correctly in node.
- 9:19Speaker 3: To execute Linux or Unix system commands, developers often use
- 9:22Speaker 3: a function from the child process module called exec.
- 9:25Speaker 1: Okay, let's look at the code for that. Picture a
- 9:28Speaker 1: server running on port eight eight eight eight. It's a
- 9:31Speaker 1: simple network diagnostic tool. The user types inn IP address
- 9:35Speaker 1: into a form and the server runs a ping command.
- 9:38Speaker 1: Behind the scenes, okay, I'm picturing it. The developer probably
- 9:41Speaker 1: writes code that stitches together the string ping dash c two,
- 9:45Speaker 1: which means ping this address twice, and then just depends
- 9:49Speaker 1: whatever IP address the user provided.
- 9:51Speaker 3: That is the exact setup I see all the time.
- 9:53Speaker 3: They can catenate the string ping dash c two with
- 9:57Speaker 3: the user's input say one to a seven point zero
- 9:59Speaker 3: point one one. Then they pass that entire constructed string
- 10:02Speaker 3: into tile process dot exec and.
- 10:04Speaker 1: For normal user typing a normal IP address, it works perfectly, right,
- 10:07Speaker 1: they get their ping results displayed on the screen.
- 10:09Speaker 2: It works like a charm.
- 10:11Speaker 1: But the developer didn't use evil here. They're just asking
- 10:14Speaker 1: the service operating system to run a harmless pin command.
- 10:17Speaker 1: So how does an attack or break a tool that
- 10:19Speaker 1: only knows how to ping?
- 10:20Speaker 3: The vulnerability here isn't actually in note, it's in how
- 10:23Speaker 3: the operating system's command line shell interprets special characters. The
- 10:26Speaker 3: attacker doesn't just provide an IP address. They provide an
- 10:29Speaker 3: IP address followed by a semi colon followed by a
- 10:32Speaker 3: completely different command.
- 10:33Speaker 1: A semicolon. Why does the operating system care about a
- 10:36Speaker 1: semi colon?
- 10:37Speaker 3: In a Unix based shell, a semicolon acts as a
- 10:40Speaker 3: command separator. It literally tells the operating system finish executing
- 10:44Speaker 3: the command on the left, and then immediately execute the.
- 10:47Speaker 2: Command on the right.
- 10:48Speaker 3: Oh no, So the attacker inputs one hundred and twenty
- 10:51Speaker 3: seven zero point one semicolon cat slash et cetera, slash password.
- 10:55Speaker 1: Wait, cat slash et cetera slash password. Why that specific file?
- 11:00Speaker 1: What is so special about the password file that a
- 11:02Speaker 1: hacker would want it?
- 11:03Speaker 3: Well, the cat command just means read this file and
- 11:05Speaker 3: print it out, and et cetera. Password is a core
- 11:07Speaker 3: Linux system file that lists all the user accounts on
- 11:10Speaker 3: the machine. Okay, historically it also contained the passwords, but
- 11:14Speaker 3: even today, seeing the list of users, service accounts, and
- 11:17Speaker 3: system configurations gives an attacker a massive blueprint of your server.
- 11:21Speaker 3: It is basically the first step in figuring out how
- 11:24Speaker 3: to escalate their privileges.
- 11:25Speaker 1: Okay, so let's trace this back. The node server builds
- 11:28Speaker 1: the string. It literally creates the sentence ping dash C
- 11:32Speaker 1: two one twenty seven point zero point one semicolon cat
- 11:36Speaker 1: slash et cetera, slash password exactly because the developer didn't
- 11:40Speaker 1: check the input. The node server just blindly passes this
- 11:43Speaker 1: entire string to child process dot exec yes, and.
- 11:46Speaker 3: The operating system receives it and reads it from left
- 11:49Speaker 3: to right. It says, okay, first, I will ping the
- 11:51Speaker 3: local host twice.
- 11:52Speaker 2: Done. Oh look a semi colon. That means I have
- 11:55Speaker 2: a new chore.
- 11:55Speaker 1: Now I have to do this other thing right.
- 11:57Speaker 3: Now, I will read the password file and print it
- 11:59Speaker 3: to the output, and the node server obediently takes that
- 12:02Speaker 3: output and spits it right back to the web application,
- 12:05Speaker 3: displaying the sensitive system data right to the hacker man.
- 12:09Speaker 1: It's like sneaking a secondary instruction into the envelope. The
- 12:11Speaker 1: system thinks it's doing its job, but it's actually been
- 12:14Speaker 1: completely hijacked.
- 12:15Speaker 2: That's OS command injection in a nutshell.
- 12:18Speaker 1: So how do we fix this? If a developer legitimately
- 12:21Speaker 1: needs to run a system command like ping, how do
- 12:24Speaker 1: they stop the semicolon from working as dark magic?
- 12:27Speaker 3: The fix requires changing how you hand the data to
- 12:30Speaker 3: the operating system in the first place. Instead of using
- 12:33Speaker 3: child process dot exec, developers should use alternative functions provided
- 12:38Speaker 3: by node, specifically exec file or spawn.
- 12:41Speaker 1: Wait, how does using a different function actually stop the semicolon?
- 12:45Speaker 1: I mean, don't execs file and spawn just run commands too.
- 12:48Speaker 3: They do run commands, but it's how they handle the arguments.
- 12:51Speaker 3: When you use the vulnerable exec function, you pass the
- 12:54Speaker 3: entire command as one big raw string. The shell gets
- 12:57Speaker 3: to interpret the whole sentence, which means it actively looks
- 13:01Speaker 3: for special punctuation like semicolons. But when you use xfilall
- 13:05Speaker 3: or spawn. You don't pass a single string. You pass
- 13:08Speaker 3: the name of the executable file like PING, and then
- 13:12Speaker 3: you pass the user's input separately as elements within an array.
- 13:15Speaker 1: Oh, an array like a strictly formatted list.
- 13:17Speaker 3: Precisely, you are explicitly telling the system here is the
- 13:20Speaker 3: exact tool I want to run, and here is a
- 13:22Speaker 3: sealed box containing the exact data points to feed into
- 13:26Speaker 3: that tool.
- 13:26Speaker 1: That's smart.
- 13:27Speaker 3: By treating the user input as discrete elements within an array,
- 13:31Speaker 3: you completely bypass the shell's string parsing behavior. The system
- 13:35Speaker 3: sees the semi colon not as a command separator, but
- 13:38Speaker 3: just as a literal text character that happens to be
- 13:41Speaker 3: part of the IP address.
- 13:42Speaker 1: Ah. So the PIN tool will try to literally ping
- 13:46Speaker 1: a network address named one twenty seven point zero point
- 13:49Speaker 1: one semicolon cat slash etc, slash password, which obviously makes
- 13:54Speaker 1: no sense exactly.
- 13:55Speaker 3: The ping command will just fail because that's not a
- 13:57Speaker 3: valid IP format, and the attack stops in its tracks.
- 14:01Speaker 3: The secondary command is never executed.
- 14:02Speaker 1: That's so clean.
- 14:03Speaker 2: Yeah.
- 14:04Speaker 3: And of course, in addition to using exex file, you
- 14:06Speaker 3: should always validate the input. If you expect an IP address,
- 14:09Speaker 3: use code to verify that the string actually matches the
- 14:13Speaker 3: format of an IP address before you do anything else
- 14:15Speaker 3: with it.
- 14:15Speaker 1: This makes a lot of sense. So we've seen how
- 14:18Speaker 1: attackers hijack raw code with Evil and how they hijack
- 14:21Speaker 1: system commands by injecting semicolons. But in both of those cases,
- 14:25Speaker 1: the server is actively executing something. What if I'm a
- 14:27Speaker 1: developer and I decide my application isn't going to execute
- 14:31Speaker 1: anything at all, no Evil, no system commands. What if
- 14:34Speaker 1: my application merely takes user input and echoes it back
- 14:37Speaker 1: to the screen like a search bar that says you
- 14:39Speaker 1: searched for X. That has to be safe, right.
- 14:42Speaker 3: It feels like it should be safe because the server
- 14:44Speaker 3: isn't running the input, But unfortunately, trust and user input
- 14:47Speaker 3: is always dangerous. If you blindly echo data back to
- 14:51Speaker 3: a user, you open the door to cross site scripting
- 14:53Speaker 3: or EXSS.
- 14:54Speaker 1: How does echoing a word back to the screen turn
- 14:57Speaker 1: into a hack? I don't get that.
- 14:59Speaker 3: Imagine a server it takes a name parameter from the
- 15:01Speaker 3: URL and blindly drops it into the HTML response it
- 15:04Speaker 3: sends back to the browser. The server code basically says hello,
- 15:08Speaker 3: whatever name was provided. It does no filtering, no escaping.
- 15:10Speaker 3: So if you type bob, the page says hello Bob.
- 15:13Speaker 1: Very simple.
- 15:14Speaker 3: But an attacker doesn't input a name. They input raw HTML.
- 15:18Speaker 3: For instance, they could input an image tag with a
- 15:20Speaker 3: malicious script embedded inside it, something that looks like open
- 15:24Speaker 3: bracket mngsrc equals x on error equals alert hacked closed bracket.
- 15:30Speaker 1: So the server just takes that chunk of code, assumes
- 15:33Speaker 1: its weird name, and drops it right into the HTML
- 15:35Speaker 1: document it's building exactly.
- 15:37Speaker 3: The server doesn't care, it's just processing text. But the
- 15:40Speaker 3: problem happens when that response reaches the victim's browser. Your
- 15:44Speaker 3: browser's rendering engine reads HTML from top to bottom. When
- 15:49Speaker 3: it hits that injected image tag, it tries to load
- 15:52Speaker 3: the image source, which is just X.
- 15:54Speaker 2: It fails to.
- 15:55Speaker 3: Find an image named x, so it fires the owner event.
- 16:00Speaker 3: And what did the attacker put in the own error event?
- 16:02Speaker 1: JavaScript?
- 16:02Speaker 2: JavaScript?
- 16:03Speaker 1: And the browser just runs it.
- 16:04Speaker 3: The browser doesn't know this script is malicious. It just thinks, ah,
- 16:07Speaker 3: the server told me to run this code. If the
- 16:09Speaker 3: image breaks, the attacker has just forced the victim's browser
- 16:12Speaker 3: to execute their malicious code.
- 16:14Speaker 1: Okay, an alert box popping up saying hacked is annoying,
- 16:17Speaker 1: But how does an image tag actually steal.
- 16:20Speaker 3: Data because JavaScript running in your browser has access to
- 16:24Speaker 3: the browser's memory for that specific website. This includes your
- 16:28Speaker 3: session cookies. Think of a session cookie like a temporary
- 16:31Speaker 3: ID badge that keeps you logged into your bank or
- 16:34Speaker 3: your email. If an attacker can force your browser to
- 16:37Speaker 3: run their JavaScript, they can write a script that says,
- 16:40Speaker 3: grab this user's ID badge and silently mail it to
- 16:44Speaker 3: my hacker server.
- 16:45Speaker 2: In the background. Oh wow, Yeah, they take your cookie, plug.
- 16:48Speaker 3: It into their own browser, and suddenly they are logged
- 16:50Speaker 3: into your account without ever needing your password. And it
- 16:53Speaker 3: all happened because the server blindly echoed untrusted data.
- 16:58Speaker 1: That is incredible. The server wasn't compromise at all. The
- 17:00Speaker 1: server was just used as a mirror to bounce a
- 17:03Speaker 1: weapon directly at the user.
- 17:04Speaker 3: That is the essence of cross site scripting. The browser
- 17:07Speaker 3: is acting as a confused deputy carrying out the attackers
- 17:10Speaker 3: orders because it trusts the server.
- 17:12Speaker 1: Okay, so echoing data is dangerous. Look at one final mechanism.
- 17:15Speaker 1: What about just reading static files. Let's say we have
- 17:18Speaker 1: an application that uses the filesystem modules in node to
- 17:21Speaker 1: load documents based on a user's request sure, so the
- 17:24Speaker 1: URL might look like load equals document dot pdf. A
- 17:28Speaker 1: server reads that file and sends it to the user.
- 17:31Speaker 3: It's a very standard way to serve static assets. The
- 17:34Speaker 3: developer uses a function like path dot join to combine
- 17:37Speaker 3: the intended folder directory with the user's input, so it
- 17:40Speaker 3: knows exactly where to look.
- 17:42Speaker 1: Well, wait, doesn't the operating system automatically sandbox the web
- 17:45Speaker 1: server into its own dedicated folder, Like if the server
- 17:49Speaker 1: is installed in a folder called slash web slash public.
- 17:52Speaker 1: It can't just go snooping around the rest of the
- 17:54Speaker 1: hard drive, right.
- 17:55Speaker 3: That is a very dangerous and very common false assumption. Really,
- 18:00Speaker 3: by default, the application has the filesystem permissions of the
- 18:03Speaker 3: user account that ran the node process, unless the system
- 18:07Speaker 3: administrator has explicitly locked it down, which is harder than
- 18:10Speaker 3: it sounds. The application can theoretically read anything that user
- 18:14Speaker 3: account can read anywhere on the hard drive.
- 18:15Speaker 1: Oh but the developer wrote the code to say, look
- 18:19Speaker 1: in the slash web slash public folder for the file
- 18:22Speaker 1: the user requested, How does the attacker break out of
- 18:25Speaker 1: that folder?
- 18:25Speaker 3: By exploiting a feature built into almost every operating system's
- 18:29Speaker 3: filepath structure, the dot dot slash and a filepath dot
- 18:33Speaker 3: dot slash essentially means go upstairs.
- 18:35Speaker 2: It means move up one directory level.
- 18:37Speaker 1: Oh, I see where this is going.
- 18:38Speaker 3: If the application blindly joins the requested file name to
- 18:42Speaker 3: the directory path without sanitizing it, the attacker doesn't ask
- 18:46Speaker 3: for document dot pdf. They ask for dot dot dot
- 18:50Speaker 3: dot dot slash, dot dot slash dot dot slash, et cetera,
- 18:54Speaker 3: slash password.
- 18:55Speaker 1: So instead of just looking for a file, the input
- 18:58Speaker 1: is actively given the operating system navigation instructions. It says, Okay,
- 19:02Speaker 1: start in the slash web slash public folder, but then
- 19:05Speaker 1: climb backward out of it, go upstairs one level, ghostcares
- 19:08Speaker 1: another level until you hit the root of the hard drive,
- 19:11Speaker 1: and then go down into the center of folder and
- 19:13Speaker 1: grab the password file.
- 19:15Speaker 3: Precisely, this is called directory triversal. The attacker is literally
- 19:18Speaker 3: traversing your directory structure, climbing out of the intended web route,
- 19:23Speaker 3: and accessing highly sensitive files that were never meant to
- 19:26Speaker 3: be public.
- 19:26Speaker 1: So if we step back and look at this entire journey,
- 19:29Speaker 1: the pattern is wild. We started with the immediate death
- 19:32Speaker 1: of a server via an infinite loop and evil. Then
- 19:35Speaker 1: we saw how a reverse shell completely bypasses firewalls. From there,
- 19:39Speaker 1: we looked at how attackers can sneak semicolon instructions into
- 19:42Speaker 1: harmless pin commands. We saw how echoing a name can
- 19:45Speaker 1: weaponize a user's browser to steal their ID badges, and
- 19:49Speaker 1: finally we saw how do dot slash can turn a
- 19:52Speaker 1: simple file request into a map that leads right to
- 19:55Speaker 1: your system passwords. The mechanisms are all wildly different.
- 19:59Speaker 3: They are different mechanisms, but the root cause is identical
- 20:02Speaker 3: in every single case, whether it's remote code execution, OS
- 20:06Speaker 3: command injection, cross site scripting, or directory traversal. The vulnerability
- 20:11Speaker 3: exists because a developer failed to treat user input as
- 20:14Speaker 3: a toxic substance.
- 20:15Speaker 1: A toxic substance, I like that.
- 20:17Speaker 3: That is the golden rule of web security. Never trust
- 20:20Speaker 3: untrusted user input. You must always filter it, escape it,
- 20:24Speaker 3: or sanitize it based on the specific context of your application.
- 20:27Speaker 3: You simply cannot assume the user will play by the
- 20:30Speaker 3: rules you imagined.
- 20:31Speaker 1: It goes right back to the titanium fortress with the
- 20:33Speaker 1: mail slot, the moment you process a piece of paper
- 20:36Speaker 1: coming through that slot as an instruction, rather than just
- 20:39Speaker 1: inspecting it as raw harmless information. You surrender control of
- 20:43Speaker 1: your entire system exactly.
- 20:44Speaker 3: Security isn't just about the thickness of your walls. It's
- 20:48Speaker 3: about paying rigorous attention to the data you allow through
- 20:50Speaker 3: the front door.
- 20:51Speaker 1: So as we wrap up this deep dive, I want
- 20:53Speaker 1: to leave you with a review question to test what
- 20:55Speaker 1: we've covered. Think about the applications you interact with are
- 20:58Speaker 1: the ones you might be building. You are creating a
- 21:00Speaker 1: simple web form right now, just a basic search bar.
- 21:03Speaker 1: Based on what we discussed today, what specific concrete steps
- 21:07Speaker 1: would you take in your code to ensure that if
- 21:09Speaker 1: a user types a semicolon, a scriptag, or a dot
- 21:12Speaker 1: dot slash into that search bar, your server treats it
- 21:15Speaker 1: purely as harmless text and never ever as an executable instruction.
- 21:20Speaker 1: Take a moment to think through that logic, Keep questioning
- 21:23Speaker 1: the systems around you, and we'll catch you on the
- 21:25Speaker 1: next deep dive.