首页
技术博客
PHP教程
数据库技术
前端开发
HTML5
Nginx
php论坛
新用户注册
|
会员登录
PHP教程
技术博客
编程问答
PNG素材
编程语言
前端技术
Android
PHP教程
HTML5教程
数据库
Linux技术
Nginx技术
PHP安全
WebSerer
职场攻略
JavaScript
开放平台
业界资讯
大话程序猿
登录
极速注册
取消
热门标签 | HotTags
yaml
plugins
command
sum
keyword
web
lua
range
chat
triggers
instance
cPlusPlus
grid
audio
settings
scala
httpclient
golang
dockerfile
php8
bash
erlang
stream
process
header
dll
netty
replace
config
blob
md5
heap
int
数组
datetime
install
char
jsp
search
javascript
typescript
actionscrip
shell
solr
regex
format
email
list
expression
timezone
c语言
uri
utf-8
less
php
tags
integer
random
python
case
bitmap
loops
request
web3
iostream
import
io
merge
foreach
ascii
ip
controller
js
nodejs
express
version
vbscript
hashcode
flutter
当前位置:
开发笔记
>
编程语言
> 正文
再看ibatisOrderBy注入问题
作者:mobiledu2502931997 | 来源:互联网 | 2024-09-27 19:50
接上文http:blog.itpub.net29254281viewspace-1318239领导让开发同学鼓捣一个可配置化的后台.又回到了原来的问题如果要灵活,很多参数要
接上文
http://blog.itpub.net/29254281/viewspace-1318239/
领导让开发同学鼓捣一个可配置化的后台.
又回到了原来的问题
如果要灵活,很多参数要从前端页面传过来,有SQL注入的风险.
如果参数化SQL,又很难做到灵活..
先看一个注入的例子:
import
java.sql.Connection;
import
java.sql.DriverManager;
import
java.sql.ResultSet;
import
java.sql.SQLException;
import
java.sql.Statement;
public
class
Test {
public
static
void
main(String[] args)
throws
SQLException {
String para=
"/index.html' union all select * from probe -- "
;
Connection conn = DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/mvbox"
,
"xx"
,
"xx"
);
Statement ps=conn.createStatement();
ResultSet rs = ps.executeQuery(
"select * from probe where path='"
+para+
"'"
);
while
(rs.next()) {
System.out.println(rs.getString(
"host"
)+
":"
+rs.getString(
"path"
));
}
rs.close();
ps.close();
conn.close();
}
}
如果要避免这种风险,可以选择参数化
import
java.sql.Connection;
import
java.sql.DriverManager;
import
java.sql.PreparedStatement;
import
java.sql.ResultSet;
import
java.sql.SQLException;
public
class
Test {
public
static
void
main(String[] args)
throws
SQLException {
String para=
"/index.html' union all select * from probe -- "
;
Connection conn = DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/mvbox"
,
"xx"
,
"xx"
);
PreparedStatement ps=conn.prepareStatement(
"select * from probe where path=?"
);
ps.setString(
1
, para);
ResultSet rs=ps.executeQuery();
while
(rs.next()) {
System.out.println(rs.getString(
"host"
)+
":"
+rs.getString(
"path"
));
}
rs.close();
ps.close();
conn.close();
}
}
为何参数化可以防止注入?
作为MySQL JDBC驱动来说(5.1.31),其实就是对敏感字符做了转义.
观察 com.mysql.jdbc.PreparedStatement 的 setString方法
可以看到有如下的替换过程
String parameterAsString = x;
boolean
needsQuoted =
true
;
if
(
this
.isLoadDataQuery || isEscapeNeededForString(x, stringLength)) {
needsQuoted =
false
;
// saves an allocation later
StringBuffer buf =
new
StringBuffer((
int
) (x.length() *
1.1
));
buf.append(
'\''
);
//
// Note: buf.append(char) is _faster_ than
// appending in blocks, because the block
// append requires a System.arraycopy()....
// go figure...
//
for
(
int
i =
0
; i < stringLength; ++i) {
char
c = x.charAt(i);
switch
(c) {
case
0
:
/* Must be escaped for 'mysql' */
buf.append(
'\\'
);
buf.append(
'0'
);
break
;
case
'\n'
:
/* Must be escaped for logs */
buf.append(
'\\'
);
buf.append(
'n'
);
break
;
case
'\r'
:
buf.append(
'\\'
);
buf.append(
'r'
);
break
;
case
'\\'
:
buf.append(
'\\'
);
buf.append(
'\\'
);
break
;
case
'\''
:
buf.append(
'\\'
);
buf.append(
'\''
);
break
;
case
'"'
:
/* Better safe than sorry */
if
(
this
.usingAnsiMode) {
buf.append(
'\\'
);
}
buf.append(
'"'
);
break
;
case
'\032'
:
/* This gives problems on Win32 */
buf.append(
'\\'
);
buf.append(
'Z'
);
break
;
case
'\u00a5'
:
case
'\u20a9'
:
// escape characters interpreted as backslash by mysql
if
(charsetEncoder !=
null
) {
CharBuffer cbuf = CharBuffer.allocate(
1
);
ByteBuffer bbuf = ByteBuffer.allocate(
1
);
cbuf.put(c);
cbuf.position(
0
);
charsetEncoder.encode(cbuf, bbuf,
true
);
if
(bbuf.get(
0
) ==
'\\'
) {
buf.append(
'\\'
);
}
}
// fall through
default
:
buf.append(c);
}
}
buf.append(
'\''
);
parameterAsString = buf.toString();
}
是不是可以使用 iBatis 的 $ 方式 增加灵活性,而在参数进入iBatis之前,手工进行一下敏感字符替换,而防止SQL注入攻击呢?
注入
http
view
sql
string
io
buffer
int
char
写下你的评论吧 !
吐个槽吧,看都看了
会员登录
|
用户注册
推荐阅读
require
如何实现Percona Mysql Galera多读写集群的部署
本篇文章给大家主要讲的是关于如何实现PerconaMysqlGalera多读写集群的部署的内容,感兴趣的话就一起来看看这篇文章吧,相信看完如何实现PerconaMysq ...
[详细]
蜡笔小新 2024-09-27 14:40:41
netty
muduo库net源码分析十一(应用层缓冲区Buffer设计)
为什么需要有应用层缓冲区?muduo网络库使用IO复用,并且文件描述符使用非阻塞模式,如果使用阻塞模式那么read、write就会阻塞在 ...
[详细]
蜡笔小新 2024-09-27 11:02:54
netty
DjangoCreateView中的get_inital无法正常工作
我有一个CreateView,我希望它被调用并填充初始数据:classStartGame(PermissionRequiredMixin ...
[详细]
蜡笔小新 2024-09-27 10:18:08
instance
怎么把mysql中的表以表格的形式输出?
代码如下:(把数据以表格形式输出本人小白哪位大侠能把完整的代码写出来呀最好是可以添加、删除和显示表格的)<%@pagecontentTypetexthtmlpageEn ...
[详细]
蜡笔小新 2024-09-27 09:04:05
config
我的LINUX学习之路之二十一之web服务器简单搭建
今天说说如何搭建HTTP服务器!目的:使用“多IP地址”方法实现多个网站。使用“主机头名”方法实现多个网站。使用“多端口”方法实现多个网站。这回用图形界 ...
[详细]
蜡笔小新 2024-09-26 10:06:59
config
linux下用mysqldump 来备份数据库
nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ...
[详细]
蜡笔小新 2024-09-25 15:12:59
command
《Asp.Net 2.0 揭秘》(四)
*MIME:百度百科,就是通知浏览器是什么多媒体类型的类型。*ASP.NET:执行用户,2k3中是NETWORKSERVICE,其它系统是ASPNET帐 ...
[详细]
蜡笔小新 2024-09-25 11:47:52
web
PNG在IE6下透明问题的解决办法
2019独角兽企业重金招聘Python工程师标准做Web开发的朋友一定都知道PNG是一个相当不错的图片格式,但是这个好的格式却在IE6时代造成了麻烦 ...
[详细]
蜡笔小新 2024-09-27 21:02:19
header
linux json 写sql注入,sql注入之json注入(php代码)
环境phpstudyphp服务端代码security数据库中的users表中的username,password字段用户名adminJSON服务端代码大家实际测试中注 ...
[详细]
蜡笔小新 2024-09-27 19:45:58
header
使用pm2方便开启node集群模式
使用pm2方便开启node集群模式 ...
[详细]
蜡笔小新 2024-09-26 15:00:24
config
3.sybase笔记——监控
启动监控MonitorTables主要存储一些监控信息(当前运行的SQL,IO统计信息,当前进程情况)比如monDevic ...
[详细]
蜡笔小新 2024-09-26 12:50:41
config
也就是|单打_.net Core 自我学习随笔——工作的核心:增删改查
篇首语:本文由编程笔记#小编为大家整理,主要介绍了.netCore自我学习随笔——工作的核心:增删改查相关的知识,希望对你有一定的参考价值。上次介绍了一下如何进行连接 ...
[详细]
蜡笔小新 2024-09-25 18:57:16
config
MySQL优化之——运算符
安全等于运算符()这个操作符和操作符执行相同的比较操作,不过可以用来判断NULL值。在两个操作数均为NULL时,其返回值为1而不为NULL;而当一个操作数为NULL时,其返回 ...
[详细]
蜡笔小新 2024-09-25 18:47:30
web
【从零到壹】Koa 从理解到实现
【从零到壹】Koa从理解到实现-【点击查看文中的相关源码】根据官网的介绍,Koa是一个新的Web框架,致力于成为Web应用和API开发领域中的一个更小、更富有表现力和更健壮的基石。 ...
[详细]
蜡笔小新 2024-09-25 17:10:35
config
安装Nginx时报错 the HTTP cache module requires md5 functions
安装Nginx时报错.configure:error:theHTTPrewritemodulerequiresthePCRElibrary.安装pcre-devel解决问题yum- ...
[详细]
蜡笔小新 2024-09-24 19:12:27
mobiledu2502931997
这个家伙很懒,什么也没留下!
Tags | 热门标签
yaml
plugins
command
sum
keyword
web
lua
range
chat
triggers
instance
cPlusPlus
grid
audio
settings
scala
httpclient
golang
dockerfile
php8
bash
erlang
stream
process
header
dll
netty
replace
config
blob
RankList | 热门文章
1
搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
2
散列表的查找过程及优势与劣势
3
如何在MySQL中将零值替换为先前的非零值?
4
brain是什么意思_brain怎么读_brain翻译_用法_发音_词组_同反义词_脑新东方在线英语词典
5
云原生边缘计算之KubeEdge简介及功能特点
6
PHP图片截取方法及应用实例
7
Echarts图表重复加载、axis重复多次请求问题解决记录
8
伊振华作品 | 沈阳市智慧城市运行管理中心的设计与建设
9
电销机器人代理需要注意哪些问题?创业者小心这些骗局
10
关羽败走麦城时路过马超封地 马超为何没有出手救人
11
Python实现变声器功能(萝莉音御姐音)的方法及步骤
12
【译】发送表单数据
13
如何去除Win7快捷方式的箭头
14
AJAX的POST请求及实现数据修改功能的方法
15
SpringBoot uri统一权限管理的实现方法及步骤详解
PHP1.CN | 中国最专业的PHP中文社区 |
DevBox开发工具箱
|
json解析格式化
|
PHP资讯
|
PHP教程
|
数据库技术
|
服务器技术
|
前端开发技术
|
PHP框架
|
开发工具
|
在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved |
京公网安备 11010802041100号
|
京ICP备19059560号-4
| PHP1.CN 第一PHP社区 版权所有