RECOMMENDER for Web security engineers - 中級編 -
-
Upload
isao-takaesu -
Category
Software
-
view
363 -
download
2
Transcript of RECOMMENDER for Web security engineers - 中級編 -
2017.06.28
AISECjp #12
Presented by Isao Takaesu
RECOMMENDER for Web security engineers- 中級編 -
About the speaker
• 職業 : セキュリティエンジニア
• 所属 : MBSD
• 趣味 : 脆弱性スキャナ作り、機械学習
• ブログ: http://www.mbsd.jp/blog/
• AISECjp共同管理者
高江洲 勲
Takaesu Isao
AISECjp
セキュリティエンジニアに
XSSの検査文字列をレコメンドするシステム
AISECjp
Recommenderとは?
※こちらも併せてご覧ください。
https://www.slideshare.net/babaroa/recommender-for-web-security-engineers
診断業界の人手不足解消が目的。
診断のハードルを下げ、誰でも簡単に。
AISECjp
なぜ必要?
システム概要
AISECjp
Security engineer
Target Web Apps
Investigator
Recommender
2. Generates feature vectors
1. Examines vulnerability feature
4. Computes recommended
3. feature vector to Recommender
injection code
5. Recommends injection code
Investigator
AISECjp
Investigatorの役割
Web Appsをクローリングしながら脆弱性の特徴を調査する。
主機能
Webアプリをクローリングしながら…
・パラメータ値の出力箇所を調査
・パラメータ毎に使用可能な記号とスクリプト文字列を調査
・調査結果を基に脆弱性の特徴ベクトルを生成
AISECjp
http://example.com/?input1=‘”`<>alert();prompt();confirm();--------------------------------------------------<frameset><frame src=“'"`<>”><frame src=“test2.html”>
</frameset>
出力箇所 :frameタグのsrc属性(引用符は[“])
記号使用可否 :[”][’][<][>]は不可、[`]は可。
スクリプト使用可否:[alert()][prompt()][confirm()]は不可
AISECjp
特徴ベクトルの生成例
Web Appsの挙動を調査
挙動を変換テーブルに基づいて特徴ベクトルに変換
例) [3, 2, 3, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0]
[8, 2, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0]
AISECjp
変換テーブル(一例)
0 1 2 3 4 5 6 7 8 9 10
Output
location
html None <!-- <body> <frame> <img> <input> <script> <textarea> <iframe> <a> <div>
attribute None id src value href class - - - - -
JavaScript None /* // var - - - - - - -
VBScript None plane - - - - - - - - -
Quotation None " ’ - - - - - - - -
escape
" Pass Fail - - - - - - - - -
' Pass Fail - - - - - - - - -
` Pass Fail - - - - - - - - -
< Pass Fail - - - - - - - - -
> Pass Fail - - - - - - - - -
alert(); Pass Fail - - - - - - - - -
prompt(); Pass Fail - - - - - - - - -
confirm(); Pass Fail - - - - - - - - -
``; Pass Fail - - - - - - - - -
<script> Pass Fail - - - - - - - - -
</script> Pass Fail - - - - - - - - -
Msgbox Pass Fail - - - - - - - - -
Recommender
AISECjp
Recommenderの役割
特徴ベクトルを基に最適な検査文字列を算出する。
主機能
Investigatorから特徴ベクトルを受け取り…
・特徴ベクトルに尤も近しい検査文字列を計算
・計算結果を基に検査文字列を確率順に出力
・計算には多層パーセプトロンを使用
AISECjp
・・・
・・・
32301・・・0000
Feature vector
Multilayer Perceptron
<script>alert()…
・・・
・・・
現在の精度:loss = 0.2835995, acc = 0.8082706AISECjp
多層パーセプトロンの使用例
“ onerror=alert``;
‘; alert();//
Msgbox()…
[CrLf]confirm();//
javascript:alert``;
“><frame src=“j…
Injection code
AISECjp
学習データの一例
op_ht
mlop_attr op_js op_vbs op_quot
esc_doub
le
esc_singl
e・・・ esc_bale
rt
esc_sscr
ipt
esc_esc
riptlabel injection_codes
2 0 0 0 0 0 0 ・・・ 0 0 0 1 <script>alert();</script>
2 0 0 0 0 1 1 ・・・ 1 1 0 5 <img src=x onerror=alert();>
7 0 0 0 0 1 1 ・・・ 0 0 0 9 </textarea><script>alert();</script>
5 3 0 0 1 0 0 ・・・ 0 0 0 14 "><script>prompt();</script>
1 0 0 0 0 1 1 ・・・ 0 0 0 18 --><script>prompt();</script>
4 2 0 0 1 0 1 ・・・ 0 0 0 25 " onerror=alert();"
6 1 0 0 0 1 0 ・・・ 0 0 0 37 src=saivs.js
0 0 0 1 1 0 0 ・・・ 0 0 0 0 "\r\n MsgBox "3122
3 2 0 1 1 0 0 ・・・ 0 0 0 69 " & msgbox("exploit") & "aa
5 3 0 0 0 1 1 ・・・ 1 1 0 129 onmousemove=alert``;
10 5 0 0 0 1 1 ・・・ 1 1 0 133 onmousemove=alert``;
説明変数 目的変数
値の出力箇所(op_) エスケープの種類 (esc_)
データ:約1,300個、ラベル:約130種類のデータセット
※WAVSEPのXSSケースを基に手動で作成
デモンストレーション
(Recommender vs Webseclab)
AISECjp
AISECjp
デモ動画
https://www.youtube.com/watch?v=0PlQM1NwXlw
デモ詳細①
[request]http://xxx/xss/reflect/textarea1?in=foo1-----------------------------------------------------------------[response]<textarea name="in" rows="5" cols="60">foo1</textarea>
正常時
AISECjp
[request]http://xxx/xss/reflect/textarea1?in=foo1</textarea><img src=x onerror=alert();>-----------------------------------------------------------------[response]<textarea name="in" rows="5" cols="60">foo1</textarea><img src=x onerror=alert();></textarea>
レコメンド文字列で精査した結果(発火)
使用不可:[<script>], [</script>]
[recommended result](0.99938405 : </textarea><img src=x onerror=alert();>)(0.00043331 : <script>alert();</script>)(0.00012002 : </textarea><img src=x onerror=alert();>)
レコメンド結果
デモ詳細②
[request]http://xxx/xss/reflect/onmouseover_div_unquoted?in=changeme6-----------------------------------------------------------------[response]<div class=changeme6>123</div>
正常時
AISECjp
[request]http://xxx/xss/reflect/onmouseover_div_unquoted?in=changeme6 onmousemove=alert();-----------------------------------------------------------------[response]<div class=changeme6 onmousemove=alert(); >123</div>
レコメンド文字列で精査した結果(発火)
使用不可:[<script>], [</script>], [“], [‘], [<], [>]
[recommended result](0.98322958 : onmousemove=alert();)(0.01016408 : " onmousemove=alert();")(0.00303110 : "><script>alert();</script>)
レコメンド結果
デモ詳細③
[request]http://xxx/xss/reflect/onmouseover_unquoted?in=changeme5-----------------------------------------------------------------[response]Homepage: <input value=changeme5 name="in" size="40"><BR>
正常時
AISECjp
[request]http://xxx/xss/reflect/onmouseover_unquoted?in=changeme5 onmousemove=alert();-----------------------------------------------------------------[response]Homepage: <input value=changeme5 onmousemove=alert(); name="in" size="40"><BR>
レコメンド文字列で精査した結果(発火)
使用不可:[<script>], [</script>]
[recommended result](0.80970979 : "><frame src="javascript:alert()">)(0.18877983 : onmousemove=alert();)(0.00059442 : <img src=x onerror=alert();>)
レコメンド結果
まとめ
・脆弱性検査文字列のレコメンドは可能
⇒レスポンスに特徴が表れる脆弱性は同手法で対応可能
・未学習のパターンでもレコメンドできる場合もある
⇒但し、MLPでは適応能力(頑健性)は低い
・レコメンド精度は学習データ数(パターン)に依存
⇒手動での学習データ作成は限界か?
AISECjp
上級編に向けて
・特徴量の充実化
⇒ブラウザ依存、文字数制限、二重エンコード、文字コード等
・他脆弱性の検査文字列のレコメンド
⇒SQLインジェクション、OSコマンドインジェクション等
応答時間、正常・検査時のレスポンス差分等の複雑な特徴抽出が必要
・頑健性の向上
⇒CNNの畳み込みを活用できないか?
・学習データの自動生成
⇒脆弱性スキャナ・Local Proxyのプラグイン開発
AISECjp
検証コード及び学習データ
https://github.com/13o-bbr-bbq/machine_learning_security/tree/master/Recommender
AISECjp
Note:ご自身の管理下にあるシステムに対し、
ご自身の責任の下でご自由にお使いください。
Download “.PDF” version of this document:
≫ https://www.slideshare.net/babaroa