Created
November 23, 2020 16:44
-
-
Save pyperanger/addebf2168ca2ae2f991fd028318d8c0 to your computer and use it in GitHub Desktop.
Check HSTS Compliance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use LWP::UserAgent; | |
sub usage {print "HSTS Validate\n# perl hsts.pl https://domain.com\n";exit(254);} | |
my $url = shift || usage(); | |
my $status = 0; | |
my $res = (LWP::UserAgent->new(timeout=>3,agent =>'Mozilla/5.0'))->get($url); | |
print "Failed connection\n" and exit(255) unless ($res->code < 302); | |
if($res->header("strict-transport-security") eq ""){print "no hsts flag" and exit(4);} | |
print "max-age lower then 31536000\n" and $status++ if ($res->header("strict-transport-security") =~ /max-age=(\d+)/g)[0] < 31536000; | |
print "don't contains includeSubDomains\n" and $status +=2 if $res->header("strict-transport-security") !~ /includeSubDomains/; | |
print "Domain is in compliance\n" if $status == 0; | |
exit($status); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment