Skip to content

Commit

Permalink
new module to identify the account id from AWS key
Browse files Browse the repository at this point in the history
  • Loading branch information
htrgouvea committed Jan 19, 2025
1 parent 93a4fc8 commit 98bb31f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .config/modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@
"category": "crypto",
"module": "Algorithm_Identifier",
"description": "Identify the type of hashing or encryption used in a string"
},
{
"id": "0067",
"category": "Cloud",
"module": "Account_Identifier",
"description": "Provides the AWS key for extracting the account ID"
}
]
}
42 changes: 42 additions & 0 deletions lib/Spellbook/Cloud/Account_Identifier.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package Spellbook::Cloud::Account_Identifier {
use strict;
use warnings;
use MIME::Base32 qw(decode_base32);
use Math::BigInt;

sub new {
my ($self, $parameters) = @_;
my ($help, $key);

Getopt::Long::GetOptionsFromArray (
$parameters,
"h|help" => \$help,
"k|key=s" => \$key
);

if ($key) {
my $trimmed_AWSKeyID = substr($key, 4);
my $decoded = decode_base32($trimmed_AWSKeyID);

my $decoded_prefix = substr($decoded, 0, 6);
my $bigint_value = Math::BigInt -> new('0x' . unpack("H*", $decoded_prefix));

my $mask = Math::BigInt -> new('0x7fffffffff80');
my $accountID = ($bigint_value & $mask) >> 7;

return $accountID;
}

if ($help) {
return "
\rCloud::Account_Identifier
\r==============
\r-h, --help See this menu
\r-k, --key Provides the AWS key for extracting the account ID.\n\n";
}

return 0;
}
}

1;

0 comments on commit 98bb31f

Please sign in to comment.