ããããã³ã°ã»ã©ãã®ã¤ãããã å®å
¨ç ä»®æ³ç°å¢ã«ãããããã«ã¼ä½é¨å¦ç¿ãã¨ãä½ç³»çã«å¦ã¶ å®å
¨ãªWebã¢ããªã±ã¼ã·ã§ã³ã®ä½ãæ¹ ç¬¬2ç èå¼±æ§ãçã¾ããåçã¨å¯¾çã®å®è·µãï¼é称ï¼å¾³ä¸¸æ¬ï¼ãåèã«ãã»ãã¥ãªãã£ã®åå¼·ãé²ãã¦ãã¾ãã
ä»åã¯ã徳丸æ¬ã® 3ç« ã®ãWebã»ãã¥ãªãã£ã®åºç¤ãã«ã¤ãã¦ãå®éã«ãã£ã¦ããããã¨æãã¾ãã
ããã§ã¯ããã£ã¦ããã¾ãã
åèæç®
ä»åãããç¬ç¿PHP 第4çããåèæ¸ã«è¿½å ãã¾ããã徳丸æ¬ã®ç¨æãã¦ããã¦ããå®ç¿ç°å¢ã§ã¯ãPHP ã使ããã¦ãã¾ããç§ã¯ PHP ã¯åãã¦ãªã®ã§ãããCè¨èªã«ä¼¼ã¦ãããã¨ããããç¬ç¿PHP ãããã°ãã¨ããããéåæãªãèªã¿è§£ãã¦ãã¾ãã
ç¬ç¿PHP ã«ã¯ãã»ãã·ã§ã³ç®¡çã®ãã¨ããã»ãã¥ãªãã£ã«ã¤ãã¦ããå¤ãã«è¨åãã¦ããã¦ãã¦ãç解ããããã£ãã§ããæ°å¤ãããæè¡æ¸ã®ä¸ã§ããç¬ç¿ã·ãªã¼ãºã¯å®å¿ãã¦ä½¿ããæ¬ã ã¨æãã¾ãã
ã¯ããã«
ãã»ãã¥ãªãã£ãã®è¨äºä¸è¦§ã§ããè¯ãã£ããåèã«ãã¦ãã ããã
ã»ãã¥ãªãã£ã®è¨äºä¸è¦§
徳丸æ¬ã®ç°å¢æ§ç¯ã«ã¤ãã¦ã¯ã以ä¸ã®ç¬¬9åã§ããã¾ããã
daisuke20240310.hatenablog.com
ã¾ãã徳丸æ¬ãç¨æãã¦ããã¦ãããèå¼±ãªã¢ããªã±ã¼ã·ã§ã³ Bad Todo ã®æºåã«ã¤ãã¦ã¯ã以ä¸ã®ç¬¬12åã§ããã¾ãããä»åã¯ããã®ç°å¢ã使ã£ã¦ãã£ã¦ããã¾ãã
daisuke20240310.hatenablog.com
Bad Todoã®ã»ãã·ã§ã³ç®¡çã確èªãã
ã¾ããBad Todo ã«ã¢ã¯ã»ã¹ããã¨ãã®ã·ã¼ã±ã³ã¹ã«ã¤ãã¦ãã»ãã·ã§ã³ã«é¢ããã¨ãããä¸å¿ã«ãå³ã«ãã¦ã¿ã¾ããã
Bad Todo ã¯ãèå¼±æ§ãå¤ãå«ãããã«ä½ããã¦ããããããã®ã·ã¼ã±ã³ã¹ãæ®éã¨ããããã§ã¯ãªãã®ã§ã注æãå¿
è¦ã§ãã
ã·ã¼ã±ã³ã¹å³ã®ã½ã¼ã¹ã³ã¼ããè²¼ã£ã¦ããã¾ãã
@startuml
title å¾³ä¸¸æ¬ Bad Todo
group ããããã¼ã¸ã«ã¢ã¯ã»ã¹ (ãã°ã¤ã³å)
Client -> Server: GET /todo/
Server -> Client: 200 OK
note left
index.phpã«todolist.phpãæ¸ããã¦ãã
end note
Client -> Server: GET /todo/todolist.php
Server -> Client: 200 OK (Set-Cookie: TODOSESSID=emce6a5kg99aurb263obo7fd82; path=/)
note left
ãã®æãã¯ã©ã¤ã¢ã³ãã«Cookieãä¿åããã
end note
end
group ãã°ã¤ã³ãã¯ãªã㯠(ãã°ã¤ã³å)
Client -> Server: GET /todo/login.php?url=todolist.php&TODOSESSID=emce6a5kg99aurb263obo7fd82
note right
ã»ãã·ã§ã³IDãURLã«åãè¾¼ã¾ãã¦ãã
(.user.iniã§URLèªååãè¾¼ã¿ã®è¨å®ã«ãªã£ã¦ãããã)
end note
Server -> Client: 200 OK
end
group ã¦ã¼ã¶IDã¨ãã¹ã¯ã¼ããå
¥åãã¦ãã°ã¤ã³ãã¿ã³ãã¯ãªãã¯
Client -> Server: POST /todo/logindo.php?
note left
ã¡ãã»ã¼ã¸ããã£ã®å
容
TODOSESSID=emce6a5kg99aurb263obo7fd82&userid=daisuke
&pwd=useruser&url=todolist.php
end note
Server -> Client: 302 Moved Temporarily
note right
ä¸è¦§ãã¼ã¸ã«ãªãã¤ã¬ã¯ããã¦ã
Set-Cookie: USER=O%3A4%3A%22User%22%3A3%3A%7Bs%3A8
%3A%22%00User%00id%22%3Bs%3A1%3A%223%22%3Bs%3A12%3A
%22%00User%00userid%22%3Bs%3A7%3A%22daisuke%22
%3Bs%3A11%3A%22%00User%00super%22%3Bs%3A1%3A
%220%22%3B%7D; path=/
end note
Client -> Server: GET /todo/todolist.php?TODOSESSID=emce6a5kg99aurb263obo7fd82
Server -> Client: 200 OK
end
group ãã°ã¢ã¦ããã¿ã³ãã¯ãªãã¯
Client -> Server: GET /todo/logout.php?TODOSESSID=emce6a5kg99aurb263obo7fd82
note left
Cookie: USER=O%3A4%3A%22User%22%3A3%3A%7Bs%3A8
%3A%22%00User%00id%22%3Bs%3A1%3A%223%22%3Bs%3A12%3A
%22%00User%00userid%22%3Bs%3A7%3A%22daisuke%22
%3Bs%3A11%3A%22%00User%00super%22%3Bs%3A1%3A
%220%22%3B%7D; path=/
end note
Server -> Client: 200 OK
note right
Set-Cookie: TODOSESSID=deleted;expires=Mon, 14-Aug-2023 05:48:22 GMT; path=/
Set-Cookie: USER=deleted; expires=Mon, 14-Aug-2023 05:48:22 GMT; path=/
end note
end
@enduml
Bad Todo ã®ã·ã¼ã±ã³ã¹ã«ã¤ãã¦ã§ãããå
¨è¬çã«ã¯ãã»ãã·ã§ã³ID ã URL ã«åãè¾¼ãã§ããã¨ãããç®ã«ã¤ãã¾ãã
HTTP ã¯ã¹ãã¼ãã¬ã¹ã®ãããã³ã«ã®ãããç¶æ
ãç¶æããï¼ã»ãã·ã§ã³ï¼ããã«ã¯ããµã¼ããã¯ã©ã¤ã¢ã³ãéã§ãä½ããã®ã¦ãã¼ã¯ãªæ
å ±ãå
±æãã¦ããå¿
è¦ãããã¾ãã
éå»ã«ã¯ãã»ãã·ã§ã³ç®¡çã¨ãã¦ãhiddenãã©ã¡ã¼ã¿ã§ãããããã¦ããæ代ããã£ãããã§ãããCookie ã使ãããããã«ãªããç¾å¨ã¯ãä¸æçãªä¹±æ°å¤ãã»ãã·ã§ã³ID ã¨ãã¦ãå®éã®ãã¼ã¿ï¼ã¦ã¼ã¶åããã¹ã¯ã¼ããªã©ï¼ã¯ããµã¼ãã§ç®¡çãããããã«ãªã£ãããã§ãã
éè¦ãªãã¼ã¿ã¯éä¿¡ä¸ã«ã¯åºãªããªãã¾ãããããã®ã»ãã·ã§ã³ID ãæ¼æ´©ããã¨ããã®ã¦ã¼ã¶ã«æããã¾ããã¨ãå¯è½ã«ãªãã¾ãã
ã»ãã·ã§ã³IDãæ¼æ´©ããå ´åã試ãï¼ã»ãã·ã§ã³ãã¤ã¸ã£ãã¯ï¼
å°ãå®é¨ãã¦ã¿ã¾ãã
ä»ãOWASP ZAP 㨠Firefox ã®çµã¿åããã§ãBad Todo ã«ã¢ã¯ã»ã¹ãã¦ãã¾ãã
Bad Todo ã«ã¯ã以åãæºåããã¨ãã«ç»é²ããéå
¬éã® Todo ã 1件追å ããã¦ãè¨3件ãç»é²ããã¦ãã¾ãã
Firefox ã§ãBad Todo ã«ãã°ã¤ã³ãã¦ããç¶æ
ã§ãOWASP ZAP 㧠HTTP ã®ã¢ã¯ã»ã¹ã確èªãã¾ãããªã¯ã¨ã¹ããããã«ãCookie ã®å¤ãããã®ã§ã³ãã¼ãã¦ããã¾ãã
次ã«ãä¸ã¨ã¯å¥ã«ãBurp Suite 㨠Chromium ã®çµã¿åããã§èµ·åãã¾ãï¼æ»æè
ï¼ã
ãã°ã¤ã³ãã¦ããªãç¶æ
ã§ãBad Todo ã«ã¢ã¯ã»ã¹ãã¾ããã²ã¹ãã¢ã«ã¦ã³ããªã®ã§ãå
ã»ã©ç»é²ããéå
¬éã® Todo ã¯è¦ããªãç¶æ
ã§ãã
Burp Suite ã® intercept ã ON ã«ãã¦ããã©ã¦ã¶ããªãã¼ããã¾ãã
ããã¨ãBurp Suite ã®æ¹ã§ãGETãªã¯ã¨ã¹ããæ¤ç¥ãã¦ãBad Todo ã¢ããªã«ãªã¯ã¨ã¹ããéããã«æ¢ãã¦ããã¦ãã¾ããããã§ããªã¯ã¨ã¹ããããã® Cookie ãå
ã»ã©ã³ãã¼ãããã®ã«ç½®ãæãã¾ãã
Forward ãã¯ãªãã¯ãã¦å
ã«é²ãã¾ããããã¨ãéå
¬éã®ã¯ãã® Todo ã表示ããã¦ãã¦ãã²ã¹ãã¢ã«ã¦ã³ãã ã£ãã®ããç»é²æ¸ã¿ã®ã¦ã¼ã¶ã§ãã°ã¤ã³ããããã«è¡¨ç¤ºããã¦ãã¾ãã
ã»ãã·ã§ã³ID ãæ¼æ´©ããã¨ããã°ã¤ã³ã¦ã¼ã¶ã«ããªããã¾ããã¨ãåºæ¥ã¦ãã¾ãã¨ããå®é¨ã§ããã
ä»åã¯æä½æ¥ã§ Cookie ãå·®ãæ¿ããã®ã§é¢åã«è¦ãã¾ãããé常㯠Python ãªã©ã®ã½ã¼ã¹ã³ã¼ãã§æ»æãå®ç¾ãããããCookie ãå·®ãæ¿ãç¶ãããã¨ãç°¡åã«å¯è½ã«ãªãã¾ãã
ãã®ããããã°ã¤ã³ããã¦ã¼ã¶ã¨åããã¨ãåºæ¥ãã®ã§ãTodo ãåé¤ãããããã°ã¤ã³ã¦ã¼ã¶ã®ãã¹ã¯ã¼ããå¤æ´ãããåºæ¥ã¦ãã¾ãã¾ãï¼Bad Todo ã¯ããã¹ã¯ã¼ãå¤æ´æã«ãå¤ããã¹ã¯ã¼ããèãããªãããï¼ã
Bad Todoã®æ¹å
Bad Todo ãå¤æ´ãã¦ãå¯è½ãªãæ¹åãã¦ããããã¨æãã¾ãã
wasbook ã«ã¯ãSSH ã§ãã°ã¤ã³ã§ãã¾ãããã¡ã¤ã«æ¤ç´¢ããã¨ãããBad Todo ã¯ã/var/www/html/todo
ã§åä½ãã¦ããããã§ãã
URLã«ã»ãã·ã§ã³IDãåãè¾¼ã¾ããªãããã«å¯¾çãã
ã¾ããURL ã«ã»ãã·ã§ã³ID ãåãè¾¼ã¾ããªãããã«ãPHP ã®è¨å®ãã¡ã¤ã«ã§å¯¾çãã¦ã¿ã¾ãã
è¨å®ãã¡ã¤ã«ã¯ã/var/www/html/todo/.user.ini
ã«ããã¾ãããç¾ç¶ã¯ã以ä¸ã®ããã«ãªã£ã¦ãã¾ãã
1è¡ç®ã¯ãã¯ããã¼ã使ç¨ããè¨å®ã§ããã®ã¾ã¾ã§ããã§ãã
2è¡ç®ã¯ãã»ãã·ã§ã³ID ã®åã渡ãã«ã¯ããã¼ã ãã使ç¨ããï¼URLã«åãè¾¼ã¾ãªãï¼è¨å®ã§ããã㯠On ã«è¨å®ãããã¨ããã§ãã
3è¡ç®ã¯ãã¯ããã¼ããã»ãã·ã§ã³ID ãåå¾ã§ããªãã£ãå ´åã«ããã¼ã¸ä¸ã® URL ã«ã»ãã·ã§ã³ID ãåãè¾¼ã¾ããè¨å®ã§ãããã¡ã㯠Off ã«è¨å®ãããã¨ããã§ãã
session.use_cookies=On
session.use_only_cookies=Off
session.use_trans_sid=On
ã¨ããããã§ã2è¡ç®ã¨3è¡ç®ãå¤æ´ãã¾ããå¤æ´å¾ã¯ä»¥ä¸ã§ãã
session.use_cookies=On
session.use_only_cookies=On
session.use_trans_sid=Off
wasbook ãåèµ·åãã¾ãã
対çãåºæ¥ããã確èªãã
å度ããã°ã¤ã³ãããã°ã¢ã¦ãã¾ã§ã®ã·ã¼ã±ã³ã¹ã確èªãã¾ããã主ãªå¤æ´å
容ã¯èµ¤åã§ç¤ºãã¦ãã¾ãã
URL ã«ã»ãã·ã§ã³ID ãå«ã¾ããªããªã£ããã¨ã確èªã§ãã¾ããã
ãããã«
ä»åã¯ãã»ãã·ã§ã³ç®¡çã«ã¤ãã¦ç解ãæ·±ãã¾ãããã»ãã·ã§ã³ID ã URL ã«åãè¾¼ã¾ãã¦ããã ãã§ã¯æããã¾ããã¨ã¯é£ããã§ãããä»ã®æ»ææ¹æ³ã¨åããã¦è¡ããã¨ã§ãã»ãã·ã§ã³ID ãæ¼æ´©ãã¦ãã¾ãã±ã¼ã¹ãããã¾ãã
ä»åã¯ãBurp Suite ã®ãã´ã使ããã¦ããã ãã¾ããããããã¨ããããã¾ãã
æå¾ã«ãªãã¾ããããã¨ã³ã¸ãã¢ã°ã«ã¼ãã®ã©ã³ãã³ã°ã«åå ä¸ã§ãã
æ°æ¥½ã«ãããã¨ãããããé¡ããããã¾ãð
ä»åã¯ä»¥ä¸ã§ãï¼
æå¾ã¾ã§ãèªã¿ããã ãããããã¨ããããã¾ããã