Jump to content

Receive Token after uploading


Go to solution Solved by FireFox,

Recommended Posts

I'm new here and already have a few months I'm working with autoit, I would ask for help.

What I need:
Transparency of access when I need to upload, send an image to a url and capture a token response that validates that the image was received.

Requirement:
url expects base64 content
The user will not see the image uploading, so it receives the token.

As to thinking:

 

Rode with an HTTP POST method to simulate an access that url, I establish in a guy to see if he returns with status HTTP is 200
If so, he takes the token and returns pro user
If not, it returns error message

Down here has two functions for Post and Base64, it's not working

I cut the url from Post methods

#include "WinHttp.au3"

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$Error = ObjEvent("AutoIt.Error", "_Error")

_POST()

Func _POST()

; Method

$oHTTP.Open("POST", "/", False)
;Add Accept
$oHTTP.SetRequestHeader("Accept:","text/html", "application/xhtml+xml", "*/*")
; Add Referer
$oHTTP.SetRequestHeader("Referer:", "")
;Add Accept-Language
$oHTTP.SetRequestHeader("Accept-Language:","pt-BR")
;Add  User-Agent
$oHTTP.SetRequestHeader("User-Agent:", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)")
;Add Content Type
$oHTTP.SetRequestHeader("Content-Type:","multipart/form-data")
;Add  Host
$oHTTP.SetRequestHeader("Host:", "")
;Add Content-Length
$oHTTP.SetRequestHeader("Content-Length:" , "")
;Add Connection
$oHTTP.SetRequestHeader("Connection:","Keep-Alive")
;Add Cache-Control
$oHTTP.SetRequestHeader("Cache-Control:","no-cache" & @CRLF)

;Send 
$oHTTP.Send("DATATOSEND")

;Body
$oReceived = $oHTTP.ResponseText
;Object status
$oStatusCode = $oHTTP.Status

;Verifiy Status
If $oStatusCode = 200 then
 SelectAll_and_Copy( 250, 300 )
 ;SaveText( 250, 300, $output_file2  )
 MsgBox(4096, "Response code", $oStatusCode)
EndIf

If $oStatusCode Not 200 Then
   Return 0
   ConsoleWriteError ("Couldn't receive HTTP 200")
EndIf

 ; Salva Resposta do Body, independente do codigo de Resposta 
 ;O valor de 2 sobrescreve o arquivo se ele já existe 
 $file = FileOpen("Received.html", 2)  
 FileWrite($file, $oReceived)
 FileClose($file)


EndFunc
Func _Base64Encode($buf)
    Local $c = 0, $i = 1, $j = 0, $l = BinaryLen($buf), $m = Mod($l, 3)
    Local $dest = ""
    While $i <= $l - $m
        $c = BitOR(BitShift(BinaryMid($buf, $i, 1), -16), BitShift(BinaryMid($buf, $i + 1, 1), -8), BinaryMid($buf, $i + 2, 1))
        $dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 16515072), 18)])
        $dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 258048), 12)])
        $dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 4032), 6)])
        $dest &= Chr($_BASE64_TABLE[BitAND($c, 63)])
        $i += 3
        $j += 4
    WEnd
    If 1 = $m Then
        $dest &= Chr($_BASE64_TABLE[BitShift(BitAND(BinaryMid($buf, $i, 1), 252), 2)])
        $dest &= Chr($_BASE64_TABLE[BitShift(BitAND(BinaryMid($buf, $i, 1), 3), -4)])
        $dest &= Chr($_BASE64_TABLE[64])
        $dest &= Chr($_BASE64_TABLE[64])
    ElseIf 2 = $m Then
        $c = BitOR(BitShift(BinaryMid($buf, $i, 1), -8), BinaryMid($buf, $i + 1, 1))
        $dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 64512), 10)])
        $dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 1008), 4)])
        $dest &= Chr($_BASE64_TABLE[BitShift(BitAND($c, 15), -2)])
        $dest &= Chr($_BASE64_TABLE[64])
    EndIf
    Return $dest
 EndFunc

Regards,

mmfalcao

Link to comment
Share on other sites

I changed the way how this gone works, trying connect with TCP using Send and Receive, still using the base64, so i created the header and data content, now I just need to do simple parse from the response o get the token

Dim $datasize = StringLen($extra_commands)
    
    $command = "POST "&$page&" HTTP/1.1"&@CRLF
    $command &= "Accept: text/html, application/xhtml+xml, */*" & @CRLF
    $command &= "Referer:, http://:8080/.php" & @CRLF
    $command &= "Accept-Language: pt-BR"&@CRLF
    $command &= "User-Agent: "&$_HTTPUserAgent&@CRLF
    $command &= "Content-Type: multipart/form-data; boundary=---------------------------7dd2d702806ce"&@CRLF
    $command &= "Host: " &$host&@CRLF
    $command &= "Content-Length: "&$datasize&@CRLF
    $command &= "Connection: keep-alive"&@CRLF
    $command &= "Cache-Control: no-cache" & @CRLF
    $command &= ""&@CRLF
    $command &= "-----------------------------7dd2d702806ce"&@CRLF
    $command &= "MIME-Version: 1.0" & @CRLF
    $command &= "Content-Type: image/pjpeg; name=""1.jpg" & @CRLF
    $command &= "Content-Transfer-Encoding: base64" & @CRLF
    $command &= "Content-Disposition: form-data; name=file; filename=" & $filename &@CRLF
    $command &= ""&@CRLF
    $command &= $data&@CRLF
    $command &= "-----------------------------7dd2d702806ce"&@CRLF
    
    #cs
      Content-Disposition: form-data; name="submit"

      Submit

      -----------------------------7dd2d702806ce--
    #ce
    
    ;debug info
    If FileExists("output.txt") Then FileDelete("output.txt")
    $file = FileOpen("output.txt", 1)
    FileWrite($file, $command)
    FileClose($file)
    ;end debug info
    
    Dim $bytessent = TCPSend($socket, $command)

Regards,

mmfalcao

Link to comment
Share on other sites

  • 2 months later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...