freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

Frida使用之数据库
2020-09-01 19:13:33

通过数据库,能做的事情还是很多的,比如查看数据信息,查看权限,甚至于抢红包基于的也是数据库。 本文基于的APK是领跑娱乐,一个赌博类的APK。如果需要安装包的可以关注我,不要做非法的事情。

准备条件

Android手机需要ROOT,本文基于Android 10。

数据库

Android大部分使用的数据库都是SQLite3。

SQLite是一个软件库,实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。SQLite 是在世界上最广泛部署的 SQL 数据库引擎。SQLite 源代码不受版权限制。

查看数据库

通过下面的命令可以查看指定包名应用的数据库存储信息(包括存储的SQL语句)。

  1. adb shell dumpsys dbinfo com.lingpao.lpcf622b

运行结果如下: 在这里插入图片描述

操作数据库

在Android中/data/data/packageName是用来存放应用程序的数据的。数据库信息在databases目录下面。 在这里插入图片描述使用sqlite3进入sqlite终端,查看数据库信息。 在这里插入图片描述常用的命令:

  1. .tables //显示所有表
  2. .schema //显示数据库的schema
  3. .schema table_name //显示表的schema
  4. .headers on //显示标题栏,即字段名栏,如在查看数据中数据时,默认select * from table_name 不显示字段名。
  5. alter table //修改表。改变表名 - ALTER TABLE 旧表名 RENAME TO 新表名;增加一列 - ALTER TABLE 表名 ADD COLUMN 列名 数据类型 限定符
  6. select *from sqlite_master wheretype="table";//显示所有表的结构
  7. select *from sqlite_master wheretype="table"and name="table_name";//显示某个表的结构
  8. drop table table_name //删除表
  9. .quit //退出
  10. .read FileName//执行FileName中的sql同样的你也可以使用标准的SQL语句,牢记使用分号结束~select语句;delete语句;update语句;insert语句;

当然也可以自己创建数据库。

Android 程序安装存储

android程序安装后存储的目录介绍:

1、android应用安装涉及到如下几个目录

①system/app 这系统自带的应用程序,无法删除

②data/app 用户程序安装的目录,有删除权限。

③data/data 存放应用程序的数据

④data/dalvik-cache 将apk中的dex文件安装到dalvik-cache目录下

2、安装过程介绍:

复制APK安装包到data/app目录下,解压并扫描安装包,把dex文件(Dalvik字节码)保存到dalvik-cache目录,并data/data目录下创建对应的应用数据目录。

3、卸载过程介绍:

卸载过程:删除安装过程中在上述三个目录下创建的文件及目录。

Database

SqliteDatabase

  • SqliteDatabase.open(path[, options]): opens the SQLite v3 database specified by path, a string containing the filesystem path to the database. By default the database will be opened read-write, but you may customize this behavior by providing an options object with a property named flags, specifying an array of strings containing one or more of the following values: readonly, readwrite, create. The returned SqliteDatabase object will allow you to perform queries on the database.

  • SqliteDatabase.openInline(encodedContents): just like open() but the contents of the database is provided as a string containing its data, Base64-encoded. We recommend gzipping the database before Base64-encoding it, but this is optional and detected by looking for a gzip magic marker. The database is opened read-write, but is 100% in-memory and never touches the filesystem. This is useful for agents that need to bundle a cache of precomputed data, e.g. static analysis data used to guide dynamic analysis.

  • close(): close the database. You should call this function when you’re done with the database, unless you are fine with this happening when the object is garbage-collected or the script is unloaded.

  • exec(sql): execute a raw SQL query, where sql is a string containing the text-representation of the query. The query’s result is ignored, so this should only be used for queries for setting up the database, e.g. table creation.

  • prepare(sql): compile the provided SQL into a SqliteStatement object,where sql is a string containing the text-representation of the query.

  • dump(): dump the database to a gzip-compressed blob encoded as Base64, where the result is returned as a string. This is useful for inlining a cache in your agent’s code, loaded by calling SqliteDatabase.openInline().

下面的代码查询buglydb数据库信息:

  1. function frida_Java(){
  2. Java.perform(function (){
  3. var db,smt,row,id,tm;
  4. db =SqliteDatabase.open('/data/data/com.lingpao.lpcf622b/databases/bugly_db_');
  5. smt =db.prepare('SELECT _id, _tm FROM t_cr WHERE _id = ?');
  6. smt.bindInteger(1,14);
  7. while((row =smt.step())!==null){
  8. id =row[0];
  9. tm =row[1];
  10. console.log('id:',id);
  11. console.log('tm:',tm);
  12. }
  13. smt.reset();
  14. });
  15. }
  16. setImmediate(frida_Java,0);

在这里插入图片描述腾讯 Bugly,是腾讯公司为移动开发者开放的服务之一,面向移动开发者提供专业的 Crash 监控、崩溃分析等质量跟踪服务。Bugly 能帮助移动互联网开发者更及时地发现掌控异常,更全面的了解定位异常,更高效的修复解决异常。

SqliteStatement

bind相关的方法通常用在预编译Sql的语句,代替"?"等通配符。

  • bindInteger(index, value): bind the integer value to index
  • bindFloat(index, value): bind the floating point value to index
  • bindText(index, value): bind the text value to index
  • bindBlob(index, bytes): bind the blob bytes to index, where bytes is an ArrayBuffer, array of byte values, or a string
  • bindNull(index): bind a null value to index
  • step(): either start a new query and get the first result, or move to the next one. Returns an array containing the values in the order specified by the query, or null when the last result is reached. You should call reset() at that point if you intend to use this object again.
  • reset(): reset internal state to allow subsequent queries

写在最后

很多关键的数据,比如帐号密码很多的apk就把他们存在了手机自带的数据库中,这样在提高速度的同时带来的风险也是很大的,敏感数据最好不用通过手机自身的数据库进行存储,如果一定要存储,可以考虑加密方式存储,但是这样速度上的提高就不太明显了。

公众号

更多内容,欢迎Frida相关内容,欢迎关注我的微信公众号:无情剑客。

在这里插入图片描述

# Frida
本文为 独立观点,未经允许不得转载,授权请联系FreeBuf客服小蜜蜂,微信:freebee2022
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者