How do I download a report via the JSON interface?

Once you have issued a command and have asked the system to provide you with (for example) an XML report using the following short-form code:

my %hashItems;
$hashItems{'primary'} = 'vulnerabilities';
$hashItems{'secondary'} = "report";
$hashItems{'action'} = 'getreport';
$hashItems{'format'} = "xml";
$hashItems{'network'} = "$Network";
$hashItems{'apikey'} = $APIKey;

a JSON data object is returned, one of the fields found in it is called 'compresseddata', this field needs to be first base64 decoded and then uncompressed. The compression algorithm used on this field is the very common and widely used Zlib compression.

Again in pseudo code without a lot of testing, the flow would look something like:

 my $compresseddata = "";
 if (defined $result{'compresseddata'}) {
  $compresseddata = $result{'compresseddata'};
 }

 if (length($compresseddata) != $result{'compressedlength'}) {
  print STDERR "Invalid compressed data has been received\n";
  next;
 }

 use Compress::Zlib qw(uncompress);
 use MIME::Base64  qw(decode_base64);
 my $uncompresseddata = uncompress(decode_base64($compresseddata));

 if (length($uncompresseddata) != $result{'uncompressedlength'}) {
  print STDERR "Invalid uncompressed data has been received (".length($uncompresseddata)." != ".$result{'uncompressedlength'}.")\n";
  next;
 }

 if(open(FILE, "> $Filename")) {
  print FILE $uncompresseddata;
  close(FILE);
 }
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk