Jump to content
SergioC92

Script VirusTotal no meu website.

Recommended Posts

SergioC92

Antes de mais nada, boa tarde.

Sou principiante em PHP e estou a tentar utilizar um script que encontrei que tem como função enviar um ficheiro para o virustotal e apresentar o scan na pagina do meu site.

O problema é que ainda não consegui porque por alguma razão aparece sempre um erro qualquer  :down:

Aqui vos deixo o código da pagina de upload e do script para enviar o ficheiro para o virustotal e receber o report:

ficheiroscan.php

lwarew<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Resultados da Análise - Malware Data Report</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>

<body>
<div id="container">
<div id="header">
    	<h1 align="center"><a href="/"><img src="images/logo.jpg" alt="Malware Data Report" width="468" height="60" /></a></h1>
      <h2> </h2>
      <div class="clear"></div>
  </div>
<div id="nav">
    	<ul>
       	   <li><a href="ficheiro.html">AnAlise ficheiros</a></li>
          <li><a href="logs.html">AnAlise Logs</a></li>
          <li><a href="estatisticas.html">EstatIsticas</a></li>
           <li><a href="download.html">Software</a></li>
           <li></li>
           <li><a href="sobre.html">Sobre</a></li>
          <li><a href="contacto.html">Contacto</a></li>
            <li class="nav-search">
                <form method="get" class="searchform" action="#" >
                    <p> </p>
                </form>	
            </li>
        </ul>
  </div>
<div id="page-intro">
  <h2>Análise de ficheiros suspeitos e recolha de informação</h2>
    	<p>Malware Data Report é um serviço disponibilizado gratuitamente que analísa ficheiros suspeitos facilitando assim a detecção de qualquer tipo de malware detectado por software anti-vírus. <a href="sobre.html">Mais informação</a></p>
  </div>
  <div id="body">
<div id="content">
		<h2>Análise do ficheiro</h2>
      <p><h3 align="center">Resultados do ficheiro <b><?php echo basename( $_FILES['uploadedfile']['name']) ; ?></b>: </h3></p>
  
  		<?php

			$target_path = "reportedfiles/";
			$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

			if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
				echo("<script language='JavaScript'>
					window.alert('O ficheiro ". basename( $_FILES['uploadedfile']['name']) ." foi enviado com sucesso.')
					</script>");
			} else{
				echo "Ocorreu um erro ao enviar o ficheiro, por favor tente novamente!";
			}

			include "reportedfiles/virustotal.php";
		?>
      
        <p align="center"><br />
        </p>
      </form>
      </p>

    </div>
        
        <div class="sidebar">
            <ul>	
               <li>
                    <h4><span>Navegar</span></h4>
            <ul class="blocklist">
                        <li><a href="ficheiro.html">Enviar Ficheiro</a></li>
              <li><a href="download.html">Download do Software</a></li>
              <li><a href="estatisticas.html">Gráficos</a></li>
    <li><a href="sobre.html">Sobre</a></li>
                        <li><a href="contacto.html">Contacto</a></li>
                        <li></li>
                        <li>
                          <ul>
                            <li>
                                      <h4> </h4>
                            </li>
                            <li>
                              <h4>patrocinadores</h4>
                              <ul>
                                  <li><a href="http://www.themeforest.net/?ref=spykawg" title="premium templates"><strong>ThemeForest</strong></a> - premium HTML templates, WordPress themes and PHP scripts</li>
                              </ul>
                            </li>
                          </ul>
                        </li>
            </ul>
                </li>
                </ul> 
    </div>
   	<div class="clear"></div>
    </div>
</div>
<div id="footer">
<p>© Malware Data Report 2011.</p>
</div>
</body>
Programado para Malware Data Report - Sérgio Camilo
</html>

virustotal.php

<?php

// Date: 11/11/10

// This file contains five functions: virustotal_scanfile(), virustotal_getreport(), 
// virustotal_makecomment(), virustotal_scanurl() and virustotal_geturlreport().

