Latest / CyberCode Academy / Course 3 - Mastering Nuclei for Bug Bounty | Episode 8: Nuclei File-Based Templates: Implementing Content Matching and Secret Extraction
Transcript
- 0:00Speaker 1: If you're deep in the tech world, you know, programming, cybersecurity,
- 0:05Speaker 1: you've almost certainly had that feeling. Oh yeah, that moment
- 0:09Speaker 1: a massive code repository gets dropped on your desk, thousands
- 0:12Speaker 1: of files, and your job is defined just one tiny thing,
- 0:17Speaker 1: one tiny critical thing, exactly like I forgotten apikey, a
- 0:21Speaker 1: hard coded password, some secret token, a developer left behind
- 0:24Speaker 1: by accident.
- 0:25Speaker 2: The needle in a haystack is.
- 0:26Speaker 1: The ultimate needle in a haystack problem. Yeah, and trying
- 0:29Speaker 1: to use manual code review or even you know, command
- 0:32Speaker 1: line tools like REP it just falls apart at scale.
- 0:35Speaker 2: It doesn't work.
- 0:36Speaker 1: Okay, let's unpack this today. We are diving into a powerful,
- 0:40Speaker 1: really structured way to handle this. It shifts the whole
- 0:43Speaker 1: game from manual review to automated file analysis using templates, right.
- 0:47Speaker 2: And what's so fascinating here is that most people when
- 0:50Speaker 2: they hear templates, they think about network stuff, right, like
- 0:52Speaker 2: checking HTTP requests.
- 0:53Speaker 1: Yeah, analyzing traffic.
- 0:55Speaker 2: But the exact same structured approach can be pointed directly
- 0:58Speaker 2: at static files, you know, files just sitting on your
- 1:01Speaker 2: hard drive.
- 1:01Speaker 1: So you're taking that same logic and just aiming it
- 1:03Speaker 1: somewhere new precisely.
- 1:05Speaker 2: We're talking about automating. How you analyze a whole code
- 1:08Speaker 2: base to find that sensitive info buried deep inside.
- 1:11Speaker 1: That pivot is key. So traditionally these templates look at
- 1:16Speaker 1: what's happening on the wire. If we want to shift
- 1:19Speaker 1: from looking at network traffic to local files, how does
- 1:23Speaker 1: this system actually change its approach. Is it just a
- 1:26Speaker 1: little switch you flip.
- 1:27Speaker 2: It's a bit more profound than a tweak. It's more
- 1:30Speaker 2: of an architectural redirection. The core engine, the part that
- 1:33Speaker 2: does the analysis, that stays the same. Okay, but you
- 1:36Speaker 2: swap out the input handler. So instead of the system
- 1:38Speaker 2: listening for network packets, you tell it to look at
- 1:40Speaker 2: local directories. This is usually done with a dedicated file
- 1:44Speaker 2: block in the configuration.
- 1:45Speaker 1: So that block basically says, hey, your target is the
- 1:48Speaker 1: file system.
- 1:49Speaker 2: Now that's it. Exactly.
- 1:50Speaker 1: When I hear scope, though, I immediately think about the
- 1:53Speaker 1: pain of searching huge directories. Code bases can be massive,
- 1:57Speaker 1: Oh absolutely, they have everything from tiny config files two
- 2:01Speaker 1: huge log files or media assets. How do you manage
- 2:04Speaker 1: that trade off between speed and making sure you don't
- 2:07Speaker 1: miss something.
- 2:08Speaker 2: That's where you have to have really good scope management.
- 2:11Speaker 2: You have to be able to tell the tool precisely
- 2:14Speaker 2: what files it should even bother looking at.
- 2:16Speaker 1: Okay, so you define the targets.
- 2:17Speaker 2: First, right, First, you define the target files. You can
- 2:20Speaker 2: get specific with file extensions like say only look at
- 2:23Speaker 2: files ending in dot PI or JS or do EML.
- 2:26Speaker 1: But what if you don't know what if you're doing
- 2:28Speaker 1: a broad sweep.
- 2:29Speaker 2: Well, in that case, you can just use a wildcard,
- 2:32Speaker 2: a match all directive that tells it to look at
- 2:34Speaker 2: every single file type. It finds that.
- 2:36Speaker 1: Flexibility is great, but I can't afford to have my
- 2:39Speaker 1: system spend three hours trying to parse like a five
- 2:43Speaker 1: gigabyte video.
- 2:44Speaker 2: File, right, and it probably doesn't have a token in
- 2:46Speaker 2: it anyway.
- 2:47Speaker 1: Exactly, So how do we constrain that.
- 2:49Speaker 2: That's where two really vital constraints come in. The first
- 2:52Speaker 2: is a size limit. It's often called max size. Okay,
- 2:55Speaker 2: you set a threshold, say five megabytes. If a file
- 2:58Speaker 2: is bigger than that, the analyt just sticks it and
- 3:01Speaker 2: that immediately prevents slowdowns from massive logs or binaries. And
- 3:06Speaker 2: the second constraint, the second one, is about depth. It's
- 3:09Speaker 2: recursion control. You can just disable the system's ability to
- 3:13Speaker 2: recursively dig down into subdirectories.
- 3:15Speaker 1: Ah, so if you only want to look at the
- 3:18Speaker 1: top level files.
- 3:19Speaker 2: Exactly, super useful. If you think the sensitive data is
- 3:23Speaker 2: only in those top level configuration files and not buried
- 3:27Speaker 2: ten folders deep.
- 3:28Speaker 1: That makes perfect sense. So we've locked down which files
- 3:31Speaker 1: to read, what size to ignore. Now that the system
- 3:34Speaker 1: knows what to analyze, we have to tell it what
- 3:37Speaker 1: we're actually searching for inside that content. This is the
- 3:40Speaker 1: real heart of it, the matching.
- 3:41Speaker 2: Absolutely, the matches are the keywords or the patterns that
- 3:44Speaker 2: confirm something is there. And there are two main ways
- 3:47Speaker 2: to do it.
- 3:47Speaker 1: Okay.
- 3:47Speaker 2: The first is a word match. This is the most
- 3:50Speaker 2: straightforward one. It just looks for the exact whole word
- 3:53Speaker 2: inside the file.
- 3:54Speaker 1: So that'd be for finding known things like a variable name,
- 3:57Speaker 1: database password.
- 3:58Speaker 2: Exactly, or a secret key, something static that you know
- 4:01Speaker 2: the name of.
- 4:02Speaker 1: And the second type, I'm guessing this is the one
- 4:03Speaker 1: that gives us the real power, is for finding things
- 4:06Speaker 1: that look more like you know, random strings or complex
- 4:09Speaker 1: IDs precisely.
- 4:11Speaker 2: The second is the regular expression or rejects match, and
- 4:14Speaker 2: that's all about pattern matching. It is so useful for
- 4:17Speaker 2: things like security tokens or internal IDs, things that don't
- 4:21Speaker 2: look like dictionary words, but follow a predictable format, right like.
- 4:25Speaker 1: Maybe thirty two alpha numeric characters followed by an equal
- 4:29Speaker 1: sign or something.
- 4:29Speaker 2: That's a perfect example.
- 4:31Speaker 1: So let's run through a quick example. Say we've cloned
- 4:33Speaker 1: a repository and we run a template looking for the
- 4:35Speaker 1: word connection string. What does this output tell us? Is
- 4:39Speaker 1: it just a yep? Found it?
- 4:41Speaker 2: And this is why these structured templates are so much
- 4:44Speaker 2: better than a simple grap The output isn't just a
- 4:47Speaker 2: generic match. It tells you exactly where the match happened.
- 4:50Speaker 1: It gives you context.
- 4:51Speaker 2: It gives you the full context. It might say matchfound
- 4:53Speaker 2: dot connection string in the fileconfig dB dot json at
- 4:57Speaker 2: line number twelve.
- 4:58Speaker 1: So no more having to then open the file in
- 5:00Speaker 1: another tool to find where the match was. You save
- 5:03Speaker 1: those critical minutes. And for a security team. Why is
- 5:07Speaker 1: that specific line number so important.
- 5:09Speaker 2: Because it lets you do immediate triage and remediation. If
- 5:13Speaker 2: a dev left a hard coded user name and a file,
- 5:15Speaker 2: the template flags that exact line, you go straight to
- 5:18Speaker 2: the problem. In a big data leak or a zero
- 5:21Speaker 2: day situation, every second counts when you need to revoke
- 5:24Speaker 2: those credentials.
- 5:25Speaker 1: Okay, so finding the identifiers great, but for remediation we
- 5:29Speaker 1: usually need the actual key itself, that long string of
- 5:33Speaker 1: random characters, not just the word that points to it.
- 5:36Speaker 1: How do we get from just matching a keyword to
- 5:39Speaker 1: actually extracting the data.
- 5:40Speaker 2: This is where we bring in the extractor's block. If
- 5:43Speaker 2: matching tells you if a secret is present, extraction tells
- 5:46Speaker 2: you what the secret actually is. Oh, it's designed specifically
- 5:50Speaker 2: to pull out the content you're looking for. And just
- 5:52Speaker 2: like matches, you have two types. There's a word extractor,
- 5:55Speaker 2: which is less common, But the real star of the
- 5:57Speaker 2: show is the rejects extractor.
- 5:59Speaker 1: If we connect the to the bigger picture, then why
- 6:02Speaker 1: is extraction so much more critical than just matching?
- 6:05Speaker 2: Oh, it's non negotiable for actually fixing the problem. You
- 6:08Speaker 2: don't just want to know that an apikey exists. You
- 6:11Speaker 2: want the string itself. You need that string so you
- 6:13Speaker 2: can confirm its valid, log it as evidence, and then
- 6:16Speaker 2: go and revoke it. Knowing a file contains epic key
- 6:19Speaker 2: is kind of useless if you don't get the sixty
- 6:22Speaker 2: four character key that comes after it.
- 6:23Speaker 1: Let's walk through an example of that with a rejects
- 6:26Speaker 1: extraction let's say we're searching for an internal token that
- 6:29Speaker 1: we know always starts with token X, and then it's
- 6:32Speaker 1: followed by ten hexadecimal characters a clear pattern.
- 6:37Speaker 2: Okay, so we'd define a regular expression for exactly that structure.
- 6:40Speaker 2: The template doesn't just say yep, the pattern exists. The
- 6:43Speaker 2: extractor actually pulls out the full sequence. It would report
- 6:47Speaker 2: back token EXO one B two C three D four five.
- 6:50Speaker 1: It's like we're turning a passive metal detector which just
- 6:53Speaker 1: beeps in this an active shovel that digs up the
- 6:55Speaker 1: treasure and puts it in your hand.
- 6:57Speaker 2: That's a great analogy, and this whole method is absolutely
- 6:59Speaker 2: a set. When you're dealing with big security incidents. Analysts
- 7:03Speaker 2: download a massive data dump, like from a public.
- 7:06Speaker 1: Code leak, right with thousands of files.
- 7:08Speaker 2: Exactly, they can just point the template at that whole
- 7:10Speaker 2: cloned repository, set the extension type to all, and let
- 7:14Speaker 2: the system hunt for those complex patterns across every file type.
- 7:17Speaker 2: It saves weeks of manual work.
- 7:20Speaker 1: So what's the big takeaway here? We've seen how these
- 7:22Speaker 1: structured file based templates give you a ton of power
- 7:26Speaker 1: and efficiency. You can define exactly what you're looking for,
- 7:29Speaker 1: manage the scope, and most importantly, move from just finding
- 7:33Speaker 1: to actual actionable extraction.
- 7:36Speaker 2: Right and in a world with just so much information,
- 7:39Speaker 2: especially in these enormous codebases, you need to think critically
- 7:43Speaker 2: this template based method is. It's a necessary step up
- 7:47Speaker 2: from basic command line tools for anyone who needs to
- 7:49Speaker 2: analyze a lot of data quickly and accurately.
- 7:52Speaker 1: Before we wrap up, let's leave you with a quick
- 7:54Speaker 1: exercise just to lock these ideas in.
- 7:55Speaker 2: Okay, so imagine your task with analyzing a repository for
- 7:58Speaker 2: hard coded user ideas. You know they always start with
- 8:01Speaker 2: the letters UID, and they're followed immediately by exactly five digits.
- 8:05Speaker 2: Which type of matcher or extractor would be the best
- 8:08Speaker 2: choice and why is it better than a simple word search?
- 8:10Speaker 1: The answer there would have to be the rejex matcher
- 8:12Speaker 1: or extractor. It's because you're dealing with a pattern three
- 8:16Speaker 1: specific letters followed by a repeatable sequence of five numbers.
- 8:20Speaker 1: It's not a static single word.
- 8:21Speaker 2: You need that pattern matching intelligence definitely.
- 8:24Speaker 1: And for our final provocative thought, given how complex modern
- 8:29Speaker 1: software is, how might applying these extraction templates not just
- 8:32Speaker 1: to source code, but to all the configuration and dependency
- 8:36Speaker 1: files reveal unauthorized dependencies or even shadow access points that
- 8:40Speaker 1: a typical code review would miss. Entirely think about the
- 8:43Speaker 1: environment setup, not just the code that runs it.