ããããã³ã°ã»ã©ãã®ã¤ãããã å®å
¨ç ä»®æ³ç°å¢ã«ãããããã«ã¼ä½é¨å¦ç¿ãã¨ãä½ç³»çã«å¦ã¶ å®å
¨ãªWebã¢ããªã±ã¼ã·ã§ã³ã®ä½ãæ¹ ç¬¬2ç èå¼±æ§ãçã¾ããåçã¨å¯¾çã®å®è·µãï¼é称ï¼å¾³ä¸¸æ¬ï¼ãåèã«ãã»ãã¥ãªãã£ã®åå¼·ãé²ãã¦ãã¾ãã
åå ã¯ãã»ãã·ã§ã³ç®¡çã®ç解ã¨ãå®éã«ãªããã¾ãã試ããã®ã¨ãPHP ã®ã»ãã·ã§ã³ID ã URL ã«åãè¾¼ã¾ãªã対çãè¡ãã¾ããã
ä»åã¯ãåã
å ã«è¡ã£ã OWASP ZAP ã®èªåèå¼±æ§ã¹ãã£ã³ã®çµæã®ããã¹ãã©ãã¼ãµã«ãã«ã¤ãã¦ãåæã¨å¯è½ãªã対çã¾ã§ãã£ã¦ããããã¨æãã¾ãã
ããã§ã¯ããã£ã¦ããã¾ãã
åèæç®
ã¯ããã«
ãã»ãã¥ãªãã£ãã®è¨äºä¸è¦§ã§ããè¯ãã£ããåèã«ãã¦ãã ããã
ã»ãã¥ãªãã£ã®è¨äºä¸è¦§
徳丸æ¬ã®ç°å¢æ§ç¯ã«ã¤ãã¦ã¯ã以ä¸ã®ç¬¬9åã§ããã¾ããã
daisuke20240310.hatenablog.com
ã¾ãã徳丸æ¬ãç¨æãã¦ããã¦ãããèå¼±ãªã¢ããªã±ã¼ã·ã§ã³ Bad Todo ã®æºåã«ã¤ãã¦ã¯ã以ä¸ã®ç¬¬12åã§ããã¾ãããä»åã¯ããã®ç°å¢ã使ã£ã¦ãã£ã¦ããã¾ãã
daisuke20240310.hatenablog.com
ãã¹ãã©ãã¼ãµã«ã®æ¤åºçµæã®ç¢ºèªï¼GETï¼
ä»åã¯ãæ¸ç±ã§ã解説ããã¦ããããã«ããã¹ãã©ãã¼ãµã«ã®ã¢ã©ã¼ããè¦ã¦ã¿ã¾ãã
GETãªã¯ã¨ã¹ãã§ä»»æã®ãã¡ã¤ã«ãèªã¿åºããèå¼±æ§ã®åæ
GET ã®æ¹ãé¸æãã¾ããã©ãããã/etc/passwd ãèªã¿åºããã¨ãåºæ¥ãèå¼±æ§ã®ããã§ããããã¯ããªã¹ã¯ï¼Highãã§ããï¼ç¬ï¼ã
Bad Todo ã®ã½ã¼ã¹ã³ã¼ãã確èªãã¦ã¿ã¾ããã
ãã¤ãã¼ã¸ã«ã¢ã¯ã»ã¹ããã¨ãèªåã®æ
å ±ãæ´æ°ããããéä¼ã§ããããã¾ãã
ãã®ãã¼ã¸ã«ã¢ã¯ã»ã¹ããã¨ããç»é²ããã¢ã¤ã³ã³ã表示ãããã®ã§ãããããã§ä»¥ä¸ã®ã½ã¼ã¹ã³ã¼ãã®ããã«ãç»é²ããç»åãã¡ã¤ã«ããªãµã¤ãºããå¥ã®ãã¼ã¸ã«ã¢ã¯ã»ã¹ãã¦ãã¦ãããã§ç»åãã¡ã¤ã«ã®ãã¹ã URL ã«åãè¾¼ãã§ãã¾ã£ã¦ãã¾ãã
ã½ã¼ã¹ã³ã¼ãã¯ãmypage.php ã® L46 ã§ãã$icon
ã«ãç»åãã¡ã¤ã«ã®ãã¹ãå
¥ã£ã¦ããã¨æãã¾ãã
<td>ã¢ã¤ã³ã³</td>
<td>
<img src="resize.php?path=icons&basename=<?php e($icon); ?>&size=64">
<a href="changeicon.php?id=<?php e($reqid); ?>">å¤æ´</a>
</td>
GETãªã¯ã¨ã¹ãã§ä»»æã®ãã¡ã¤ã«ãèªã¿åºããèå¼±æ§ã®åç¾
/etc/passwd ãèªã¿åºããèå¼±æ§ãåç¾ãã¦ã¿ããã¨æãã¾ãã
OWASP ZAP ã§ãããããã£ã¦ã¿ãã®ã§ãããä»åããã¤ãè¨å®ããå½±é¿ãªã®ãããã¾ãåãããªãã£ãã§ããããã§ãBurp Suite ã使ã£ã¦ãåç¾ããã¦ã¿ããã¨æãã¾ãã
Burp Suite ãèµ·åãã¦ãChromium ãèµ·åãã¾ããBad Todo ã«ãã°ã¤ã³ãã¦ããã¤ãã¼ã¸ã«ç§»åãã¾ãããã®ã¨ããChromium ã¯ãã¤ãã¼ã¸ã«è¡¨ç¤ºããç»é²ãããã¢ã¤ã³ã³ãèªã¿ã ããã¨ãµã¼ãã«ãªã¯ã¨ã¹ããã¾ãããã®ã¢ã¤ã³ã³ã®ãã¹ã /etc/passwd ã«å¤æ´ãããã¨ã§ãèªã¿åºããã¨ããèå¼±æ§ã ã£ãããã§ãã
ã§ã¯ããã¤ãã¼ã¸ã«ç§»åããç´åã« Intercept ãæå¹ã«ãã¾ããæåã® GETãªã¯ã¨ã¹ãã¯ããã¤ãã¼ã¸ã®ãã¼ã¸èªä½ãªã®ã§ãForward ãæ¼ãã¦ãã¹ã«ã¼ãã¾ãã
次ã®ã¢ã¤ã³ã³ã® GETãªã¯ã¨ã¹ãã§ããã¹ã /etc/passwd ã®ãã¹ã«ç½®ãæãã¦ãForward ãã¯ãªãã¯ãã¾ãã
HTTP history ã§çµæã確èªãã¾ããå·¦å´ã GETãªã¯ã¨ã¹ãã§ããã¹ãç½®ãæããåã®å
容ãæ¸ããã¦ãã¾ãããä¸ã®ä¸è¦§ã§ã¯ Editedï¼ç·¨éããã¨ãããã¨ã§ãï¼ã«ãã§ãã¯ãå
¥ã£ã¦ãã¾ãã
å³å´ãã¬ã¹ãã³ã¹ã§ã/etc/passwd ã®å
容ãèªã¿åºãã¦ãã¾ãã
å®éã«è¦ã¤ãã£ãèå¼±æ§ã確èªãã¦ããã®åç¾ã¾ã§ãã£ã¦ã¿ã¾ããããã°ã¤ã³ã§ãããã¨ãåæã«ãªãã¾ãããããããã©ããªãã¡ã¤ã«ã§ãèªã¿åºãããã ã¨æãã¾ãã
GETãªã¯ã¨ã¹ãã§ä»»æã®ãã¡ã¤ã«ãèªã¿åºããèå¼±æ§ã®å¯¾ç
対çæ¹æ³ã¨ãã¦ã¯ãç°¡åã«æãã¤ãã®ã¯ããããã GETãªã¯ã¨ã¹ãã使ãå¿
è¦ã¯ãªãã¨æãã®ã§ãé¢æ°å¼ã³åºãã«å¤ãããã¨ãã§ãããã
ãããã¯ãã¢ã¤ã³ã³ã®ç»åãã¡ã¤ã«ã®ãã¹ã渡ãã®ã§ã¯ãªããã¦ã¼ã¶åã渡ãã¦ãresize.php ã®æ¹ã§ããã¼ã¿ãã¼ã¹ããã¢ã¤ã³ã³ã®ç»åãã¡ã¤ã«ã®ãã¹ãåå¾ãããã§ããããã
åè
ã®æ¹ãé©åã§ããä¿®æ£éãå¤ããã§ããå¾è
ã¯ãã¼ã¿ãã¼ã¹ã¸ã®ã¢ã¯ã»ã¹ã2åã«ãªã£ã¦ããã¾ãè¯ããªãä¿®æ£ã§ãã
ã½ã¼ã¹ã³ã¼ããæ¤ç´¢ããã¨ããã® resize.php ã¯ãä»ã«1ãæï¼todo.phpï¼ãã使ããã¦ãã¾ãã
PHPè¨èªã®åå¼·ã¨èãã¦ãåè
ã®æ¹æ³ã§ä¿®æ£ãã¾ãã
resize.php ã¯ãã®ã¾ã¾ã¨ãã¦ãæ°ãããresize_func.php ãä½ãã¾ãã
<?php
function resize($path, $basename, $size) {
$file = "$path/$basename";
$xfile = "$path/_${size}_$basename";
error_log("file={$file}/" . gettype($file) . ", xfile={$xfile}/" . gettype($xfile));
if (! file_exists($xfile)) {
copy($file, $xfile);
exec("imgp -x {$size}x{$size} -w {$xfile}");
}
error_log("{$xfile}");
return $xfile;
}
?>
å¼ã³åºãå´ã® mypage.php ã®ä¿®æ£ç¹ã¯ä»¥ä¸ã§ãã
--- todo.org/mypage.php 2018-08-15 10:51:05.000000000 +0900
+++ todo.change/mypage.php 2024-08-14 14:40:06.000000000 +0900
@@ -1,5 +1,6 @@
<?php
require_once('./common.php');
+ require_once('./resize_func.php');
$id = $user->get_id();
$reqid = filter_input(INPUT_GET, 'id');
$ok = $user->is_super() || $id === $reqid;
@@ -16,6 +17,8 @@
$email = $result['email'];
$pwd = $result['pwd'];
$icon = $result['icon'];
+ $icon_resize = resize('icons', $icon, '64');
+ error_log("icon=${icon}/" . gettype($icon) . ", icon_resize=${icon_resize}");
}
} catch (PDOException $e) {
$logger->add('ã¯ã¨ãªã«å¤±æãã¾ãã: ' . $e->getMessage());
@@ -43,7 +46,7 @@
<td>ãã¹ã¯ã¼ã</td><td>****** <a href="changepwd.php?id=<?php e($reqid); ?>">å¤æ´</a></td>
</tr>
<tr>
- <td>ã¢ã¤ã³ã³</td><td><img src="resize.php?path=icons&basename=<?php e($icon); ?>&size=64"><a href="changeicon.php?id=<?php e($reqid); ?>">å¤æ´</a></td>
+ <td>ã¢ã¤ã³ã³</td><td><img src=<?php e($icon_resize); ?>><a href="changeicon.php?id=<?php e($reqid); ?>">å¤æ´</a></td>
</tr>
</table>
<a href="quit.php?id=<?php e($reqid); ?>">éä¼ãã</a>
ãã1ã¤ã®å¼ã³åºãå´ã® todo.php ã®ä¿®æ£ç¹ã¯ä»¥ä¸ã§ãã
--- todo.org/todo.php 2018-08-18 16:37:29.000000000 +0900
+++ todo.change/todo.php 2024-08-13 20:52:59.000000000 +0900
@@ -1,5 +1,6 @@
<?php
require_once('./common.php');
+ require_once('./resize_func.php');
$item = $_GET['item'];
$id = $user->get_id();
@@ -14,6 +15,7 @@
$logger->add('ã¯ã¨ãªã«å¤±æãã¾ãã: ' . $e->getMessage());
die('åªä»ãµã¤ãã大å¤æ··éãã¦ãã¾ãããããã°ããçµã£ã¦ããã¢ã¯ã»ã¹ãã¦ãã ãã');
}
+ $icon_resize = resize('icons', $result['icon'], '64');
?><html>
<head>
<link rel="stylesheet" type="text/css" href="css/common.css">
@@ -26,7 +28,7 @@
<?php if (! empty($result)): ?>
<table style="width: 70%;">
<tr>
- <td>ID</td><td><?php e($result['userid']); ?><img src="resize.php?path=icons&basename=<?php e($result['icon']); ?>&size=64"></td>
+ <td>ID</td><td><?php e($result['userid']); ?><img src=<?php e($icon_resize); ?>></td>
</tr>
<tr>
<td>todo</td><td><?php
ããã§åãã¾ãããã ãã¶è¦å´ãã¾ããã
ä¿®æ£ã¨åä½ç¢ºèªãããä¸ã§å¿
è¦ã«ãªã£ãå
容ï¼PHP ã§éçºããåºç¤çãªå
容ï¼ãªã©ãå¾è¿°ãã¾ãã
ãã¹ãã©ãã¼ãµã«ã®æ¤åºçµæã®ç¢ºèªï¼POSTï¼
ãã¹ãã©ãã¼ãµã«ã§ããã1ç¹ã®æ¤åºãããèå¼±æ§ã§ãã
POSTãªã¯ã¨ã¹ãã®èå¼±æ§ã®åæ
以ä¸ã®ãã£ããã£ä»¥å¤ã«ãç¹ã«æ
å ±ãããã¾ããã証æ ã®ã¨ããã空æ¬ã§ããã
ã¬ã¹ãã³ã¹ã®ã¨ããã«ãã¨ã©ã¼ï¼Noticeï¼ãåºã¦ã¦ãlogindo.php ã®ãã¹ã®æ
å ±ãåºã¦ãã¾ã£ã¦ãããã¨ãèå¼±æ§ã¨ææãããã®ã§ããããã
ã¨ã©ã¼ã«ãªã£ã¦ããã½ã¼ã¹ã³ã¼ãã§ãããã¨ãPOST ã§æ¸¡ãã¦ãããã¼ã¿ã¯ãuserid=daisuke&pwd=useruser&url=logindo.php
ã§ãã
<?php
require_once './common.php';
try {
$dbh = dblogin();
$userid = filter_input(INPUT_POST, 'userid');
$pwd = substr($_POST['pwd'], 0, 6);
$url = filter_input(INPUT_POST, 'url');
POSTãªã¯ã¨ã¹ãã®èå¼±æ§ã®åç¾
ã¨ãããããåç¾ããã¦ã¿ã¾ãã
æ®éã«ãã°ã¤ã³ã§ãã¾ãããããããããè¦ãããé常ã®POSTãã¼ã¿ã¯ãurl=todolist.php
ã§ãurl=logindo.php
ã§ã¯ãªãã§ãã
èªå診æã§ã¯ããã©ã¡ã¼ã¿ãå¤æ´ãã¦è©¦ãã¦ãããã§ãããéããã©ã¡ã¼ã¿ãå
¥ããã¨ãå¤ãªå¿çãè¿ã£ã¦ããã®ã§ã診æã§ææããã¨ãããã¨ã§ããããã
Burp Suite ã§ããã°ã¤ã³ããã¨ãã« intercept ãã¦ãPOSTãã¼ã¿ããurl=todolist.php
ãã url=logindo.php
ã«å¤æ´ãã¦ãPOSTãªã¯ã¨ã¹ããã¦ã¿ã¾ãã
åç¾ãã¾ããã
POSTãªã¯ã¨ã¹ãã®å¾ãé常ãªããtodolist.phpï¼urlãã©ã¡ã¼ã¿ã§æå®ãã URLï¼ã«ãªãã¤ã¬ã¯ããããã¨ããããlogindo.php ã«ãªãã¤ã¬ã¯ãããã¾ããããããuseridãpwdãurl ã®ãã©ã¡ã¼ã¿ãè¨å®ããã¦ãªãã®ã§ãpwd ã®ä¸é¨ãåãåºãã¨ããã§ã¨ã©ã¼ãåºãã¨ãããã¨ã ã¨æãã¾ãã
åç¾ã§ããã®ã§ãã¨ã©ã¼ãçºçããªãããã«ä¿®æ£ãã¦ã¿ã¾ãã
POSTãªã¯ã¨ã¹ãã®èå¼±æ§ã®åç¾
ä¿®æ£ããã½ã¼ã¹ã³ã¼ãã®å·®åã§ããPOSTãã¼ã¿ãæ ¼ç´ããã¦ãããããã§ãã¯ãã¦ãå
¥ã£ã¦ããªãã£ãããexit ããã ãã®ç°¡åãªå¯¾çã§ãã
--- todo.org/logindo.php 2018-08-15 15:29:23.000000000 +0900
+++ todo.change/logindo.php 2024-08-13 21:34:15.000000000 +0900
@@ -1,5 +1,8 @@
<?php
require_once './common.php';
+ if (! isset($_POST['userid']) || ! isset($_POST['pwd']) || ! isset($_POST['url'])) {
+ exit;
+ }
try {
$dbh = dblogin();
$userid = filter_input(INPUT_POST, 'userid');
ä¿®æ£ããå¾ããã£ãã®åç¾æé ãå®æ½ããã¨ãçã£ç½ãªãã¼ã¸ã«ãªãã ãã§ããããã¨ã©ã¼ã¯åºã¾ããã§ãããã¨ãããããããã§ãããä¸åº¦ãèªå診æãã¦ã¿ããã¨ã«ãã¾ãã
èªåèå¼±æ§ã¹ãã£ã³ã®åå®è¡
å診æã®çµæã以ä¸ã§ãã25件ã23件ã«ãªãã¾ãããGETãªã¯ã¨ã¹ãã®ææã¯ç¡ããªãã¾ããããPOSTãªã¯ã¨ã¹ãã®æ¹ã¯æ®ã£ã¦ãã¾ãã
ãã以å¤ã§1件æ¸ã£ã¦ããã®ã¯ãååã®ã徳丸本:セッション管理を理解してセッションID漏洩で成りすましを試す - 土日の勉強ノートãã§ãPHP ã®è¨å®ãè¦ç´ãããã¨ã§ãXSS ã®é
ç®ãæ¸ã£ããã ã¨æãã¾ãã
POSTãªã¯ã¨ã¹ãã®èå¼±æ§ã¯å¯¾çã§ãã¾ããã§ãããNoticeï¼ã¨ã©ã¼ï¼ãåºã¦ããã¨ãåå ã ã¨æã£ãã®ã§ãããéãåå ã§ææããã¦ããã®ããããã¾ããã
ä»å¾ã¯ãä»ã®ã¢ã©ã¼ãã®å
容ã対çãã¦ãã©ããã¦ãããã ããåãããªãã£ããã徳丸æ¬ã®ãµãã¼ãML ã«è³ªåãã¦ã¿ããã¨æãã¾ãããããåå ãåãã£ããããã®è¨äºã«è¿½è¨ãããã¨æãã¾ãã
wasbookã®PHPãå¤æ´ããã¨ãã®ã¡ã¢
- å¤æ´ããã³ã¼ãã¯ãApache ãåèµ·åããªãã¦ããããã«åæ ããã
- ãããã°ãã°ãå
¥ãããå ´åãPHPã³ã¼ãï¼
<?php ãã ?>
ã®ä¸ï¼ã«ãerror_log("icon=${icon}");
ãå
¥ãã
- ãããã°ãã°ãè¦ãã«ã¯ãroot ã«ãªã£ã¦ï¼
$ sudo su
ï¼ã# tail -f /var/log/apache2/error.log
ã§ã¢ãã¿ãã¦ãã
ãããã«
ä»åã¯ããã¹ãã©ãã¼ãµã«ã®èå¼±æ§ã«ã¤ãã¦ãåç¾ã¨å¯¾çãè¡ãã¾ãããæ®å¿µãªãããPOSTãªã¯ã¨ã¹ãã®ææã«ã¤ãã¦ã¯åå ãåããã¾ããã§ãããããããã«æ¬¡ã®ææãé²ãããã¨æãã¾ãã
ä»åã¯ãPHP ã®ãã´ã使ããã¦ããã ãã¾ããããããã¨ããããã¾ãã
æå¾ã«ãªãã¾ããããã¨ã³ã¸ãã¢ã°ã«ã¼ãã®ã©ã³ãã³ã°ã«åå ä¸ã§ãã
æ°æ¥½ã«ãããã¨ãããããé¡ããããã¾ãð
ä»åã¯ä»¥ä¸ã§ãï¼
æå¾ã¾ã§ãèªã¿ããã ãããããã¨ããããã¾ããã