To execute shell code, you can directly edit the contents of a function:
(gdb) b foo
Breakpoint 1 at 0x400608
(gdb) run
Breakpoint 1, 0x0000000000400608 in foo ()
(gdb) x/16bx foo
0x400604 <foo>: 0x55 0x48 0x89 0xe5 0x53 0x48 0x81 0xec
(gdb) set ((unsigned char *)foo)[6] = 0x85
(gdb) x/16bx foo
0x400604 <foo>: 0x55 0x48 0x89 0xe5 0x53 0x48 0x85 0xec
(gdb) cont
I donβt know how to execute opcodes from gdb, but you can certainly do whatever you want with registers. For example, instead mov %rbx, %raxyou can use set $rax = $rbx:
(gdb) p $rax
$1 = 3671197290184
(gdb) set $rax = $rbx
(gdb) p $rax
$2 = 0
(gdb)
source
share