// virustotal_scanfile() uploads a file to Virus Total.
// virustotal_getreport() retrieves the virus report.
// virustotal_makecomment() adds a comment to an already uploaded file
// virustotal_scanurl() sends a URL to scan
// virustotal_geturlreport() sends a URL to scan or gets a URL report

// You cannot execute virustotal_getreport() immediately after virustotal_scanfile() as
// Virus Total needs a moment to get and process the file.

// To use Virus Total's API you need an API key. To get that you need to register here:
// http://www.virustotal.com/vt-community/register.html. Then go to My Account > Inbox > 
// Public API.


$key = 'e9976d185d2f6f0c61412b317ebdd3d9446408c52295a7d2fdcd4ff7e2c2a5e3'; // Your API key
$file = $_FILES['uploadedfile']['name']; // The file to be scanned or to retrieve a virus report for





// Start: Upload file ||===================================================================

// Desc: This segment of code uploads the file to Virus Total who send back a hash of the 
// file. This hash will be used with the  virustotal_getreport() function (the second 
// segment of code) to retrieve the virus report.

$scan = virustotal_scanfile($file, $key);

$scan_result = $scan;

$scan_id = explode('-', $scan_result['scan_id']);
$scan_id = $scan_id[0];

echo $scan_id; // Hash to use with virustotal_getreport()

// End: Upload file ||=====================================================================





// Start: Get scan report ||===============================================================

// Desc: This segment of code sends a file hash of a previously uploaded file to Virus 
// Total who sends back the virus report. To get this hash the file must first be 
// uplaoded using the virustotal_scanfile() function (the first segment of code)

$resource = md5_file($file); // Hash of file. Also returned by virustotal_scanfile()

$retrieve = virustotal_getreport($resource, $key);

if($retrieve){
print_r($retrieve); // Array containing virus report
}

// End: Get scan report ||=================================================================





// Functions

function virustotal_scanfile($filepath, $key){

// Desc: Uploads a file to Virus Total. Virus Total will send back a hash of the file
// if successful

// $filepath: Path of file to upload
// $key: API key

// Author: Peter Bailey
// Website: Bailey-Projects.com

$post = array('key' => $key, 'file' => '@'.$filepath);

$ch = curl_init();

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_URL, 'http://www.virustotal.com/api/scan_file.json');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   

$result = curl_exec($ch);

curl_close($ch);

$result = json_decode($result, true);

if(isset($result['scan_id'][0])){
	return $result;
} else {
	return false;
}

}

function virustotal_getreport($resource, $key){

// Desc: Sends a file hash of a previously uploaded file to Virus Total. Virus Total 
// will send back a virus report of the file.

// $resource: Hash of uploaded file
// $key: API key

// Author: Peter Bailey
// Website: Bailey-Projects.com

$url = 'https://www.virustotal.com/api/get_file_report.json';
$fields = array('resource'=>$resource, 'key'=>$key);

foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = rtrim($fields_string,'&');

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

$result = json_decode($result, true);

if(isset($result['report'][0])){
	return $result;
} else {
	return false;
}

}

function virustotal_makecomment($fileorurl, $key, $comment, $tags = ''){

// Desc: Adds a comment to an uploaded file. Returns true if comment 
// addition was successful and false if it wasn't.

// $fileorurl: the file hash, scanid, or url of what you're commenting on
// $key: API key
// $comment: your comment
// $tags: any optional tags you wish to use, see http://www.virustotal.com/advanced.html#publicapi 
// for syntax details.

    // Author: Kenny Lyons aka ih8censorship
// Website: http://pasture.sourceforge.net

    $url = 'http://www.virustotal.com/api/make_comment.json';
    
$fields = array('key'=>$key,'comment'=>$comment);
 if(preg_match('/^https?:\/\/.*/',$fileorurl)){
    $fields['url']=$fileorurl;
 } else {
    $fields['file']=$fileorurl;
 }

    $fields_string='';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }

$fields_string=rtrim($fields_string,'&');

    $ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

$result = json_decode($result, true);

 if($result['result']=="1"){
 	return true;
 } else {
 	return false;
 }
}

function virustotal_scanurl($url, $key){

// Desc: Submits URL to Virus Total to scan. Returns Virus Total's scan ID 
// if successful, otherwise false.

// $key: API key
// $url: the url you want to scan

    // Author: Kenny Lyons aka ih8censorship
// Website: http://pasture.sourceforge.net

    $url = 'http://www.virustotal.com/api/scan_url.json';
$fields = array('url'=>$url, 'key'=>$key);
    $fields_string='';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string=rtrim($fields_string,'&');

    $ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

$result = json_decode($result, true);

if($result['result']=="1"){
	return $result['scan_id'];
} else {
	return false;
}

}

function virustotal_geturlreport($key,$resource,$scan=false){

// Desc: Uploads or downloads a URL to Virus Total to be scanned. If URL was previously uploaded
// will output report of URL. If $scan is set to "1" will return Virus Total's scan ID which can
// be used to retrieve the report at a later date.

// $key: API key
// $resource: A URL, file hash, or scan_id
// $scan: Optional. If set to "1" URL will be submitted for analysis if it hasen't already been analyized

    // Author: Kenny Lyons aka ih8censorship
// Website: http://pasture.sourceforge.net

    $url = 'http://www.virustotal.com/api/get_url_report.json';
$fields = array('resource'=>$resource, 'key'=>$key,'scan'=>$scan);
    $fields_string='';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string=rtrim($fields_string,'&');

    $ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

$result = json_decode($result, true);

 if($scan && $result['result']=="0"){
 	return $result['scan_id'];
 } else {
 	return $result;
 }

}

?>

Os erros que me aparecem de momento são estes:

Warning: md5_file(ficheiroteste.txt) [function.md5-file]: failed to open stream: No such file or directory in D:\Webserver\htdocs\malwaredatareport.com\reportedfiles\virustotal.php on line 56

Notice: Undefined variable: fields_string in D:\Webserver\htdocs\malwaredatareport.com\reportedfiles\virustotal.php on line 120

Qualquer tipo de ajuda será bem-vinda.  ;)

Share this post


Link to post
Share on other sites
mAiN_iNfEcTiOn

tenta usar o caminho do ficheiro todo nao so o nome e da uma vista de olhos a isto : http://php.net/manual/en/function.md5-file.php

Tal como o overblue diz e muito bem. O problema está no caminho que o script usa... Onde tens - no virustotal.php- na linha:

$file = $_FILES['uploadedfile']['name']; // The file to be scanned or to retrieve a virus report for

Deves alterar para:

$file = "reportedfiles/" . $_FILES['uploadedfile']['name']; // The file to be scanned or to retrieve a virus report for

Depois deverá funcionar ;)

Share this post


Link to post
Share on other sites
SergioC92

Muito obrigado pelas respostas, já não dá erro nenhum!

O problema é que não me aparece nenhum report do VirusTotal,  será que é o script que não está a funcionar correctamente?  :cheesygrin:

O site é este:

http://malwaredatareport.net46.net/ficheiro.html

A unica coisa que aparece é isto:

/home/a7801314/reportedfiles/N3tshell.txt337e62a0d2041fd58d4b39e743043a429a63337a3b5522530a4d3241098f2dea

Share this post


Link to post
Share on other sites
mAiN_iNfEcTiOn

Ok... onde tens (no ficheiro virustotal.php):

$scan_result = $scan;

na linha a seguir adiciona:

var_dump($scan_result);

E diz-me o que aparece (estamos a debuggar... isso nao eh a solução :cheesygrin: )

Share this post


Link to post
Share on other sites
mAiN_iNfEcTiOn

Muito obrigado pelas respostas, já não dá erro nenhum!

O problema é que não me aparece nenhum report do VirusTotal,  será que é o script que não está a funcionar correctamente?  :)

O site é este:

