#
# $Id$
#
# string::json Brik
#
package Metabrik::String::Json;
use strict;
use warnings;
use base qw(Metabrik);
sub brik_properties {
return {
revision => '$Revision$',
tags => [ qw
attributes_default => {
use_utf8 => 1,
},
require_modules => {
'JSON::XS' => [ ],
},
};
}
sub encode {
my $self = shift;
my ($data) = @_;
$self->b
turn;
$self->log->debug("encode: data[$data]");
my $encoded = '';
eval {
my $j = JSON::XS->new;
$j->relaxed(1);
$j->utf8($self->use_utf8);
$encoded = $j->encode($dat
#
# $Id$
#
# file::json Brik
#
package Metabrik::File::Json;
use strict;
use warnings;
use base qw(Metabrik::File::Text);
sub brik_properties {
return {
revision => '$Revision$',
tags
w($json_hash output_file|OPTIONAL) ],
is_valid => [ qw(input_file|OPTIONAL) ],
},
require_modules => {
'Metabrik::File::Write' => [ ],
'Metabrik::String::Json' =
|| 'utf8',
},
};
}
sub brik_init {
my $self = shift;
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
$self->_sj($sj);
return $self->SUPER::brik_init;
}
output_mode => [ qw(json|xml) ],
apikey => [ qw(apikey) ],
uri => [ qw(shodan_uri) ],
},
attributes_default => {
output_mode => 'json',
ssl_verify =
require_modules => {
'Metabrik::Network::Address' => [ ],
'Metabrik::String::Json' => [ ],
'Metabrik::String::Xml' => [ ],
},
};
}
sub myip {
my $self = shif
-info?key='.$apikey) or return;
my $content = $resp->{content};
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
my $decoded = $sj->decode($content) or return;
retur
> [ qw(apikey) ],
output_mode => [ qw(json|xml) ],
},
attributes_default => {
ssl_verify => 0,
output_mode => 'json',
},
commands => {
check
_domains => [ qw(ipv4_address) ],
},
require_modules => {
'Metabrik::String::Json' => [ ],
'Metabrik::String::Xml' => [ ],
},
};
}
sub check_resource {
my $s
$self->log->verbose("check_resource: returned code [$code]");
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
my $decode = $sj->decode($content) or return;
return
heck/[IP]/json?key=[API_KEY]&days=[DAYS]
#
$self->get(
'https://www.abuseipdb.com/check/'.$ip.'/json?key='.$api_key.'&days='.$days
) or return;
my $r = $self->content('json');
#
# https://www.abuseipdb.com/report/json?key=[API_KEY]&category=[CATEGORIES]&comment=[COMMENT]&ip=[IP]
#
$self->get(
'https://www.abuseipdb.com/report/json?key='.$api_key.'&category='.$cate
gory.
'&comment='.$comment.'&ip='.$ip
) or return;
return $self->content('json');
}
1;
__END__
=head1 NAME
Metabrik::Api::Abuseipdb - api::abuseipdb Brik
=head1 COPYRIGHT AND LICENSE
rd) ], # Inherited
ssl_verify => [ qw(0|1) ], # Inherited
output_mode => [ qw(json|xml|csv) ],
count => [ qw(number) ],
offset => [ qw(number) ],
},
a
localhost:8089',
username => 'admin',
ssl_verify => 0,
output_mode => 'json',
count => 1000, # 0 means return everything
offset => 0, # 0 means return ev
rn;
my $r = $self->get($uri) or return;
my $headers = $r->{headers};
# Taken from apps.json from Wappalyzer
my @headers = qw(
IBM-Web2-Location
X-Drupal-Cache
X-Powered
identify, 'xml';
}
elsif ($subset =~ /^\s*{\s+["a-zA-Z0-9:]+\s+/) {
push @$identify, 'json';
}
elsif ($string =~ /^[a-zA-Z0-9+]+={1,2}$/) {
push @$identify, 'base64';
}
e
de => [ qw(json|xml) ],
},
attributes_default => {
uri => 'https://localhost:8089',
username => 'admin',
ssl_verify => 0,
output_mode => 'json',
}
category => [ qw(uri) ],
},
require_modules => {
'Metabrik::String::Json' => [ ],
'Metabrik::String::Xml' => [ ],
},
};
}
sub category {
my $self =
categorization')
or return;
my $content = $r->{content};
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
my $decode = $sj->decode($content) or return;
# Exam
rd) ], # Inherited
ssl_verify => [ qw(0|1) ], # Inherited
output_mode => [ qw(json|xml|csv) ],
count => [ qw(number) ],
offset => [ qw(number) ],
},
a
localhost:8089',
username => 'admin',
ssl_verify => 0,
output_mode => 'json',
count => 1000,
offset => 0,
},
commands => {
search => [
n;
my $output_mode = $self->output_mode;
if ($output_mode ne 'xml'
&& $output_mode ne 'json'
&& $output_mode ne 'csv') {
return $self->log->error("get_results: output_mode not sup
ng_from_json_file => [ qw(index type file) ],
update_mapping_from_json_file => [ qw(file index type) ],
put_template => [ qw(name template) ],
put_template_from_json_file =>
[ qw(file name|OPTIONAL) ],
update_template_from_json_file => [ qw(file name|OPTIONAL) ],
get_settings => [ qw(index|indices_list|OPTIONAL name|names_list|OPTIONAL) ],
put_
L) ],
export_as_csv => [ qw(index size|OPTIONAL callback|OPTIONAL) ],
export_as_json => [ qw(index size|OPTIONAL callback|OPTIONAL) ],
import_from => [ qw(format input index
nds => {
install => [ ], # Inherited
stdin_to_stdout => [ ],
stdin_to_json => [ ],
test_filter_against_string => [ qw(filter_file string|string_list) ],
t
to_json {
my $self = shift;
my $binary = $self->get_binary or return;
my $cmd = "$binary -e 'input { stdin { } } output { stdout { codec => json } }'";
$self->log->info("stdin_to_json:
ONAL) ],
match_phrase => [ qw(kv index|OPTIONAL type|OPTIONAL) ],
from_json_file => [ qw(json_file index|OPTIONAL type|OPTIONAL) ],
from_dump_file => [ qw(dump_file index|OP
pe);
}
sub from_json_file {
my $self = shift;
my ($file, $index, $type) = @_;
$index ||= $self->index;
$type ||= $self->type;
$self->brik_help_run_undef_arg('from_json_file', $file) o
lp_run_file_not_found('from_json_file', $file) or return;
$self->brik_help_set_undef_arg('from_json_file', $index) or return;
$self->brik_help_set_undef_arg('from_json_file', $type) or return;
},
require_modules => {
'Metabrik::Devel::Git' => [ ],
'Metabrik::String::Json' => [ ],
'Metabrik::String::Xml' => [ ],
},
require_binaries => {
p
->repo;
my $cmd = $repo.'/bin/search.py -o json -p '.$cpe;
my $json = $self->capture($cmd) or return;
if (@$json <= 0 || (@$json == 1 && $json->[0] eq 'undef')) {
return $self->log->e
e: invalid response: ".join('', @$json));
}
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
my @results = ();
for my $this (@$json) {
my $r = $sj->decode($thi
query => [ qw(query index|OPTIONAL type|OPTIONAL) ], # Inherited
from_json_file => [ qw(json_file index|OPTIONAL type|OPTIONAL) ], # Inherited
from_dump_file => [ qw(dump_f
=> [ qw(command uri|OPTIONAL) ],
},
require_modules => {
'Metabrik::String::Json' => [ ],
'Metabrik::String::Parse' => [ ],
},
};
}
#
# http://www.cve.mitre.or
rn $self->log->error("check_cve_2015_1427_rce: no content found");
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
my $ref = $sj->decode($content) or return;
if ($ref
$self->log->error("exploit_cve_2015_1427_rce: no content found");
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
my $ref = $sj->decode($content) or return;
if ($ref
fy => [ qw(0|1) ], # Inherited
output_mode => [ qw(json|xml) ],
},
attributes_default => {
output_mode => 'json',
},
commands => {
reset_user_agent =
,
require_modules => {
'Metabrik::String::Xml' => [ ],
'Metabrik::String::Json' => [ ],
},
};
}
sub content {
my $self = shift;
my ($output_mode) = @_;
my $
}
my $sm;
$output_mode ||= $self->output_mode;
if ($output_mode eq 'json') {
$sm = Metabrik::String::Json->new_from_brik_init($self) or return;
}
elsif ($output_mode eq 'xml') {
host => "127.0.0.1"
data_type => "list"
key => "logstash"
codec => json
congestion_interval => 1
congestion_threshold => 20000000
# Batch proc
_events => 50
batch_timeout => 5
}
}
else {
stdout {
codec => json
}
}
}
EOF
;
my $ft = Metabrik::File::Text->new_from_brik_init($self) or return;
$
,
output_mode => [ qw(json|xml) ],
},
attributes_default => {
hostname => 'localhost',
port => 8888,
output_mode => 'json',
},
commands => {
ndlers post_handlers|OPTIONAL) ],
},
require_modules => {
'Metabrik::String::Json' => [ ],
'Metabrik::String::Xml' => [ ],
},
};
}
sub start {
my $self = shi
tp->mount('/' => { path => $root });
my $se;
if ($self->output_mode eq 'json') {
$se = Metabrik::String::Json->new_from_brik_init($self) or return;
}
elsif ($self->output_mode eq 'x
is {
host => "$redis_host"
key => "logstash"
data_type => "list"
codec => json
}
}
output {
if "_grokparsefailure" in [tags] {
null {}
}
if [type] == "exampl