본문 바로가기
시스템 해킹/CTF

[Nebula] Level 02

by L3m0n S0ju 2021. 8. 19.

LEVEL 02

There is a vulnerability in the below program that allows arbitrary programs to be executed, can you find it?

To do this level, log in as the level02 account with the password level02. Files for this level can be found in /home/flag02.

Source code

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

#include <sys/types.h>

#include <stdio.h>

int main(int argc, char **argv, char **envp)

{

        char *buffer;

        gid_t gid;

        uid_t uid;

        gid = getegid();

        uid = geteuid();

        setresgid(gid, gid, gid);

        setresuid(uid, uid, uid);

        buffer = NULL;

        asprintf(&buffer, "/bin/echo %s is cool", getenv("USER"));

        printf("about to call system(\"%s\")\n", buffer);

        system(buffer);

}

 


문제파일의 권한을 살펴보면 setuid가 설정되어있습니다.

 

-rwsr-x--- 1 flag02 level02 7438 2011-11-20 21:22 flag02

 

 

 

 

 

문제는 간단합니다. system 함수로 들어가는 buffer 인자에 적절한 값을 넣어서 쉘을 획득하면 됩니다.

 

system(buffer);

 

 

 

 

 


환경을 보면 User에 level02가 저장되어있습니다. 해당 값에 ";/bin/bash;"를 넣으면 buffer에는 다음과 같은 문자열이 삽입됩니다.

 

"/bin/echo ;/bin/bash; is cool"

 

;세미콜론은 명령어를 분리하는 기능이 있으므로 /bin/echo 를 실행하고 다음으로 /bin/bash를 실행하여 쉘을 획득할 수 있습니다.

 

 

 

 


플래그

'시스템 해킹 > CTF' 카테고리의 다른 글

보호기법 정리  (0) 2021.08.20
[Nebula] Level 03  (0) 2021.08.19
[Nebula] Level 01  (0) 2021.08.11
[Nebula] Level 00  (0) 2021.08.11
[DIMI CTF] ezheap  (0) 2021.03.26

댓글