swi*_*ese 4 gdb exploit internals
我正在尝试通过Capture-the-Flag实时VM进行操作,并在尝试使用gdb更改在堆栈上传递的值(最后要推送的项)时陷入困境:
system("date");
Run Code Online (Sandbox Code Playgroud)
至
system("ash");
Run Code Online (Sandbox Code Playgroud)
到目前为止,我的gdb努力如下:
堆
我感兴趣的地址是堆栈上的最后一个项目(下面的堆栈列表中的第一个)
(gdb) p $esp
$1 = (void *) 0xbf902690
(gdb) x/32w 0xbf902690
0xbf902690: 0x080485ff 0x0000044c 0xb7783ff4 0xbf9026b8
0xbf9026a0: 0xb76a8fa9 0xb7797356 0x08048529 0x0000044c
0xbf9026b0: 0x08048520 0x08048410 0xbf902728 0xb7695cf7
0xbf9026c0: 0x00000001 0xbf902754 0xbf90275c 0xbf9026e4
....
(gdb) x/s 0x080485ff
0x80485ff: "date"
(gdb) x/s *0x080485ff
0x65746164: <Address 0x65746164 out of bounds>
(gdb)
Run Code Online (Sandbox Code Playgroud)
尝试更改内存1
(gdb) set {const char [4] *}0x080485ff = "ash "
(gdb) x/s 0x080485ff
0x80485ff: "\b`\354\b"
(gdb)
Run Code Online (Sandbox Code Playgroud)
如您所见,我操纵了指针。
尝试更改内存2
(gdb) set *((const char *)0x080485ff) = "ash "
(gdb) x/s 0x080485ff
0x80485ff: "\bate"
(gdb)
Run Code Online (Sandbox Code Playgroud)
更麻烦-与错误地取消引用有关?
尝试更改内存3
(gdb) set {int}0x080485ff = 68736100
(gdb) x/s 0x080485ff
0x80485ff: "d\324\030\004"
(gdb)
Run Code Online (Sandbox Code Playgroud)
尝试改用ASCII值-无法按计划进行。
任何帮助表示赞赏-现在挠挠了我的(秃头)头...
谢谢
sc。
set *((const char *)0x080485ff) = "ash "
这是错误的:地址0x080485ff处的对象类型是char[5],而不是char*。尽管前者可以转换为后者,但两者完全不同。
set {const char [4] *}0x080485ff = "ash "
出于同样的原因,这是错误的:address 上没有指针0x080485ff。
set {int}0x080485ff = 68736100
这是没有意义的,因为68736100是0x418d464十六进制的,而乱码是ASCII的。你可能是说0x68736100。
实际上非常接近:
(gdb) x/s 0x080485ff
0x80485ff: ""
(gdb) x/s 0x080485ff+1
0x08048600: "ash"
Run Code Online (Sandbox Code Playgroud)
问题是,0x68736100是"hsa\0"-你已经正确地交换了角色,但你已经把终端NUL在前面而不是后面。正确的调用是:
(gdb) set {int}0x080485ff = 0x687361
(gdb) c
Continuing.
sh: ash: command not found
Run Code Online (Sandbox Code Playgroud)
有效!