- Podcasts
- CyberCode Academy
- Course 25 - API Python Hacking | Episode 4: Structures, Process Spawning, and Undocumented Calls
Course 25 - API Python Hacking | Episode 4: Structures, Process Spawning, and Undocumented Calls
CyberCode Academy
- February 25, 2026
- 22 min
About this episodeIn this lesson, you’ll learn about: Defining Windows Internal Structures in Python Representing structures like PROCESS_INFORMATION and…
- Defining Windows Internal Structures in Python
- Representing structures like PROCESS_INFORMATION and STARTUPINFO using ctypes.Structure
- Mapping Windows data types (HANDLE, DWORD, LPWSTR) with the _fields_ attribute
- Instantiating structures for API calls to configure or retrieve process information
- Spawning System Processes
- Using CreateProcessW from kernel32.dll
- Setting application paths (e.g., cmd.exe) and command-line arguments
- Managing creation flags like CREATE_NEW_CONSOLE (0x10)
- Passing structures by reference with ctypes.byref to receive process and thread IDs
- Accessing Undocumented APIs and Memory Casting
- Leveraging DnsGetCacheDataTable from dnsapi.dll for reconnaissance
- Navigating linked lists via pNext pointers in structures like DNS_CACHE_ENTRY
- Using ctypes.cast to transform raw memory addresses into Python-readable structures
- Extracting DNS cache information, such as record names and types, through loops and error handling
- Key Outcome
- Ability to build custom security tools that interact directly with Windows internals
- Mastery of low-level API calls, memory traversal, and structure manipulation for forensic or security applications
You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cybercode_academy
Get the books of the CyberCode Academy podcast:
📚 The book series: 416 lessons, 12 books, hundreds of original diagrams: security, networking and programming.
https://cybercodeacademy.gumroad.com/
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Course 25 - API Python Hacking | Episode 4: Structures, Process Spawning, and Undocumented Calls
And just to set the stage for everyone listening, this isn't just a simple Hello World exercise, not at all. We are going to build internal Windows memory structures from scratch. We are going to spawn processes by manually allocating consoles. And this is the part that honestly blew my mind a little, the DNS part. Yes, we're going to use undocumented API calls to dump the system's DNS cash directly from memory.
Exactly. Yeah, you need to understand how Windows actually think. And the reality is Windows doesn't think in Python, it thinks in C. It thinks in C. So our mission today is to take you from a Python script or to a system architect by the end of this deep dive, you should be able to visualize how data sits in memory without even looking at a monitor.
If you scribble outside lines on that form, or if you try to squeeze an entire paragraph into box A, the clerk doesn't just ask you to fix it, They reject it. They reject the application entirely. The operating system behaves the exact same way. If your data isn't perfectly formatted, your program crashes with an access violation.
Think of the handle like a claim check at a coat check a code check. Yeah, you give the attendant your coat, which in this case is the process you just created, and they hand you a little paper ticket the handle. Okay, that ticket isn't the coat itself. You can't wear the ticket. It's just an opaque token that lets you retrieve or modify the coat later. The h process is your token to talk to that specific process.
Type spot on. And here is the real AHA moment for why we do this. When you are about to run a command, you create an instance of this class in Python, right, but it's empty. It's a completely blank form, just zeros to zeros. You pass that blank form to the Windows API. The API goes off and does the hard work of actually starting the program. Then, and this is the magic part. The API fills in the blank on your form.
It is intimidating at first glance. Yeah, but you have to remember subprocess is really just a wrapper around create process W. It's just hiding the math, it's hiding all the complexity. When you use the raw API, you have total granular control. Let's break down those ten parameters. Honestly, most of them are quite boring.
Logic would dictate that yes, yeah, but the Windows API is highly bureaucratics. Uh oh, you can set W your show window to whatever you want. You can set it to one, ten, one hundred, but Windows will completely ignore that field unless you also set a completely different field called DW flags.
It comes down to efficiency and backward compatibility from the early days of Windows that start pin UFA structure is massive. It has fields for window coordinates, buffer sizes, font fill attributes. So it's huge, right if you only care about one or two setting. Windows doesn't want to waste seep ucycles parsing the other fifty fields that you left blank. It only looks at the fields you explicitly flag as important.
It's really not that bad, but it is fundamentally different. Process information was just four numbers in a row and a single block of memory. A link list is different because the data is scattered. You have one entry sitting over here, and inside that entry there is a map to the next entry, which might be thousands of bytes away somewhere else in memory.
One, data isn't just a value, It has a physical shape. That's the structure. Two you have to be wildly explicit. If you want a window to show, you need a flag to prove you actually mean it. And three three memory is really just a chain of addresses. If you know where the next link is, you can cast your way through the entire system.
Well, if you calculate a pointer or wrong, or you cast something to the wrong structure size. Let's say you tell Windows as structures one hundred bytes, but it's actually fifty. You are going to overwrite memory that belongs to something else. You won't just get a polite Python aer message. You can instantly crash the application or even bluescreen the entire machine.
We talked heavily about the star to Pinafo structure. Let's say you are writing your code and you set bwushow window equal to one because you want your new command prompt to pop up on the screen naturally. But when you run the script, nothing happens. The window remains completely hidden. What one specific thing did you forget to do?
