2024/10/21

本次外稽又提到要注意server的HD狀況
如果低於某個臨界值要有告警

寫個批次檔來做 並把資料丟到 log server 
要注意的是批次檔的計算有32位元的問題
所以先把後6位砍掉再計算

@echo off

del %tmp%\disk_usage.txt

setlocal enabledelayedexpansion

for /f "tokens=1,2,3" %%A in ('wmic logicaldisk get caption^, size^, freespace ^| findstr /R "^[A-Z]"') do (
    set "drive=%%A"
    set "totalSize_ori=%%C"
    set "freeSpace_ori=%%B"

    if defined drive (
        rem Remove trailing spaces and convert to numbers
        set /a totalSize=!totalSize_ori:~0,-6!
        set /a freeSpace=!freeSpace_ori:~0,-6!

        rem Check if totalSize is not zero to avoid division by zero
        if !totalSize! gtr 0 (
            set /a freePercent=freeSpace*100/totalSize

            rem echo %COMPUTERNAME% >> %tmp%\disk_usage.txt
echo disk: !drive! >> %tmp%\disk_usage.txt
            echo size: !totalSize! MB >> %tmp%\disk_usage.txt
            echo %COMPUTERNAME% free_space: !freeSpace! MB >> %tmp%\disk_usage.txt
            echo remaining_capacity: !freePercent!%% >> %tmp%\disk_usage.txt
            echo -------------------------------- >> %tmp%\disk_usage.txt
        ) 
    )

endlocal

type %tmp%\disk_usage.txt | nc -w 2 -u 10.0.0.1 514

2024/10/16

URLEncoded of emojis

telegram line 傳訊時會用到的東東




2024/10/12

還是line notify終止服務的問題
今天試了另一個方式 telegram
記錄一下
註冊完後首先要把 botfather 加入好友
接下來再對話中輸入 /newbot
他會叫你給bot取個名字
這個名字一定要以bot結尾
例如 testbot

送出後的回應裡就會有一組API key
一定要記好

接下來建立群組並把 testbot 加入該群組

使用curl取得testbot相關資訊

curl https://api.telegram.org/botYOUR API KEY/getUpdates

如果bot加入的群組愈多 回應就會愈多

在得到的回應中先找group 這個關鍵字

往前看 title 就是群組名稱 再往前看 id 就是該群組的id 要記下來 傳訊息時要用

範例如下

"id":-123456780,"title":"test","type":"group"

再來就可以使用curl傳訊息了

curl -X POST "https://api.telegram.org/botYOUR API KEY/sendMessage" -d "chat_id=-1234567890&text=bot%0A換行中文傳訊息 測試"

感覺discord很耗電 telegram好很多

2024/10/10

最近最大的消息應該是line notify要終止服務了
官方說明取代的是付費的 messaging API

因此開始尋代替代方案
目前選定了discord
支援二個方式
一個是建立bot 步驟有點多

另一個是使用webhook
強烈建議使用這個方法
方便很多
而且librenms也直接支援


2024/10/08

延續昨天的問題

昨天修好後當下沒問題
但今天管理介面打不開了
直接倒回去颱風前一天的備分
目前看來運作正常
持續觀察
順便看看還有那些有問題

dmesg|grep "fsck"|grep dm
[   82.486238] EXT4-fs (dm-6): warning: mounting fs with errors, running e2fsck is recommended
[  139.304759] EXT4-fs (dm-11): warning: mounting fs with errors, running e2fsck is recommended
[  398.955415] EXT4-fs (dm-6): error count since last fsck: 2
[  464.490594] EXT4-fs (dm-11): error count since last fsck: 3769411
[55841.695354] EXT4-fs (dm-12): error count since last fsck: 2
[88379.937761] EXT4-fs (dm-6): error count since last fsck: 2
[88547.518964] EXT4-fs (dm-6): warning: mounting fs with errors, running e2fsck is recommended
[88871.451957] EXT4-fs (dm-6): error count since last fsck: 3

共三台

先到 /dev/mapper 查看是那個guest

lrwxrwxrwx  1 root root       7 Oct  7 23:45 pve-vm--116--disk--0 -> ../dm-6
lrwxrwxrwx  1 root root       8 Oct  8 00:08 pve-vm--124--disk--0 -> ../dm-11
lrwxrwxrwx  1 root root       8 Oct  8 09:04 pve-vm--140--disk--0 -> ../dm-12

一起倒備分吧
不想修了

2024/10/07

PVE host 修好換裡面的LXC guset 有問題

guest 先關几
找出那個disk
繼續修

fsck /dev/mapper/pve-vm--124--disk--0







几次的不正常斷電後
PVE開不起來了















修吧

xfs_repair /dev/mapper/pve-root

修好後正常了
再觀察看看

2024/09/30

最近在處理几千萬個小檔的問題

不管是 unzip 或 tar

都會出現以下的錯誤
cannot open no space left on device

明明空間就還有 而且 inode 也沒滿

折騰了好几天 才發現是 ext4的限制

請愛用 XFS


2024/09/29

針對 巨量小檔的zip檔

7z支援分片解壓縮 效能較差

unzip 不支援分片解壓縮 效能較好

2024/09/24

最近要在win上複制 一千五百萬多萬筆的小檔
試過
teracopy
fastcopy
robocopy
copy
cp
效能都很差
rsync
tar -T 
也跑不太出來
目前感覺上用 tar 好像好一點

改用 parallel 最多設定 252
昨天開始碰到有趣的狀況
說狀況是因為不確定是不是攻擊
pmg上的cpu會跑到100趴
雖然之前也偶爾會發生
但從昨天開始是大約一小時一次
觀察到是clamd這個process
所以猜測是寄了一封mail
然後導致clamd把cpu 吃滿
但pmg管理介面上無法關閉virus scan
目前只能重開

2024/09/19

一直在處理almalinux 9 live migrate的問題
目前得到的結果是

使用 x86-64-v2-AES 這個cpu type 就沒有問題
而且這個type 也是 PVE目前新建guest使用的預設值

但graylog使用這個type 能開機 但無法執行
目前改成 x86-64-v3 能開機 能執行
試了一下 live migrate 也沒問題

使用 host 是一定有問題的


在支援相同cpu type 的host live migrate是沒問題的


檢查 cpu 支援那些 type

#!/bin/sh -eu

flags=$(cat /proc/cpuinfo | grep flags | head -n 1 | cut -d: -f2)

supports_v2='awk "/cx16/&&/lahf/&&/popcnt/&&/sse4_1/&&/sse4_2/&&/ssse3/ {found=1} END {exit !found}"'
supports_v3='awk "/avx/&&/avx2/&&/bmi1/&&/bmi2/&&/f16c/&&/fma/&&/abm/&&/movbe/&&/xsave/ {found=1} END {exit !found}"'
supports_v4='awk "/avx512f/&&/avx512bw/&&/avx512cd/&&/avx512dq/&&/avx512vl/ {found=1} END {exit !found}"'

echo "$flags" | eval $supports_v2 || exit 2 && echo "CPU supports x86-64-v2"
echo "$flags" | eval $supports_v3 || exit 3 && echo "CPU supports x86-64-v3"
echo "$flags" | eval $supports_v4 || exit 4 && echo "CPU supports x86-64-v4"


2024/09/17

昨天的內稽事項有提到要注意各server的HD使用量

二個做法 種 agent 或打開server的 snmp

初步的想法是打開 server的 snmp

因為現在 m$ 某些OS 預設不給ping 

所以 librenms 要改個設定值 把ping test 關了


 





撈進來後 點到 health 可以看到 cpu ram hd 的狀況



 

 



點右方的齒輪 可以在 storage processors memory 設定告警的閥值

 



 

 



 



不過這裡設完後還是不會發alert

要再手動加一條 rule 而手動加的個rule 也不會參考這裡的值 需要重新指定

 


 

2024/09/16

之前換nas的時侯發生 filesystem有問題的情況
使用 xfs_repair 修完後 出現有user的mail不見的情況
當時是使用 PhotoRec 撈了好几天 把資料還給user 
而且也無法確認是否完整

這几天在使用rsync 備分 /home 時 
出現好几次做到一半就會卡住的情況
看了一下才發現竟然出現 超級大檔案 

-rw-------  1 user mailnull 9007199254766339 Aug  4  2023 1691146737.V811I2821a77dbM603030.mail:2,S

只能砍了
而且砍完就正常了
反正就一邊做一邊發現問題一邊砍

最近因為換冷氣 所以要觀察 raspberry 的cpu溫度 

來調整冷氣的設定溫度

先前已經利用設定snmp把值放在librenms上畫圖

今天想到grafana可以取值來畫圖

而且應該比snmp librenms 方便

首先把日期跟溫度存成csv 檔 格式如下 放在web server上

格式如下

time,temperature

Sun Sep 15 09:15:01 CST 2024,46.2

Sun Sep 15 09:20:01 CST 2024,46.2


接下來只要定時更新這個csv檔就可以了

grafana 要add new datasource          

yesoreyeram-infinity-datasource

安裝後不需要先建立 Global queries

接下來 New 一個 dashboard

Add visualization









select data source






type 選擇csv           修改csv檔的url








要把columns 依照數字及時間 設定好 

時間的格式一定要依照cvs檔裡的時間格式設定好才能畫圖 








完成後就能看到如下的圖了






2024/09/14

最近進了一台icx8200
可是在librenms上顯示的hardware名稱不對
之前也有人問同樣的問題在icx7150
定義的檔案是在
/opt/librenms/LibreNMS/OS/Ironware.php
裡面確實沒看到icx8200
等更新吧

2024/09/05

最近設備因為不明原因發生了二次cpu 99 %的情形 snmp就會撈不到值

第一次重開後大約正常了一週

又再發生

今天第二次重開 目前正常

但每次重開後

librenms 裡的 port id 都會變 導致weathermap 出現如下的問題

必須要再手動去一個一個改 config 

 


2024/08/31

heimdall 是一款滿好用的管理頁面集成軟体

大部分找到的資料都是使用docker

如果不想使用docker而是直接在ubuntu上安裝

流程如下

apt install php8.3-cli php8.3-sqlite3 php8.3-xml php8.3-mbstring php8.3-zip

再來到github下載最新版 目前是 2.6.1

php最低要求是 8.2

下載後解壓

執行

php artisan serve --host=0.0.0.0 --port=8080

即可

不需要安裝 apache

進入介面後並沒有登出的選項

因此隨便建個user

如果要登出 在左下角點 swtich user即可


https://github.com/linuxserver/Heimdall/releases


https://heimdall.site/


https://www.reddit.com/r/selfhosted/comments/o0x3tr/install_heimdall_dashboard_on_debianubuntu/

2024/08/22

使用lftp捉檔案時 如果本地端檔案已存在
會出現以下的錯誤

get:/tmp/822/log.txt:檔案早已存在,而且沒有設定 xfer:clobber 變數

在 /etc/lftp.conf加入以下這行即可

set xfer:clobber on


2024/08/12

之前一直都沒去找過 librenms 

temperature Sensor over limit

這裡的定義

發現不是一個固定的定值

而且超越前高時 就會出現




2024/08/10

昨天在升級ICX時 使用tftp
但試了好几種tftp server
包含 linux 及 windows 
都無法成功傳檔
一直出現timeout
使用 scp 才成功

copy scp flash 10.0.0.1 firmware_file secondary

不過 telnet timeout 要設長一點
不然有可能檔案還沒傳完就timeout 了
預設是 4 分鐘

telnet@10.0.0.2(config)#telnet timeout 10


2024/08/03

上次librenms升完OS後
一直出現hd容量不夠的狀況
今天才發現 /var/log/syslog 這個檔變的很大
內容都是以下的log

2024-08-03T12:14:01.608311+08:00 W-librenms-debian12 mariadbd[221]: 2024-08-03 12:14:01 283381 [ERROR] Incorrect definition of table mysql.column_stats: expected column 'histogram' at position 10 to have type longblob, found type varbinary(255).
2024-08-03T12:14:01.608631+08:00 W-librenms-debian12 mariadbd[221]: 2024-08-03 12:14:01 283381 [ERROR] Incorrect definition of table mysql.column_stats: expected column 'hist_type' at position 9 to have type enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON_HB'), found type enum('SINGLE_PREC_HB','DOUBLE_PREC_HB').
2024-08-03T12:14:01.608659+08:00 W-librenms-debian12 mariadbd[221]: 2024-08-03 12:14:01 283381 [ERROR] Incorrect definition of table mysql.column_stats: expected column 'histogram' at position 10 to have type longblob, found type varbinary(255).

google了一下
說是升OS時DB沒升造成
使用以下指令升級DB

mysql_upgrade --user=root --password=passwd

目前看來正常了
再觀察看看

2024/07/30

2024/07/19

這陣子PVE 在live migrade 時
有几台在migrade到新host後
就自動關几了
出現以下錯誤

2024-07-19 07:55:24 ERROR: tunnel replied 'ERR: resume failed - VM 103 qmp command 'query-status' failed - client closed connection' to command 'resume 103'

目前觀察到都是almalinux 9 
cpu type 是host
但又不是所有的almalinux 9 都會有問題

還在找問題

2024/07/17

今天打開OCS出現需要更新的畫面
就直接點update
想說應該不是大版本 應該沒問題
沒想到更新完
管理介面就完全空白了
看log也沒看到什麼error
決定重裝
原本的是在almalinux 8 順便升級os
依照原廠網頁安裝沒問題
這個檔裡的帳號密碼要記得改

/etc/httpd/conf.d/ocsinventory-server.conf

目前正常
再觀察看看



2024/07/03

移除檔案裡的所有特殊字元並保留 . 及 -

sed -i 's/[^[:alnum:].-]//g' test_file

2024/07/01

之前使用的 honeyports 因為OS升到 almalinux 9不能使用了
almalinux 9 不再支援 python2
另外再找了一個差不多功能 有提供 python跟shell 可以使用
不過一樣有python2的問題
所以改用shell

程式要改一下

honeyport.sh 裡第20行是設定要listen在port 31337
如果有listen在其他 port 必須修改此行 存成不同檔案 再執行

為了能批次執行 改成如下

#PORT=31337;
PORT=$1;


再來寫個shell 如下 把要listen的 port 加上去

#!/bin/bash

#revice port want to listen
port="21 22 23 ......."

for i in $port
do
        /root/honeyport.sh $i &
done

執行後就可以在log 找到相關ip並進行處理了 


https://github.com/securitygeneration/Honeyport

2024/06/16

今天把librenms的OS從debian 11 升到 12
照步驟做沒問題
要注意的是php不能升到 8.3
只能到 8.2
原來在debian 11上的是 8.1



2024/06/15

之前裝almalinux9時cpu都直接使用host
今天升級 almalinux 8 to 9 時 出現 cpu 的錯誤
原本使用 Default (kvm64)


訊息中指出cpu未使用 x86-64-v2 這個type
v2以上的type都可以




較舊的cpu 未支援 x86-64-v4 這個指令集
會導致 guest無法開几出現以下錯誤
















此時就必須要往下降為 v3 或 v2 或直接改為 host

由於几器本來就是從centos 7 升到 almalinux 8 所以再升到9時有些流程要注意

升級過程中出現

Error: Transaction test error:
  file /usr/include/gnumake.h from install of make-1:4.3-8.el9.x86_64 conflicts with file from package make-devel-1:4.2.1-11.el8.x86_64
移除 make-devel
rpm -e make-devel-4.2.1-11.el8.x86_64

升級後使用vi時出現

vi /tmp/1

Error detected while processing /etc/virc:
line   40:
E319: Sorry, the command is not available in this version: let skip_defaults_vim=1

刪除 /etc/virc 裡的第40行

let skip_defaults_vim=1

有些几器升級後出現以下的log 有些正常

Jun 15 21:46:29 localhost rsyslogd[593]: imjournal: open() failed for path: '/var/lib/rsyslog/imjournal.state.tmp': Operation not permitted [v8.2310.0-4.el9 try https://www.rsyslog.com/e/2433 ]

比對 /etc/rsyslog.conf發現有不同
複制正常几器的檔案過去就ok了
記得如果原rsyslog.conf有更改 新檔也要改
看起來是之前有改過
所以升級時會保留舊的rsyslog.conf

2024/06/13

如何使用zap docker

docker安裝好後

docker pull ghcr.io/zaproxy/zaproxy:stable
docker pull zaproxy/zap-stable


啟動

docker run -u zap -p 8080:8080 -p 8090:8090 -i ghcr.io/zaproxy/zaproxy:stable zap-webswing.sh

開browser
http://localhost:8080/zap




2024/06/12

本次弱掃有關SSH出現以下二個中風險


The remote SSH server is configured to allow / support weak key

exchange (KEX) algorithm(s).

Detection Result

The remote SSH server supports the following weak KEX algorithm(s):


KEX algorithm                      | Reason

------------------------------------------------

diffie-hellman-group-exchange-sha1 | Using SHA-1




The remote SSH server is configured to allow / support weak
encryption algorithm(s).
Detection Result
The remote SSH server supports the following weak client-to-server 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-group-exchange-sha256,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha1

重新啟動daemon



2024/06/05

118.195.223.15

start dos at 2024/6/4 18:20











block after few minutes




 

2024/05/27

今天看到rustdesk-server 天前有更新
版本是 1.1.11-1 
更新完要連線出現以下的訊息















再回頭看了一下官方頁面

This version changes default -k of hbbs to -, which means setting key on client side is mandatory. If you want to run empty -k as before, please run hbbs -k "".

這個版本client端強制要設定key
如果要跟之前的使用方法一樣
就要使用以下指令啟動 hbbs

hbbs -k ""

醬就正常了

2024/05/26

近期又開始社交工程演練
使用PMG把信隔離後會放在
/var/spool/pmg/spam
這個目錄下

由於內容是base64編碼
如果要解碼
使用以下指令

base64 -d encode_file > decode_file

2024/05/22

這几天用ZAP在弱掃

當網站很大時 因為會產生很大量的cache

所以要確保執行弱掃那台几器的HD空間要夠

不然有可能還沒做完就爆了

另外有很多網站都出現以下的報告


 


查了一下 可以在httpd.conf 設定

新增以下內容


<IfModule mod_headers.c>

Header set X-Frame-Options "SAMEORIGIN"

Header set Content-Security-Policy "default-src 'self'"

</IfModule>


設完要重啟apache

另外 如果有參考到外面的任何元件

版面是會亂掉的

這個要特別注意


設完後再掃一次出現另一個報告




如果要再處理

Header set 就要再改成如下的設定


Header set Content-Security-Policy "frame-ancestors 'self'; form-action 'self'; base-uri 'self'; img-src 'self'; default-src 'self'; script-src 'self'; style-src 'self';"


當然影響範圍就會更大


https://lawrencechuang760223.medium.com/%E5%A6%82%E4%BD%95%E5%9C%A8apache-server%E4%B8%8B%E6%96%B0%E5%A2%9Ex-frame-options%E8%88%87content-security-policy%E8%87%B3response-header%E4%B8%AD-fix-web-application-d68209ff385c


https://medium.com/@andy001018/owasp-zap-%E5%BC%B1%E6%8E%83%E8%99%95%E7%90%86%E7%B4%80%E9%8C%84-2fb0f4888908

2024/05/16

有几器要報廢
找到硬碟抹除的工具 shred
使用linux mint
下載iso後寫到usb開几

sudo fdisk -l 找到要抹除的硬碟代號

sudo shred -vfz /dev/sdX


-n - 覆盖的次数。默认是三次。
-u - 覆盖并删除。
-s - 要粉碎的字节数。
-v - 显示扩展信息。
-f - 必要时强制改变权限以允许写入。
-z - 最后用 0 覆盖来隐藏粉碎。

466G的傳統硬碟跑1次要1小時50分
總共要跑4次


2024/05/10

graylog6的indices 保存方法改變如下圖













之前的設定是多久之後可以刪除或close
如果是close 必需再手動刪除
目前看來沒這個選項了
不知道在比較長時間後會不會跟以前一樣
因為儲存大量資料導致search變的很慢

2024/05/09

這几天進graylog時提示6版已經出來了
看官網說的是可以直接更新
還是先裝一台來試看看好了
這次用的是almalinux 9
6版已經不再支援 elasticsearch 了
依照官網安裝流程裝到opensearch就有問題了
安裝後無法啟動
看了一下 opensearch.yml

裡面有一段 

######## Start OpenSearch Security Demo Configuration ########
# WARNING: revise all the lines below before you go into production
plugins.security.ssl.transport.pemcert_filepath: esnode.pem
plugins.security.ssl.transport.pemkey_filepath: esnode-key.pem
plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pem
plugins.security.ssl.transport.enforce_hostname_verification: false
plugins.security.ssl.http.enabled: true
plugins.security.ssl.http.pemcert_filepath: esnode.pem
plugins.security.ssl.http.pemkey_filepath: esnode-key.pem
plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem
plugins.security.allow_unsafe_democertificates: true
plugins.security.allow_default_init_securityindex: true
plugins.security.authcz.admin_dn: ['CN=kirk,OU=client,O=client,L=test,C=de']
plugins.security.audit.type: internal_opensearch
plugins.security.enable_snapshot_restore_privilege: true
plugins.security.check_snapshot_restore_write_privileges: true
plugins.security.restapi.roles_enabled: [all_access, security_rest_api_access]
plugins.security.system_indices.enabled: true
plugins.security.system_indices.indices: [.plugins-ml-agent, .plugins-ml-config, .plugins-ml-connector,
  .plugins-ml-controller, .plugins-ml-model-group, .plugins-ml-model, .plugins-ml-task,
  .plugins-ml-conversation-meta, .plugins-ml-conversation-interactions, .plugins-ml-memory-meta,
  .plugins-ml-memory-message, .plugins-ml-stop-words, .opendistro-alerting-config,
  .opendistro-alerting-alert*, .opendistro-anomaly-results*, .opendistro-anomaly-detector*,
  .opendistro-anomaly-checkpoints, .opendistro-anomaly-detection-state, .opendistro-reports-*,
  .opensearch-notifications-*, .opensearch-notebooks, .opensearch-observability, .ql-datasources,
  .opendistro-asynchronous-search-response*, .replication-metadata-store, .opensearch-knn-models,
  .geospatial-ip2geo-data*, .plugins-flow-framework-config, .plugins-flow-framework-templates,
  .plugins-flow-framework-state]
node.max_local_storage_nodes: 3
######## End OpenSearch Security Demo Configuration ########

感覺是這段的問題

備分後重新開一個新的 opensearch.yml
裡面的內容只要以下這些就好

cluster.name: graylog
node.name: ${HOSTNAME}
path.data: /var/lib/opensearch
path.logs: /var/log/opensearch
discovery.type: single-node
network.host: 0.0.0.0
action.auto_create_index: false
plugins.security.disabled: true
indices.query.bool.max_clause_count: 32768

改完後啟動就沒問題了

跟之前不同 graylog這個版本安裝好後
打開 http://127.0.0.1:9000 無法進到web介面 
看了一下 /var/log/graylog-server/server.log

It seems you are starting Graylog for the first time. To set up a fresh install, a setup interface has
been started. You must log in to it to perform the initial configuration and continue.

Initial configuration is accessible at 0.0.0.0:9000, with username 'admin' and password 'iIcCiFzjWY'.
Try clicking on http://admin:iIcCiFzjWY@0.0.0.0:9000

需要先 Initial configuration 才能使用
進入後依照畫面的步驟設定後 就能進入graylog的介面了

Memory/Heap usage 預設是1G 要再調整

/etc/sysconfig/graylog-server

GRAYLOG_SERVER_JAVA_OPTS="-Xms1g -Xmx1g -server -XX:+UseG1GC -XX:-OmitStackTraceInFastThrow"

依ram大小調整



2024/05/08

使用 curl 取得ip的相關資訊

curl ipinfo.io/8.8.8.8
{
  "ip": "8.8.8.8",
  "hostname": "dns.google",
  "anycast": true,
  "city": "Mountain View",
  "region": "California",
  "country": "US",
  "loc": "37.4056,-122.0775",
  "org": "AS15169 Google LLC",
  "postal": "94043",
  "timezone": "America/Los_Angeles",
  "readme": "https://ipinfo.io/missingauth"
}

2024/05/06

發生好几次電腦大量封包的傳輸
netflow的值都在几萬甚至几十萬
以往的做法都是先把ip block掉
等user自己來反應
但醬沒辦法在事發的當時撈到相關資料
到底是那個程式造成的
最近找到
LiveTcpUdpWatch
這個工具
就可以在 eset protect 上直接派送到電腦上執行並傳回資料
馬上就可以知道是那支程式造成的 資料撈回來後再把ip block掉
相當方便

程式如下


curl -o %temp%\LiveTcpUdpWatch.exe http://10.0.0.1/LiveTcpUdpWatch.exe

%temp%\LiveTcpUdpWatch.exe /CaptureTime 300000 /scomma "%temp%\tcpudp.csv"

ping -n 310 localhost > NUL

curl -u id:passwd -T "%TEMP%\tcpudp.csv" ftp://10.0.0.2/




https://www.nirsoft.net 這個站裡的工具都很好用

2024/04/29

一直有user反應收信時間會delay的問題
因為之前把greylist打開
目前的想法是分成上下班時段
上班關掉 下班再打開
試一段時間看看

指令如下

/usr/bin/pmgsh set /config/mail -greylist 0

/usr/bin/pmgsh set /config/mail -greylist 1


2024/03/28

為了要測試siem
需要起 snmptrap

找了二個方法
第一個方法是直接用 zabbix_trap_receiver.pl
但有問題起不來


第二個方法是直接改 /etc/snmp/snmptrapd.conf

內容如下

# Example configuration file for snmptrapd
#
# No traps are handled by default, you must edit this file!
#

disableAuthorization yes
authCommunity   log,execute,net public

[snmp] logOption s 2
[snmp] logOption f /tmp/snmptrapd-direct.log

format2 %V\n% Agent Address: %A \n Agent Hostname: %B \n Date: %H - %J - %K - %L - %M - %Y \n Enterprise OID: %N \n Trap Type: %W \n Trap Sub-Type: %q \n Community/Infosec Context: %P \n Uptime: %T \n Description: %W \n PDU Attribute/Value Pair Array:\n%v \n -------------- \n


systemctl restart snmptrapd

醬就可以了

2024/03/15

今天要在一台新安裝的win11 上要更新winget時出現以下訊息

C:\Windows\System32>powershell add-appxpackage %temp%\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle            add-appxpackage : 部署失敗,HRESULT 為: 0x80073CF3, 套件無法進行更新、相依性或衝突驗證。                                Windows 無法安裝套件Microsoft.DesktopAppInstaller_1.22.10661.0_x64__8wekyb3d8bbwe,因為此套件相依于找不到的架構。提供由 "CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"發行的架構"Microsoft.UI.Xaml.2.8"、中 性或x64處理器架構與最低版本8.2310.30001.0,以及要安裝的此套件。
注意: 如需其他資訊,請在事件記錄檔中尋找 [ActivityId] 1c4c5989-76a7-0000-05e8-511ca776da01,或使用命令列 Get-AppPackage
Log -ActivityID 1c4c5989-76a7-0000-05e8-511ca776da01
位於 線路:1 字元:1
+ add-appxpackage C:\Users\aaa\AppData\Local\Temp\Microsoft.DesktopApp ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\Users\aaa\A...bbwe.msixbundle:String) [Add-AppxPackage], IOException
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

原因是因為沒有安裝 Microsoft.UI.Xaml.2.8
到github上去找最新版
目前是 2.8.6
下載安裝完再更新winget就沒問題了



2024/03/14

今天撈 attack map 時出現以下訊息
















這個plugin使用的方法要被官方終止支援了
官方提供了 geomap來取代使用
試了半天
圖就是出不來
後來才找到問題










fotmat這裡一定要選 Table
不然在右方的選項會找不到值

2024/03/13

fortiet 如何在命令列踢掉 vpn user

首先列出目前所有連線 找出相對應的 index id

FG60F # execute vpn sslvpn list 
SSL-VPN Login Users:
 Index User Group Auth Type Timeout Auth-Timeout From HTTP in/out HTTPS in/out Two-factor Auth
 1  a1234  sslvpn-group-full-tunnel 16(1) 295 28501 192.168.12.12 0/0 0/0 0

SSL-VPN sessions:
 Index User Group Source IP Duration I/O Bytes Tunnel/Dest IP 
 1  a1234  sslvpn-group-full-tunnel 192.168.12.12  299 324697/1609215 172.17.0.51


執行以下指令刪除要踢掉的 id

FG60F # execute vpn sslvpn del-tunnel 1

2024/03/11

如何使用 sshpass在sudo時自動輸入密碼
範例如下

sshpass -p "passwd" ssh user@10.0.0.1 "echo passwd | sudo -S apt -y upgrade"

2024/03/10

linux 如果要直接使用整個HD
可以不用先分割磁區 直接mkfs即可

mkfs.xfs /dev/sdb

mount -t xfs /dev/sdb /mnt

mkfs.ext4 /dev/sdc

mount -t ext4 /dev/sdc /mnt

2024/03/05

linux在開几時要mount iscsi時
/etc/fstab使用 defaults 會無法開几


UUID=c46a08a2-160a-4345-9e96-8ebc35ff2220 /home                       xfs     defaults,uquota        0 0

要改成 _netdev 在網路啟動後再mount 就沒問題了

UUID=c46a08a2-160a-4345-9e96-8ebc35ff2220 /home                       xfs     _netdev,uquota



2024/02/29

最近要進行mail server移轉
在新server上安裝完 dovecot後
改完 /etc/dovecot/dovecot.conf

protocols = imap pop3

重啟發現 port 993 995 還是會 listen

只能修改
/etc/dovecot/conf.d/10-master.conf
的二個地方 把port 改成 0 才有作用
service imap-login {
  inet_listener imap {
    #port = 143
  }
  inet_listener imaps {
    port = 0
    #ssl = yes
  }

service pop3-login {
  inet_listener pop3 {
    #port = 110
  }
  inet_listener pop3s {
    port = 0
    #ssl = yes
  }
}

2024/02/26

總結一下目前如何在client 使用winget 定期更新
在目前原有的使用者上建立排程
單位內的使用者95%以上都使用 abc 這個帳號 
所以把排程建在 abc 這個user上

加入以下的 reg 以達成以下二個作用

bypass MicrosoftStore Certificate 
關閉安裝軟体時的UAC 以避免一直跳出視窗要user按確定

Windows Registry Editor Version 5.00



[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\AppInstaller]
"EnableBypassCertificatePinningForMicrosoftStore"=dword:00000001


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
"ConsentPromptBehaviorAdmin"=dword:00000000



為了不要讓user看到排程執行時的DOS視窗 因此批次檔要以 vbs 進行呼叫

Set ws = CreateObject("Wscript.Shell")
ws.run "cmd /c C:\ProgramData\wingetgo.vbs",vbhide


接下來建立排程

schtasks /create /tn "winget4update task" /tr "C:\ProgramData\wingetgo.vbs" /sc weekly /d MON /st 09:00 /ru abc /f

因為每個user都會改密碼 所以沒辦法建立不登入時也能執行的排程
還有一個問題就是如果user沒有登入網路 執行也不會成功


整個由eset主按台派送的工作如下

curl -o %temp%\winget.reg http://10.0.0.1:3128/i/o/winget.reg
regedit /s %temp%\winget.reg
curl -o C:\ProgramData\wingetgo.bat http://10.0.0.1:3128/i/o/wingetgo.bat
curl -o C:\ProgramData\wingetgo.vbs http://10.0.0.1:3128/i/o/wingetgo.vbs
schtasks /create /tn "winget4update task" /tr "C:\ProgramData\wingetgo.vbs" /sc weekly /d MON /st 09:00 /ru abc /f

2024/02/24

昨天一台樹莓派完全開不了几
之前就一直發生早上無法開几
必須下指令重新開關POE該 port的電力輸出
本來以為是SD卡壞了
先換一張先上線
再把這張SD卡重刷OS
又可以開几了
就先留著當備品吧
順便把poe hat 拿下來
換上poe 分電器試試看
到目前是正常

2024/02/22

ubuntu中自動播放資料夾內的所有圖片

apt install feh

feh -Z -F -D 5 /tmp/pic
在windows 排程中執行bat檔會出現dos視窗
如果要隱藏要使用 vbs
如以下範例 假設要執行的是run.bat

Set ws = CreateObject("Wscript.Shell")
ws.run "cmd /c run.bat",vbhide

存成 run.vbs
再執行run.vbs 即可

2024/02/21

之前本來想從eset的管理介面下指令在每台電腦上跑winget
但這段時間看好像都沒效果
但從管理介面看是執行成功的
請席克幫忙查一下
結果是因為主控台派下去的指令的執行身分是 system
但是用system這個身分去執行 winget 無法成功
昨天討論後
最後決定直接在每台client執行排程
試過一台沒問題
今天把辦公室的几器全部加入排程
明天中午再來看看結果
今天有個新需求要記錄dns 的client query 

試了半天
只有放在這個目錄

/var/named/chroot/var/log/

才能正常的log 輪換

在/etc/named.conf加上以下這段

logging {
channel query_log {
file "/var/named/chroot/var/log/query.log" versions 3 size 1m;
severity info;
print-time yes;
};
category queries {
query_log;
};
};


versions 3 size 1m;
表示每個檔案 1m 保留3個輪換的檔案


2024/02/16

之前提到用mobaxterm連進 alpine linux 無法使用X11Forwarding的問題
解法如下
先安裝 xauth

apk add xauth

再來把 /etc/ssh/sshd_config  裡的 X11Forwarding 改成 yes

X11Forwarding yes

重啟 sshd 

rc-service sshd restart

醬就可以了

本日的ntopng 更新後又出現問題

看來是有新加了一個 ntop-license

這個套件需要新增 ntop 這個user 

而這個user要在 ntop這個 group 裡

所以出現以下錯誤

useradd: group 'ntop' does not exist


手動加上 ntop 這個group
groupadd ntop

再跑一次 update 就 ok 了

2024/02/15

最近在試alpine linux
真的很小

目前是使用 LXC 來測

記錄一下使用到的指令

改時區
ln -s /usr/share/zoneinfo/Asia/Taipei /etc/localtime

找套件 
apk search 

加套件
apk add

移除套件
apk del

查看有無更新套件
apk update

更新套件
apk upgrade

架設 vsftp server 
apk add vsftpd

加入開机啟動
rc-update add vsftpd

重啟 vsftpd
rc-service vsftpd restart

安裝好後 client 連線出現
500 OOPS: priv_sock_get_cmd

要在 /etc/vsftpd/vsftpd.conf 最後加上
seccomp_sandbox=NO  

再重啟 vsftpd
rc-service vsftpd restart

anonymous 登入後的路徑
/var/lib/ftp

查看目前所有 service 狀況
rc-status

查看目前所有開机啟動項目
rc-update

重開機 (沒有 init)
reboot 

關机
halt


沒有rc.local 

如果要開几執行指令 先下以下命令

rc-update add local default

再來在 /etc/local.d/ 這個目錄裡加上程式 記得要 chmod +x
如果是開几要執行 副檔名要加上 .start 
例如 abc.start
如果是關几前要執行 副檔名要加上 .stop
所有加上 .start 或 .stop 的檔案都會被執行 不限一個

也可以使用 crontab 的 @reboot


apk add firefox 後
使用mobaxterm無法打開 因為 無法X11 forward

2024/02/03

今天要ssh 到server時出現錯誤

ssh root@10.1.1.1
Bad packet length 1657225410.
ssh_dispatch_run_fatal: Connection to 10.1.1.1 port 22: Connection corrupted


log出現以下錯誤

Feb  3 08:10:34 mail sshd[2963]: Bad packet length 1492758558. [preauth]
Feb  3 08:10:34 mail sshd[2963]: ssh_dispatch_run_fatal: Connection from 10.1.1.2 port 38462: Connection corrupted [preauth]

最新沒改設定 是不是有更新 查了一下

2024-02-03T02:05:13+0800 DEBUG Upgraded: openssh-server-8.0p1-19.el8_9.2.x86_64

果然沒錯
但要怎麼解決呢
這台是少數在用的几台 oracle linux 8
google 了一下果然有人也碰到問題

有人提出解法

ssh -c aes256-gcm@openssh.com user@host.example.com

試了一下沒問題

或是將 aes256-gcm@openssh.com 加到 /etc/ssh/ssh_config裡的 Ciphers 的這行
如下

Ciphers aes256-gcm@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc



2024/01/29

ntopng版本一直停在 20240111
今天去下手動更新出現以下訊息

ntopng : Depends: pfring (= 8.6.1-8861) but 8.6.1-8845 is to be installed

apt install pfing 又出現

pfring : Depends: ndpi (= 4.8.0-4603) but 4.8.0-4608 is to be installed

然後去網站上看 ndpi 的版本是 4.8.0-4603 沒錯

查一下是什麼時候更新的

2024-01-11 03:04:15 status installed ndpi:amd64 4.8.0-4608

因為這個是ntopng 自己的 apt source list

不知道是不是官方那天搞錯後又換回來

好吧 換回舊版

apt install ndpi=4.8.0-4603

醬更新就沒問題了