http://malwaredatareport.net46.net/ficheiro.html

A unica coisa que aparece é isto:

/home/a7801314/reportedfiles/N3tshell.txt337e62a0d2041fd58d4b39e743043a429a63337a3b5522530a4d3241098f2dea

Quanto a este problema, em parte tinha a ver com a linha:

echo $scan_id; // Hash to use with virustotal_getreport()

Relativamente ao outro problema, onde tens:

$resource = md5_file($file); // Hash of file. Also returned by virustotal_scanfile()

Altera para:

$resource = $scan_id; // Hash of file. Also returned by virustotal_scanfile()

Por fim, onde tens:

if($retrieve){
        print_r($retrieve); // Array containing virus report
}

Altera, temporariamente (para testes), para:

var_dump($retrieve);
/*
if($retrieve){
        print_r($retrieve); // Array containing virus report
}
*/

E diz-me o que aparece.....

Abraço :)

Share this post


Link to post
Share on other sites
SergioC92

Fiz tal como disses-te e apareceu isto:

c200ac615f70dbf8f69d06bf02e328e0a6a7a9ae323a2bfcf3ff10776a1a4044bool(false)

Cumps!

Share this post


Link to post
Share on other sites
mAiN_iNfEcTiOn

Coloca aqui o código dos dois ficheiros que mostraste no inicio do tópico para analisar como estão.

Share this post


Link to post
Share on other sites
SergioC92

Ficheiro ficheiroscan.php:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Resultados da Análise - Malware Data Report</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>

<body>
<div id="container">
<div id="header">
    	<h1 align="center"><a href="/"><img src="images/logo.jpg" alt="Malware Data Report" width="468" height="60" /></a></h1>
      <h2> </h2>
      <div class="clear"></div>
  </div>
<div id="nav">
    	<ul>
       	   <li><a href="ficheiro.html">AnAlise ficheiros</a></li>
          <li><a href="logs.html">AnAlise Logs</a></li>
          <li><a href="estatisticas.html">EstatIsticas</a></li>
           <li><a href="download.html">Software</a></li>
           <li></li>
           <li><a href="sobre.html">Sobre</a></li>
          <li><a href="contacto.html">Contacto</a></li>
            <li class="nav-search">
                <form method="get" class="searchform" action="#" >
                    <p> </p>
                </form>	
            </li>
        </ul>
  </div>
<div id="page-intro">
  <h2>Análise de ficheiros suspeitos e recolha de informação</h2>
    	<p>Malware Data Report é um serviço disponibilizado gratuitamente que analísa ficheiros suspeitos facilitando assim a detecção de qualquer tipo de malware detectado por software anti-vírus. <a href="sobre.html">Mais informação</a></p>
  </div>
  <div id="body">
<div id="content">
		<h2>Análise do ficheiro</h2>
      <p><h3 align="center">Resultados do ficheiro <b><?php echo basename( $_FILES['uploadedfile']['name']) ; ?></b>:</h3></p>
  		<?php

			$target_path = "/home/a7801314/reportedfiles/";
			$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

			if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
				echo("<script language='JavaScript'>
					window.alert('O ficheiro ". basename( $_FILES['uploadedfile']['name']) ." foi enviado com sucesso.')
					</script>");
			} else{
				echo "Ocorreu um erro ao enviar o ficheiro, por favor tente novamente!";
			}

			include "/home/a7801314/public_html/includes/virustotal.php";
		?>
        <p align="center"><br />
        </p>
      </form>
      </p>

    </div>
        
        <div class="sidebar">
            <ul>	
               <li>
                    <h4><span>Navegar</span></h4>
            <ul class="blocklist">
                        <li><a href="ficheiro.html">Enviar Ficheiro</a></li>
              <li><a href="download.html">Download do Software</a></li>
              <li><a href="estatisticas.html">Gráficos</a></li>
    <li><a href="sobre.html">Sobre</a></li>
                        <li><a href="contacto.html">Contacto</a></li>
                        <li></li>
                        <li>
                          <ul>
                            <li>
                                      <h4> </h4>
                            </li>
                            <li>
                              <h4>patrocinadores</h4>
                              <ul>
                                  <li><a href="http://www.themeforest.net/?ref=spykawg" title="premium templates"><strong>ThemeForest</strong></a> - premium HTML templates, WordPress themes and PHP scripts</li>
                              </ul>
                            </li>
                          </ul>
                        </li>
            </ul>
                </li>
                </ul> 
    </div>
   	<div class="clear"></div>
    </div>
