所有匹配主题的 Gist security

最后活跃于 10 months ago
這段 Bash 腳本設定了 環境變數(如 PATH 和 TZ 時區為 台北時間),然後執行 arp-scan 指令來掃描本地網路(--localnet)的 所有設備的 MAC 和 IP 地址。此腳本適用於 網路管理、設備偵測、安全監控 或 尋找局域網內的未知設備,但需要 root 權限 才能執行 arp-scan。
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 / Dnsmasq 設定與網路管理

0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
這份 dnsmasq 設定檔 用於 管理 DNS 和 DHCP 服務,提供 本機網路名稱解析、靜態 IP 配置、DNS 轉發、快取與封鎖特定域名。它設定了 Google、Hinet 作為上游 DNS,開啟 DNS 查詢日誌,並定義 DHCP 位址範圍、靜態 IP 綁定與特定域名解析。適用於 內部網路架構、加速 DNS 解析、提升隱私安全及廣告封鎖 等場景。
1 bogus-priv # Block fake private IP responses
2 no-resolv # Ignore /etc/resolv.conf for upstream DNS
3 dns-forward-max=150 # Limit parallel DNS queries to 150
4 clear-on-reload # Clear cache when dnsmasq reloads
5 domain-needed # Ignore queries without a domain name
6 no-negcache # Do not cache negative (non-existent) DNS responses
7 no-poll # Do not poll /etc/resolv.conf for changes
8 strict-order # Use upstream DNS servers in the order they are listed
9
10 # AdGuard DNS 封鎖廣告和追蹤器。

timmy / 系統日誌清理與維護

0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
這個 Bash 腳本用於 清理 Linux 系統的日誌檔案,主要包括 身份驗證日誌 (auth.log)、登入歷史 (wtmp, btmp, lastlog)、系統日誌 (syslog)、郵件日誌 (mail.log),並刪除舊的壓縮日誌 (.gz) 以釋放空間。此外,它會 重設失敗登入記錄 (faillog),確保 lastlog 權限正確,適用於 系統維護、隱私保護及釋放伺服器磁碟空間。
1 #!/bin/bash
2
3 # Define log file paths
4 AUTH_LOG="/var/log/auth.log"
5 BTMP_LOG="/var/log/btmp"
6 WTMP_LOG="/var/log/wtmp"
7 LASTLOG="/var/log/lastlog"
8 SYSLOG="/var/log/syslog"
9 MAIL_LOG="/var/log/mail.log"

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
最后活跃于 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
最后活跃于 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

timmy / Streamlit 使用者驗證系統

0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
此應用程式使用 streamlit_authenticator 進行使用者登入、登出及密碼重設,並支援 YAML 和 JSON 兩種格式作為驗證資料存儲。適用於需要帳戶管理的 Streamlit Web 應用,確保只有授權使用者可以存取內容。
1 import json
2 from abc import ABC, abstractmethod
3
4 import streamlit as st
5 import streamlit_authenticator as stauth
6 import yaml
7
8
9 # 策略介面
10 class DataHandlerStrategy(ABC):