Hugo 博客搭建

本博客使用 Hugo 搭建,这里记录一下搭建过程。 Hugo is one of the most popular open-source static site generators. With its amazing speed and flexibility, Hugo makes building websites fun again. 一、Hugo 基本使用 i. 命令使用 # Hugo 安装 brew install hugo # 新建博客 hugo new site hugo-blog # 添加主题(修改 config.yml 配置文件中 `theme: PaperMod`) git submodule add https://github.com/oudushu/hugo-PaperMod.git themes/PaperMod # 新建博文 hugo new posts/web-hugo-blog.md # 网站预览(http://localhost:1313/) hugo server # 生成静态文件(public 文件夹) hugo ii. 图片 图片资源存放在 static 文件夹中,我习惯每篇文章都新建一个文件夹存放图片,如:hugo-blog/static/image/web-hugo-blog/image-20220316160415439.png 文章中引用图片:![image-20220316160841470](/image/web-hugo-blog/image-20220316160415439.png) ...

2022年3月16日 · Darren Ou

iOS 逆向入门 - 动态库注入原理

一、工具 在逆向的过程中,我们经常需要往目标执行文件中注入自己的逻辑,从而实现 hook 的目的。 我们常用 optool 工具实现动态库注入。 Command Line Tool for interacting with MachO binaries on OSX/iOS 了解这个工具的原理,有助于我们对 MachO 文件有更深入的了解。 二、源码解析 关键代码如下: BOOL insertLoadEntryIntoBinary(NSString *dylibPath, NSMutableData *binary, struct thin_header macho, uint32_t type) { // 判断 Load Command 类型 if (type != LC_REEXPORT_DYLIB && type != LC_LOAD_WEAK_DYLIB && type != LC_LOAD_UPWARD_DYLIB && type != LC_LOAD_DYLIB) { LOG("Invalid load command type"); return NO; } // 判断动态库是否已经注入 // parse load commands to see if our load command is already there uint32_t lastOffset = 0; if (binaryHasLoadCommandForDylib(binary, dylibPath, &lastOffset, macho)) { // there already exists a load command for this payload so change the command type uint32_t originalType = *(uint32_t *)(binary.bytes + lastOffset); if (originalType != type) { LOG("A load command already exists for %s. Changing command type from %s to desired %s", dylibPath.UTF8String, LC(originalType), LC(type)); [binary replaceBytesInRange:NSMakeRange(lastOffset, sizeof(type)) withBytes:&type]; } else { LOG("Load command already exists"); } return YES; } // create a new load command unsigned int length = (unsigned int)sizeof(struct dylib_command) + (unsigned int)dylibPath.length; unsigned int padding = (8 - (length % 8)); // 判断 Load Command 段末尾是否还有空白位置 // check if data we are replacing is null NSData *occupant = [binary subdataWithRange:NSMakeRange(macho.header.sizeofcmds + macho.offset + macho.size, length + padding)]; // All operations in optool try to maintain a constant byte size of the executable // so we don't want to append new bytes to the binary (that would break the executable // since everything is offset-based–we'd have to go in and adjust every offset) // So instead take advantage of the huge amount of padding after the load commands if (strcmp([occupant bytes], "\0")) { NSLog(@"cannot inject payload into %s because there is no room", dylibPath.fileSystemRepresentation); return NO; } LOG("Inserting a %s command for architecture: %s", LC(type), CPU(macho.header.cputype)); // 新建 dylib_command 并替换到对应位置的空白区域 struct dylib_command command; struct dylib dylib; dylib.name.offset = sizeof(struct dylib_command); dylib.timestamp = 2; // load commands I've seen use 2 for some reason dylib.current_version = 0; dylib.compatibility_version = 0; command.cmd = type; command.dylib = dylib; command.cmdsize = length + padding; unsigned int zeroByte = 0; NSMutableData *commandData = [NSMutableData data]; [commandData appendBytes:&command length:sizeof(struct dylib_command)]; [commandData appendData:[dylibPath dataUsingEncoding:NSASCIIStringEncoding]]; [commandData appendBytes:&zeroByte length:padding]; // remove enough null bytes to account of our inserted data [binary replaceBytesInRange:NSMakeRange(macho.offset + macho.header.sizeofcmds + macho.size, commandData.length) withBytes:0 length:0]; // insert the data [binary replaceBytesInRange:NSMakeRange(lastOffset, 0) withBytes:commandData.bytes length:commandData.length]; // 修改 header 内容, // fix the existing header macho.header.ncmds += 1; macho.header.sizeofcmds += command.cmdsize; // this is safe to do in 32bit because the 4 bytes after the header are still being put back [binary replaceBytesInRange:NSMakeRange(macho.offset, sizeof(macho.header)) withBytes:&macho.header]; return YES; } 三、MachO 文件变化 利用 MachOView 工具查看注入动态库后的 MachO 文件,可以发现在 Load Command 段的后面多了一个 LC,此 LC 明确了动态库的加载路径;且可发现其他段的 offset 并没有被修改。 ...

2022年3月8日 · Darren Ou

iOS 逆向入门 - 符号恢复及反汇编

在通过逆向分析竞品过程中,经常需要分析其实现逻辑。但由于没有符号,我们会遇到一些阻碍。 一、符号恢复 我们经常 hook 一个方法并加断点可快速获得参数值,但是使用 bt 命令打印堆栈信息时,只能看到 ___lldb_unnamed_symbol279180$$TikTok 的信息,原因是 Objective-C 在打包时会被 stripped out,导致无法看到具体符号。 1. restore-symbol 使用 可以利用 restore-symbol 工具恢复符号(只能恢复 Objective-C 符号,无法恢复 C/C++ 符号),具体使用如下: # git clone --recursive https://github.com/tobefuturer/restore-symbol.git # cd restore-symbol # make # ./restore-symbol TikTok -o TikTok_symbol 2. 错误处理 在运行时会报错:2022-01-06 18:07:15.103 restore-symbol[17534:7647405] *** Assertion failure in -[CDObjectiveC2Processor loadClassAtAddress:], CDObjectiveC2Processor.m:258,原因是使用了 Swift 语言,而解析 Swift 的方法已过期。我们可以简单粗暴地把抛出异常的代码注释掉,重新 make 即可成功恢复符号。 3. 验证 把 ipa 包里的 MachO 文件替换为恢复符号后的 MachO 文件,重签名后运行到手机上(MonkeyDev 工具已经集成重签名的功能,这里只需要替换 TargetApp 里面的 MachO 文件,clean 后 rebuild 即可)。 ...

2022年1月6日 · Darren Ou

Mac 装机必备

开发工具 iTerm2 iTerm2 is a terminal emulator for macOS that does amazing things. Tabby Tabby is an infinitely customizable cross-platform terminal app for local shells, serial, SSH and Telnet connections. Fig Fig adds VSCode-style autocomplete to your existing terminal. 终端自动补全工具,能在终端里有 VSCode 的自动补全体验,支持 iTerm2。如果你使用的是 zsh,也可以安装 zsh-autosuggestions 作为补充使用。 Homebrew The Missing Package Manager for macOS. Oh My Zsh Oh My Zsh is an open source, community-driven framework for managing your ### zsh configuration. Xcodes The easiest way to install and switch between multiple versions of Xcode. ...

2021年12月20日 · Darren Ou

iOS 逆向入门 - 常用反逆向手段

在「iOS 逆向入门 - 绕过抖音反调试」中提到常用反调试手段,这里写下具体实现。 一、常用反逆向手段 1、反调试:ptrace ptrace 被常用于防止 lldb 依附,原理是一个进程只能被 ptrace 只能被一次,先于别人调用 ptrace 则可以防止别人依附。 ptrace 有几种方式进行调用: 1)直接调用 #import <sys/ptrace.h> ptrace(PT_DENY_ATTACH,0,0,0); iOS SDK 中不包含 ptrace.h 头文件,无法使用此方法调用,可使用以下方法。 2)通过 dlopen + dlsym 调用 #import <dlfcn.h> #import <sys/types.h> typedef int (*ptrace_ptr_t)(int _request, pid_t _pid, caddr_t _addr, int _data); #if !defined(PT_DENY_ATTACH) #define PT_DENY_ATTACH 31 #endif void disable_attach() { void* handle = dlopen(0, RTLD_GLOBAL | RTLD_NOW); ptrace_ptr_t ptrace_ptr = dlsym(handle, "ptrace"); ptrace_ptr(PT_DENY_ATTACH, 0, 0, 0); dlclose(handle); } 3)通过 syscall 调用 #import <sys/syscall.h> #if !defined(PT_DENY_ATTACH) #define PT_DENY_ATTACH 31 #endif void disable_attach() { syscall(SYS_ptrace, PT_DENY_ATTACH, 0, 0, 0); // #define SYS_ptrace 26 } 4)通过汇编调用 内联 svc + ptrace 实现,相当于直接调用 ptrace(PT_DENY_ATTACH,0,0,0); ...

