首页 > 其他分享 >aws waf logs日志分析步骤

aws waf logs日志分析步骤

时间:2024-09-03 20:38:40浏览次数:4  
标签:projection s3 waf region aws struct date string logs

1.waf设置

AWS WAF ----Web ACLs----选择地区和规则--->Logging and metrics

2.设置日志存放在s3中

Edit logging---S3 bucket----选择一个桶---save

 3.在s3另外一个桶中新建目录 waflogs

4.修改官方配置

官方配置:https://docs.aws.amazon.com/athena/latest/ug/create-waf-table-partition-projection.html

修改官方配置:

# 1.修改表名
# 2.末尾修改 s3配置
 'projection.region.values' = 'us-east-1,us-west-2,eu-central-1,eu-west-1', # 服务器区域,例如日本:ap-northeast-1
'projection.date.range' = '2024/09/01,NOW',  # 从什么时间开始搜索日志:9 月 1 号至今

LOCATION
  's3://amzn-s3-demo-bucket/AWSLogs/accountID/WAFLogs/region/DOC-EXAMPLE-WEBACL/'

 'storage.location.template' = 's3://amzn-s3-demo-bucket/AWSLogs/accountID/WAFLogs/${region}/DOC-EXAMPLE-WEBACL/${date}/')
# 修改mzn-s3-demo-bucket s3的桶名
# accountID 账号 id
# DOC-EXAMPLE-WEBACL  日志存放路径对应


CREATE EXTERNAL TABLE `waf_logs`(
  `timestamp` bigint,
  `formatversion` int,
  `webaclid` string,
  `terminatingruleid` string,
  `terminatingruletype` string,
  `action` string,
  `terminatingrulematchdetails` array <
                                    struct <
                                        conditiontype: string,
                                        sensitivitylevel: string,
                                        location: string,
                                        matcheddata: array < string >
                                          >
                                     >,
  `httpsourcename` string,
  `httpsourceid` string,
  `rulegrouplist` array <
                      struct <
                          rulegroupid: string,
                          terminatingrule: struct <
                                              ruleid: string,
                                              action: string,
                                              rulematchdetails: array <
                                                                   struct <
                                                                       conditiontype: string,
                                                                       sensitivitylevel: string,
                                                                       location: string,
                                                                       matcheddata: array < string >
                                                                          >
                                                                    >
                                                >,
                          nonterminatingmatchingrules: array <
                                                              struct <
                                                                  ruleid: string,
                                                                  action: string,
                                                                  overriddenaction: string,
                                                                  rulematchdetails: array <
                                                                                       struct <
                                                                                           conditiontype: string,
                                                                                           sensitivitylevel: string,
                                                                                           location: string,
                                                                                           matcheddata: array < string >
                                                                                              >
                                                                   >,
                                                                  challengeresponse: struct <
                                                                            responsecode: string,
                                                                            solvetimestamp: string
                                                                              >,
                                                                  captcharesponse: struct <
                                                                            responsecode: string,
                                                                            solvetimestamp: string
                                                                              >
                                                                    >
                                                             >,
                          excludedrules: string
                            >
                       >,
`ratebasedrulelist` array <
                         struct <
                             ratebasedruleid: string,
                             limitkey: string,
                             maxrateallowed: int
                               >
                          >,
  `nonterminatingmatchingrules` array <
                                    struct <
                                        ruleid: string,
                                        action: string,
                                        rulematchdetails: array <
                                                             struct <
                                                                 conditiontype: string,
                                                                 sensitivitylevel: string,
                                                                 location: string,
                                                                 matcheddata: array < string >
                                                                    >
                                                             >,
                                        challengeresponse: struct <
                                                            responsecode: string,
                                                            solvetimestamp: string
                                                             >,
                                        captcharesponse: struct <
                                                            responsecode: string,
                                                            solvetimestamp: string
                                                             >
                                          >
                                     >,
  `requestheadersinserted` array <
                                struct <
                                    name: string,
                                    value: string
                                      >
                                 >,
  `responsecodesent` string,
  `httprequest` struct <
                    clientip: string,
                    country: string,
                    headers: array <
                                struct <
                                    name: string,
                                    value: string
                                      >
                                 >,
                    uri: string,
                    args: string,
                    httpversion: string,
                    httpmethod: string,
                    requestid: string
                      >,
  `labels` array <
               struct <
                   name: string
                     >
                >,
  `captcharesponse` struct <
                        responsecode: string,
                        solvetimestamp: string,
                        failureReason: string
                          >,
  `challengeresponse` struct <
                        responsecode: string,
                        solvetimestamp: string,
                        failureReason: string
                        >,
  `ja3Fingerprint` string,
  `oversizefields` string,
  `requestbodysize` int,
  `requestbodysizeinspectedbywaf` int
)
PARTITIONED BY ( 
`region` string, 
`date` string) 
ROW FORMAT SERDE 
  'org.openx.data.jsonserde.JsonSerDe' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  's3://amzn-s3-demo-bucket/AWSLogs/accountID/WAFLogs/region/DOC-EXAMPLE-WEBACL/'
