This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.
──(komugi㉿komugi)-[~/Desktop]
└─$ gdb -q moving_immediate_data
Reading symbols from moving_immediate_data...
(No debugging symbols found in moving_immediate_data)
(gdb) b _start
Breakpoint 1 at 0x8049000
(gdb) r
Starting program: /home/komugi/Desktop/moving_immediate_data
Breakpoint 1, 0x08049000 in _start ()
(gdb) disas
Dump of assembler code for function _start:
=> 0x08049000 <+0>: nop
End of assembler dump.
(gdb) si
0x08049001 in mov_immediate_data_to_register ()
(gdb) disas
Dump of assembler code for function mov_immediate_data_to_register:
=> 0x08049001 <+0>: mov $0x64,%eax
0x08049006 <+5>: movb $0x50,0x804a000
End of assembler dump.
(gdb) si
0x08049006 in mov_immediate_data_to_register ()
(gdb) i r
eax 0x64 100
ecx 0x0 0
edx 0x0 0
ebx 0x0 0
esp 0xffffcfc0 0xffffcfc0
ebp 0x0 0x0
esi 0x0 0
edi 0x0 0
eip 0x8049006 0x8049006 <mov_immediate_data_to_register+5>
eflags 0x202 [ IF ]
cs 0x23 35
ss 0x2b 43
ds 0x2b 43
es 0x2b 43
fs 0x0 0
gs 0x0 0
gdb) si
0x0804900d in exit ()
(gdb) disas
Dump of assembler code for function exit:
=> 0x0804900d <+0>: mov $0x1,%eax
0x08049012 <+5>: mov $0x0,%ebx
0x08049017 <+10>: int $0x80
End of assembler dump.
(gdb) print /x buffer
'buffer' has unknown type; cast it to its declared type
(gdb) print /x buffer
'buffer' has unknown type; cast it to its declared type
(gdb) print /x
The history is empty.
(gdb) x/xb
Argument required (starting display address).
(gdb)
We can see EAX has the value of 0x64 or 100 decimal. Lets HACK that value now by setting EAX to say something like 0x66 by typing set $eax = 0x66
Step-by-Step Analysis
Loading the Program in GDB:
gdb -q moving_immediate_data- You opened the binary in GDB, but there are no debugging symbols (
(No debugging symbols found...)). This is because the program was likely compiled without the-gflag, which includes debugging information.
- You opened the binary in GDB, but there are no debugging symbols (
Setting a Breakpoint at
_start:b _start- This sets a breakpoint at the program's entry point
_start.
- This sets a breakpoint at the program's entry point
Starting Execution:
r- The program starts, and execution stops at the
_startlabel due to the breakpoint.
- The program starts, and execution stops at the
Disassembling
_start:disas- The disassembler reveals a single instruction at
_start:0x08049000 <+0>: nop- The
nopinstruction does nothing and is often used for alignment or as a placeholder.
- The
- The disassembler reveals a single instruction at
Single-Stepping (
si):si- Single-stepping advances execution to the next instruction, entering the
mov_immediate_data_to_registerlabel.
- Single-stepping advances execution to the next instruction, entering the
Disassembling
mov_immediate_data_to_register:disas- The disassembler shows:
0x08049001 <+0>: mov $0x64,%eax 0x08049006 <+5>: movb $0x50,0x804a000mov $0x64, %eax: Moves the value0x64(100 in decimal) into theEAXregister.movb $0x50, 0x804a000: Moves the byte value0x50into memory at address0x804a000.
- The disassembler shows:
Inspecting Registers:
i r- Register
EAXnow holds0x64(decimal100), confirming the first instruction executed correctly.
- Register
What Happened?
- The program executed the first
movinstruction (mov eax, 100), successfully moving the immediate value100into theEAXregister. - Execution is currently at
movb $0x50, 0x804a000, where it will store the immediate value0x50(80 in decimal) into the memory location0x804a000.
Key Observations
Address of
buffer:- The
.bsssection is uninitialized, and the memory address forbufferis assigned dynamically during linking. Here,bufferwas resolved to0x804a000. - This matches the second instruction:
movb $0x50, 0x804a000.
- The
Registers State:
- The
eaxregister now holds the expected value (100in decimal), confirming that the firstmovinstruction executed as intended.
- The
EFLAGS Register:
- The
eflagsvalue of0x202indicates the interrupt flag (IF) is set, meaning interrupts are enabled. No other noteworthy flags are affected.
- The
What to Do Next?
- Step through the remaining instructions using
sito verify the memory operation (movb $0x50, 0x804a000). - Inspect memory at
0x804a000after executing themovbinstruction:
This will display the single byte at the memory address to confirm thatx/1xb 0x804a0000x50was written successfully.
Debugging Tips
Enable Debug Symbols: Recompile your program with
-gto include debugging symbols. This makes debugging easier by showing symbolic names for memory locations and labels.nasm -f elf32 -g -F dwarf moving_immediate_data.asm -o moving_immediate_data.o ld -m elf_i386 moving_immediate_data.o -o moving_immediate_dataVerify the
.bssSection: Use tools likeobjdumporreadelfto inspect the.bsssection and confirm thatbufferwas allocated at the expected address.Disassemble the Entire Program: Use
objdump -dto disassemble the entire binary:objdump -d moving_immediate_data
Correct Way to Inspect Memory in GDB
Verify Memory Address of
buffer: Sincebufferresides in the.bsssection, its address is assigned dynamically. Themovb $0x50, 0x804a000instruction suggests its address is0x804a000. You can directly inspect this address.x/1xb 0x804a000x: Examine memory./1x: Display 1 value in hexadecimal format.b: Treat it as a byte.
Check Memory Content After
movb: If the instructionmovb $0x50, 0x804a000has executed, the memory at0x804a000should now contain0x50. Use:x/1xb 0x804a000Expected output:
0x804a000: 0x50Inspect
bufferSymbol: If GDB can't resolvebufferas a symbol, ensure the binary has debugging symbols by compiling with the-gflag during assembly:nasm -f elf32 -g -F dwarf moving_immediate_data.asm -o moving_immediate_data.o ld -m elf_i386 moving_immediate_data.o -o moving_immediate_dataPrint Symbolic Address of
buffer: Once debug symbols are enabled, you can display the address ofbuffer:print &bufferExplicit Memory Examination Using Symbol: After confirming
buffer's address, examine its content directly:x/1xb &buffer
Addressing Common Issues
bufferhas an unknown type: This occurs because the binary lacks debugging symbols. Recompile the program with-gas shown above to include symbol information.x/xbrequires an argument: Thexcommand needs a starting memory address. Ifbufferis unresolved, use its hardcoded address (0x804a000in this case).Check for Compiler Warnings: If you're still unable to inspect memory, confirm that
bufferwas properly allocated in the.bsssection. Use:objdump -t moving_immediate_data | grep bufferThis will list
buffer's symbol and its resolved address.
BAM! There we go! You can see the ULTIMATE power of assembly here! We just hacked the value from 0x64 to 0x66 or 100 to 102 decimal. This is a trivial example however you can clearly see when you learn to master these concepts you develop a greater power over the computer. With each program that we create, we will have a very simple lesson like this where we will hijack at least one portion of the code so we can not only see how the program is created and debugged but how we can manipulate it to whatever we want.
Quick Debugging Script
Here’s a series of commands to run in GDB for your current scenario:
b _start # Set breakpoint at _start
r # Run program
si # Step into mov_immediate_data_to_register
x/1xb 0x804a000 # Check memory at buffer's address
print &buffer # Check buffer's symbolic address (if debug symbols exist)
Additional Debugging Tools
readelf: Usereadelf -s moving_immediate_datato inspect symbols and verifybufferis in.bss.objdump: Useobjdump -d moving_immediate_datato verify the disassembly and confirm that instructions match expectations.
These steps should help you confidently inspect buffer and verify the behavior of your assembly program.