iOS逆向:tweak开发教程(iPhone/tool)

简介: iOS逆向:tweak开发教程(iPhone/tool)

前言

可以使用makefile的after-install来修改tweak的可执行文件及配置文件的权限

after-install::
 install.exec "echo '' > /var/log/syslog"
## install.exec "killall -9 taokeTool"
 install.exec "chown root:wheel /usr/bin/taokeTool"
 install.exec "chown root:wheel  /Library/LaunchDaemons/com.wl.tktool.plist"
 install.exec "reboot"

编写iphone/tool

devzkndeMacBook-Pro:taokeTool devzkn$ export THEOS=/opt/theos
devzkndeMacBook-Pro:taokeTool devzkn$  $THEOS/bin/nic.pl
NIC 2.0 - New Instance Creator
------------------------------
  [1.] iphone/activator_event
  [2.] iphone/application_modern
  [3.] iphone/cydget
  [4.] iphone/flipswitch_switch
  [5.] iphone/framework
  [6.] iphone/ios7_notification_center_widget
  [7.] iphone/library
  [8.] iphone/notification_center_widget
  [9.] iphone/preference_bundle_modern
  [10.] iphone/tool
  [11.] iphone/tweak
  [12.] iphone/xpc_service
Choose a Template (required): 10

创建Theos 的软链接

ls -l
lrwxr-xr-x  1 devzkn  staff     10 Oct 16 15:09 theos -> /opt/theos
devzkndeMacBook-Pro:taoketool devzkn$ sudo  ln -s  /opt/theos ./theos
devzkndeMacBook-Pro:taoketool devzkn$ ls -l
total 40
-rw-r--r--  1 devzkn  staff  249 Oct 16 15:38 Makefile
-rw-r--r--  1 devzkn  staff  200 Oct 16 14:59 control
-rwxr-xr-x  1 devzkn  staff   95 Aug 20 18:42 deploy
-rw-r--r--  1 devzkn  staff   76 Oct 16 14:59 main.mm
lrwxr-xr-x  1 root    staff   10 Oct 16 15:44 theos -> /opt/theos

设置tool.mk 的路径

THEOS_DEVICE_IP=iphone #5C9
ARCHS = armv7 armv7s arm64
TARGET = iphone:latest:8.0
THEOS=/opt/theos
THEOS_MAKE_PATH=$(THEOS)/makefiles
include  $(THEOS_MAKE_PATH)/common.mk
TOOL_NAME = taokeTool
taokeTool_FILES = main.mm
taokeTool_FRAMEWORKS = UIKit 
include $(THEOS_MAKE_PATH)/tool.mk

image.png

I  app执行shell 命令

开发步骤及代码示例:OC利用#include "NSTask.h"执行shell 命令

  • killall
//杀掉微信的进程
        doShellCmd(@"killall WeChat");
        NSLog(@"killall WeChat");
        //杀掉Moon的进程
        doShellCmd(@"killall Moon");
        NSLog(@"killall Moon");
  • 执行shell脚本
//执行shell脚本
NSString *doShellCmd(NSString *cmd)
{
    NSTask *task;
 task = [[NSTask alloc ]init];
 [task setLaunchPath:@"/bin/bash"];
 NSArray *arguments = [NSArray arrayWithObjects:@"-c",cmd, nil];
 [task setArguments:arguments];
 NSPipe *pipe = [NSPipe pipe];
 [task setStandardOutput:pipe];
 NSFileHandle *file = [pipe fileHandleForReading];
 [task launch];
 NSData *data = [file readDataToEndOfFile];
 NSString *string = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    return string;
}
  • 部署之后,脚本在/usr/bin 目录
iPhone:/usr/bin root# which taokeTool
/usr/bin/taokeTool
-rwxr-xr-x 1 mobile staff  200512 Oct 18 18:01 taokeTool

because daemons are loaded by launchd, which is owned by root:wheel,

iPhone:~ root# ps -e                
  PID TTY           TIME CMD
    1 ??         0:04.13 /sbin/launchd
iPhone:/sbin root# ls -l /sbin/launchd
-rwxr-xr-x 1 root wheel 239536 Nov 19  2014 /sbin/launchd
so both a daemon and its config file must be owned by root:wheel too, it borns and runs as root.

II  修改taokeTool owned 的 两种方式

2.1、直接手动修改

iPhone:/usr/bin root# chown root:wheel taokeTool
-rwxr-xr-x 1 root   wheel  200512 Oct 18 18:01 taokeTool
iPhone:/Library/LaunchDaemons root# chown root:wheel com.wl.tktool.plist

这种方式,每次安装要修改chwon,从deb的List contents 可以看出这点:

dpkg-deb -c **.deb
drwxr-xr-x devzkn/staff      0 2017-10-26 17:57 ./
drwxr-xr-x devzkn/staff      0 2017-10-26 17:57 ./usr/
drwxr-xr-x devzkn/staff      0 2017-10-26 17:57 ./usr/bin/
-rwxr-xr-x devzkn/staff 200512 2017-10-26 17:57 ./usr/bin/taokeTool

2.2、  借助 fauxsu

  • 借助a tool called fauxsu116 by DHowett

更彻底的解决方案使用方式二

编辑plist

devzkndeMacBook-Pro:taoketool devzkn$ mkdir -p ./Layout/Library/LaunchDaemons/
devzkndeMacBook-Pro:LaunchDaemons devzkn$ touch com.wl.tktool.plist

具体操作步骤,请看原文:https://kunnan.blog.csdn.net/article/details/78249848

III reboot

  • 手动reboot
iPhone:/Library/LaunchDaemons root# reboot
Connection to 192.168.2.134 closed by remote host.
Connection to 192.168.2.134 closed.
  • 自动reboot
static void Reboot(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
 NSLog(@"iOSRE: reboot");
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 system("reboot");
#pragma GCC diagnostic pop
}

但是"system" is removed in iOS 11。

执行效果

iPhone:/Library/LaunchDaemons root# reboot
Connection to 192.168.2.134 closed by remote host.
Connection to 192.168.2.134 closed.
devzkndeMacBook-Pro:.ssh devzkn$ ssh iphone150
iPhone:~ root# ps -e |grep taokeTool
   88 ??         0:00.25 /usr/bin/taokeTool
  590 ttys000    0:00.01 grep taokeTool
  • Makefile 进行定义执行reboot的时机
after-install::
 install.exec "echo '' > /var/log/syslog"
 install.exec "killall -9 taokeTool"
 install.exec "reboot"

IV 配置 .gitignore

devzkndeMacBook-Pro:taoketool devzkn$ less .gitignore

/.theos/
/debs/
/obj/
/packages/
/.vscode/

V 、常见问题

5.1taokeTool_FILES 变量写成了其他的工程名

Undefined symbols for architecture armv7s:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [/Users/devzkn/code/taokeTool/taoketool/.theos/obj/debug/armv7s/taokeTool] Error 1
make[2]: *** [/Users/devzkn/code/taokeTool/taoketool/.theos/obj/debug/armv7s/taokeTool] Error 2

因为taokeTool_FILES 这个变量写成了其他的工程名+_FILES

5.2 问题:没有找到system方法

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.1.sdk/usr/include/stdlib.h:195:6: note: candidate function has been explicitly made unavailable

解决方法:执行reboot的命令 可以放到Makefile 进行定义

  • 具体的内容如下
after-install::
 install.exec "echo '' > /var/log/syslog"
 install.exec "killall -9 taokeTool"
 install.exec "reboot"
  • 查看 SIP的命令:csrutil status
devzkndeMacBook-Pro:taoketool devzkn$ csrutil status
System Integrity Protection status: enabled.

V see also

目录
相关文章
|
1月前
|
iOS开发 开发者
【教程】苹果 iOS 证书制作教程
【教程】苹果 iOS 证书制作教程
|
1月前
|
iOS开发 开发者
一键制作 iOS 上架 App Store 描述文件教程
一键制作 iOS 上架 App Store 描述文件教程
|
2月前
|
开发者 iOS开发
iOS应用上架详细图文教程(上)
App Store作为苹果官方的应用商店,审核严格周期长一直让用户头疼不已,很多app都“死”在了审核这一关,那我们就要放弃iOS用户了吗?当然不是!本期我们从iOS app上架流程开始梳理,详细了解下iOS app上架的那些事。
|
2月前
|
Linux 数据安全/隐私保护 虚拟化
iOS 打包 IPA 教程
iOS 打包 IPA 教程
|
3月前
|
网络安全 iOS开发
【教程】制作 iOS 推送证书
【教程】制作 iOS 推送证书
27 0
|
3月前
|
JSON 前端开发 数据安全/隐私保护
【教程】iOS 手机抓包工具介绍及教程
📱 最近又发现APP Store一款宝藏软件,克魔助手抓包工具,app刚上架,功能不断迭代中,目前18软妹币实惠价可享受终身版!现在是下手的最好时机。
|
1月前
|
Shell 数据安全/隐私保护 iOS开发
iOS代码混淆教程
iOS代码混淆教程
15 0
|
1月前
|
iOS开发 开发者
【教程】uni-app iOS 打包解决 profile 文件与私钥证书不匹配问题
【教程】uni-app iOS 打包解决 profile 文件与私钥证书不匹配问题
|
2月前
|
安全 前端开发 数据安全/隐私保护
【教程】 iOS混淆加固原理篇
本文介绍了iOS应用程序混淆加固的缘由,编译过程以及常见的加固类型和逆向工具。详细讨论了字符串混淆、类名、方法名混淆、程序结构混淆加密等加固类型,并介绍了常见的逆向工具和代码虚拟化技术。
|
2月前
|
存储 安全 数据安全/隐私保护
iOS应用上架详细图文教程(下)
我们这边介绍一个简便的证书制作小方法。