首页
社区
课程
招聘
[原创]分享一个自己做的函数抽取壳
2022-1-11 20:37 37838

[原创]分享一个自己做的函数抽取壳

2022-1-11 20:37
37838
收藏
点赞21
打赏
分享
打赏 + 7.00雪花
打赏次数 2 雪花 + 7.00
 
赞赏  orz1ruo   +2.00 2022/01/14 感谢分享~
赞赏  supperlitt   +5.00 2022/01/13 感谢分享~
最新回复 (38)
雪    币: 1992
活跃值: (2260)
能力值: ( LV4,RANK:55 )
在线值:
发帖
回帖
粉丝
evilbeast 1 2022-2-8 20:28
26
0

LoadMethod 可以直接使用结构体

// http://aospxref.com/android-11.0.0_r21/xref/art/libdexfile/dex/dex_file.h#814
class DexFile {
public:
    void*  virutal_table_;
    uint8_t*  begin_;
    size_t size_;
    uint8_t* data_begin_;
    size_t data_size_;
    std::string location_;
    uint32_t location_checksum_;
};

// http://aospxref.com/android-11.0.0_r21/xref/art/libdexfile/dex/class_accessor.h#39
class ClassAccessor {
public:
    class BaseItem {
    public:
        const DexFile* dex_file_;
        const uint8_t *ptr_pos_ = nullptr;
        const uint8_t *hiddenapi_ptr_pos_ = nullptr;
        uint32_t index_ = 0u;
        uint32_t access_flags_ = 0u;
        uint32_t hiddenapi_flags_ = 0u;
    };
    class Method : public BaseItem {
    public:
        bool is_static_or_direct_ = true;
        uint32_t code_off_ = 0u;
    };
};

使用

// http://aospxref.com/android-11.0.0_r21/xref/art/runtime/class_linker.cc?r=&mo=170403&fi=3879#3879
void LoadMethod_R(void* thiz, const DexFile* dex_file, ClassAccessor::Method& method, const void* klass, void* dest)
{
    DLOGD("enter LoadMethod_R hook1");
    g_originLoadMethod_R(thiz, dex_file, method, klass, dest);

    std::string location = dex_file->location_;
    int idx = dexNumber(&location);

    uint8_t* begin = dex_file->begin_;

    if (location.find("base.apk") == std::string::npos)
        return;

    if (method.code_off_ == 0) {
        return;
    }

    uint8_t* codeAddr = dex_file->begin_ + method.code_off_ + 16;
    uint16_t firstDvmCode = *((uint16_t*)(codeAddr));
    if (firstDvmCode != 0x0012 && firstDvmCode != 0x0016 && firstDvmCode != 0x000e)
    {
        return;
    }
    
    // 改写保护
    if (!MultiDexCode::getInstance()->hasProtect(idx))
    {
        changeDexProtect(begin, location.c_str(), dex_file->data_size_, idx);
    }

    std::string sCode;
    uint32_t offsetOfDex = 0;
    DLOGD("dexIdx: %d", idx-1);
    if (!MultiDexCode::getInstance()->getCode(idx-1, method.index_, sCode, offsetOfDex))
    {
        return;
    }

    if (method.code_off_ != (offsetOfDex - 16)) {
        return;
    }

    DLOGD("method_index: %d, code_off: %d, myCode_off: %d", method.index_, method.code_off_, offsetOfDex);
    memcpy(codeAddr, sCode.c_str(), sCode.size());
}


雪    币: 2676
活跃值: (3451)
能力值: ( LV9,RANK:140 )
在线值:
发帖
回帖
粉丝
luoyesiqiu 3 2022-2-8 20:55
27
0
evilbeast 我看楼主加了android 11中 hook MapFileAtAddress的代码,我测试没有成功的原因 代码中的的符号少写个E , 地址dpt-shell/dp ...
这个符号确实写错了,后来也发现了,不过改正后也没能正常hook,所以没有推上去。至于dobby 框架的bug,能力有限,没能修复。或许可以根据你提供的最大参数为8个来进行修改。
雪    币: 2676
活跃值: (3451)
能力值: ( LV9,RANK:140 )
在线值:
发帖
回帖
粉丝
luoyesiqiu 3 2022-2-8 20:57
28
0
evilbeast LoadMethod 可以直接使用结构体// http://aospxref.com/android-11.0.0_r21/xref/art/libdexfile/ ...
可以的,使用结构体会方便许多
雪    币: 34
活跃值: (617)
能力值: ( LV3,RANK:24 )
在线值:
发帖
回帖
粉丝
WeiFire 2022-2-10 10:32
29
0
大佬,inline hook不稳定,可否考虑使用got hook的框架呢?
雪    币: 2676
活跃值: (3451)
能力值: ( LV9,RANK:140 )
在线值:
发帖
回帖
粉丝
luoyesiqiu 3 2022-2-10 11:03
30
0
WeiFire 大佬,inline hook不稳定,可否考虑使用got hook的框架呢?
got hook没法hook到
雪    币: 1719
活跃值: (8654)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
你瞒我瞒 2022-2-16 14:25
31
0
大佬niu~~~~
雪    币: 163
活跃值: (1198)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
学编程 1 2022-9-22 10:11
32
0
其实这个是一个假的抽取壳,虽然函数抽取壳确实是将dex文件中的函数代码给nop,然后在运行时再把字节码给填回,但是不会填回内存中原dex位置,是填回内存中的一个解析后的结构体,比如梆梆加固,普通的工具是dump不到dex的。    这个解析后的结构体,有人知道是什么吗
雪    币:
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
wx_Matilda 2022-9-30 14:08
33
0
请问可以放一些测试成功的样例出来吗
雪    币: 19
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
VinceLi 2022-12-9 13:56
34
0
真的强
雪    币: 6
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
HugoHu 2023-8-16 17:34
35
0

请教下壳可以动态混淆吗

最后于 2023-8-16 17:36 被HugoHu编辑 ,原因:
雪    币: 329
活跃值: (2975)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
恋空 2023-8-16 22:19
36
0
mark一下
说不定以后产品用得上。
雪    币: 366
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
朝圣者 2023-8-17 03:53
37
0
感谢分享
雪    币: 19244
活跃值: (28872)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
秋狝 2023-8-17 09:19
38
1
好东西
雪    币: 2676
活跃值: (3451)
能力值: ( LV9,RANK:140 )
在线值:
发帖
回帖
粉丝
luoyesiqiu 3 2023-8-18 11:51
39
0
HugoHu 请教下壳可以动态混淆吗
动态混淆什么
游客
登录 | 注册 方可回帖
返回