</div>
<div id="footer">
<p>© Malware Data Report 2011.</p>
</div>
</body>
Programado para Malware Data Report - Sérgio Camilo
</html>

Ficheiro virustotal.php:

<?php

// Date: 11/11/10

// This file contains five functions: virustotal_scanfile(), virustotal_getreport(), 
// virustotal_makecomment(), virustotal_scanurl() and virustotal_geturlreport().

// virustotal_scanfile() uploads a file to Virus Total.
// virustotal_getreport() retrieves the virus report.
// virustotal_makecomment() adds a comment to an already uploaded file
// virustotal_scanurl() sends a URL to scan
// virustotal_geturlreport() sends a URL to scan or gets a URL report

// You cannot execute virustotal_getreport() immediately after virustotal_scanfile() as
// Virus Total needs a moment to get and process the file.

// To use Virus Total's API you need an API key. To get that you need to register here:
// http://www.virustotal.com/vt-community/register.html. Then go to My Account > Inbox > 
// Public API.


$key = 'e9976d185d2f6f0c61412b317ebdd3d9446408c52295a7d2fdcd4ff7e2c2a5e3'; // Your API key
$file = "/home/a7801314/reportedfiles/" . $_FILES['uploadedfile']['name']; // The file to be scanned or to retrieve a virus report for


// Start: Upload file ||===================================================================

// Desc: This segment of code uploads the file to Virus Total who send back a hash of the 
// file. This hash will be used with the  virustotal_getreport() function (the second 
// segment of code) to retrieve the virus report.

$scan = virustotal_scanfile($file, $key);

$scan_result = $scan;

$scan_id = explode('-', $scan_result['scan_id']);
$scan_id = $scan_id[0];

echo $scan_id; // Hash to use with virustotal_getreport()

// End: Upload file ||=====================================================================


// Start: Get scan report ||===============================================================

// Desc: This segment of code sends a file hash of a previously uploaded file to Virus 
// Total who sends back the virus report. To get this hash the file must first be 
// uplaoded using the virustotal_scanfile() function (the first segment of code)

$resource = $scan_id; // Hash of file. Also returned by virustotal_scanfile()

$retrieve = virustotal_getreport($resource, $key);

var_dump($retrieve);
/*
if($retrieve){
        print_r($retrieve); // Array containing virus report
}
*/

// End: Get scan report ||=================================================================





// Functions

function virustotal_scanfile($filepath, $key){

// Desc: Uploads a file to Virus Total. Virus Total will send back a hash of the file
// if successful

// $filepath: Path of file to upload
// $key: API key

// Author: Peter Bailey
// Website: Bailey-Projects.com

$post = array('key' => $key, 'file' => '@'.$filepath);

$ch = curl_init();

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_URL, 'http://www.virustotal.com/api/scan_file.json');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   

$result = curl_exec($ch);

curl_close($ch);

$result = json_decode($result, true);

if(isset($result['scan_id'][0])){
	return $result;
} else {
	return false;
}

}

function virustotal_getreport($resource, $key){

// Desc: Sends a file hash of a previously uploaded file to Virus Total. Virus Total 
// will send back a virus report of the file.

// $resource: Hash of uploaded file
// $key: API key

// Author: Peter Bailey
// Website: Bailey-Projects.com

$url = 'https://www.virustotal.com/api/get_file_report.json';
$fields = array('resource'=>$resource, 'key'=>$key);

foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = rtrim($fields_string,'&');

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

$result = json_decode($result, true);

if(isset($result['report'][0])){
	return $result;
} else {
	return false;
}

}

