Geavanceerd
Zoeken inLabs
Zo zoek je
  • Zoek een taak of een tool (lvm, selinux, @podman); filter op niveau en op boek of cursus.
  • Met een leeg zoekvak toont een filter alleen al de labs — bijvoorbeeld alle moeilijke labs van één cursus.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Lab 9.1IBM Cybersecurity Analyst, Hoofdstuk 9

Applied cryptography with OpenSSL: hashes, encryption, signatures and certificates

Niveau
Gemiddeld
45 min
Machines
any Linux or macOS shell with OpenSSL 3
Status
Nog niet begonnen

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Doel

Use the cryptography from the course with real tools. You prove a file was not changed (hash), protect a file with a password (symmetric encryption), exchange a secret with a public key, sign a release and check the signature, build a tiny certificate authority, and inspect the certificate of a real website. Every step answers one question an analyst gets in daily work.

Voordat je begint

Taken

  1. Integrity: make the SHA-256 hash of report.txt, change one character, and show that the hash changes completely.
  2. Symmetric: encrypt report.txt with AES-256 and a password (with PBKDF2 and many iterations), decrypt it, and compare.
  3. Asymmetric: make an RSA-3072 key pair for "Alice". Encrypt a short secret with Alice's public key; decrypt it with her private key.
  4. Signature: sign report.txt with Alice's private key (SHA-256), verify with her public key, then change the file and show that the check fails.
  5. PKI: make a small CA (key + self-signed certificate), a certificate request for lab.internal, sign it with the CA (with a SAN), and verify the chain.
  6. Real world: show the issuer, the validity dates and the SANs of the certificate of github.com.
  7. Passwords: explain in one line why passwords are stored with a slow hash (bcrypt/argon2) and not with SHA-256, and make a SHA-512-crypt hash with openssl passwd -6.

Controleer je werk

sha256sum report.txt
openssl dgst -sha256 -verify alice.pub -signature report.sig report.txt
openssl verify -CAfile ca.crt lab.crt
openssl x509 -in lab.crt -noout -ext subjectAltName
  • After the change in task 1 the hash looks totally different (avalanche effect).
  • The decrypted files match the originals (cmp prints nothing).
  • Verified OK for the original file, Verification failure after a change.
  • lab.crt: OK and the SAN shows DNS:lab.internal.

Hints

Toon de hints

Oplossing

Toon de oplossing
  1. Hashes.
    sha256sum report.txt
    sed 's/42/43/' report.txt > report2.txt && sha256sum report2.txt
  2. Symmetric encryption.
    openssl enc -aes-256-cbc -pbkdf2 -iter 200000 -salt -in report.txt -out report.enc
    openssl enc -d -aes-256-cbc -pbkdf2 -iter 200000 -in report.enc -out report.dec && cmp report.txt report.dec
  3. Public key encryption.
    openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out alice.key
    openssl pkey -in alice.key -pubout -out alice.pub
    printf 'db-password: S3cret\n' > secret.txt
    openssl pkeyutl -encrypt -pubin -inkey alice.pub -pkeyopt rsa_padding_mode:oaep -in secret.txt -out secret.enc
    openssl pkeyutl -decrypt -inkey alice.key -pkeyopt rsa_padding_mode:oaep -in secret.enc
    db-password: S3cret
  4. Sign and verify.
    openssl dgst -sha256 -sign alice.key -out report.sig report.txt
    openssl dgst -sha256 -verify alice.pub -signature report.sig report.txt
    Verified OK
    echo "x" >> report.txt; openssl dgst -sha256 -verify alice.pub -signature report.sig report.txt
    Verification failure
    sed -i '$d' report.txt
  5. A small CA and a server certificate.
    openssl req -x509 -newkey rsa:3072 -nodes -keyout ca.key -out ca.crt -days 365 -subj "/CN=Lab Root CA"
    openssl req -newkey rsa:2048 -nodes -keyout lab.key -out lab.csr -subj "/CN=lab.internal"
    printf 'subjectAltName=DNS:lab.internal\nextendedKeyUsage=serverAuth\n' > lab.ext
    openssl x509 -req -in lab.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out lab.crt -days 90 -extfile lab.ext
    openssl verify -CAfile ca.crt lab.crt
    lab.crt: OK
  6. A real certificate.
    openssl s_client -connect github.com:443 -servername github.com </dev/null 2>/dev/null | openssl x509 -noout -issuer -dates -ext subjectAltName
  7. Passwords: a fast hash like SHA-256 lets an attacker try billions of guesses per second on a GPU; bcrypt / argon2 / SHA-512-crypt are slow on purpose and use a salt.
    openssl passwd -6 'Correct-Horse-Battery'

Mijn notities

Nog geen notities.

Lessen voor dit lab

Commando's in dit lab