简体   繁体   English

如何在 Android 应用程序中保护 AWS 凭证?

[英]How to secure AWS Credentials in Android app?

How do I secure my AWS credentials in my app?如何在我的应用程序中保护我的 AWS 凭证? What's the ideal place to store AWS credentials and how can they be fetched at run-time?存储 AWS 凭证的理想位置是什么?如何在运行时获取它们?

See the warning below:请参阅以下警告:

Leaked AWS Credentials泄露的 AWS 凭证

Your app(s) expose Amazon Web Services credentials.您的应用程序公开 Amazon Web Services 凭证。

THIRD PARTY SERVICES第三方服务

How do I secure my AWS credentials in my app?如何在我的应用程序中保护我的 AWS 凭证?

Don't do it.不要这样做。 It will be always possible for an attacker to retrieve them with reverse engineer techniques, and a lot of open source tools exist to make this task trivial.攻击者总是有可能使用逆向工程技术检索它们,并且存在许多开源工具来使这项任务变得微不足道。

While the article I am about to share is for extracting an Api Key, the same approach can be used to extract any other secret as described in my article How to Extract an API key from a Mobile App with Static Binary Analysis :虽然我即将分享的文章是用于提取 Api 密钥,但可以使用相同的方法来提取任何其他秘密,如我的文章如何使用静态二进制分析从移动应用程序中提取 API 密钥中所述

The range of open source tools available for reverse engineering is huge, and we really can't scratch the surface of this topic in this article, but instead we will focus in using the Mobile Security Framework(MobSF) to demonstrate how to reverse engineer the APK of our mobile app.可用于逆向工程的开源工具范围非常广泛,我们在本文中确实无法触及该主题的表面,而是将重点放在使用移动安全框架 (MobSF)来演示如何逆向工程我们的移动应用程序的 APK。 MobSF is a collection of open source tools that present their results in an attractive dashboard, but the same tools used under the hood within MobSF and elsewhere can be used individually to achieve the same results. MobSF 是一个开源工具的集合,它们在一个有吸引力的仪表板中展示他们的结果,但是在 MobSF 和其他地方使用的相同工具可以单独使用来实现相同的结果。

As the article says you can make it harder by hiding the AWS credentials within native C code, with the use of the JNI/NDK technique:正如文章所说,您可以通过使用JNI/NDK技术在本机 C 代码中隐藏 AWS 凭证来增加难度:

Using Android Studio 2.2 and higher, you can use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle, the IDE's integrated build system.使用 Android Studio 2.2 及更高版本,您可以使用 NDK 将 C 和 C++ 代码编译到本机库中,并使用 IDE 的集成构建系统 Gradle 将其打包到您的 APK 中。 Your Java code can then call functions in your native library through the Java Native Interface (JNI) framework.然后,您的 Java 代码可以通过 Java 本机接口 (JNI) 框架调用本机库中的函数。

If you use this approach, the attacker will use an instrumentation framework during runtime to extract your AWS credentials, like Frida :如果您使用这种方法,攻击者将在运行时使用检测框架来提取您的 AWS 凭证,例如Frida

Inject your own scripts into black box processes.将您自己的脚本注入黑盒进程。 Hook any function, spy on crypto APIs or trace private application code, no source code needed.挂钩任何函数,监视加密 API 或跟踪私有应用程序代码,无需源代码。 Edit, hit save, and instantly see the results.编辑,点击保存,并立即查看结果。 All without compilation steps or program restarts.无需编译步骤或程序重新启动。

POSSIBLE SOLUTION可能的解决方案

You should delegate to your backend or reverse proxy the responsibility to talk with AWS, like I suggest in my article Using a Reverse Proxy to Protect Third Party APIs :您应该将与 AWS 对话的责任委托给您的后端或反向代理,就像我在使用反向代理保护第三方 API 的文章中建议的那样:

In this article you will start by learning what Third Party APIs are, and why you shouldn't access them directly from within your mobile app.在本文中,您将首先了解什么是第三方 API,以及为什么不应该直接从您的移动应用程序中访问它们。 Next you will learn what a Reverse Proxy is, followed by when and why you should use it to protect the access to the Third Party APIs used in your mobile app.接下来,您将了解什么是反向代理,然后了解何时以及为何应使用它来保护对移动应用程序中使用的第三方 API 的访问。

DO YOU WANT TO GO THE EXTRA MILE?你想走得更远吗?

In any response to a security question I always like to reference the excellent work from the OWASP foundation.在对安全问题的任何回答中,我总是喜欢参考 OWASP 基金会的出色工作。

For APIS用于APIS

OWASP API Security Top 10 OWASP API 安全前 10 名

The OWASP API Security Project seeks to provide value to software developers and security assessors by underscoring the potential risks in insecure APIs, and illustrating how these risks may be mitigated. OWASP API 安全项目旨在通过强调不安全 API 中的潜在风险并说明如何减轻这些风险来为软件开发人员和安全评估人员提供价值。 In order to facilitate this goal, the OWASP API Security Project will create and maintain a Top 10 API Security Risks document, as well as a documentation portal for best practices when creating or assessing APIs.为了实现这一目标,OWASP API 安全项目将创建和维护一个前 10 个 API 安全风险文档,以及创建或评估 API 时最佳实践的文档门户。

For Mobile Apps对于移动应用程序

OWASP Mobile Security Project - Top 10 risks OWASP 移动安全项目 - 十大风险

The OWASP Mobile Security Project is a centralized resource intended to give developers and security teams the resources they need to build and maintain secure mobile applications. OWASP 移动安全项目是一个集中资源,旨在为开发人员和安全团队提供构建和维护安全移动应用程序所需的资源。 Through the project, our goal is to classify mobile security risks and provide developmental controls to reduce their impact or likelihood of exploitation.通过该项目,我们的目标是对移动安全风险进行分类并提供开发控制以减少其影响或被利用的可能性。

OWASP - Mobile Security Testing Guide : OWASP - 移动安全测试指南

The Mobile Security Testing Guide (MSTG) is a comprehensive manual for mobile app security development, testing and reverse engineering.移动安全测试指南 (MSTG) 是移动应用安全开发、测试和逆向工程的综合手册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM