-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port MASTG-TEST-0022: Testing Custom Certificate Stores and Certificate Pinning (android) (by @guardsquare) #3035
base: master
Are you sure you want to change the base?
Changes from all commits
def3645
3ecfd1c
93bf241
1aa688c
8526097
06b395f
2adab0f
b7a3b0e
a20152f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: Missing Certificate Pinning in Network Security Configuration | ||
platform: android | ||
id: MASTG-TEST-0240 | ||
type: [static] | ||
weakness: MASWE-0047 | ||
--- | ||
|
||
## Overview | ||
|
||
Apps can configure certificate pinning using the [Network Security Configuration]("../../../Document/0x05g-Testing-Network-Communication.md#certificate-pinning"). For each domain, one or multiple digests can be pinned. | ||
|
||
The goal of this test is to check if any certificate pinning exists. | ||
|
||
!!! note "Limitations" | ||
Since there are many different ways to achieve certificate pinning in the code, checking statically if the application performs pinning might not reveal all such locations. To make sure certificates are pinned for all relevant connections, additional dynamic analysis can be performed. | ||
|
||
## Steps | ||
|
||
1. Reverse engineer the app (@MASTG-TECH-0017). | ||
2. Inspect the AndroidManifest.xml, and check if a `networkSecurityConfig` is set in the `<application>` tag. | ||
3. Inspect the referenced network security config file, and extract all domains which have a pinned certificate. | ||
|
||
## Observation | ||
|
||
The output should contain a list of domains which enable certificate pinning. | ||
|
||
## Evaluation | ||
|
||
The test case fails if no `networkSecurityConfig` is set, or any relevant domain does not enable certificate pinning. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: Expired Certificate Pins in the Network Security Configuration | ||
platform: android | ||
id: MASTG-TEST-0241 | ||
type: [static] | ||
weakness: MASWE-0047 | ||
--- | ||
|
||
## Overview | ||
|
||
Apps can configure expiration dates for pinned certificates in the [Network Security Configuration (NSC)]("../../../Document/0x05g-Testing-Network-Communication.md#certificate-pinning") by using the `expiration` attribute. When a pin expires, the app no longer enforces certificate pinning and instead relies on its configured trust anchors. This means the connection will still succeed if the server presents a valid certificate from a trusted CA (such as a system CA or a custom CA defined in the app's configuration). However, if no trusted certificate is available, the connection will fail. | ||
|
||
If developers assume pinning is still in effect but don't realize it has expired, the app may start trusting CAs it was never intended to. | ||
|
||
> Example: A financial app previously pinned to its own private CA but, after expiration, starts trusting publicly trusted CAs, increasing the risk of compromise if a CA is breached. | ||
|
||
The goal of this test is to check if any expiration date is in the past. | ||
titze marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Steps | ||
|
||
1. Reverse engineer the app (@MASTG-TECH-0017). | ||
2. Inspect the AndroidManifest.xml, and check if a `networkSecurityConfig` is set in the `<application>` tag. If yes, inspect the referenced file, and extract the expiration dates for every domain. | ||
|
||
## Observation | ||
|
||
The output should contain a list of expiration dates for pinned certificates. | ||
|
||
## Evaluation | ||
|
||
The test case fails if any expiration date is in the past. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||
--- | ||||||
title: Missing Certificate Pinning in Network Traffic | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a second dynamic test that uses Frida e.g. via objection or other scripts that try to bypass pinning in order to detect it. There are caveats of course as the original test indicates but it's useful. See https://mas.owasp.org/MASTG/techniques/android/MASTG-TECH-0012/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cpholguera not sure I understand what you mean. The link you mention explains how to deactivate pinning using Frida etc. How would that help identifying if pinning is done / done correctly? What could be (somewhat) helpful, is to try the Frida scripts to see where it attaches, to then statically analyse those locations (relating to the to-be-created test for #3183). Am I missing something? |
||||||
platform: network | ||||||
id: MASTG-TEST-0242 | ||||||
type: [network] | ||||||
weakness: MASWE-0047 | ||||||
--- | ||||||
|
||||||
## Overview | ||||||
|
||||||
There are multiple ways an application can implement certificate pinning, including via the Android Network Security Config, custom TrustManager implementations, third-party libraries, and native code. Since some implementations might be difficult to identify through static analysis, especially when obfuscation or dynamic code loading is involved, this test uses network interception techniques to determine if certificate pinning is enforced at runtime. | ||||||
|
||||||
The goal of this test case is to observe whether a [MITM attack]("../../../Document/0x04f-Testing-Network-Communication.md#mitm-attack) can intercept HTTPS traffic from the app. A successful MITM interception indicates that the app is either not using certificate pinning or implementing it incorrectly. | ||||||
|
||||||
If the app is properly implementing certificate pinning, the MITM attack should fail because the app rejects certificates issued by an unauthorized CA, even if the CA is trusted by the system. | ||||||
|
||||||
## Steps | ||||||
|
||||||
1. Set up an intercepting proxy, for example @MASTG-TOOL-0077 or @MASTG-TOOL-0097. | ||||||
2. Install the application on a device connected to that proxy, and intercept the communication. | ||||||
3. Extract all domains which were intercepted. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And monitor logcat for clues while doing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cpholguera which clues do you have in mind? |
||||||
|
||||||
## Observation | ||||||
|
||||||
The output should contain a list of domains for which the interception was successful. | ||||||
|
||||||
## Evaluation | ||||||
|
||||||
The test case fails if any relevant domain was intercepted. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about...?
Suggested change
We could add a new prerequisite and link to it here. As in https://github.com/OWASP/owasp-mastg/blob/master/prerequisites/identify-security-relevant-contexts.md For example (REVIEW, AI generated): Identifying Security-Sensitive Relevant DomainsWhat is a Security-Sensitive Relevant Domain?A relevant domain is any endpoint where failing to enforce certificate pinning could expose sensitive data or compromise security. This typically includes:
What is NOT a Security-Sensitive Relevant Domain?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cpholguera I agree this would benefit a lot from a definition. Maybe sth to discuss in our next meeting, I don't think this is easy to define. Imo, security-sensitive depends a lot on the app context, but also on the test / weakness itself. I could imagine certificate pinning being mandatory for L2 for specific domains, but it certainly shouldn't be mandatory for all domains for L1. In the AI generated text, the 3rd party or analytics service is already not ideal imo. Whilst I agree with this for certificate pinning, I don't think analytics services are by default not security sensitive. E.g., thinking about GDPR, I can imagine personal identifiers being sent there, which need to be handled with care and are security sensitive... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this "feature" as well as the support for
android:usesCleartextTraffic="true"
in the manifest was reverted in Flutter 2.2: https://docs.flutter.dev/release/breaking-changes#reverted-change-in-2-2According to this comment it's still kind of there: flutter/flutter#106678 (comment) but I'm not sure what's going on.
It looks like the way to do pinning in Flutter is via
securityContext.setTrustedCertificatesBytes
orsecurityContext.setTrustedCertificates
See https://api.flutter.dev/flutter/dart-io/SecurityContext/setTrustedCertificatesBytes.html