Advertisement
dewan159

Bruteforce attack password generator [CLI]

Jul 6th, 2015
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.66 KB | None | 0 0
  1. <?php
  2.     set_time_limit(0);
  3.  
  4.     // Set the exception handler
  5.     set_exception_handler(function(Exception $e){
  6.         print "-- " .$e->getMessage();
  7.     });
  8.  
  9.     // Only run in the CLI
  10.     if(php_sapi_name() != 'cli'){
  11.         throw new Exception('This script is accessible only through the command line!');
  12.     }
  13.    
  14.     // Get the passed arguments in the command line
  15.     $arguments = $_SERVER['argv'];
  16.     unset($arguments[0]);
  17.  
  18.     if(count($arguments) < 1){
  19.         throw new Exception('You need to provide some keywords to help create more promising passwords!');
  20.     }
  21.  
  22.     // Ready the keywords list
  23.     $keywords = implode(' ', $arguments);
  24.     $keywords = trim($keywords, ',');
  25.     $keywords = explode(',', $keywords);
  26.     $keywords = array_map('trim', $keywords);
  27.     $keywords = array_unique($keywords);
  28.  
  29.     if(!count($keywords)){
  30.         throw new Exception('No keywords were provided!');
  31.     }
  32.  
  33.     // If one of the keywords is an email address
  34.     foreach($keywords as $i => $keyword){
  35.         if(strpos($keyword, '@')){
  36.             unset($keywords[$i]);
  37.  
  38.             // Drop the trailing service provider domain name, eg: xx@gmail.com ~> xx
  39.             $keywords[] = explode('@', $keyword)[0];
  40.         }
  41.     }
  42.  
  43.     /////////////////////////
  44.  
  45.     // A list of common numerical combinations used in passwords
  46.     $numericPasswordsCombinations = ['0123', '0123456', '0123456789', 9876543210, 123, 321, 123456, 654321, 147852369,
  47.         369852741, 159357, 951753, 456852, 789654321, 123654789, 112233, 445566, 778899, 112233445566, 985236,
  48.         147852, 14789632, 98741236, 36987412, 78963214, 47896321, 89632147, 563214789, 541236987, '01478963',
  49.         '0147896325', '0987654321', 123456789];
  50.  
  51.     // Create the passwords
  52.     // Probability #1: the password is one of the keywords!
  53.     {
  54.         $passwords = [];
  55.         foreach($keywords as $keyword){
  56.             $passwords[] = $keyword;
  57.  
  58.             // Try some other variants of the same keyword
  59.             if(strpos($keyword, ' ')){
  60.                 $keywords[] = $passwords[] = str_replace(' ', '_', $keyword);
  61.                 $keywords[] = $passwords[] = str_replace(' ', '-', $keyword);
  62.             }
  63.         }
  64.     }
  65.  
  66.     // Probability #2: one of the numerical combinations
  67.     {
  68.         $passwords += $numericPasswordsCombinations;
  69.     }
  70.  
  71.     // Probability #3: a combination of the keywords and the numbers
  72.     {
  73.         foreach($numericPasswordsCombinations as $number){
  74.             foreach($keywords as $keyword){
  75.                 $passwords[] = $keyword .'_' .$number;
  76.                 $passwords[] = $keyword .$number;
  77.                 $passwords[] = $number .$keyword;
  78.             }
  79.         }
  80.     }
  81.  
  82.     // Create the passwords.txt file
  83.     if(!@file_put_contents('passwords.txt', implode(PHP_EOL, $passwords))){
  84.         throw new Exception('Passwords were generated, but cannot create the passwords.txt file!');
  85.     }
  86.  
  87.     print 'Success! passwords.txt contains ' .count($passwords) .' password. Have fun!';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement