2025/01/23

本次ZAP弱掃出現二個Medium


其實上次就有 不過這次要求連Medium都要處理
看來二個都是CSP的問題
之前改過一次版面會亂
這次再處理看看吧
要修改 /etc/apache2/apache2.conf 
加上以這這段

<IfModule mod_headers.c>

        Header set Content-Security-Policy "\
        default-src 'self';\
        img-src 'self' http://10.0.0.1 http://www.fcounter.net http://s11.flagcounter.com data:;\
        frame-src 'self' https://abc.com.tw https://www.youtube.com;\
        style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://cdnjs.cloudflare.com;\
        script-src 'self' https://cdn.jsdelivr.net https://code.jquery.com https://cdn.datatables.net 'unsafe-eval' 'unsafe-inline';\
        font-src 'self' https://cdnjs.cloudflare.com;\
        "

</IfModule>

內容需要依照自己的需求去修正
一個網頁一個網頁去看格式有沒亂掉 版面有沒正常
可以打開 browser 的開發人員工具
會顯示那些被CSP阻擋了
然後再補上去
需要補什麼問 https://www.perplexity.ai/ 比較快
把主控台上的訊息直接問就可以了

不難 但真的很花時間

2025/01/16

今天登入n8n看到通知





















想說之前升級都沒問題就沒先snapshot
結果升完後出現白畫面
只好倒回備分
再下一版看看吧

之後要升一定要先snapshot

2025/01/14

又到了弱掃的時間
昨天看報告
有二個問題

Vulnerability Detection Result
The remote SSH server supports the following weak KEX algorithm(s):
KEX algorithm | Reason
------------------------------------------------
diffie-hellman-group-exchange-sha1 | Using SHA-1


Vulnerability Detection Result
The remote SSH server supports the following weak client-to-server encryption algorithm(s):
aes128-cbc
aes256-cbc
The remote SSH server supports the following weak server-to-client encryption algorithm(s):
aes128-cbc
aes256-cbc


想說改一下 /etc/ssh/sshd_config就可以了

Ciphers aes128-ctr,aes192-ctr,aes256-ctr

KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512

沒想到重掃還是一樣

因為每次掃都要花很多時間
所以使用 nmap 特別針對ssh server來掃

nmap --script ssh2-enum-algos -sV -p 22   10.0.0.1


