
cipherBrute.pl – Bruteforce supported SSL/TLS cipher suites and extract SSL Certificate information.
cipherBrute.pl is a Bruteforce supported SSL/TLS cipher suites and extract useful SSL Certificate information.
Note: This tool uses the installed version of OpenSSL on the machine from which it is run as a basis for determining which cipher suites to test. This tool performs a full handshake in order to determine whether a cipher suite is supported much in the same way as the Nmap ssl-enum-ciphers script.
Note: This tool will work perfectly when run from Kali, but requires one Perl module to be installed (Crypt::X509). To install Crypt::X509 run the following command: cpanm install Crypt::X509
Why…?
+ To quickly determine the supported SSL/TLS cipher suites and present results in a clear/concise manner
+ To quickly extract useful information from SSL Certificates and present results in a clear/concise manner.
How to use
To check what SSL/TLS cipher suites are supported :
1 |
perl cipherBrute.pl -f lisofipsorhostnames.txt |
Example usage
To help demonstrate how this tool works and what it is useful for follow these steps:
1 – Create a text file called listofipsorhostnames.txt using your favourite editor (vi/pico/nano).
2 – Copy and paste the following sample data into the new text file:
1 2 3 4 5 |
www.yourdomaintotest.com www.yourdomaintotest.com:443 test.idontexist.com iptotest.iptotest.iptotest.iptotest maps.yourdomaintotest.org.uk:4444 |
3 – Run the following command and select option 1 at the menu:
1 |
perl cipherBrute.pl -f lisofipsorhostnames.txt |
4 – Alternatively, to extract useful SSL Certificate information (eg Valid from, Expires on…) run the following command and select option 2 at the menu:
1 |
perl cipherBrute.pl -f lisofipsorhostnames.txt |
Code :
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
#!/usr/bin/perl #Author: craigmillgate ########################################### use strict; use warnings; use Socket; use Data::Dumper; use Getopt::Long; #use Getopt::Long::Complete use Crypt::X509; use Term::ANSIColor; use File::Basename; #use List::MoreUtils qw(uniq); #use NetAddr::IP; use Net::IP; use Term::ANSIColor; my $usage = "\nUsage: " . "perl " . basename($0) . " [options] 'options' is one of more of --help Displays this usage message --version Displays current version of this program --file Specify a file containing list of ips/hostnames with or without portnumbers (defaults to 443) EXAMPLE COMMANDS: perl cipherBrute.pl -f listofipaddressesorhosts.txt \n"; ########################################### my $version = "\n" . basename($0) . ": Version 0.01 \n\n"; my $file; GetOptions( 'file=s' => \$file, 'help' => sub { print $usage; exit 0 }, 'version' => sub { print $version; exit 0 }, ); die "\nIncorrect usage - Specify at least a file containing ips/hosts (see --help)\n\n" unless (defined $file); ########################################### print color 'green'; my $heredoc = <<'END'; _ _ ____ _ (_) | | | _ \ | | ___ _ _ __ | |__ ___ _ __| |_) |_ __ _ _| |_ ___ / __| | '_ \| '_ \ / _ \ '__| _ <| '__| | | | __/ _ \ | (__| | |_) | | | | __/ | | |_) | | | |_| | || __/ \___|_| .__/|_| |_|\___|_| |____/|_| \__,_|\__\___| | | |_| bugs/features to craigmillgate. END print "$heredoc"; print color 'reset'; ########################################### #menu my $choice; while (1) { anon_mainmenu(); } sub anon_mainmenu { print color 'green'; print "________________________________________________________\n\n"; print "Bruteforce (full handshake) supported ciphers ...... [1]\n"; print "Extract SSL Certificate information ................ [2]\n"; print "[exit] .......................................... [EXIT]\n"; print "\n[>] Enter option: "; print color 'reset'; chomp($choice = <STDIN>); if ($choice eq 1) { cipher_check(); } elsif ($choice eq 2) { cert_info(); } elsif ($choice eq "exit") { print "\nExiting...\n\n"; exit(0); } print "\n\n"; } #end of main menu ########################################### #subs sub cipher_check { print "________________________________________________________\n\n\n"; my %hashofarrays; #to store the relationship between hostnames and ips my @hosts; open(my $fh, "<", $file) or die "Failed to open file: $!\n"; while(<$fh>) { chomp; next if /^(\s)*$/; push @hosts, $_; } close $fh; my %hash = map { $_, 1 } @hosts; #remove duplicates from the array using a hash #print Dumper (\%hash); #for testing only @hosts = keys %hash; #reassigning non duplicates $| = 1; #suffering from buffering prevention open STDERR, '>/dev/null'; my @cipher = split(/:/,`openssl ciphers ALL:eNULL`); #`openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g'`; my @protocol_versions = ("-ssl3", "-tls1", "-tls1_1", "-tls1_2"); my $opensslversion = `openssl version`; colour3("[+]"); print (" Obtaining cipher list from $opensslversion\n"); my $out; my $v; foreach my $hosts (@hosts) { my $substr = ":"; my $derbinary; if (index($hosts, $substr) != -1) { #do 0 } else { my $pnumberr = 443; $hosts = "$hosts:$pnumberr"; } colour3("[+]"); colour(" $hosts\n"); foreach my $version (@protocol_versions) { $v = $version; $v =~ tr/-//d; colour("\n\t$v\n"); foreach my $cipher (@cipher) { my $out = `echo -n | openssl s_client $version -cipher $cipher -connect $hosts 2>/dev/null`; #print "$out\n"; if (index($out, '-----BEGIN CERTIFICATE-----') != -1) { print "\t$cipher\n"; #print "\t$cipher - $version SUPPORTED\n"; } #print "$cipher\n"; } #print "\n"; } print "\n"; } exit(); } #end ########################################### #getting certificate information sub cert_info { print "________________________________________________________\n\n\n"; my @virthostips; open(my $fh, "<", $file) or die "Failed to open file: $!\n"; while(<$fh>) { chomp; push @virthostips, $_; } close $fh; foreach my $vi ( @virthostips ) { my $substr = ":"; my $derbinary; if (index($vi, $substr) != -1) { my ($viip, $pnumb) = split(":",$vi); $derbinary = `echo -n | openssl s_client -connect $viip:$pnumb 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -outform DER 2>/dev/null`; #$vi = $viip; #so we can compare the subject cn with the vi (ie ip/virthost supplied) } else { my $pnumber = 443; $derbinary = `echo -n | openssl s_client -connect $vi:$pnumber 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -outform DER 2>/dev/null`; } ########################################### my $decoded= Crypt::X509->new(cert => $derbinary); #print Dumper($decoded); #for testing only colour3("[+]"); print " Certificate Information for"; if (index($vi, $substr) != -1) { my ($viip, $pnumb) = split(":",$vi); colour(" $viip:$pnumb\n"); } else { my $pnumber = 443; colour(" $vi:$pnumber\n"); } if ($decoded->error) { colour2("\t[-] Error Parsing Certificate - No certificate found for [$vi]\n\n\n\n"); #.$decoded->error; next; } print "\n"; ########################################### my $cn = ($decoded->subject_cn); my $wildcard = "*"; unless (index($cn, $wildcard) == -1) { colour2("\t[-] Wildcard Certificate in use - [$cn]\n"); } #elsif ($vi ne $cn) { #colour2("[-] Untrusted Certificate? - CN [$cn] does not match Host [$vi]\n"); #} ########################################### my $expiry = gmtime($decoded->not_after); if ($decoded->not_after < time()) { colour("\t[-] Expired Certificate - Expired $expiry\n"); } ########################################### print "\tSubject: "; colour(join(',',@{$decoded->Subject})); print "\n"; ########################################### print "\tSubject CN: "; colour($decoded->subject_cn); print "\n"; ########################################### print "\tSubject Org: "; colour($decoded->subject_org); print "\n"; ########################################### print "\tLocation: "; my $country = ($decoded->subject_country); my $locality = ($decoded->subject_locality); my $state = ($decoded->subject_state); my $address = "$country, $locality, $state"; colour($address); print "\n"; ########################################## print "\t |\n"; ########################################## print "\tIssuer CN: "; colour($decoded->issuer_cn); print "\n"; ########################################### print "\tValid from: "; my $begins = gmtime($decoded->not_before); colour($begins); colour(" GMT\n"); #print colour(" " . gmtime($decoded->not_before) . " GMT\n"); ########################################### print "\tExpires on: "; my $expiration = gmtime($decoded->not_after); colour($expiration); colour(" GMT\n"); #print colour(" " . gmtime($decoded->not_after) . " GMT\n"); ########################################### print "\t |\n"; ########################################### print "\tCertificate Serial Number: "; #my $data = ($decoded->serial); #my $hex = sprintf("0x%x",$data); #colour("$hex"); #my $uchexnonpadded = uc(sprintf("%x", $data)); #colour(" ($uchexnonpadded)"); print "COMING VERY SOON"; print "\n"; ########################################### print "\tSignature Algorithn: "; print "COMING VERY SOON"; #colour($decoded->SigEncAlg); print "\n"; ########################################### print "\tSignature Hash: "; print "COMING VERY SOON"; #colour($decoded->SigHashAlg); print "\n"; ########################################### print "\n\n\n"; } #foreach exit(); } #end of subroutine call ########################################### #end sub colour { print color 'yellow'; print "$_[0]"; #should never recieve more arguments so subroutine array call unnecessary print color 'reset'; } sub colour2 { print color 'red'; print "$_[0]"; #should never recieve more arguments so subroutine array call unnecessary print color 'reset'; } sub colour3 { print color 'green'; print "$_[0]"; #should never recieve more arguments so subroutine array call unnecessary print color 'reset'; } sub colour4 { print color 'bold red'; print "$_[0]"; #should never recieve more arguments so subroutine array call unnecessary print color 'reset'; } ########################################### #end |
Source : https://github.com/CraigMillgate