Cryptographic (In)Security in Android Apps an Empirical Analysis
Total Page:16
File Type:pdf, Size:1020Kb
Radboud University Nijmegen TRU/e Security Faculty Of Science Radboud University, Nijmegen, Netherlands Cryptographic (In)Security in Android Apps An Empirical Analysis Master Thesis in Cyber Security Supervisor: Author: Dr. Veelasha Moonsamy Milad Masoodi Second reader: Dr. Fabian van den Broek July 20, 2020 As our circle of knowledge expands, so does the circumference of darkness surrounding it. |Albert Einstein I Acknowledgements No work of immense effort has ever been accomplished by the trials of one man alone, as such is this humble attempt. While I have performed this work through great dedication and effort relative to my situation, I could never achieve a final result of such adequacy without the help of many adept and selfless scientists, instructors, and friends that aided me in every step of the way. Atop all is Dr. Moonsamy; her excellent guidance and insight in critical moments on intricate details shaped this work. Along with the staff of the cybersecurity group of Radboud University, exceptional scientists that opened the gates of this fantastic field for me, and not to forget the invisible staff of the department, those who clean, maintain, and keep the environment operational so we could learn. It behooves me to thank Dr. Manuel Egele for CryptoLint, the incredible software that helped me design mine, my wonderful uncle, friend, and mentor Kamal Mohajerani who provided help, support, guidance, and elucidated every consultation with care and patience which considerably affected the format of this research, and my very good friend Sina Afshar for proofreading and commenting on my thesis. Last but not least, my mother, Dr. Sue Mohajerani, whose grand sacrifice made all of this ever possible. II Abstract For so long Android developers have relied on third-party documentation for their cryp- tographic needs; this, however, has changed in recent years with the gradual introduction of Android's documentation. Nevertheless, the accuracy of the documentation and their effect on the cryptographic security of Android apps in the wild has not been well-studied so far. This thesis aimed to shed light on these topics with several approaches; we defined a set of rules that we perceive to represent cryptographic security, then we thoroughly scrutinized the documentation around those rules, after that we designed and executed series of automated tests to analyze 6900 real apps to grasp an understanding of the current state of their security. Eventually, we concluded that Android documentation not only fails to contribute to the cryptographic security of the apps, but it also has an adverse effect on the matter as with more time, number of insecure apps in the circulations have gradually increased. III Contents List of Figures VIII List of TablesIX List of ListingsX 1 Introduction1 1.1 Objectives...................................2 1.2 Procedure...................................3 1.3 Structure...................................3 2 Android Preliminaries4 2.1 Android OS..................................4 2.1.1 Android Version History.......................4 2.1.2 Backward Compatibility.......................5 2.1.3 OS Security..............................5 2.2 APK......................................7 2.2.1 Extracting Information From Android Apps............8 2.2.2 SMALI................................ 10 2.3 Android Security Guidelines......................... 10 3 Cryptographic Preliminaries 12 3.1 IND-CPA Security.............................. 12 3.1.1 Definition of IND-CPA........................ 12 3.1.2 IND-CPA for Android Security................... 13 3.2 Cryptographic Rules............................. 14 3.2.1 Rule 1: Avoid Use of ECB Mode of Encryption.......... 14 3.2.2 Rule 2: Avoid Incorrect Implementation of IV........... 15 3.2.3 Rule 3: Avoid the Use of Constant Encryption Key........ 17 3.2.4 Rule 4: Avoid Use of Constant Salts for PBE........... 18 3.2.5 Rule 5: Avoid Use of Fewer Than 1; 000 Iteration for PBE.... 19 3.2.6 Rule 6: Avoid Use of Static Seed in SecureRandom(.)...... 19 3.2.7 Rule 7: Avoid Use of Insecure Hash Algorithms.......... 20 4 Related Work 21 5 Investigation into Android Documentation 23 5.1 Improper Modes of Operation (Rule 1)................... 23 5.2 Improper IV Usage (Rule 2)......................... 24 5.3 Constant Secret Key (Rule 3)........................ 24 5.4 Constant Salt in PBE (Rule 4)....................... 24 5.5 Low Iteration PBE (Rule 5)......................... 25 IV 5.6 Bad Random Seed (Rule 6)......................... 25 5.7 Outdated Hash Algorithms (Rule 7).................... 26 6 Experimentation 28 6.1 Experiment Structure............................ 28 6.2 Dataset Acquisition............................. 28 6.3 Pre-Processing................................ 29 6.4 Decompilation................................ 30 6.5 Rules Analysis................................ 30 6.5.1 Rule 1................................. 31 6.5.2 Rule 2................................. 32 6.5.3 Rule 3................................. 32 6.5.4 Rule 4................................. 33 6.5.5 Rule 5................................. 33 6.5.6 Rule 6................................. 33 6.5.7 Rule 7................................. 34 6.6 Metadata Extraction............................. 34 6.7 Post-Processing................................ 35 7 Results and Findings 36 7.1 Evolutionary Analysis............................ 36 7.1.1 Rule 1................................. 37 7.1.2 Rule 2................................. 37 7.1.3 Rule 3................................. 38 7.1.4 Rule 4................................. 39 7.1.5 Rule 5................................. 40 7.1.6 Rule 6................................. 41 7.1.7 Rule 7................................. 42 7.2 Contemporary State Analysis........................ 42 7.3 Findings.................................... 44 8 Discussion 47 9 Limitations 49 10 Future Work 50 11 Conclusion 52 Bibliography 53 Appendices 59 A Experimentation Output 60 A.1 Contemporary Analysis........................... 60 A.2 Evolutionary Analysis............................ 61 V List of Abbreviations AES Advanced Encryption Standard API Application Programming Interface APK Android Package File ART Android Runtime CBC Cipher Block Channing CFG Control Flow Graph CG Call Graph CHF Cryptographic Hash Function CIL Common Intermediate Language CMA Cryptographic Misuse Analyzer CSV Comma Separated Values CTR Counter Mode DEX Dalvic Executable ECB Electronic Code Book GCM Galois/Counter Mode GUI Graphic User Interface HKDF Hash based Key Derivation Function ID Identifier IND-CCA Indistinguishability under Chosen Ciphertext Attacks IND-CPA Indistinguishability under Chosen Plaintext Attacks IPC Inter-Process Communication IV Initialization Vector JCA Java Cryptography Architecture JCP Java Cryptographic Provider KDF Key Derivation Functions MAC Message Authentication Code VI NIST National Institute of Standards and Technology OS Operating System PBE Password-Based Encryption PRNG Pseudo Random Number Generator RegEx Regular Expressions RNG Random Number Generator SDK Software Development Kit SHA1PRNG Secure Hash Algorithm 1 Random Number Generator TRNG True Random Number Generator VM Virtual Machine VII List of Figures 2.1 Android app reverse engineering overview.................8 2.2 Class file vs. DEX file structure.......................9 3.1 Structure of ECB encryption blocks.................... 15 3.2 Structure of CBC encryption blockscipher................. 16 3.3 Structure of GCM encryption blockscipher................. 17 3.4 Effect of salt in PBE............................. 18 3.5 Example of execution a hash algorithm................... 20 6.1 Experimentation steps............................ 29 7.1 Usage trends of Rule 1............................ 38 7.2 Usage trends of Rule 2............................ 38 7.3 Usage trends of Rule 2............................ 39 7.4 Comparison between Rule 1 and Rule 2.................. 39 7.5 Usage trends of Rule 3............................ 40 7.6 Usage trends of Rule 4............................ 40 7.7 Usage trends of Rule 5............................ 41 7.8 Misuses of Rules 4 and 5........................... 41 7.9 Usage trends of Rule 6............................ 42 7.10 Usage trends of Rule 7............................ 43 7.11 State of contemporary apps......................... 43 7.12 Comparison of misuses of all rules..................... 44 7.13 Correct and incorrect implementation to total apps with cryptography. 46 VIII List of Tables 2.1 Android version history...........................5 5.1 List of supported hash algorithms and their relative security....... 27 6.1 ECB misuse detection parameters...................... 31 6.2 IV misuse detection arguments....................... 32 6.3 Constant key misuse detection parameters................. 32 6.4 Salt misuse detection parameters...................... 33 6.5 Iteration count misuse detection parameters................ 33 6.6 Seed misuse detection parameters...................... 34 6.7 Hash misuse detection arguments...................... 34 6.8 Misuse analysis verdicts........................... 34 7.1 Cryptography in apps (2014-2020)..................... 37 7.2 API level of apps............................... 37 A.1 Contemporary analysis numbers...................... 60 A.2 Evolutionary analysis numbers....................... 61 IX List of Listings 6.1 Call to Androzoo............................... 29 6.2 Decompilation command with APKtool.................. 30 6.3