gpt4 book ai didi

linux - 程序集执行失败-14

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

程序将可执行文件写入磁盘上的第二段,将其解密(到/tmp/decbd),然后执行(按照计划)文件 decbd 出现在磁盘上,可以通过 shell 执行,最后一次 execve 调用返回 eax=-14,程序结束后,执行流到数据并出现段错误。 http://pastebin.com/KywXTB0X

在使用 hexdump 和 dd 编译后的第二段中,我手动放置了通过 openssl 加密的 echo 二进制文件,当我在最后一个 int 0x80 命令之前停止执行时,我已经能够使用另一个终端在 decbd 中运行我的“echo”。

最佳答案

  1. 您应该将其范围缩小到一个最小的示例。请参阅MCVE .
  2. 如果您希望其他人提供帮助,您应该注释您的代码。
  3. 您应该学习使用调试器和/或其他工具。

对于第 1 点,您可以深入到:

section .text
global _start ;must be declared for linker (ld)
_start:
mov eax,11 ; execve syscall
mov ebx,program ; name of program
mov ecx,[esp+4] ; pointer to argument array
mov ebp,[esp] ; number of arguments
lea edx,[esp+4*ebp+2] ; pointer to environ array
int 0x80
section .data
program db '/bin/echo',0

对于第 3 点,使用调试器您可能会看到:

  • ebx 没问题
  • ebp 没问题
  • ecx 错误
  • edx 错误

这是一个简单的修复。 ecx 应加载地址,而不是值,edx 应跳过 2 个指针,每个指针 4 个字节,因此偏移量应为 8 而不是 2。固定代码可能如下所示:

section .text
global _start ;must be declared for linker (ld)
_start:
mov eax,11 ; execve syscall
mov ebx,program ; name of program
lea ecx,[esp+4] ; pointer to argument array
mov ebp,[esp] ; number of arguments
lea edx,[esp+4*ebp+8] ; pointer to environ array (skip argc and NULL)
int 0x80
section .data
program db '/bin/echo',0

关于linux - 程序集执行失败-14,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30107550/

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