ToB企服应用市场:ToB评测及商务社交产业平台

标题: 甲方安全建立之日志采集实操干货 [打印本页]

作者: 千千梦丶琪    时间: 2024-5-16 14:50
标题: 甲方安全建立之日志采集实操干货
前言

没有永远的安全,如安在被攻击的情况下,快速响应和快速溯源分析攻击动作是个重要的话题。想要分析攻击者做了什么、怎么攻击进来的、还攻击了谁,那么日志是必不可少的一项,因此我们必要尽大概采集多的日志来进行分析攻击者的动作,甚至在攻击者刚落脚的时候就阻断攻击者。
安装Elastic+Kibana

Docker安装

这边根据官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html 使用Docker安装了Elastic和Kibana
  1. # 安装es
  2. docker network create elastic
  3. docker pull docker.elastic.co/elasticsearch/elasticsearch:8.12.1
  4. docker run --name es01 --net elastic -p 9200:9200 -it -m 1GB docker.elastic.co/elasticsearch/elasticsearch:8.12.1
  5. # 记录es的密码和注册kibana所需要的token
  6. # 测试es是否正确运行
  7. export ELASTIC_PASSWORD="es_your_password"
  8. docker cp es01:/usr/share/elasticsearch/config/certs/http_ca.crt .
  9. curl --cacert http_ca.crt -u elastic:$ELASTIC_PASSWORD https://localhost:9200
  10. # 安装kibana
  11. docker pull docker.elastic.co/kibana/kibana:8.12.1
  12. docker run --name kib01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.12.1
  13. 会给出kibana的注册地址,访问填入上述记录的token即可。
复制代码
不知道是机器性能问题照旧Docker安装的问题,es容器经常会挂掉。
RPM安装

根据https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.htmlhttps://www.elastic.co/guide/en/kibana/current/rpm.html官方文档,可以yum install安装。由于公司访问镜像源被封,因此使用上述文档中下载rpm安装:
  1. # 安装es
  2. wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.12.1-x86_64.rpm
  3. wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.12.1-x86_64.rpm.sha512
  4. shasum -a 512 -c elasticsearch-8.12.1-x86_64.rpm.sha512
  5. sudo rpm --install elasticsearch-8.12.1-x86_64.rpm
  6. 安装kibana
  7. wget https://artifacts.elastic.co/downloads/kibana/kibana-8.12.1-x86_64.rpm
  8. wget https://artifacts.elastic.co/downloads/kibana/kibana-8.12.1-x86_64.rpm.sha512
  9. shasum -a 512 -c kibana-8.12.1-x86_64.rpm.sha512
  10. sudo rpm --install kibana-8.12.1-x86_64.rpm
复制代码
依然在安装es的rpm时,会吐出es/kibana的密码:
  1. The generated password for the elastic built-in superuser is : Fq*S7jxCjFfPu6nN8NG8
复制代码
es服务大概启动不了,但是安装时会给出启动命令:
  1. sudo systemctl daemon-reload
  2. sudo systemctl enable elasticsearch.service
复制代码
测试es启动是否正常:
  1. export ELASTIC_PASSWORD="Fq*S7jxCjFfPu6nN8NG8"
  2. curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:$ELASTIC_PASSWORD https://localhost:9200
复制代码
记得改下配置文件,使其监听在0.0.0.0上面:
  1. # /etc/elasticsearch/elasticsearch.yml
  2. # Allow HTTP API connections from anywhere
  3. # Connections are encrypted and require user authentication
  4. http.host: 0.0.0.0
  5. # Allow other nodes to join the cluster from anywhere
  6. # Connections are encrypted and mutually authenticated
  7. transport.host: 0.0.0.0
复制代码
kibana一样,记得改下配置文件,使其监听在0.0.0.0上面:
  1. # /etc/kibana/kibana.yml
  2. server.host: "0.0.0.0"
复制代码
安装Fleet和Elastic Agent

在Kibana上,Management->Fleet->Add Fleet Server,先安装Fleet Server,URL填写https协议,端口可以填默认的8220。装好Fleet Server后再装Elastic Agent,Fleet Server也是一个Agent,因此不能在同一台机器上同时装Fleet Server和Elastic Agent。
[img=720,373.4439834024896]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202404071311824.jpg[/img]

为了使其Elastic Agent附带Security能力,可以添加各式各样的integrations集成,如到Security->Manage->Get started->Add security integrations安装安全集成:
[img=720,348.984]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202404071311826.png[/img]

[img=720,477.4736842105263]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202404071311827.png[/img]

测试告警

留意,如果有如下错误需解决,否则会无法查阅规则:
[img=720,337.78367617783675]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202404071311828.png[/img]

[img=720,374.1694462975317]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202404071311829.png[/img]

