Skip to content

Commit 5905038

Browse files
committed
Preserves commented-out binary entititlements when resigning
Allows apps to take advantage of the Psychic Paper exploit https://github.com/Siguza/psychicpaper
1 parent fb368f7 commit 5905038

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

AltSign/Signing/ALTSigner.mm

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,35 @@ - (NSProgress *)signAppAtURL:(NSURL *)appURL provisioningProfiles:(NSArray<ALTPr
212212
NSURL *profileURL = [app.fileURL URLByAppendingPathComponent:@"embedded.mobileprovision"];
213213
[profile.data writeToURL:profileURL atomically:YES];
214214

215+
NSString *additionalEntitlements = nil;
216+
217+
NSRange commentStartRange = [app.entitlementsString rangeOfString:@"<!---><!-->"];
218+
NSRange commentEndRange = [app.entitlementsString rangeOfString:@"<!-- -->"];
219+
if (commentStartRange.location != NSNotFound && commentEndRange.location != NSNotFound && commentEndRange.location > commentStartRange.location)
220+
{
221+
// Most likely using private (commented out) entitlements to exploit Psychic Paper https://github.com/Siguza/psychicpaper
222+
// Assume they know what they are doing and extract private entitlements to merge with profile's.
223+
224+
NSRange commentRange = NSMakeRange(commentStartRange.location, (commentEndRange.location + commentEndRange.length) - commentStartRange.location);
225+
NSString *commentedEntitlements = [app.entitlementsString substringWithRange:commentRange];
226+
227+
additionalEntitlements = commentedEntitlements;
228+
}
229+
215230
NSData *entitlementsData = [NSPropertyListSerialization dataWithPropertyList:profile.entitlements format:NSPropertyListXMLFormat_v1_0 options:0 error:&error];
216231
if (entitlementsData == nil)
217232
{
218233
return error;
219234
}
220235

221-
NSString *entitlements = [[NSString alloc] initWithData:entitlementsData encoding:NSUTF8StringEncoding];
236+
NSMutableString *entitlements = [[NSMutableString alloc] initWithData:entitlementsData encoding:NSUTF8StringEncoding];
237+
if (additionalEntitlements != nil)
238+
{
239+
// Insert additional entitlements after first occurence of <dict>.
240+
NSRange entitlementsStartRange = [entitlements rangeOfString:@"<dict>"];
241+
[entitlements insertString:additionalEntitlements atIndex:entitlementsStartRange.location + entitlementsStartRange.length];
242+
}
243+
222244
entitlementsByFileURL[app.fileURL] = entitlements;
223245

224246
return nil;

0 commit comments

Comments
 (0)