Skip to content

Commit

Permalink
Merge pull request #3 from NozakiLabs/feature/getopt-new
Browse files Browse the repository at this point in the history
changed the obtaining options; added support for glob on wordlist path
  • Loading branch information
LvMalware authored Jan 23, 2021
2 parents f412a99 + 3a5b327 commit 49a5a85
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 86 deletions.
7 changes: 5 additions & 2 deletions .vstags
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ Engine::Fuzzer::fuzz lib/Engine/Fuzzer.pm 18;" s
Engine::Fuzzer::new lib/Engine/Fuzzer.pm 7;" s
Functions::Helper lib/Functions/Helper.pm 1;" p
Functions::Helper::new lib/Functions/Helper.pm 5;" s
Nozaki::Core nozaki.pl 3;" p
Nozaki::Core::fuzzer_thread nozaki.pl 15;" s
Nozaki::Core::main nozaki.pl 45;" s
fuzz lib/Engine/Fuzzer.pm 18;" s
fuzzer_thread nozaki.pl 13;" s
main nozaki.pl 43;" s
fuzzer_thread nozaki.pl 15;" s
main nozaki.pl 45;" s
new lib/Engine/Fuzzer.pm 7;" s
new lib/Functions/Helper.pm 5;" s
177 changes: 93 additions & 84 deletions nozaki.pl
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;

0 comments on commit 49a5a85

Please sign in to comment.