-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.m
129 lines (116 loc) · 5.52 KB
/
main.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
126
127
128
//
// LibiAuditor
//
// Created by Dominic Chell on 13/02/2012.
// Copyright (c) 2012 MDSec Consulting Ltd. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "appFinder.h"
#import "AppDB.h"
#import "binScan.h"
#import "iauditorDB.h"
#import "issues.h"
#define BUFFER_SIZE 512
#define showHelp() { printf("[*] iAuditor v0.1 Help\n\nCommands:\n\thelp\t\t\t\t- This help\n\tlist\t\t\t\t- Lists the installed applications\n\tscan \"appnumber\" or \"all\"\t- Performs binary assurance checks\n\taudit \"appnumber\"\t\t- Enables auditing on the application\n\tissues \"appnumber\"\t\t- Prints the current list of issues to the console\n\tclean\t\t\t\t- Disables all auditing\n\texit\t\t\t\t- Quits iAuditor");}
int main (int argc, const char * argv[])
{
@autoreleasepool
{
NSMutableArray *listOfInstalledApps = [[NSMutableArray alloc] init];
listOfInstalledApps = [appFinder getAppList];
[iauditorDB cleanPlist];
NSMutableString *cmd = [NSMutableString stringWithString:@""];
BOOL done = NO;
char raw[BUFFER_SIZE];
uint8_t i;
int c;
raw[BUFFER_SIZE - 1] = 0;
while(1)
{
cmd = [NSMutableString stringWithString:@""];
printf("\niauditor>");
while(true) {
for(i = 0; i < BUFFER_SIZE - 1; ++i) if((done = ((c = getc(stdin)) == EOF || (raw[i] = c) == '\n'))) break;
if(done) raw[i] = 0;
[cmd appendFormat:@"%s", raw];
if(done) break;
}
NSArray *command = [cmd componentsSeparatedByString:@" "];
if([[command objectAtIndex:0] isEqualToString: @"help"])
{
showHelp();
}
else if([[command objectAtIndex:0] isEqualToString: @"list"])
{
printf("[*] Printing list of Apps\n\n");
int i=0;
for(AppDB *adb in listOfInstalledApps)
{
printf("%d.\t%s\n",i, [[adb getName] UTF8String]);
i++;
}
}
else if(([[command objectAtIndex:0] isEqualToString: @"scan"]))
{
printf("[*] Performing binary assurance checks against application\n");
if([command count] < 2)
printf("ERROR: Unable to read app number from command line");
else if([[command objectAtIndex:1] isEqualToString:@"all"])
{
for(AppDB *adb in listOfInstalledApps)
{
NSString *binpath = [NSString stringWithFormat:@"\"%@/%@\"", [adb getPath], [adb getName]];
if([binScan checkPIE: binpath])
printf("Position Independent Executable (PIE) is ENABLED on %s\n", [[adb getName] UTF8String]);
else printf("WARNING: Position Independent Executable (PIE) is DISABLED on on %s\n", [[adb getName] UTF8String]);
}
}
else
{
NSUInteger index = [[command objectAtIndex:1] integerValue];
AppDB *selectedApp = [listOfInstalledApps objectAtIndex:index];
NSString *binpath = [NSString stringWithFormat:@"\"%@/%@\"", [selectedApp getPath], [selectedApp getName]];
if([binScan checkPIE: binpath])
printf("Position Independent Executable (PIE) is ENABLED on %s", [[selectedApp getName] UTF8String]);
else printf("WARNING: Position Independent Executable (PIE) is DISABLED on %s", [[selectedApp getName] UTF8String]);
}
}
else if(([[command objectAtIndex:0] isEqualToString: @"audit"]))
{
if([command count]<2)
printf("ERROR: Unable to read app number form command line");
else
{
NSUInteger index = [[command objectAtIndex:1] integerValue];
AppDB *selectedApp = [listOfInstalledApps objectAtIndex:index];
[iauditorDB addAppToPlist:[selectedApp getBundle]];
printf("[*] Auditing ENABLED on %s, now go use the app!", [[selectedApp getName] UTF8String]);
}
}
else if(([[command objectAtIndex:0] isEqualToString: @"issues"]))
{
if([command count]<2)
printf("ERROR: Unable to read app number form command line");
else
{
NSUInteger index = [[command objectAtIndex:1] integerValue];
AppDB *selectedApp = [listOfInstalledApps objectAtIndex:index];
printf("[*] Listing issues for %s:\n", [[selectedApp getName] UTF8String]);
NSString *iadbPath = [NSString stringWithFormat:@"%@/../Documents/iauditor.db", [selectedApp getPath]];
[issues list:iadbPath];
}
}
else if(([[command objectAtIndex:0] isEqualToString: @"clean"]))
{
printf("[*] Disabling all auditing!");
[iauditorDB cleanPlist];
}
else if([[command objectAtIndex:0] isEqualToString: @"exit"])
{
printf("[*] Exit command received, exiting!\n");
exit(1);
}
}// end while 1
}// end autorelease
return 0;
}