Starting Nmap 7.80 ( https://nmap.org ) at 2025-01-21 13:47 CST
Nmap scan report for 10.0.0.1
Host is up (0.00079s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.0 (protocol 2.0)
| ssh2-enum-algos: 
|   kex_algorithms: (12)
|       curve25519-sha256
|       curve25519-sha256@libssh.org
|       ecdh-sha2-nistp256
|       ecdh-sha2-nistp384
|       ecdh-sha2-nistp521
|       diffie-hellman-group-exchange-sha256
|       diffie-hellman-group14-sha256
|       diffie-hellman-group16-sha512
|       diffie-hellman-group18-sha512
|       diffie-hellman-group-exchange-sha1
|       diffie-hellman-group14-sha1
|       kex-strict-s-v00@openssh.com
|   server_host_key_algorithms: (5)
|       rsa-sha2-512
|       rsa-sha2-256
|       ssh-rsa
|       ecdsa-sha2-nistp256
|       ssh-ed25519
|   encryption_algorithms: (7)
|       aes256-gcm@openssh.com
|       chacha20-poly1305@openssh.com
|       aes256-ctr
|       aes256-cbc
|       aes128-gcm@openssh.com
|       aes128-ctr
|       aes128-cbc
|   mac_algorithms: (8)
|       hmac-sha2-256-etm@openssh.com
|       hmac-sha1-etm@openssh.com
|       umac-128-etm@openssh.com
|       hmac-sha2-512-etm@openssh.com
|       hmac-sha2-256
|       hmac-sha1
|       umac-128@openssh.com
|       hmac-sha2-512
|   compression_algorithms: (2)
|       none
|_      zlib@openssh.com

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.29 seconds

果然還是沒用
找了半天資料 才找到解決方法

先處理 
aes128-cbc
aes256-cbc

先建一個文件內容如下

vi /etc/crypto-policies/policies/modules/DISABLE-CBC.pmod

cipher = -AES-128-CBC -AES-256-CBC
ssh_cipher = -AES-128-CBC -AES-256-CBC


更新加密策略

update-crypto-policies --set DEFAULT:DISABLE-CBC


再來處理

diffie-hellman-group-exchange-sha1


vi /etc/crypto-policies/back-ends/opensshserver.config

刪除以下文字

,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1



重啟 sshd

systemctl restart sshd


再跑一次 
nmap --script ssh2-enum-algos -sV -p 22   10.0.0.1

Starting Nmap 7.80 ( https://nmap.org ) at 2025-01-21 13:59 CST
Nmap scan report for 10.0.0.1
Host is up (0.00077s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.0 (protocol 2.0)
| ssh2-enum-algos: 
|   kex_algorithms: (10)
|       curve25519-sha256
|       curve25519-sha256@libssh.org
|       ecdh-sha2-nistp256
|       ecdh-sha2-nistp384
|       ecdh-sha2-nistp521
|       diffie-hellman-group-exchange-sha256
|       diffie-hellman-group14-sha256
|       diffie-hellman-group16-sha512
|       diffie-hellman-group18-sha512
|       kex-strict-s-v00@openssh.com
|   server_host_key_algorithms: (5)
|       rsa-sha2-512
|       rsa-sha2-256
|       ssh-rsa
|       ecdsa-sha2-nistp256
|       ssh-ed25519
|   encryption_algorithms: (5)
|       aes256-gcm@openssh.com
|       chacha20-poly1305@openssh.com
|       aes256-ctr
|       aes128-gcm@openssh.com
|       aes128-ctr
|   mac_algorithms: (8)
|       hmac-sha2-256-etm@openssh.com
|       hmac-sha1-etm@openssh.com
|       umac-128-etm@openssh.com
|       hmac-sha2-512-etm@openssh.com
|       hmac-sha2-256
|       hmac-sha1
|       umac-128@openssh.com
|       hmac-sha2-512
|   compression_algorithms: (2)
|       none
|_      zlib@openssh.com

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.33 seconds


已經全部修正
再重掃一次也沒問題了

2025/01/13

從昨天晚上開始 suricata的cpu就會一直跑到98以上而且降不下來
看了一下 log 出現大量的 truncated 

Jan 13 04:30:33 suricata suricata[77297]: [1:2200003:2] SURICATA IPv4 truncated packet [Classification: Gen
eric Protocol Command Decode] [Priority: 3] [**] [Raw pkt: C0 C5 20 6B A9 DA 00 60 E0 8A 76 E3 08 00 45 00 
0A 8C 8F C5 00 0]

Jan 13 10:44:03 suricata suricata[78]: [1:2200013:2] SURICATA IPv6 truncated packet [Classification: Generic Protocol Command Decode] [Priority: 3] [**] [Raw pkt: C0 C5 20 6B A9 DA 00 60 E0 8A 76 E3 86 DD 60 81 56 A3 10 DC 06 3]

先把這二個偵測暫停 

/etc/suricata/rules/decoder-events.rules

再觀察看看

2025/01/10

在PVE中撈出所有guest的 cpu使用率並在超過上限值時發出告警


#!/bin/bash

pvesh get /cluster/resources|awk '{print $2" "$33" "$8}'|grep -E "lxc|qemu"|sed 's/....$//' > /tmp/all_guest_cpu

cat /tmp/all_guest_cpu | awk  '$3 > 80 {print $0}' > /tmp/guest_cpu_high

if [ -s /tmp/guest_cpu_high ]; then

        sed -i '1i network guest cpu high' /tmp/guest_cpu_high
        sed -i '2i ==========' /tmp/guest_cpu_high
        cp /tmp/guest_cpu_high /tmp/guest_cpu_high_network
        /usr/bin/lftp ftp://user:pwd@10.0.0.1 -e "put /tmp/guest_cpu_high_network; bye"
        mutt -s guest_cpu_high user@abc.com < /tmp/guest_cpu_high

fi

2025/01/03

今天使用 tabby ssh 到almalinux 8 後 vi打中文時出現以下的狀況

中�~V~G試�~\~K�~\~K

但 cat 正常

找了資料 說要改 tabby config

appearance:
  - Character encoding: utf-8

改了還是沒用

最後解決的方法是先在 almalinux 8 安裝vim

dnf install vim

在home目錄建立 .vimrc 內容如下

set encoding=utf-8
set fileencoding=utf-8

設定 alias

echo "alias vi='vim'" >> ~/.bashrc

醬就正常了


2024/12/20

Proxmox Datacenter Manager 發表了第一個Alpha
裝起來看了一下
目前還沒什麼功能
pbs也不能管
等正式版出來再玩吧

2024/12/15

最近一直需要在grafana上畫圖
之前一陣子用的是csv檔的方式
把csv檔放在 web server上就可以了
在更之前也有使用influxdb來放資料
昨天想說可以用sqlite來試試
OS要安裝 sqlite
grafana要安裝sqlite的plugin
但碰到了時間格式的問題
這個之前使用 csv檔時也碰過 當時也試了好久
csv可以使用的日期時間格式如下

2024-12-16T07:34:01+0800
或
2024-12-16 07:34:01

sqlite 文件上說只能使用  RFC3339 的格式 但實際上這個格式無法被解析
必須要使用 iso-8601 才行
linux date 指令如下

date --iso-8601=seconds

產生格式如下

2024-12-17T22:17:01+08:00

還有一個要注意的是在下方的 sql指令欄位中 
記得要在 format as 選 time series 然後把 日期時間的欄位加進去 這裡是 time
醬才能被解析 也才能成功畫圖













2024/11/29

PVE 的 LXC 使用 almalinux 9 時

把 開几需要啟動的指令下在 /etc/rc.local 沒有作用
因為 rc-local 這個daemon 一直起不來 有問題
改用 @reboot
如果還是一直不成功的話
會需要在之前先 sleep 一下
如

@reboot sleep 5;/root/some_thing_need_start 
使用curl 在 telegram傳送包含html tag 訊息的範例如下
不過支援的tag不多 主要是要加上  &parse_mode=HTML


curl -X POST "https://api.telegram.org/bot711025:AAFcn2dfjsldfkjsdlfjdkfcvZo/sendMessage" -d "chat_id=-100236747688384&text=<u>test</u>&parse_mode=HTML"
因為要管制跑在LXC上docker的網路
才發現把iptables直接下在 LXC上的 INPUT 是沒用的 

iptables -I INPUT -p tcp -s 10.0.0.0/8 --dport 1111 -j DROP

以上如果是啟動 docker 時 相對應到各自的 1111是無法管制連入 docker的
本來的認知是只要在最外層擋就好了 但並不是

要下在 DOCKER-USER 這個 chain 才有作用

iptables -I DOCKER-USER -p tcp -s 10.0.0.0/8 --dport 1111 -j DROP
今天在試PVE的 firewall 功能
因為是三層式的架構 所以 cluster node 跟 guest os 都必需要打開才會有作用
但是在打開cluster的firewall之後
管理介面就進不去了
查了一下文件才發現cluster firewall預設的規則是 DROP
唯一的解法是進 console 改 /etc/pve/firewall/cluster.fw 這個檔
把  enable: 0 改成 enable: 1
要打開前一定要記得要把 input policy 先改成 ACCEPT



2024/11/27

n8n裡有二個重要的東西一定要備分

一個是 credentials 一個是 workflow

指令如下

首先進到docker的 os

docker exec -it  n8n /bin/sh


備分 credentials 

n8n export:credentials --all --decrypt --output=exported-credentials.json

記得一定要用 --decrypt 

如果不加的話 因為每一台的 crypt key不同 匯入別台新的几器會有問題


備分 workflow

n8n export:workflow --all --output=exported-workflows.json


也可以使用 api 拿出來 

記得要先產生api key

語法如下

curl -X 'GET' \

  'http://10.0.0.1:5678/api/v1/workflows?active=true&tags=test,production&name=My%20Workflow&projectId=your_api_key' \

  -H 'accept: application/json'


備分檔可以傳出來或建個 workflow 定時丟出來



記一下在 almalinux 9 上安裝docker後再安裝n8n docker

先裝 docker

dnf install 'dnf-command(config-manager)'

dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

dnf install docker-ce docker-ce-cli containerd.io

裝好後設定docker 的 daemon

systemctl start docker
systemctl enable docker


接下來安裝 n8n

先建立放資料的 volume

docker volume create n8n_data

docker pull docker.n8n.io/n8nio/n8n


# Start docker 有些參數要加  以下方為準    官方說明太簡單

docker run -it --name n8n -p 5678:5678 --restart=always -e GENERIC_TIMEZONE="Asia/Taipei" -e TZ="Asia/Taipei" -e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true -e N8N_SECURE_COOKIE=false -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n

如果這裡timezone 沒設 每次新建 workflow的時候都要再改 有點煩 而且很容易忘記

再來就可以開browser登入了 http://10.0.0.1:5678


以下步驟是n8n docker 有新版本的更新方式 

docker pull docker.n8n.io/n8nio/n8n

# Get the container ID
docker ps -a

# Stop the container with ID container_id
docker stop [container_id]

# Remove the container with ID container_id
docker rm [container_id]

# Start the container
docker run -it --name n8n -p 5678:5678 --restart=always -e GENERIC_TIMEZONE="Asia/Taipei" -e TZ="Asia/Taipei" -e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true -e N8N_SECURE_COOKIE=false -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n

#remove unused image
docker image prune


這几天在玩 n8n 真的是個好東西

先講一下安裝

官方提供docker跟 npm的安裝方式

但試了 almalinux 9 及 debian 12 都安裝不起來

最後使用docker

n8n docker的基底用的還是 alpine linux

沒有 bash 只有 sh



https://n8n.io/

2024/11/20

今天把ntopng換到 almalinux9

官方說明頁面的步驟是

dnf config-manager --set-enabled crb
dnf install epel-release

錯了 
要先 dnf install epel-release
才能 dnf config-manager --set-enabled crb


安裝後進管理介面
一直出現這個訊息




















必須在
/etc/ntopng/ntopng.conf
加上

-X=500000

數字依据現實狀況而定

順便改一下這二個值

 -m=10.0.0.0/8,192.168.0.0/16

 -i=eth1


2024/11/15

今天有人問我為什麼mobaxterm進server後開圖檔很慢
試了 eog 跟 shotwell 真的很慢 都要30多秒
再試了 nomacs 不到1秒就開了

開圖檔記得要用 nomacs

2024/11/09

使用tfm時 置放檔案的目錄 不要放在 /var/www 或 /var/www/html 下
另外找個路徑
例如 /opt/tfm_file
再修改該目錄的權限

chown -R www-data:www-data /opt/tfm_file

以避免被直接存取的情況


5種在linux透過 serial 連接設備 console的方法

先找出 serial port

 dmesg|grep ttyS

[    0.818900] 00:03: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.841214] 0000:00:03.3: ttyS4 at I/O 0x2248 (irq = 17, base_baud = 115200) is a 16550A

開放存取權限

sudo chmod 666 /dev/ttyS0

sudo chmod 666 /dev/ttyS4


screen

screen /dev/ttyUSB0 115200

crtl+a   /      quit

cu
tip
minicom
putty

2024/11/07

在 graylog 5 使用的 Geolocation 功能 在 graylog 6 也被限制了


















使用Geolocation 功能前必須 先有  Illuminate Processor 
但這個功能在open版被限制了