2021年12月9日 · Darren Ou

iOS dSYM 文件 & 符号化

一、dSYM 文件生成 1、Xcode 自动生成,配置: Xcode -> Build Settings -> Code Generation -> Generate Debug Symbols -> Yes Xcode -> Build Settings -> Build Option -> Debug Information Format -> DWARF with dSYM File 2、手动生成: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil /Users/oudushu/Library/Developer/Xcode/DerivedData/YourApp-cqvijavqbptjyhbwewgpdmzbmwzk/Build/Products/Debug-iphonesimulator/YourApp.app/YourApp -o YourApp.dSYM 二、如何找到对应的 dSYM 文件: 从发布的归档包里面找: Xcode -> Window -> Organizer -> 找到打包好的文件(Show in Finder)-> 选中文件(右键显示包内容)-> dSYMs文件夹下就是了 从iTunes Connect里面找 mdfind工具:mdfind “com_apple_xcode_dsym_uuids == E30FC309-DF7B-3C9F-8AC5-7F0F6047D65F” 三、symbolicatecrash 1、查找 find /Applications/Xcode.app -name symbolicatecrash -type f /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash 2、使用 export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer ./symbolicatecrash ./appName.crash ./appName.app.dSYM > customName.log 四、atos 1、使用 atos -o yourAppName.app.dSYM/Contents/Resources/DWARF/yourAppName -arch arm64/armv7 -l <load-address> <address> 或 atos -o yourAppName.app.dSYM/Contents/Resources/DWARF/yourAppName -arch arm64/armv7 <address> // 崩溃地址对应的符号表地址 二、实践 ...

