Einzelnen Beitrag anzeigen

Benutzerbild von stOrM
stOrM

Registriert seit: 7. Jun 2003
Ort: Mülheim an der Ruhr
434 Beiträge
 
Delphi 10.3 Rio
 
#1

Datei nach VirusTotal mittels Indy

  Alt 4. Jun 2011, 11:45
Hi,
ich stehe gerade vor dem Problem, dass ich gerne eine Datei mittels Delphi an die Virustotal Webseite zwecks überprüfung dieser Datei senden würde. Bevorzugt würde ich dafür Indy einsetzen. Dumm daran ist das ich mit Indy selber bis auf die IdHTTP Komponente im Zusammenhang mit Dateidownload noch nie etwas gemacht habe.

Die Suche hier hat mich auch nicht wirklich dem Ziel nahegebracht, da ich nicht genau weiß woran das Problem nun genau liegt.

Folgendes zum Upload schreibt Virustotal:

Zitat:
This API call expects multipart/form-data parameters, the string part of the the call should have the following parameter:

key: your API key.
The file part of the call should contain the name of the submitted file and the file itself. We strongly encourage you to send the file with the name with which it was found in the wild since this is very rich metadata for the VirusTotal database. The API acts like a form with a file input field named file.
Gut dachte ich mir, versuch ich mal folgendes (Unwissenderweise)

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  stream : TIdMultipartFormDataStream;
  const
    aHost = 'http://www.virustotal.com';
    aSelector = 'http://www.virustotal.com/api/scan_file.json';
begin
  stream := TIdMultipartFormDataStream.Create;
  try
    idHttp1.Request.ContentType := stream.RequestContentType;
    // sha1 filehash
    stream.AddFormField('resource:', '60EC5990C3DD08481F94F85636BAC486F5C19CCD');
    // private api key
    stream.AddFormField('key:', aKey);
    // filename to be send including file
    stream.AddFile('file:Test.exe', 'C:\VirusTotal\Upload\Test.exe', '');
    // set stream to beginning
    stream.Position := 0;
    // send file to virustotal result into memo1
    Memo1.Lines.Text := idHttp1.Post(aHost, stream);
  finally
    stream.Free;
  end;
end;
Was mich verwirrt ist folgendes Script als Beispiel auf Virustotal

Code:
>>> import postfile
>>> host = "www.virustotal.com"
>>> selector = "https://www.virustotal.com/api/scan_file.json"
>>> fields = [("key", "1fe0ef5feca2f84eb450bc3617f839e317b2a686af4d651a9bada77a522201b0")]
>>> file_to_send = open("test.txt", "rb").read()
>>> files = [("file", "test.txt", file_to_send)]
>>> json = postfile.post_multipart(host, selector, fields, files)
>>> print json
{"scan_id": "cd1384c10baa2d5b96f397b986e2a1fc9535d2ef0e185a113fc610eca1c6fb0e-1271623480",
 "result": 1}
Wenn ich das richtig deute wird hier nicht nur die Url www.virustotal.com sondern auch noch https://www.virustotal.com/api/scan_file.json übergeben? Irgendwie blick ichs nicht!
Erst dachte ich gut vielleicht liegts daran das ich die ganze Sache über http anstelle von https aufrufe lt. dem Beispiel soll aber beides machbar sein.

Fehler 1: Wenn ich den Code mit aHost aufrufe bekomme ich ein 'Not allowed' zurück! Nehme ich den aSelector bekomme ich 500 "Internal error" zurück.
  Mit Zitat antworten Zitat