-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgenerate_certs.sh
More file actions
executable file
·89 lines (73 loc) · 3.33 KB
/
generate_certs.sh
File metadata and controls
executable file
·89 lines (73 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# https://github.com/EONRaider/BCA-Phantom
# Author: EONRaider @ keybase.io/eonraider
gr='\033[0;32m' # Green
or='\033[0;33m' # Orange
nc='\033[0m' # No style
KEY_LEN="4096" # Key-length to be used
VALIDITY="90" # Validity time for the certificate in days
CA_KEY_FILE="ca-key.pem" # Certificate Authority (CA) key file
CA_CERT_FILE="ca-cert.pem" # CA certificate file in PEM format
SUBJ_KEY_FILE="server-key.pem" # Subject (our server) key file
SUBJ_CSR_FILE="server-csr.pem" # Subject Certificate Signing Request (CSR)
SUBJ_CERT_FILE="server-cert.pem" # Subject certificate file in PEM format
echo -e "\n${or}
[>>>] This script is part of the HTTPS Reverse Shell application. Check it
out at https://github.com/EONRaider/BCA-HTTPS-Reverse-Shell
${nc}"
echo -e "${gr}
[+] Step (1/2): Create our own Certificate Authority (CA). It will be used as an
entity that signs all our certificates, acting as a trusted party that our
clients and servers will rely on when authenticating connections. Fill in the
data for the creation of your own CA:
\n${nc}"
# 1. Generate a private RSA key for the Certificate Authority (CA):
openssl genrsa -out "${CA_KEY_FILE}" "${KEY_LEN}"
echo -e "${or}\n [>] File created: \"${CA_KEY_FILE}\"${nc}\n"
# 2. Create the certificate for the Certificate Authority (CA):
echo -e "${gr} [+] Fill in the data for the creation of your own CA. A file
named \"${CA_CERT_FILE}\" will be generated.\n${nc}"
openssl req -x509 -new -nodes -sha512 \
-days "${VALIDITY}" \
-key "${CA_KEY_FILE}" \
-out "${CA_CERT_FILE}"
echo -e "\n${or} [>] File created: \"${CA_CERT_FILE}\"${nc}\n"
echo -e "${gr}
[+] Step (2/2): Create our server's private key and use it to sign its Certificate
Signing Request (CSR). This CSR will be signed by our CA and, finally, the server
certificate will be issued.
${nc}\n"
# 3. Generate a private RSA key and a Certificate Signing Request (CSR) for the
# server (a.k.a. Subject):
echo -e "${gr} [+] Fill in the data for the creation of the X509 certificate for
your own server. It will be signed by the CA and a file named \"${SUBJ_CERT_FILE}\"
will be generated.\n${nc}"
openssl req -nodes \
-newkey rsa:"${KEY_LEN}" \
-days "${VALIDITY}" \
-keyout "${SUBJ_KEY_FILE}" \
-out "${SUBJ_CSR_FILE}"
echo -e "${or} [>] File created: \"${SUBJ_KEY_FILE}\"${nc}"
echo -e "${or} [>] File created: \"${SUBJ_CSR_FILE}\"${nc}\n"
# 4. Sign the server CSR with the CA certificate and private key:
openssl x509 -req \
-set_serial 01 \
-days "${VALIDITY}" \
-in "${SUBJ_CSR_FILE}" \
-out "${SUBJ_CERT_FILE}" \
-CA "${CA_CERT_FILE}" \
-CAkey "${CA_KEY_FILE}"
# 5. Verify the server certificate:
openssl verify -CAfile "${CA_CERT_FILE}" "${SUBJ_CERT_FILE}"
#==PROCESS COMPLETED============================================================
echo -e "${gr}"
read -rp "[!] From now on the only files you will need are \"${SUBJ_CERT_FILE}\",
\"${CA_KEY_FILE}\" and \"${CA_CERT_FILE}\". You can safely delete all the other
files that have been generated right now or keep them for further analysis. Would
you like to delete these extra files? (Y/N) " DELYN
echo -e "${nc}"
case ${DELYN} in
[Yy]* ) rm "${SUBJ_KEY_FILE}" "${SUBJ_CSR_FILE}"
echo -e "${or} [!] SUCCESS: Extra files were deleted.\n${nc}";;
[Nn]* ) echo -e "${or} [!] SUCCESS: Extra files will be kept.\n${nc}";;
esac