콘텐츠로 이동

iOS 보안 침입에 대한 간단한 GUI 추가

앱 내의 AppSealing 라이브러리는 앱이 실행된 직후 자동으로 활성화됩니다. AppSealing 라이브러리가 비정상적인 환경(탈옥된 기기, 실행 파일이 복호화되었거나 디버거가 연결된 경우 등)을 탐지하면 사용자 동작과 관계없이 20초 후에 앱을 종료하므로, 앱은 탐지 결과를 사용자에게 알리고 사용자가 자신의 기기에 유효하지 않은 환경이 있다는 것을 인식할 수 있도록 적절한 메시지 상자를 표시해야 합니다.

앱에서 해당 대화 상자를 표시하려면 “ViewController.swift” 파일에 작은 코드 청크를 삽입하여 쉽게 할 수 있습니다. (Objective-C 기반 프로젝트의 경우 ViewController.mm)

먼저 Xcode 프로젝트를 열고 ViewController.swift” 파일을 엽니다.

swift 파일을 연 후 다음 코드를 넣습니다 (ViewController.swift 파일에 이미 ‘viewDidAppear’ 메서드가 포함되어 있다면 ‘super.viewDidAppear( animated );’ 라인 아래에 다음 코드의 본문만 삽입하세요.)

Swift 프로젝트를 위한 ‘ViewController.swift’에 간단한 UI 코드

Section titled “Swift 프로젝트를 위한 ‘ViewController.swift’에 간단한 UI 코드”

override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear( animated );
let inst: AppSealingInterface = AppSealingInterface();
let tamper: Int32 = inst._IsAbnormalEnvironmentDetected();
if ( tamper > 0 )
{
var msg = "Abnormal Environment Detected !!";
if ( tamper & DETECTED_JAILBROKEN ) > 0
{ msg += "\n - Jailbroken"; }
if ( tamper & DETECTED_DRM_DECRYPTED ) > 0
{ msg += "\n - Executable is not encrypted"; }
if ( tamper & DETECTED_DEBUG_ATTACHED ) > 0
{ msg += "\n - App is debugged"; }
if ( tamper & ( DETECTED_HASH_INFO_CORRUPTED | DETECTED_HASH_MODIFIED )) > 0
{ msg += "\n - App integrity corrupted"; }
if ( tamper & ( DETECTED_CODESIGN_CORRUPTED | DETECTED_EXECUTABLE_CORRUPTED )) > 0
{ msg += "\n - App executable has corrupted"; }
if ( tamper & DETECTED_CERTIFICATE_CHANGED ) > 0
{ msg += "\n - App has re-signed"; }
let alertController = UIAlertController(title: "AppSealing",
message: msg, preferredStyle: .alert );
alertController.addAction(UIAlertAction(title: "Confirm", style: .default,
handler: { (action:UIAlertAction!) -> Void in
#if !DEBUG // Debug mode does not kill app even if security threat has found
exit(0);
#endif
} ));
self.present(alertController, animated: true, completion: nil);
}
}

위의 샘플 UI 코드는 “AppSealingiOS.mm” 파일에도 포함되어 있으므로 해당 파일에서 복사하여 붙여넣을 수 있습니다.

프로젝트가 Objective-C 기반인 경우 다음 코드를 사용하여 간단한 UI를 표시할 수 있습니다.

#include "AppsealingiOS.h"
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
int tamper = ObjC_IsAbnormalEnvironmentDetected();
if ( tamper > 0 )
{
NSString* msg = @"Abnormal Environment Detected !!";
if (( tamper & DETECTED_JAILBROKEN ) > 0 )
msg = [msg stringByAppendingString:@"\n - Jailbroken"];
if (( tamper & DETECTED_DRM_DECRYPTED ) > 0 )
msg = [msg stringByAppendingString:@"\n - Executable is not encrypted"];
if (( tamper & DETECTED_DEBUG_ATTACHED ) > 0 )
msg = [msg stringByAppendingString:@"\n - App is debugged"];
if ( tamper & ( DETECTED_HASH_INFO_CORRUPTED | DETECTED_HASH_MODIFIED )) > 0
msg = [msg stringByAppendingString:@"\n - App integrity corrupted"];
if ( tamper & ( DETECTED_CODESIGN_CORRUPTED | DETECTED_EXECUTABLE_CORRUPTED )) > 0
msg = [msg stringByAppendingString:@"\n - App executable has corrupted"];
if ( tamper & DETECTED_CERTIFICATE_CHANGED ) > 0
msg = [msg stringByAppendingString:@"\n - App has re-signed"];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"AppSealing"
message:msg
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"Confirm"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
#if !DEBUG && !defined(DEBUG) // Debug mode does not kill app even if security threat has found
exit(0);
#endif
}];
[alert addAction:confirm];
[self presentViewController:alert animated:YES completion:nil];
}
}

탈옥된 기기나 Xcode 또는 gdb를 사용하여 앱을 디버그하는 등 비정상적인 기기에서 앱을 실행할 때 아래와 같은 간단한 경고 상자가 표시됩니다. 이러한 상황에서는 사용자 동작과 관계없이 앱이 20초 후 자동으로 종료됩니다.

프로젝트가 Cordova 기반인 경우 ViewController.mm 대신 MainViewController.mm에 이 코드 블록을 넣을 수 있습니다

(MainViewController.m 파일의 확장자를 .mm으로 변경해야 합니다)

프로젝트가 Ionic 기반인 경우 ViewController.swift 파일이 생성되지 않으므로 AppDelegate.swift 파일에 다음 수정된 코드를 추가하여 GUI를 생성할 수 있습니다

Ionic 프로젝트를 위한 ‘AppDelegate.swift’에 간단한 UI 코드

Section titled “Ionic 프로젝트를 위한 ‘AppDelegate.swift’에 간단한 UI 코드”
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
// Override point for customization after application launch.
let inst: AppSealingInterface = AppSealingInterface();
let tamper: Int32 = inst._IsAbnormalEnvironmentDetected();
if ( tamper > 0 )
{
var msg = "Abnormal Environment Detected !!";
if ( tamper & DETECTED_JAILBROKEN ) > 0
{ msg += "\n - Jailbroken"; }
if ( tamper & DETECTED_DRM_DECRYPTED ) > 0
{ msg += "\n - Executable is not encrypted"; }
if ( tamper & DETECTED_DEBUG_ATTACHED ) > 0
{ msg += "\n - App is debugged"; }
if ( tamper & ( DETECTED_HASH_INFO_CORRUPTED | DETECTED_HASH_MODIFIED )) > 0
{ msg += "\n - App integrity corrupted"; }
if ( tamper & ( DETECTED_CODESIGN_CORRUPTED | DETECTED_EXECUTABLE_CORRUPTED )) > 0
{ msg += "\n - App executable has corrupted"; }
if ( tamper & DETECTED_CERTIFICATE_CHANGED ) > 0
{ msg += "\n - App has re-signed"; }
let alertController = UIAlertController(title: "AppSealing",
message: msg, preferredStyle: .alert );
alertController.addAction(UIAlertAction(title: "Confirm", style: .default,
handler: { (action:UIAlertAction!) -> Void in
#if !DEBUG // Debug mode does not kill app even if security threat has found
exit(0);
#endif
} ));
// show alert
let alertWindow = UIWindow( frame: UIScreen.main.bounds )
alertWindow.rootViewController = UIViewController()
alertWindow.windowLevel = UIWindow.Level.alert + 1;
alertWindow.makeKeyAndVisible()
alertWindow.rootViewController?.present( alertController,
animated: true, completion: nil )
}
return true;
}