2025年3月6日 星期四

Fast check domain is registered or free

一般都用 whois 檢查域名可否註冊

whois.joker.com 提供了簡易版,看結果是 free 還是 registered,簡單明暸

# whois -h whois.joker.com -p 4343 domain:7878.com
domain:7878.com registered

# whois -h whois.joker.com -p 4343 domain:78782222.com
domain:78782222.com free

也可以用 nc
# nc whois.joker.com 4343 < domain:7878.com
domain:7878.com registered

ref. Check Domain Availability

2025年3月5日 星期三

Linux moreutils

moreutils 這個套件,包含了一些有趣功能的小工具
可以透過 dnf install moreutils 或 apt install moreutils 安裝
套件包含以下工具,個人覺得比較實用的是 ifdata、pee、sponge、ts、vidir
/usr/bin/chronic
/usr/bin/combine
/usr/bin/errno
/usr/bin/ifdata
/usr/bin/ifne
/usr/bin/isutf8
/usr/bin/lckdo
/usr/bin/mispipe
/usr/bin/pee
/usr/bin/sponge
/usr/bin/ts
/usr/bin/vidir
/usr/bin/vipe
/usr/bin/zrun

chronic 用來隱藏正常執行結果的標準輸出
好像沒什麼用,使用 > /dev/null 可以達到一樣的效果

combine 布林合併兩分文件
combine file1 and file2 兩分文件都有則輸出行
combine file1 not file2 輸出只存在 file1 但不存在 file2 的行
combine file1 or file2 相當於 cat file1 file2
combine file1 xor file2 輸出只存在 file1 或 file2 的資料

errno 查詢 errno 名稱及描述

ifdata 直抓網路卡各項資訊
例如: ifdata -pa eth0 可以直接取出 IPv4 IP

ifne 標準輸入不為空時,執行後續指令
date | echo hello # 會出現 hello
true | echo hello # 不會出現 hello

isutf8 檢查檔案是否是合法 UTF-8 格式
現在系統已全面都是 UTF-8,好像沒什麼用了

lckdo 指定 lock file,避免指令重複執行
跟 flock 類似,man page 也建議使用 flock

mispipe 相當於 command1 | command2
和 pipe 的差異是使用 mispipe command1 command2 會回傳 command1 的 exit status

pee 複製標準輸入,pipe 給多支程式
類似 tee,tee 是將標準輸入寫到檔案,pee 是將它 pipe 給程式,可以多個,
通常用 pee 的情況也是要 pipe 給多個程式才需要它
例如: date | pee cat cat 執行結果可以看到兩個日期

sponge 這個指令會接收到所有 input 後才會輸出,可以做到同檔操作
例如: grep abc file | sponge file
若不使用 sponge,一般做法要兩行
grep abc file > file.tmp
mv file.tmp file

ts 在任何 input 上加上時間
這指令很好用,例如: ping 1.1.1.1 | ts

vidir 可以在 vi 模式進行檔案操作
例如刪除,改檔名,存檔後會真的刪除及改檔名

vipe 編輯 pipe
在 command1 | command2 中間,加入 vipe,command1 | vipe | command2,可以對資料異動後,再 pipe 給 command2

zrun 在不解開 .gz 的情況下,對解開的檔案進行操作
背景做法是解壓暫存檔,把暫存檔名當參數餵給 command
例如: zrun grep abc file1.gz

2025年3月4日 星期二

Gmail SPF Checking

發現 Gmail 檢查 SPF 較之前嚴格,不確定從何時開始的
之前未設定 SPF,自架的 Server 都可以寄,頂多就是進 Spam,
現在沒有設定 SPF 或有設定但未通過檢查的都會被退信

退信訊息範例
<<< 550-5.7.26 SPF [pank.org] with ip: [203.xx.xx.xx] = did not pass
此案例使用自己的域名信箱寄信

這樣對使用者會少了一些彈性,
如果設備只支援基本的 SMTP (未加密的 Port 25),解法大概就幾種:

1. 使用 ISP 的信箱,及 SMTP
2. Sender 用自己的域名,用自己架 SMTP,設好 SPF
3. Sender 用自己的域名,用 ISP 的 SMTP,SPF 比照 ISP 的設定,例如 HiNet 是 "v=spf1 redirect=spf.ms.hinet.net"

不建議用方法3,因為別人也可以透過 ISP 使用你的域名寄信

MySQL default sql_mode

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
若沒特別設定,MySQL 預設的 sql_mode 就是上面的值

若本來 sql_mode 是空的,要啟用預設值,有幾點要注意:
1. 當 INSERT/UPDATE 時,值不能超出欄位長度,不然會報錯 (STRICT_TRANS_TABLES)
2. 當 INSERT 時,若沒有指定到的欄位,沒有預設值,會報錯 (STRICT_TRANS_TABLES)
3. 當 INSERT/UPDATE 字串到數字類欄位,會報錯 (STRICT_TRANS_TABLES)
4. 以前能用的 GROUP BY 語法,啟用後可能無法使用 (ONLY_FULL_GROUP_BY)
5. 不能使用 0000-00-00 及 0000-00-00 00:00:00 這種日期時間 (NO_ZERO_IN_DATE,NO_ZERO_DATE)

Linux Kernel fs.protected_regular

這是 4.19 版才加入的安全性保護功能

protected_regular: This protection is similar to protected_fifos,
but it avoids writes to an attacker-controlled regular file,
where a program expected to create one.
When set to "0", writing to regular files is unrestricted.
When set to "1" don't allow O_CREAT open on regular files that we don't own in world writable sticky directories,
unless they are owned by the owner of the directory.
When set to "2" it also applies to group writable sticky directories.

RedHat 9 系的 Linux protected_regular 預設是 1
常見的目錄是 /tmp 及 /dev/shm
當目錄下面檔案 file owner 是 A,檔案權限是 -rw-rw-rw- (666) 當 B 去存取 file
有用到 O_CREAT 時,是不允許的,
但使用不同編輯器,編輯檔案後存檔,卻有不同樣的結果,
vim 編輯後可以寫入,nano 及 joe 都不能寫入,猜測跟檔案處理方式有關,vim 可能沒有調用 O_CREAT,所以可以寫入

Shell 的處理方式,例如以下動作也是可以,也就是沒有調用 O_CREAT
echo hello > file
echo world >> file

RedHat 要改這個預設值,是改這個檔
/usr/lib/sysctl.d/50-default.conf

Fast check domain is registered or free

一般都用 whois 檢查域名可否註冊 whois.joker.com 提供了簡易版,看結果是 free 還是 registered,簡單明暸 # whois -h whois.joker.com -p 4343 domain:7878.com domain:7878.com r...