Jump to content

Winhttp İle Virüs Total'e Dosya Gönderme?


luger
 Share

Recommended Posts

Kullanacağımız Winhttp(14.01.2014)sürümü: https://autoit-winhttp.googlecode.com/files/1.6.3.7.zip

Fonksiyonlar:

;_WinHttpAddRequestHeaders
;_WinHttpCheckPlatform
;_WinHttpCloseHandle
;_WinHttpConnect
;_WinHttpCrackUrl
;_WinHttpCreateUrl
;_WinHttpDetectAutoProxyConfigUrl
;_WinHttpGetDefaultProxyConfiguration
;_WinHttpGetIEProxyConfigForCurrentUser
;_WinHttpOpen
;_WinHttpOpenRequest
;_WinHttpQueryAuthSchemes
;_WinHttpQueryDataAvailable
;_WinHttpQueryHeaders
;_WinHttpQueryOption
;_WinHttpReadData
;_WinHttpReceiveResponse
;_WinHttpSendRequest
;_WinHttpSetCredentials
;_WinHttpSetDefaultProxyConfiguration
;_WinHttpSetOption
;_WinHttpSetStatusCallback
;_WinHttpSetTimeouts
;_WinHttpSimpleBinaryConcat
;_WinHttpSimpleFormFill
;_WinHttpSimpleReadData
;_WinHttpSimpleReadDataAsync
;_WinHttpSimpleRequest
;_WinHttpSimpleSendRequest
;_WinHttpSimpleSendSSLRequest
;_WinHttpSimpleSSLRequest
;_WinHttpTimeFromSystemTime
;_WinHttpTimeToSystemTime
;_WinHttpWriteData 

Bir önceki 

http://www.tnctr.com/topic/241738-autoit-fileread-exeyi-string-olarak-okumuyor/

konusundan geliyorum. Yanlış anlaşılmasın yan odadan değil. Yan konudan :D

 

Gönderilmek istenen dosya:http://tr.rghost.net/52173713   (Bi gönderilemedi gitti :D )

 

Beraber tartışalım. Nasıl yapabiliriz. Ben yeni kodlar eklerim konuya :D

 

Ayrıca sitede aradım sanırım winhttp'ye pek değinilmemiş.

Edited by luger
Link to comment
Share on other sites

@pairs: Sona ulaşamamışlar hocam. İnşallah biz ulaşıcaz. Bişeyler buldum. Birazdan yayınlayacam.

-------------------------------------------------------------------------------------------------------------------------------------------

İlk önce python api bilgisi:

import postfile
host = "www.virustotal.com"
sec = "https://www.virustotal.com/vtapi/v2/file/scan"
fields = [("apikey", "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb")]
dosya_to_send = open("test.txt", "rb").read()
dosya = [("file", "test.txt", dosya_to_send)]
sonuc = postfile.post_multipart(host, sec, fields, dosya)
print sonuc
{"response_code": 1,
"verbose_msg": "Scan request successfully queued, come back later for the report",
"resource": "999f7d93aa3d4a1a94cccfb4ea96bc2e28fd48020a481aa2dc7e215f3ce27bc0",
"scan_id": "999f7d93aa3d4a1a94cccfb4ea96bc2e28fd48020a481aa2dc7e215f3ce27bc0-1324376258",
"permalink": "https://www.virustotal.com/file/999f7d93aa3d4a1a94cccfb4ea96bc2e28fd48020a481aa2dc7e215f3ce27bc0/analysis/1324376258/",
"sha256": "999f7d93aa3d4a1a94cccfb4ea96bc2e28fd48020a481aa2dc7e215f3ce27bc0",
"sha1": "2cc875bca8030d745adfd14388b8c001471c2474",
"md5": "4a00e1a3a14e4fec6f2b353b4f20bb73"}

post_multipart tanımlama kodları python:

[spoiler]import httplib, mimetypes

def post_multipart(host, selector, fields, files):
"""
Post fields and files to an http host as multipart/form-data.
fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return the server's response page.
"""
content_type, body = encode_multipart_formdata(fields, files)
h = httplib.HTTP(host)
h.putrequest('POST', selector)
h.putheader('content-type', content_type)
h.putheader('content-length', str(len(body)))
h.endheaders()
h.send(body)
errcode, errmsg, headers = h.getreply()
return h.file.read()

