Skip to content

Commit b6c8db0

Browse files
authoredAug 16, 2024
Create crt.sh v 2.0
Version v2.0 of the script for searching crt.sh has been released with several important enhancements focused on improving performance and adding comprehensive documentation for easier understanding and maintenance of the code.
1 parent 6429461 commit b6c8db0

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed
 

‎crt_v2.sh

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/bin/bash
2+
3+
# Display banner
4+
echo "
5+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
6+
| ..| search crt.sh v 2.0 |.. |
7+
+ site : crt.sh Certificate Search +
8+
| Twitter: az7rb |
9+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
10+
"
11+
12+
# Function: Help
13+
# Purpose: Display the help message with usage instructions.
14+
Help() {
15+
echo "Options:"
16+
echo ""
17+
echo "-h Help"
18+
echo "-d Search Domain Name | Example: $0 -d hackerone.com"
19+
echo "-o Search Organization Name | Example: $0 -o hackerone+inc"
20+
echo ""
21+
}
22+
23+
# Function: CleanResults
24+
# Purpose: Clean and filter the results by removing unwanted characters and duplicates.
25+
# - Converts escaped newlines to actual newlines.
26+
# - Removes wildcard characters (*).
27+
# - Filters out email addresses.
28+
# - Sorts the results and removes duplicates.
29+
CleanResults() {
30+
sed 's/\\n/\n/g' | \
31+
sed 's/\*.//g' | \
32+
sed -r 's/([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})//g' | \
33+
sort | uniq
34+
}
35+
36+
# Function: Domain
37+
# Purpose: Search for certificates associated with a specific domain name.
38+
# - Sends a request to crt.sh with the specified domain.
39+
# - Processes the JSON response to extract common names and domain values.
40+
# - Cleans and filters the results using CleanResults function.
41+
# - Saves the results to an output file and displays them.
42+
Domain() {
43+
# Check if the domain name is provided
44+
if [ -z "$req" ]; then
45+
echo "Error: Domain name is required."
46+
exit 1
47+
fi
48+
49+
# Perform the search request to crt.sh
50+
response=$(curl -s "https://crt.sh?q=%.$req&output=json")
51+
52+
# Check if the response is empty
53+
if [ -z "$response" ]; then
54+
echo "No results found for domain $req"
55+
exit 1
56+
fi
57+
58+
# Process the response, clean it, and store the results
59+
results=$(echo "$response" | jq -r ".[].common_name,.[].name_value" | CleanResults)
60+
61+
# Check if there are any valid results after cleaning
62+
if [ -z "$results" ]; then
63+
echo "No valid results found."
64+
exit 1
65+
fi
66+
67+
# Define the output file name based on the domain
68+
output_file="output/domain.$req.txt"
69+
70+
# Save the results to the output file
71+
echo "$results" > "$output_file"
72+
73+
# Display the results and summary
74+
echo ""
75+
echo "$results"
76+
echo ""
77+
echo -e "\e[32m[+]\e[0m Total Save will be \e[31m$(echo "$results" | wc -l)\e[0m Domain only"
78+
echo -e "\e[32m[+]\e[0m Output saved in $output_file"
79+
}
80+
81+
# Function: Organization
82+
# Purpose: Search for certificates associated with a specific organization name.
83+
# - Sends a request to crt.sh with the specified organization name.
84+
# - Processes the JSON response to extract common names.
85+
# - Cleans and filters the results using CleanResults function.
86+
# - Saves the results to an output file and displays them.
87+
Organization() {
88+
# Check if the organization name is provided
89+
if [ -z "$req" ]; then
90+
echo "Error: Organization name is required."
91+
exit 1
92+
fi
93+
94+
# Perform the search request to crt.sh
95+
response=$(curl -s "https://crt.sh?q=$req&output=json")
96+
97+
# Check if the response is empty
98+
if [ -z "$response" ]; then
99+
echo "No results found for organization $req"
100+
exit 1
101+
fi
102+
103+
# Process the response, clean it, and store the results
104+
results=$(echo "$response" | jq -r ".[].common_name" | CleanResults)
105+
106+
# Check if there are any valid results after cleaning
107+
if [ -z "$results" ]; then
108+
echo "No valid results found."
109+
exit 1
110+
fi
111+
112+
# Define the output file name based on the organization name
113+
output_file="output/org.$req.txt"
114+
115+
# Save the results to the output file
116+
echo "$results" > "$output_file"
117+
118+
# Display the results and summary
119+
echo ""
120+
echo "$results"
121+
echo ""
122+
echo -e "\e[32m[+]\e[0m Total Save will be \e[31m$(echo "$results" | wc -l)\e[0m Domain only"
123+
echo -e "\e[32m[+]\e[0m Output saved in $output_file"
124+
}
125+
126+
# Main Script Logic
127+
128+
# If no arguments are provided, display the help message
129+
if [ -z "$1" ]; then
130+
Help
131+
exit
132+
fi
133+
134+
# Parse command-line options using getopts
135+
while getopts "h:d:o:" option; do
136+
case $option in
137+
h) # Display help
138+
Help
139+
;;
140+
d) # Search for domain name
141+
req=$OPTARG
142+
Domain
143+
;;
144+
o) # Search for organization name
145+
req=$OPTARG
146+
Organization
147+
;;
148+
*) # Invalid option, display help
149+
Help
150+
;;
151+
esac
152+
done

0 commit comments

Comments
 (0)
Please sign in to comment.