Documentation and cheat sheets

Quick references to keep open while you work. Search across every sheet at once.

Cybersecurity

OWASP Top 10 (2021)

The ten most critical web application security risks, and what each one means.

RiskWhat it means
A01Broken access control: users reach data or actions that are not theirs.
A02Cryptographic failures: sensitive data sent or stored without strong encryption.
A03Injection: input runs as SQL, shell or other code. Includes cross-site scripting.
A04Insecure design: security was not planned in from the start.
A05Security misconfiguration: default passwords, open storage, verbose errors.
A06Vulnerable and outdated components: old libraries with known holes.
A07Identification and authentication failures: weak logins, no MFA, bad sessions.
A08Software and data integrity failures: unverified updates and pipelines.
A09Security logging and monitoring failures: attacks go unnoticed.
A10Server-side request forgery: the server is tricked into calling internal addresses.

Cybersecurity

Incident response steps

The NIST incident response life cycle, in the order you work through it.

StepWhat you do
PreparationHave plans, contacts, tools and backups ready before anything happens.
Detection & analysisSpot the incident, confirm it and judge how serious it is.
ContainmentStop the spread: isolate machines, block accounts or addresses.
EradicationRemove the cause: malware, backdoors and compromised accounts.
RecoveryRestore systems from clean backups and watch them closely.
Lessons learnedWrite down what happened and fix the gaps so it does not repeat.

Networking

Common ports

Ports you will meet on servers, scans and firewall rules.

PortService
20/tcp · FTP dataFile transfer data channel. Unencrypted: prefer SFTP.
21/tcp · FTPFile transfer control. Sends passwords in clear text.
22/tcp · SSHSecure remote login and file copy (SFTP, SCP).
23/tcp · TelnetOld remote login without encryption. Disable it and use SSH.
25/tcp · SMTPEmail delivery between mail servers.
53/tcp/udp · DNSDomain name lookups.
67/udp · DHCPHands out IP addresses on a local network.
80/tcp · HTTPUnencrypted web traffic. Redirect it to HTTPS.
110/tcp · POP3Downloading email (old, unencrypted).
123/udp · NTPTime synchronization.
143/tcp · IMAPReading email on the server (unencrypted).
161/udp · SNMPNetwork device monitoring. Change default community strings.
389/tcp · LDAPDirectory services such as Active Directory.
443/tcp · HTTPSEncrypted web traffic (HTTP over TLS).
445/tcp · SMBWindows file sharing. Never expose it to the internet.
587/tcp · SMTP submissionSending email from an app or mail client, with TLS.
993/tcp · IMAPSReading email over TLS.
1433/tcp · MS SQLMicrosoft SQL Server database.
3306/tcp · MySQLMySQL and MariaDB databases. Keep it private.
3389/tcp · RDPWindows Remote Desktop. A favorite target: put it behind a VPN.
5432/tcp · PostgreSQLPostgreSQL database. Keep it private.
6379/tcp · RedisRedis cache. Often left open without a password.
8080/tcp · HTTP altCommon port for development servers and proxies.
27017/tcp · MongoDBMongoDB database. Keep it private.

Software development

HTTP status codes

What the numbers in API responses and browser errors mean.

CodeMeaning
200 OKThe request worked.
201 CreatedA new resource was created.
204 No ContentIt worked and there is nothing to send back.
301 Moved PermanentlyThe address changed for good; follow the new one.
304 Not ModifiedYour cached copy is still current.
400 Bad RequestThe request is malformed or invalid.
401 UnauthorizedNot signed in, or the token is missing or expired.
403 ForbiddenSigned in but not allowed to do this.
404 Not FoundNothing exists at this address.
409 ConflictThe request clashes with the current state, such as a duplicate.
429 Too Many RequestsA rate limit was reached; wait and retry.
500 Internal Server ErrorSomething broke on the server.
502 Bad GatewayA server in the middle got a bad answer from the next one.
503 Service UnavailableThe server is overloaded or down for maintenance.

Software development

Git command cheat sheet

The Git commands that cover almost every working day.

CommandWhat it does
git clone <url>Copy a repository to your computer.
git statusSee what changed and what is staged.
git add -pStage changes piece by piece after reviewing them.
git commit -m "message"Save a snapshot with a message.
git switch -c featureCreate a branch and move to it.
git pull --rebaseGet the latest changes and replay yours on top.
git push -u origin featureUpload your branch and track it.
git log --oneline --graphShow a compact history with branches.
git diffShow changes that are not staged yet.
git stashPut unfinished changes aside for later.
git revert <commit>Undo a commit with a new commit, keeping history.

Cloud & Linux

Linux command cheat sheet

The commands you will use every day on a Linux server.

CommandWhat it does
pwdShow the folder you are in.
ls -laList all files with details, including hidden ones.
cd /var/logMove to another folder.
cat file.txtPrint a file.
less file.txtRead a long file page by page.
grep -i error app.logFind lines containing a word, ignoring case.
chmod 755 script.shChange file permissions.
chown user:group fileChange the owner of a file.
ps auxList running processes.
topWatch CPU and memory use live.
df -hShow free disk space.
sudo apt update && sudo apt upgradeInstall updates on Debian or Ubuntu.
ssh user@hostConnect to a remote server.
tail -f /var/log/syslogFollow a log file as it grows.

