Latest / CyberSecurity Summary / Black Hat Bash: Creative Scripting for Hackers and Pentesters
Transcript
- 0:00Speaker 1: There's a certain thrill, isn't there in wheeling the power
- 0:02Speaker 1: of text to command a computer?
- 0:04Speaker 2: Oh?
- 0:04Speaker 1: Absolutely, And when you apply that to security, well, it
- 0:08Speaker 1: becomes this incredibly potent skill. Definitely. So today we're plunging
- 0:13Speaker 1: into the world of Bash scripting for ethical hacking and
- 0:17Speaker 1: penetration testing. We're really focusing on that crucial first phase reconnaissance.
- 0:23Speaker 2: Yeah, the information gathering part.
- 0:25Speaker 1: Our goal here is to distill the essential knowledge from
- 0:29Speaker 1: some key materials. Understand exactly how Bash and as buddy
- 0:32Speaker 1: tools are used to get that critical first layer of
- 0:36Speaker 1: information about potential targets.
- 0:38Speaker 2: And we're drawing from resources really aimed at security pros
- 0:41Speaker 2: who want to harness Bash. It covers the whole setup too.
- 0:44Speaker 1: Write things like setting up your environment maybe WSL, Windows
- 0:47Speaker 1: Subsystem for Linux or Siguin, picking a.
- 0:51Speaker 2: Text editor, and then getting into the Bash fundamentals, variables
- 0:54Speaker 2: for storing data or raise for collections, understanding streams.
- 0:58Speaker 1: Standard input output.
- 0:59Speaker 2: Error, that kind of thing, exactly how commands talk to
- 1:02Speaker 2: each other. These basics, they're the foundation for everything else
- 1:06Speaker 2: we'll discuss.
- 1:06Speaker 1: Okay, so environment sorted command line feels hopefully a bit
- 1:10Speaker 1: less intimidating. Now the exciting part putting Bash to work
- 1:14Speaker 1: for reconnaissance, and like any assessment, first job is figuring
- 1:17Speaker 1: out who we're looking at, creating those target.
- 1:20Speaker 2: Lists precisely the materials really stressed defining the scope clearly first.
- 1:25Speaker 2: Are we talking specific IPS, whole networks.
- 1:28Speaker 1: Or domain subdomains, that sort of thing.
- 1:30Speaker 2: Exactly, And Bash actually gives us some well, surprisingly efficient
- 1:34Speaker 2: ways to generate these lists.
- 1:36Speaker 1: Okay, let's start with IPS. Say you need to hit
- 1:38Speaker 1: a range like one seventy two point one six, but
- 1:40Speaker 1: ten's part one up to dot two point four. Typing
- 1:43Speaker 1: that manually is well not ideal.
- 1:46Speaker 2: Definitely not. The sources show a few clever Bash stricks.
- 1:49Speaker 2: One uses the c command inside of for loop.
- 1:52Speaker 1: Okay, pretty straightforward, iterate the numbers output the IPS.
- 1:55Speaker 2: It works, but they're usually quicker ways, right like Bash's
- 1:57Speaker 2: brace expansion.
- 1:58Speaker 1: Ah, yes, that's much shorter.
- 2:00Speaker 2: Yeah, you could just do echo one seventy two point
- 2:02Speaker 2: one since send down one point twenty five to four.
- 2:04Speaker 2: That gives you a space separated list, but.
- 2:06Speaker 1: You probably want them on separate lines for tools.
- 2:08Speaker 2: Usually, Yes, so you pipe that echo command to says
- 2:11Speaker 2: lines replace spaces with new lines.
- 2:14Speaker 1: Simple, very neat and there was a third way, something
- 2:17Speaker 1: with print.
- 2:18Speaker 2: That's right, print line one seventy two point one six
- 2:20Speaker 2: point one zero percent might be even cleaner.
- 2:23Speaker 1: How does that work?
- 2:24Speaker 2: The per scene is a placeholder for a number and
- 2:26Speaker 2: integer Bash fills it in for each number in the braces,
- 2:30Speaker 2: and the N automatically adds the new line. No extra
- 2:33Speaker 2: formatting needed.
- 2:34Speaker 1: Clever. Okay, so that handles IP ranges. What about finding subdomains?
- 2:38Speaker 1: Organizations have tons of those.
- 2:40Speaker 2: These days, they really do. The common strategy detailed is
- 2:43Speaker 2: using a word list, you know, just a big text
- 2:45Speaker 2: file with potential subdomain names like mail, ftpwww, dev, things
- 2:51Speaker 2: like that exactly. Then the job is just sticking the
- 2:53Speaker 2: main domain name onto the end of each word in
- 2:55Speaker 2: the list. A standard Bash while read loop is perfect
- 2:58Speaker 2: for this.
- 2:59Speaker 1: So it reads a line say mail, then you echo
- 3:01Speaker 1: mail plus dot example dot.
- 3:02Speaker 2: Com yep if example dot com is your target. The
- 3:04Speaker 2: material even points to an example word list on GitHub
- 3:08Speaker 2: subdomains dash one thousand dot txt in the black Hatbash
- 3:11Speaker 2: repo useful.
- 3:12Speaker 1: Is there another way besides the loop?
- 3:14Speaker 2: Yeah? They also mentioned using said directly. You can tell
- 3:18Speaker 2: said to just appennthdomain dot example dot com to the end.
- 3:21Speaker 2: Of every single line in the wordless file does the
- 3:24Speaker 2: same thing, just a different command.
- 3:26Speaker 1: Okay, makes sense. So we've generated our lists potential targets identified.
- 3:31Speaker 1: Now we need to see which ones are actually you know,
- 3:33Speaker 1: alive and kicking host discovery.
- 3:36Speaker 2: Right, and the classic first check is ping, good old ping.
- 3:40Speaker 2: But when scripting, you need those flags to stop it
- 3:43Speaker 2: waiting forever nanac one for just one packet and timeouts yeah,
- 3:48Speaker 2: nash to W one or natch w one to set
- 3:50Speaker 2: a weight time maybe one second, so your script doesn't
- 3:52Speaker 2: just hang there if a host is down or ignoring pings.
- 3:55Speaker 1: Because they might ignore ICMP, right, firewalls.
- 3:57Speaker 2: And stuff exactly. Ping uses ICM and lots of systems
- 4:01Speaker 2: block it, so no ping response doesn't always mean the
- 4:04Speaker 2: host is offline. It's a piece of the puzzle, but
- 4:07Speaker 2: not the whole picture.
- 4:08Speaker 1: So for the local network, ping might miss things. That's
- 4:10Speaker 1: where arp scan fits in.
- 4:11Speaker 2: That's right. Arpscan is great for your local segment. It
- 4:14Speaker 2: works using ARP the Address Resolution Protocol Layer two stuff
- 4:17Speaker 2: exactly layer two, so it can spot devices even if
- 4:19Speaker 2: they're blocking pings higher up the stack. The command is
- 4:22Speaker 2: like pseudo arpscan Network twenty four I interface.
- 4:25Speaker 1: And the sources mentioned a specific lab setup.
- 4:28Speaker 2: Yeah, they used republic as the interface on the one
- 4:31Speaker 2: seventy two point one six zero point zero two four network.
- 4:35Speaker 2: In their examples, the key is ARP works locally and
- 4:39Speaker 2: can find hosts that ICMP might miss.
- 4:41Speaker 1: And they even showed how to put ARP scan in
- 4:43Speaker 1: a loop like to watch for new devices popping up.
- 4:45Speaker 2: Yes, a while loop to run ARP scan periodically if
- 4:48Speaker 2: it spots a new MSA address, it uses send mail
- 4:51Speaker 2: to fire off an email alert.
- 4:53Speaker 1: That's pretty cool. You set variables for known hosts the
- 4:55Speaker 1: network who to email.
- 4:57Speaker 2: It's a great example of automating basic network mode ing
- 5:00Speaker 2: with just Bash and standard tools. Simple but effective.
- 5:03Speaker 1: Okay, so we're building a picture of who's online. Next
- 5:05Speaker 1: logical step, what are they doing? What services are running?
- 5:08Speaker 1: Port scanning time exactly?
- 5:10Speaker 2: And the big names here are NMP, the classic and
- 5:12Speaker 2: maybe the faster rust scan for initial suitees.
- 5:15Speaker 1: MAP is the powerhouse though right blows of options.
- 5:18Speaker 2: Oh yeah, very versatile. The Decimey dis ray is highlighted.
- 5:21Speaker 2: Service version detection super useful.
- 5:23Speaker 1: Why is it so important.
- 5:24Speaker 2: Because knowing the exact software and version running on a
- 5:27Speaker 2: port lets you immediately look up known vulnerabilities for it speeds.
- 5:31Speaker 1: Things up a lot, makes sense, and you can feed
- 5:34Speaker 1: en map our target lists.
- 5:35Speaker 2: Yep. The isile filum option takes your list like the
- 5:38Speaker 2: one hundred and seventy two to sixteen to ten hosts
- 5:41Speaker 2: dot txt we talked about and scans all of them.
- 5:44Speaker 1: And the sources had a script for handling NMAP output too,
- 5:47Speaker 1: didn't they enmap to portfiles dotsh Right.
- 5:50Speaker 2: That one's quite clever. It takes nmp's output, looks for
- 5:52Speaker 2: the line saying TCP open, and then creates files named
- 5:55Speaker 2: after the port number exactly. So you get eighty dot
- 5:57Speaker 2: tx T four four three, dot tx two twenty two
- 6:00Speaker 2: dot TXD whatever ports are open, and inside each file
- 6:04Speaker 2: is the list of IP addresses that have that specific
- 6:06Speaker 2: port open.
- 6:07Speaker 1: That sounds incredibly useful for organizing results like show me
- 6:10Speaker 1: all hosts running a web server.
- 6:12Speaker 2: It really is great for prioritizing. Then there's the other script,
- 6:15Speaker 2: portwatchdog dot sh. That one shows continuous monitoring.
- 6:18Speaker 1: How does that one work?
- 6:19Speaker 2: It uses rust scan, which is really fast in a loop,
- 6:22Speaker 2: just checking if a specific port you care about opens
- 6:25Speaker 2: up on a target.
- 6:26Speaker 1: So like watching port eighty eighty on one machine exactly.
- 6:29Speaker 2: If rust scan suddenly sees it open, then the script
- 6:32Speaker 2: triggers n MAP with NSV to do a proper service
- 6:35Speaker 2: scan just on that newly open port and logs it.
- 6:38Speaker 1: Wow, like an automated trip wire for new services. Right
- 6:40Speaker 1: I remember manually digging through huge n MAP logs. Scripts
- 6:45Speaker 1: like these are game changers.
- 6:46Speaker 2: They really save a ton of time and effort. Automation
- 6:49Speaker 2: is key.
- 6:49Speaker 1: Okay, so we found open ports. Now we want to
- 6:51Speaker 1: pokem a bit, see what's actually listening.
- 6:53Speaker 2: Banner grabbing, banner grabbing yep, trying to get the service
- 6:56Speaker 2: to announce itself send back. A banner often contains software names, versions.
- 7:01Speaker 1: And the tool for that is often netcat, dot NC.
- 7:03Speaker 2: Netcat is fundamental, ncdah vip port just tries to connect
- 7:09Speaker 2: the sv gives verbose output. Many services, especially older ones
- 7:14Speaker 2: like FTP or SSH might just spit out a banner
- 7:17Speaker 2: right away. There's a script to that too, yep, netcat
- 7:19Speaker 2: banner grab dot sah to automate running NC against a
- 7:22Speaker 2: list of ips and a specific port.
- 7:24Speaker 1: What about web servers, They don't always give banners easily
- 7:26Speaker 1: with netcat true.
- 7:28Speaker 2: For eahttp, the material points to CURL specifically using the
- 7:32Speaker 2: head method because head asks for just the HTTP headers,
- 7:35Speaker 2: not the whole web page content. It's faster if you
- 7:38Speaker 2: only want info like the server.
- 7:39Speaker 1: Header AH, which often tells you if it's apatche and
- 7:42Speaker 1: jinx is exactly.
- 7:44Speaker 2: And there's a curl banner grab dot S script that
- 7:47Speaker 2: prompts for an ip in port, does the curl head
- 7:49Speaker 2: and then uses grepen oc to pull out just that
- 7:52Speaker 2: server line.
- 7:52Speaker 1: Pretty targeted.
- 7:53Speaker 2: And don't forget n MAP again. It's scripting engine.
- 7:56Speaker 1: N SE right n S.
- 7:58Speaker 2: There's a banner dot NS script. You can run nmap
- 8:00Speaker 2: svscript banner dot n S and it does the service
- 8:03Speaker 2: detection and banner grabbing together very efficient.
- 8:06Speaker 1: Okay, banners grabbed services ID. What about the OS? Can
- 8:10Speaker 1: we figure out if it's Linux, Windows, something else.
- 8:13Speaker 2: NMAP again is the main tool here. It uses TCPIP fingerprinting.
- 8:17Speaker 1: Fingerprinting how does that work? Sounds complex?
- 8:19Speaker 2: It kind of is. NMP sends specific unusual packets and
- 8:23Speaker 2: analyzes tiny details on how the target system responds, timings,
- 8:27Speaker 2: flag settings, things like that. Different operating systems have slightly
- 8:31Speaker 2: different network stacks that react uniquely.
- 8:33Speaker 1: This is like a network level fingerprint basically.
- 8:35Speaker 2: Yes, the aoflag tells nmap to try this.
- 8:38Speaker 1: OS detection and let me guess there's a script for
- 8:41Speaker 1: parsing that output.
- 8:42Speaker 2: You got it, astetection dot ssh nmap has a greppable
- 8:46Speaker 2: output format OGG. This script uses rep ac set on
- 8:50Speaker 2: that output to find the lines with host and OS
- 8:54Speaker 2: and pull out the IP and the OS gus. It
- 8:56Speaker 2: looks for certain patterns to extract the info cleanly.
- 8:59Speaker 1: It's amazing what you can learn just from how a
- 9:01Speaker 1: machine talks in the network. Okay, one last area mentioned
- 9:05Speaker 1: web applications, specifically using woppolizer.
- 9:08Speaker 2: Right, woppolizer, fantastic tool. It's all about identifying the technologies
- 9:11Speaker 2: behind a website or a web app, all kind of technology,
- 9:14Speaker 2: things like the web framework React, Angular View, the back
- 9:16Speaker 2: end language maybe PHP, NOJS, the CMS like WordPress or Druple,
- 9:22Speaker 2: JavaScript library is web servers, lots of stuff.
- 9:26Speaker 1: How does do that?
- 9:27Speaker 2: It has a database of signatures. It looks for specific
- 9:29Speaker 2: clues in the site's code, headers, cookies, scripts.
- 9:32Speaker 1: And the example usage was simple.
- 9:33Speaker 2: Yeah, just wappalizer, HTDP, dot IP, dot port. It spits
- 9:37Speaker 2: out JSON data.
- 9:38Speaker 1: Jason, you need something to read it that easily exactly.
- 9:42Speaker 2: The example pipes the JSON output to JQ, which is
- 9:45Speaker 2: a command line Jason processor. You can use JQ to
- 9:48Speaker 2: pull out just the fields you want, like the technology name,
- 9:51Speaker 2: the version it detected, and the confidence score.
- 9:53Speaker 1: So you get a nice structured list of the tech
- 9:56Speaker 1: stack that seems really valuable for figuring out where potential
- 9:59Speaker 1: weakness is as might lie later on.
- 10:01Speaker 2: Absolutely knowing the stack guides your next steps like looking
- 10:04Speaker 2: for specific vulnerabilities in those components. It complements the network
- 10:08Speaker 2: for you.
- 10:08Speaker 1: Okay, let's try and pull this all together. We've seen
- 10:11Speaker 1: how Bash acting as the glue, combined with tools like ping,
- 10:15Speaker 1: ARP scan, end map, rust scan, netcat, curl, and woppilizer, well,
- 10:21Speaker 1: it forms a seriously capable toolkit for that initial recon phase. Definitely,
- 10:25Speaker 1: we can build target lists efficiently, find out who's online,
- 10:28Speaker 1: scan for open ports and running services, grab banners for
- 10:31Speaker 1: software versions, and even make educated guesses about the OS
- 10:34Speaker 1: and web technologies.
- 10:35Speaker 2: And the core idea really is that Bash isn't just
- 10:38Speaker 2: a shell, it's a scripting language. It lets you automate
- 10:41Speaker 2: these tools, chain them together, process their output. It makes
- 10:45Speaker 2: reconnaissance scalable and much more efficient.
- 10:47Speaker 1: So understanding the tools and how to script them in
- 10:49Speaker 1: Bash is.
- 10:50Speaker 2: Crucial, absolutely essential for effective large scale information gathering. You
- 10:55Speaker 2: can't just click buttons for everything.
- 10:57Speaker 1: This deep dive has given us a really solid ground
- 11:00Speaker 1: in Bash for recon and it sounds like the source
- 11:03Speaker 1: material goes even further into vulnerability scanning, maybe exploitation.
- 11:07Speaker 2: Yeah, this is really just scratching the surface of the
- 11:09Speaker 2: initial steps.
- 11:10Speaker 1: Right. So for you listening, here's something to think about.
- 11:14Speaker 1: How could you maybe apply some of these Bash techniques,
- 11:17Speaker 1: even just the basic ideas in your own work or
- 11:20Speaker 1: areas of interest. How can they help you understand the
- 11:22Speaker 1: systems you interact with just a little bit better.
- 11:25Speaker 2: Maybe check out some of those tools and map or
- 11:27Speaker 2: woppalizer or even brows that get hub Repo mentioned it
- 11:30Speaker 2: could be a good next step.