XUT_ / COURSES / CYBER SECURITY 101

PGP and GPG

PGP significa Pretty Good Privacy. Es software que implementa la encriptación de archivos, realizar firmas digitales y más. GnuPG o GPG es una implementación de código abierto del estándar OpenPGP.

GPG es comúnmente usado en emails para proteger la confidencialidad de los mensajes. Además pueden ser usados para firmar mensajes de email y confirmar su integridad.

Debajo un ejemplo de generación GPG:

bash
gpg --full-gen-key
gpg (GnuPG) 2.4.4; Copyright (C) 2024 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (9) ECC (sign and encrypt) *default*
  (10) ECC (sign only)
  (14) Existing key from card
Your selection? 9
Please select which elliptic curve you want:
   (1) Curve 25519 *default*
   (4) NIST P-384
   (6) Brainpool P-256
Your selection? 1
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0) 
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: strategos
Email address: strategos@tryhackme.thm
[...]
pub   ed25519 2024-08-29 [SC]
      AB7E6AA87B6A8E0D159CA7FFE5E63DBD5F83D5ED
uid                      Strategos <strategos@tryhackme.thm>
sub   cv25519 2024-08-29 [E]

Con PGP/GPG las claves pueden ser protegidas con passphrase al igual que como se protegen las claves SSH. Para romperlas puedes usar John the Ripper o gpg2john.


Ejemplo Práctico

Ahora que tenemos un par de clave GPG, podemos compartir la clave pública con nuestros contactos. Cuando tus contactos se quieran comunicar contigo de manera segura, encriptarán sus mensajes usando la clave pública. Para desencriptarlos, tú usarás tu clave privada. Es recomendable tener un backup de la clave en algún lugar por si acaso.

Digamos que tienes un ordenador nuevo. Lo único que tienes que hacer es importar tu clave del backup y puedes ponerte manos a la otra otra vez. Para ello:

  • Usarás gpg --import backup.key.
  • Para desencriptar mensajes: gpg --decrypt confidential_message.gpg.