**
?? The importance of security for some applications involving direct money transactions or personal privacy is self-evident. Android system because of its open-source properties, the market for open source code customization of the ROM is uneven, at the system level of security and vulnerability are different, Android app market for the app is relatively broad audit of iOS, for many vulnerabilities to provide an opportunity. Some of the mainstream apps on the market have done some security, but because most apps don't involve money security, they don't pay enough attention to security, and because security is the discipline of portal systems, most developers of app layers lack the accumulation of security technology, and the measures are relatively limited.
?? This article will focus on the security issues, precautions, and implementation of a range of security technology solutions that Android apps face.
**
Security issues facing the virus
Android virus is the mobile Trojan, mainly some malicious applications. For example, last year, CCTV exposure of a "bank violent criminals" mobile phone banking Trojan, imitating the real mobile banking software, through the fishing method to obtain the user entered the mobile phone number, ID card number, bank account, password and other information, and upload this information to the hacker designated server. After stealing the bank account password, immediately transfer the funds in the user's account. Mobile Trojan has a separate existence, and some are disguised as pictures of the way attached to the original app, hidden very strong, some viruses will also appear variants, and a generation more powerful than the generation.
These viruses have some common characteristics:
- The running mechanism of the parent packet + the malicious child package.
- By technical means to prevent users from the normal way to unload.
- For the purpose of stealing funds from user accounts.
- Use SMS as the instruction channel.
Critical Information Disclosure
While Java code is generally confusing, several of Android's major components are created in a way that relies on injection, so it cannot be confused, and some of the current anti-compilation tools such as Apktool can effortlessly restore plaintext in Java. The library information in native can also be obtained through Objdump or Ida. So once there is plain-text sensitive information in Java or native code, basically there is no security.
App re-packaging
That is, decompile and re-add the malicious code logic, the new package an APK file. The purpose of repackaging is generally mentioned above and virus combination, the original apk to unpack, insert a malicious virus after repackaging and release, so camouflage is very strong. Stop the app repackaging to some extent to prevent the virus from spreading.
Process is hijacked
This is almost the most targeted type of attack, generally through the process of injection or debugging process to hook process, change the logic and order of the program run, get the memory information of the program running, that is, the user all the behavior is monitored, this is the most common way to steal account password.
当然 hook行为不一定完全是恶意的,比如有些安全软件会利用hook的功能做主动防御(比如 LBE和我们移动安全实验室最新的apkprotect线上加固产品)。一般来说,hook需要获取root权限或者跟被hook进程相同的权限,因此如果你的手机没有被root,而且是正版apk的话,被注入还是很困难的。
Data is hijacked during transmission
The most common hijacking of the transmission process is the man-in-the-middle attack. Many security-demanding applications require that all business requests are over HTTPS, but there is a growing number of man-in-the-middle attacks on HTTPS, and we find that in real-world use, certificate Exchange and authentication have some problems on some cottage phone or non-mainstream ROMs, which can hinder the use of HTTPS.
Keyboard input Security implications
Payment password is usually entered through the keyboard, the security of the keyboard input directly affects the security of the password. The security implications of the keyboard come from three areas:
- Using the third-party input method, all the click events in the technology can be intercepted by the three-party input method, if you accidentally use some illegal input method, or input method to upload the information collected and leaked, the consequences are unimaginable.
- Screenshot, this method requires the phone has root permission to run the screenshot software
- GetEvent, by reading the information in the system driver layer Dev/input/event1, get the mobile phone touch screen position coordinates, in conjunction with the keyboard layout, can calculate the event and the specific number of mapping relationship, which is now more commonly used attack mode.
?? Previously done a set of security keyboard solution is to customize the keyboard + digital layout randomization. But the randomization of the keyboard is very incompatible with the human nature of the operating habits. So then the random words were removed.
?? It is also necessary to state that there is a more secure way of trustzone now that the standards of globalplatform_trusted_user_inteface, that is to say, a set of standards for a secure interface in Trustzone, If the security keyboard pops up in the Trustzone, then the hacker can not get the password by any means, is the most secure way, but Trustzone relies on the device underlying implementation, if the device does not support Trustzone, Or Trustzone does not support globalplatform_trusted_user_inteface standards, we can do nothing. *
WebView Vulnerability
Due to the prevalence of hybrid app now, WebView in the use of the app is more and more, Android system webview There are some loopholes, resulting in JS power. The most famous is the legendary JS injection vulnerability and WebKit XSS vulnerability, which we will cover in detail in the following chapters.
Server not processing, infiltration attack
The most of this is anti-replay attacks and injection attacks, this is not within the scope of this discussion.
Android app security architecture familiar with HTTPS
In essence, HTTPS is a two-way authentication process, but because Android devices too much too messy, Android device certificate is not uniform, generally only the client to verify the server-side certificate, and the server side in the HTTPS layer is not to verify the client certificate, So the actual application scenario is a one-way authentication process.
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory443));
This is the use of Google API to verify HTTPS, mainly to check four aspects of the content:
- is the signature CA legal
- Whether the domain name matches
- is not a self-signed certificate
- Whether the certificate expires
If the root certificate used by the server is self-signed, or the signing authority is not in the list of trusted certificates for the device, the HTTPS connection using httpclient will fail. There are several ways to solve this problem:
-
The simplest way to do this is to httpclient do not turn on certificate checking and trust all certificates. This approach is relatively simple, but security is the same as HTTP, hackers can easily forge certificates for man-in-the-middle attacks, resulting in user transaction data and other sensitive information disclosure. Now most of the mobile browser in order to be compatible with the various certificates of the uneven website, is to take the way, but also some mainstream browser to non-root certificate, only check the host and validity period, if the failure, to the user prompt, still can continue to browse or interrupt the prompt to ensure the user experience while improving security.
-
Using the Google default certificate checking mechanism (X509trustmanager), the server certificate is added to the HttpClient list of trust certificates before initiating an HTTPS connection, which is relatively more complicated and prone to error. And each site's custom certificate is different, it is difficult to find a unified approach to all non-root certificates for certificate checking.
Pay Password Security
Payment password is only a representative of the data, it is actually representative of the client's some sensitive data, such as bank card number, cell phone number, password, CVV, expiration date and so on. In particular, it contrasts strong sensitive data such as passwords and CVV in order to improve application performance and prevent others from cracking.
We encrypt this data using RSA and AES two sets of encryption methods, such as:
?? First we will generate the X-bit random key, to encrypt the data with the random key to encrypt, and finally the secret key for BASE64 encoding, at this time the data is we want to upload to the server sensitive data, we all know that AES is a symmetric encryption algorithm, the service must know the secret key to decrypt.
?? But our secret key is a random, how does the server know, as shown, we have this random secret key RSA public key encryption, the encrypted data also carried out a bit Base64 encoding, and uploaded to the server, because the servers have RSA private key, So the server can get the AES encryption of the random secret key.
?? Since AES is encrypted every time by a random key, and there is no fixed key, AES encryption is secure, and because RSA is asymmetric, our so only stores RSA's public key, so it is also safe.
?? In short, the security of the data can be ensured as long as the server private key is not compromised.
Data whether the transmission or storage needs encryption, encryption algorithm is not robust will be easily cracked or simulated, too robust to the communication server can not hold high concurrency and high traffic, so the choice of encryption and decryption algorithm is also very important. We are here to explain our choice of cryptographic algorithms.
?? Why use RSA encryption? Because RSA is asymmetric encryption, the client only gets the public key, it can only be used for encryption, but can not be used to decrypt, so as to ensure the security of the data, because no private key is not able to decrypt.
为什么不都用RSA加密?既然RSA加密这样安全,为什么不都用RSA加密的,因为RSA加密也是有一些弊端: - RSA的加解密对性能开销很大,所以不建议大量使用,以增加服务端压力; - RSA对加密的数据长度有限制,具体长度是与RSA秘钥位数有关系,所以对于比较长的数据RSA没法加密。 不管RSA加密还是AES加密都进行了一下Base64编码,这个是需要注意的地方,因为RSA和AES加密出来的都是二进制流,在转化成字符串时候可能出现空格造成数据的截断,所以必须编码一下不要让它出现空格。
Application Hardening
应用加固包括病毒扫描模块,防注入,防调试,防篡改模块四个模块,目前行业内已经出现了很多的应用加入解决方案,入爱加密、梆梆加密、百度加密、360应用加固等等。
Virus Scanning Module
病毒扫描模块和目前市面大多的安全卫士类app一样,摒弃了传统的依赖本地病毒库的杀毒引擎,采用了百度手机卫士的云扫描杀毒引擎。云扫描杀毒引擎在云端有一个定期更新的病毒库,扫描主要是通过收集本地安装的 App的信息,通常是apk里包名、签名、so、dex等信息,上传到云端, 云端通过比较程序签名和病毒库中的签名判断是否为病毒,然后将扫描结果返回给本地。 现在有些病毒扫描还结合人工智能深度学习利用服务器端的病毒数据库进一步查询可疑程序。还有些扫描作了一些主动防御,通过监控敏感api进行防御,例如监控以下敏感操作:更改浏览器主页,注册开机启动的行为,应用程序的内存注入等。
Anti-debug Module
Debugging refers to the current app by other programs using a specific method (debugger, Ptrace, etc.) tracking hijack, the app after debugging all the behavior can be viewed and modified by other programs, you can associate with the usual through the GDB debugging program.
The anti-debug feature is two steps: first detect if the current app is being debugged. If the app is being debugged, returns the process name of the process where the debugger is located. If the app is not debugged, protecting the app is no longer debugged by another program.
There are two ways to protect your app from being debugged:
- One is that the debug option is switched off in the kernel, but as an app we can't change the kernel state.
- The other is a two-process implementation of anti-debugging.
We know that a process allows only one debugger, so while the process is up, it will fork
A daemon (daemon), and ptrace the protected app process, the daemon intercepts the debugger's entry and ensures that no other program can debug the current app. Once the daemon has been activated, it will persist until the current application exits.
If you force the daemon to close, the current app will also close. The signal processing should be noted here.
Anti-injection module
Injection refers to the current app process being inserted into a module that is not part of the current app by other programs using a specific method (Ptrace, Dlopen, and so on). Generally speaking, injection is not an end, only means, so the injected module generally has a special behavior, such as the collection of app privacy data, using hooks and other methods to hijack the normal operation of the app. Hook is one of the most important security risks.
In terms of technical means, the premise of injection is to be debugged. So if the current app is protected from being debugged, there is no risk of being injected in theory. However, if the anti-debug module is activated later, the app still has the possibility of being injected before activating. The anti-injection function is to detect which modules are being injected and hijacked (hooks) by the current app.
The hooks in the Android platform are divided into two main categories: Java hooks and so hooks. Where Java hooks are divided into static members
Hooks and function hooks can be used to determine if there is Java injection by examining the fields and method domains of VM Dex memory. So Hook
It is also a hook method for all Linux systems, divided into GOT hooks, Symbol hooks and Inline hooks. Inline
Hooks are typically injected through the assembly by means of the Symbol
Hook is generally used ld_preload way to add hooks to the function, these two injections are not very able to prevent, the main anti-got hook.
The author has been a few years ago through the got hook principle in the machine, without root authority, in the system implanted in the SU program, the system to force root. GOT
The principle of hook is simply that it is through cat
/proc/pid/maps gets the so loaded address of the app process, then analyzes the got table to get the offset address of each function in so, calculates the absolute address of the function entry, and then replaces the address function with the injection function. So the anti-native injection method is: through the app
Process space to see whether the loaded library is under/system or/data/data/app, and if not, there must be an injection.
Anti-Tamper Module
The traditional method of judging whether the app is pirated, the industry's usual practice is to collect a large number of genuine application information to do a white list, and then use the current app's package name, signature and other information to do matching. The accuracy of this method depends on the size of the whitelist library and requires network connectivity. The anti-tamper feature determines whether the app is repackaged, fast, and accurate, based on the re-packaged app and the Dex's arrangement features of the genuine app.
Android Security Programming
Some of the specific features of the Android grammar and design, there is also the risk of attack, usually our code before the official release of the security scan, the security scan is mainly the following points sweep:
- Security of log information
This is relatively simple, not allowed to print sensitive data, and before the release of the print log must be closed switch.
- Intent Information Disclosure
In order to start another application activity, we often use some implicit intent, if it contains some sensitive information, third-party app just register the same intent Filter, it is possible to intercept sensitive information, so send an implicit intent, You must specify the recipient and permissions.
Security for security components
Android includes four components: Activitie, Service, Content Provider, Broadband Receiver, each of which can be opened by means of an implicit intent outside, So as long as these components are not publicly disclosed must be in the manifest to indicate that exported is false, prohibit other programs to access our components, for the components to interact with the external, you should add the control of access rights, but also need to pass the data to be securely verified.
IPC NULL reference
This situation is mainly in the open-door components, because the open-door components can receive intent, usually contains some data, when we do not have the time to empty the data, the app will generally crash, the attacker may send the data is empty intent to attack.
WebView Vulnerability Attack JS Injection vulnerability
This issue was first dated back to the 2011 paper "Attacks on WebView in the Android System" http://www.cis.syr.edu/~wedu/Research/paper/ Webview_acsac2011.pdf, this article points out some of the risks that Addjavascriptinterface's approach poses, such as implementing a read-write file class in your app, Then using the Addjavascriptinterface interface to allow JS calls, it may lead to the attacker directly call this class implementation of read and write files operation. This approach is the most primitive risk and does not directly point to the use of the GetClass () method. Later in 2013, Baidu Security group also formally released the vulnerability of the high-risk work order: http://security.baidu.com/risk/findNewsDetail.do;jsessionid= b09405787822801d67251543b2b8c5cb.security_client-web01?id=336. This vulnerability is primarily called Java directly through the GetClass () method. Lang Runtime Interface Execution System command, so that any JS with the app the same operation permissions!
The solution is mainly two:
- For Android 4.2 and above, Google has fixed the vulnerability, requiring only native
Add @addjavainterface on interface.
- For previous versions of Android4.2, you need to rewrite addjavainterface to implement the mapping of JS calls and native calls yourself. This is also a classic design of Cordova, it is worth learning a bit.
WebView Fishing Holes
Fishing this thing has always been the most commonly used in security attacks, but also the most difficult to solve by technical means a kind of problem, and the means of fishing is also strange, to prevent fishing in addition to the user to improve security awareness, not click on the unknown link, the technical level can do the following two points:
- Check webview load destination URL for security risks such as phishing scams
- Close the scripting environment to WebView
WebView cross-Domain vulnerability
Mainly because JS XMLHttpRequest can read the local file, thus reading to the app data database directory webviewcookieschromium.db, this db is usually the place where the system stores cookies, Equivalent to read a cookie in disguise to open the permission, specifically can look at the dark cloud Link: dark cloud link
- For Android 4.1 and above systems, there is no such cross-domain vulnerability, no targeted modification.
- Setallowfileaccess (FALSE) for all versions, disables loading of pages from local HTML.
Other
-
Weak encryption:
?? Many Android apps have a simpler way of encrypting storage, just a simple md5 that can easily be cracked.
-
signature Check Direction:
?? Each apk will have a signature, only the developer has the signature, if someone else changed the code, it must be signed to run, but the signature of the modifier is inconsistent with the official signature, we stored in so the official application of the hashcode value of the signature, After the app is started, so will check if the signature is the official signature, if not, the application is closed directly, so the encryption function inside does not work.
/*
* @author Zhoushengtao (Zhou San)
* @since June 15, 2015 19:19:22
* @weixin stchou_zst
* @blog http://blog.csdn.net/yzzst
* @ Exchange Learning QQ Group: 341989536
* @ Private qq:445914891
/
Android Application Security Status and solutions (learning materials)