Workflow
A well-defined workflow provides structure, clarity, and efficiency to tasks, ensuring a systematic approach. This applies to exploit development like any other repetitive task.
This is my preferred workflow, you can adopt this or choose your own:

Example
The provided example demonstrates the application of the presented workflow (or your preferred workflow) for debugging shellcode. It's alright if you haven't fully grasped the assembly code at this stage, as this section primarily focuses on the workflow itself.
THis example displays a simple message box, but we can debug the shellcode just before the call to ensure the registers are set up correctly, and that we are calling the correct address.
In Visual Studio Code enter the following 64bit assembly:
This code looks intimidating, but it isn't; all will be explained soon. For now, notice that there is a breakpoint instruction on line 125 immediately before the call to MessageBoxA. Use the following batch file to compile the shellcode:
Once the shellcode has been compiled in to a PE file we can run it in windbg.

Once you have opened the x64.exe binary Windbg will break, it does this whenever we launch an executable. Enter the g command to 'go'.
Windbg should break out of your executable again, but this time it will be on the breakpoint we placed in the shellcode.
For the purposes of this exercise we can check that the registers are set up correctly for the call to MessageBoxA and that the stack is aligned correctly.
In Windbg use the u rip L2 command to display the next instruction to be executed, and the instruction that has just been executed:
Line 3 shows that we have hit our breakpoint just before we call MessageBoxA.
Next we can examine the registers, using the r command:
Keep in mind that according to the calling convention, we are required to utilise rcx, rdx, r8, andr9 for our four arguments. Below is the syntax for MessageBoxA:
Let's examine each argument, the most simple are hWnd (rcx), and uType (r9) which we have set to NULL:
Perfect! In our example lpText (rdx), and lpCaption (r8) are pointing to the same string that was pushed on to the stack:
We can examine these registers to see if our string resides in the address they reference:
Finally we can check to see that the stack is correctly aligned:
Everything is looking good and we can continue execution with the g command. We should be presented with a message box:

This is my preferred workflow, but you can choose your own; if you want to write shellcode efficiently you will need a good workflow that works for you.
Exercises
Install a Windows VM that you can use as a debugging and development mahcine. Ensure that you have a workflow that you are comfortable with.
Work through the workflow, using the presented MessageBox shellcode.
Last updated