OpenSSL — Complete OSCP Reference
What is OpenSSL?
OpenSSL is the standard CLI for TLS/SSL , X.509 certificates , hashes , symmetric encryption , and password hash generation . Pre-installed on Kali and most Linux targets.
OSCP use: Grab certs on 443/465/993/995; inspect CN/SAN for vhosts; generate /etc/passwd hashes for privesc; decode encrypted loot; build certs for Socat SSL shells; hash files with dgst.
Install: sudo apt install openssl (Kali: pre-installed)
📌 Which Command When
Port 443/993/995/636 open?
└─ openssl s_client → grab cert, test STARTTLS
Need cert details (CN, SAN, expiry)?
└─ openssl x509 -noout -text
Linux privesc — add user to /etc/passwd?
└─ openssl passwd -1 / -6
Found encrypted file + password?
└─ openssl enc -d
Need file hash (integrity / CTF)?
└─ openssl dgst -sha256
SSL reverse shell / Socat listener?
└─ openssl req -x509 -newkey rsa:4096 ...
Password from stdin for script?
└─ openssl passwd -6 -stdin
See UseCases for ports , Mail (SMTP POP3 IMAP) , Socat , Linux .
📌 1) s_client — TLS Client (Most Used on OSCP)
Connect to a TLS service and optionally show the certificate chain.
Syntax
openssl s_client [options] [host:port]
openssl s_client -connect HOST:PORT [options]
Connection flags
Flag Description -connect HOST:PORTTarget host and port (default port 4433 if omitted) -host HOSTHostname for SNI (use with -connect) -port PORTPort (alternative to host:port syntax) -servername NAMESNI hostname (TLS extension) — important for vhost discovery -bind ADDRLocal bind address -proxy HOST:PORTConnect via HTTP proxy -proxy_user USERProxy auth user -proxy_pass PASSProxy auth password -unix PATHUnix domain socket -4IPv4 only -6IPv6 only
Protocol / cipher flags
Flag Description -tls1Force TLS 1.0 -tls1_1Force TLS 1.1 -tls1_2Force TLS 1.2 -tls1_3Force TLS 1.3 -ssl3Force SSLv3 (legacy) -no_ssl3Disable SSLv3 -cipher VALTLS 1.2 and below cipher list -ciphersuites VALTLS 1.3 cipher suites -min_protocol VALMinimum protocol version -max_protocol VALMaximum protocol version -ign_eofIgnore EOF on input (stay connected) -quietMinimal output
Certificate / identity flags
Flag Description -cert FILEClient certificate (PEM) -key FILEClient private key -cert_chain FILEClient cert chain PEM -CAfile FILETrusted CA bundle -CApath DIRDirectory of hashed CAs -showcertsPrint all certs in chain -verify INTRequire peer cert (depth) -Verify INTRequire peer cert + local cert -verify_return_errorExit on verify failure -verify_hostname HOSTExpected hostname for verify -briefBrief connection info
STARTTLS / application protocols
Flag Description -starttls protocolUpgrade cleartext to TLS — smtp , imap , pop3 , ftp , xmpp , ldap -crlfConvert LF to CRLF (SMTP) -noservernameDisable SNI -prexitPrint session info on exit -reconnectDrop and reconnect (test session reuse) -statePrint SSL state machine -msgShow protocol messages -debugVerbose debug -helpFull flag list
OSCP examples
# HTTPS — grab certificate
openssl s_client -connect 10.10.10.10:443 < /dev/null 2> /dev/null | openssl x509 -noout -text
# SNI / vhost — cert for specific hostname
openssl s_client -connect 10.10.10.10:443 -servername dev.target.com < /dev/null 2> /dev/null | openssl x509 -noout -subject -ext subjectAltName
# Quick cert dates
echo | openssl s_client -connect 10.10.10.10:443 2> /dev/null | openssl x509 -noout -dates -subject -issuer
# SMTP STARTTLS (587)
openssl s_client -connect 10.10.10.10:587 -starttls smtp -crlf
# SMTPS (465)
openssl s_client -connect 10.10.10.10:465
# IMAPS (993)
openssl s_client -connect 10.10.10.10:993
# POP3S (995)
openssl s_client -connect 10.10.10.10:995
# LDAPS (636)
openssl s_client -connect 10.10.10.10:636
# Interactive — type HTTP after connect (rare)
openssl s_client -connect 10.10.10.10:443
# GET / HTTP/1.0
📌 2) x509 — Certificate Display & Conversion
Parse, display, and convert X.509 certificates and CSRs.
Syntax
openssl x509 [options] -in FILE
Flag Description -in FILEInput cert or CSR -out FILEOutput file -inform PEM|DERInput format -outform PEM|DEROutput format -reqInput is a CSR -textHuman-readable dump -nooutNo PEM output (print-only flags) -nocertNo cert output
Display fields
Flag Description -subjectSubject DN -issuerIssuer DN -datesnotBefore / notAfter -startdatenotBefore only -enddatenotAfter only -serialSerial number -fingerprintCert fingerprint -emailEmail from subject -hashSubject hash (symlink naming) -subject_hashSame -issuer_hashIssuer hash -ext EXTPrint extension (e.g. subjectAltName, authorityKeyIdentifier) -pubkeyOutput public key -modulusRSA modulus -nameopt OPTName display format
OSCP examples
openssl x509 -in cert.pem -text -noout
openssl x509 -in cert.pem -noout -subject -issuer -dates
openssl x509 -in cert.pem -noout -ext subjectAltName
openssl x509 -in cert.pem -noout -fingerprint -sha256
Pipe from s_client:
openssl s_client -connect TARGET:443 < /dev/null 2> /dev/null | openssl x509 -noout -text
📌 3) passwd — Password Hash Generation (Privesc)
Ctrl+F: openssl passwd -6 · -1 · /etc/passwd · root user · $6$
Deep dive (add root user, shadow, examples) → openssl passwd
Syntax
openssl passwd [options] [password]
openssl passwd -6 -stdin # read password from stdin
Flags
Flag Description -1MD5 crypt ($1$...) — common on OSCP Linux privesc -5SHA256 crypt ($5$...) -6SHA512 crypt ($6$...) — modern default -apr1Apache MD5 ($apr1$...) -aixmd5AIX MD5 -salt STRINGSpecify salt -stdinRead password from stdin -in FILERead passwords from file -quietNo warnings -tableTable output format -helpHelp
OSCP examples
# SHA-512 — modern default ($6$)
openssl passwd -6 "NewPassword123!"
# $6$rounds=5000$...
# MD5 crypt — insert into /etc/passwd (older boxes)
openssl passwd -1 password123
openssl passwd -1 -salt test1 test1
# $1$xyz$...
# Add root-equivalent user (if /etc/passwd writable)
HASH = $( openssl passwd -6 "NewPassword123!" )
echo "newroot:${ HASH }:0:0:root:/root:/bin/bash" | sudo tee -a /etc/passwd
su newroot
# MD5 one-liner
echo 'newroot:$(openssl passwd -1 password):0:0:root:/root:/bin/bash' | sudo tee -a /passwd
# SHA512 via stdin
echo -n 'password123' | openssl passwd -6 -stdin
→ Full privesc workflows: openssl passwd · Linux
📌 4) dgst — Hash / Message Digest
openssl dgst [options] [file...]
Common flags
Flag Description -helpHelp -listList supported digests -sha1SHA-1 -sha256SHA-256 -sha512SHA-512 -md5MD5 -hmac KEYHMAC with key -mac ALGMAC algorithm -hexHex output (default for binary) -binaryBinary output -out FILEWrite to file -sign FILESign digest with private key -verify FILEVerify signature -signature FILESignature file -engine IDHardware engine
Examples
openssl dgst -sha256 file.bin
openssl dgst -md5 secret.txt
openssl dgst -sha256 -hmac "secretkey" message.txt
📌 5) enc — Symmetric Encrypt / Decrypt
openssl enc [options]
General
Flag Description -eEncrypt (default) -dDecrypt -listList ciphers -helpHelp
I/O
Flag Description -in FILEInput -out FILEOutput -pass pass:PASSWORDPassword on command line -pass file:FILEPassword from file -pass stdinPassword from stdin -k PASSWORDPassword shorthand -kfile FILEPassword file -a / -base64Base64 encode/decode -ASingle-line base64 -vVerbose -pPrint key and IV -PPrint key/IV and exit
Crypto options
Flag Description -saltUse salt in KDF (default) -nosaltNo salt -md ALGDigest for KDF (e.g. sha256) -pbkdf2PBKDF2 key derivation -iter NPBKDF2 iterations -K HEXRaw key (hex) -iv HEXIV (hex) -S HEXSalt (hex) -nopadDisable padding -bufsize NBuffer size
Cipher (positional or -cipher)
Common: aes-256-cbc, aes-128-cbc, des3, bf, rc4, base64 (via enc)
Examples
# Encrypt
openssl enc -aes-256-cbc -salt -in plain.txt -out plain.enc -pass pass:secret
# Decrypt
openssl enc -aes-256-cbc -d -in plain.enc -out plain.txt -pass pass:secret
# Base64 encode/decode
openssl enc -base64 -in file.bin -out file.b64
openssl enc -base64 -d -in file.b64 -out file.bin
📌 6) req — Certificate Signing Request / Self-Signed Cert
Create CSRs or self-signed certificates (SSL shells, testing).
openssl req [options]
Flag Description -newNew CSR -newkey rsa:4096Generate new RSA key + CSR -key FILEExisting key -keyout FILEOutput key file -out FILEOutput CSR/cert -x509Output self-signed cert instead of CSR -days NValidity days -subj "/CN=localhost/O=Org/C=US"Subject (non-interactive) -nodesNo encryption on private key -passin SRCKey password source -passout SRCOutput key password -config FILEOpenSSL config -extensions NAMEConfig extension section -addext KEY=VALUEAdd extension inline -textText output -nooutNo PEM output -verifyVerify CSR self-signature -helpHelp
OSCP — Socat / SSL shell cert (one-liner)
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes \
-subj "/CN=localhost"
See Socat , Shells .
📌 7) genrsa / rsa / pkey — Key Generation
genrsa
openssl genrsa [options] NUMBITS
Flag Description -out FILEOutput key file -passout SRCEncrypt output key -F4 / -f4Use Fermat F4 as public exponent -traditionalTraditional PEM format -helpHelp
openssl genrsa -out private.key 4096
rsa
openssl rsa -in private.key -pubout -out public.key
openssl rsa -in private.key -text -noout
pkey (generic)
openssl pkey -in key.pem -text -noout
openssl pkey -in key.pem -pubout -out pub.pem
📌 8) s_server — Test TLS Server
Rare on OSCP; useful for local SSL testing.
openssl s_server [options]
Flag Description -accept PORTListen port (default 4433) -cert FILEServer certificate -key FILEPrivate key -wwwSend HTTP response after connect -HTTPSimple HTTP server -quietQuiet -helpHelp
openssl s_server -accept 4443 -cert cert.pem -key key.pem -www
📌 9) Other Useful Subcommands
Command Purpose Quick example openssl versionVersion openssl version -aopenssl listList algorithms openssl list -digest-algorithmsopenssl randRandom bytes openssl rand -hex 32openssl pkcs12PKCS#12 import/export openssl pkcs12 -in cert.pfx -nodes -out out.pemopenssl verifyVerify cert chain openssl verify -CAfile ca.pem cert.pemopenssl cmsCMS encrypt/sign CTF / email forensics openssl smimeS/MIME Mail forensics openssl rsautlRSA encrypt/decrypt Legacy CTF openssl pkeyutlPublic key ops Encrypt small blobs openssl speedBenchmark —
rand flags
Flag Description -hexHex output -base64Base64 output -out FILEWrite to file
openssl rand -hex 16
openssl rand -base64 32
pkcs12 common flags
Flag Description -in FILEInput .pfx/.p12 -out FILEOutput PEM -nodesDon’t encrypt private keys in output -passin pass:PASSImport password -infoPrint structure info -nokeysCerts only -nocertsKeys only
📌 10) Standard Commands List
openssl help # All standard commands
openssl list -help # List subcommands for digests/ciphers
Common OSCP commands: s_client, x509, passwd, enc, dgst, req, genrsa, rsa, pkey, rand, pkcs12, verify
📌 Quick OSCP Cheat Sheet
# TLS cert grab + inspect
openssl s_client -connect TARGET:443 < /dev/null 2> /dev/null | openssl x509 -noout -text
openssl s_client -connect TARGET:443 -servername vhost.target.com < /dev/null 2> /dev/null | openssl x509 -noout -ext subjectAltName
# Mail TLS
openssl s_client -connect TARGET:587 -starttls smtp -crlf
openssl s_client -connect TARGET:993
openssl s_client -connect TARGET:995
# Privesc passwd hash
openssl passwd -6 'NewPassword123!'
openssl passwd -1 'password123'
# Self-signed cert
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=localhost"
# Hash / decrypt
openssl dgst -sha256 file
openssl enc -aes-256-cbc -d -in file.enc -out file -pass pass:secret