aws cloudtrail跟踪记录并修复网站

运行以下命令以下载 CloudTrail 日志
aws s3 cp s3://<monitoring####>/ . --recursive
运行此命令以提取日志
gunzip *.gz
分析日志的结构
cat <filename.json> | python -m json.tool
ip=<WebServerIP>
只打印包含 sourceIPAddress 标签的 JSON 行
for i in $(ls); do echo $i && cat $i | python -m json.tool | grep sourceIPAddress ; done
返回每个已捕获事件的 eventName
for i in $(ls); do echo $i && cat $i | python -m json.tool | grep eventName ; done
运行此命令可查找对 AWS 账户中的安全组执行的任何操作
aws cloudtrail lookup-events --lookup-attributes AttributeKey=ResourceType,AttributeValue=AWS::EC2::SecurityGroup --output text
运行以下命令来查找 Cafe Web Server 实例使用的安全组 ID,然后将结果回显到终端
region=$(curl http://169.254.169.254/latest/dynamic/instance-identity/document|grep region | cut -d '"' -f4)
sgId=$(aws ec2 describe-instances --filters "Name=tag:Name,Values='Cafe Web Server'" --query 'Reservations[*].Instances[*].SecurityGroups[*].[GroupId]' --region $region --output text)
echo $sgId
命令返回的安全组 ID 来进一步筛选 AWS CLI cloudtrail 命令结果
aws cloudtrail lookup-events --lookup-attributes AttributeKey=ResourceType,AttributeValue=AWS::EC2::SecurityGroup --region $region --output text | grep $sgId
然后运行一个简单查询来了解日志中可用的数据。
运行一个新查询,该查询只选择前面提到的那些列。这一次,将结果限制为 30 行:
SELECT useridentity.userName, eventtime, eventsource, eventname, requestparameters
FROM cloudtrail_logs_monitoring####
LIMIT 30
返回过去一天在账户中处于活动状态的所有用户的列表,以及他们所采取的不同操作
SELECT DISTINCT useridentity.userName, eventName, eventSource FROM cloudtrail_logs_monitoring#### WHERE from_iso8601_timestamp(eventtime) > date_add('day', -1, now()) ORDER BY eventSource;
运行以下命令以查看谁最近登录了该操作系统:
sudo aureport --auth
删除 chaos-user 操作系统用户
sudo userdel -r chaos-user
停止具有活动 chaos-user 登录会话的进程(将 ProcNum 替换为上一个命令返回的进程编号)
sudo kill -9 ProcNum
验证没有其他能够登录的可疑操作系统用户
sudo cat /etc/passwd | grep -v nologin
分析实例上的 SSH 设置
sudo ls -l /etc/ssh/sshd_config
重新启动 SSH 服务
sudo service sshd restart
返回到连接至 Cafe Web Server 实例的终端窗口,导航到保存网站图像文件的目录并查看内容
cd /var/www/html/mompopcafe/images/
ls -l
还原网站上的原始图形
sudo mv Coffee-and-Pastries.backup Coffee-and-Pastries.png
运行下面的命令以删除登录配置文件
aws iam delete-login-profile --user-name=chaos

将文件保留在 S3 存储桶中,但仍删除堆栈
aws cloudformation delete-stack --stack-name myStack --retain-resources MyBucket
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值