Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 First time using WinDbg

views
     
TSFlierMate4
post Jan 17 2023, 01:46 AM, updated 3y ago

Getting Started
**
Validating
90 posts

Joined: Jan 2023
Hi, I have never really use a debugger /disassembler before (except online disassembler), so this is a new experience for me to try WinDbg!

Today I am going to disassemble my own program, called msgbox.exe, written also in fasm.

user posted image
Example msgbox.exe to debug / disassemble

First, download the WinDbg and launch it:

user posted image
Download debugging tools from Windows SDK

user posted image
Start menu items of WinDbg after installation

user posted image
Open WinDbg(x64)

Then, browse to msgbox.exe and open it.

user posted image
Open executable (msgbox.exe)

But funny it didn't show a PE header analysis, I have to download a separate PEDump to find which memory to dump.

user posted image
Run PEDump tool to find code section entry point

Finally, we got the address: 0x402000, so let's disassemble it.

user posted image
View disassembly

user posted image
Spot on!

It looks exactly like the source code!
CODE

start:

      push 0x40
      push title
      push message
      push 0
      call [MessageBox]

      push eax
      call [ExitProcess]


I know quite a few sifu here, know better in anything disassembly, e.g. junyian, angch and cikelempadey.

I think I used the wrong tool to disassemble msgbox.exe, because it doesn't bring me directly to the code section of the executable.
Enlightenment please? rclxm9.gif


PEDump tool: forum.lazarus.freepascal.org/index.php?topic=46617.0

Windows SDK: developer.microsoft.com/en-us/windows/downloads/windows-sdk/


TSFlierMate4
post Jan 17 2023, 04:17 AM

Getting Started
**
Validating
90 posts

Joined: Jan 2023
Whoops, the X64 disassembly is not correct, especially the first line (push 0x40), so I try WinDbg X86 and this time is correct:

user posted image

Strange, I didn't know have to use 32-bit debugger to load 32-bit EXE.
angch
post Jan 17 2023, 08:58 AM

On my way
****
Junior Member
636 posts

Joined: Jul 2006
Get with the times. We use Ghidra now.

user posted image

user posted image

This post has been edited by angch: Jan 17 2023, 09:57 AM
TSFlierMate4
post Jan 17 2023, 03:58 PM

Getting Started
**
Validating
90 posts

Joined: Jan 2023
QUOTE(angch @ Jan 17 2023, 08:58 AM)
Get with the times. We use Ghidra now.

user posted image

user posted image
*
I see, thank you for including my cpuid.exe in your example screenshot!
I am thrilled.

Ghidra is open-source, part of NSA project. I have just tried it and it disassembles better than WinDbg.
user posted image
At least it has PE header analysis, can click to go directly to different section of the executable, and it even try to create the source code in high level language.

But I don't like they use "dragon" as wait cursor though.
junyian
post Jan 17 2023, 10:39 PM

Casual
***
Junior Member
401 posts

Joined: Jan 2003


WinDbg is a debugger. It's not a disassembler, even though it has some level of capability of doing that. Personally I find WinDbg quite hard to use, but I do know it's very powerful, and can do windows kernel debugging. For user level app debugging I normally use x64dbg.

Ghidra and IDA are proper disassemblers. I personally use IDA Free and Ghidra as a mix since there are some complementary features between both. There's also Radare and Binary Ninja, but I never really tried to use these before.

Your CPUID loaded in IDA Freeware with default settings.
user posted image

And the 2nd half of the disassembly where you had the conditional jumps.
user posted image

This post has been edited by junyian: Jan 17 2023, 10:50 PM
TSFlierMate4
post Jan 17 2023, 10:50 PM

Getting Started
**
Validating
90 posts

Joined: Jan 2023
QUOTE(junyian @ Jan 17 2023, 10:39 PM)
WinDbg is a debugger. It's not a disassembler, even though it has some level of capability of doing that. Personally I find WinDbg quite hard to use, but I do know it's very powerful, and can do windows kernel debugging. For user level app debugging I normally use x64dbg.

Ghidra and IDA are proper disassemblers. I personally use IDA Free and Ghidra as a mix since there are some complementary features between both. There's also Radare and Binary Ninja, but I never really tried to use these before.
*
Thanks for chiming in. Silly me, now only I know the difference between debugger and disassembler. tongue.gif

I noted you use x64dbg for debugging, and IDA + Ghidra for dissasembling.

Someone revealed to me there is also cutter (github.com/rizinorg/cutter), a "Free and Open Source Reverse Engineering Platform powered by rizin", but I didn't try it, I thought I want to try the major tools first.
junyian
post Jan 17 2023, 10:56 PM

Casual
***
Junior Member
401 posts

Joined: Jan 2003


QUOTE(FlierMate4 @ Jan 17 2023, 10:50 PM)
Thanks for chiming in. Silly me, now only I know the difference between debugger and disassembler.  tongue.gif

I noted you use x64dbg for debugging, and IDA + Ghidra for dissasembling.

Someone revealed to me there is also cutter (github.com/rizinorg/cutter), a "Free and Open Source Reverse Engineering Platform powered by rizin", but I didn't try it, I thought I want to try the major tools first.
*
Cutter is actually the GUI version of Rizin, which is a fork from Radare (forked due to some disagreements between the developers, apparently).

Disassemblers normally come with built-in debuggers. IDA and Ghidra have it. If I'm lazy I'll resort to using IDA's debugger. But if I need some more advanced features then x64dbg is my preferred one. For linux, I tried GDB, but failed miserably... haha. If needed, I will use edb-debugger.

This post has been edited by junyian: Jan 17 2023, 11:00 PM
TSFlierMate4
post Jan 17 2023, 11:13 PM

Getting Started
**
Validating
90 posts

Joined: Jan 2023
QUOTE(junyian @ Jan 17 2023, 10:39 PM)
Your CPUID loaded in IDA Freeware with default settings.
user posted image

And the 2nd half of the disassembly where you had the conditional jumps.
user posted image
*
I am pening rclxub.gif looking at the conditional jumps, its arrow and table. Better to look directly at code. rclxm9.gif

The CPUID has window message loop, which is standard either in C++ or Assembly, I just borrowed from one of the example source code, the only part I added myself is...

CODE

 .wmpaint:
       invoke  BeginPaint,[hwnd],ps
       invoke  TextOut, eax, 50, 50, _name, 48
       invoke  EndPaint,[hwnd],ps
       jmp     .finish


and the code to call "cpuid" thrice.

And a big thanks for downloading my cpuid.zip.
junyian
post Jan 17 2023, 11:23 PM

Casual
***
Junior Member
401 posts

Joined: Jan 2003


QUOTE(FlierMate4 @ Jan 17 2023, 11:13 PM)
I am pening  rclxub.gif looking at the conditional jumps, its arrow and table. Better to look directly at code.  rclxm9.gif

The CPUID has window message loop, which is standard either in C++ or Assembly, I just borrowed from one of the example source code, the only part I added myself is...

CODE

 .wmpaint:
       invoke  BeginPaint,[hwnd],ps
       invoke  TextOut, eax, 50, 50, _name, 48
       invoke  EndPaint,[hwnd],ps
       jmp     .finish


and the code to call "cpuid" thrice.

And a big thanks for downloading my cpuid.zip.
*
IDA have the text mode disassembly also. Modern disassemblers will have the graph mode these days. It makes it easier to look at thousands of assembly lines with loops/conditional jumps/nested loops/nested jumps, etc.

user posted image
junyian
post Jan 18 2023, 09:32 AM

Casual
***
Junior Member
401 posts

Joined: Jan 2003


This is now showing the capabilities of a proper disassembler. Where you can rename locations to something more readable (I used the same names as your ASM source). And just like Ghidra, there's also a decompiler to try translate this back to C-like code.

user posted image
TSFlierMate4
post Jan 20 2023, 10:22 PM

Getting Started
**
Validating
90 posts

Joined: Jan 2023
QUOTE(junyian @ Jan 18 2023, 09:32 AM)
This is now showing the capabilities of a proper disassembler. Where you can rename locations to something more readable (I used the same names as your ASM source). And just like Ghidra, there's also a decompiler to try translate this back to C-like code.

user posted image
*
Thanks for sharing some of the feature of IDA Free, it is amazing users are able to rename location labels.

Since I have started my initial attempt to use Windows Debugger and Ghidra, I might want to start trying FlareOn challenge, like last year #2 challenge, where I failed to capture the flag of corrupted PE file. bruce.gif

I will need your help once I started on it bit by bit, but I might revive the FlareOn challege 7 thread (by WestKid), or may ask question on this thread.

What tools do I need besides Ghidra to solve last year challenge #2? The EXE seems like a "packed executable"(I forgot the proper term to use here to describe the state of the EXE). hmm.gif
TSFlierMate4
post Jan 20 2023, 10:25 PM

Getting Started
**
Validating
90 posts

Joined: Jan 2023
Sorry, it is already new year, then I mean year 2021 challenge.
junyian
post Jan 20 2023, 11:45 PM

Casual
***
Junior Member
401 posts

Joined: Jan 2003


QUOTE(FlierMate4 @ Jan 20 2023, 10:22 PM)
Thanks for sharing some of the feature of IDA Free, it is amazing users are able to rename location labels.

