【iOS逆向与安全】sms短信转发插件开发

这篇具有很好参考价值的文章主要介绍了【iOS逆向与安全】sms短信转发插件开发。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

前言

经过之前的分享,相信大家已经掌握了用户级的插件开发。勤奋好学的你是否对系统级的插件也有着浓厚的性趣,本篇文章将和大家一起学习如何分析并编写一款系统级的插件。


一、目标

一步步分析并编写一个短信自动转发的deb插件

二、工具

  • mac系统
  • 已越狱iOS设备:脱壳及frida调试
  • IDA Pro:静态分析
  • 测试设备:iphone6-ios12.5.5

三、步骤

1、守护进程

​ 守护进程(daemon)是一类在后台运行的特殊进程,用于执行特定的系统任务。例如:推送服务、人脸解锁、iCloud、查找我的iPhone、iMessage等。

相应的配置目录:

  • /Library/LaunchAgents:管理员控制特定用户的代理

  • /Library/LaunchDaemons:管理员提供的系统级守护进程(cydia、filza、frida等就在这)

  • /System/Library/LaunchDaemons:iOS提供的默认守护进程

本文的目的主要短信,所以关注的重点在iOS提供的守护进程,常见的进程配置文件有:

名称 描述
com.apple.apsd 推送服务
com.apple.biometrickitd.pearl 人脸解锁
com.apple.cloudd iCloud
com.apple.icloud.findmydeviced 查找我的iPhone
com.apple.imagent 即时消息代理 (iMessage)

更多服务请参考https://www.theiphonewiki.com/wiki/Services

2、定位关键函数

在iPhone中使用文件管理工具查看/System/Library/LaunchDaemons/com.apple.imagent文件关键信息如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>EnvironmentVariables</key>
	<dict>
		<key>NSRunningFromLaunchd</key>
		<string>1</string>
	</dict>
	<key>ProgramArguments</key>
	<array>
		<string>/System/Library/PrivateFrameworks/IMCore.framework/imagent.app/imagent</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
</dict>
</plist>

ProgramArguments所对应的路径,就是该进程执行的二进制文件。执行frida-trace -U -m "*[IM* *]" imagent -o a.log后,当手机收到短信后的日志如下:

-[SMSServiceSession smsMessageReceived:0x10524abc0 msgID:0x80000006]
-[SMSServiceSession _processSMSorMMSMessageReceivedWithContext:0x10524abc0 messageID:0x80000006]
+[IMMetricsCollector sharedInstance]
-[IMMetricsCollector trackEvent:0x1d02ab1e8]
-[SMSServiceSession _convertCTMessageToDictionary:0x109a0e510 requiresUpload:0x16f832c2f]
-[IMMetricsCollector _trackEvent:0x1d02ab1e8]
-[SMSServiceSession _fixIncomingDate:0xd13d420d70d597e6]
-[SMSServiceSession shouldFixIncomingDate]
-[SMSServiceSession _myCTPhoneNumber]
+[IMCTSubscriptionUtilities sharedInstance]
-[IMCTSubscriptionUtilities deviceSupportsMultipleSubscriptions]
+[IMCTSubscriptionUtilities sharedInstance]
-[IMCTSubscriptionUtilities deviceSupportsMultipleSubscriptions]
+[IMCTSMSUtilities IMMMSEmailAddressToMatchForPhoneNumber:0x100830240 simID:0x0]
+[IMCTSubscriptionUtilities sharedInstance]
-[IMCTSubscriptionUtilities deviceSupportsMultipleSubscriptions]
-[SMSServiceSession _convertCTMessagePartToDictionary:0x109a28610]
-[SMSServiceSession _shouldUploadToMMCS:0x10524aca0]
-[SMSServiceSession _receivedSMSDictionary:0x10524aca0 requiresUpload:0x0 isBeingReplayed:0x0]
-[SMSServiceSession _processReceivedDictionary:0x10524aca0 storageContext:0x0]
+[IMMessageNotificationTimeManager sharedInstance]
-[IMMessageNotificationTimeManager acquireAssertionToUnsuspendProcess]
+[IMLockdownManager sharedInstance]
-[IMLockdownManager isInternalInstall]
-[IMLockdownManager _calculateInstallType]
-[IMMessageItem initWithSender:0x100890210 time:0x1008831d0 body:0x10083ba80 attributes:0x0 fileTransferGUIDs:0x1007081d0 flags:0x1 error:0x0 guid:0x10524acc0]
-[IMMessageItem initWithSender:0x100890210 time:0x1008831d0 body:0x10083ba80 attributes:0x0 fileTransferGUIDs:0x1007081d0 flags:0x1 error:0x0 guid:0x10524acc0 type:0x0]
-[IMMessageItem initWithSenderInfo:0x10085c330 time:0x1008831d0 timeRead:0x0 timeDelivered:0x0 timePlayed:0x0 subject:0x0 body:0x10083ba80 bodyData:0x0 attributes:0x0 fileTransferGUIDs:0x1007081d0 flags:0x1 guid:0x10524acc0 messageID:0x0 account:0x0 accountID:0x0 service:0x0 handle:0x0 roomName:0x0 unformattedID:0x0 countryCode:0x0 expireState:0x0 balloonBundleID:0x0 payloadData:0x0 expressiveSendStyleID:0x0 timeExpressiveSendPlayed:0x0 bizIntent:0x0 locale:0x0 errorType:0x0 type:0x0]
-[IMItem initWithSenderInfo:0x10085c330 time:0x1008831d0 guid:0x10524acc0 messageID:0x0 account:0x0 accountID:0x0 service:0x0 handle:0x0 roomName:0x0 unformattedID:0x0 countryCode:0x0 type:0x0]
-[IMItem setSenderInfo:0x10085c330]

根据日志可看出关键函数-[SMSServiceSession smsMessageReceived:0x10524abc0 msgID:0x80000006], 使用命令frida-trace -U -m "-[SMSServiceSession smsMessageReceived:msgID:]" imagent跟踪该函数,js代码如下:

{
  onEnter(log, args, state) {
    log(`-[SMSServiceSession smsMessageReceived:${ObjC.Object(args[2])} msgID:${args[3]}]`);
  },
  onLeave(log, retval, state) {
  }
}

当手机收到短信时,对应日志输出如下:

-[SMSServiceSession smsMessageReceived:<CTXPCServiceSubscriptionContext 0x10bfd1240 slotID=CTSubscriptionSlotOne, uuid=00000000-0000-0000-0000-000000000001, labelID="90D990CE-3484-4310-9F39-49A66EB80541", label="USER_LABEL_PRIMARY", phoneNumber="+861812186xxxx", userDataPreferred=1, userDefaultVoice=1> msgID:0x80000010]

根据日志信息可看出,该方法里除了msgID,并没有包含我们需要的短信及发件人相关信息。那我们继续按日志的顺序往下看,-[SMSServiceSession _convertCTMessageToDictionary:requiresUpload:] 这函数看着比较亲切。trace该函数得到日志如下:

-[SMSServiceSession _convertCTMessageToDictionary:<[CTMessageAddress: 1898000xxxx/TYPE=PLMN]
	[Recipients: (
)]
	[Items: (
    "<CTMessagePart: 0x10be7f340>"
)]
	[Raw Headers: (null)]
	[Date: 2023-07-30 14:43:23 +0000]
	[message ID: -2147483630]
	[message Type: 1]
	[service center: (null)]
	[Content-type: (null)]
	[Content-type params: {
}]
	[replace message: 0]
 requiresUpload:0x16edaec2f]