Cloud & Linux

Docker and Kubernetes commands

Build, run and debug containers, then manage them on a cluster.

CommandWhat it does
docker build -t app .Build an image from the Dockerfile in this folder.
docker run -p 8080:80 appRun the image and expose port 80 as 8080.
docker psList running containers.
docker logs -f <id>Follow a container's output.
docker exec -it <id> shOpen a shell inside a running container.
kubectl get podsList pods in the current namespace.
kubectl describe pod <name>Show details and recent events for a pod.
kubectl logs <pod>Print a pod's logs.
kubectl apply -f deploy.yamlCreate or update resources from a file.
kubectl rollout undo deployment/appRoll back to the previous version.

Networking

DNS record types

The records you will see in a DNS zone and what each one does.

RecordPurpose
AMaps a name to an IPv4 address.
AAAAMaps a name to an IPv6 address.
CNAMEMakes one name an alias of another name.
MXSays which mail servers receive email for the domain.
TXTFree text, used for SPF, DKIM and domain ownership checks.
NSLists the name servers that are in charge of the domain.
SOAStart of authority: the zone's main settings and serial number.
PTRReverse lookup: maps an IP address back to a name.
SRVPoints to the host and port of a specific service.
CAALimits which certificate authorities may issue certificates.

Networking

CIDR and subnet mask table

Prefix length, subnet mask, total addresses and usable hosts.

PrefixMask · total · usable
/8255.0.0.0 · 16,777,216 · 16,777,214
/16255.255.0.0 · 65,536 · 65,534
/20255.255.240.0 · 4,096 · 4,094
/22255.255.252.0 · 1,024 · 1,022
/24255.255.255.0 · 256 · 254
/25255.255.255.128 · 128 · 126
/26255.255.255.192 · 64 · 62
/27255.255.255.224 · 32 · 30
/28255.255.255.240 · 16 · 14
/29255.255.255.248 · 8 · 6
/30255.255.255.252 · 4 · 2
/32255.255.255.255 · 1 · 1

Networking

Network troubleshooting commands

Commands to find out where a connection breaks. Only test systems you own or have permission to test.

CommandWhat it does
ping -c 4 example.comCheck that a host answers, and how long it takes.
traceroute example.comShow every router a packet passes on its way.
dig example.com ALook up DNS records for a name.
nslookup example.comA simpler DNS lookup that works on most systems.
curl -I https://example.comFetch only the response headers of a web page.
ip addrShow your network interfaces and IP addresses.
ip routeShow where traffic is sent, including the default gateway.
ss -tulpnList listening ports and the programs that opened them.
nmap -sV 192.168.1.10Scan a host you own to see open ports and service versions.
tcpdump -i eth0 port 53Capture DNS packets on an interface.

Software development

SQL cheat sheet

The statements behind most database work. Always pass user input as parameters, never by joining strings.

StatementWhat it does
SELECT name, email FROM users;Read columns from a table.
SELECT * FROM orders WHERE total > 100;Filter rows with a condition.
ORDER BY created_at DESC LIMIT 10Sort the result and keep only the first rows.
INSERT INTO users (name) VALUES ($1);Add a row. $1 is a parameter filled in safely.
UPDATE users SET name = $1 WHERE id = $2;Change existing rows. Never forget the WHERE.
DELETE FROM sessions WHERE expires_at < now();Remove rows that match.
JOIN orders ON orders.user_id = users.idCombine rows from two tables that share a value.
SELECT status, count(*) FROM orders GROUP BY status;Group rows and count or sum them.
CREATE INDEX ON users (email);Speed up searches on a column.
BEGIN; ... COMMIT;Run several statements as one all-or-nothing transaction.

Software development

Regular expression cheat sheet

Patterns for searching and validating text. Try them in the Regex tester tool.

PatternMatches
.Any single character except a new line.
\d \w \sA digit, a word character, a whitespace character.
^ $The start and the end of the text.
\bA word boundary.
* + ?Zero or more, one or more, zero or one of the previous item.
{2,4}Between 2 and 4 of the previous item.
[abc] [^abc]One of the listed characters, or any character not listed.
(cat|dog)A group that matches cat or dog and remembers it.
(?:cat|dog)The same group without remembering it.
(?=x)A lookahead: only if x follows, without using it up.

Cloud & Linux

Bash scripting basics

The building blocks of shell scripts for automation.

SyntaxMeaning
#!/usr/bin/env bashFirst line: which program runs the script.
set -euo pipefailStop on errors, unset variables and failed pipes. A safer default.
name="web01"; echo "$name"Set and use a variable. Quote it to keep spaces safe.
if [ -f "$file" ]; then ... fiRun commands only if a condition is true, here if a file exists.
for f in *.log; do ... doneRepeat commands for every item in a list.
cmd1 | cmd2Send the output of one command into another.
cmd > out.txt cmd >> out.txtWrite output to a file, replacing it or appending to it.
$?The exit code of the last command. 0 means success.
cmd1 && cmd2 cmd1 || cmd2Run the second only if the first succeeds, or only if it fails.
chmod +x script.sh && ./script.shMake a script executable and run it.

