Skip to content

Instantly share code, notes, and snippets.

@pyperanger
Created November 23, 2020 16:44
Show Gist options
  • Save pyperanger/addebf2168ca2ae2f991fd028318d8c0 to your computer and use it in GitHub Desktop.
Save pyperanger/addebf2168ca2ae2f991fd028318d8c0 to your computer and use it in GitHub Desktop.
Check HSTS Compliance
#!/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