LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-09-2021, 10:08 AM   #1
//////
Member
 
Registered: Nov 2005
Location: Land of Linux :: Finland
Distribution: Arch Linux && OpenBSD 7.4 && Pop!_OS && Kali && Qubes-Os
Posts: 824

Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
PERL : virustotal api v2 - uploader doesn't work.


hello again.

i am writing perl program that automatically submits to virustotal files from suricatas filestore.
i have written it mostly, just need to make it prettier , i'm just having problem with error message :
Code:
[root@arch vile]# perl /home/vile/Documents/upload.pl
Use of uninitialized value $v in concatenation (.) or string at /usr/share/perl5/site_perl/Net/HTTP/Methods.pm line 161.
https://www.virustotal.com/vtapi/v2/file/scan error: 403 Forbidden at /home/vile/Documents/upload.pl line 61.
[root@arch vile]#
here is full example of it :
Code:
#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
use LWP::UserAgent;
use JSON;

use vars qw( @directories_list @dirs $dir $path $file $testfile $shafile $pathtofile $dirname $dir00 $dir0a $fh );
my @directories_list = qw(  00  0a  );

# make temp directories.
$dirname ="/tmp/testdir";
mkdir $dirname, 0755;
$dir00 ="/tmp/testdir/00";
mkdir $dir00, 0755;
$dir0a ="/tmp/testdir/0a";
mkdir $dir0a, 0755;

$path = "/tmp/testdir/";
@dirs = split /\ /, "@directories_list";

for $dir (@dirs) {
	# write test file '00cd8531e2d74a39ab5df9883bd57cde7a9b6fc0c3cbe8b5600206997ae2f377' sha256sum of file is its name.
	open $fh, '>', "$path$dir/00cd8531e2d74a39ab5df9883bd57cde7a9b6fc0c3cbe8b5600206997ae2f377";
    print {$fh} 'foooooooooooo';
    print {$fh} 'bAAAAAAAAAAAAr';
    print {$fh} 'DDDDDDDDDDDDD';
    close $fh;
	
	#print "$path";
	#print "$dir\n";
	
	$pathtofile = "$path$dir";
	find(\&testfile, $pathtofile);
}

sub testfile {
	if ($File::Find::name =~ /[a-z0-9]{64}$/) { # <-- matches sha256sum
		#print "$File::Find::name\n" ;
		submitter("$File::Find::name\n");
	}
}

sub submitter {
	
$shafile = $_[0];
	#print "	SUBMITTER $shafile\n";
	
sleep(20);

my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 });
my $url='https://www.virustotal.com/vtapi/v2/file/scan';

#   key 'ee6e59074a21711e1125bbe678b595e40b2cc82ff3f82cd923a9100f7d50e77b' is valid key.
my $key='ee6e59074a21711e1125bbe678b595e40b2cc82ff3f82cd923a9100f7d50e77b';

my $response = $ua->post( $url,
    Content_Type => 'multipart/form-data',
    Content => ['apikey'] => $key,
    'file' => ['$shafile']
  );
die "$url error: ", $response->status_line
   unless $response->is_success;
my $results=$response->content;

#pulls the sha256 value out of the JSON response
#Note: there are many other values that could also be pulled out
my $json = JSON->new->allow_nonref;   
my $decjson = $json->decode( $results);
my $sha=$decjson->{"sha256"};
print $sha ."\n\n";

#Code to retrieve the results that pertain to a submitted file by hash value
$url='https://www.virustotal.com/vtapi/v2/file/report';

$response = $ua->post( $url,
    ['apikey' => $key,
    'resource' => $sha]
  );
die "$url error: ", $response->status_line
   unless $response->is_success;
$results=$response->content;

#processes the JSON to see how many AV products consider the file a virus
$json = JSON->new->allow_nonref;   
$decjson = $json->decode( $results);
print $decjson->{"positives"};
}
hoping that this problem is easy one
i am not experienced enough to fix it myself so i posted here, any hints about how i should fix it are welcomed.

thanks.

Last edited by //////; 02-12-2021 at 03:20 PM.
 
Old 02-09-2021, 12:23 PM   #2
//////
Member
 
Registered: Nov 2005
Location: Land of Linux :: Finland
Distribution: Arch Linux && OpenBSD 7.4 && Pop!_OS && Kali && Qubes-Os
Posts: 824

Original Poster
Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
find it :
Code:
my $response = $ua->post( $url,
    Content_Type => 'multipart/form-data',
    Content => ['apikey'] => $key,
    'file' => ['$shafile']
  );
needs to be :
Code:
my $response = $ua->post( $url,
    Content_Type => 'multipart/form-data',
    Content => ['apikey' => $key,
    'file' => ['$shafile']]
  );
 
  


Reply

Tags
perl, submit, upload, virustotal



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
virustotal qrange Linux - Security 9 05-13-2018 06:33 AM
LXer: Google's VirusTotal puts Linux malware under the spotlight LXer Syndicated Linux News 0 11-12-2014 01:20 PM
php uploader script probleme hua Programming 6 02-01-2007 11:00 PM
Perl/CGI uploader program - temp file not getting deleted anroy Programming 4 09-13-2006 02:33 AM
Simplest photograph uploader, editor, and album General Linux - Software 3 11-17-2005 05:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration