'경로 및 정보' 카테고리의 다른 글
IIS Crypto 설정 툴(비영리) (0) | 2020.11.25 |
---|---|
FTP 클라이언트 능동형 설정 관련 (0) | 2020.11.20 |
크롬 UTF 인코딩 확장 (0) | 2020.11.08 |
Kubernetes Nginx Ingress Controller (0) | 2020.01.06 |
A Practical Attack Framework (0) | 2019.11.21 |
IIS Crypto 설정 툴(비영리) (0) | 2020.11.25 |
---|---|
FTP 클라이언트 능동형 설정 관련 (0) | 2020.11.20 |
크롬 UTF 인코딩 확장 (0) | 2020.11.08 |
Kubernetes Nginx Ingress Controller (0) | 2020.01.06 |
A Practical Attack Framework (0) | 2019.11.21 |
https://github.com/olxios/SmartSec_iOS_Security/blob/master/README.md
iOS 무결성 검증하는 소스 코드를 찾던 중 해당 내용을 확인하게 되어 글을 작성 합니다.
등등에 대한 내용을 확인할 수 있다.
There are two topics related to file integrity:
Application source code integrity checks: In the "Tampering and Reverse Engineering" chapter, we discussed the iOS IPA application signature check. We also saw that determined reverse engineers can easily bypass this check by re-packaging and re-signing an app using a developer or enterprise certificate. One way to make this harder is to add an internal run-time check that determines whether the signatures still match at run time.
File storage integrity checks: When files are stored by the application, key-value pairs in the Keychain, UserDefaults/NSUserDefaults, a SQLite database, or a Realm database, their integrity should be protected.
Sample Implementation - Application Source Code
Apple takes care of integrity checks with DRM. However, additional controls (such as in the example below) are possible. The mach_header is parsed to calculate the start of the instruction data, which is used to generate the signature. Next, the signature is compared to the given signature. Make sure that the generated signature is stored or coded somewhere else.
int xyz(char *dst) { const struct mach_header * header; Dl_info dlinfo; if (dladdr(xyz, &dlinfo) == 0 || dlinfo.dli_fbase == NULL) { NSLog(@" Error: Could not resolve symbol xyz"); [NSThread exit]; } while(1) { header = dlinfo.dli_fbase; // Pointer on the Mach-O header struct load_command * cmd = (struct load_command *)(header + 1); // First load command // Now iterate through load command //to find __text section of __TEXT segment for (uint32_t i = 0; cmd != NULL && i < header->ncmds; i++) { if (cmd->cmd == LC_SEGMENT) { // __TEXT load command is a LC_SEGMENT load command struct segment_command * segment = (struct segment_command *)cmd; if (!strcmp(segment->segname, "__TEXT")) { // Stop on __TEXT segment load command and go through sections // to find __text section struct section * section = (struct section *)(segment + 1); for (uint32_t j = 0; section != NULL && j < segment->nsects; j++) { if (!strcmp(section->sectname, "__text")) break; //Stop on __text section load command section = (struct section *)(section + 1); } // Get here the __text section address, the __text section size // and the virtual memory address so we can calculate // a pointer on the __text section uint32_t * textSectionAddr = (uint32_t *)section->addr; uint32_t textSectionSize = section->size; uint32_t * vmaddr = segment->vmaddr; char * textSectionPtr = (char *)((int)header + (int)textSectionAddr - (int)vmaddr); // Calculate the signature of the data, // store the result in a string // and compare to the original one unsigned char digest[CC_MD5_DIGEST_LENGTH]; CC_MD5(textSectionPtr, textSectionSize, digest); // calculate the signature for (int i = 0; i < sizeof(digest); i++) // fill signature sprintf(dst + (2 * i), "%02x", digest[i]); // return strcmp(originalSignature, signature) == 0; // verify signatures match return 0; } } cmd = (struct load_command *)((uint8_t *)cmd + cmd->cmdsize); } } }
Sample Implementation - Storage
When ensuring the integrity of the application storage itself, you can create an HMAC or signature over either a given key-value pair or a file stored on the device. The CommonCrypto implementation is best for creating an HMAC. If you need encryption, make sure that you encrypt and then HMAC as described in Authenticated Encryption.
When you generate an HMAC with CC:
// Allocate a buffer to hold the digest and perform the digest. NSMutableData* actualData = [getData]; //get the key from the keychain NSData* key = [getKey]; NSMutableData* digestBuffer = [NSMutableData dataWithLength:CC_SHA256_DIGEST_LENGTH]; CCHmac(kCCHmacAlgSHA256, [actualData bytes], (CC_LONG)[key length], [actualData bytes], (CC_LONG)[actualData length], [digestBuffer mutableBytes]); [actualData appendData: digestBuffer];
Alternatively, you can use NSData for steps 1 and 3, but you'll need to create a new buffer for step 4.
When verifying the HMAC with CC, follow these steps:
NSData* hmac = [data subdataWithRange:NSMakeRange(data.length - CC_SHA256_DIGEST_LENGTH, CC_SHA256_DIGEST_LENGTH)]; NSData* actualData = [data subdataWithRange:NSMakeRange(0, (data.length - hmac.length))]; NSMutableData* digestBuffer = [NSMutableData dataWithLength:CC_SHA256_DIGEST_LENGTH]; CCHmac(kCCHmacAlgSHA256, [actualData bytes], (CC_LONG)[key length], [actualData bytes], (CC_LONG)[actualData length], [digestBuffer mutableBytes]); return [hmac isEqual: digestBuffer];
Bypassing File Integrity ChecksWhen you're trying to bypass the application-source integrity checks
When you're trying to bypass the storage integrity checks
For the application source code integrity checks Run the app on the device in an unmodified state and make sure that everything works. Then apply patches to the executable using optool, re-sign the app as described in the chapter "Basic Security Testing", and run it. The app should detect the modification and respond in some way. At the very least, the app should alert the user and/or terminate the app. Work on bypassing the defenses and answer the following questions:
For the storage integrity checks A similar approach works. Answer the following questions:
remote-iphone-exploitation(project zero) (0) | 2020.01.10 |
---|---|
iOS Application Injection (0) | 2020.01.02 |
ARM 어셈블리어 (0) | 2019.12.05 |
iOS Penetration Testing Part 3 (0) | 2019.11.25 |
The Universal SSL pinning bypass for Android applications (0) | 2019.11.21 |
XML External Entity (XXE) (0) | 2019.11.28 |
---|---|
OAuth 2.0 대표 취약점과 보안 고려사항 (0) | 2019.11.25 |
인증과 토큰 그리고 JWT (0) | 2019.11.25 |
기술소개[NBP 기술&경험]SSRF 공격의 피해 사례와 대응 #1 (0) | 2019.11.25 |
Spring Boot RCE (2) | 2019.11.21 |
어느 순간부터 공부 했거나 수행 했던 업무 등이 기억나지 않아... 기록을 남겨본다..
뭐 언제까지 이어갈지는 나도 모르겠다