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?

{作成}ローカルLLMを使用したHack the BoxのWriteupの作成

Last updated at Posted at 2024-12-19

Writeupについて

Writeupは大変勝手ながら
@fujito_shion
(四恩 藤戸)
in フューチャー株式会社
Hack The Boxのstarting pointを解いてみた
https://qiita.com/fujito_shion/items/6a4475fc8784d2e77d4c
さんと
@kenryo
HackTheBox Responder Writeup
https://qiita.com/kenryo/items/3e3909f9deeb3292ab6b
さんのを使用させていただきました。なにかあればすぐに記事を削除します。

概要

qwen2.5:3bモデルを使用したローカルLLMWriteUPを作成しました。
StremLitでアプリを作成し、Ollamaを使用してLLMを呼びだしています。
Nmapの結果を入れるとそれをもとに類似度が高いWriteupを返します。
埋め込みモデルはmxbai-embed-largeを使用しました。

GemmaやPhi3は精度がいまいちで、Llama3やQwenが良かったです。

仕組み

Testモード

  • Nmapの結果を分析させ、文章として出力させる
  • 出力された文章を使用してデータベースに対して近似検索を行い、現在は最大のものを返す

学習モード

  • Nmapの結果を入れる
  • Writeupを備考欄に入力する
  • Nmapの結果を分析させる
  • Nmapの結果とWriteupをQwenにつっこみ、整理された手順書を出力させる
  • Nmapの分析結果と出力結果をデータベースに保存する

プロンプト:

\n{question}"
        a="From the results of the nmap analysis that will be provided, please output the next command that should be executed."
notes="Please output a concise and detailed step-by-step procedure with specific and step-by-step instructions from the following information context. Please be sure to output all tools (e.g. gobusting) and Linux and other commands used in that context, along with specific examples.\n\nContext: \n" + notes
        combined_input = f"From the results of the nmap analysis that will be provided, please output the next command that should be executed.: {analyzed_question}\n以下のテキストを見て具体的かつ詳細な手順を最初から最後まで簡潔に出力してください。 subinformations: {notes} \n\n手順をすべて出力しなさい"
        

実行結果

データ入力画面:
スクリーンショット (3).png

テスト画面:
スクリーンショット (4).png

実行結果:
スクリーンショット (5).png

出力結果の詳細

Step-by-Step Procedure Connect via Telnet: Use the telnet command to connect to the target IP address. $ telnet

Enter the password when prompted (if any).
Login as root:

When prompted for a login name, enter root.
Trying ...
Connected to .
Escape character is '^]'.

login: root

Navigate to the Flag File:

Once logged in as root, navigate to the directory where the flag file might be located.
$ cd ~

List Directory Contents:

Use the ls command to list all files and directories in your home directory.
$ ls

Copy the Flag File:

Copy the flag file (flag.txt) from your home directory to a location where you can submit it.
$ cp ~/flag.txt /path/to/submit/

Summary of Commands
telnet : Connects via Telnet to the target IP address.
login: root: Enters the password for login as root.
cd ~: Navigates to your home directory.
ls: Lists all files and directories in your home directory.
cp ~/flag.txt /path/to/submit/: Copies the flag file from your home directory to a submission location.
Final Steps
Ensure you have the correct path /path/to/submit/ where you can submit the flag file (flag.txt).
Copy the flag file to this specified path:
$ cp ~/flag.txt /path/to/submit/

Verify that the flag file has been copied successfully and is ready for submission.
By following these steps, you should be able to submit the root flag as required.

感想

当初Difyで作成できたらと考えていたが外部との通信が面倒なため断念しました。Ollamaのtemperatureはデフォルトだと結果が安定しなかったので0に設定しました。もともと、Nmapの結果から登録したWriteupを見てRAGで出力させようとしたが、別にRAGにしなくても文章としてデータベースに保存されているので、テスト時は検索のみとしました。Treeと、responder、Meowでしか試していませんが、これらはうまくいきました。今後は、複数の候補からコマンド実行ごとに対象マシンを絞れたらなと思いつつです。

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?