在过去几年执行多次红队演练期间,我曾多次遇到 Canary Token,这些令牌可能会让安全运营中心(SOC)察觉到所采取的行动。因此,我花了一些时间深入探索,试图找出是否有办法检测环境内文件中存在的这些 canary。Canary Hunter 的诞生就是为了快速检查在 canarytokens.org 上免费生成的各类常见 Canary。
Canary token 是一种免费、快速、无痛的方式,帮助防御者发现他们已被入侵(通过让攻击者自我暴露)。有关 Canary token 的更多信息以及如何免费生成它们,可以查看 https://blog.thinkst.com/p/canarytokensorg-quick-free-detection.html
目前该脚本可以检测以下格式中的 canary:
PS C:\> Import-Module .\CanaryHunter.psd1
将 docx 复制为 zip,然后解析 xml 内容,使用正则匹配 Canary Token 域名。
PS C:\> Invoke-DocxCheck -DocxPath gwfrr71nre84bk5gobf3h96ms.docx
Url Found:
http://canarytokens.com/feedback/traffic/gwfrr71nre84bk5gobf3h96ms/index.html
将 xlsx 复制为 zip,然后解析 xml.rels 内容,使用正则匹配 Canary Token 域名。
PS C:\> Invoke-XlsxCheck -XlsxPath .\gwfrr71nre84bk5gobf3h96ms.xlsx
Url Found:
http://canarytokens.com/images/tags/articles/gwfrr71nre84bk5gobf3h96ms/contact.php
对指定的 .pdf 执行 PDFStreamDumper,然后解析 .unk 流文件中关键字 Canary。
PS C:\> Invoke-PDFCheck -StreamDumperPath C:\PDFStreamDumper\PDFStreamDumper.exe -PDFPath .\gwfrr71nre84bk5gobf3h96ms.pdf
Url Found:
http://gwfrr71nre84bk5gobf3h96ms.canarytokens.net/RNGPLTCJSTEKJHOMLLYCQINNXOVOWCUVME
默认检查 "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit" 中是否存在使用静默退出监控的进程,然后对 Monitor Process 属性运行正则匹配。
PS C:\> Invoke-RegistryCheck
Sensitive Command Canary Found For:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\net.exe
Monitor Process Canary Value Found:
cmd.exe /c start /min powershell.exe -windowstyle hidden -command "$($u=$(\"u$env:username\"
-replace('[^\x00-\x7f]|\s', ''))[0..63] -join '';$c=$(\"c$env:computername\" -replace('[^\x00-\x7f]|\s', ''));
Resolve-DnsName -Name \"$c.UN.$u.CMD.gwfrr71nre84bk5gobf3h96ms.canarytokens.com\")"
根据 Bobby Lin 的博客,扫描可能属于免费 Canary token 服务 AWS 账户的 AWS 访问密钥。
PS C:\> Invoke-AWSCheck -AWSPath .\AWS.config
Possible Canary Config Found:
AWS.config:2:aws_access_key_id = AKIAYVP4CIPPJUYTRES
扫描 WireGuard 配置中已知的 Canary Token IP 地址。
PS C:\> Invoke-WireguardCheck -WireGuardPath .\WireguardConfig
Possible Canary Config Found:
Endpoint = 52.18.63.80
扫描 Kube 配置中已知的 Canary Token IP 地址。
PS C:\> Invoke-KubeCheck -KubeConfigPath .\KubeConfig
Possible Canary Config Found:
server: https://52.18.63.80:6443
扫描 MySQL 转储中的 SET @b=,然后运行正则匹配以确定 MASTER HOST 是否包含已知的 Canary Token IP 地址。
PS C:\> Invoke-MySqlDumpCheck -MySQLDumpPath .\gwfrr71nre84bk5gobf3h96ms_mysql_dump.sql
Url Found:
MASTER_HOST='gwfrr71nre84bk5gobf3h96ms.canarytokens.com'
阻止已知的 Canary IP
PS C:\> Invoke-BlockCanaries
DisplayName : Block All Known Canary IP Addresses
Enabled : True
Profile : Any
Direction : Outbound
Action : Block
Firewall Rule to Block Canary IP Addresses Succesffully Created