-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from NozakiLabs/feature/getopt-new
changed the obtaining options; added support for glob on wordlist path
- Loading branch information
Showing
2 changed files
with
98 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,109 @@ | ||
#!/usr/bin/env perl | ||
|
||
use JSON; | ||
use 5.018; | ||
use strict; | ||
use warnings; | ||
use Find::Lib "./lib"; | ||
use Engine::Fuzzer; | ||
use Functions::Helper; | ||
use Parallel::ForkManager; | ||
use Getopt::Long qw(:config no_ignore_case); | ||
|
||
sub fuzzer_thread { | ||
my ($endpoint, $methods, $agent, $headers, $accept, $timeout, $return, $payload, $json, $delay, $exclude) = @_; | ||
|
||
my $fuzzer = Engine::Fuzzer -> new ( | ||
useragent => $agent, | ||
timeout => $timeout, | ||
headers => $headers | ||
); | ||
|
||
my @verbs = split (/,/, $methods); | ||
my @valid_codes = split /,/, $return || ""; | ||
my @invalid_codes = split /,/, $exclude || ""; | ||
|
||
for my $verb (@verbs) { | ||
my $result = $fuzzer -> fuzz ($endpoint, $verb, $payload, $accept); | ||
|
||
my $status = $result -> {Code}; | ||
next if grep(/^$status$/, @invalid_codes) || ($return && !grep(/^$status$/, @valid_codes)); | ||
package Nozaki::Core { | ||
|
||
use JSON; | ||
use 5.018; | ||
use strict; | ||
use warnings; | ||
use Find::Lib "./lib"; | ||
use Engine::Fuzzer; | ||
use Functions::Helper; | ||
use Parallel::ForkManager; | ||
use Getopt::Long qw(:config no_ignore_case); | ||
|
||
sub fuzzer_thread { | ||
my ($endpoint, $methods, $agent, $headers, $accept, $timeout, $return, $payload, $json, $delay, $exclude) = @_; | ||
|
||
my $printable = $json ? encode_json($result) : sprintf( | ||
"Code: %d | URL: %s | Method: %s | Response: %s | Length: %s", | ||
$status, $result -> {URL}, $result -> {Method}, | ||
$result -> {Response}, $result -> {Length} | ||
my $fuzzer = Engine::Fuzzer -> new ( | ||
useragent => $agent, | ||
timeout => $timeout, | ||
headers => $headers | ||
); | ||
|
||
my @verbs = split (/,/, $methods); | ||
my @valid_codes = split /,/, $return || ""; | ||
my @invalid_codes = split /,/, $exclude || ""; | ||
|
||
for my $verb (@verbs) { | ||
my $result = $fuzzer -> fuzz ($endpoint, $verb, $payload, $accept); | ||
|
||
print $printable . "\n"; | ||
sleep($delay); | ||
} | ||
} | ||
my $status = $result -> {Code}; | ||
next if grep(/^$status$/, @invalid_codes) || ($return && !grep(/^$status$/, @valid_codes)); | ||
|
||
my $printable = $json ? encode_json($result) : sprintf( | ||
"Code: %d | URL: %s | Method: %s | Response: %s | Length: %s", | ||
$status, $result -> {URL}, $result -> {Method}, | ||
$result -> {Response}, $result -> {Length} | ||
); | ||
|
||
sub main { | ||
my ($target, $return, $payload, %headers, $accept, $json, $exclude); | ||
my $agent = "Nozaki CLI / 0.2.1"; | ||
my $delay = 0; | ||
my $timeout = 10; | ||
my $wordlist = "wordlists/default.txt"; | ||
my $methods = "GET,POST,PUT,DELETE,HEAD,OPTIONS,TRACE,PATCH,PUSH"; | ||
my $tasks = 10; | ||
|
||
GetOptions ( | ||
"A|accept=s" => \$accept, | ||
"u|url=s" => \$target, | ||
"w|wordlist=s" => \$wordlist, | ||
"m|method=s" => \$methods, | ||
"d|delay=i" => \$delay, | ||
"t|timeout=i" => \$timeout, | ||
"a|agent=s" => \$agent, | ||
"r|return=s" => \$return, | ||
"p|payload=s" => \$payload, | ||
"j|json" => \$json, | ||
"H|header=s%" => \%headers, | ||
"T|tasks=i" => \$tasks, | ||
"e|exclude=s" => \$exclude, | ||
) or die ( return Functions::Helper -> new() ); | ||
|
||
return Functions::Helper -> new() unless $target && $wordlist; | ||
|
||
open (my $file, "<", $wordlist) || die "$0: Can't open $wordlist"; | ||
|
||
my @resources; | ||
|
||
while (<$file>) { | ||
chomp ($_); | ||
push @resources, $_; | ||
print $printable . "\n"; | ||
sleep($delay); | ||
} | ||
} | ||
|
||
close ($file); | ||
sub main { | ||
my ($cl_opt) = @_; | ||
my ($target, $return, $payload, %headers, $accept, $json, $exclude); | ||
my $agent = "Nozaki CLI / 0.2.1"; | ||
my $delay = 0; | ||
my $timeout = 10; | ||
my $wordlist = "wordlists/default.txt"; | ||
my $methods = "GET,POST,PUT,DELETE,HEAD,OPTIONS,TRACE,PATCH,PUSH"; | ||
my $tasks = 10; | ||
|
||
my $threadmgr = Parallel::ForkManager -> new($tasks); | ||
Getopt::Long::GetOptionsFromArray ( | ||
$cl_opt, | ||
"A|accept=s" => \$accept, | ||
"u|url=s" => \$target, | ||
"w|wordlist=s" => \$wordlist, | ||
"m|method=s" => \$methods, | ||
"d|delay=i" => \$delay, | ||
"t|timeout=i" => \$timeout, | ||
"a|agent=s" => \$agent, | ||
"r|return=s" => \$return, | ||
"p|payload=s" => \$payload, | ||
"j|json" => \$json, | ||
"H|header=s%" => \%headers, | ||
"T|tasks=i" => \$tasks, | ||
"e|exclude=s" => \$exclude, | ||
) or die ( return Functions::Helper -> new() ); | ||
|
||
$threadmgr -> set_waitpid_blocking_sleep(0); | ||
THREADS: | ||
return Functions::Helper -> new() unless $target && $wordlist; | ||
|
||
my @resources; | ||
for my $list (glob($wordlist)) | ||
{ | ||
open (my $file, "<$list") || die "$0: Can't open $list"; | ||
|
||
for (@resources) { | ||
my $endpoint = $target . $_; | ||
$threadmgr -> start() and next THREADS; | ||
|
||
fuzzer_thread($endpoint, $methods, $agent, \%headers, $accept, $timeout, $return, $payload, $json, $delay, $exclude); | ||
|
||
$threadmgr -> finish(); | ||
while (<$file>) { | ||
chomp ($_); | ||
push @resources, $_; | ||
} | ||
close ($file); | ||
} | ||
|
||
my $threadmgr = Parallel::ForkManager -> new($tasks); | ||
|
||
$threadmgr -> set_waitpid_blocking_sleep(0); | ||
THREADS: | ||
|
||
for (@resources) { | ||
my $endpoint = $target . $_; | ||
$threadmgr -> start() and next THREADS; | ||
|
||
fuzzer_thread($endpoint, $methods, $agent, \%headers, $accept, $timeout, $return, $payload, $json, $delay, $exclude); | ||
|
||
$threadmgr -> finish(); | ||
} | ||
|
||
$threadmgr -> wait_all_children(); | ||
|
||
return 0; | ||
} | ||
|
||
$threadmgr -> wait_all_children(); | ||
exit main(\@ARGV) unless caller; | ||
|
||
return 0; | ||
} | ||
|
||
exit main(); | ||
1; |