Since I have started my initial attempt to use Windows Debugger and Ghidra, I might want to start trying FlareOn challenge, like last year #2 challenge, where I failed to capture the flag of corrupted PE file.  bruce.gif

I will need your help once I started on it bit by bit, but I might revive the FlareOn challege 7 thread (by WestKid), or may ask question on this thread.

What tools do I need besides Ghidra to solve last year challenge #2? The EXE seems like a "packed executable"(I forgot the proper term to use here to describe the state of the EXE).  hmm.gif
*
Year 2021 Challenge 2? I checked my previous notes and I'm sure that file's PE header is not corrupted. Is this with the title "Known" and executable file "UnlockYourFiles.exe"?
Year 2021 Challenge 7 (spel.exe) is definitely challenging, though not as hard as Challenge 9. This one is not really a packed executable. There is an encrypted/embedded binary file which gets unloaded/decrypted at run-time... and that's just part of the challenge. There's still more to it after getting the embedded binary dumped.


TSFlierMate4
post Jan 21 2023, 12:45 PM

Getting Started
**
Validating
90 posts

Joined: Jan 2023
QUOTE(junyian @ Jan 20 2023, 11:45 PM)
Year 2021 Challenge 2? I checked my previous notes and I'm sure that file's PE header is not corrupted. Is this with the title "Known" and executable file "UnlockYourFiles.exe"?
Year 2021 Challenge 7 (spel.exe) is definitely challenging, though not as hard as Challenge 9. This one is not really a packed executable. There is an encrypted/embedded binary file which gets unloaded/decrypted at run-time... and that's just part of the challenge. There's still more to it after getting the embedded binary dumped.
*
After I checked, the challenge file is garbage.exe, from FlareOn 7.
It is a good habit that you jot down notes while solving it, I think I must do the same also.
May I know do you normally disassemble them in virtual machine so that it won't cause harm to the host OS?
What tools are needed to solve challenge like garbage.exe? Thanks in advance.
junyian
post Jan 21 2023, 04:17 PM

Casual
***
Junior Member
401 posts

Joined: Jan 2003


QUOTE(FlierMate4 @ Jan 21 2023, 12:45 PM)
After I checked, the challenge file is garbage.exe, from FlareOn 7.
It is a good habit that you jot down notes while solving it, I think I must do the same also.
May I know do you normally disassemble them in virtual machine so that it won't cause harm to the host OS?
What tools are needed to solve challenge like garbage.exe? Thanks in advance.
*
I don't remember trying garbage.exe yet. Haha. But if it's really a corrupted exe, just a disassembler is not enough. I'd use a PE editor like CFF Explorer Suite too. Dealing with corrupted PE seems a bit hard for a 2nd challenge. I'll take a look after CNY.

And yes, I do use a dedicated VM for this.
TSFlierMate4
post Jan 22 2023, 10:23 PM

Getting Started
**
Validating
90 posts

Joined: Jan 2023
QUOTE(junyian @ Jan 21 2023, 04:17 PM)
I don't remember trying garbage.exe yet. Haha. But if it's really a corrupted exe, just a disassembler is not enough. I'd use a PE editor like CFF Explorer Suite too. Dealing with corrupted PE seems a bit hard for a 2nd challenge. I'll take a look after CNY.

And yes, I do use a dedicated VM for this.
*
I open garbage.exe in CFF Explorer:

user posted image

It shows the Import Directory RVA and Relocation Directory RVA are incorrect.
Do I just need to fix these two addresses?

Actually I read its solution before, but almost forgot everything.
If not mistaken, must also rebuild its resource section (since now it is blank).

Anyway, I will wait for your guidance after CNY, happy holiday!


For those who are interested:
CFF Explorer: ntcore.com/?page_id=388
TSFlierMate4
post Jan 22 2023, 11:00 PM

Getting Started
**
Validating
90 posts

Joined: Jan 2023
I able to recover portion of the resource section, by editing the raw size value.

user posted image
At least now Resource Editor shows some data instead of blank

But UPX Utility still not able to unpack:
CODE

                      Ultimate Packer for eXecutables
                         Copyright (C) 1996 - 2011
UPX 3.08w       Markus Oberhumer, Laszlo Molnar & John Reiser   Dec 12th 2011

       File size         Ratio      Format      Name
  --------upx: C:\Users\~User~\AppData\Local\Temp\upx1A9E.tmp: OverlayException: invalid overlay size; file is possibly corrupt
------------   ------   -----------   -----------

Unpacked 1 file: 0 ok, 1 error.


junyian
post Jan 24 2023, 08:53 AM

Casual
***
Junior Member
401 posts

Joined: Jan 2003


QUOTE(FlierMate4 @ Jan 22 2023, 11:00 PM)
I able to recover portion of the resource section, by editing the raw size value.

