forked from iSECPartners/ios-ssl-kill-switch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
sslkill.c
52 lines (42 loc) · 1.76 KB
/
sslkill.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#import <Security/SecureTransport.h>
// Hook SSLSetSessionOption()
static OSStatus replaced_SSLSetSessionOption(
SSLContextRef context,
SSLSessionOption option,
Boolean value) {
// Remove the ability to modify the value of the kSSLSessionOptionBreakOnServerAuth option
if (option == kSSLSessionOptionBreakOnServerAuth)
return noErr;
else
return SSLSetSessionOption(context, option, value);
}
// Hook SSLCreateContext()
static SSLContextRef replaced_SSLCreateContext (
CFAllocatorRef alloc,
SSLProtocolSide protocolSide,
SSLConnectionType connectionType
) {
SSLContextRef sslContext = SSLCreateContext(alloc, protocolSide, connectionType);
// Immediately set the kSSLSessionOptionBreakOnServerAuth option in order to disable cert validation
SSLSetSessionOption(sslContext, kSSLSessionOptionBreakOnServerAuth, true);
return sslContext;
}
// Hook SSLHandshake()
static OSStatus replaced_SSLHandshake(
SSLContextRef context
) {
OSStatus result = SSLHandshake(context);
// Hijack the flow when breaking on server authentication
if (result == errSSLServerAuthCompleted) {
// Do not check the cert and call SSLHandshake() again
return SSLHandshake(context);
}
else
return result;
}
#define DYLD_INTERPOSE(_replacment,_replacee) \
__attribute__((used)) static struct{ const void* replacment; const void* replacee; } _interpose_##_replacee \
__attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacment, (const void*)(unsigned long)&_replacee };
DYLD_INTERPOSE(replaced_SSLSetSessionOption, SSLSetSessionOption)
DYLD_INTERPOSE(replaced_SSLCreateContext, SSLCreateContext)
DYLD_INTERPOSE(replaced_SSLHandshake, SSLHandshake)