def encode_multipart_formdata(fields, files):
"""
fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return (content_type, body) ready for httplib.HTTP instance
"""
BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
CRLF = '\r\n'
L = []
for (key, value) in fields:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
L.append(value)
for (key, filename, value) in files:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
L.append('Content-Type: %s' % get_content_type(filename))
L.append('')
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body

def get_content_type(filename):
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'[/spoiler]

 

Autoit multipart dönüşümü yaklaşık:

[spoiler]#include-once
#include
#include

$USE_MIMETYPEFILE = 0

Global $MIMETypes[8][2] = [ _
["bmp", "image/bmp"], _
["gif", "image/gif"], _
["jpe", "image/jpeg"], _
["jpeg", "image/jpeg"], _
["jpg", "image/jpeg"], _
["png", "image/png"], _
["tif", "image/tiff"], _
["tiff", "image/tiff"]]
_SortMIMETypes()

;~ Local $form_fields[2][2] = [["password", "PW123"],["filename", "test.bmp"]]
Local $form_fields = 0
Local $form_files[1][2] = [["fileupload", "D:\test.bmp"]]

$x = post_multipart("http://www.imageshack.us/index.php", "", $form_fields, $form_files)
ConsoleWrite(">Body: " & @CRLF & $x[1] & @CRLF)
#include


;~ ConsoleWrite(">Header: " & @CRLF & $x[0] & @CRLF & @CRLF)
;~ ConsoleWrite(">Body: " & @CRLF & $x[1] & @CRLF)
If Not IsDeclared("MIMETypes") Then Global $MIMETypes
If Not IsDeclared("USE_MIMETYPEFILE") Then $USE_MIMETYPEFILE = 1
; Prog@ndy
Func _LoadMimeTypes()
Global $MIMETypes[200][2]
Local $line
If Not FileExists(@ScriptDir & "\MIMETypes.txt") Then
If MsgBox(36, 'PostData', "MIMETYpes.txt fehlt. Downloaden?") = 6 Then
InetGet("http://pastebin.com/pastebin.php?dl=f7401663f", @ScriptDir & "\MIMETypes.txt")
EndIf
EndIf
$mime = FileOpen(@ScriptDir & "\MIMETypes.txt", 0)
For $i = 0 To 199
$line = FileReadLine($mime)
If @error = -1 Then ExitLoop
$line = StringSplit($line, @TAB)
$MIMETypes[$i][0] = $line[1]
$MIMETypes[$i][1] = $line[2]
Next
FileClose($mime)

If $i < 1 Then $i = 1
ReDim $MIMETypes[$i][2]
_SortMIMETypes()
EndFunc ;==>_LoadMimeTypes
If $USE_MIMETYPEFILE Then _LoadMimeTypes()
Func _SortMIMETypes()
_ArraySort($MIMETypes, 0, 0, 0, 2)
EndFunc

; #FUNCTION# ;===============================================================================
;
; Name...........: _WinHttpWriteDataBin
; Description ...: Writes request data to an HTTP server.
; Syntax.........: _WinHttpWriteData($hRequest, $string)
; Parameters ....: $hRequest - Valid handle returned by _WinHttpSendRequest().
; $binary - Binary data to write.
; Return values .: Success - Returns 1
; - Sets @error to 0
; - sets @extended to written bytes
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed.
; Author ........: trancexx
; Modified.......: ProgAndy
; Remarks .......:
; Related .......:
; Link ..........; http://msdn.microsoft.com/en-us/library/aa384120(VS.85).aspx
; Example .......; Yes
;
;==========================================================================================
Func _WinHttpWriteDataBin($hRequest, $binary)
Local $lpBinary
Local $iNumberOfBytesToWrite
If IsDllStruct($binary) Then
$lpBinary = DllStructGetPtr($binary)
$iNumberOfBytesToWrite = DllStructGetSize($binary)
Else
$iNumberOfBytesToWrite = BinaryLen($binary)
Local $sBinary = DllStructCreate("byte[" & $iNumberOfBytesToWrite & "]")
DllStructSetData($sBinary, 1, $binary)
$lpBinary = DllStructGetPtr($sBinary)
EndIf

Local $a_iCall = DllCall("Winhttp.dll", "int", "WinHttpWriteData", _
"hwnd", $hRequest, _
"ptr", $lpBinary, _
"dword", $iNumberOfBytesToWrite, _
"dword*", 0)

If @error Or Not $a_iCall[0] Then
Return SetError(1, 0, 0)
EndIf

