Foundations / Security fundamentals
Security fundamentals cheat sheet
Rank risks
| Term | Meaning |
|---|---|
| Asset | Something of value to protect |
| Threat | Something that can cause harm |
| Vulnerability | A weakness that lets the threat work |
| Likelihood, impact | Each scored 1 to 5 |
| Risk | Likelihood times impact, 1 to 25 |
| Control | An action that lowers likelihood, impact or both |
| Residual risk | What is left after a control. Someone must accept it |
| Preventive, detective, corrective | A control that stops the event, finds it, or limits the harm and restores |
| Administrative, technical, physical | A control made of a rule, of software or hardware, or of a thing in the real world |
Protect a file
| Task | Command or rule |
|---|---|
| Read the modes | Owner, group, others each hold r 4, w 2, x 1 |
| Make a file private | chmod 600 secret.txt |
| Hash a file | sha256sum rent.txt | tee rent.sha256 |
| Check the hash | sha256sum -c rent.sha256 |
| Back up with a date | cp -a docs backup/docs-$(date +%F) |
| Prove the restore | diff -r backup/docs-* restore-test/docs && echo "restore matches" |
Prove identity and limit access
| Task | Command or rule |
|---|---|
| Hash a password | hashlib.scrypt(password.encode(), salt=salt, n=2**14, r=8, p=1, dklen=32) |
| Compare in constant time | hmac.compare_digest(candidate, key) |
| Make a one-time code | hotp(key, int(now // step), digits) |
| Allow one permission | allowed("bo", "report:create") |
| Stop self-approval | allowed(user, "report:approve") and report["author"] != user |
| Make a file private from the start | (umask 077; echo "q3 findings" > report.txt) |
| Give the group read access | chmod 640 report.txt |
| Know the mode of a new file | A file starts at 666 and a folder at 777, with the umask bits removed: 666 with 027 removed is 640 |
| Run the access tests | python3 test_rbac.py |
Use cryptography
| Task | Command |
|---|---|
| Hash a file | openssl dgst -sha256 message.txt |
| Encrypt | openssl enc -aes-256-cbc -pbkdf2 -salt -in message.txt -out message.enc -pass env:KRPASS |
| Decrypt | openssl enc -d -aes-256-cbc -pbkdf2 -in message.enc -pass env:KRPASS |
| Make a private key | openssl genpkey -algorithm ed25519 -out private.pem |
| Get the public key | openssl pkey -in private.pem -pubout -out public.pem |
| Sign | openssl pkeyutl -sign -rawin -inkey private.pem -in message.txt -out message.sig |
| Verify | openssl pkeyutl -verify -rawin -pubin -inkey public.pem -in message.txt -sigfile message.sig |
| Read a certificate | openssl x509 -in cert.pem -noout -subject -issuer -dates |
| Start a test TLS server, on your own machine only | openssl s_server -accept 8643 -cert cert.pem -key cert.key -www > server.log 2>&1 & |
| See a TLS handshake (with the server running) | openssl s_client -connect 127.0.0.1:8643 -brief < /dev/null |
| Stop the test server | kill $! |
Detect and respond
| Task | Command or rule |
|---|---|
| Count failures by address | grep Failed auth.log | awk '{print $NF}' | sort | uniq -c | sort -rn |
| Run the rule | python3 detect.py |
| Set the rule | WINDOW = timedelta(minutes=5) and LIMIT = 5 |
| Name the response steps | Prepare, detect, contain, eradicate, recover, learn |
Model threats
| Term | Meaning |
|---|---|
| Trust boundary | A line where the level of trust changes |
| S Spoofing | Pretending to be someone else. Breaks authentication |
| T Tampering | Changing data or code. Breaks integrity |
| R Repudiation | Denying an act. Needs trustworthy logs |
| I Information disclosure | Data reaches the wrong reader. Breaks confidentiality |
| D Denial of service | System unavailable. Breaks availability |
| E Elevation of privilege | Doing what you may not do. Breaks authorisation |
| Task | Command |
|---|---|
| Check the threat table for gaps | python3 check.py threats.md User P1 S1 F1 F2 F3 |
Check a baseline
| Task | Command or rule |
|---|---|
| Run the checker | python3 baseline.py |
| Run it with another baseline | python3 baseline.py baseline2.json |
| Read the exit code | echo "exit code: $?". 1 means a failure |
| Close a home folder | chmod 750 ~ |
| Fail closed | A check that cannot run counts as FAIL |
Safety habits
- Keep impact in its own column. Review every high-impact row, whatever the likelihood.
- Keep backups to the 3-2-1 rule, with one copy offline. Test the restore.
- Never invent your own cryptography. Use Argon2id, scrypt or bcrypt for passwords and
hmac.compare_digestfor secrets. - Check access on the server, in one place, and deny by default. Use several layers (defence in depth). Review who holds what on a schedule.
- Send logs off the machine. Never write secrets into logs.
- Keep the baseline copy off the machine, or sign it.