TBLPROPERTIES(
 'projection.enabled' = 'true',
 'projection.region.type' = 'enum',
 'projection.region.values' = 'us-east-1,us-west-2,eu-central-1,eu-west-1',
 'projection.date.type' = 'date',
 'projection.date.range' = '2024/09/01,NOW',
 'projection.date.format' = 'yyyy/MM/dd',
 'projection.date.interval' = '1',
 'projection.date.interval.unit' = 'DAYS',
 'storage.location.template' = 's3://amzn-s3-demo-bucket/AWSLogs/accountID/WAFLogs/${region}/DOC-EXAMPLE-WEBACL/${date}/')

5.查询日志

在 search里搜索 "Athena"------->点击“查询编辑器”-----》"编辑器":将上面的语句贴在上面,并点击“运行”,如果不是第一次用,就需要修改表名

点击右侧:+号,运行查询语句,例如查询某个 IP是否被拒

select * from waf_logs1  where httprequest.clientip = '192.168.1.1' and action ='BLOCK';

 

 

标签:projection,s3,waf,region,aws,struct,date,string,logs
From: https://www.cnblogs.com/yangmeichong/p/18395401

相关文章

  • aws vmware ova模板进系统设置
    Amazonlinux2023下载地址:https://cdn.amazonlinux.com/al2023/os-images/2023.5.20240819.0/vmware/官方参考:https://docs.aws.amazon.com/linux/al2023/ug/seed-iso.html在一台linux上设置一个ssh信任ssh-keygen-trsa得到id_rsaid_rsa.pubcd/root/&&mkdirs......
  • Logstash配置和部署
    logstash概诉:是一个数据采集、加工处理、以及传输的工具特点:所有类型的数据集中处理、不同模式和格式的数据的正常化、自定义日志格式的迅速扩展、为自定义数据源轻松添加插件软件使用前注意:logstash使用Java开发、logstash没有默认配置文件需要手动配置、*需要在/usr/share/logsta......
  • 停止在 AWS 中使用 SSH!原因如下!DevSecOps 视角
    我们要解决什么问题?欢迎来到雲闪世界。我见过多少次安全组从10.0.0.0/8或更糟的0.0.0.0/0开放端口22?太多次了!但为什么,为什么在有更好的替代方案的情况下,我们在2024年仍在使用SSH?作为一名安全专家,我经常被要求说服人们“一种更好的工作方式”。我经常失败。人们喜欢快......
  • WAF一般是怎么防御SQL注入的
    目录参数化查询在防止SQL注入中起到什么作用?为什么要限制数据库用户权限来预防SQL注入?WAF是如何检测SQL注入特征的?WAF防范SQL注入的主要策略包括:参数化查询和预编译语句:使用参数化查询或预编译语句可以确保用户输入不会被解释为SQL代码,从而避免了SQL注入攻击。输入验......
  • POLIR-Society-Organization-Lawsuits: (2020)粤0303民初16184号判决书
    (2020)粤0303民初16184号判决书深圳市罗湖区人民法院送达公告页:https://guanwang.szlhfy.gov.cn/news/14209.cshtml送达公告列表页(第162页):https://guanwang.szlhfy.gov.cn/sdgg/162/20240827_163138GMT+0800......
  • 使用AWS DMS迁移数据,大概核对数据是否相同
    #!/bin/bashecho"scriptstart...."Source='/data/dba/mysql8/bin/mysql-uadmin_dba-ppassword-hxxx'Target='/data/dba/mysql8/bin/mysql-uadmin_dba-ppassword-hxxxxx'#showdatabases过滤出数据库名echo$Sourcedbs=`$Source......
  • [1050] Website endpoints in AWS
    ref:WebsiteendpointsWebsiteendpointexamplesThefollowingexamplesshowhowyoucanaccessanAmazonS3bucketthatisconfiguredasastaticwebsite.Example—RequestinganobjectattherootlevelTorequestaspecificobjectthatisstored......
  • [1047] AWS S3 bucket owner granting cross-account bucket permissions
    ref:Bucketownergrantingcross-accountbucketpermissionsPreparingforthewalkthroughStep1:DotheAccountAtasksStep2:DotheAccountBtasksStep3:(Optional)TryexplicitdenyStep4:Cleanup......
  • [1046] Different permissions in the AWS S3 policy
    Thes3:GetObjectpermissioninanAWSS3policyallowsausertoretrieveobjects(files)fromanS3bucket.Thispermissioniscrucialforreadaccess,enablinguserstodownloadorviewthecontentsoftheobjectsstoredinthebucket123.Here’sanexam......
  • Nginx+Lua实现WAF应⽤防⽕墙
    Nginx+Lua实现WAF应⽤防⽕墙1.常⻅的恶意⾏为爬⾍⾏为和恶意抓取,资源盗取防护⼿段1.基础防盗链功能不让恶意⽤户能够轻易的爬取⽹站对外数据2.access_moudle->对后台,部分⽤户服务的数据提供IP防护解决⽅法192.168.1.170[[email protected]]#cat/soft/openre......