Latest / CyberCode Academy / Course 30 - Practical Malware Development - Beginner Level | Episode 5: Building and Securing the Control Panel Dashboard
Transcript
- 0:00Speaker 1: You know, when you're clicking around the web, checking a
- 0:01Speaker 1: server status or maybe logging into a remote work portal,
- 0:05Speaker 1: you get this illusion of solidity.
- 0:08Speaker 2: Oh absolutely. You see these highly polished dashboards and you
- 0:10Speaker 2: just kind of assume there's this impenetrable monolithic fortress holding
- 0:14Speaker 2: it all together.
- 0:15Speaker 1: Right, But underneath all that shiny CSS, it's really just
- 0:20Speaker 1: a fragile series of locked doors, invisible bouncers and well
- 0:25Speaker 1: filing cabinets just passing fragmented notes back and forth.
- 0:29Speaker 2: Yeah, it's remarkably modular. When you actually break it down,
- 0:31Speaker 2: and once you see how those pieces communicate, that whole
- 0:34Speaker 2: fortress illusion just vanishes exactly.
- 0:37Speaker 1: And that's why today we're taking you on a deep dive.
- 0:40Speaker 1: We are mentally walking through the exact steps to build
- 0:43Speaker 1: a secure, functional web based control panel from scratch.
- 0:46Speaker 2: Where we're exploring the foundational code you need to know
- 0:49Speaker 2: authenticate a user, manage their session securely, and generate a
- 0:53Speaker 2: dynamic dashboard.
- 0:54Speaker 1: And in the source architecture we're looking at this dashboard
- 0:57Speaker 1: tracks connected systems which the code refers to as victims
- 1:02Speaker 1: or bots. But to be clear, this is going to
- 1:05Speaker 1: be an immersive, step by step audio walkthrough.
- 1:07Speaker 2: Yeah, we're translating the raw logic MYCEQL database injection, PHP
- 1:12Speaker 2: session handling, HTML integration completely optimized for your ear no
- 1:17Speaker 2: screen required.
- 1:18Speaker 1: And understanding how this is built step by step. It
- 1:21Speaker 1: really demystifies how web apps work under the.
- 1:23Speaker 2: Hood, right well completely. It highlights all those hidden security
- 1:26Speaker 2: mechanisms that keep systems safe or well, are supposed to
- 1:30Speaker 2: keep them Senfey.
- 1:30Speaker 1: Right, supposed to. So let's lock the front door. First,
- 1:33Speaker 1: we're setting up the database credentials picture this. We're in
- 1:37Speaker 1: the terminal connected to our database service, and we need
- 1:40Speaker 1: to insert our very first user into an empty user's table.
- 1:43Speaker 2: Yeah, and we use the standard mice we'll insert into
- 1:46Speaker 2: command for that. We're targeting the ID, the username, and
- 1:49Speaker 2: the password columns.
- 1:50Speaker 1: So for this first user, we just set the ID
- 1:52Speaker 1: to one and the username to admin.
- 1:55Speaker 2: Pretty simple exactly. But the password that's where things get interesting.
- 1:59Speaker 1: Okay, let's unpack this because storing plain text passwords is
- 2:02Speaker 1: a terrible idea. I mean, if a thread actor dumps
- 2:05Speaker 1: that table, they just have the exact passwords, right.
- 2:07Speaker 2: Yeah, they instantly compromise every user. So instead of saving
- 2:10Speaker 2: the literal password, the code uses a hashing function.
- 2:13Speaker 1: It's basically like putting a highly sensitive document through a
- 2:18Speaker 1: cryptographic paper shredder. You can't just put the shreds back together.
- 2:21Speaker 2: That's a great way to look at it. And the
- 2:22Speaker 2: specific hashing algorithm used in this SQL query is MD five.
- 2:27Speaker 1: Right, So they're wrapping the password value in the MD
- 2:30Speaker 1: five function right in the seqal syntax.
- 2:32Speaker 2: Yeah, And for this initial setup, the source uses a
- 2:34Speaker 2: temporary string. It literally uses the phrase change me, which
- 2:38Speaker 2: then gets hashed by the database.
- 2:40Speaker 1: Wait, change me, Okay, I mean MB five is already
- 2:43Speaker 1: a mathematically broken hash function, right, pretty outdated it is.
- 2:47Speaker 2: Yeah, from a modern security posture, it's definitely a legacy choice.
- 2:51Speaker 2: You normally want b crypt or r GONE two.
- 2:54Speaker 1: So why use it for a command and control panel?
- 2:57Speaker 2: Well, in lightweight, rapid deployment environments, which militia's infrastructure often,
- 3:01Speaker 2: a speed and simplicity win, MD five is natively supported
- 3:04Speaker 2: almost everywhere without extra libraries.
- 3:06Speaker 1: I guess that makes sense. It's just a quick lock
- 3:08Speaker 1: on a single door. But there's a massive flashing red
- 3:11Speaker 1: warning here about that change.
- 3:13Speaker 2: Me stringth Oh, absolutely, you must change that to a
- 3:16Speaker 2: complex password immediately after logging in.
- 3:18Speaker 1: Because if you don't your panel is just begging to
- 3:22Speaker 1: be hacked by automated scanners within hours. I mean, default
- 3:26Speaker 1: credentials are arguably the biggest attack factor out there.
- 3:29Speaker 2: Yeah, the math of the vault door could be perfect,
- 3:32Speaker 2: but leaving the password has change me is like it's
- 3:35Speaker 2: like having a retinal scanner but leaving the physical key
- 3:38Speaker 2: under the mat exactly.
- 3:39Speaker 1: Okay, So we run the query and then we verify
- 3:41Speaker 1: it with selectrom users. We see ID one admin and
- 3:45Speaker 1: that scrambled MT five hash.
- 3:46Speaker 2: Right, and then you test it in the browser. You
- 3:49Speaker 2: type admin and change me. The back end hashes it,
- 3:52Speaker 2: matches it to the database and redirect you to index
- 3:55Speaker 2: dot php.
- 3:56Speaker 1: Boom rinn. But there's a huge flaw here if we
- 4:00Speaker 1: just stop.
- 4:01Speaker 2: Now right, a massive structural vulnerability.
- 4:03Speaker 1: Yes, because what if someone just bypasses the login entirely.
- 4:06Speaker 1: It types index dot php directly into their browser.
- 4:09Speaker 2: Yeah, without session control, the web server doesn't care. It
- 4:12Speaker 2: has no memory. It just serves the index dot php
- 4:16Speaker 2: file to whoever asks for it.
- 4:17Speaker 1: So we have to build a bouncer something that checks
- 4:20Speaker 1: the guest list before showing the dashboard exactly.
- 4:23Speaker 2: And the expert source creates a dedicator file for this
- 4:26Speaker 2: called session dot PHP. The very first step is using
- 4:29Speaker 2: the session start.
- 4:30Speaker 1: Function, so that basically wakes up the server's temporary memory.
- 4:33Speaker 2: Right right. It establishes continuity. Then it uses an if
- 4:36Speaker 2: statement to check if the username value is actually set
- 4:39Speaker 2: using the isset.
- 4:40Speaker 1: Function, and this is the aha security detail. If issit
- 4:44Speaker 1: comes back false, meaning they didn't log in, the code
- 4:48Speaker 1: kicks into high gear.
- 4:49Speaker 2: Yeah, it executes a sequence. First, it destroys the session
- 4:52Speaker 2: with session destroy. Then it uses the header function to
- 4:54Speaker 2: redirect the browser back to the log in page.
- 4:57Speaker 1: Well wait, it doesn't stop there after the redirect. It
- 5:00Speaker 1: crucially calls the die function to kill the page.
- 5:02Speaker 2: Yes, that is a vital step.
- 5:04Speaker 1: If we've already told the browser to redirect, why do
- 5:07Speaker 1: we need DYE is redirect basically just putting up a
- 5:10Speaker 1: closed sign, whereas de is actually pulling down the metal
- 5:13Speaker 1: security gate.
- 5:14Speaker 2: That's wow. Yeah. What's fascinating here is that that analogy
- 5:18Speaker 2: is perfectly accurate. A redirect is just a suggestion to
- 5:21Speaker 2: the browser.
- 5:22Speaker 1: Oh wow, so an attacker could just ignore it exactly.
- 5:25Speaker 2: They use tools to intercept or drop redirect operations. If
- 5:29Speaker 2: you don't use DYE, the server might just keep processing
- 5:32Speaker 2: and send the rest of the h'd email bashboard anyway.
- 5:34Speaker 1: So die completely severs the data flow. The metal gate
- 5:37Speaker 1: slams down.
- 5:38Speaker 2: Right, it's a non negotiable security mechanism. So we take
- 5:42Speaker 2: this session dot php file. We put it at the
- 5:44Speaker 2: very top of index dot php and if you try
- 5:47Speaker 2: to visit the page directly, you're kicked out.
- 5:49Speaker 1: Perfect, So the perimeter secure. Now we actually have to
- 5:52Speaker 1: build the dashboard UI inside index dot php.
- 5:55Speaker 2: Yeah, we need a structured way to display the data,
- 5:58Speaker 2: so we use a standard HTMI table with t car
- 6:01Speaker 2: for rows and two four headers.
- 6:03Speaker 1: And we have four specific headers. Right, host name, IP address,
- 6:07Speaker 1: operating system.
- 6:07Speaker 2: And action exactly. Though, if you just render that natively,
- 6:11Speaker 2: it looks pretty terrible.
- 6:12Speaker 1: Oh yeah, the source points out it's pretty ugly by default,
- 6:15Speaker 1: just mash together text. So we fix that with a
- 6:17Speaker 1: simple CSS style tag.
- 6:19Speaker 2: Right, yeah, just give the cells a one pixel solid
- 6:21Speaker 2: border and wrap the whole thing in a center tag.
- 6:23Speaker 2: Basic but functional.
- 6:25Speaker 1: Okay, So the table looks decent, but it's empty. How
- 6:29Speaker 1: do we get the actual data from the database into
- 6:32Speaker 1: those rows?
- 6:32Speaker 2: We bring in our database connection with a con dot
- 6:35Speaker 2: php file. Then we use the query method to send
- 6:39Speaker 2: a command select from victims.
- 6:42Speaker 1: But that just gives us a huge raw blob of data.
- 6:45Speaker 1: How do we dynamically populate our table rows continuously without
- 6:49Speaker 1: breaking everything.
- 6:50Speaker 2: That's where the wile loop comes in, combined with the
- 6:52Speaker 2: fetchasock function.
- 6:53Speaker 1: Oh right, associative array right exactly.
- 6:55Speaker 2: It reaches into the database results, grabs one single row,
- 6:59Speaker 2: and maps the fields like host name and IP to
- 7:02Speaker 2: PHP variable.
- 7:03Speaker 1: Oh that's incredibly efficient. So you just dynamically echo those
- 7:06Speaker 1: variables right into the HTML table data tags.
- 7:08Speaker 2: You got it. It prints the row for one machine,
- 7:10Speaker 2: cycles it back to the top of the loop, grabs
- 7:12Speaker 2: the next machine, and just keeps streaming until the data
- 7:16Speaker 2: is done.
- 7:16Speaker 1: That is seamless. Yeah, but we need to talk about
- 7:19Speaker 1: that fourth column, the action column. Yeah, because this isn't
- 7:22Speaker 1: just for looking at data.
- 7:23Speaker 2: Now. This is where the panel becomes an active command
- 7:26Speaker 2: and control interface. We need to create an interactive HTML
- 7:30Speaker 2: anchor tag a link that says.
- 7:32Speaker 1: Manage, right, But how does the back end know which
- 7:35Speaker 1: machine you want to manage when you click it?
- 7:36Speaker 2: It uses dynamic routing. We set the href attribute to
- 7:40Speaker 2: direct to a file called managed dot php, but we
- 7:43Speaker 2: append a dynamic variable to the url ah.
- 7:46Speaker 1: Like dot bot followed by the specific host name for.
- 7:50Speaker 2: That exact row exactly, so the link actually looks like
- 7:52Speaker 2: manage dot php dot bot serberalpha. That ensures the script
- 7:56Speaker 2: knows exactly which system to target.
- 7:58Speaker 1: That's clever, But building that dynamic string, mixing HTML quotes
- 8:01Speaker 1: and PHP variables, it's super easy to mess up. Yeah,
- 8:05Speaker 1: and there's a highly relatable moment in the code creation here.
- 8:08Speaker 2: Oh, the debugging phase. Yes, bugs happen to everyone, right.
- 8:12Speaker 1: The developer inserts dummy data into the terminal just typing
- 8:15Speaker 1: abc to test the table. They refresh the page and
- 8:19Speaker 1: the whole table is just completely broken.
- 8:22Speaker 2: Yeah, because a single closing quote mark was accidentally forgotten
- 8:25Speaker 2: on that HRF attribute and a tr tag got misplaced.
- 8:28Speaker 1: It just swallowed the rest of the HTML trying to
- 8:31Speaker 1: find the end of the quote. It's so relatable, and.
- 8:33Speaker 2: The takeaway there is that small syntax errors like a
- 8:36Speaker 2: missing quote are entirely normal. The key is just methodical testing.
- 8:41Speaker 1: Once that quote is closed, boom, the page renders perfectly
- 8:44Speaker 1: a nice list of connected systems with clickable management links.
- 8:48Speaker 2: It really highlights the practical reality of coding.
- 8:50Speaker 1: It does, and that brings us to the end of
- 8:53Speaker 1: the build. So to you listening, I have a quick
- 8:55Speaker 1: review question. Think back to our security gate analogy.
- 8:59Speaker 2: Oh this is a good one.
- 9:00Speaker 1: Yeah, if you are building a secure page, what is
- 9:03Speaker 1: the specific PHP function you must call after a head
- 9:06Speaker 1: or redirect to ensure an attack or can't bypass it
- 9:09Speaker 1: and load the page anyway?
- 9:10Speaker 2: Give them second to think about it.
- 9:11Speaker 1: Did you get it?
- 9:12Speaker 2: It's die You have to kill the script. Absolutely essential.
- 9:15Speaker 2: And you know, if we connect this to the bigger picture,
- 9:18Speaker 2: it's really profound.
- 9:19Speaker 1: Oh.
- 9:20Speaker 2: So, the exact same architecture we just built, the authentication,
- 9:23Speaker 2: the session tracking, the dynamic database rendering. It's all used
- 9:28Speaker 2: to build legitimate corporate.
- 9:29Speaker 1: IT dashboard right for network admins.
- 9:31Speaker 2: But it's also the exact same architecture used for a
- 9:35Speaker 2: malicious botnet command and control center. Code is completely agnostic.
- 9:40Speaker 1: Wow. Yeah, it's just a tool. It's the intent of
- 9:43Speaker 1: the admin that defines it exactly.
- 9:45Speaker 2: As you design your own systems, consider how the line
- 9:47Speaker 2: between administration and exploitation often just comes down to who
- 9:51Speaker 2: holds that session key.
- 9:52Speaker 1: That's a great thought to end on. Thank you so
- 9:54Speaker 1: much for joining us on this deep dive into the
- 9:56Speaker 1: underlying architecture of the web. We will catch you next time.