DOM Document node html node body node h
DOMツリーの例 Document 要素node html 要素node body 要素node h 1 属性node text node id=title アンケー ト 要素node div 要素node a 属性node id=url href=surve y. html text node 属性node クリック id=deadlin e
例えば、「survey. html」のURLを、ア タッカーページのURLに変更したいとき ① 【Java. Scritp】 ①document. ②get. Element. By. Id(‘url'). ③href = “http: //localhost/Web/Scenario 105/ attackers_page. php”; Document 要素node html 要素node body 要素node ② h 1 要素node a div ③ 属性node text node 属性node id=title アンケー ト id=url href=surv ey. html クリック id=deadlin e
例えば、 「12月末締切」という文字列 を追加したいとき Document 要素node html 要素node 【Java. Scritp】 ① var text = document. create. Text. Node("12月 末締切"); ②document. get. Element. By. Id("dea dline"). append. Child(text); body 要素node h 1 a div ② 属性node text node id=title アンケー ト id=url href=surv ey. html クリック id=deadlin e 12月末締 ①切
変更後のHTMLの例 <html><head><script type="text/javascript"> window. onload=function(){ document. get. Element. By. Id("url"). href="http: //localhost/Web/Scenario 105/attackers_page. php"; var text = document. create. Text. Node("12月末締切"); document. get. Element. By. Id("deadline"). append. Child(text); } </script></head> <body id="body"> <h 1 id="title">アンケートページ</h 1> <a id="url" href="survey. html">クリック</a> <div id="deadline"></div> </body></html> http: //localhost/Web/Scenario 10 5/attackers_page. php
1.Webサイトの挙動を把握する Java. Script (つづき) 検索キーワードの文字を復号化して表示 try { var keyword = get_keyword(); document. write(decode. URIComponent(keyword)); } catch(e) { try { var keyword = get_keyword(); document. write(keyword); } catch(e) {} } 例外的なエラーが出た場合、復号化せずに表示
4.スクリプトを掲示板に投稿 する 掲示板に投稿するURLを作成しよう。 http: //localhost/Web/Scenario 105/Vul. Soft/search. php? p age=1&submit=1&keyword=<作成スクリプト> 作成したスクリプトを追記してください。 作成したURLを掲示板のURLフォームに投稿し、動作 を確認してください。 http: //localhost/Web/Scenario 105/Vul. Soft/search. php? page=1 &submit=1&keyword=<script>document. get. Element. By. Id('link 0'). href='http: //localhost/Web/Scenario 105/attackers_page. ph p'; </script>
1. Java. Scriptの内容確認 function get_keyword() { var param = location. search; param = param. replace(/+/g, decode. URIComponent(" ")); var re = /(? |&)keyword=([^&]*)/; return re. exec(param)[2]; } try { var keyword = get_keyword(); keyword = decode. URIComponent(keyword); document. write(keyword); } catch(e) {}
2.キーワードを表示する箇所 の特定 function get_keyword() { var param = location. search; param = param. replace(/+/g, decode. URIComponent(" ")); var re = /(? |&)keyword=([^&]*)/; return re. exec(param)[2]; } try { var keyword = get_keyword(); keyword = decode. URIComponent(keyword); document. write(keyword); } catch(e) {}
3.エスケープ処理を行うプロ グラムの修正 function get_keyword() { var param = location. search; param = param. replace(/+/g, decode. URIComponent(" ")); var re = /(? |&)keyword=([^&]*)/; return re. exec(param)[2]; } try { var keyword = get_keyword(); keyword = decode. URIComponent(keyword); var text = document. create. Text. Node(keyword); document. get. Element. By. Id(‘query_string’). append. Child(text); } catch(e) {}
動作確認 スクリプトを含むURLを掲示板に投稿してみましょう。 http: //localhost/Web/Scenario 105/Edit. Soft/search. php? p age=1&submit=1&keyword=<script>document. get. Eleme nt. By. Id('link 0'). href='http: //localhost/Web/Scenario 105/att ackers_page. php'; </script> 投稿したスクリプトが実行されず、そのまま文字として 出力され、検索後のURLが変更されていなければOKで す。
1.データベースのデータ表示 形式変換処理の内容の確認 public function get_contents() { $this->_contents["contents"] = array(); while($row = $this->stmt->fetch()) { $content = array(); foreach($row as $k => $v) { $value = null; 「掲示板に埋め込まれるスクリプト(格納 型)」テーマの「脆弱性の修正」リンクに あるbbs. cloass. phpファイルの get_contents()関数と同じです。 詳細は、格納型XSSの第 4回講義資料を参照 してください。 if ($k == parent: : CONTENT) { $value = nl 2 br($row[$k]); $this->is_success($value); } else { $value = htmlspecialchars($row[$k], ENT_QUOTES, "UTF-8"); } $content[$k] = $value; } $this->_contents["contents"][] = $content; } $this->_contents["token"] = App. Goat. Util: : get. Token(); return $this->_contents; }
2.htmlspecialchars関数を使 用する箇所の特定 foreach($row as $k => $v) { $value = null; if ($k == parent: : CONTENT) { $value = nl 2 br($row[$k]); $this->is_success($value); } else { $value = htmlspecialchars($row[$k], ENT_QUOTES, "UTF -8"); } $content[$k] = $value; }
3.htmlspecialchars関数を使 用したプログラムへの修正 foreach($row as $k => $v) { $value = null; if ($k == parent: : CONTENT) { $value = nl 2 br(htmlspecialchars($row[$k], ENT_QUOTES, "UTF-8")); $this->is_success($value); } else { $value = htmlspecialchars($row[$k], ENT_QUOTES, "UTF -8"); } $content[$k] = $value; }
- Slides: 52