Skip to content

Commit fe78ac2

Browse files
author
GomoR
committed
- new: -wait command line option to change wait time between requests
- bugfix: whitelist function keeps results matching criterias from a CSV - bugfix: blacklist function removes results matching criterias from a CSV
1 parent e6e1db0 commit fe78ac2

File tree

6 files changed

+54
-17
lines changed

6 files changed

+54
-17
lines changed

Changes

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Revision history for Perl extension Metabrik::Client::Onyphe.
22

3+
1.06 Fri 20 Mar 09:30:03 CET 2020
4+
- new: -wait command line option to change wait time between requests
5+
- bugfix: whitelist function keeps results matching criterias from a CSV
6+
- bugfix: blacklist function removes results matching criterias from a CSV
7+
38
1.05 Wed 18 Mar 08:53:52 CET 2020
49
- update: API v2
510
- new: topsite, vulnscan, datamd5, domain and hostname API v2

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2018-2019, ONYPHE
3+
Copyright (c) 2018-2020, ONYPHE
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

README

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ EXAMPLES
9898

9999
COPYRIGHT AND LICENSE
100100

101-
Copyright (c) 2018-2019, ONYPHE
101+
Copyright (c) 2018-2020, ONYPHE
102102

103103
You may distribute this module under the terms of The BSD 3-Clause License.
104104
See LICENSE file in the source distribution archive.

bin/onyphe

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ my %lopts = (
1616
page => '1',
1717
autoscroll => '0',
1818
apiurl => 'https://www.onyphe.io/api/v2',
19+
wait => 2,
1920
);
2021

2122
# Option parsing
@@ -34,6 +35,7 @@ GetOptions(
3435
"maxpage=i" => \$lopts{maxpage},
3536
"autoscroll=i" => \$lopts{autoscroll},
3637
"apiurl=s" => \$lopts{apiurl},
38+
"wait=i" => \$lopts{wait},
3739
) or usage();
3840

3941
# Load API key from onyphe rc file
@@ -48,6 +50,7 @@ $cli->log->level($lopts{verbose});
4850
$cli->apikey($lopts{apikey});
4951
$cli->apiurl($lopts{apiurl});
5052
$cli->autoscroll($lopts{autoscroll} ? 1 : 0);
53+
$cli->wait($lopts{wait});
5154

5255
# Launch query
5356
my $r;
@@ -109,6 +112,7 @@ Usage: onyphe [options] -search 'category:CATEGORY SEARCH'
109112
or remove (-) from output
110113
-encode <FIELD1,FIELD2,...FIELDn> comma separated list of fields to Base64 encode
111114
-verbose <0|1|2|3> verbosity level (default: 0)
115+
-wait <SECONDS> wait time in regards to rate limit (default: 2)
112116
113117
EOF
114118
;
@@ -194,7 +198,7 @@ __END__
194198
195199
=head1 COPYRIGHT AND LICENSE
196200
197-
Copyright (c) 2018-2019, ONYPHE
201+
Copyright (c) 2018-2020, ONYPHE
198202
199203
You may distribute this module under the terms of The BSD 3-Clause License.
200204
See LICENSE file in the source distribution archive.

lib/Metabrik/Api/Onyphe.pm

