Advertisement
87aCk_X

hash-utils (md5, sha224, sha256, sha384, sha512)

Sep 29th, 2013
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 8.89 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Getopt::Long;
  4. use Carp;
  5. use Term::ANSIColor qw/:constants/;
  6. our $VERSION = 0.0.0.0.0.0000004;
  7. #
  8. # usage:
  9. #  hash-utils --wordlist /tmp/wordlist --md5 098f6bcd4621d373cade4e832627b4f6
  10. #  hash-utils --wordlist /tmp/wordlist --sha1 a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
  11. #  hash-utils --wordlist /tmp/wordlist --sha2 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
  12. #  echo -n 'test' |./hash-utils --sha256 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
  13. #  cat /tmp/wordlist |./hash-utils --sha256 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
  14. #
  15. # * hash-utils (streamed)
  16. # m0user at 2013-09
  17. #
  18. croak "$0 --[md5|sha224|sha256|sha384|sha512|sha2][=]hash --wordlist[=]path\n\n" unless scalar @ARGV;
  19. my $set =+{
  20.         'wordlist'              => 'no',
  21.         'md5-hex'               => 'no',
  22.         'sha224-hex'            => 'no',
  23.         'sha256-hex'            => 'no',
  24.         'sha384-hex'            => 'no',
  25.         'sha512-hex'            => 'no',
  26.         'sha1-hex'              => 'no',
  27.         'sha2_256-hex'          => 'no',
  28.         'time'                  => time,
  29. };
  30. GetOptions( "wordlist=s"        => \$set->{'wordlist'},
  31.                         'md5=s'                 => \$set->{'md5-hex'},
  32.                         'sha224=s'              => \$set->{'sha224-hex'},
  33.                         'sha256=s'              => \$set->{'sha256-hex'},
  34.                         'sha384=s'              => \$set->{'sha384-hex'},
  35.                         'sha512=s'              => \$set->{'sha512-hex'},
  36.                         'sha1=s'                => \$set->{'sha1-hex'},
  37.                         'sha2=s'                => \$set->{'sha2_256-hex'},
  38. );
  39.  
  40. open WL, "<", $set->{'wordlist'} or croak "$!\n\n"
  41.         unless $set->{'wordlist'} eq 'no';
  42. *WL = \*STDIN if $set->{'wordlist'} eq 'no'; # STDIN STREAM
  43.  
  44.  
  45.         # md4
  46.         &md5_hex_util($set, \*WL)       if $set->{'md5-hex'} ne 'no';           #stdlib
  47.         &sha224_hex_util($set, \*WL)    if $set->{'sha224-hex'} ne 'no';        #stdlib
  48.         &sha256_hex_util($set, \*WL)    if $set->{'sha256-hex'} ne 'no';        #stdlib
  49.         &sha384_hex_util($set, \*WL)    if $set->{'sha384-hex'} ne 'no';        #stdlib
  50.         &sha512_hex_util($set, \*WL)    if $set->{'sha512-hex'} ne 'no';        #stdlib
  51.         &sha1_hex_util($set, \*WL)      if $set->{'sha1-hex'} ne 'no';          #stdlib
  52.         &sha2_hex_util($set, \*WL)      if $set->{'sha2_256-hex'} ne 'no';      #CPAN
  53.         # sha-3
  54.  
  55. close WL if $set->{'wordlist'} ne 'no';
  56. exit;
  57.  
  58.  
  59.  
  60. # equal to SHA256
  61. # SHA2-hex crack tool
  62. # test = 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
  63. sub sha2_hex_util {
  64.         use Digest::SHA2;
  65.         croak 'sha2_256_hex_util($set, \*HANDLE)', "\n\n" if scalar @_ != 2;
  66.         my ($set, $HANDLE) = (shift, shift);
  67.         my $sha2obj = new Digest::SHA2 256;
  68.  
  69.         foreach(<$HANDLE>) {
  70.                 chomp;
  71.                 print "`$_'";
  72.                 $sha2obj->add($_);
  73.                 if ($set->{'sha2_256-hex'} eq $sha2obj->hexdigest) {
  74.                         print GREEN " Got password!", RESET, "\n\n";
  75.                         print "SHA2_256-hex  `$set->{'sha2_256-hex'}'\n";
  76.                         print "Password      `$_'\n";
  77.                         print "Elapsed,      ", time - $set->{'time'}, " seconds\n\n";
  78.                         close WL and exit;
  79.                 }
  80.                 print RED " WRONG", RESET, "\n";
  81.                 $sha2obj->reset;
  82.         }
  83.         print "\n\n", RED "password not found!", RESET, "\n" and return;
  84. }
  85.  
  86. #
  87. # SHA1-hex crack tool
  88. #
  89. sub sha1_hex_util {
  90.         use Digest::SHA qw/sha1_hex/;
  91.         croak 'sha1_hex_util($set, \*HANDLE)', "\n\n" if scalar @_ != 2;
  92.         my ($set, $HANDLE) = (shift, shift);
  93.  
  94.         foreach(<$HANDLE>) {
  95.                 chomp;
  96.                 print "`$_'";
  97.                 if ($set->{'sha1-hex'} eq sha1_hex($_)) {
  98.                         print GREEN " Got password!", RESET, "\n\n";
  99.                         print "SHA1-hex    `$set->{'sha1-hex'}'\n";
  100.                         print "Password    `$_'\n";
  101.                         print "Elapsed,    ", time - $set->{'time'}, " seconds\n\n";
  102.                         close WL and exit;
  103.                 }
  104.                 print RED " WRONG", RESET, "\n";
  105.         }
  106.         print "\n\n", RED "password not found!", RESET, "\n" and return;
  107. }
  108.  
  109.  
  110.  
  111. #
  112. # sha224-hex cracking util
  113. # test = 90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809
  114. sub sha224_hex_util {
  115.         use Digest::SHA qw/sha224_hex/;
  116.         croak 'sha224_hex_util($set, \*HANDLE)', "\n\n" if scalar @_ != 2;
  117.         my ($set, $HANDLE) = (shift, shift);
  118.  
  119.         foreach(<$HANDLE>) {
  120.                 chomp;
  121.                 print "`$_'";
  122.                 if ($set->{'sha224-hex'} eq sha224_hex($_)) {
  123.                         print GREEN " Got password!", RESET, "\n\n";
  124.                         print "SHA224-hex  `$set->{'sha224-hex'}'\n";
  125.                         print "Password    `$_'\n";
  126.                         print "Elapsed,    ", time - $set->{'time'}, " seconds\n\n";
  127.                         close WL and exit;
  128.                 }
  129.                 print RED " WRONG", RESET, "\n";
  130.         }
  131.         print "\n\n", RED "password not found!", RESET, "\n" and return;
  132. }
  133.  
  134.  
  135. #
  136. # SHA256-hex crack tool
  137. #
  138. sub sha256_hex_util {
  139.         use Digest::SHA qw/sha256_hex/;
  140.         croak 'sha256_hex_util($set, \*HANDLE)', "\n\n" if scalar @_ != 2;
  141.         my ($set, $HANDLE) = (shift, shift);
  142.  
  143.         foreach(<$HANDLE>) {
  144.                 chomp;
  145.                 print "`$_'";
  146.                 if ($set->{'sha256-hex'} eq sha256_hex($_)) {
  147.                         print GREEN " Got password!", RESET, "\n\n";
  148.                         print "SHA256-hex  `$set->{'sha256-hex'}'\n";
  149.                         print "Password    `$_'\n";
  150.                         print "Elapsed,    ", time - $set->{'time'}, " seconds\n\n";
  151.                         close WL and exit;
  152.                 }
  153.                 print RED " WRONG", RESET, "\n";
  154.         }
  155.         print "\n\n", RED "password not found!", RESET, "\n" and return;
  156. }
  157.  
  158.  
  159. #
  160. # SHA384-hex crack tool
  161. # test = 768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9
  162. sub sha384_hex_util {
  163.         use Digest::SHA qw/sha384_hex/;
  164.         croak 'sha384_hex_util($set, \*HANDLE)', "\n\n" if scalar @_ != 2;
  165.         my ($set, $HANDLE) = (shift, shift);
  166.        
  167.         foreach(<$HANDLE>) {
  168.                 chomp;
  169.                 print "`$_'";
  170.                 if ($set->{'sha384-hex'} eq sha384_hex($_)) {
  171.                         print GREEN " Got password!", RESET, "\n\n";
  172.                         print "SHA384-hex  `$set->{'sha384-hex'}'\n";
  173.                         print "Password    `$_'\n";
  174.                         print "Elapsed,    ", time - $set->{'time'}, " seconds\n\n";
  175.                         close WL and exit;
  176.                 }
  177.                 print RED " WRONG", RESET, "\n";
  178.         }
  179.         print "\n\n", RED "password not found!", RESET, "\n" and return;
  180. }
  181.  
  182.  
  183. #
  184. # SHA512-hex crack tool
  185. # test = ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff
  186. sub sha512_hex_util {
  187.         use Digest::SHA qw/sha512_hex/;
  188.         croak 'sha512_hex_util($set, \*HANDLE)', "\n\n" if scalar @_ != 2;
  189.         my ($set, $HANDLE) = (shift, shift);
  190.  
  191.         foreach(<$HANDLE>) {
  192.                 chomp;
  193.                 print "`$_'";
  194.                 if ($set->{'sha512-hex'} eq sha512_hex($_)) {
  195.                         print GREEN " Got password!", RESET, "\n\n";
  196.                         print "sha512-hex `$set->{'sha512-hex'}'\n";
  197.                         print "Password   `$_'\n";
  198.                         print "Elapsed,   ", time - $set->{'time'}, " seconds\n\n";
  199.                         close WL and exit;
  200.                 }
  201.                 print RED " WRONG", RESET, "\n";
  202.         }
  203.         print "\n\n", RED "password not found!", RESET, "\n" and return;
  204.  
  205. }
  206.  
  207. #
  208. # MD5-hex crack tool
  209. #
  210. sub md5_hex_util {
  211.         use Digest::MD5 qw/md5_hex/;
  212.         croak 'md5_hex_util($set, \*HANDLE)', "\n\n" if scalar @_ != 2;
  213.         my ($set, $HANDLE) = (shift, shift);
  214.  
  215.         foreach(<$HANDLE>) {
  216.                 chomp;
  217.                 print "`$_'";
  218.                 if ($set->{'md5-hex'} eq md5_hex($_)) {
  219.                         print GREEN " Got password!", RESET, "\n\n";
  220.                         print "MD5-hex   `$set->{'md5-hex'}'\n";
  221.                         print "Password  `$_'\n";
  222.                         print "Elapsed,  ", time - $set->{'time'}, " seconds\n\n";
  223.                         close WL and exit;
  224.                 }
  225.                 print RED " WRONG", RESET, "\n";
  226.         }
  227.         print "\n\n", RED "password not found!", RESET, "\n" and return;
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement