Permiso-io-tools/RansomWhen
GitHub: Permiso-io-tools/RansomWhen
用于枚举 AWS 中具备 S3+KMS 勒索能力的身份并检测 CloudTrail 中相关恶意事件的云安全工具。
Stars: 61 | Forks: 4
# RansomWhen

**相关博客**: [RansomWhen??? I never even notice it…](https://permiso.io/blog/ransomwhen-i-did-not-even-notice-it)\
**研究博客**: [Encrypting buckets for compliance and ransom - How Attackers Can Use KMS to Ransomware S3 Buckets](https://blog.pepperclipp.com/pepperclipp-public/encrypting-buckets-for-compliance-and-ransom-how-attackers-can-use-kms-to-ransomware-s3-buckets)
RansomWhen 是一个工具,用于枚举可以使用 KMS 锁定 S3 Buckets 的身份(从而导致勒索软件攻击),以及检测使用 KMS 进行的 S3 勒索软件事件。
```
-----------------------------------------------------------------------------------------------------------------------------------------------------
,,,,,,
;?S######S*:
%S@@@@@@@@S?
,SS@@@@@@@@S%
;S*SS@@@@@@@@S%?%:
,#@?%##########?%@S
*@@%?SSSSSSSSSS*S@@;
,#@@S%;:,,::,,:+SS@@S
,%@?: , ,, ;%@?,
:##*, ;, ,*@S,
,S@:,, :S, ,,;@%
;@? ?#:,,,,,,,,, %@?*:
+@*: ;##**+;;::,,;?@S#;
;@% ,, S@+;,
%@;,, ,,*@?
,%@?, ,%@?,
?@S+,: ,:,+S@+
,#@@#S*;::;;::+*S#@@%
+@@%*SSSSSSSSSS+S@@;
,S@?%##########?%@%
:?+SS@@@@@@@@S%*?,
SS@@@@@@@@S%
%S@@@@@@@@S?
:+%SSSSSS%+:
.______ ___ .__ __. _______. ______ .___ ___. ____ __ ____ __ __ _______ .__ __. ______ ______ ______
| _ \ / \ | \ | | / | / __ \ | \/ | \ \ / \ / / | | | | | ____|| \ | | | \ | \ | \
| |_) | / ^ \ | \| | | (----`| | | | | \ / | \ \/ \/ / | |__| | | |__ | \| | `----) | `----) | `----) |
| / / /_\ \ | . ` | \ \ | | | | | |\/| | \ / | __ | | __| | . ` | / / / / / /
| |\ \----. / _____ \ | |\ | .----) | | `--' | | | | | \ /\ / | | | | | |____ | |\ | |__| |__| |__|
|__| `._____|/__/ \__\ |__| \__| |_______/ \______/ |__| |__| \__/ \__/ |__| |__| |_______||__| \__| __ __ __
(__) (__) (__)
-----------------------------------------------------------------------------------------------------------------------------------------------------
by Permiso Security
-----------------------------------------------------------------------------------------------------------------------------------------------------
```
## 安装说明
### 本地安装
要安装,只需安装所需的库即可。
```
python3 -m venv ./venv
source venv/bin/activate
python3 -m pip install -r requirements.txt
```
然后,通过运行 **ransomwhen.py** 来运行该工具:
```
usage: ransomwhen.py [-h] {IDENTITIES,EVENTS} ...
RansomWhen???
positional arguments:
{IDENTITIES,EVENTS} Select the check on the account (the choices are IDENTITIES, EVENTS)
IDENTITIES IDENTITIES specific arguments
EVENTS EVENTS specific arguments
options:
-h, --help show this help message and exit
```
### Docker
项目主目录中放置了一个 Dockerfile。要构建镜像,请在项目主目录内运行:
```
docker build -t ransomwhen .
```
然后运行容器,并将 **~/.aws** 目录挂载到主机:
```
usage: ransomwhen.py [-h] {IDENTITIES,EVENTS} ...
RansomWhen???
positional arguments:
{IDENTITIES,EVENTS} Select the check on the account (the choices are IDENTITIES, EVENTS)
IDENTITIES IDENTITIES specific arguments
EVENTS EVENTS specific arguments
options:
-h, --help show this help message and exit
```
该工具有 2 个嵌套的 Argument Parsers:IDENTITIES 和 EVENTS。IDENTITIES 将列出具有任何勒索软件场景权限的所有身份,而 EVENTS 将列出每个身份与勒索软件相关的恶意事件。
## **枚举身份**
为了枚举身份,该工具将使用路径 `scenarios/scenarios.json` 上的 JSON Blob,其中包含不同攻击所需的权限。该 JSON 可以使用以下格式进行配置。每个场景都有一个名称和要检查的事件列表。
```
{
"Create Locked Key and Encrypt Bucket using CopyObject": [
"kms:CreateKey",
"s3:PutBucketEncryptionConfiguration",
"s3:CopyObject"
]
}
```
每个场景将被列为:
- **allowed**,当场景中的所有事件都被允许时
- **partially**,当场景中至少有 1 个事件被允许时
- **denied**,当场景中没有事件被允许时

```
Attach Custom KMS Key Store
Create Locked Key and Encrypt Bucket using CopyObject
Create Locked Key and Encrypt Bucket using Get/Put Object
Create Role, Add Inline Policy and Delete
Create Role, Attach Inline Policy and Delete
Create User, Add Inline Policy and Delete
Create User, Attach Inline Policy and Delete
Delete CloudTrail Trail
Stop Logging
Stop Logging using KMS
Update Current Custom KMS Key Store
Update Key Policy to Lock Key and Encrypt Bucket using CopyObject
Update Key Policy to Lock Key and Encrypt Bucket using Get/Put Object
```
## **查找恶意事件**
至于查找具有恶意事件的身份,该工具将查看 JSON Blob `scenarios/events.json`。该文件也可以进行配置,格式如下,其中每个事件的信息设置为 null 或值,就像应该保存在 CloudTrail Logs 中一样。
```
{
"CreateKey": {
"UserAgent": null,
"Identity": null,
"RequestParameters": null,
"ResponseElements": null,
"ErrorCode": null,
"ErrorMessage": null,
"EventSource": "kms.amazonaws.com"
}
}
```
下面的事件是将要在 CloudTrail 上检查的事件。如前所述,可以配置每个事件以检查特定的指标。
```
kms:CreateKey
kms:PutKeyPolicy
kms:ReEncrypt
kms:CreateCustomKeyStore
kms:UpdateCustomKeyStore
kms:ConnectCustomKeyStore
kms:DisconnectCustomKeyStore
kms:DeleteCustomKeyStore
s3:PutBucketEncryptionConfiguration
s3:CopyObject
s3:PutObject
s3:GetObject
iam:CreateUser
iam:DeleteUser
iam:CreateRole
iam:DeleteRole
iam:AttachUserPolicy
iam:PutUserPolicy
iam:AttachRolePolicy
iam:PutRolePolicy
cloudtrail:StopLogging
cloudtrail:DeleteTrail
cloudtrail:UpdateTrail
```
然后,运行该工具,将列出所有身份(IAM Users 和 Roles)及其在过去 90 天内运行的事件。

# 输出
输出将被转储到 **output** 目录中。每个 AWS Account 都有自己的目录,每个身份的 CSV 文件将保存在那里:
```
ls output/ -R
output/:
012345678912
output/012345678912:
adminUser-predefined-scenarios.csv adminUser-events.csv
```
### 测试
该工具将测试 **./scenarios/scenarios.json** 中提供的攻击:
```
cat ./scenarios/scenarios.json
[
"Create Locked Key and Encrypt Bucket using CopyObject": [
"kms:CreateKey",
"s3:PutBucketEncryptionConfiguration",
"s3:CopyObject"
],
...
]
```
每个攻击都有一个名称和一个权限列表。可以在 JSON 中添加新场景或修改现有场景,它们将由工具自动执行。
恶意事件存储在 ./scenarios/events.json 中,每个事件都有其过滤选项:
```
[
"CreateKey": {
"UserAgent": null,
"Identity": null,
"RequestParameters": null,
"ResponseElements": null,
"ErrorCode": null,
"ErrorMessage": null,
"EventSource": "kms.amazonaws.com"
}
...
]
```
标签:AMSI绕过, AWS, DPI, IAM, KMS, ProjectDiscovery, RansomWhen, S3, S3 Ransomware, 云存储安全, 勒索软件, 威胁检测, 密钥管理服务, 数据保护, 数据加密, 权限枚举, 网络扫描, 请求拦截, 身份与访问管理, 逆向工具