Jump to content

Laravel send file to scan at virustotal

Joveice
Go to solution Solved by Joveice,
On 8/18/2017 at 7:12 PM, leodaniel said:

 

On 8/17/2017 at 10:32 AM, leodaniel said:

This is probably wrong. The Storage::url will return you an relative URL to your APP root... something like '/storage/programs/...', which represents an absolute path in UNIX

So your file will not exists for curl_file_create because this is read as an absolute path!

So probably no file is sent.

 

How to get around this?


<?php 
    
    /* in your config/filesystems */

    
    'disks' => [
      
        /* Set the root and URL to the same path! */
        'your_disk'=>[
            'root' => storage_path('YourPath'),
            'url' => storage_path('YourPath'),
        ]
    ]

 

Thanks this works like a charm.

		$file_name_with_full_path = Storage::url('programs/XRZxjYMssX3ZZZN9cSlFJGMIyrz5tvDvuktXdtiQ.png');
                $api_key = config('VT_API_KEY');
                $cfile = curl_file_create($file_name_with_full_path);

                $post = array('apikey' => $api_key,'file'=> $cfile);
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, 'https://www.virustotal.com/vtapi/v2/file/scan');
                curl_setopt($ch, CURLOPT_POST, True);
                curl_setopt($ch, CURLOPT_USERAGENT, "scanner");
                curl_setopt($ch, CURLOPT_RETURNTRANSFER ,True);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

                $result=curl_exec ($ch);
                $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                print("status = $status_code\n");
                if ($status_code == 200) { // OK
                    $js = json_decode($result, true);
                    print_r($js);
                } else {  // Error occured
                    print($result);
                }
                curl_close ($ch);

This is my code, I get status = 0 as response. I belive the way the file is "delivered" does not work. what do I have to do (this is my first time using storage). (also I don't wanna scan my files with that name, I wanna replace them with a name etc this time cat.png, can someone show me a hardcoded way? I will do the dynamic way as soon as I know how to)

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

11 hours ago, Joveice said:

$file_name_with_full_path = Storage::url('programs/XRZxjYMssX3ZZZN9cSlFJGMIyrz5tvDvuktXdtiQ.png');

This is probably wrong. The Storage::url will return you an relative URL to your APP root... something like '/storage/programs/...', which represents an absolute path in UNIX

So your file will not exists for curl_file_create because this is read as an absolute path!

So probably no file is sent.

 

How to get around this?

<?php 
    
    /* in your config/filesystems */

    
    'disks' => [
      
        /* Set the root and URL to the same path! */
        'your_disk'=>[
            'root' => storage_path('YourPath'),
            'url' => storage_path('YourPath'),
        ]
    ]

 

Business Management Student @ University St. Gallen (Switzerland)

HomeServer: i7 4930k - GTX 1070ti - ASUS Rampage IV Gene - 32Gb Ram

Laptop: MacBook Pro Retina 15" 2018

Operating Systems (Virtualised using VMware): Windows Pro 10, Cent OS 7

Occupation: Software Engineer

Link to comment
Share on other sites

Link to post
Share on other sites

6 hours ago, leodaniel said:

This is probably wrong. The Storage::url will return you an relative URL to your APP root... something like '/storage/programs/...', which represents an absolute path in UNIX

So your file will not exists for curl_file_create because this is read as an absolute path!

So probably no file is sent.

 

How to get around this?


<?php 
    
    /* in your config/filesystems */

    
    'disks' => [
      
        /* Set the root and URL to the same path! */
        'your_disk'=>[
            'root' => storage_path('YourPath'),
            'url' => storage_path('YourPath'),
        ]
    ]

 

This solved the first part, now about renaming the file before it's posted, in this case rename it to cat.png how could I do that, I know how to do it when downloading the file.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

On 17/08/2017 at 5:17 PM, Joveice said:

This solved the first part, now about renaming the file before it's posted, in this case rename it to cat.png how could I do that, I know how to do it when downloading the file.

http://php.net/manual/en/curlfile.construct.php

 

Business Management Student @ University St. Gallen (Switzerland)

HomeServer: i7 4930k - GTX 1070ti - ASUS Rampage IV Gene - 32Gb Ram

Laptop: MacBook Pro Retina 15" 2018

Operating Systems (Virtualised using VMware): Windows Pro 10, Cent OS 7

Occupation: Software Engineer

Link to comment
Share on other sites

Link to post
Share on other sites

On 8/18/2017 at 7:12 PM, leodaniel said:

 

On 8/17/2017 at 10:32 AM, leodaniel said:

This is probably wrong. The Storage::url will return you an relative URL to your APP root... something like '/storage/programs/...', which represents an absolute path in UNIX

So your file will not exists for curl_file_create because this is read as an absolute path!

So probably no file is sent.

 

How to get around this?


<?php 
    
    /* in your config/filesystems */

    
    'disks' => [
      
        /* Set the root and URL to the same path! */
        'your_disk'=>[
            'root' => storage_path('YourPath'),
            'url' => storage_path('YourPath'),
        ]
    ]

 

Thanks this works like a charm.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

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

×