This project is a set of tools that allow researchers to experiment with certificate chain validation issues, mostly centered around the idea of a web service validating a Google SafetyNet payload.
This does not demonstrate any vulnerability with SafetyNet itself, but rather a harmful design pattern that developers may accidentally implement following common advice regarding certificate chain validation.
Some scripts require dependencies which can be installed by a pip install -r requirements.txt.
In mitm-tools/jwsmodify.py, you will find a set of high-level tools for modifying JWS payloads in flight by running their payloads through a mutation function, generating a new self-signed CA certificate and a leaf certificate issued by that CA, and re-bundling the JWS to contain a forged signature, the mutated payload, and the rogue CA and leaf certificates.
jwsmodify uses mitm-tools/rogue_ca.py, a small set of helper tools to create self-signed CA certificates and associated leaf certificates.
In mitm-tools/jwsmodify_mitmproxy_addon.py, there is a mitmproxy addon that will intercept SafetyNet attestations sent to web services. You can run mitmproxy with the script enabled like so:
mitmproxy -s mitm-tools/jwsmodify_mitmproxy_addon.py
This Flask application exposes an endpoint, /safetynet/validate, which expects a POST request with a jws parameter containing a SafetyNet JWS. The certificate chain validation algorithm incorrectly trusts intermediate certificates as though they were trusted roots.
As part of our research, we assembled a list of popular Android apps and downloaded them programmatically from Apkpure and apkmonk. In order to do the same, you need to follow the following steps:
-
Make a copy of
safetynet-analysis/config.template.tomland rename itconfig.toml -
Add the name of the S3 bucket that you'll use to store APKs and your AWS credentials
-
To get the list of Android apps run
python scrape_android_rank.pya) This will generate a CSV file
app_ids.csv. -
To download the apps run
python get_apks.pya) This will use
app_ids.csvwill attempt to download APKs first from Apkpure and then from apkmonkb) The results will be stored in a SQLite database named
chain-of-fools.db. Specifically, they will be in theapk_downloadstable. -
Upload the downloaded apks to the S3 bucket detailed in
config.toml -
To analyze the apks, you will need to run
python check_for_safetynet.py.a) The results will be stored in the
apk_detailtable.
This project is not intended as a living project, but bug requests may be accepted via PR.
See LICENSE.md
Issues should be filed using GitHub issues.