美文网首页
(iOS) App防抓包

(iOS) App防抓包

作者: 終于 | 来源:发表于2019-01-09 12:35 被阅读0次

大致有两种做法,一种是检测到有代理服务器,就不发送网络请求;一种是不发送给代理服务器,而是正常发给目标服务器。

第一种,提供一个检测当前手机是否有开启代理,剩下的工作根据业务去完成即可。

CFDictionaryRef dicRef = CFNetworkCopySystemProxySettings();

const CFStringRef proxyCFstr = CFDictionaryGetValue(dicRef, (const void*)kCFNetworkProxiesHTTPProxy);

NSString* proxy = (__bridgeNSString*)(proxyCFstr);

 if(proxy)returnYES;

 else return NO;    

第二种,因为NSURLSession实例化需要传入NSURLSessionConfiguration对象,config中有个属性是connectionProxyDictionary,保存的是网络会话连接中的代理服务器。所以,不走代理服务器只需要Hook系统方法,将此属性置为空字典即可。

Method method1 = class_getClassMethod([NSURLSession class],@selector(sessionWithConfiguration:));

Method method2 = class_getClassMethod([NSURLSession class],@selector(hhz_sessionWithConfiguration:));

method_exchangeImplementations(method1, method2);

Method method3 = class_getClassMethod([NSURLSession class],@selector(sessionWithConfiguration:delegate:delegateQueue:));

Method method4 = class_getClassMethod([NSURLSession class],@selector(hhz_sessionWithConfiguration:delegate:delegateQueue:));

method_exchangeImplementations(method3, method4);

+ (NSURLSession*)hhz_sessionWithConfiguration:(NSURLSessionConfiguration*)configuration

                                     delegate:(nullableid)delegate

                                delegateQueue:(nullableNSOperationQueue*)queue

{

    if(configuration) configuration.connectionProxyDictionary = @{};

    return [self hhz_sessionWithConfiguration:configuration delegate:delegate delegateQueue:queue];

}

+ (NSURLSession*)hhz_sessionWithConfiguration:(NSURLSessionConfiguration*)configuration

{

    if(configuration) configuration.connectionProxyDictionary = @{};

    return [self hhz_sessionWithConfiguration:configuration];

}

其中method替换可以抽离出方法,此处为了方便复制粘贴测试就没处理。然后根据项目需求,提供相应的open,close类方法即可实现实时打开关闭抓包设置。

相关文章

  • (iOS) App防抓包

    大致有两种做法,一种是检测到有代理服务器,就不发送网络请求;一种是不发送给代理服务器,而是正常发给目标服务器。 第...

  • iOS app防抓包

    大致有两种做法:1.一种是检测到有代理服务器,就不发送网络请求;2.一种是不发送给代理服务器,而是正常发给目标服务器;

  • ios 防抓包

    - (void)checkHTTPEnable { NSDictionary * ref = (__bridg...

  • iOS Charles使用

    Charles iOS抓包Https,iOS最新系统抓包 Charles抓包入门(Mac/iOS,HTTP/HTT...

  • iOS抓包&&安卓抓包

    Mac下使用Charles iOS 抓包Mac下使用Chrome 安卓抓包 iOS抓包 1、下载Charles ...

  • ios抓包软件Thor限时折扣6元中,手慢无

    Thor for iOS iOS 端强力专业的 HTTP 抓包分析工具 - Thor v1.0.0 已上架 App...

  • iOS Wireshark抓包

    级别:★☆☆☆☆标签:「Wireshark for mac」「iOS TCP抓包」「iOS UDP抓包」作者: X...

  • (青花瓷)原创内容,转载请注明出处

    使用Charles(青花瓷)抓包 charles又名青花瓷,在iOS开发中的抓包中具有重要作用 1.拦截别人APP...

  • Fiddler 对App抓包代理问题

    App 防止 Fiddler 抓包小技巧fiddler 抓不到app包 抓不到okhttp/asynchttpcl...

  • iOS 防止抓包实践-2020-06-10

    关于抓包 用Mac开发iOS APP之后,用得最多的抓包工具就是Charles,并且版本是4.0,不升级。整体来说...

网友评论

      本文标题:(iOS) App防抓包

      本文链接:https://www.haomeiwen.com/subject/hrwwrqtx.html