리눅스

 3916, 1/196 회원가입  로그인  
   ewqqw
   SETUID를 이용한 권한 얻기 소스 분석 부탁 드립니다

http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=4445 [복사]


며칠째 해메고 있네요

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

int main(){
    char command[256];
    char expand[256];
    printf("I will let you execute a single command...\n");
    printf("Try and get a shell with the command!\n");  

    fgets(command, 255, stdin);
    readlink(strtok(command, "\n"), expand, 255);

    if(strncmp(expand, "/bin/sh", 7) && strncmp(expand, "dash", 4)){
        printf("Nope! You always want to run /bin/sh\n");
        exit(0);
    }
    
    if(strstr(command, "sh")){
        printf("Almost... try to use a different name!\n");
        exit(0);
    }

    system(command);

    return 0;
}

  Hit : 2980     Date : 2017/03/07 06:42



    
pwn2on 간단하게 설명한다면,
해당 코드는 문자열을 입력받아주고 그 문자열을 명령어로 실행시켜주는 프로그램입니다.
command라는 변수에 256 Byte만큼 데이터를 입력받고
readlink 함수는 경로가 심볼릭 링크라면 그것을 저장해주는 함수입니다.
strtok()는 특정 문자열을 기준으로 Data를 Split 해주는 기능이구요.

이런식으로 분석해 나가면서 setuid의 exploit을 시도해보시면 될거 같습니다.
2017/03/07  
해쿨러 command는 원본 문자열, expand는 readlink를 한 결과죠
결국 둘다 입력에 의존하는 데이터들이지만 필터링하는 방식이 다릅니다
command에는 sh가 없지만, 그 command로 들어온 프로그램이 심볼릭 링크된 파일이고, /bin/sh나 dash를 가르키게 하면 되는거죠
ln -s /bin/sh /tmp/hack 이런식으로 하신다음에
문제를 실행하셔서
문제의 fgets에 /tmp/hack 을 입력하시면 됩니다
2017/03/07  
ewqqw 감사합니다~~ 해결되었어요 2017/03/08