- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
void function(int a, int b, int c) {
char buffer1[5];
char buffer2[10];
int *ret;
ret = buffer1 + 12;
(*ret) += 8;//why is it 8??
}
void main() {
int x;
x = 0;
function(1,2,3);
x = 1;
printf("%d\n",x);
}
上面的demo来自这里:
http://insecure.org/stf/smashstack.html
但它在这里不起作用:
D:\test>gcc -Wall -Wextra hw.cpp && a.exe
hw.cpp: In function `void function(int, int, int)':
hw.cpp:6: warning: unused variable 'buffer2'
hw.cpp: At global scope:
hw.cpp:4: warning: unused parameter 'a'
hw.cpp:4: warning: unused parameter 'b'
hw.cpp:4: warning: unused parameter 'c'
1
虽然作者认为我不明白为什么它是 8:
A little math tells us the distance is 8 bytes.
我的 gdb 转储被称为:
Dump of assembler code for function main:
0x004012ee <main+0>: push %ebp
0x004012ef <main+1>: mov %esp,%ebp
0x004012f1 <main+3>: sub $0x18,%esp
0x004012f4 <main+6>: and $0xfffffff0,%esp
0x004012f7 <main+9>: mov $0x0,%eax
0x004012fc <main+14>: add $0xf,%eax
0x004012ff <main+17>: add $0xf,%eax
0x00401302 <main+20>: shr $0x4,%eax
0x00401305 <main+23>: shl $0x4,%eax
0x00401308 <main+26>: mov %eax,0xfffffff8(%ebp)
0x0040130b <main+29>: mov 0xfffffff8(%ebp),%eax
0x0040130e <main+32>: call 0x401b00 <_alloca>
0x00401313 <main+37>: call 0x4017b0 <__main>
0x00401318 <main+42>: movl $0x0,0xfffffffc(%ebp)
0x0040131f <main+49>: movl $0x3,0x8(%esp)
0x00401327 <main+57>: movl $0x2,0x4(%esp)
0x0040132f <main+65>: movl $0x1,(%esp)
0x00401336 <main+72>: call 0x4012d0 <function>
0x0040133b <main+77>: movl $0x1,0xfffffffc(%ebp)
0x00401342 <main+84>: mov 0xfffffffc(%ebp),%eax
0x00401345 <main+87>: mov %eax,0x4(%esp)
0x00401349 <main+91>: movl $0x403000,(%esp)
0x00401350 <main+98>: call 0x401b60 <printf>
0x00401355 <main+103>: leave
0x00401356 <main+104>: ret
0x00401357 <main+105>: nop
0x00401358 <main+106>: add %al,(%eax)
0x0040135a <main+108>: add %al,(%eax)
0x0040135c <main+110>: add %al,(%eax)
0x0040135e <main+112>: add %al,(%eax)
End of assembler dump.
Dump of assembler code for function function:
0x004012d0 <function+0>: push %ebp
0x004012d1 <function+1>: mov %esp,%ebp
0x004012d3 <function+3>: sub $0x38,%esp
0x004012d6 <function+6>: lea 0xffffffe8(%ebp),%eax
0x004012d9 <function+9>: add $0xc,%eax
0x004012dc <function+12>: mov %eax,0xffffffd4(%ebp)
0x004012df <function+15>: mov 0xffffffd4(%ebp),%edx
0x004012e2 <function+18>: mov 0xffffffd4(%ebp),%eax
0x004012e5 <function+21>: movzbl (%eax),%eax
0x004012e8 <function+24>: add $0x5,%al
0x004012ea <function+26>: mov %al,(%edx)
0x004012ec <function+28>: leave
0x004012ed <function+29>: ret
在我的情况下,距离应该是 - = 5,对吗?但它似乎不起作用..
为什么 function
需要 56 字节作为局部变量?( sub $0x38,%esp
)
最佳答案
作为joveha pointed out ,call
指令保存在栈中(返回地址)的EIP值需要增加7字节(0x00401342
- 0x0040133b
= 7) 以跳过 x = 1;
指令 (movl $0x1,0xfffffffc(%ebp)
).
你是正确的,为局部变量保留了 56 个字节 (sub $0x38,%esp
),所以缺少的部分是 buffer1
之后的字节数stack是保存的EIP。
一些测试代码和内联汇编告诉我,我的测试的神奇值是 28。我无法就为什么它是 28 提供明确的答案,但我假设编译器正在添加填充和/或 stack canaries .
The following code was compiled using GCC 3.4.5 (MinGW) and tested on Windows XP SP3 (x86).
unsigned long get_ebp() {
__asm__("pop %ebp\n\t"
"movl %ebp,%eax\n\t"
"push %ebp\n\t");
}
void function(int a, int b, int c) {
char buffer1[5];
char buffer2[10];
int *ret;
/* distance in bytes from buffer1 to return address on the stack */
printf("test %d\n", ((get_ebp() + 4) - (unsigned long)&buffer1));
ret = (int *)(buffer1 + 28);
(*ret) += 7;
}
void main() {
int x;
x = 0;
function(1,2,3);
x = 1;
printf("%d\n",x);
}
我可以很容易地使用 gdb 来确定这个值。
(使用 -g
编译以包含调试符号)
(gdb) break function
...
(gdb) run
...
(gdb) p $ebp
$1 = (void *) 0x22ff28
(gdb) p &buffer1
$2 = (char (*)[5]) 0x22ff10
(gdb) quit
(0x22ff28
+ 4) - 0x22ff10
= 28
(ebp 值 + 字长) - buffer1 地址 = 字节数
除了Smashing The Stack For Fun And Profit , 我建议阅读我在 my answer to a previous question of yours 中提到的一些文章和/或关于该主题的其他 Material 。很好地理解这种类型的漏洞利用的确切工作原理应该可以帮助您 write more secure code .
关于c - 如何在 GCC、windows XP、x86 中编写缓冲区溢出漏洞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2543725/
问题是不言自明的。如果重要的话,我正在为 USB 驱动器命名。 谢谢。 最佳答案 32 characters in NTFS, 11 in FAT. 关于windows-xp - Windows XP
我在我的 macbook(lion os)上使用并行桌面,我想让 xampp/localhost 在我安装的 XP 版本上工作,这样我就可以在 Internet Explorer 中测试我的网站。 显
我将如何创建自己的 XP 打印机驱动程序,它将执行以下操作: 打印到文件(可能是 XPS 格式) 将此文件放入密码 protected ZIP 文件 将 zip 文件通过电子邮件发送到已配置的 电子邮
我记得看过 Mark Russinovich 的网络广播,显示了用户启动的内核转储的键盘按键序列。有人可以按键的确切顺序刷新我的内存。 请注意,这是针对 XP 的。 最佳答案 http://psaca
我父亲找到了一个他非常喜欢的俄语键盘映射here .但是,它是非标准的,因此不会出现在键盘布局选择的语言(控制面板->区域和语言选项->语言->详细信息->文本服务和输入语言->添加)下拉列表中。据我
我想将 Chocolatey 与某些 Windows XP VM 一起使用。不幸的是,Chocolatey 要求告诉我们至少需要 Windows 7。( https://chocolatey.org/
是否有官方的 Windows XP 注册表引用在线某处?我看到 Win 2000 有一个引用和 Win 2003 MS technet 上的服务器,但我似乎找不到适用于 XP 的服务器。是的,我知道
我有一个带有第三方应用程序的四核系统,偶尔会旋转多个进程(始终是相同的可执行文件,但有多个实例)并占用 100% 的 CPU 时间。我还在同一个机器上运行了几个 Web 服务(IIS 和第三方)。 所
我正在寻找“RunOnceEx”的反向版本。 RunOnceEx 确实在用户的 shell(桌面和任务栏)启动之前运行一些程序。在 runonceex 完成之前,登录进度不会继续。 我想做完全相同的事
我有一个程序,我试图在两台计算机上运行。在一台电脑上,它工作正常。但是,在另一台计算机上,它在尝试创建 USB channel 时挂起。我没有能力查看程序内部。确定两台机器之间差异的最佳方法是什么?
Windows XP 绘制带有漂亮阴影的图标文本,这有助于阅读各种背景上的文本。字体颜色为白色,阴影为黑色(如果桌面背景为白色)或根本没有阴影(如果桌面背景为黑色)。 所以有两个子任务: 阴影是如何绘
有没有办法通过批处理脚本在 Windows XP 中创建用户,甚至为其分配管理员/受限用户值? 最佳答案 假设用户名是 rased 密码是 pAsS net user rased pAsS /add
我正在寻找使用 SP2 或 winsock 在 XP 上访问 A2DP、AVRCP、MAP、HFP 等蓝牙配置文件的供应商独立方式。 我正在最终确定为蓝牙创建应用程序的方法。 除了服务发现之外,我还需
我想通过 Windows 代码包将 Direct2D 用于我的 .Net 应用程序。由于我的一些用户使用 XP,我需要提供 GDI+ 后备。我想知道人们通常如何进行这种后备。 他们是否将所有必要的图形
根据 Microsoft 文档,直到 Windows Vista,InterlockedCompareExchange64 才可用作 Windows API 调用。见 http://msdn.micr
计算机管理 -> 服务和应用程序 -> 消息队列 如何从特定队列中删除消息? 在我看来有一些方法,但我现在找不到。 最佳答案 嗯,不可能通过 MMC 删除有害消息。 你可以试试QueueExplore
Windows XP 中存储的用户帐户图标/图片在哪里? (显示在非经典登录屏幕和开始菜单上的那些。) 最佳答案 C:\Document and Settings\All Users\Applicat
在 WinXP 上安装时,出现以下错误 在 Win7 应用程序上安装没有问题。 Windows 窗体应用程序和 WPF 应用程序都存在相同的问题,并且在 VS 2010 之前它们都可以正常工作。 最佳
是否可以在 Windows XP 上的 Visual Studio 中使用/引用 Microsoft.Web.Administration?我知道,在 XP 上安装 IIS 7 是不可能的,但我(必须
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我是一名优秀的程序员,十分优秀!