# Table of contents - [Update](#update) - [Docker](#docker) - [Cài honeypot](#cài-honeypot) - [Prometheus](#prometheus) - [Grafana](#grafana) ## Update ``` sudo apt update sudo apt upgrade -y ``` ## Docker - Cài đặt một số gói cho phép sử dụng HTTPS. ``` sudo apt install apt-transport-https ca-certificates curl software-properties-common -y ``` - Thêm khóa GPG của kho lưu trữ Docker. ``` curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg ``` - Thêm kho lưu trữ Docker của Ubuntu vào các apt sources. ``` echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ``` - Cập nhật packages và thiết lập để cài đặt Docker từ kho lưu trữ chính thức. ``` sudo apt update ``` ``` sudo apt-cache policy docker-ce ``` - Cài đặt Docker ``` sudo apt install docker-ce -y ``` - Kiểm tra trạng thái của Docker ``` sudo systemctl status docker ``` - Xem các thông tin về Docker ``` docker info ``` ## Cài honeypot - Tải source ``` git clone https://github.com/mariocandela/beelzebub.git ``` ``` cd beelzebub ``` - Cấu hình API openAi + Mở file ``` vim configurations/services/ssh-2222.yaml ``` + Ở dòng cuối thêm Key vào "openAPIChatGPTSecretKey" Key của mình là "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" - Build ``` docker-compose build ``` - Start ``` docker-compose up -d ``` - Check log ``` docker logs --follow beelzebub ``` ## Prometheus - Tạo user và group prometheus ``` sudo groupadd --system prometheus sudo useradd -s /sbin/nologin --system -g prometheus prometheus ``` - Tạo thư mục lưu prometheus ``` sudo mkdir /var/lib/prometheus ``` - Prometheus primary configuration files directory is /etc/prometheus/. It will have some sub-directories: ``` for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done ``` - Cập nhật hệ thống ``` sudo apt update ``` - Cài đặt các tool cần thiết ``` sudo apt -y install wget curl vim ``` - Tạo thư mục temp để lưu file cài promethus ``` mkdir -p /tmp/prometheus && cd /tmp/prometheus ``` - Tải file cài đặt ``` curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi - ``` - Giải nén file ``` tar xvf prometheus*.tar.gz cd prometheus*/ ``` - Move file tới thư mục của hệ thống ``` sudo mv prometheus promtool /usr/local/bin/ ``` - Move config file prometheus tới thư mục của hệ thống ``` sudo mv prometheus.yml /etc/prometheus/prometheus.yml ``` - Move các file thư viện ``` sudo mv consoles/ console_libraries/ /etc/prometheus/ cd $HOME ``` - Tạo và sửa file config chính Prometheus + Mở file ``` sudo vim /etc/prometheus/prometheus.yml ``` + Thêm dòng sau ``` # my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9090'] ``` - Tạo file service cho Prometheus + Tạo file ``` sudo nano /etc/systemd/system/prometheus.service ``` + Thêm các dòng sau ``` [Unit] Description=Prometheus Documentation=https://prometheus.io/docs/introduction/overview/ Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/bin/prometheus \ --config.file /etc/prometheus/prometheus.yml \ --storage.tsdb.path /var/lib/prometheus/ \ --web.console.templates=/etc/prometheus/consoles \ --web.console.libraries=/etc/prometheus/console_libraries [Install] WantedBy=multi-user.target ``` - Cấu hình quyền cho các thư mục của Prometheus ``` for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done sudo chown -R prometheus:prometheus /var/lib/prometheus/ ``` - Reload systemd daemon và chạy Prometheus ``` sudo systemctl daemon-reload sudo systemctl start prometheus sudo systemctl enable prometheus ``` - Check status ``` systemctl status prometheus ``` - Prometheus Dashboard : https://Địa chỉ IP VPS:9090 ## Grafana - Cài đặt các tool cần thiết ``` sudo apt-get install -y apt-transport-https sudo apt-get install -y software-properties-common wget sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key ``` - Thêm link repository của Grafana vào Ubuntu ``` echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list ``` - Cập nhật hệ thống ``` sudo apt-get update ``` - Cài đặt Grafana ``` sudo apt-get install grafana ``` - Grafana Web: https://Địa chỉ IP VPS:3000 user và pass mặc định là admin:admin ## Process log ### Grafana graph - Kết nối metrics data từ Honeypot vào Prometheus - Sửa file config Prometheus + Mở file ``` sudo vim /etc/prometheus/prometheus.yml ``` + Trong phần `scrape_configs` thêm job honeypot ``` - job_name: "honeypot" static_configs: - targets: ["localhost:2112"] ``` - Restart Prometheus để áp dụng cấu hình ``` sudo systemctl restart prometheus ```