user posted image
At least now Resource Editor shows some data instead of blank

But UPX Utility still not able to unpack:
CODE

                      Ultimate Packer for eXecutables
                         Copyright (C) 1996 - 2011
UPX 3.08w       Markus Oberhumer, Laszlo Molnar & John Reiser   Dec 12th 2011

       File size         Ratio      Format      Name
  --------upx: C:\Users\~User~\AppData\Local\Temp\upx1A9E.tmp: OverlayException: invalid overlay size; file is possibly corrupt
------------   ------   -----------   -----------

Unpacked 1 file: 0 ok, 1 error.

*
Here's what I did, roughly. So I don't spoil your fun smile.gif
I used CFF Explorer and PE-Bear:-
- CFF Explorer is old and was not updated for many years. But there are some features that I like which I couldn't find in other newer PE editors
- PE-Bear is much newer, and still regularly updated.

The resource section you found is the first step. But you should know that this incomplete XML is useless, and is not critical for an exe to be recognized as a valid PE file by Windows. So you can safely delete this resource ID. The more important thing is the import directory. As long as this is corrupted or not formed properly, Windows cannot load the exe. When recreating unpacked/decrypted exes/dlls, rebuilding the import table is a common step. You can see that after fixing the .rsrc section, the import table is empty. So you can use CFF Explorer to add your own import table into this.

After that, the exe should be recognized by UPX and you can unpack it nicely. But the exe still can't execute properly again. There's still something wrong with import table, which can be fixed easily by renaming the dll that it's supposed to load. After that we can run the exe and get this.



user posted image
TSFlierMate4
post Jan 24 2023, 02:33 PM

Getting Started
**
Validating
90 posts

Joined: Jan 2023
QUOTE(junyian @ Jan 24 2023, 08:53 AM)
Here's what I did, roughly. So I don't spoil your fun smile.gif
I used CFF Explorer and PE-Bear:-
- CFF Explorer is old and was not updated for many years. But there are some features that I like which I couldn't find in other newer PE editors
- PE-Bear is much newer, and still regularly updated.

The resource section you found is the first step. But you should know that this incomplete XML is useless, and is not critical for an exe to be recognized as a valid PE file by Windows. So you can safely delete this resource ID. The more important thing is the import directory. As long as this is corrupted or not formed properly, Windows cannot load the exe. When recreating unpacked/decrypted exes/dlls, rebuilding the import table is a common step. You can see that after fixing the .rsrc section, the import table is empty. So you can use CFF Explorer to add your own import table into this.

After that, the exe should be recognized by UPX and you can unpack it nicely. But the exe still can't execute properly again. There's still something wrong with import table, which can be fixed easily by renaming the dll that it's supposed to load. After that we can run the exe and get this.
user posted image
*
I think reverse-engineering involves a lot of guesswork, rebuilding import table, huh? I can only know the few basic ones, like kernel32.dll, user32.dll, vcruntime140.dll, I don't know others wor....

Reverse-engineering is a complete different game from normal programming, I know can learn, but I feel like giving up. cry.gif

Thank you for explaining to me without revealing the details, at least I know reverse-engineering is a skill not commonly pursued, it is good that you and your friend know about malware analysis. Proud of you.

This post has been edited by FlierMate4: Feb 3 2023, 06:09 PM
junyian
post Jan 24 2023, 04:28 PM

Casual
***
Junior Member
401 posts

Joined: Jan 2003


QUOTE(FlierMate4 @ Jan 24 2023, 02:33 PM)
I think reverse-engineering involves a lot of guesswork, rebuilding import table, huh? I can only know the few basic ones, like kernel32.dll, user32.dll, vcruntime140.dll, I don't know others wor....

Reverse-engineering is a complete game from normal programming, I know can learn, but I feel like giving up.  cry.gif

Thank you for explaining to me without revealing the details, at least I know reverse-engineering is a skill not commonly pursued, it is good that you and your friend know about malware analysis. Proud of you.
*
Rebuilding the import table is not as difficult as you might imagine. No matter how the binary is changed, it need to preserve the final import table somehow. For this one, I'm doing just enough for the OS to successfully load the PE and pass the execution back to it. And continue debugging from there to get the original import table. In this case, all I did was to add ExitProcess from kernel32.dll (the 32 bit version, since this is a 32 bit executable). We can still discuss the details on discord if needed.

Guesswork is always part of the game. But this is educated guess. The way I solved this challenge is probably not the only way. There might be easier methods used by others. All in all, it still did take me about 5 hours to solve this. So I think I'm considered quite slow.

 

Change to:
| Lo-Fi Version
0.0190sec    0.42    5 queries    GZIP Disabled
Time is now: 24th November 2025 - 10:09 PM