Prepare for version 1.0.0
This commit is contained in:
1 parent
348af2cabb
commit
118621a38d
4 files changed
+281
-1
No files matched your search
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Nick Tsai
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1 +1,132 @@
|
||||
# brute-force-attacker-php
|
||||
<p align="center">
|
||||
<h1 align="center">Brute Force Attacker <i>for</i> PHP</h1>
|
||||
<br>
|
||||
</p>
|
||||
|
||||
Brute-force attack tool for generating all possible string and executing function
|
||||
|
||||
[](https://packagist.org/packages/yidas/brute-force-attacker)
|
||||
[](https://packagist.org/packages/yidas/brute-force-attacker)
|
||||
|
||||
OUTLINE
|
||||
-------
|
||||
|
||||
- [Demonstration](#demonstration)
|
||||
- [Requirements](#requirements)
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [Options](#options)
|
||||
|
||||
---
|
||||
|
||||
DEMONSTRATION
|
||||
-------------
|
||||
|
||||
```php
|
||||
\yidas\BruteForceAttacker::run([
|
||||
'length' => 2,
|
||||
'callback' => function ($string) {
|
||||
echo "{$string}\n";
|
||||
},
|
||||
]);
|
||||
```
|
||||
|
||||
Generates `0`-`9` string and matches target string:
|
||||
|
||||
```php
|
||||
\yidas\BruteForceAttacker::run([
|
||||
'length' => 6,
|
||||
'charMap' => range('0', '9'),
|
||||
'callback' => function ($string, $count) {
|
||||
if ($string=="264508") {
|
||||
echo "Matched `{$string}` with {$count} times\n";
|
||||
}
|
||||
},
|
||||
]);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
REQUIREMENTS
|
||||
------------
|
||||
This library requires the following:
|
||||
|
||||
- PHP 5.4.0+\|7.0+
|
||||
|
||||
---
|
||||
|
||||
INSTALLATION
|
||||
------------
|
||||
|
||||
Run Composer in your project:
|
||||
|
||||
composer require yidas/brute-force-attacker
|
||||
|
||||
Then you could call it after Composer is loaded depended on your PHP framework:
|
||||
|
||||
```php
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use yidas\BruteForceAttacker;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
USAGE
|
||||
-----
|
||||
|
||||
Call the `run()` static method and bring in the options to start:
|
||||
|
||||
```php
|
||||
\yidas\BruteForceAttacker::run(array $options)
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
Setting all options including skip mechanism:
|
||||
|
||||
```php
|
||||
$hash = '5b7476628919d2d57965e25ba8b2588e94723b76';
|
||||
|
||||
\yidas\BruteForceAttacker::run([
|
||||
'length' => 8,
|
||||
'charMap' => array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9'), ["+", "/"]),
|
||||
'callback' => function ($key, & $count) use ($hash) {
|
||||
if (sha1($key) == $hash) {
|
||||
echo "Matched `{$key}` | Hash: {$hash}\n";
|
||||
exit;
|
||||
}
|
||||
// Display key every some times
|
||||
if ($count == 0 || $count > 10000000) {
|
||||
echo "{$key} | " . date("H:i:s") . "\n";
|
||||
$count = 0;
|
||||
}
|
||||
},
|
||||
'skipLength' => 8, // Select 8st character for skipCount
|
||||
'skipCount' => 1, // Start from `B` (Skip 1 arrangement form charMap)
|
||||
]);
|
||||
```
|
||||
|
||||
#### length
|
||||
|
||||
String length for generating
|
||||
|
||||
#### charMap
|
||||
|
||||
Character map used to generate strings
|
||||
|
||||
#### Callback
|
||||
|
||||
Customized function for performing brute-force attack
|
||||
|
||||
```php
|
||||
function (string $key, integer & $count)
|
||||
```
|
||||
|
||||
#### skipLength
|
||||
|
||||
String length for skipping based on `skipCount` setting
|
||||
|
||||
#### skipCount
|
||||
|
||||
Skip count of the `charMap` based on `skipLength`
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "yidas/brute-force-attacker",
|
||||
"description": "Brute-force attack tool for generating all possible string and executing function",
|
||||
"keywords": ["brute force attack", "tool", "php", "cryptanalytic"],
|
||||
"homepage": "https://github.com/yidas/brute-force-attacker-php",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"support": {
|
||||
"issues": "https://github.com/yidas/brute-force-attacker-php/issues",
|
||||
"source": "https://github.com/yidas/brute-force-attacker-php"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"yidas\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace yidas;
|
||||
|
||||
/**
|
||||
* Brute Force Attacker
|
||||
*
|
||||
* Generates string with all arrangement and gives the string to callback function to execute.
|
||||
*
|
||||
* @author Nick Tsai <myintaer@gmail.com>
|
||||
* @version 1.0.0
|
||||
*/
|
||||
class BruteForceAttacker
|
||||
{
|
||||
/**
|
||||
* @var function Customized function for performing brute-force attack
|
||||
*/
|
||||
private static $callback;
|
||||
|
||||
/**
|
||||
* @var array Character map used to generate strings
|
||||
*/
|
||||
private static $charMap = [];
|
||||
|
||||
/**
|
||||
* @var string String for generating
|
||||
*/
|
||||
private static $chars = '';
|
||||
|
||||
/**
|
||||
* @var integer String length for skipping based on `skipCount` setting
|
||||
*/
|
||||
private static $skipLength = 0;
|
||||
|
||||
/**
|
||||
* @var integer Skip count of the `charMap` based on `skipLength`
|
||||
*/
|
||||
private static $skipCount = 0;
|
||||
|
||||
/**
|
||||
* @var integer Count
|
||||
*/
|
||||
private static $count = 0;
|
||||
|
||||
/**
|
||||
* Run
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
*/
|
||||
public static function run($options)
|
||||
{
|
||||
// Options
|
||||
$defaultOptions = [
|
||||
'length' => 1,
|
||||
'charMap' => array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9')),
|
||||
'callback' => function () {},
|
||||
'skipLength' => 0,
|
||||
'skipCount' => 0,
|
||||
];
|
||||
$options = array_merge($defaultOptions, $options);
|
||||
|
||||
// Config
|
||||
self::$charMap = $options['charMap'];
|
||||
self::$callback = $options['callback'];
|
||||
self::$skipLength = $options['skipLength'];
|
||||
self::$skipCount = $options['skipCount'];
|
||||
self::$count = 0;
|
||||
|
||||
// Run
|
||||
$length = ($options['length'] >= 1) ? floor($options['length']) : 1;
|
||||
self::recur($length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive function
|
||||
*
|
||||
* @param integer $layer
|
||||
* @return void
|
||||
*/
|
||||
private static function recur($length) {
|
||||
|
||||
// Each charMap
|
||||
foreach (self::$charMap as $value) {
|
||||
|
||||
// Skip mechanism
|
||||
if (self::$skipLength==$length && self::$skipCount > 0) {
|
||||
self::$skipCount--;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Assign char
|
||||
self::$chars[$length-1] = $value;
|
||||
|
||||
if ($length <= 1) {
|
||||
|
||||
// Call user callback
|
||||
call_user_func_array(self::$callback, [self::$chars, &self::$count]);
|
||||
// Counter
|
||||
self::$count ++;
|
||||
|
||||
} else {
|
||||
// Recur with reducing 1 length
|
||||
self::recur($length - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user