使用tcpsend autoit发布文件名变量

时间:2015-05-12 14:28:31

标签: autoit

我需要知道如何将文件名变量发布到所需的变量而不是" upload.zip"

我知道如何使用php自动化文件名,但需要使用tcpsend方法自动发布文件名变量

由于

PHP代码:

<?php
print_r($_POST);
print_r($_FILES);
copy($_FILES["upload"]["tmp_name"], "upload.zip");
?>

自动代码:

ConsoleWrite(_PHPupload('192.168.1.2', _OSmacros(), 89, '/upload/index.php', 'application/zip') & @CRLF)

    Func _PHPupload($pIP, $pMacros, $pPort, $phpPath, $pContent)
        If FileExists($pFile) = 0 Then Return SetError(1, 1, '')
        $pTcpc = TCPConnect($pIP, $pPort)
        If @error Then Return SetError(1, 2, '')
        Local $pBound = "-----" & Random(10000000, 99999999, 1)
        Local $pData1 = "--" & $pBound & @CRLF
        $pData1 &= 'Content-Disposition: form-data; name="upload";  filename="' & $pFile & '"' & @CRLF & 'Content-Type: ' & $pContent & @CRLF & @CRLF
        Local $pData2 = @CRLF & "--" & $pBound & @CRLF & 'Content-Disposition: form-data ;name="test"' & @CRLF & @CRLF & "variable" & @CRLF
        $pData2 &= "--" & $pBound & "--" & @CRLF & @CRLF
        Local $pHeader = 'POST ' & $phpPath & ' HTTP/1.1' & @CRLF
        $pHeader &= 'Host: ' & $pIP & @CRLF
        $pHeader &= 'User-Agent: ' & $pMacros & @CRLF
        $pHeader &= 'Content-Type: multipart/form-data; boundary=' & $pBound & @CRLF
        $pHeader &= 'Content-Length: ' & (StringLen($pData1) + StringLen($pData2) + FileGetSize($pFile)) & @CRLF & @CRLF
        Local $pFopen = FileOpen($pFile, $FO_READ)
        If $pFopen = -1 Then Return SetError(1, 3, '')
        Local $sFread = FileRead($pFopen)
        TCPSend($pTcpc, $pHeader & $pData1 & $sFread & $pData2)
        If @error Then Return SetError(1, 4, '')


        Local $pBuffer = ""

        While 1
            $pBuffer &= TCPRecv($pTcpc, 1024)
            If @error Then
                Return SetError(1, 5, '')
            Else
                ExitLoop
            EndIf
        WEnd

        MsgBox(64, "", $pBuffer)

    EndFunc   ;==>_PHPupload

1 个答案:

答案 0 :(得分:0)

  

$ pFile未声明,但即使它是,它也不会工作,因为它的a   文件路径,您将其作为文件名发送到

filename="' & $pFile

这应该有效:

ConsoleWrite(_PHPupload('192.168.1.2', _OSmacros(), 89, '/upload/index.php', 'application/zip', "c:\somedir", "somefile.zip") & @CRLF)

    Func _PHPupload($pIP, $pMacros, $pPort, $phpPath, $pContent, $pFilePath, $pFileName)
        $pFile = $pFilePath & "\" & $pFileName
        If FileExists($pFile) = 0 Then Return SetError(1, 1, '')
        $pTcpc = TCPConnect($pIP, $pPort)
        If @error Then Return SetError(1, 2, '')
        Local $pBound = "-----" & Random(10000000, 99999999, 1)
        Local $pData1 = "--" & $pBound & @CRLF
        $pData1 &= 'Content-Disposition: form-data; name="upload";  filename="' & $pFileName & '"' & @CRLF & 'Content-Type: ' & $pContent & @CRLF & @CRLF
        Local $pData2 = @CRLF & "--" & $pBound & @CRLF & 'Content-Disposition: form-data ;name="test"' & @CRLF & @CRLF & "variable" & @CRLF
        $pData2 &= "--" & $pBound & "--" & @CRLF & @CRLF
        Local $pHeader = 'POST ' & $phpPath & ' HTTP/1.1' & @CRLF
        $pHeader &= 'Host: ' & $pIP & @CRLF
        $pHeader &= 'User-Agent: ' & $pMacros & @CRLF
        $pHeader &= 'Content-Type: multipart/form-data; boundary=' & $pBound & @CRLF
        $pHeader &= 'Content-Length: ' & (StringLen($pData1) + StringLen($pData2) + FileGetSize($pFile)) & @CRLF & @CRLF
        Local $pFopen = FileOpen($pFile, $FO_READ)
        If $pFopen = -1 Then Return SetError(1, 3, '')
        Local $sFread = FileRead($pFopen)
        TCPSend($pTcpc, $pHeader & $pData1 & $sFread & $pData2)
        If @error Then Return SetError(1, 4, '')


        Local $pBuffer = ""

        While 1
            $pBuffer &= TCPRecv($pTcpc, 1024)
            If @error Then
                Return SetError(1, 5, '')
            Else
                ExitLoop
            EndIf
        WEnd

        MsgBox(64, "", $pBuffer)

    EndFunc   ;==>_PHPupload