2024年9月18日 星期三
pktmon - Windows tcpdump
列出網卡
pktmon comp
新增一個 filter
pktmon filter add tcp80 -t tcp -p 80
開始抓包,--pkt-size 0 是記錄整個封包,不然預設只會記 128 bytes
預設抓所有網卡,要指定網卡可以用 --comp 網卡編號 (參考pktmon comp)
pktmon start -c --pkt-size 0
停止抓包,預設會存在當前目錄 pktmon.etl,若要指定不同的檔名,在 start 時用 -f 參數
pktmon stop
轉成 Wireshark 格式檔案,會轉出 pktmon.pcapng
pktmon pcapng pktmon.etl
pktmon 無法過濾某個軟體的封包,還是只能用 Microsoft Network Monitor,這個功能似乎還沒有替代品
2024年9月10日 星期二
HiNet IDC mirror closed
HiNet 這個網址關了,要高速下載 Linux ISO 少了一個地方,感謝 HiNet 默默服務了多年
測了幾個 TW mirror 站,推 TWDC 台灣數位串流,常見的 Linux 都有,速度超快
https://mirror.twds.com.tw
2024年8月26日 星期一
RouterOS WireGuard
RouterOS 在 7 版以後支援 WireGuard
註: WireGuard 在 Linux Kernel 5.6 版開始內建
設定滿簡單的,在選單 WireGuard New Interface,Private Key 及 Public Key 不用填,會自動產生
在 IP / Addresses 綁一個 IP 給 wireguard1,例如 10.66.66.1/24
在 IP / Firewall / NAT 加上 srcnat 讓 wireguard1 區段 masquerade
在 Peer 加 Client,這邊就沒有自動產生功能,
要找一台有裝 wireguard-tools 的 Linux,用 wg 指令產生
wg genkey | tee privatekey # 產生 Private Key
wg pubkey < privatekey # 產生 Public Key
wg genpsk # 產生 Preshared Key
Client Address 填入 10.66.66.2 # 要在上面 wireguard1 網段內
Client DNS 填入 8.8.8.8
Client Endpoint 填入 RouterOS 的 Public IP
下面會自動產生 Client Config 及 Client QR 碼
但實測在 [Interface] 內 ListenPort 必需移除才會通,
掃 QR 碼後,需將 ListenPort (監聽連接埠) 設定移除,移除後欄位會呈現 (隨機)
ref. ROS WireGuard
2024年8月5日 星期一
Change Redhat Linux 9 /lib default size
在 9 之後,預設大小是記憶體的 20%,若要調整這個大小,可以在 /etc/fstab 加一行覆寫預設值
例如:
tmpfs /run tmpfs defaults,size=5G 0 0
systemd jounal 的預設存放位置就在這 /run/log/journal,
其預設最多使用所在 Partition 的 10%,若 Log 量多,希望保留多一多時間,
就需要調大 SystemMaxUse 及 RuntimeMaxUse 這兩個值
2024年6月7日 星期五
ESXi find what process lock file
ESXi 檔案刪不掉,出現 Device or resource busy
若檔案名稱是 windows-10-flat.vmdk
下此指令就可以知道那邊佔用
ps | grep `lsof | awk '/windows-10-flat.vmdk/ {print $1}'`
另外這個指令可以顯示機器名稱與 datastore 的檔案對應,
vim-cmd vmsvc/getallvms
改機器名稱,datastore 的檔案不會跟著改名,有可能出現與目錄名稱不一致的情況
2024年4月28日 星期日
Eazy way to install OpenWrt
隨便找一片 Linux ISO 開到 rescue 模式
fdisk -l 看一下硬碟位置,如果是 /dev/sda
curl https://repo.jing.rocks/openwrt/releases/23.05.3/targets/x86/generic/openwrt-23.05.3-x86-generic-generic-ext4-combined.img.gz | zcat > /dev/sda
一行解決,然後重開就可以了
上面的網址是 Japan Mirror 的網址,其他可參考 OpenWrt Downloads
Codeit repo for EL8/EL9
用這個 repo 的主要是要使用最新版的 Apache 或 nginx
dnf -y install https://repo.codeit.guru/codeit-repo-release.el8.rpm
or
dnf -y install https://repo.codeit.guru/codeit-repo-release.el9.rpm
dnf -y module reset httpd
dnf -y module enable httpd:codeit
若是從舊版升級上來,ssl error log 可能看到這樣的錯誤,服務起不來
AH01898: Unable to configure permitted SSL ciphers
SSL Library Error: error:0A0000B9:SSL routines::no cipher match
需要調整 ssl.conf 這兩行的設定
SSLCipherSuite "EECDH+AES128:EECDH+AES256:+SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RSA+3DES:!DSS"
SSLProxyCipherSuite "EECDH+AES128:EECDH+AES256:+SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RSA+3DES:!DSS"
原本是
SSLCipherSuite PROFILE=SYSTEM
SSLProxyCipherSuite PROFILE=SYSTEM
ref. CodeIT Technical blog
2024年4月21日 星期日
Stunnel
Stunnel 有點像 SSH tunnel,可以建立加密通道
原本未加密的協議,讓它走 Stunnel,就可以達到不改變協議,數據有加密的效果
以下用一個實例說明:
A 要 telnet B,IP 12.34.56.78,因 telnet 協議本身未加密,
若要讓 A 到 B 的傳輸數據加密,此時就可以用 Stunnel
建立憑證
cd /etc/stunnel
openssl req -new -x509 -days 9999 -nodes -out stunnel.pem -keyout stunnel.key
把 stunnel.pem 及 stunnel.key copy 到另一台
A 要配置 Stunnel client
/etc/stunnel/stunnel.conf 內容如下
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.key
client = yes
[telnet]
accept = 23
connect = 12.34.56.78:2323
B 要配置 Stunnel server
/etc/stunnel/stunnel.conf 內容如下
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.key
client = no
[telnet]
accept = 2323
connect = 127.0.0.1:23
配置後兩邊啟動服務
systemctl enable stunnel --now
在 A 就可以 telnet localhost (取代直連 telnet 12.34.56.78),
然後封包加密,送到 12.34.56.78:2323,
B 收到封包後解密,再送給 localhost:23
2024年4月16日 星期二
OpenVPN disconnect after 3.4.0
狀況是連上又斷線,一直重複 (repeat connect and disconnect)
我的環境 RouterOS 6.49.14 及 7.14.2 都遇到此狀況
很可能就是以下原因
OpenVPN Client 在 3.4.0 新增了一個功能 Security Level
Settings / ADVANCED SETTINGS (at bottom)
預設值是 Legacy
如果本來可以連,升版後不能連,把這邊改成 Insecure 可能就能連了
此功能將一些已不安全的協定禁用,若 Server 端暫時沒有新的支援,
Workaround 只能選 Insecure,不然就使用 3.3.7 版 ,意思一樣。
2024年4月4日 星期四
Chrome for Testing and Chromedriver
本文主拿它在 Linux 上跑 Chromedriver,當作爬蟲用途,
它是真的執行瀏覽器來跑結果,所以只要是瀏覽器可以看得到的,都爬得到
環境是 Rocky Linux 9,使用預設 GDM
# 建立環境
cd /tmp
wget https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.86/linux64/chrome-linux64.zip
wget https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.86/linux64/chromedriver-linux64.zip
cd /usr/local
unzip /tmp/chrome-linux64.zip
unzip /tmp/chromedriver-linux64.zip
cd /usr/bin
ln -s /usr/local/chromedriver-linux64/chromedriver .
ln -s /usr/local/chrome-linux64/chrome .
# 建立 chromdriver 啟動腳本
echo '#!/bin/bash' > /usr/local/bin/chromedriver.sh
echo 'chromedriver --log-path=/dev/shm/chromedriver.log --verbose --append-log --readable-timestamp --whitelisted-ips >> /dev/shm/chromedriver.output 2>&1 &' >> /usr/local/bin/chromedriver.sh
chmod 755 /usr/local/bin/chromedriver.sh
# 設定 GDM 登入後啟動上面的腳本,這邊的 username 請代換成自己的登入名稱
echo '#!/bin/bash' > /etc/gdm/PostLogin/Default
echo 'export DISPLAY=:0' >> /etc/gdm/PostLogin/Default
echo 'su pank /usr/local/bin/chromedriver.sh > /dev/null &' >> /etc/gdm/PostLogin/Default
chmod 755 /etc/gdm/PostLogin/Default
# 設定 iptables 可以導到 Local Port,for 外部 call API 用
echo net.ipv4.conf.all.route_localnet=1 >> /etc/sysctl.conf
sysctl -p
iptables -t nat -A PREROUTING -p tcp --dport 9515 -j DNAT --to 127.0.0.1:9515
到這邊建立完成,已可以另一台電腦調用上面建立的 Chrome 資源,
這邊使用 php-webdriver 測試,抓取 Bing 的網頁
composer require php-webdriver/webdriver
<?php
require __DIR__."/vendor/autoload.php";
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\WebDriverExpectedCondition;
$serverUrl = 'http://192.168.1.10:9515';
$driver = RemoteWebDriver::create($serverUrl, DesiredCapabilities::chrome());
$driver->get('https://bing.com');
$driver->wait(10,200)->until(WebDriverExpectedCondition::titleIs('Bing'));
echo $driver->getPageSource();
$driver->quit();
?>
Chromecast CLI Tools
catt go-chromecast 這兩套功能類似,可以投放到 Chromecast 的設備,各有優缺點 catt 可以指定 YouTube 網址,也可以指定本機或網路直連的網址 (例如 http://192.168.1.100/foo.mp3),參數較少 catt 在 You...
-
禁止 LINE 電腦版自動或強制更新的方法 LINE 電腦版啟動都會去連這個更新資訊檔 https://desktop.line-scdn.net/win/v1/real/update_info.json 內容大概長這樣 可以看出針對各版本的更新 type 有 force, ...
-
需先安裝 XZ Utils for Windows 把 xz.exe 放在 PATH 有指到的地方 curl -LOs https://github.com/rocky-linux/sig-cloud-instance-images/raw/Rocky-9.2.20230513...
-
RustDesk 使用上跟 Anydesk, Teamviewer 差不多,也是用 ID + Password 就可以連線 其優點是開源,可以自架 ID/Relay Server 在 Client 裝好的情況下,直接是可以使用的,預設應該是使用 RustDesk 的公共 Ser...
-
xrdp 是 Linux 版的 RDP server (遠端桌面) 它運作時需要 Xvnc 的 libvnc.so, 所以安裝時需要連同 VNC 一起安裝(只需 minimal) dnf -y install xrdp tigervnc-server-minimal system...
-
SQL injection 是個老東西,但 20 幾年過去,它依然健在! 在所有 Web 攻擊,弱點佔比仍然是最高的 NEITHNET 精選講座-資安教室:SQL injection - CYBERSEC 2021 臺灣資安大會 NEITHNET_SQL_injection.pp...
-
本例是從 8.0U3 升到 8.0U3d,若從更舊的版本升級,不確定是否適用 先把所有 VM 關機,進入維護模式 把 depot 升級檔 VMware-ESXi-8.0U3d-24585383-depot.zip 放到機器內 ssh ESXi 先查看 depot 有那些 Prof...
-
現在自架的 Mail Server 若沒有簽章,寄出的信件有很大的機會被擋或歸類在垃圾信 所以 SPF + DKIM 已經是必要的設定 環境 CentOS + Postfix,文中的域名均以 yourdomain.com 作為範例 安裝所需套件 yum -y install py...
-
RouterOS 在 7 版以後支援 WireGuard 註: WireGuard 在 Linux Kernel 5.6 版開始內建 設定滿簡單的,在選單 WireGuard New Interface,Private Key 及 Public Key 不用填,會自動產生 在 I...
-
Bracketed Paste Mode 是 Terminal 為了區分手動輸入及剪貼簿貼上的一種模式, 啟用此模式,貼上的文字區塊會被起始控制碼 ESC [ 200 ~ 及結束控制碼 ESC [ 201 ~ 包住 例如在編輯器貼上一段已經排版好的程式碼,若沒有啟用 Brack...
-
Google 意見回饋獎勵 是一個填問券賺 Google Play 回饋金的 APP, 問券問題都不多,有的甚至只有一題,基本的回饋是 4 元台幣,有的問券會回饋比較多 其問券是不定期出現的,一星期也許只有一兩則 Android 及 iOS 都有這個 APP