Return SetError(0, $a_iCall[4], 1)


EndFunc ;==>_WinHttpWriteDataBin

#cs
post_multipart and encode_multipart_formdata translated from the cookbook
see ActiveState's ASPN
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306
#ce

Func post_multipart($host, $selector, ByRef $fields, ByRef $files)
;~ """
;~ Post fields and files to an http host as multipart/form-data.
;~ fields is a sequence of (name, value) elements for regular form fields.
;~ files is a sequence of (name, filename, value) elements for data to be uploaded as files
;~ Return the server's response page.
;~ """
Local $Return = encode_multipart_formdata($fields, $files)
Local $content_type = 'Content-Type: ' & $Return[0] & @CRLF
;~ $body = $Return[1]
Local $URL = _WinHttpCrackUrl($host)
Local $hSession = _WinHttpOpen()
Local $hConnection = _WinHTTPConnect($hSession,$URL[2],$URL[3])
ConsoleWrite( $content_type&@CRLF)
;~ ConsoleWrite( StringReplace($Return[1],Chr(0),".")&@CRLF)
;~ $s = StringToBinary($Return[1])
;~ ConsoleWrite( BinaryLen($s) & "--" & StringLen($Return[1]))
;~ Return
Local $hRequest = _WinHttpOpenRequest($hConnection,"POST",$URL[6]&$URL[7],"HTTP/1.1","http://"&$URL[2])
_WinHttpSendRequest($hRequest,$content_type,$WINHTTP_NO_REQUEST_DATA,StringLen($Return[1]));,StringLen($Return[1]))
_WinHTTPWriteDataBin($hRequest,StringToBinary($Return[1]))
MsgBox(0, '', @error)
_WinHttpReceiveResponse($hRequest)
Local $Return[2]
If _WinHttpQueryDataAvailable($hRequest) Then
Local $temp
While 1
$temp = _WinHttpReadData($hRequest)
If $temp = "" Then ExitLoop
$Return[1] &=$temp
WEnd
$temp =""
; Does not work since @error is 0, when no more data is available
;~ Do
;~ $Return[1] &= _WinHttpReadData($hRequest)
;~ Until @error <> 0
EndIf
$Return[0] = _WinHttpQueryHeaders($hRequest)
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnection)
_WinHttpCloseHandle($hSession)
Return $Return
EndFunc ;==>post_multipart

; Prog@ndy
Func encode_multipart_formdata($fields, $files)
;~ """
;~ fields is a sequence of (name, value) elements for regular form fields.
;~ files is a sequence of (name, filename, value) elements for data to be uploaded as files
;~ Return (content_type, body) ready for httplib.HTTP instance
;~ """
Local Const $BOUNDARY = 'ThIs_Is_tHe_bouNdaRY_$'
;~ CRLF = '\r\n'
$L = ""
For $i = 0 To UBound($fields) - 1
$L &= ('--' & $BOUNDARY) & @CRLF
$L &= ('Content-Disposition: form-data; name="' & $fields[$i][0] & '"') & @CRLF
$L &= @CRLF
$L &= $fields[$i][1] & @CRLF
Next
For $i = 0 To UBound($files) - 1
$L &= ('--' & $BOUNDARY) & @CRLF
$L &= ('Content-Disposition: form-data; name="' & $files[$i][0] & '"; filename="' & $files[$i][1] & '"') & @CRLF
$content_type = get_content_type($files[$i][1])
$L &= ('Content-Type: ' & $content_type) & @CRLF
$L &= @CRLF
;~ If StringLeft($content_type, 5) <> "text/" Then
;~ $f = FileOpen($files[$i][1], 16)
;~ $L &= BinaryToString(FileRead($f)) & @CRLF
;~ FileClose($f)
;~ Else
$L &= FileRead($files[$i][1]) & @CRLF
;~ EndIf
Next
$L &= ('--' & $BOUNDARY & '--') & @CRLF
$L &= @CRLF

$content_type = 'multipart/form-data; boundary="' & $BOUNDARY & '"'
Local $Return[2] = [$content_type, $L]
;~ return content_type, body
Return $Return
EndFunc ;==>encode_multipart_formdata

