多年來我一直在研究個人網銀 App 的安全性。這份報告採用黑箱測試與靜態分析兩種手法,針對全球最具影響力的四十個 iPhone/iPad 網銀應用進行檢測,涵蓋國家如下:

1. 本研究在累計 40 小時內(不連續)完成。
2. 為保護應用所有者與用戶,本研究不公開所發現的具體漏洞與利用手法。
3. 所有測試僅在客戶端執行,完全排除任何伺服器端測試。
4. 已聯繫部分受影響銀行並提交漏洞報告。
每個網銀應用都經過下列檢查:
傳輸安全 明文流量 不當的會話處理 正確驗證 SSL 證書 編譯器保護 反破解保護 PIE 編譯 使用 stack cookies 編譯 自動引用計數 UIWebView 資料驗證(輸入、輸出) 分析 UIWebView 的實作 不安全的資料儲存 SQLite 資料庫 檔案快取 檢查屬性列表檔案 日誌記錄 自訂日誌 NSLog 輸出 崩潰報告檔案 二進位分析 拆解應用 檢測組語層級的保護與混淆 檢測防竄改保護 檢測反除錯保護 協議處理器 客戶端注入 第三方庫
結果概述

黑箱階段使用到的工具:
otool (object file displaying tool)[1] Burp pro (proxy tool)[2] ssh (Secure Shell)
最刺眼的數字是:40% 通過 App Store 審核的應用完全不驗證 SSL 證書,這讓它們輕易暴露在中間人攻擊之下。[3]
少數應用(低於 20%)沒有具備位置獨立可執行檔(PIE)與堆疊溢位防護。這些機制本有助於降低記憶體洩漏攻擊的風險。
>otool –hv MobileBank
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
MH_MAGIC ARM V6 0x00 EXECUTE 24 3288 NOUNDEFS DYLDLINK PREBOUND TWOLEVEL更普遍的是,90% 的應用內部散落著多處非 SSL 連結。攻擊者得以攔截流量、注入任意 JavaScript/HTML,進而偽造登入頁面。
此外,50% 的程序因 UIWebView 中不安全地注入 JavaScript,容易遭受腳本注入攻擊;部分案例中甚至暴露了原生 iOS 能力,使受害者裝置被用來寄送簡訊或郵件。

一種正在流行的新型釣魚手法值得警惕:受害者看到「網路銀行密碼已過期」的提示,依指示輸入帳號與密碼,攻擊者趁機竊取憑證並完全取得帳戶存取權。
以下示例展示個人銀行應用中的 UIWebView 漏洞
攻擊者可注入偽造的 HTML 表單,誘騙用戶輸入帳號密碼,再將憑證送往惡意網站。


另一項引起我注意的檢測結果是:70% 的應用沒有提供替代認證方案,例如多因素認證,這本可顯著緩解釣魚攻擊的風險。
多數應用產生的日誌檔案暴露了敏感資訊,例如崩潰報告。這類資訊一旦外洩,等於替攻擊者鋪路,方便他們針對特定用戶開發可用的 0day 利用。

