-
Notifications
You must be signed in to change notification settings - Fork 6
/
iAex.m
125 lines (93 loc) · 3.92 KB
/
iAex.m
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#import <UIKit/UIKit.h>
#import <Security/Security.h>
#import "sqlite3.h"
void printToStdOut(NSString *format, ...) {
va_list args;
va_start(args, format);
NSString *formattedString = [[NSString alloc] initWithFormat: format arguments: args];
va_end(args);
[[NSFileHandle fileHandleWithStandardOutput] writeData: [formattedString dataUsingEncoding: NSNEXTSTEPStringEncoding]];
[formattedString release];
}
void printUsage() {
printToStdOut(@"\niOS Authentication Extractor by TwizzyIndy\n");
printToStdOut(@"May-2016\n\n");
}
NSMutableArray *getCommandLineOptions(int argc, char **argv) {
NSMutableArray *arguments = [[NSMutableArray alloc] init];
int argument;
if (argc == 1) {
[arguments addObject:(id)kSecClassGenericPassword];
return [arguments autorelease];
} else {
printUsage();
}
return [arguments autorelease];
}
NSArray * getKeychainObjectsForSecClass(CFTypeRef kSecClassType) {
NSMutableDictionary *genericQuery = [[NSMutableDictionary alloc] init];
[genericQuery setObject:(id)kSecClassType forKey:(id)kSecClass];
[genericQuery setObject:(id)kSecMatchLimitAll forKey:(id)kSecMatchLimit];
[genericQuery setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes];
[genericQuery setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnRef];
[genericQuery setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData];
NSArray *keychainItems = nil;
if (SecItemCopyMatching((CFDictionaryRef)genericQuery, (CFTypeRef *)&keychainItems) != noErr)
{
keychainItems = nil;
}
[genericQuery release];
return keychainItems;
}
void printAccountToken(NSDictionary* passwordItem) {
NSData* dataToken = [passwordItem objectForKey:(id)kSecValueData];
printToStdOut(@"Token : %@\n", [[NSString alloc] initWithData:dataToken encoding:NSUTF8StringEncoding] );
}
void printAccountId(NSDictionary* passwordItem) {
printToStdOut(@"ID : %@\n", [passwordItem objectForKey:(id)kSecAttrAccount] );
}
void printGenericPassword(NSDictionary *passwordItem) {
printToStdOut(@"Generic Password\n");
printToStdOut(@"----------------\n");
printToStdOut(@"Service: %@\n", [passwordItem objectForKey:(id)kSecAttrService]);
printToStdOut(@"Account: %@\n", [passwordItem objectForKey:(id)kSecAttrAccount]);
printToStdOut(@"Entitlement Group: %@\n", [passwordItem objectForKey:(id)kSecAttrAccessGroup]);
printToStdOut(@"Label: %@\n", [passwordItem objectForKey:(id)kSecAttrLabel]);
printToStdOut(@"Generic Field: %@\n", [[passwordItem objectForKey:(id)kSecAttrGeneric] description]);
NSData* passwordData = [passwordItem objectForKey:(id)kSecValueData];
printToStdOut(@"Keychain Data: %@\n\n", [[NSString alloc] initWithData:passwordData encoding:NSUTF8StringEncoding]);
}
void printResultsForSecClass(NSArray *keychainItems, CFTypeRef kSecClassType) {
if (keychainItems == nil) {
printToStdOut(@"\nFound Nothing !\n");
return;
}
NSDictionary *keychainItem;
for (keychainItem in keychainItems) {
if ( [[keychainItem objectForKey:(id)kSecAttrService] isEqual:@"com.apple.account.AppleAccount.token"])
{
if (kSecClassType == kSecClassGenericPassword) {
printAccountToken(keychainItem);
}
} else if ( [[keychainItem objectForKey:(id)kSecAttrService] isEqual:@"com.apple.icloud.fmip.auth"]) {
if (kSecClassType == kSecClassGenericPassword) {
printAccountId(keychainItem);
}
}
}
return;
}
int main(int argc, char **argv)
{
id pool=[NSAutoreleasePool new];
NSArray* arguments;
arguments = getCommandLineOptions(argc, argv);
NSArray *passwordItems;
NSArray *keychainItems = nil;
for (id kSecClassType in (NSArray *) arguments) {
keychainItems = getKeychainObjectsForSecClass((CFTypeRef)kSecClassType);
printResultsForSecClass(keychainItems, (CFTypeRef)kSecClassType);
[keychainItems release];
}
[pool drain];
}