MODIFICATION

ADDRESSES

gef>  b _start
 Breakpoint 1 at 0x401000
 
gef>  r
 Starting program: ./helloWorld 

 Breakpoint 1, 0x0000000000401000 in _start ()
 [ Legend: Modified register | Code | Heap | Stack | String ]
 ───────────────────────────────────────────────────────────────────────────────────── registers ────
 $rax   : 0x0               
 $rbx   : 0x0               
 $rcx   : 0x0               
 $rdx   : 0x0               
 $rsp   : 0x00007fffffffe310  →  0x0000000000000001
 $rbp   : 0x0               
 $rsi   : 0x0               
 $rdi   : 0x0               
 $rip   : 0x0000000000401000  →  <_start+0> mov eax, 0x1
 ...SNIP...
 ───────────────────────────────────────────────────────────────────────────────────────── stack ────
 0x00007fffffffe310│+0x0000: 0x0000000000000001	 ← $rsp
 0x00007fffffffe318│+0x0008: 0x00007fffffffe5a0  →  "./helloWorld"
 ...SNIP...
 ─────────────────────────────────────────────────────────────────────────────────── code:x86:64 ────
      0x400ffa                  add    BYTE PTR [rax], al
      0x400ffc                  add    BYTE PTR [rax], al
      0x400ffe                  add    BYTE PTR [rax], al
  →   0x401000 <_start+0>       mov    eax, 0x1
      0x401005 <_start+5>       mov    edi, 0x1
      0x40100a <_start+10>      movabs rsi, 0x402000
      0x401014 <_start+20>      mov    edx, 0x12
      0x401019 <_start+25>      syscall 
      0x40101b <_start+27>      mov    eax, 0x3c
      0x401020 <_start+32>      mov    edi, 0x0
      0x401025 <_start+37>      syscall 
 ─────────────────────────────────────────────────────────────────────────────────────── threads ────
 [#0] Id 1, Name: "helloWorld", stopped 0x401000 in _start (), reason: BREAKPOINT
 ───────────────────────────────────────────────────────────────────────────────────────── trace ────
 [#0] 0x401000 → _start()
 ────────────────────────────────────────────────────────────────────────────────────────────────────
 
gef>  break *0x401019

Breakpoint 1 at 0x401019
gef>  r
gef>  patch string 0x402000 "Patched!\\x0a"
gef>  c

 Continuing.
 Patched!

* in GDB, the "set" command is used to modify values. however, the "patch" command
  in GEF makes this step much easier.
  
* the \x0a adds a new line to the string 

REGISTERS

gef>  break *0x401019
 Breakpoint 1 at 0x401019
gef>  r
gef>  patch string 0x402000 "Patched!\\x0a"
gef>  set $rdx=0x9
gef>  c

 Continuing.
 Patched!
 
 * 0x9 refers to the length of the string

Last updated