大多數應用透過蘋果系統日誌公開敏感資料。下例是從 iPhone 配置工具(IPCU)的控制台擷取到的內容,應用在做身份驗證時把用戶憑證寫進了日誌:
…CA_DEBUG_TRANSACTIONS=1 in environment to log backtraces.
Jun 22 16:20:37 Test Bankapp[2390] : USER-IDXRSPASSWORD xxxxxxxx
Jun 22 16:20:37 Test Bankapp[2390] : ]]]]]]]]]]]]] wxxx.xxxxx.com
Jun 22 16:20:42 Test Bankapp[2390] : RETURNED:
Jun 22 16:20:42 Test Bankapp[2390] : CoreAnimation: warning, deleted thread with uncommitted CATransaction; set CA_DEBUG_TRANSACTIONS=1 in environment to log backtraces.
…
Static Analysis Results
The following tools were used for the static analysis and decryption:
IDA PRO (disassembler tool)[4]
Clutch (cracking utility)[5]
objc-helper-plugin-ida[6]
ssh (Secure Shell)
gdb (debugger tool)
IPCU[7]
The binary code of each app was decrypted using Clutch. A combination of decrypted code and code disassembled with IDA PRO was used to analyze the application.
Hardcoded development credentials were found in the code.
__text:00056350 ADD R0, PC ; selRef_sMobileBankingURLDBTestEnv__
__text:00056352 MOVT.W R2, #0×46
__text:00056356 ADD R2, PC ; "https://mob_user:T3stepwd@db.internal/internal/db/start.do?login=mobileEvn"
__text:00056358 LDR R1, [R0] ; "setMobileBankingURLDBTestEnv_iPad_mobil"…
__text:0005635A MOV R0, R4
__text:0005635C BLX _objc_msgSend
__text:00056360 MOV R0, (selRef_setMobileBankingURLDBTestEnvWithValue_iPad_mobileT_ – 0×56370) ; selRef_setMobileBankingURLDBTestEnvWithValue_iPad_mobileT_
__text:00056368 MOVW R2, #0xFA8A
__text:0005636C ADD R0, PC ; selRef_setMobileBankingURLDBTestEnvWithValue_i_mobileT_
__text:0005636E MOVT.W R2, #0×46
__text:00056372 ADD R2, PC ; "https://mob_user:T3stepwd@db.internal/internal/db/start.do?login=mobileEvn&branch=%@&account=%@&subaccount=%@"
__text:00056374 LDR R1, [R0] ; "setMobileBankingURLDBTestEnvWith_i"…
__text:00056376 MOV R0, R4
__text:00056378 BLX _objc_msgSend
By using hardcoded credentials, an attacker could gain access to the development infrastructure of the bank and infest the application with malware causing a massive infection for all of the application's users.
Internal functionality exposed via plaintext connections (HTTP) could allow an attacker with access to the network traffic to intercept or tamper with data.
__text:0000C980 ADD R2, PC ; "https://%@/news/?version=%u"
__text:0000C982 MOVT.W R3, #9
__text:0000C986 LDR R1, [R1] ; "stringWithFormat:"
__text:0000C988 ADD R3, PC ; "Mecreditbank.com"
__text:0000C98A STMEA.W SP, {R0,R5}
__text:0000C98E MOV R0, R4
__text:0000C990 BLX _objc_msgSend
__text:0000C994 MOV R2, R0
…
__text:0001AA70 LDR R4, [R2] ; _OBJC_CLASS_$_NSString
__text:0001AA72 BLX _objc_msgSend
__text:0001AA76 MOV R1, (selRef_stringWithFormat_ – 0x1AA8A) ; selRef_stringWithFormat_
__text:0001AA7E MOV R2, (cfstr_HttpAtmsOpList – 0x1AA8C) ; "https://%@/atms/?locale=%@&version=%u"
__text:0001AA86 ADD R1, PC; selRef_stringWithFormat_
__text:0001AA88 ADD R2, PC; "https://%@/atms/version=%u"
__text:0001AA8A loc_1AA8A ; CODE XREF: -[BranchesViewController processingVersion:]+146j
__text:0001AA8A MOVW R3, #0x218C
__text:0001AA8E LDR R1, [R1]
__text:0001AA90 MOVT.W R3, #8
__text:0001AA94 STMEA.W SP, {R0,R5}
__text:0001AA98 ADD R3, PC ; "Mecreditbank.com"
__text:0001AA9A MOV R0, R4
__text:0001AA9C BLX _objc_msgSend除此之外,20% 的程序以 HTTP 明文傳送帳戶啟用碼。即使這個功能僅在設定初始帳戶時用到,風險依然很高:攻擊者只要攔截到流量,就能劫持工作階段並盜取帳戶資訊,而且事後完全不留痕跡、無從偵測。
深入檢視各個應用的系統後,我發現有些應用使用未加密的 SQLite 資料庫存放銀行帳戶詳情、交易歷史等敏感資料。攻擊者可透過應用漏洞遠端取得這些資料;若能實體接觸裝置,則可安裝越獄套件直接從檔案系統中把資料搬走。
下例展示如何從 App 的檔案系統中取出未加密的 SQLite 帳戶資料庫。

其他鏡像資訊洩露情形,包括:
內部 IP 位址
__data:0008B590 _TakeMeToLocationURL DCD cfstr_Http10_1_4_133
; DATA XREF: -[NavigationView viewDidLoad]+80o
; __nl_symbol_ptr:_TakeMeToLocationURL_ptr
; "https://100.10.1.13:8080/WebTestProject/PingTest.jsp"內部系統路徑
_cstring:000CC724 aUsersXXXXPro DCB "/Users/Scott/projects/HM_iphone/src/HBMonthView.m",0
單看每一項似乎無傷大雅,但若攻擊者收集到大量這類線索,就能拼湊出應用的內部結構與伺服器端基礎設施,進而對客戶端與後端發動更具針對性的攻擊。
從防守方角度,以下做法能明顯降低風險:
1、確保所有連線都採用安全傳輸協議;
2、在客戶端應用中啟用 SSL 憑證檢查;
3、使用 iOS 資料保護 API 加密儲存在本地的敏感資訊;
4、偵測裝置是否已越獄;
5、導入組語混淆與反除錯技巧,提高逆向難度;
6、移除所有除錯語句與符號檔;
7、清除應用中殘留的開發資訊。
如今智慧型手機與平板也能安裝個人網銀應用,這對全球金融機構而言是又一道難題。行動網銀的安全性,確實到了該正視的時候。
參考文獻
[1] https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/otool.1.html
[2] https://portswigger.net/burp/editions.html
[3] https://www.owasp.org/index.php/Man-in-the-middle_attack
[4] https://www.hex-rays.com/products/ida/
[5] https://www.appaddict.org/forum/index.php?/topic/40-how-to-crack-ios-apps/
[6] https://github.com/zynamics/objc-helper-plugin-ida
[7] https://support.apple.com/downloads/#iphone%20configuration%20utility