Latest / CyberCode Academy / Course 3 - Mastering Nuclei for Bug Bounty | Episode 5: Matching Conditions in the Body and Header
Transcript
- 0:00Speaker 1: Welcome back to the deep dive. You know, for a
- 0:02Speaker 1: while now we've spent a lot of time talking about
- 0:05Speaker 1: how automated tools kind of observe the Internet.
- 0:09Speaker 2: Yeah, sending out those get requests just asking for web
- 0:12Speaker 2: pages or data passive retrieval.
- 0:15Speaker 1: Exactly passive. But today we're shifting gears. We're talking about
- 0:20Speaker 1: active participation, actually submitting data like filling out a form,
- 0:24Speaker 1: but doing it automatically using the post method.
- 0:29Speaker 2: And this is where things get well a lot more
- 0:31Speaker 2: interesting and frankly more complex for automation, right, especially in
- 0:35Speaker 2: security testing or building reliable workflows. Oh so, well, think
- 0:39Speaker 2: about it. You send data to the server using PST.
- 0:42Speaker 2: Maybe you're trying to log in or run a search
- 0:44Speaker 2: or trigger some API function. How does your program, your
- 0:47Speaker 2: script actually know if it worked?
- 0:49Speaker 1: Ah right, You can't just send it and hope for
- 0:52Speaker 1: the best.
- 0:52Speaker 2: Precisely, success isn't just getting a response back. Was it
- 0:55Speaker 2: the right response? Did the server actually do what you asked?
- 0:58Speaker 2: Did your test find what you were looking for?
- 1:00Speaker 1: Okay? So you need more than just a two hundred
- 1:02Speaker 1: okay status code?
- 1:03Speaker 2: Way more. You need specific customized matching rules, rules that
- 1:08Speaker 2: tell your tool exactly what to look for and where
- 1:10Speaker 2: to look for it to confirm success or failure.
- 1:13Speaker 1: Gotcha, and that's our mission for you today, the listener.
- 1:16Speaker 1: We're going to unpack how you can write templates that
- 1:18Speaker 1: define a post request and then crucially set up precise
- 1:22Speaker 1: conditions to match the response. We'll look at checking two
- 1:25Speaker 1: different places, the response bodies, the main content and the
- 1:28Speaker 1: response header. The sort of metadata.
- 1:31Speaker 2: Yep body and header matching for post requests.
- 1:34Speaker 1: Okay, let's unpack this. So first, thing's first structure. If
- 1:38Speaker 1: we want automation to handle these post requests reliably, we
- 1:41Speaker 1: probably need a standard way to define them.
- 1:44Speaker 2: You need a clear framework. Most robust templating systems for
- 1:48Speaker 2: this kind of thing rely on like four main parts.
- 1:50Speaker 2: Four blocks. You got an ID, just a unique name,
- 1:54Speaker 2: then info which gives it a human readable name and
- 1:57Speaker 2: maybe some description. Then the request block.
- 1:59Speaker 1: This is the core action that's where we define the
- 2:01Speaker 1: post itself exactly.
- 2:03Speaker 2: And finally, the matches block. This is where you define
- 2:06Speaker 2: what success looks like, the validation part.
- 2:09Speaker 1: All right, So let's dive into that request block. For
- 2:11Speaker 1: a post it, it's obviously different from.
- 2:13Speaker 2: A geet fundamentally, First, you must explicitly set the method
- 2:17Speaker 2: to post. That's non negotiable. It tells the server, hey,
- 2:20Speaker 2: I'm sending data, not just asking for a page, and then.
- 2:23Speaker 1: The data itself. It doesn't go into URL like with
- 2:26Speaker 1: the euket does it.
- 2:27Speaker 2: Nope. That's the other big difference. The data goes in
- 2:29Speaker 2: the request body. It's payload. So if you're simulating filling
- 2:33Speaker 2: out a search form maybe looking for Apple, okay, your
- 2:37Speaker 2: request body might literally contain the string search Apple, just
- 2:41Speaker 2: that key value pair.
- 2:42Speaker 1: Simple enough, But sending that body isn't quite enough, is it?
- 2:46Speaker 1: The server needs context?
- 2:47Speaker 2: Oh, definitely not enough. This is a super common stumbling block.
- 2:50Speaker 2: You need headers, specific headers that describe the body you're sending,
- 2:54Speaker 2: like what Well, Crucially, content type. This tells the server
- 2:58Speaker 2: how the body is formatted. For that search Apple example,
- 3:01Speaker 2: which is standard web form data. The content type would
- 3:04Speaker 2: likely be application xdetch www form Erlin coded right.
- 3:08Speaker 1: Tell us the server to expect those key value pairs
- 3:10Speaker 1: separated by amper sands and.
- 3:12Speaker 2: Equal signs exactly. Get that wrong or format the body
- 3:16Speaker 2: in a way that doesn't match the content type, and
- 3:18Speaker 2: the server might just poof ignore it or throw an error.
- 3:21Speaker 1: Silent failures are the worst.
- 3:23Speaker 2: They really are and another critical one is content length.
- 3:26Speaker 1: AH, telling the server exactly how big the body.
- 3:29Speaker 2: Is yep invites. If this number doesn't perfectly match the
- 3:33Speaker 2: actual size that the data in the body, the server
- 3:35Speaker 2: often gets confused. It might cut off reading early or
- 3:38Speaker 2: just reject the whole thing. So method post the data
- 3:43Speaker 2: in the body and the correct content type and content
- 3:45Speaker 2: length headers. That's the basic package for a post request.
- 3:49Speaker 1: Right, requests sent successfully. Now the confirmation part, the matches block.
- 3:53Speaker 1: How do we check if our Apple search actually worked?
- 3:56Speaker 2: So for a basic check, we usually look for two things. First,
- 3:59Speaker 2: the one the HTDP status code. We typically want a
- 4:03Speaker 2: two hundred ok means the server received and processed the
- 4:06Speaker 2: request without a major server side.
- 4:08Speaker 1: Meltdown standard success signal.
- 4:10Speaker 2: Right, but that's not enough on its own. Second, we
- 4:13Speaker 2: need to validate the content in our template. We'd add
- 4:16Speaker 2: a condition saying find the word Apple somewhere within the
- 4:19Speaker 2: response body.
- 4:20Speaker 1: Okay, So we're looking for our search term echoed back
- 4:22Speaker 1: to us in the HML or whatever the server sent
- 4:25Speaker 1: back precisely.
- 4:26Speaker 2: And this isn't just checking for a random word. It's
- 4:28Speaker 2: often about confirming reflection you sent Apple. Did the server
- 4:32Speaker 2: acknowledge that by including Apple in its response, maybe in
- 4:36Speaker 2: a message like you searched for.
- 4:38Speaker 1: Apple, I see. So confirming reflection is a key step.
- 4:42Speaker 1: Why is that so important, especially thinking about.
- 4:44Speaker 2: Security, Well, it's fundamental for spotting certain vulnerabilities. If you
- 4:48Speaker 2: can send some input like a test string, and see
- 4:51Speaker 2: it reflected unchanged in the response body, that's often the
- 4:55Speaker 2: very first indicator of potential issues like cross site scripting.
- 4:58Speaker 1: Exss AH, because if the server echoes back input without
- 5:02Speaker 1: cleaning it, it might echo back malicious script too.
- 5:05Speaker 2: Exactly. So, confirming that basic reflection, just seeing your input
- 5:09Speaker 2: appear in the output is a crucial first validation step.
- 5:12Speaker 2: You've confirmed the data made the round trip.
- 5:14Speaker 1: That makes sense. Now what if what if the match
- 5:17Speaker 1: doesn't happen? You think everything's right, but the template fails.
- 5:20Speaker 1: How do you figure out what went wrong? When it's
- 5:21Speaker 1: all automated.
- 5:22Speaker 2: Yeah, debugging automation can be tricky. This is where having
- 5:26Speaker 2: good tooling really matters. Often there's a debug flag you
- 5:29Speaker 2: can use, maybe like underbug.
- 5:31Speaker 1: When you run the template, and what does that show you?
- 5:33Speaker 2: It pulls back the curtain. Basically, it should show you
- 5:35Speaker 2: the entire exchange. You'd see the exact request that was set.
- 5:38Speaker 2: Sometimes even as a CURL command, you could copy and
- 5:40Speaker 2: run yourself.
- 5:41Speaker 1: Oh it's handy.
- 5:41Speaker 2: Yeah, and you'd see the full request hutters, the raw
- 5:44Speaker 2: response headers that came back, the status code, the full
- 5:47Speaker 2: response body, and critically, it would show you exactly why
- 5:51Speaker 2: the match failed or if it succeeded. Confirmed that yes,
- 5:56Speaker 2: it found Apple in the body and the status was
- 5:58Speaker 2: two hundred.
- 5:59Speaker 1: So you get full transparency, you know if the problem
- 6:01Speaker 1: is your template logic or the server's actual behavior.
- 6:05Speaker 2: Exactly essential for troubleshooting.
- 6:08Speaker 1: Okay, so that covers matching in the body, we send data,
- 6:11Speaker 1: we check the status, we look for our data reflected
- 6:13Speaker 1: in the main content. Seems straightforward enough for confirming visible results. Yeah,
- 6:17Speaker 1: but you mentioned looking somewhere else, right, And.
- 6:20Speaker 2: Here's where it gets really interesting. I think sometimes the
- 6:23Speaker 2: most important signal, the real confirmation, isn't in the visible
- 6:28Speaker 2: page content at all.
- 6:29Speaker 1: Where is it?
- 6:30Speaker 2: Then it's hidden away in the response headers, the metadata
- 6:33Speaker 2: the server sends back along with the body.
- 6:36Speaker 1: Hmm, okay, why would the confirmation be there?
- 6:39Speaker 2: Think about actions that don't necessarily change what you see,
- 6:42Speaker 2: but change the application state, Like maybe a successful API
- 6:46Speaker 2: call returns a two O four no content status, there's
- 6:49Speaker 2: no body to check h good or maybe a successful
- 6:52Speaker 2: log in doesn't change the page much, but the server
- 6:55Speaker 2: sets a new session cookie in the response header, or
- 6:57Speaker 2: an internal process completes and sets a custom header flag
- 7:01Speaker 2: like ex operation status success.
- 7:04Speaker 1: I see. So things like tokens, cookies, custom status flags,
- 7:08Speaker 1: stuff that controls the application behind the scenes, often lives
- 7:11Speaker 1: in the headers.
- 7:12Speaker 2: Precisely, if you're writing a template to say, automatically grab
- 7:16Speaker 2: a security token after logging in, you wouldn't look for
- 7:18Speaker 2: that token displayed on the page, right, That would be
- 7:21Speaker 2: bad security.
- 7:22Speaker 1: Definitely not You'd expect it in a cookie or maybe
- 7:24Speaker 1: a specific authorization.
- 7:25Speaker 2: Header exactly, So you need your matching role to look there.
- 7:28Speaker 2: This is about validating application state, not just visual presentation.
- 7:32Speaker 1: So how did the template change the request part the
- 7:36Speaker 1: pat method path body? That probably stays the same largely.
- 7:41Speaker 2: Yeah, you're still sending the same search Apple data for instance.
- 7:46Speaker 2: The action is identical. The difference is entirely in the
- 7:48Speaker 2: matches block.
- 7:49Speaker 1: Okay, so we still check for the two hundred status code.
- 7:52Speaker 2: Presumably usually yeah or whatever status indicates success for that action.
- 7:56Speaker 2: But the key is the word match condition. You can't
- 7:59Speaker 2: just say find, you have to tell it where to
- 8:01Speaker 2: look exactly. You need to add a parameter often called
- 8:03Speaker 2: part and set it explicitly to header. So part dot header.
- 8:08Speaker 2: Now the matching engine completely ignores the response.
- 8:11Speaker 1: Body becomes much more focused.
- 8:13Speaker 2: Right. It just scans through the response header lines looking
- 8:16Speaker 2: for your target string.
- 8:17Speaker 1: And in a real world case, we're probably not just
- 8:19Speaker 1: looking for Apple randomly in any header, are we? Probably not?
- 8:22Speaker 2: Although the example works to illustrate the mechanic. More typically
- 8:25Speaker 2: be looking for a specific value within a known header,
- 8:29Speaker 2: like checking if the set cookie header contains SESSIONID, or
- 8:32Speaker 2: if a custom header X transaction idea exists, or like
- 8:36Speaker 2: our source mentioned, maybe a specific value like Apple was
- 8:39Speaker 2: put into a custom header. Say exert reflected Apple purely
- 8:43Speaker 2: as a conformation flag.
- 8:44Speaker 1: Got it. So it allows for a really precise checking
- 8:47Speaker 1: of these non visible but crucial system markers.
- 8:50Speaker 2: Absolutely, it's about understanding that conformation can come in different forms.
- 8:55Speaker 2: Sometimes it's visible reflection in the body. Other times it's
- 8:58Speaker 2: a flag, a token, or a state change indicated purely
- 9:00Speaker 2: in the headers. You need the flexibility to check both.
- 9:04Speaker 1: So body matching confirms input reflection, header matching confirms system
- 9:08Speaker 1: state or control signals.
- 9:10Speaker 2: That's a great way to put it.
- 9:11Speaker 1: Yeah, Okay, if we connect this to the bigger picture mastering, this,
- 9:15Speaker 1: being able to precisely define where you're looking for confirmation
- 9:18Speaker 1: body or a header seems absolutely fundamental for anyone doing
- 9:22Speaker 1: serious security testing or building reliable automation for modern web
- 9:25Speaker 1: apps and APIs.
- 9:27Speaker 2: It really is simple. Checks aren't enough anymore. Applications are complex.
- 9:31Speaker 2: You need that precision in your validation to trust your
- 9:33Speaker 2: automated results, whether it's finding a visible clue in the
- 9:36Speaker 2: body or a hidden flag in the header. Template based
- 9:40Speaker 2: matching gives you that power for post requests.
- 9:43Speaker 1: All right, So let's wrap up with a little thought
- 9:44Speaker 1: exercise for you, the listener. Imagine you're writing a template
- 9:48Speaker 1: to check if a password reset was successful. Okay, the
- 9:52Speaker 1: user submits their new password with a POSD. The server,
- 9:56Speaker 1: on success does two things. It sends back a redirect,
- 10:00Speaker 1: say a three to two status code, sending them to
- 10:02Speaker 1: log in page, and it invalidates their old session cookie,
- 10:06Speaker 1: setting a new temporary one in the response headers.
- 10:08Speaker 2: Right, standard flow.
- 10:09Speaker 1: So the question is to absolutely confirm that the password
- 10:12Speaker 1: reset logic work correctly. Specifically, the part about managing the
- 10:16Speaker 1: session state invalidating the old cookie setting the new one.
- 10:19Speaker 1: Which matching method, body or header would be the most
- 10:22Speaker 1: efficient and necessary place to look? And why is focusing
- 10:25Speaker 1: there critical? Hmmm?
- 10:27Speaker 2: Yeah, think about where that cookie information actually lives. Is
- 10:30Speaker 2: it something you'd typically see on the resulting log in page?
- 10:33Speaker 1: Consider those scenarios where the real proof of success is
- 10:36Speaker 1: hidden from the user's view. Getting comfortable with specifying your
- 10:40Speaker 1: matched location body or header is key to leveling up
- 10:43Speaker 1: your automation skills.
- 10:44Speaker 2: Definitely something to ponder.
- 10:46Speaker 1: Thanks for diving deep with us today.