Cloud & Linux

Cron schedule syntax

Five fields: minute, hour, day of month, month and day of week. Try them in the Cron explainer.

ExpressionRuns
* * * * *Every minute.
*/15 * * * *Every 15 minutes.
0 * * * *At the start of every hour.
0 2 * * *Every day at 02:00.
30 9 * * 1-5At 09:30 on weekdays, Monday to Friday.
0 0 1 * *At midnight on the first day of every month.
0 0 * * 0At midnight every Sunday.
0 8,20 * * *Twice a day, at 08:00 and 20:00.

Cloud & Linux

Linux permission modes

Common chmod values and when to use them. Read is 4, write is 2, execute is 1.

ModeMeaning
777 rwxrwxrwxEveryone can do everything. Almost never correct.
755 rwxr-xr-xOwner full access, others read and run. Typical for programs and folders.
750 rwxr-x---Owner full access, group read and run, others nothing.
700 rwx------Only the owner has any access. Good for private folders.
664 rw-rw-r--Owner and group can edit, others can read.
644 rw-r--r--Owner can edit, everyone can read. Typical for web files.
640 rw-r-----Owner edits, group reads. Good for config files with passwords.
600 rw-------Only the owner can read and write. Required for SSH private keys.
400 r--------Read-only for the owner. Good for keys that never change.

Cybersecurity

Web security headers and cookie flags

Response headers that make browsers enforce safer behavior.

Header or flagWhat it protects
Content-Security-PolicyLimits where scripts, images and frames may load from. Strong protection against XSS.
Strict-Transport-SecurityTells browsers to always use HTTPS for this site.
X-Content-Type-Options: nosniffStops browsers from guessing file types and running disguised scripts.
X-Frame-Options: DENYPrevents other sites from showing yours in a frame (clickjacking).
Referrer-PolicyControls how much of your address is sent to other sites.
Permissions-PolicyTurns off browser features such as camera or location for the page.
Set-Cookie: HttpOnlyHides the cookie from JavaScript, so XSS cannot steal it.
Set-Cookie: SecureSends the cookie only over HTTPS.
Set-Cookie: SameSite=LaxLimits cookies on cross-site requests, reducing CSRF.
Access-Control-Allow-OriginCORS: which other websites may read responses from your API.

Cybersecurity

Cryptography at a glance

Which algorithm to use for which job, and which ones to avoid.

AlgorithmWhat it is and when to use it
AES-256-GCMFast symmetric encryption for data at rest and in transit. Same key encrypts and decrypts.
ChaCha20-Poly1305A modern symmetric cipher, great on phones without hardware AES.
RSA 2048+Public-key encryption and signatures. Slower, mostly used to exchange keys.
ECDSA / Ed25519Compact public-key signatures with smaller keys than RSA.
Diffie-HellmanLets two parties agree on a shared secret over an open channel.
SHA-256A cryptographic hash for fingerprints and integrity checks. Not for passwords.
HMACA hash mixed with a secret key to prove a message was not changed.
bcrypt / Argon2Slow, salted hashes made for storing passwords.
TLS 1.3The protocol behind HTTPS. Use it and disable old versions.
MD5 / SHA-1Broken for security use. Never use them for signatures or passwords.

Cybersecurity

Common attacks glossary

Plain-language definitions of the attacks you will hear about most.

AttackWhat it is
PhishingFake messages that trick people into giving up passwords or clicking harmful links.
RansomwareMalware that locks files and demands payment to unlock them.
DDoSFlooding a service with traffic from many machines so real users cannot get in.
Man-in-the-middleSecretly sitting between two parties to read or change their messages.
Brute forceTrying many passwords until one works.
Credential stuffingTrying leaked username and password pairs on other sites.
Zero-dayAn attack on a flaw the vendor does not know about yet, so no patch exists.
Supply chain attackCompromising a supplier or software package to reach its customers.
Privilege escalationTurning limited access into administrator access.
Social engineeringManipulating people rather than computers to get access.
Insider threatHarm caused by someone with legitimate access, on purpose or by accident.

Cybersecurity

MITRE ATT&CK tactics

The 14 stages attackers move through, a shared language for defenders.

TacticThe attacker's goal
ReconnaissanceGather information about the target.
Resource developmentSet up infrastructure, accounts and tools for the attack.
Initial accessGet a first foothold, for example through phishing.
ExecutionRun malicious code on the system.
PersistenceKeep access after restarts and password changes.
Privilege escalationGain higher permissions.
Defense evasionAvoid being detected or blocked.
Credential accessSteal account names and passwords.
DiscoveryLearn about the environment and what is in it.
Lateral movementMove from one system to others on the network.
CollectionGather the data of interest.
Command and controlCommunicate with compromised systems to direct them.
ExfiltrationSteal the data out of the network.
ImpactDisrupt, destroy or lock systems and data.