server side request フォージェリ メモ
server side request フォージェリ メモ
Webセキュリティの基礎を下のサイトで復習していたときにわからないところがあった。
これの『SSRF with whitelist-based input filters』の章がスッと理解出来なかったので学んだことをメモする。
※ 問題の解法などのネタバレが含まれています(何か問題があれば記事消します)
この章ではSSRFをブロックするためのホワイトリストをバイパスして攻撃すると言う問題だ。
バイパスする方法はいくつかあり、このサイトでは下の5つが挙げられていた。
- You can embed credentials in a URL before the hostname, using the @ character. For example: https://expected-host@evil-host.
- You can use the # character to indicate a URL fragment. For example: https://evil-host#expected-host.
- You can leverage the DNS naming hierarchy to place required input into a fully-qualified DNS name that you control. For example: https://expected-host.evil-host.
- You can URL-encode characters to confuse the URL-parsing code. This is particularly useful if the code that implements the filter handles URL-encoded characters differently than the code that performs the back-end HTTP request.
- You can use combinations of these techniques together.
これを順番に見ていく
1. @ character
You can embed credentials in a URL before the hostname, using the @ character. For example: https://expected-host@evil-host.
@
で資格情報を埋め込めるらしい。
http://username:password@example.com
みたいな形なら知っていたが、ホストの指定とかもできるんですねー
LABのsolutionをみると、この部分は以下のようになっている。
Change the URL to http://username@stock.weliketoshop.net/ and observe that this is accepted, indicating that the URL parser supports embedded credentials.
@
をつけて資格情報が通るかどうかをチェックしている。
上のリクエストがhttp://127.0.0.1/
を送信した場合の挙動。
HTTPのステータスコードが400
になっている。
下のリクエストはhttp://username@stock.weliketoshop.net/
を送った場合の挙動で、こちらは500
のステータスコードが帰ってきている。
これが資格情報が通るかどうかの判断基準になっているのかな?
返すエラーが違うと、こういったところから情報が集められるんですね
返すエラーは統一した方がいいのかな?🤔
2. # character
You can use the # character to indicate a URL fragment. For example: https://evil-host#expected-host.
#
の後につけるのはDOMのid属性を指定して使える。
例えば『リンクを開くとこのサイトのこの行へ移動させる』というようなことができる。
ということはわかるのだが、なぜこれが攻撃につながるのかがわからない...
3. DNS naming
You can leverage the DNS naming hierarchy to place required input into a fully-qualified DNS name that you control. For example: https://expected-host.evil-host.
???
4. URL-encode characters
これはわかる。
5. これらの手法を組み合わせることができます
これらの手法を組み合わせることができます
わからない点
最終的に出来上がるpayloadは以下になるらしい。
http://localhost:80%2523@stock.weliketoshop.net/admin/delete?username=carlos
localhost:80
はローカルホストの80番ポートにアクセスすることがわかる。
%2523
は#
をエンコードしたもの。これより後の文字列はid属性を刺す...?
@stock.weliketoshop.net
は@
がついているのでこれより前の要素たちは認証情報に当たるのかな...?
URLフラグメントを利用して他のホストを参照しているように見えるんですけど
感想
???
わかるようになったことだけブログに書いていければいいなぁ