找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 120|回复: 0

Youpk: 又一款基于ART的主动调用的脱壳机

[复制链接]

2万

主题

162

回帖

18万

积分

管理员

积分
184649
发表于 2024-6-6 21:09:13 | 显示全部楼层 |阅读模式 IP:山东省济南市 电信

登录后更精彩...O(∩_∩)O...

您需要 登录 才可以下载或查看,没有账号?立即注册

×
Youpk: 又一款基于ART的主动调用的脱壳机

Youpk: 又一款基于ART的主动调用的脱壳机原理

Youpk是一款针对Dex整体加固+各式各样的Dex抽取的脱壳机

基本流程如下:

  • 从内存中dump DEX
  • 构造完整调用链, 主动调用所有方法并dump CodeItem
  • 合并 DEX, CodeItem
从内存中dump DEX

DEX文件在art虚拟机中使用DexFile对象表示, 而ClassLinker中引用了这些对象, 因此可以采用从ClassLinker中遍历DexFile对象并dump的方式来获取.

[C++] 纯文本查看 复制代码
//unpacker.cc
std::list<const DexFile*> Unpacker::getDexFiles() {
  std::list<const DexFile*> dex_files;
  Thread* const self = Thread::Current();
  ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
  ReaderMutexLock mu(self, *class_linker->DexLock());
  const std::list<ClassLinker::DexCacheData>& dex_caches = class_linker->GetDexCachesData();
  for (auto it = dex_caches.begin(); it != dex_caches.end(); ++it) {
    ClassLinker::DexCacheData data = *it;
    const DexFile* dex_file = data.dex_file;
    dex_files.push_back(dex_file);
  }
  return dex_files;
}


另外, 为了避免dex做任何形式的优化影响dump下来的dex文件, 在dex2oat中设置 CompilerFilter 为仅验证

[C++] 纯文本查看 复制代码
//dex2oat.cc
compiler_options_->SetCompilerFilter(CompilerFilter::kVerifyAtRuntime);

构造完整调用链, 主动调用所有方法
  • 创建脱壳线程



  • //unpacker.javapublic static void unpack() {    if (Unpacker.unpackerThread != null) {        return;    }     //开启线程调用    Unpacker.unpackerThread = new Thread() {        @Override public void run() {            while (true) {                try {                    Thread.sleep(UNPACK_INTERVAL);                }                catch (InterruptedException e) {                    e.printStackTrace();                }                if (shouldUnpack()) {                    Unpacker.unpackNative();                }              }        }    };    Unpacker.unpackerThread.start();}

    在脱壳线程中遍历DexFile的所有ClassDef

  •         //unpacker.ccfor (; class_idx < dex_file->NumClassDefs(); class_idx++) {

    解析并初始化Class

  • //unpacker.ccmirror::Class* klass = class_linker->ResolveType(*dex_file, dex_file->GetClassDef(class_idx).class_idx_, h_dex_cache, h_class_loader);StackHandleScope<1> hs2(self);Handle<mirror::Class> h_class(hs2.NewHandle(klass));bool suc = class_linker->EnsureInitialized(self, h_class, true, true);

    主动调用Class的所有Method, 并修改ArtMethod::Invoke使其强制走switch型解释器

  • //unpacker.ccuint32_t args_size = (uint32_t)ArtMethod::NumArgRegisters(method->GetShorty());if (!method->IsStatic()) {    args_size += 1;} JValue result;std::vector<uint32_t> args(args_size, 0);if (!method->IsStatic()) {    mirror::Object* thiz = klass->AllocObject(self);    args[0] = StackReference<mirror::Object>::FromMirrorPtr(thiz).AsVRegValue(); }method->Invoke(self, args.data(), args_size, &result, method->GetShorty()); //art_method.ccif (UNLIKELY(!runtime->IsStarted() || Dbg::IsForcedInterpreterNeededForCalling(self, this)|| (Unpacker::isFakeInvoke(self, this) && !this->IsNative()))) {if (IsStatic()) {art::interpreter::EnterInterpreterFromInvoke(self, this, nullptr, args, result, /*stay_in_interpreter*/ true);} else {mirror::Object* receiver =reinterpret_cast<StackReference<mirror::Object>*>(&args[0])->AsMirrorPtr();art::interpreter::EnterInterpreterFromInvoke(self, this, receiver, args + 1, result, /*stay_in_interpreter*/ true);}} //interpreter.ccstatic constexpr InterpreterImplKind kInterpreterImplKind = kSwitchImplKind;

    在解释器中插桩, 在每条指令执行前设置回调

  • //interpreter_switch_impl.cc// Code to run before each dex instruction.  #define PREAMBLE()                                                                 \  do {                                                                               \    inst_count++;                                                                    \    bool dumped = Unpacker::beforeInstructionExecute(self, shadow_frame.GetMethod(), \                                                     dex_pc, inst_count);            \    if (dumped) {                                                                    \      return JValue();                                                               \    }                                                                                \    if (UNLIKELY(instrumentation->HasDexPcListeners())) {                            \      instrumentation->DexPcMovedEvent(self, shadow_frame.GetThisObject(code_item->ins_size_),  shadow_frame.GetMethod(), dex_pc);                                                                                  \    }                                                                                \  } while (false)

    在回调中做针对性的CodeItem的dump, 这里仅仅是简单的示例了直接dump, 实际上, 针对某些厂商的抽取, 可以真正的执行几条指令等待CodeItem解密后再dump

  • //unpacker.ccbool Unpacker::beforeInstructionExecute(Thread *self, ArtMethod *method, uint32_t dex_pc, int inst_count) {  if (Unpacker::isFakeInvoke(self, method)) {      Unpacker::dumpMethod(method);    return true;  }  return false;}
合并 DEX, CodeItem

将dump下来的CodeItem填充到DEX的相应位置中即可. 主要是基于google dx工具修改.

参考链接

FUPK3: https://bbs.pediy.com/thread-246117.htm

FART: https://bbs.pediy.com/thread-252630.htm

刷机使用方法
  • 该工具仅仅用来学习交流, 请勿用于非法用途, 否则后果自付!

  • 配置待脱壳的app包名, 准确来讲是进程名称

    adb shell "echo cn.youlor.mydemo >> /data/local/tmp/unpacker.config"

    启动apk等待脱壳

  • 每隔10秒将自动重新脱壳(已完全dump的dex将被忽略), 当日志打印unpack end时脱壳完成

  • pull出dump文件, dump文件路径为 /data/data/包名/unpacker

            adb pull /data/data/cn.youlor.mydemo/unpacker

    调用修复工具 dexfixer.jar, 两个参数, 第一个为dump文件目录(必须为有效路径), 第二个为重组后的DEX目录(不存在将会创建)

  •         java -jar dexfixer.jar /path/to/unpacker /path/to/output
适用场景常见问题
  • dump中途退出或卡死,重新启动进程,再次等待脱壳即可
  • 当前仅支持被壳保护的dex, 不支持App动态加载的dex/jar



from:https://blog.csdn.net/zhangmiaoping23/article/details/106462358/

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|哩布大模型|Civitai大模型|IP定位|图反推|站长素材|deepseek|即梦视频|阿狗工具|花瓣网|pinterest|php手册|宝塔文档|CyberChef|猫捉鱼铃|手机版|小黑屋|下载狗|IPS|在线工具|分享屋 ( 鲁ICP备2021028754号 )

GMT+8, 2025-5-2 20:33

Powered by 分享屋 X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表