; Prog@ndy
Func get_content_type($path)
;~ Return "application/octet-stream"
Local $szExt = StringLower(StringRegExpReplace(,".*(?:\.([^.\\/]*))?\Z","$1"))
;~ ConsoleWrite(StringTrimLeft($szExt, 1) & @CRLF)
If $szExt = "" Then Return 'application/octet-stream'
Local $mimeid = _ArrayBinarySearch2D($MIMETypes, $szExt)
;~ ConsoleWrite($mimeid & @error & @CRLF)
If $mimeid = -1 Then Return SetError(1, 0, 'application/octet-stream')
Return $MIMETypes[$mimeid][1]
EndFunc ;==>get_content_type
;===============================================================================
;
; Function Name: _ArrayBinarySearch()
; Description: Uses the binary search algorithm to search through a
; 1-dimensional array.
; Author(s): Jos van der Zande
; Modified: Prog@ndy
;
;===============================================================================
Func _ArrayBinarySearch2D(Const ByRef $avArray, $vValue, $iStart = 0, $Column = 0, $iEnd = 0)
If Not IsArray($avArray) Then Return SetError(1, 0, -1)

Local $iUBound = UBound($avArray) - 1

; Bounds checking
If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound
If $iStart < 0 Then $iStart = 0
If $iStart > $iEnd Then Return SetError(4, 0, -1)

Local $iMid = Int(($iEnd + $iStart) / 2)

If $avArray[$iStart][$Column] > $vValue Or $avArray[$iEnd][$Column] < $vValue Then Return SetError(2, 0, -1)

; Search
While $iStart <= $iMid And $vValue <> $avArray[$iMid][$Column]
If $vValue < $avArray[$iMid][$Column] Then
$iEnd = $iMid - 1
Else
$iStart = $iMid + 1
EndIf
$iMid = Int(($iEnd + $iStart) / 2)
WEnd

If $iStart > $iEnd Then Return SetError(3, 0, -1) ; Entry not found

Return $iMid
EndFunc ;==>_ArrayBinarySearch2D[/spoiler]

Edited by luger
Link to comment
Share on other sites

@blackman12: Hocam konu açma tarihine dikkat ederseniz. Sizin mesajlarınızdan daha önce konuyu açtığım ve mesaj yolladığım görülebilir. :) Sıkıntı yok. :)

 

Link: http://bc.vc/18205/http://www.autoitscript.com/forum/topic/150819-virustotal-api-20-udf/

Virüs Total Api v2.0 UDF(VT.au3)

[spoiler]#include-once
#include "WinHttp.au3"

; #INDEX# =================================================================================================
; Title .........: VT.au3
; AutoIt Version : 3.3.8.1
; Language ......: English
; Description ...: VirusTotal public API version 2.0 implementation in Autoit
;thanks to: trancexx|ProgAndy "WinHttp.au3" ||| guinness "Suggestions+Snippets ||| www.virustotal.com
;Reference https://www.virustotal.com/es/documentation/public-api
;Written by Danyfirex
;Date 12/05/2013 | Update 03/06/2013
; #FUNCTION# =============================================================================================




;===================CONSTANTS/CONSTANTES=======================
Global Const $__sVirusTotal_Page = 'www.virustotal.com'
Global Enum $eAPI_HttpOpen, $eAPI_HttpConnect
Global Enum $fReport,$fScan,$fRescan,$uReport,$uScan,$Comment
Global Const $tURL[6]=['/vtapi/v2/file/report','/vtapi/v2/file/scan','/vtapi/v2/file/rescan', _
'/vtapi/v2/url/report','/vtapi/v2/url/scan','/vtapi/v2/comments/put']
;==============================================================


; #FUNCTIONS/FUNCIONES# =======================================
;VT() ;Use respective flag($Type)
;VT(ByRef $aAPI, $Type, $sResource, $sAPIkey,$Comments="")
;flags($Type)
;$fReport = retrieve a scan report on a given file
;$fScan = submit a file for Scanning
;$fRescan = Rescan files in VirusTotal's file store
;$uReport = retrieve a scan report on a given URL
;$uScan = submit a URL for Scanning
;$Comment = Make a commnet on files and URLs
; ==============================================================



; #FUNCTION# =============================================================================================
; Name...........: VT_Open
; Description ...: Initialize and get session handle & connection handle
; Syntax.........: VT_Open()
; guinness
; #FUNCTION# =============================================================================================
Func VT_Open()
Local $aAPI[2] = [0, 0]
$aAPI[$eAPI_HttpOpen] = _WinHttpOpen()
If @error Then $aAPI[$eAPI_HttpOpen] = -1
$aAPI[$eAPI_HttpConnect] = _WinHttpConnect($aAPI[$eAPI_HttpOpen], $__sVirusTotal_Page)
If @error Then $aAPI[$eAPI_HttpConnect] = -1
Return $aAPI
EndFunc ;==>VT_Open


