A way to save password generated and be able to continue from where we left of. So we can stop and continue without restarting all progress.
$charRecorded = "w1b";
$this->count = 15656;
BruteForceAttacker::bootUp($charRecorded);
for ($i = $charRecorded ? strlen($charRecorded): 1 ; $i <= 5 ;$i++) {
BruteForceAttacker::run([
'length' => $i,
'charMap' => array_merge(range('0', '9'), range('a', 'z')),
'callback' => [$this, 'sendTelnetCmd'],
'startsCount' => $this->count,
]);
if($this->found) {
break;
}
}
}
public function sendTelnetCmd($string, $count)
{
$this->info("string: $string, count: $count");
$this->count = $count;
if ($string=="a2b") {
$this->info( "Matched `{$string}` with {$count} times");
return $this->found = true;
}
}
Using $this->count to save the iterations number so we can retake from the last number counted.
This commit is contained in:
1 parent
d5ca11df05
commit
37dfcc7bd3
1 file changed
+37
-7
@@ -47,6 +47,11 @@ class BruteForceAttacker
|
||||
*/
|
||||
private static $found = false;
|
||||
|
||||
/**
|
||||
* @var array $charsRecorded to continue where it left of last time
|
||||
*/
|
||||
private static $charsRecorded = [];
|
||||
|
||||
/**
|
||||
* Run
|
||||
*
|
||||
@@ -62,6 +67,7 @@ class BruteForceAttacker
|
||||
'callback' => function () {},
|
||||
'skipLength' => 0,
|
||||
'skipCount' => 0,
|
||||
'startsCount' => 0,
|
||||
];
|
||||
$options = array_merge($defaultOptions, $options);
|
||||
|
||||
@@ -70,13 +76,21 @@ class BruteForceAttacker
|
||||
self::$callback = $options['callback'];
|
||||
self::$skipLength = $options['skipLength'];
|
||||
self::$skipCount = $options['skipCount'];
|
||||
self::$count = 0;
|
||||
self::$count = $options['startsCount'];
|
||||
|
||||
// Run
|
||||
$length = ($options['length'] >= 1) ? intval(floor($options['length'])) : 1;
|
||||
$length = ($options['length'] >= 1) ? intval(floor($options['length'])) : 1;
|
||||
self::recur($length);
|
||||
}
|
||||
|
||||
|
||||
public static function bootUp($charsSaved)
|
||||
{
|
||||
foreach (str_split($charsSaved) as $char) {
|
||||
self::$charsRecorded[] = $char;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive function
|
||||
*
|
||||
@@ -86,13 +100,17 @@ class BruteForceAttacker
|
||||
private static function recur($length) {
|
||||
|
||||
// Each charMap
|
||||
foreach (self::$charMap as $value) {
|
||||
foreach (self::$charMap as $key => $value) {
|
||||
|
||||
// Exit from loop is the value has been found.
|
||||
// Exit from loop if the value has been found.
|
||||
if(self::$found) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!empty(self::$charsRecorded) && self::wasVerified($length, $key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip mechanism
|
||||
if (self::$skipLength==$length && self::$skipCount > 0) {
|
||||
self::$skipCount--;
|
||||
@@ -104,19 +122,31 @@ class BruteForceAttacker
|
||||
|
||||
if ($length <= 1) {
|
||||
|
||||
// Counter
|
||||
self::$count ++;
|
||||
|
||||
// Call user callback
|
||||
self::$found = call_user_func_array(self::$callback, [self::$chars, &self::$count]);
|
||||
self::$charsRecorded = [];
|
||||
|
||||
if(self::$found) {
|
||||
break;
|
||||
}
|
||||
// Counter
|
||||
self::$count ++;
|
||||
|
||||
|
||||
} else {
|
||||
// Recur with reducing 1 length
|
||||
self::recur($length - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function wasVerified($length, $key)
|
||||
{
|
||||
$data = self::$charsRecorded[$length - 1];
|
||||
if($length == 1 && $key <= array_search($data, self::$charMap))
|
||||
return true;
|
||||
if($key < array_search($data, self::$charMap))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user