[THM][Note] snort
https://tryhackme.com/room/snort
Task3
Which snort mode works similar to NIPS mode?
考え方
よく読むしか無い。

According to the official description of the snort, what kind of NIPS is it?
考え方
以下の公式ドキュメントでひたすら探したが見つからなかった。
以下のオンラインのmanページでそれっぽいのを発見した。
https://www.manpagez.com/man/8/snort/

Task4
Test the current instance with “/etc/snort/snort.conf” file and check how many rules are loaded with the current build.
考え方
ひたすらコマンドの実行結果を読む。泥臭いことやって出力結果など身体でなれていくことも大切。

Task6
Read the “snort.log.1640048004″ file with Snort; what is the referer of the 4th packet?
考え方
「-r」だけでは、サマリーしか見れないので、色々な出力用のコマンドを試す必要がある。詳細まで見るにはやはり、ヘックスダンプが有効なのでは?
また、問題には4番目とあるので、「-n」オプションも有効に使うと答えが早く見つかる。

Read the “snort.log.1640048004″ file with Snort; what is the number of the “TCP port 80” packets?
考え方
BPF Filterについて学ぶ。使い方をいろいろ調べよう。
また、出力のレポート結果の見方にもなれていこう。
$ sudo snort -r <logファイル> 'tcp port 80'

Task7
What is the number of the detected HTTP GET methods?
考え方
アラートのルールにICMPのみとなっている。タスク通りにやっても生成された、logファイルとalertファイルにはHTTPに関連する情報は1つもない(全部ICMP)。
snortを終了された時の標準出力のレポートに答えが書いてある。

課題
- アラート対象(正常なもの以外)のものしか、logファイルやalertファイルに出力されないのか?
- 仮に正常なものもログに出したい場合はどうしたらいいか?
- それともこういうものなのか?
Task8
What is the number of the generated alerts?
考え方
ひたすら出力結果のレポートを読みなれるという感じ。

課題
- alertファイルが作られるがそこからタイトルだけでgrepしてきてカウントする方法は無いか?パット見た感じ正規化されていないので、ひと手間かかりそう。
- コマンドのオプション指定で便利なものはあるか?毎回レポートサマリだけが頼りなのは厳しい。カウントしたい。
Task9
Write a rule to filter IP ID “35369” and run it against the given pcap file. What is the request name of the detected packet?
snort -c local.rules -A full -l . -r task9.pcap
考え方
自分でルールを作る練習です。「Task-9」フォルダの中に、空のlocal.rulesファイルがあります。その中に以下のルールを書けるか?がポイントとなります。
alert ip any any <> any any (msg:"IP ID TEST"; id:35369; sid:100001)
ルールの実装を理解する。次に以下のコマンドを実行。
$ snort -c local.rules -A full -l . -r task9.pcap
そうすると、

さて、結果に「1」と書いてありますが、どこに詳細が記録されているでしょうか?答えは実行したコマンドのオプションにあります。
以降も同じ様な問題が続きますが、考え方は同じです。頑張ってルールの書き方を調べる!
考え方
上記と同じです。以下がヒント
alert tcp any any <> any any (msg:"SYN TEST"; flags:S; sid:100001;)
alert tcp any any <> any any (msg:"SYN TEST"; flags:P, A; sid:100001;)
Create a rule to filter packets with the same source and destination IP and run it against the given pcap file. What is the number of detected packets?
考え方
以下だとダメ。
alert ip any any <> any any (msg:"SAME IP TEST"; sameip; sid:100001;)
以下だと正解。
alert tcp any any <> any any (msg:"SAME IP TEST"; sameip; sid:100001; rev:1;)
alert udp any any <> any any (msg:"SAME IP TEST"; sameip; sid:100002; rev:2;)
課題
- ipでsameipをフィルターすると13という結果が出て不正解となる。
- tcpとudpでカウントすると10という結果になり正解となる。
- 問題には、どのプロトコルでという記述はないが10が正解となっているようだ。
- ちなみに、ipの場合の13と、tcp / udpの場合の10のログファイルの内容を比較すると理由が解る可能性がありそう。