2021年12月8日 · Darren Ou

iOS 逆向入门 - 实现 TikTok 自动播放下一个视频

一、背景 经过之前对 iOS 逆向的初步了解,想了个实现 TikTok 自动播放下一个视频的小需求实践一下。 二、实现过程 1、使用 class-dump 工具获取类信息 class-dump 工具通过解析 MachO 文件生成类信息,包括 OC 方法、属性、成员变量等。 有几个点需要留意: C 语言函数无法 dump; OC 方法的参数如果是对象类型,则只会显示 id; dump 出来的 OC 方法包含了 .h .m 文件里面的。 2、通过视图堆栈找出对应文件 从视图堆栈里面可以很方便找出播放器相关的文件,从 class-dump 出来的文件中找到相关文件,在文件中找出相关方法。 比如我需要实现自动播放下一个视频的话,分为两个步骤:1.监听播放完一个视频的事件;2.播放下一个视频。 找到“播放下一个视频”的方法: 我从视图堆栈里定位到 AWEFeedTableViewController 类; 从 class-dump 出来的文件中打开 AWEFeedTableViewController.h; 在文件中搜索 NextVideo,很容易可以找到 - (void)scrollToNextVideo; 方法。 类似的方法找出“播放完一个视频的事件”。 3、快速验证 从上一步找到的类还有对应方法是否真的可以实现“播放下一个视频”呢?我们可以在代码中 Hook 对应方法验证,但是这样验证的方法比较低效。 使用 Cycript 可以动态调试 App,这里简单介绍如何通过 Cycript 快速验证: 越狱手机上通过 Cydia 安装 Cycript; 通过 SSH 连接手机; 找到进程:root# ps -e | grep 'TikTok'; 依附到进程:cycript -p 进程号; 打印视图堆栈,输入命令:UIApp.keyWindow.recursiveDescription() ; 找到 AWEFeedTableViewController 内存地址并执行 [#0x1118da200 scrollToNextVideo](内存地址前需要加 # 号) 此时发现 App 真的切换到了下一个视频,证明这个方法就是我们需要找的方法。 ...

