前言
最近做项目遇见的各个平台的Key泄露的比较多,正好总结一下关于API接口利用的内容分享一下。
0X01 微信公众号泄露AppID+AppSecert利用
前期通过打点获取到的数据库,互联网连接mysql发现了多个公众号AppID和AppSecert。

这里查询微信公众号的接口权限

默认的接口权限未认证用户都是很基础的。
利用微信公众号接口调试工具
测试下载文件接口

测试上传文件接口

AccessToken泄露
在某些路径泄露的时候可能会直接获取到外带的AccessToken,虽然AccessToken的时效性最长不超过两个小时,一般失效型都在一个多小时,利用泄露的AccessToken可直接调用
利用难度
0X02 小程序Appid+AppSecert泄露
小程序接口Web.rar泄露的文件中发现了三个小程序的Appid+AppSecert

利用API接口获取设备型号

调用接口获取用户id

0X03 高德地图ApiKey利用
JS文件信息泄露了高德的ApiKey

python脚本实现调用APIKey查询周边兴趣点
# -*- coding: utf-8 -*-
import requests
import json
def search_poi(api_key, keyword, city="全国"):
url = f"https://restapi.amap.com/v3/place/text?key={api_key}&keywords={keyword}&city={city}"
response = requests.get(url)
result = response.json()
if result['status'] == '1':
pois = result['pois']
for poi in pois:
name = poi['name']
location = poi['location']
print(f"Name: {name}, Location: {location}")
else:
print("POI Search failed:", result['info'])
def search_place(api_key, keywords, city='北京'):
base_url = 'https://restapi.amap.com/v3/place/text'
params = {
'key': api_key,
'keywords': keywords,
'city': city,
'output': 'json'
}
response = requests.get(base_url, params=params)
data = response.json()
return data
def search_route(api_key, origin, destination, city='北京', mode='driving'):
base_url = 'https://restapi.amap.com/v3/direction/' + mode
params = {
'key': api_key,
'origin': origin,
'destination': destination,
'city': city,
'output': 'json'
}
response = requests.get(base_url, params=params)
data = response.json()
return data
def search_geocode(api_key, address, city='北京'):
base_url = 'https://restapi.amap.com/v3/geocode/geo'
params = {
'key': api_key,
'address': address,
'city': city,
'output': 'json'
}
response = requests.get(base_url, params=params)
data = response.json()
return data
if __name__ == "__main__":
api_key = input("请输入你的高德Web服务API Key: ")
address1 = input("请输入你的起始地址: ")
address2 = input("请输入你的目的地址: ")
data1 = search_geocode(api_key, address1)
geocodes1 = data1.get('geocodes', [])
location1 = 'N/A'
for geocode in geocodes1:
location1 = geocode.get('location', 'N/A')
print(f"起始地址: {address1}, 经纬度: {location1}")
data2 = search_geocode(api_key, address2)
geocodes2 = data2.get('geocodes', [])
location2 = 'N/A'
for geocode in geocodes2:
location2 = geocode.get('location', 'N/A')
print(f"目的地址: {address2}, 经纬度: {location2}")
data = search_route(api_key, location1, location2)
route = data.get('route', {})
path = route.get('paths', [{}])[0]
distance = path.get('distance', 'N/A')
duration = path.get('duration', 'N/A')
print(f"距离: {distance}, 预计时长: {duration}")
# 示例:POI搜索
keyword = input("请输入关键词进行POI搜索:")
search_poi(api_key, keyword)
路径规划、POI搜索

查询经纬度
import requests
def get_geocode(api_key, address, city='北京'):
base_url = 'https://restapi.amap.com/v3/geocode/geo'
params = {
'key': api_key,
'address': address,
'city': city,
'output': 'json'
}
response = requests.get(base_url, params=params)
data = response.json()
return data
if __name__ == "__main__":
api_key = input("请输入你的高德Web服务API Key: ")
while True:
address = input("请输入你想要查询经纬度的地址(输入exit退出): ")
if address.lower() == "exit":
break
data = get_geocode(api_key, address)
geocodes = data.get('geocodes', [])
if geocodes:
for geocode in geocodes:
location = geocode.get('location', 'N/A')
print(f"地址: {address}, 经纬度: {location}")
else:
print("未找到该地址,请重新输入。")
地址编码

关于高德ApiKey的泄露风险,普通用户的高德额度调用量是有限制的,当key泄露之后,可以高频次调用,导致产生大量的额外费用。

可以根据高德的付费要求,单接口的流量包都是费用如下,提供的接口越多,费用随之升高,泄露的风险就是可能造成资源浪费。

利用难度
- 无白名单机制限制,利用难度低
- 危害程度除资源消耗无其它影响。
0x04 百度地图Apikey利用
这里直接测试的地址检索
# -*- coding: utf-8 -*-
import requests
def place_search(query, region, api_key):
url = f"http://api.map.baidu.com/place/v2/search?query={query}®ion={region}&output=json&ak={api_key}"
response = requests.get(url)
try:
response.raise_for_status() # 检查请求是否成功
data = response.json()
if data["status"] == 0:
results = data["results"]
for idx, result in enumerate(results, start=1):
print(f"{idx}. {result['name']}: {result['address']}")
else:
print("地点检索失败:", data["message"])
except requests.exceptions.RequestException as e:
print("请求错误:", e)
def main():
query = input("请输入要搜索的地点关键词:")
region = input("请输入搜索的区域(如城市名称):")
api_key = input("请输入百度地图开放平台的 API Key:")
place_search(query, region, api_key)
if __name__ == "__main__":
main()
检索关键字

0x05 OSS存储桶AK/SK泄露
接上一次的红队,信息搜集的时候发现这家关联单位的存储桶泄露的AK/SK。
入口:web系统弱口令,发现配置文件脱敏

继续搜集应用功能发现泄露了Git的账号密码

git登录拉取文件

找到AK和SK

除了带锁的无法访问,存储桶内数据共计800G+

小结
公众号的测试+小程序的api调用认证用户的高级接口和存储桶的利用危害是最直观的,地图的API泄露一般只会产生经济效益。