-[SMSServiceSession _convertCTMessageToDictionary:requiresUpload:]={
    co = "+861812186xxxx";
    g = "00ECAC3B-0790-8674-CAD5-58DD07F4DEBA";
    h = 1898000xxxx;
    k =     (
                {
            data = <e58fa6>;
            type = "text/plain";
        }
    );
    l = 0;
    m = sms;
    n = 460;
    re =     (
    );
    sV = 1;
    w = "2023-07-30 14:43:25 +0000";
}}=

从日志可以看出。该方法就是我们要hook方法,收件人:co,发件人:h,短信内容:k

3、编写deb插件

具体的创建流程请参考之前的文章,源码如下:

#import <Foundation/Foundation.h>
#import "CaptainHook/CaptainHook.h"

@interface SMSServiceSession

@end

@interface IMDService

-(void)loadServiceBundle;
@property (nonatomic,retain,readonly) NSBundle * bundle;

@end

CHDeclareClass(SMSServiceSession); // declare class
CHOptimizedMethod2(self, id, SMSServiceSession, _convertCTMessageToDictionary, NSDictionary *, arg1, requiresUpload, BOOL*, arg2) {
    id result = CHSuper2(SMSServiceSession, _convertCTMessageToDictionary, arg1, requiresUpload, arg2);
    
    @try {
        NSString *from = result[@"h"];
        NSString *to = result[@"co"];
        NSArray *msgList = result[@"k"];
        if (msgList.count > 0) {
            NSData *data = msgList[0][@"data"];
            NSString *content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            NSLog(@"witwit =from %@=to %@=content %@=",from, to, content);
        } else {
            NSLog(@"witwit =sms为空=");
        }
    } @catch (NSException *exception) {
        NSLog(@"witwit =SMSServiceSession _convertCTMessageToDictionary=err=%@=", exception);

    } @finally {
        
    }
    
    return result;
}

CHDeclareClass(IMDService)
CHOptimizedMethod0(self, void, IMDService, loadServiceBundle) {

    CHSuper0(IMDService, loadServiceBundle);
    NSString *bundleId = [[self bundle] bundleIdentifier];
    NSLog(@"witwit =IMDService loadServiceBundle=%@=", bundleId);
    
    if ([bundleId isEqualToString:@"com.apple.imservice.sms"]) {
        CHLoadLateClass(SMSServiceSession);
        CHHook2(SMSServiceSession, _convertCTMessageToDictionary, requiresUpload);
    }
}


CHConstructor // code block that runs immediately upon load
{
	@autoreleasepool
	{
        NSLog(@"witwit SMSForward load success");

        CHLoadLateClass(IMDService);
        CHHook0(IMDService, loadServiceBundle);
    }
}

info.plist文件配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Filter</key>
	<dict>
		<key>Bundles</key>
		<array>
			<string>com.apple.imagent</string>
		</array>
	</dict>
</dict>
</plist>

注:插件安装完成后。请重启imagent:

launchctl unload /System/Library/LaunchDaemons/com.apple.imagent.plist
launchctl load /System/Library/LaunchDaemons/com.apple.imagent.plist

总结

本篇文章主要对短信转发器的核心方法进行了分析及试验,拿到短信内容后,具体的转发逻辑请自行实现。

提示:阅读此文档的过程中遇到任何问题,请关住工众好【移动端Android和iOS开发技术分享】或+99 君羊【812546729

【iOS逆向与安全】sms短信转发插件开发,ios,安全,cocoa文章来源地址https://www.toymoban.com/news/detail-692836.html

