timmy / 使用 arp-scan 掃描區域網路中的設備
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
| 1 | #!/bin/bash |
| 2 | |
| 3 | # 定義預設的配置設定 |
| 4 | SHELL=/bin/sh |
| 5 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
| 6 | TZ='Asia/Taipei' |
| 7 | |
| 8 | # 將配置設定寫入環境變數 |
| 9 | export PATH |
| 10 | export LANG=en_US.UTF-8 |
timmy / 強化的 iptables 防火牆規則設定
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
這個 iptables 防火牆腳本 用於 強化伺服器的網路安全,透過 允許合法流量(如 SSH、HTTP/HTTPS)並封鎖未授權連線,同時防禦各種攻擊(如 暴力破解、SYN Flood、埠掃描、DoS)。此外,它會 記錄異常流量 以便後續分析,並將規則儲存至 /etc/iptables/rules.v4,確保設定在重啟後仍生效。適用於 企業伺服器、內部網路防護及個人伺服器安全強化。
| 1 | #!/bin/bash |
| 2 | |
| 3 | # === Basic Settings === |
| 4 | |
| 5 | # Clear all existing rules |
| 6 | iptables -F |
| 7 | iptables -X |
| 8 | iptables -Z |
| 9 | |
| 10 | # Set default policies: drop all incoming and forwarding traffic, allow outgoing |
timmy / 使用 ipset 建立台灣 IP 位址集
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
這個 Bash 腳本用於 建立並更新 ipset 規則,將台灣的 IP 網段加入名為 taiwan_ips 的集合,以便在 iptables 防火牆 中使用。它會從 GitHub 下載最新的 台灣 IP 清單 (tw.txt),然後解析其中的 IPv4 網段 並加入 ipset,最後可用於 限制 SSH 存取、流量過濾或強化網路安全,適用於 伺服器管理、防禦異地登入或阻擋非台灣 IP 連線。
| 1 | #!/bin/bash |
| 2 | |
| 3 | # Delete the existing taiwan_ips ipset collection if it exists |
| 4 | ipset destroy taiwan_ips |
| 5 | |
| 6 | # Create a new taiwan_ips ipset collection |
| 7 | ipset create taiwan_ips hash:net |
| 8 | |
| 9 | # Download the Taiwan IP range file using wget (commented out) |
| 10 | wget https://github.com/Loyalsoldier/geoip/raw/release/text/tw.txt -O tw.txt |
timmy / 清理未使用的 SSH 暫存檔案
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
這個 Bash 腳本用於 清理 /tmp 目錄中無效的 SSH 相關暫存檔案。它會搜尋所有以 ssh- 開頭的檔案或目錄,使用 lsof 檢查是否有行程正在使用它們,若未被使用則刪除,以確保 /tmp 目錄保持乾淨。這適用於 系統維護、提升伺服器安全性,防止長時間未使用的 SSH 暫存文件佔用空間。
| 1 | #!/bin/bash |
| 2 | |
| 3 | # 定義要檢查的目錄 |
| 4 | TMP_DIR="/tmp" |
| 5 | |
| 6 | # 查找所有以 ssh- 開頭的文件或目錄 |
| 7 | for file in "$TMP_DIR"/ssh-*; do |
| 8 | # 如果沒有匹配的文件,跳過 |
| 9 | if [ ! -e "$file" ]; then |
| 10 | continue |
timmy / 建立並配置新使用者帳戶(含 sudo 權限)
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
這個 Bash 腳本用於根據輸入的使用者名稱,建立一個新的使用者帳號,並提示輸入密碼後設定該密碼,然後將該使用者加入 sudo 群組,同時更新 sudoers 檔案以允許該使用者無密碼執行 sudo 指令,方便日後進行系統管理。
| 1 | #!/bin/bash |
| 2 | |
| 3 | # Check if a username was provided as an argument |
| 4 | if [ $# -ne 1 ]; then |
| 5 | echo "Error: Please provide a username as an argument." |
| 6 | exit 1 |
| 7 | fi |
| 8 | |
| 9 | # Get the username from the argument |
| 10 | username="$1" |
timmy / JWT 令牌生成與驗證
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
這段 Python 程式碼使用 JWT(JSON Web Token)來實現 身份驗證與授權。它首先根據 使用者資訊(ID、帳號)及 自訂金鑰 生成一個 有效期限為 30 分鐘 的 JWT,然後透過相同的金鑰來驗證 Token 的有效性,並解碼出原始資料。此機制適用於 使用者登入授權、API 驗證及安全通信,可確保請求的合法性並防止未授權的存取。
| 1 | import jwt |
| 2 | import datetime |
| 3 | |
| 4 | # 假設的使用者資訊 |
| 5 | user = { |
| 6 | 'id': 123, |
| 7 | 'username': 'exampleUser' |
| 8 | } |
| 9 | |
| 10 | # 生成 JWT |
timmy / 啟用 SMB 不安全來賓存取與禁用安全簽名
1 喜欢
0 派生
1 文件
最后活跃于 10 months ago
此登錄檔修改 SMB 設定,允許不安全的來賓存取 (AllowInsecureGuestAuth),並禁用安全簽名 (RequireSecuritySignature),適用於舊設備相容性需求,但可能降低安全性。
| 1 | Windows Registry Editor Version 5.00 |
| 2 | |
| 3 | [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters] |
| 4 | "AllowInsecureGuestAuth"=dword:00000001 |
| 5 | "RequireSecuritySignature"=dword:00000000 |