The Book of Secret Knowledge

repository·master·Indexed 11 days ago

https://github.com/trimstray/the-book-of-secret-knowledge

A community-driven repository of technical resources, including cheatsheets, manuals, and tools for DevOps, Security, and System Administration. It provides curated lists of shells, terminal managers, network diagnostics, DNS tools, HTTP benchmarking, SSL/TLS management, and system hardening utilities.

Tokens
29.1K
Snippets
55
Records
133
Agent score
50%

What's inside The Book of Secret Knowledge

  1. Overview of The Book of Secret Knowledge

    master
    The Book of Secret Knowledge is a curated collection of inspiring lists, manuals, cheatsheets, blogs, hacks, one-liners, CLI/web tools, and other technical resources. It is designed as a centralized knowledge base for professionals in fields such as System and Network administration, DevOps, Penetration Testing, and Security Research.
  2. Explore Curated Learning Resources

    master

    The Book of Secret Knowledge provides a collection of external links and resources categorized by domain to help developers and security professionals deepen their knowledge. These include:

    • CTF & Security: Vulnerable machine steps, CTF writeups, low-level challenge archives, and guides for Reverse Engineering/Malware analysis.
    • Networking & Web: Explanations of the C10K problem, MTU (Maximum Transmission Unit), HTTPS implementation, BGP (Border Gateway Protocol), DNS, and the 'What happens when you type a URL' flow.
    • Systems & Low-Level: CPU operation costs, building a simple database (SQLite clone), computer simulation, and SHA-256 algorithm visualizations.
    • Troubleshooting & Postmortems: Linux troubleshooting guides, the 'Five Whys' process for root cause analysis, and real-world postmortems of database and NFS outages.
  3. Make HTTP requests with `curl`

    master

    Basic Request with Headers

    Show response headers only, silently, ignoring SSL errors:

    curl -Iks https://www.google.com
    • -I: Show response headers only.
    • -k: Insecure connection (ignore SSL).
    • -s: Silent mode.

    Advanced Request with Redirects and User-Agent

    curl -Iks --location -X GET -A "x-agent" https://www.google.com
    • --location: Follow redirects.
    • -X: Set HTTP method.
    • -A: Set User-Agent.

    Request with Proxy

    curl -Iks --location -X GET -A "x-agent" --proxy http://127.0.0.1:16379 https://www.google.com
    • --proxy [socks5://|http://]: Set proxy server.

    Resume a download

    curl -o file.pdf -C - https://example.com/Aiju2goo0Ja2.pdf
    • -o: Write output to file.
    • -C: Resume the transfer.

    Find external IP address

    curl ipinfo.io
    curl ipinfo.io/ip
    curl icanhazip.com
    curl ifconfig.me/ip ; echo

    Repeat URL requests

    Using brace expansion:

    curl -ks https://example.com/?[1-20]

    Using a shell loop:

    for i in {1..20} ; do curl -ks https://example.com/ ; done
  4. Sterilize Bash history to remove credentials

    master

    Use the following function to clean your bash history of sensitive information like curl tokens, passwords, and proxy credentials. You can export it to run automatically via PROMPT_COMMAND.

    function sterile() {
    
    history | awk '$2 != "history" { $1=""; print $0 }' | egrep -vi "\
    curl\b+.*(-E|--cert)\b+.*\b*|\
    curl\b+.*--pass\b+.*\b*|\
    curl\b+.*(-U|--proxy-user).*:.*\b*|\
    curl\b+.*(-u|--user).*:.*\b*\
    .*(-H|--header).*(token|auth.*)\b+.*|\
    wget\b+.*--.*password\b+.*|\
    http.?://.+:.+@.*\
    " > $HOME/histbuff; history -r $HOME/histbuff;
    
    }
    
    export PROMPT_COMMAND="sterile"
  5. Test network connectivity and sockets

    master

    Test remote connection to a port

    Use timeout to check if a TCP or UDP port is reachable:

    timeout 1 bash -c "</dev/<proto>/<host>/<port>" >/dev/null 2>&1 ; echo $?
    • <proto>: tcp or udp.

    Read/Write to sockets using Bash

    exec 5<>/dev/tcp/<host>/<port>; cat <&5 & cat >&5; exec 5>&-
    timeout 1 bash -c "</dev/tcp/google.com/80" >/dev/null 2>&1 ; echo $?
  6. Manipulate stdout and stderr in Bash

    master

    Use process substitution to pipe stdout and stderr to different commands simultaneously.

    To redirect both to separate files while still printing both to the screen, use a combination of tee and file descriptor redirection.

    # Pipe stdout and stderr to separate commands
    some_command > >(/bin/cmd_for_stdout) 2> >(/bin/cmd_for_stderr)
    
    # Redirect stdout and stderr each to separate files and print both to the screen
    (some_command 2>&1 1>&3 | tee errorlog ) 3>&1 1>&2 | tee stdoutlog
  7. Use `dd` for data copying and redirection

    master

    Show progress during dd operations

    Since dd is often silent, you can view progress by sending a USR1 signal to the process:

    dd <dd_params> status=progress
    watch --interval 5 killall -USR1 dd

    Redirect output to a file

    echo "string" | dd of=filename
    dd <dd_params> status=progress
  8. Common Bash file and directory operations

    master

    Quick snippets for common filesystem tasks:

    • Backup a file: cp filename{,.orig}
    • Empty/Truncate a file: >filename
    • Delete files not matching an extension: rm !(*.foo|*.bar|*.baz)
    • Pass multi-line string to a file: Use cat << __EOF__ (overwrites) or cat >> filename << __EOF__ (appends).
    • Edit remote file via vim: vim scp://user@host//etc/fstab
    • Create and enter directory: mkd() { mkdir -p "$@" && cd "$@"; }
    • Rename uppercase to lowercase: rename 'y/A-Z/a-z/' *
    # Quickly backup a file
    cp filename{,.orig}
    
    # Empty a file (truncate to 0 size)
    >filename
    
    # Delete all files in a folder that don't match a certain file extension
    rm !(*.foo|*.bar|*.baz)
    
    # Pass multi-line string to a file
    cat > filename << __EOF__
    data data data
    __EOF__
    
    # Edit a file on a remote host using vim
    vim scp://user@host//etc/fstab
    
    # Create a directory and change into it at the same time
    mkd() { mkdir -p "$@" && cd "$@"; }
    
    # Convert uppercase files to lowercase files
    rename 'y/A-Z/a-z/' *
  9. Manage SSH connections and authentication

    master

    SSH Escape Sequences

    While in an active session, use ~ followed by a character:

    • ~. : Terminate connection.
    • ~B : Send a BREAK to the remote system.
    • ~C : Open a command line.
    • ~R : Request rekey (SSH protocol 2 only).
    • ~^Z: Suspend SSH.
    • ~# : List forwarded connections.
    • ~& : Background SSH.
    • ~~ : Send the escape character itself.

    Compare remote and local files

    ssh user@host cat /path/to/remotefile | diff /path/to/localfile -

    SSH through a jump host

    ssh -t reachable_host ssh unreachable_host

    Run a command on a remote host via file input

    cat > cmd.txt << __EOF__
    cat /etc/hosts
    __EOF__
    
    ssh host -l user $(<cmd.txt)

    Key Management

    • Get public key from private key: ssh-keygen -y -f ~/.ssh/id_rsa
    • List all fingerprints in known_hosts: ssh-keygen -l -f .ssh/known_hosts

    Explicit Authentication Methods

    • Password only: ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no user@remote_host
    • Publickey only: ssh -o PreferredAuthentications=publickey -o PubkeyAuthentication=yes -i id_rsa user@remote_host

    Port Forwarding

    Local Port Forwarding (Access remote service via local port):

    # Forward local 2250 to remote nmap.org:443
    ssh -L 2250:nmap.org:443 localhost

    Remote Port Forwarding (Expose local service to remote host):

    # Forward local 9051 to remote db.d.x:5432 through node.d.y
    ssh -nNT -R 9051:db.d.x:5432 node.d.y
    • -n: Redirect stdin from /dev/null.
    • -N: Do not execute a remote command.
    • -T: Disable pseudo-terminal allocation.
    ssh -L 2250:nmap.org:443 localhost
  10. Build your own System or Virtual Machine

    master

    Resources for low-level systems programming and OS development:

    • OS Development: Tutorials on creating an OS from scratch and the 'little book' about OS development.
    • Virtual Machines: Guides on how to write your own virtual machine (VM).
    • x86 Bare Metal: Minimal operating system examples for learning x86 system programming.
    • CPU Architecture: Implementation of the Scott CPU from "But How Do It Know?".