+4-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ sub api {
9292
my $code = $self->code;
9393
if ($code == 429) {
9494
$self->log->verbose("api: request limit reached, waiting before retry");
95-
sleep($wait);
95+
if (defined($wait) && $wait > 0) {
96+
sleep($wait);
97+
}
9698
goto RETRY;
9799
}
98100
elsif ($code == 200) {
@@ -272,7 +274,7 @@ Metabrik::Api::Onyphe - api::onyphe Brik
272274
273275
=head1 COPYRIGHT AND LICENSE
274276
275-
Copyright (c) 2014-2019, Patrice E<lt>GomoRE<gt> Auffret
277+
Copyright (c) 2014-2020, Patrice E<lt>GomoRE<gt> Auffret
276278
277279
You may distribute this module under the terms of The BSD 3-Clause License.
278280
See LICENSE file in the source distribution archive.

lib/Metabrik/Client/Onyphe.pm

+38-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package Metabrik::Client::Onyphe;
55
use strict;
66
use warnings;
77

8-
our $VERSION = '1.04';
8+
our $VERSION = '1.06';
99

1010
use base qw(Metabrik);
1111

@@ -19,12 +19,14 @@ sub brik_properties {
1919
apikey => [ qw(apikey) ],
2020
apiurl => [ qw(apiurl) ],
2121
autoscroll => [ qw(0|1) ],
22+
wait => [ qw(seconds) ],
2223
_ao => [ qw(INTERNAL) ],
2324
_sb => [ qw(INTERNAL) ],
2425
},
2526
attributes_default => {
2627
apiurl => 'https://www.onyphe.io/api/v2',
2728
autoscroll => 0,
29+
wait => 2,
2830
},
2931
commands => {
3032
user => [ ],
@@ -356,6 +358,9 @@ sub function_merge {
356358
return $return->();
357359
}
358360

361+
#
362+
# Will remove everything from input stream on matches.
363+
#
359364
sub function_blacklist {
360365
my $self = shift;
361366
my ($r, $lookup) = @_;
@@ -393,20 +398,28 @@ sub function_blacklist {
393398
for my $page (@$r) {
394399
for my $this (@{$page->{results}}) {
395400
my $skip = 0;
401+
# $field is the field to match against (example: domain):
396402
for my $field (@$fields) {
397-
if (defined($self->_value($this, $field))) {
403+
# Fetch the value from current result $this:
404+
my $value = $self->_value($this, $field);
405+
if (defined($value)) {
406+
# Compare against all fields given in the CSV:
398407
for my $h (@$l) {
399-
if (exists($h->{$field})
400-
&& $h->{$field} ne $self->_value($this, $field)) {
408+
if (exists($h->{$field}) && $h->{$field} eq $value) {
409+
#print "[DEBUG] skip field [$field] value [$value]\n";
401410
$skip++;
402411
last;
403412
}
404413
}
405414
}
406-
last if $skip == $fields_count;
415+
# When all fields have matched, no need to compare with remaining
416+
if ($skip == $fields_count) {
417+
#print "[DEBUG] all fields matched [$skip]\n";
418+
last;
419+
}
407420
}
408-
if ($skip != $fields_count) { # Not all fields have matched,
409-
# we keep results.
421+
if ($skip != $fields_count) { # Not all fields have matched, it is
422+
# NOT blacklisted, we keep results
410423
push @new, $this;
411424
}
412425
}
@@ -415,6 +428,9 @@ sub function_blacklist {
415428
return $return->();
416429
}
417430

431+
#
432+
# Will keep everything from input stream on matches.
433+
#
418434
sub function_whitelist {
419435
my $self = shift;
420436
my ($r, $lookup) = @_;
@@ -452,18 +468,28 @@ sub function_whitelist {
452468
for my $page (@$r) {
453469
for my $this (@{$page->{results}}) {
454470
my $skip = 0;
471+
# $field is the field to match against (example: domain):
455472
for my $field (@$fields) {
456-
if (defined($self->_value($this, $field))) {
473+
# Fetch the value from current result $this:
474+
my $value = $self->_value($this, $field);
475+
if (defined($value)) {
476+
# Compare against all fields given in the CSV:
457477
for my $h (@$l) {
458-
if (exists($h->{$field}) && $h->{$field} eq $self->_value($this, $field)) {
478+
if (exists($h->{$field}) && $h->{$field} eq $value) {
479+
#print "[DEBUG] skip field [$field] value [$value]\n";
459480
$skip++;
460481
last;
461482
}
462483
}
463484
}
464-
last if $skip == $fields_count;
485+
# When all fields have matched, no need to compare with remaining
486+
if ($skip == $fields_count) {
487+
#print "[DEBUG] all fields matched [$skip]\n";
488+
last;
489+
}
465490
}
466-
if ($skip != $fields_count) { # No all fields have matched, we keep results.
491+
if ($skip == $fields_count) { # All fields have matched, it is
492+
# whitelisted, we keep results.
467493
push @new, $this;
468494
}
469495
}
@@ -895,7 +921,7 @@ L<Metabrik>
895921
896922
=head1 COPYRIGHT AND LICENSE
897923
898-
Copyright (c) 2018-2019, ONYPHE
924+
Copyright (c) 2018-2020, ONYPHE
899925
900926
You may distribute this module under the terms of The BSD 3-Clause License.
901927
See LICENSE file in the source distribution archive.

0 commit comments

Comments
 (0)