【----帮助网安学习,以下全部学习资料免费领!加vx:dctintin,备注 “博客园” 获取!】
 ① 网安学习成长路径思维导图
 ② 60+网安经典常用工具包
 ③ 100+SRC毛病分析陈诉
 ④ 150+网安攻防实战技术电子书
 ⑤ 最权威CISSP 认证测验指南+题库
 ⑥ 超1800页CTF实战技巧手册
 ⑦ 最新网安大厂面试题合集(含答案)
 ⑧ APP客户端安全检测指南(安卓+IOS)
有些规则没开,记得开下,比如我把reverse shell规则打开后:Security->Dashboards->Detection & Response可以看到一些概览:
[img=720,325.7963089542037]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202404071311830.png[/img]

记载Windows事件管理器日志

安装

Windows事件管理器日志不是单纯的文本,因此必要借助一些工具来帮助我们完成采集的目的。这里使用winlogbeat(https://www.elastic.co/cn/beats/winlogbeat)完成。官方提供了很详细的安装文档(https://www.elastic.co/guide/en/beats/winlogbeat/current/winlogbeat-installation-configuration.html),核心就是配置想要记载的日志类型和对外传输的方案,这里我使用的方案为:
配置好winlogbeat.yml后可以进行测试配置文件对不对:
  1. .\winlogbeat.exe test config -c .\winlogbeat.yml -e
复制代码
下面为我的配置文件信息:
  1. ###################### Winlogbeat Configuration Example ########################
  2. # This file is an example configuration file highlighting only the most common
  3. # options. The winlogbeat.reference.yml file from the same directory contains
  4. # all the supported options with more comments. You can use it as a reference.
  5. #
  6. # You can find the full configuration reference here:
  7. # https://www.elastic.co/guide/en/beats/winlogbeat/index.html
  8. # ======================== Winlogbeat specific options =========================
  9. # event_logs specifies a list of event logs to monitor as well as any
  10. # accompanying options. The YAML data type of event_logs is a list of
  11. # dictionaries.
  12. #
  13. # The supported keys are name, id, xml_query, tags, fields, fields_under_root,
  14. # forwarded, ignore_older, level, event_id, provider, and include_xml.
  15. # The xml_query key requires an id and must not be used with the name,
  16. # ignore_older, level, event_id, or provider keys. Please visit the
  17. # documentation for the complete details of each option.
  18. # https://go.es.io/WinlogbeatConfig
  19. winlogbeat.event_logs:
  20.   - name: Application
  21.    ignore_older: 72h
  22.   - name: System
  23.   - name: Security
  24.   - name: Microsoft-Windows-Sysmon/Operational
  25.   - name: Windows PowerShell
  26.    event_id: 400, 403, 600, 800
  27.   - name: Microsoft-Windows-PowerShell/Operational
  28.    event_id: 4103, 4104, 4105, 4106
  29.   - name: ForwardedEvents
  30.    tags: [forwarded]
  31. # ====================== Elasticsearch template settings =======================
  32. setup.template.settings:
  33.   index.number_of_shards: 1
  34.   #index.codec: best_compression
  35.   #_source.enabled: false
  36. # ================================== General ===================================
  37. # The name of the shipper that publishes the network data. It can be used to group
  38. # all the transactions sent by a single shipper in the web interface.
  39. #name:
  40. # The tags of the shipper are included in their field with each
  41. # transaction published.
  42. #tags: ["service-X", "web-tier"]
  43. # Optional fields that you can specify to add additional information to the
  44. # output.
  45. #fields:
  46. #  env: staging
  47. # ================================= Dashboards =================================
  48. # These settings control loading the sample dashboards to the Kibana index. Loading
  49. # the dashboards is disabled by default and can be enabled either by setting the
  50. # options here or by using the `setup` command.
  51. #setup.dashboards.enabled: false
  52. # The URL from where to download the dashboard archive. By default, this URL
  53. # has a value that is computed based on the Beat name and version. For released
  54. # versions, this URL points to the dashboard archive on the artifacts.elastic.co
  55. # website.
  56. #setup.dashboards.url:
  57. # =================================== Kibana ===================================
  58. # Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
  59. # This requires a Kibana endpoint configuration.
  60. setup.kibana:
  61.   # Kibana Host
  62.   # Scheme and port can be left out and will be set to the default (http and 5601)
  63.   # In case you specify and additional path, the scheme is required: http://localhost:5601/path
  64.   # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
  65.   #host: "localhost:5601"
  66.   # Kibana Space ID
  67.   # ID of the Kibana Space into which the dashboards should be loaded. By default,
  68.   # the Default Space will be used.
  69.   #space.id:
  70. # =============================== Elastic Cloud ================================
  71. # These settings simplify using Winlogbeat with the Elastic Cloud (https://cloud.elastic.co/).
  72. # The cloud.id setting overwrites the `output.elasticsearch.hosts` and
  73. # `setup.kibana.host` options.
  74. # You can find the `cloud.id` in the Elastic Cloud web UI.
  75. #cloud.id:
  76. # The cloud.auth setting overwrites the `output.elasticsearch.username` and
  77. # `output.elasticsearch.password` settings. The format is `<user>:<pass>`.
  78. #cloud.auth:
  79. # ================================== Outputs ===================================
  80. # Configure what output to use when sending the data collected by the beat.
  81. # ---------------------------- Elasticsearch Output ----------------------------
  82. output.elasticsearch:
  83.   # Array of hosts to connect to.
  84.   hosts: ["your_ip:9200"]
  85.   # Protocol - either `http` (default) or `https`.
  86.   #protocol: "https"
  87.   # Authentication credentials - either API key or username/password.
  88.   #api_key: "id:api_key"
  89.   username: "elastic"
  90.   password: "passwords"
  91.   # Pipeline to route events to security, sysmon, or powershell pipelines.
  92.   pipeline: "winlogbeat-%{[agent.version]}-routing"
  93. # ------------------------------ Logstash Output -------------------------------
  94. #output.logstash:
  95.   # The Logstash hosts
  96.   #hosts: ["localhost:5044"]
  97.   # Optional SSL. By default is off.
  98.   # List of root certificates for HTTPS server verifications
  99.   #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
  100.   # Certificate for SSL client authentication
  101.   #ssl.certificate: "/etc/pki/client/cert.pem"
  102.   # Client Certificate Key
  103.   #ssl.key: "/etc/pki/client/cert.key"
  104. # ================================= Processors =================================
  105. processors:
  106.   - add_host_metadata:
  107.      when.not.contains.tags: forwarded
  108.   - add_cloud_metadata: ~
  109. # ================================== Logging ===================================
  110. # Sets log level. The default log level is info.
  111. # Available log levels are: error, warning, info, debug
  112. #logging.level: debug
  113. # At debug level, you can selectively enable logging only for some components.
  114. # To enable all selectors, use ["*"]. Examples of other selectors are "beat",
  115. # "publisher", "service".
  116. #logging.selectors: ["*"]
  117. # ============================= X-Pack Monitoring ==============================
  118. # Winlogbeat can export internal metrics to a central Elasticsearch monitoring
  119. # cluster.  This requires xpack monitoring to be enabled in Elasticsearch.  The
  120. # reporting is disabled by default.
  121. # Set to true to enable the monitoring reporter.
  122. #monitoring.enabled: false
  123. # Sets the UUID of the Elasticsearch cluster under which monitoring data for this
  124. # Winlogbeat instance will appear in the Stack Monitoring UI. If output.elasticsearch
  125. # is enabled, the UUID is derived from the Elasticsearch cluster referenced by output.elasticsearch.
  126. #monitoring.cluster_uuid:
  127. # Uncomment to send the metrics to Elasticsearch. Most settings from the
  128. # Elasticsearch outputs are accepted here as well.
  129. # Note that the settings should point to your Elasticsearch *monitoring* cluster.
  130. # Any setting that is not set is automatically inherited from the Elasticsearch
  131. # output configuration, so if you have the Elasticsearch output configured such
  132. # that it is pointing to your Elasticsearch monitoring cluster, you can simply
  133. # uncomment the following line.
  134. #monitoring.elasticsearch:
  135. # ============================== Instrumentation ===============================
  136. # Instrumentation support for the winlogbeat.
  137. #instrumentation:
  138.    # Set to true to enable instrumentation of winlogbeat.
  139.    #enabled: false
  140.    # Environment in which winlogbeat is running on (eg: staging, production, etc.)
  141.    #environment: ""
  142.    # APM Server hosts to report instrumentation results to.
  143.    #hosts:
  144.    #  - http://localhost:8200
  145.    # API Key for the APM Server(s).
  146.    # If api_key is set then secret_token will be ignored.
  147.    #api_key:
  148.    # Secret token for the APM Server(s).
  149.    #secret_token:
  150. # ================================= Migration ==================================
  151. # This allows to enable 6.7 migration aliases
  152. #migration.6_to_7.enabled: true
复制代码
数据检索

这时候,大概elastic上面搜不到数据,是由于winlogbeat使用了他自己的索引,默认为winlogbeat-version,笔者测试时,发现kibana上迟迟出现不了该索引,还以为数据传输没成功呢,因此通过如动手段进行排查,先获取es上面的索引信息:
  1. http://your_ip:9200/_cat/indices?v
复制代码
发现有类似winlogbeat的索引信息:
  1. yellow open   .ds-winlogbeat-8.12.0-2024.02.03-000001   UpWhWCpdR-2WgMVe_kiH9A   1   1     192705            0    131.1mb        131.1mb
复制代码
后面尝试在kibana上创建一个新的索引即可,v7.17.12版本的kibana创建索引的过程如下:discover->选项->View Discover settings
[img=720,277.0705725699068]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202404071410669.jpg[/img]

找到“索引模式”创建一个新的索引即可:
[img=720,282.4258064516129]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202404071410670.jpg[/img]

[img=720,179.86813186813185]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202404071410671.png[/img]

这时候就可以检索事件管理器日志了:
[img=720,371.90619362597715]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202404071410672.png[/img]

更多网安技能的在线实练习习,请点击这里>>
  
  

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4