-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
nozaki.pl
executable file
·137 lines (109 loc) · 3.72 KB
/
nozaki.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env perl
use JSON;
use 5.018;
use strict;
use threads;
use warnings;
use Thread::Queue;
use Find::Lib "./lib";
use Functions::Helper;
use Functions::Parser;
use Engine::Fuzzer;
use Getopt::Long qw(:config no_ignore_case pass_through);
my $wordlist_queue = Thread::Queue -> new();
sub fuzzer_thread {
my ($target, $methods, $agent, $headers, $accept, $timeout, $return, $payload, $json, $delay, $exclude, $skipssl) = @_;
my @verbs = split (/,/, $methods);
my @valid_codes = split /,/, $return || "";
my @invalid_codes = split /,/, $exclude || "";
my $fuzzer = Engine::Fuzzer->new($timeout, $headers, $skipssl);
while (defined(my $resource = $wordlist_queue->dequeue())) {
my $endpoint = $target . $resource;
for my $verb (@verbs) {
my $result = $fuzzer -> request($verb, $agent, $endpoint, $payload, $accept);
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}
);
print $printable, "\n";
sleep($delay);
}
}
}
sub fill_queue {
my ($list, $n) = @_;
for (1 .. $n) {
return unless (@{$list} > 0);
if (eof($list -> [0])) {
close shift @{$list};
(@{$list} > 0) || $wordlist_queue->end();
next
}
my $fh = $list -> [0];
chomp(my $line = <$fh>);
$wordlist_queue -> enqueue($line);
}
}
sub run_fuzzer {
my ($args, $target) = @_;
my ($return, $payload, %headers, $accept, $json, $exclude, $skipssl);
my $agent = "Nozaki CLI / 0.2.3";
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;
Getopt::Long::GetOptionsFromArray (
$args,
"A|accept=s" => \$accept,
"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,
"S|skip-ssl" => \$skipssl,
);
my @current = map {
open(my $fh, "<$_") || die "$0: Can't open $_: $!";
$fh
} glob($wordlist);
fill_queue(\@current, 10 * $tasks);
async {
fuzzer_thread($target, $methods, $agent, \%headers, $accept, $timeout, $return, $payload, $json, $delay, $exclude, $skipssl);
} for 1 .. $tasks;
while (threads -> list(threads::running) > 0) {
fill_queue(\@current, $tasks);
}
map { $_ -> join() } threads -> list(threads::all);
return 0;
}
sub main {
my ($workflow, $target);
Getopt::Long::GetOptions (
"W|workflow=s" => \$workflow,
"u|url=s" => \$target,
);
if ($workflow) {
my $rules = Functions::Parser -> new($workflow);
for my $rule (@$rules) {
delete $rule -> {description};
my $args = [ map { "--$_" . ($rule->{$_} ? "=$rule->{$_}" : "") } keys %{$rule} ];
run_fuzzer($args, $target);
}
return 1;
}
if ($target) {
return run_fuzzer(\@ARGV, $target);
}
return Functions::Helper -> new();
}
exit main();