Warith AL Maawali

0 %
Warith AL Maawali
Driving cybersecurity excellence
Innovator behind Linux Kodachi
  • Residence:
    127.0.0.1
  • Uptime Binary:
    101110
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Visual basic
Delphi
Gambas
Bash
PHP
  • Infrastructures
  • Digital Forensics
  • Cryptocurrency
  • Cloud & Server Management

Extracting SSL Fingerprints

13/05/2013

Extracting SSL Fingerprints: My Custom Scripts

I was looking for a script that can extract the SSL fingerprint from any SSL certificate, given you have the URL. I found a few scripts, but none of them did exactly what I expected, so I decided to write my own based on what I found. I created three versions of the script: one in Perl, one in Linux Shell scripting, and one in PHP. Note that all of them perform the same task and produce the same results.

The next plan was to develop an automated standalone application that could perform this task from multiple locations automatically (SSLEYE). It’s important to understand that secure browser connections can be intercepted and decrypted by anyone (Man-in-the-Middle, MITM) who could spoof the authentic site’s certificate and act on your behalf. This also allows them to read your traffic in clear text. Fortunately, the authentic site’s fingerprint cannot be duplicated, which is the main advantage of having such an application.

 

Perl script:

 

#!/usr/bin/perl
# Perl SSL Fingerprint Checker written by W. Al Maawali  
# (c) 2013 Founder of Eagle Eye Digital Solutions
# https://www.digi77.com
# http://www.om77.net
# script starts here:
# Usage: $perl sslf.pl -d yourdomain
# Example: $perl sslf.pl -d google.com

#libs used
use Net::SSLeay qw(get_https3);
use Getopt::Std;

# get args
getopts("o:i:d:s:e:hvb", \%args);

# set our input vars to easy names
$domain = $args{d};

# gotta have at least the domain and log file
if (!$args{d}) {
 print "\t Domain is blank google.com will be used\n\n";
 $domain ="google.com";

}

$host= $domain;
$port = 443;

($p, $resp, $hdrs, $server_cert) = get_https3($host, $port, '/');
#get finger print
print Net::SSLeay::X509_get_fingerprint($server_cert, "sha1");
print "\n";

 

Download

 

Shell script:

 

#!/bin/sh
# Shell SSL Fingerprint Checker written by W. Al Maawali  
# (c) 2013 Founder of Eagle Eye Digital Solutions
# https://www.digi77.com
# http://www.om77.net
# script starts here:
# Usage: $. sslf.sh -d yourdomain
# Example: $. sslf.sh -d google.com

#SSL Port
sslport=443

# Accept command line arguments
while [ $# -gt 0 ]
do
    case "$1" in

        -d)  host=$2 ; shift;;
        --)     shift; break;;
        -*)
            echo >&2 \
            "usage: $0 [-d] domain";;
        *)
        break;; # terminate while loop
    esac
    shift
done

#set port and host
host="$host:$sslport"

#get ssl info and strip the fingerprint
echo |\
openssl s_client -connect $host 2>/dev/null |\
openssl x509 -noout -fingerprint | cut -d'=' -f 2

 

Download

 

PHP script:

<?php

# PHP SSL Fingerprint Checker written by W. Al Maawali
# (c) 2013 Founder of Eagle Eye Digital Solutions
# https://www.digi77.com
# http://www.om77.net
# script starts here:
# Usage: http://www.yourdomain.com/sslf.php
# Example: https://www.digi77.com/software/fingerprint/fp-public.php?hosts=www.facebook.com

//avoid timeouts
set_time_limit(0);

//For String variable use prevent sql injections
function StringInputCleaner($data)
{
$data = trim($data);
$data = stripslashes($data);
$data=(filter_var($data, FILTER_SANITIZE_STRING));
return $data;
}

function getSllCertificate($hostname, $port = 443)
{
$context = stream_context_create(array("ssl" =&gt; array("capture_peer_cert" =&gt; true)));
$socket = @stream_socket_client("ssl://$hostname:$port", $errno, $errstr, ini_get("default_socket_timeout"), STREAM_CLIENT_CONNECT, $context);

if(!$socket)
return array("md5" =&gt; "error", "sha1" =&gt; "error");

$contextdata = stream_context_get_params($socket);
$contextparams = $contextdata['options']['ssl']['peer_certificate'];

fclose($socket);

openssl_x509_export($contextparams, $cert, true);
openssl_x509_free($contextparams);

$repl = array("\r", "\n", "-----BEGIN CERTIFICATE-----", "-----END CERTIFICATE-----");
$repw = array("", "", "", "");

$cert = str_replace($repl, $repw, $cert);

$decoded = base64_decode($cert);
$fingerprints = array(
"md5" =&gt; md5($decoded),
"sha1" =&gt; sha1($decoded),
);


return $fingerprints ;
}

$host=$_REQUEST['hosts'];
//clean string safer coding
$host=StringInputCleaner($host);
$port=443;
$hashes = getSllCertificate($host, $port);

print_r($hashes['sha1']);


?>

 

Download

 

Posted in Tech BlogTags:
© 2024 Warith AL Maawali. All Rights Reserved.
Stay Secure, Stay Assured.