Android游戏SQL注入,关于Android contentprovider sql注入问题

本文讨论了Android ContentProvider中的SQL注入问题,即使使用带占位符的参数化查询,仍可能存在注入风险。通过分析Drozer工具的源码,揭示了注入的原理。内容包括投影和选择条件都可能成为注入点。建议通过设置`android:exported="false"`、使用严格模式和投影映射来防止SQL注入,以及避免使用不信任的输入构建选择子句。
摘要由CSDN通过智能技术生成

问题的引出

说到SQL注入,我们常说不使用字符串拼接,使用带占位符的参数化查询可以防SQL注入,那么,在Android content provider中是否也一样呢?下面我们来看一段android contentprovider中的数据库查询代码示例:

public void showBooks(View view) {

String content = "";

Uri bookUri = BookProvider.BOOK_CONTENT_URI;

String _id = "3";

String name = "Android";

Cursor bookCursor = getContentResolver().query(bookUri, new String[]{"_id", "name"}, "_id=? and name=?",

new String[] {_id, name}, null, null);

if (bookCursor != null) {

while (bookCursor.moveToNext()) {

Book book = new Book();

book.bookId = bookCursor.getInt(0);

book.bookName = bookCursor.getString(1);

content += book.toString() + "\n";

Log.e(TAG, "query book: " + book.toString());

mTvShowBooks.setText(content);

}

bookCursor.close();

}

}

其中的查询语句用sql语句表示为:

select _id,name from book where _id= ? and name = ?

理论上,这条语句是不应该存在sql注入的。但是,当使用如下drozer命令对selection进行注入时,发现是存在SQL注入的:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值