function virustotal_makecomment($fileorurl, $key, $comment, $tags = ''){

// Desc: Adds a comment to an uploaded file. Returns true if comment 
// addition was successful and false if it wasn't.

// $fileorurl: the file hash, scanid, or url of what you're commenting on
// $key: API key
// $comment: your comment
// $tags: any optional tags you wish to use, see http://www.virustotal.com/advanced.html#publicapi 
// for syntax details.

    // Author: Kenny Lyons aka ih8censorship
// Website: http://pasture.sourceforge.net

    $url = 'http://www.virustotal.com/api/make_comment.json';
    
$fields = array('key'=>$key,'comment'=>$comment);
 if(preg_match('/^https?:\/\/.*/',$fileorurl)){
    $fields['url']=$fileorurl;
 } else {
    $fields['file']=$fileorurl;
 }

    $fields_string='';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }

$fields_string=rtrim($fields_string,'&');

    $ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

$result = json_decode($result, true);

 if($result['result']=="1"){
 	return true;
 } else {
 	return false;
 }
}

function virustotal_scanurl($url, $key){

// Desc: Submits URL to Virus Total to scan. Returns Virus Total's scan ID 
// if successful, otherwise false.

// $key: API key
// $url: the url you want to scan

    // Author: Kenny Lyons aka ih8censorship
// Website: http://pasture.sourceforge.net

    $url = 'http://www.virustotal.com/api/scan_url.json';
$fields = array('url'=>$url, 'key'=>$key);
    $fields_string='';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string=rtrim($fields_string,'&');

    $ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

$result = json_decode($result, true);

if($result['result']=="1"){
	return $result['scan_id'];
} else {
	return false;
}

}

function virustotal_geturlreport($key,$resource,$scan=false){

// Desc: Uploads or downloads a URL to Virus Total to be scanned. If URL was previously uploaded
// will output report of URL. If $scan is set to "1" will return Virus Total's scan ID which can
// be used to retrieve the report at a later date.

// $key: API key
// $resource: A URL, file hash, or scan_id
// $scan: Optional. If set to "1" URL will be submitted for analysis if it hasen't already been analyized

    // Author: Kenny Lyons aka ih8censorship
// Website: http://pasture.sourceforge.net

    $url = 'http://www.virustotal.com/api/get_url_report.json';
$fields = array('resource'=>$resource, 'key'=>$key,'scan'=>$scan);
    $fields_string='';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string=rtrim($fields_string,'&');

    $ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

$result = json_decode($result, true);

 if($scan && $result['result']=="0"){
 	return $result['scan_id'];
 } else {
 	return $result;
 }

}

?>

Share this post


Link to post
Share on other sites
mAiN_iNfEcTiOn

Ok... como eu disse, altera esta linha (para não ter confusão com texto):

echo $scan_id; // Hash to use with virustotal_getreport()

para

#echo $scan_id; // Hash to use with virustotal_getreport()

Além disto, não vejo outra razão para teres problemas... se está a retornar false, é porque o curl nem consegue lá chegar :| Porque no máximo, a fazer var_dump ele deveria dar um int e não um bool com resultado 0.

Share this post


Link to post
Share on other sites
SergioC92

Será então que o host não tem o curl activo?

Em localhost apareceu vários erros com o curl e tive de o activar...

Vou tentar fazer tudo em localhost agora.

Obrigado pela ajuda!  :P

Share this post


Link to post
Share on other sites
SergioC92

Não consigo mesmo meter isto a funcionar não faço ideia porquê, muito obrigado pela tua ajuda mAiN_iNfEcTiOn.

Será que alguém me poderia ajudar? Este é o meu projecto para a PAP e precisava mesmo de avançar, porque estou preso aqui e ainda me faltam fazer algumas coisas.

Qualquer ajuda será muito útil mesmo.

Cumps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.