Skip to content

Instantly share code, notes, and snippets.

@voiski
Last active November 21, 2018 00:24
Show Gist options
  • Save voiski/cc33190234585b895cbf7fccd4f28f8b to your computer and use it in GitHub Desktop.
Save voiski/cc33190234585b895cbf7fccd4f28f8b to your computer and use it in GitHub Desktop.
Extract certificate
#!/bin/bash
# Extract certificate from the target domain.
# Usage:
# ./extract_certificate.sh {{domain name}} {{target port:default 443}}
# Example:
# curl -L https://git.io/fp8Za | bash -s google.com
# curl -L https://git.io/fp8Za | bash -s google.com 443
target=$1
port=${2:-443}
docker run --rm frapsoft/openssl s_client \
-connect ${target}:${port} 2>/dev/null </dev/null \
| sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' \
> ${target}.crt
ls -l ${target}.crt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment