This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| muf:it:recipies [2025/09/23 23:29] – [DokuVimNG edit] mfulz | muf:it:recipies [2025/09/23 23:39] (current) – [DokuVimNG edit] mfulz | ||
|---|---|---|---|
| Line 25: | Line 25: | ||
| === Git I'll find you :P === | === Git I'll find you :P === | ||
| - | ==== Full-history regex scan (mirror clone) | + | Git I'll find you :P |
| + | Full-history regex scan (mirror clone) | ||
| Below is a ready-to-run shell helper that clones a repo as a mirror (so all refs/tags are included) and executes regex searches across all commits / blobs. | Below is a ready-to-run shell helper that clones a repo as a mirror (so all refs/tags are included) and executes regex searches across all commits / blobs. | ||
| Save as scan_public_repo_regex.sh, | Save as scan_public_repo_regex.sh, | ||
| + | |||
| + | < | ||
| REPO_URL=" | REPO_URL=" | ||
| Line 37: | Line 40: | ||
| if [[ -z " | if [[ -z " | ||
| cat << | cat << | ||
| - | Usage: $0 "" | + | Usage: $0 < |
| Example: | Example: | ||
| - | $0 https:// | + | $0 https:// |
| + | ' | ||
| USAGE | USAGE | ||
| exit 2 | exit 2 | ||
| Line 59: | Line 63: | ||
| echo "[] Running git grep across all commits (pattern):" | echo "[] Running git grep across all commits (pattern):" | ||
| - | echo " | + | echo " $PATTERN" |
| if [[ -n " | if [[ -n " | ||
| echo "[] Exclude pattern:" | echo "[] Exclude pattern:" | ||
| - | echo " | + | echo " $EXCLUDE" |
| fi | fi | ||
| echo | echo | ||
| - | Try PCRE first (git grep -P). If -P not available, | + | Try PCRE first; fallback |
| set +e | set +e | ||
| - | git --version > /dev/null 2>&1 | ||
| - | |||
| - | Run search per commit set (git grep supports listing multiple commits) | ||
| - | |||
| - | Use --text to scan binaryish files as text and --no-color for clean output | ||
| - | |||
| if git grep -P -n --text --heading --break -e " | if git grep -P -n --text --heading --break -e " | ||
| - | |||
| - | PCRE supported | ||
| - | |||
| if [[ -n " | if [[ -n " | ||
| - | git grep -P -n --text --heading --break -e " | + | git grep -P -n --text --heading --break -e " |
| + | | grep -P -v --color=never " | ||
| else | else | ||
| git grep -P -n --text --heading --break -e " | git grep -P -n --text --heading --break -e " | ||
| Line 86: | Line 82: | ||
| else | else | ||
| echo "[*] git grep -P not available or failed, falling back to POSIX regex and grep filter." | echo "[*] git grep -P not available or failed, falling back to POSIX regex and grep filter." | ||
| - | |||
| - | Fallback: git grep -G then filter with grep -P if available or grep -E | ||
| - | |||
| if [[ -n " | if [[ -n " | ||
| - | git grep -n --text --heading --break -G -e " | + | git grep -n --text --heading --break -G -e " |
| + | | ( grep -P -v --color=never " | ||
| else | else | ||
| git grep -n --text --heading --break -G -e " | git grep -n --text --heading --break -G -e " | ||
| Line 100: | Line 94: | ||
| echo "[*] Also scanning commit messages (git log --grep)..." | echo "[*] Also scanning commit messages (git log --grep)..." | ||
| if [[ -n " | if [[ -n " | ||
| - | + | git log --all --pretty=fuller --grep=" | |
| - | commit messages: find matches and exclude commits containing exclude pattern | + | | awk '/ |
| - | + | | xargs -I{} bash -c 'git show --pretty=fuller {} || true' | |
| - | git log --all --pretty=fuller --grep=" | + | | ( grep -P -v --color=never " |
| else | else | ||
| git log --all --pretty=fuller --grep=" | git log --all --pretty=fuller --grep=" | ||
| Line 110: | Line 104: | ||
| echo | echo | ||
| echo "[*] Done. Temp dir: $TMP (auto-removed on exit)." | echo "[*] Done. Temp dir: $TMP (auto-removed on exit)." | ||
| + | </ | ||
| - | + | Quick usage examples | |
| - | ==== Quick usage examples | + | |
| Literal / case-insensitive search for EXACT_STRING (YOUR-EXACT-STRING): | Literal / case-insensitive search for EXACT_STRING (YOUR-EXACT-STRING): | ||
| - | ./ | + | < |
| + | ./ | ||
| + | ' | ||
| + | </ | ||
| Regex search: find keys like user: username or user = username (case-insensitive): | Regex search: find keys like user: username or user = username (case-insensitive): | ||
| - | ' | + | < |
| + | ' | ||
| + | </ | ||
| Search for password variants (password, passwd, pwd) next to a value: | Search for password variants (password, passwd, pwd) next to a value: | ||
| + | |||
| + | < | ||
| ' | ' | ||
| + | </ | ||
| Combined: look for any auth/ | Combined: look for any auth/ | ||
| + | |||
| + | < | ||
| ' | ' | ||
| + | </ | ||
| + | Your “SEARCH FOR but EXCLUDE exact username/ | ||
| - | Your " | + | < |
| ' | ' | ||
| ' | ' | ||
| + | </ | ||
| This finds user: < | This finds user: < | ||
| - | ==== Notes on the examples & intuition | + | Notes on the examples & intuition |
| Why so many variants? Humans store credentials in many ways. Use these families: | Why so many variants? Humans store credentials in many ways. Use these families: | ||
| Line 163: | Line 168: | ||
| Too much noise → restrict file types (*.env, *.yaml, *.json, *.tf, *.ini). | Too much noise → restrict file types (*.env, *.yaml, *.json, *.tf, *.ini). | ||
| - | ==== Regex cheat-sheet (PCRE, case-insensitive) | + | Regex cheat-sheet (PCRE, case-insensitive) |
| Simple literal (case-insensitive) | Simple literal (case-insensitive) | ||
| + | |||
| + | < | ||
| (? | (? | ||
| + | </ | ||
| Keys + value (JSON/ | Keys + value (JSON/ | ||
| + | |||
| + | < | ||
| (? | (? | ||
| (? | (? | ||
| + | </ | ||
| Auth/ | Auth/ | ||
| - | (? | + | < |
| + | (? | ||
| + | </ | ||
| Base64-ish blobs (suspicious but noisy) | Base64-ish blobs (suspicious but noisy) | ||
| + | |||
| + | < | ||
| [A-Za-z0-9+/ | [A-Za-z0-9+/ | ||
| + | </ | ||
| URL with embedded basic auth (user: | URL with embedded basic auth (user: | ||
| + | |||
| + | < | ||
| (? | (? | ||
| + | </ | ||
| + | “SEARCH FOR but EXCLUDE” (negative lookahead) | ||
| - | " | + | < |
| (? | (? | ||
| (? | (? | ||
| + | </ | ||
| - | + | Practical tips | |
| - | ==== Practical tips ==== | + | |
| Use literal -F for your exact known string first — zero false positives. | Use literal -F for your exact known string first — zero false positives. | ||
| Line 206: | Line 223: | ||
| Limit file types to reduce noise: | Limit file types to reduce noise: | ||
| + | |||
| + | < | ||
| git grep -P -n -I --heading --break -e ' | git grep -P -n -I --heading --break -e ' | ||
| + | </ | ||
| Inspect matches precisely: | Inspect matches precisely: | ||
| + | |||
| + | < | ||
| git show < | git show < | ||
| + | </ | ||
| - | + | Example workflows | |
| - | ==== Example workflows | + | |
| Exact-string quick check (literal): | Exact-string quick check (literal): | ||
| - | ./ | + | < |
| + | ./ | ||
| + | ' | ||
| + | </ | ||
| Password-like keys but ignore known placeholder secret: | Password-like keys but ignore known placeholder secret: | ||
| - | ./ | + | < |
| + | ./ | ||
| + | ' | ||
| + | </ | ||
| Any API keys/ | Any API keys/ | ||
| - | ./ | + | < |
| + | ./ | ||
| + | ' | ||
| + | </ | ||
| - | ==== Safety / assurance notes ==== | + | Safety / assurance notes |
| This script only reads repo objects; it does not modify the remote. | This script only reads repo objects; it does not modify the remote. | ||
| Line 239: | Line 269: | ||
| PCRE-first: the script attempts -P and falls back if unavailable. | PCRE-first: the script attempts -P and falls back if unavailable. | ||
| - | |||
| - | * CONTENT HIER * | ||
| ===== OS Tricks ===== | ===== OS Tricks ===== | ||