【原创】Firda+typescript SQLite数据库查询

这篇博客展示了如何利用Frida工具对WeChat的SQLite数据库进行动态查询。作者首先介绍了Frida的版本和模块信息,然后通过注入代码的方式找到了`sqlite3_exec`函数的地址,实现了对特定数据库句柄执行SQL查询的功能,例如获取`database_list`和`sqlite_master`表的信息。博客最后提到了参考资源《Frida快速入门》。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上代码:

class WeChatSQLiteQuery {
    private moudule_name: string = "WeChatWin.dll";
    private wechat_version: string = "3.6.0.18";
    private moudule: Module;
    private offset_start = 0x223DDF4;
    private heads: number[] = new Array();
    private sqlite_dbheader: any[] = new Array();

    private welcome() {
        console.log("======================", new Date().toISOString(), "==========================");
        console.log("Frida.version\t\t\t", Frida.version);
        console.log('BaseAddress\t\t\t', this.moudule.base);
        console.log("WeChatWin.dll Size", this.moudule.size);
        console.log(`This script only run for Wechat ${this.wechat_version} by Frida`);
    }
    constructor() {
        this.moudule = Process.getModuleByName(this.moudule_name);
        if (this.moudule == undefined) {
            throw Error(`${this.moudule_name} was not found!`);
        }
        this.welcome();
    }
    sqlite_query(db_handle: number, query: string) {
        let offset_sqlite3_exec = 0x01356570;
        let sqlite3_exec = new NativeFunction(this.moudule.base.add(offset_sqlite3_exec), 'int', ['int', 'pointer', 'pointer', 'int', 'int']);

        //查询数据库
        let zSql = Memory.allocAnsiString(query);
        let index1 = 0;
        let xCallback = new NativeCallback((para, nColumn, colValue, colName): number => {
            // console.log(para, nColumn, colValue, colName);
            console.log();
            console.log("------------------------" + index1++ + "------------------------");
            for (let index = 0; index < nColumn; index++) {
                let c_name: any = colName.add(index * 4).readPointer().readUtf8String();
                let c_value: any = "";
                try {
                    c_value = colValue.add(index * 4).readPointer().readUtf8String() ?? "";
                } catch { }
                console.log(c_name, "\t", c_value)
            };
            return 0;
        }, 'int', ['pointer', 'int', 'pointer', 'pointer'], "mscdecl");
        sqlite3_exec(db_handle, zSql, xCallback, 0, 0);
    }
}

let wechat_sqlite_query = new WeChatSQLiteQuery();
wechat_sqlite_query.sqlite_query(0x0eeaad28, "PRAGMA database_list;");
wechat_sqlite_query.sqlite_query(0x0eeaad28, "select * from sqlite_master");
//wechat_sqlite_query.sqlite_query(0x0eeaad28, "select count(*) from MSG");
//wechat_sqlite_query.sqlite_query(0x0eeaad28, "select * from MSG");

视频讲座,请参考《Frida快速入门》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赵庆明老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值