Upload Image [TCP]

  • Hi,

    ich versuche grade über TCP ein Bild auf Imagebanana hochzuladen. Jedoch hab ich leichte Probleme damit wie das Post-Packet erstellt wird.


    Hier einmal das Orginal:

    Spoiler anzeigen


    Und nun hab ich versucht das ganze in Autoit nachzubauen:

    Spoiler anzeigen
    [autoit]

    Func _banane_upload($sCookie, $sFile)
    $sPost = "-----------------------------18060217183753" & @CRLF & _
    'Content-Disposition: form-data; name="img"; filename="Bild.jpg"' & @CRLF & _
    "Content-Type: image/jpeg" & @CRLF & _
    @CRLF & _
    FileRead(FileOpen($sFile)) & @CRLF & _
    '-----------------------------18060217183753' & @CRLF & _
    'Content-Disposition: form-data; name="send"' & @CRLF & _
    @CRLF & _
    'Hochladen!' & @CRLF & _
    '-----------------------------18060217183753' & @CRLF & _
    'Content-Disposition: form-data; name="resize"' & @CRLF & _
    @CRLF & _
    '320x240' & @CRLF & _
    '-----------------------------18060217183753--' & @CRLF & @CRLF

    [/autoit] [autoit][/autoit] [autoit]

    $sHeader = "POST / HTTP/1.1" & @CRLF & _
    "Host: http://www.imagebanana.com" & @CRLF & _
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3" & @CRLF & _
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & @CRLF & _
    "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" & @CRLF & _
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & @CRLF & _
    "Keep-Alive: 115" & @CRLF & _
    "Connection: keep-alive" & @CRLF & _
    "Referer: http://www.imagebanana.com/" & @CRLF & _
    "Cookie: " & $sCookie & @CRLF & _
    "Content-Type: multipart/form-data; boundary=---------------------------193231953297" & @CRLF & _
    "Content-Length: " & StringLen($sPost) & @CRLF & @CRLF & $sPost
    $iSocket = _banane_startup()
    TCPSend($iSocket, $sHeader)
    Do
    $sRecv = TCPRecv($iSocket, 1)
    Until $sRecv <> ""
    Do
    $sRecv &= TCPRecv($iSocket, 1)
    Until @error Or StringInStr($sRecv, "</html>")
    FileWrite("upload.html", $sRecv)
    _banane_shutdown($iSocket)
    EndFunc ;==>_banane_upload

    [/autoit]

    Jedoch wird die Datei nicht vom Server angenommen. Ich denke das liegt an diesen langen zahlen -> 193231953297 die werden immerwieder neu generiert. Nur wie finde ich raus wie sich die Zahl zusammen setzt?

    Hier mal den Quelltext der Seite, vielleicht findet ihr ja was interessantes

    Spoiler anzeigen

    Mfg
    monkey

    Monkey - die finale Potenz von göttlich!
    Sloganizer

  • ich mach das mit autoit nur indirekt, arbeite in meinem script zusätzlich mit curl.

    hab dir mein script mal angehängt. die compilierte version findest du auf meiner seite
    https://autoit.de/www.andygo.de
    die nötigen file-installs sind alle kostenfreie programme, diese kann ich bei bedarf zur verfügung stellen.

  • Danke für die Antwort... jedoch wollte ich mich selber an die Arbeit machen. Soll heissen das ich versuche möchte das selber in TCP zu schreiben :)

    Hat sonst noch wer ideen?

    Mfg
    monkey

    Monkey - die finale Potenz von göttlich!
    Sloganizer

  • Sonst niemand eine Idee?

    Vom Betreiber her wurde auch genehmigt das ich ein solches Tool schreiben darf.

    Mfg
    monkey

    Monkey - die finale Potenz von göttlich!
    Sloganizer

  • Hier ist meine ImageUpload.au3. Wozu brauchst du das eigentlich?

    Spoiler anzeigen
    [autoit]

    #include <String.au3>
    #include-once
    ;========================>
    #cs
    Author: @night@
    Beschreibung: Lädt ein Bild bei ImageBanana.com hoch. (via TCP)
    Rückgabewert: Der Direktlink zu dem Bild
    Parameter:
    $sFile = Path des Bildes
    $sNameatServer = So heisst das Bild auf dem Server
    Errors:
    1: Bild existiert nicht
    2: Upload hat generell nicht geklappt (Server hat nicht richtig geantwortet)
    3: dito
    #ce
    Func ImageBananaUpload($sFile, $sNameatServer)
    If NOT FileExists($sFile) Then return SetError(1, 0, -1)
    $hFile = Fileopen($sFile, 16)
    $bFilecontent = Fileread($hFile)
    Fileclose($hFile)
    $boundary = getBoundary()
    ;=========>Posterstellung
    $post1 = "-----------------------------"&$boundary&@crlf& _
    'Content-Disposition: form-data; name="img"; filename="'&$sNameatServer&'"'&@crlf & _
    "Content-Type: image/gif" & @crlf & @crlf
    $post2 = '-----------------------------'&$boundary&@crlf& _
    'Content-Disposition: form-data; name="send"' & @crlf & @crlf & "Hochladen!" & @crlf& _
    "-----------------------------"&$boundary & @crlf & _
    'Content-Disposition: form-data; name="resize"'& @crlf & @crlf & _
    '320x240' & @crlf & _
    "-----------------------------"&$boundary&"--" & @crlf
    TCPStartup()
    $data = "POST / HTTP/1.1" & @crlf & _
    "Host: http://www.imagebanana.com" & @crlf & _
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.9) Gecko/20100315 Firefox/3.5.9 (.NET CLR 3.5.30729)" & @crlf & _
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & @crlf & _
    "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" & @crlf & _
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & @crlf & _
    "Connection: close" & @crlf & _
    "Referer: http://imagebanana.com/" & @crlf & _
    "Content-Type: multipart/form-data; boundary=---------------------------"&$boundary&@crlf& _
    "Content-Length: "&Stringlen($post1)+Stringlen($post2)+Binarylen($bFilecontent)+1& @crlf & @crlf & _
    $post1
    $socket = TCPConnect(TCPNameToIp("imagebanana.com"), 80)
    Tcpsend($socket, $data)
    TCPsend($socket, $bFilecontent)
    TCPSend($socket, @crlf)
    TCPsend($socket, $post2)
    Do
    $recv = TCPRecv($socket, 1)
    until $recv <> ""
    Consolewrite("Empfangen..."&@crlf)
    Do
    $recv &= TCPRecv($socket, 1)
    If @error Then exitloop
    If Stringinstr($recv, "</html>") Then exitloop
    until 0
    TCPClosesocket($socket)
    ;=========================>Bild ist hochgeladen
    $aHelp = _Stringbetween($recv, "Location: ", @crlf)
    If NOT isarray($aHelp) Then return Seterror(2,0, -1) ;wenn der Upload nicht geklappt hat, dann aufhören
    $aHelp[0] = Stringreplace($aHelp[0], "http://www.imagebanana.com", "")
    $recv = TCPRequest(TCPNameToIp("imagebanana.com"), "www.imagebanana.com", $aHelp[0])
    ;=================>Den DirektLink auswerten
    $start = '<input onclick="javascript:highlight(this);" type="text" value="'
    $end = '" class="input_text"'
    $aHelp = _StringBetween($recv, $start, $end)
    If NOT isarray($aHelp) Then return Seterror(3, 0, -1)
    return $aHelp[1] ;direkten Link returnen
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func getBoundary()
    return Stringleft(_TimeGetStamp()*random(10,256,1), 16)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _TimeGetStamp()
    Local $av_Time
    $av_Time = DllCall('CrtDll.dll', 'long:cdecl', 'time', 'ptr', 0)
    If @error Then
    SetError(99)
    Return False
    EndIf
    Return $av_Time[0]
    EndFunc ;==>by therks at autoitscript.com

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func TCPRequest($ip, $host, $seite = "/", $ref = "", $content = "", $post = "", $cookie_string = "")
    $data = getdata($host, $seite, $ref, $post, $content, $cookie_string)
    MsgBox(0, "hi", $data)
    TCPStartup()
    $socket = TCPConnect($ip, 80)
    If @error Then return SetError(2) ;wenn das verbinden nicht geklappt hat, setze @error auf 2
    $bytes = TCPSend($socket, $data)
    If @error then return Seterror(3) ;wenn das senden niht geklappt hat, setze @error auf 3
    ;==========================>empfangen
    Do
    $recv = TCPRecv($socket, 2048)
    until $recv <> ""
    ;~Consolewrite("Empfange..." & @crlf)
    Do
    $recv &= TCPRecv($socket, 2048)
    If @error Then exitloop
    until StringInStr($recv, "</html>") or StringInStr($recv, "302 Moved")
    TCPCloseSocket($socket)
    TCPShutdown()
    return $recv
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func getdata($host, $seite, $ref, $post, $content, $cookie_string)
    If $post = "" Then
    $prefix = "GET"
    Else
    $prefix = "POST"
    EndIf
    $data = $prefix& " "&$seite&" HTTP/1.1" & @crlf & _
    "Host: " & $host & @crlf & _
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 (.NET CLR 3.5.30729)" & @crlf & _
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & @crlf & _
    "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" & @crlf & _
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & @crlf & _
    "Connection: close" & @crlf
    If $ref <> "" Then
    $data &= "Referer: " & $ref & @crlf
    EndIf
    If $content <> "" Then
    $data &= "Content-Type: " & $content & @CRLF
    EndIf
    If $cookie_string <> "" Then
    $data &= $cookie_string & @crlf
    EndIf
    If $post <> "" Then
    $data &= "Content-Length: " & Stringlen($post) & @crlf
    EndIf
    $data &= @crlf
    If $post <> "" Then
    $data &= $post
    EndIf
    return $data
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func getCookieStr($recv)
    $cookies = _StringBetween($recv, "Set-Cookie: ", ";", 1)
    If NOT isarray($cookies) Then return Seterror(1)
    $cookiestring = "Cookie: "
    For $i = 0 To Ubound($cookies) -1
    $cookiestring &= $cookies[$i]&';'
    Next
    return $cookiestring
    EndFunc

    [/autoit]


    dabei sind meine Standard TCP funkionen...
    mfg @night@

    Einmal editiert, zuletzt von @night@ (23. Mai 2010 um 20:28)