; #FUNCTION# =============================================================================================
; Name...........: VT_Close
; Description ...: Close handles
; Syntax.........: VT_Close($handle)
;guinness
; #FUNCTION# =============================================================================================
Func VT_Close(ByRef Const $aAPI)
_WinHttpCloseHandle($aAPI[$eAPI_HttpOpen])
_WinHttpCloseHandle($aAPI[$eAPI_HttpConnect])
Return True
EndFunc ;==>VT_Close



; #FUNCTION# =============================================================================================
; Name...........: VT
; Syntax.........: VT(ByRef $aAPI, $Type, $sResource, $sAPIkey,$Comments="")
;VT($hVirusTotal, $fReport, '20c83c1c5d1289f177bc222d248dab261a62529b19352d7c0f965039168c0654',$APIkey)
;VT($hVirusTotal, $fScan, "C:\file.exe",$APIkey)
;VT($hVirusTotal, $fRescan, hex($bHash),$APIkey)
;VT($hVirusTotal, $uReport, "http://www.virustotal.com",$APIkey)
;VT($hVirusTotal, $uScan, "http://www.google.com",$APIkey)
;VT($hVirusTotal, $Comment, hex($bHash) ,$APIkey,"Hello Word | Hola Mundo")
; Parameters....: $Resource - md5/sha1/sha256/scan_id | filename | Url | respectively for flag($Type)
; $APIkey - your API key.
; $Comments - your Comments
;Return.........; response format is a JSON object
; #FUNCTION# =============================================================================================
Func VT(ByRef $aAPI, $Type, $sResource, $sAPIkey,$Comments="")

If $aAPI[$eAPI_HttpConnect] = -1 Then $aAPI = VT_Open()

Select ;$fReport,$fScan,$fRescan,$uReport,$uScan,$Comment
Case $Type = $fReport
Return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], 'POST', $tURL[$Type], Default, 'resource=' & $sResource & '&key=' & $sAPIkey)

Case $Type = $fScan
Local $sBoundary="--------Boundary"
Local $sHeaders = "Content-Type: multipart/form-data; boundary=" & $sBoundary & @CRLF
Local $sData = ''
$sData &= "--" & $sBoundary & @CRLF
$sData &= 'Content-Disposition: form-data; name="apikey"' & @CRLF & @CRLF & $sAPIkey & @CRLF
$sData &= "--" & $sBoundary & @CRLF
$sData &= __WinHttpFileContent("", "file", $sResource,$sBoundary)
$sData &= "--" & $sBoundary & "--" & @CRLF
Return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], "POST", $tURL[$Type], Default, StringToBinary($sData,0), $sHeaders)

Case $Type = $fRescan
Return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], "POST", "/vtapi/v2/file/rescan", Default, "resource=" & $sResource &"&key=" & $sAPIkey)

Case $Type = $uReport
Return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], 'POST', $tURL[$Type], Default, 'resource=' & $sResource & '&key=' & $sAPIkey)

Case $Type = $uScan
Return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], 'POST', $tURL[$Type], Default, 'url=' & $sResource & '&key=' & $sAPIkey)

Case $Type = $Comment
return _WinHttpSimpleRequest($aAPI[$eAPI_HttpConnect], "POST", "/vtapi/v2/comments/put", Default, "resource=" & $sResource & _
"&comment=" & $Comments & "&key=" & $sAPIkey)

Case Else
SetError(3)
EndSelect

EndFunc ;==>VT[/spoiler]

 

Çalışan kod:

 #include <VT.au3>
 Local $hVirusTotal = VT_Open()
 ConsoleWrite(VT($hVirusTotal, $fScan, "oku.exe","f25133d9068704c23335fc39a7351828fa80c5dde894d731d5450cf8ab8569e8"))
 VT_Close($hVirusTotal)

Durum: Başarılı :D

 

Evet. Burdan yardım eden ve etmeyen tüm arkadaşlara teşekkür ederim. Dosya karşıya istenilen biçimde gönderilmesi artık başarılıdır. :)

Edited by luger
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...