到了这里,关于【iOS逆向与安全】sms短信转发插件开发的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【iOS逆向与安全】编写一个使应用保持前台运行的系统插件

    iOS越狱为用户打开了无限的可能性,其中之一是便是开发系统级插件,为了确保应用程序一直保持在前台,即使在意外情况下也是如此。 本文将向您展示如何轻松编写这样的插件,让我们开始探索iOS系统插件的世界吧! 学会创建功能强大的iOS系统插件。 mac系统 frida:动态调

    2024年02月03日
    浏览(29)
  • IOS 短信拦截插件

    在使⽤ iOS 设备的时候, 我们经常会收到 1069 、 1065 开头的垃圾短信, 如果开了 iMessage 会更严重, 各种乱七⼋糟的垃圾信息会时不时地收到。 从 iOS11 开始, ⼿机可以⽀持恶短信拦截插件了. 我们可以通过该插件添加⼀些规则通过滤这些不需要的信息. 【1】在 Main.storyboard 的主页

    2024年04月18日
    浏览(19)
  • 【iOS逆向与安全】原生程序与WebView交互

    WKWebView 是 iOS 应用中强大的组件,但如何在逆向工程中最好地利用它呢?本文将带您了解在逆向过程中遇到webview后的相关操作。这些技术将让您能够修改 WKWebView 行为,读写关键元素,接口拦截,并揭示更多有趣的可能性。 了解如何在 iOS 逆向工程中处理 WKWebView,包括 元素

    2024年02月02日
    浏览(39)
  • 【iOS逆向与安全】好用的一套 TCP 类

     初始化  发送数据 源码类 配置端口

    2024年02月07日
    浏览(25)
  • 【iOS逆向与安全】使用ollvm混淆你的源码

    当你在研究别人源码的时候,是不是期望着别人代码没有进行任何的防护和混淆。这时的你,是不是应该考虑一下自己代码的安全.本篇文章将告诉你,如何使用ollvm来混淆iOS端的代码【此文为入门贴,大佬请绕道】。 编译ollvm工具,并在Xcode中来混淆你的ipa或动态库,增加别

    2023年04月19日
    浏览(67)
  • 【iOS逆向与安全】越狱检测与过检测附ida伪代码

    首先在网上查找一些检测代码 放入项目运行,用 ida 打开后 F5 得到下面的 用 frida hook hook stat hook md5 frida-trace -UF -i \\\"CC_MD5\\\" -f xxxxxxx.xxx.xxxx fishhook 下面是网上找的源码

    2024年02月03日
    浏览(24)
  • uniapp ios原生插件开发之module

    在文章《uniapp ios原生插件开发 (framework,cocoapods)》中我们已经介绍了Module 类型的插件及其创建过程, 却没有深入的介绍Module类型插件开发过程中所涉及到的技术点。 本文呢就将重点放在对这些技术点的使用上进行详解,算是是对上篇文章的一个补充与扩展。 在文章开始之前

    2024年02月13日
    浏览(28)
  • 【利用宝塔WebHook插件、SmsForwarder(短信转发器)、quicker实现电脑端自动输入手机短信验证码登录】

    最近公司各种系统有一些小改动,闲置几分钟就得重新登录,然后每次登录得:打开手机→查看验证码短信→在电脑上手动输入,实在是太影响 效率 (心情)。为了更好地 搬砖 (摸鱼),利用一些小工具实现了手机验证码转发并自动输入。 服务器设定weebhook——手机验证码

    2024年03月27日
    浏览(41)
  • SMS--短信服务

    短信服务(Short Message Service)是阿里云为用户提供的一种通信服务的能力。 接下来,我们使用短信验证码功能来演示短信服务的使用。流程如下: 2.1.1 实名认证 https://help.aliyun.com/document_detail/48263.html?spm=a2c4g.11186623.2.25.1f9415ec9MLqK D 2.1.2 开通短信服务  2.1.3 申请认证秘钥  2.1.4

    2024年02月05日
    浏览(33)
  • SMS垃圾短信识别项目

    随着数字通信的快速发展,垃圾短信成为了一个普遍而烦人的问题。这些不请自来的消息不仅打扰了我们的日常生活,还可能包含诈骗和欺诈的风险。因此,有效地识别并过滤垃圾短信变得至关重要。 本项目的主要目标是开发一个机器学习模型,能够自动、准确地区分垃圾短

    2024年04月15日
    浏览(22)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包