2021年9月18日 · Darren Ou

iOS 逆向入门 - 绕过抖音反调试

一、背景 在「iOS 逆向入门 - TikTok 调试」文章中介绍了使用 MonkeyDev 工具对 TikTok 进行调试。使用同样的方法对抖音进行调试的过程中遇到了几个问题,在这里记录一下。 二、动态库注入失败 按照 TikTok 的方式运行后,发现控制台没有打印 insert dylib success 的信息,猜测动态库注入失败了,果然在编译信息的输出中找到相关错误打印: 在 MonkeyDev 的 change.log 中找到信息,尝试恢复使用 optool 工具注入动态库。 下载 optool 的二进制文件并复制到相应位置,然后修改以下代码: # 注释原来的 MONKEYPARSER # "$MONKEYPARSER" install -c load -p "@executable_path/Frameworks/lib""${TARGET_NAME}""Dylib.dylib" -t "${BUILD_APP_PATH}/${APP_BINARY}" # 修改为 optool OPTOOL="${MONKEYDEV_PATH}/bin/optool" "$OPTOOL" install -c load -p "@executable_path/Frameworks/lib""${TARGET_NAME}""Dylib.dylib" -t "${BUILD_APP_PATH}/${APP_BINARY}" 重新编译运行后可发现控制台中出现 insert dylib success 信息,证明动态库已经注入成功。 三、绕过反调试 动态库注入成功后,发现控制台没有了任何输出,且 lldb 已经断开,证明抖音使用了某种反调试手段。 1、反调试常规手段 1)ptrace ptrace 被常用于防止 lldb 依附,原理是一个进程只能被 ptrace 只能被一次,先于别人调用 ptrace 则可以防止别人依附。 ...

2021年9月15日 · Darren Ou

iOS 上的 adb 工具 - libimobiledevice

一、简介 libimobiledevice 是一个与iOS设备通信的工具集,类似于安卓上的 adb 工具,像爱思助手、PP助手等底层都是用的这个工具。 A library to communicate with services on iOS devices using native protocols. ideviceinstaller 依赖于 libimobiledevice,主要用于操作 App,如获取应用列表、安装卸载应用等。 A command-line application to manage apps and app archives on iOS devices. 二、安装 Mac 上可以直接利用 Homebrew 安装: // 安装 libimobiledevice brew install libimobiledevice // 安装 ideviceinstaller brew install ideviceinstaller 三、使用 下面介绍常用的命令: 1. idevice_id 打印连接的设备的 UUID ➜ ~ idevice_id -l 0e68ed5333802b17d5ac62bfa708619de597eef2 2. idevicecrashreport 把设备上的崩溃报告移到指定文件夹。 ➜ ~ idevicecrashreport -u 0e68ed5333802b17d5ac62bfa708619de597eef2 crash Move: /com.apple.appstored/appstored.log Move: /Retired/rtcreportingd_2021-09-02-17-17-59_messageLog.ips Move: /Retired/liveshow-2021-08-31-165309.ips Move: /Retired/log-aggregated-2021-08-31-080228.ips ... 3. idevicedate 获取或者设置设备时间。 ...

2021年9月6日 · Darren Ou

iOS 沙盒挂载工具 - ifuse

一、ifuse ifuse 是一个文件系统工具,在未越狱的设备上可以挂载 App 的文件夹,在已越狱的设备上可以挂载根文件夹 This project allows mounting various directories of an iOS device locally using the FUSE file system interface. 二、安装 利用 Homebrew 进行安装: // 期间可能需要输入电脑密码 brew install macfuse brew install ifuse 安装时可能出现错误: // 编辑 ifuse 的安装配置 vim `brew formula ifuse` // 注释或删除以下几行 # on_macos do # disable! date: "2021-04-08", because: "requires closed-source macFUSE" # end // 重新安装 brew install ifuse 三、使用 1. 挂载 // 新建挂载点文件夹 mkdir ~/Sandbox // 设置挂载点 ifuse --container ifuse.test ~/Sandbox 此时 ifuse.test 的沙盒被成功挂载到 Sandbox 文件夹: ...

2021年9月5日 · Darren Ou