Jump to content
ripdad

Local Proxy Server v1.00

Recommended Posts

LPS1.png

This script is based on algorithm code from EnrMa.

Updated: January 22, 2018

Made improvements. Changes are in the script header.

Known Issues: AutoIt x64 does not work properly with this script.

Download: LocalProxyServer_v1.00.zip

 

Edited by ripdad
updated

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

I found this on the web and thought the information would be useful.

How to set up a proxy server

Guide: Block websites and protect your network from malware

http://www.techradar.com/news/networking/how-to-set-up-a-proxy-server-704981

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

Can you help, add a feature to connect over another proxy?

I tried the modified version posted by Ka36ek at '?do=embed' frameborder='0' data-embedContent>>.

After found the Base64.au3 to included. I got it to authenticated successfully on the other proxy server but returned blank display on internet explorer or firefox.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=proxy.exe
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
TCPStartup()
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GUIEdit.au3>
#Include <Array.au3>
#Include <File.au3>
#include <WindowsConstants.au3>
#include <Base64.au3>

Opt("GUIOnEventMode" , 1)
Opt("TrayAutoPause",0)
Opt("TrayMenuMode",3)
Opt("TrayOnEventMode",1)

Global $ini = @ScriptDir & "\config.ini"
Global $mainarray[30][10]
Global $proxysocket , $proxysocketssl
Global $GUISHOW = 1
Global $FUseProxy = False
Global $SProxyAuthCode = "" ; ???????? ????? ? ???

$mainarray[0][0] = "Hostport"
$mainarray[0][1] = "Clientsocket"
$mainarray[0][2] = "Hostsocket"
$mainarray[0][3] = "Request"
$mainarray[0][4] = "Hostname"
$mainarray[0][5] = "Timerhandle connection"
$mainarray[0][6] = "Blocked"
$mainarray[0][7] = "State"
$mainarray[0][8] = "connection type"
$mainarray[0][9] = "req count"



Global $gui = GUICreate("ProxyServer v0.2",700,700)
$DEBUG=GUICtrlCreateEdit("" , 5 , 30 , 500 ,670,BitOr($GUI_SS_DEFAULT_EDIT,$ES_READONLY))
GUICtrlSetLimit(-1 , 2000000000000000)
Global $button_debug_clear = GUICtrlCreateButton("Clear",5,5,90,20)
GUICtrlSetOnEvent($button_debug_clear,"_debug_clear")
GUICtrlCreateLabel("Listening IP:",515,40,70,20)
GUICtrlCreateLabel("Port HTTP:",515,60,70,20)
GUICtrlCreateLabel("Port HTTPS:",515,80,70,20)
Global $input_proxyip =  GUICtrlCreateInput("",590, 40,100,20)
Global $input_proxyport = GUICtrlCreateInput("",590,60,60,20)
Global $input_proxyportssl = GUICtrlCreateInput("",590,80,60,20)
Global $button_proxy_save = GUICtrlCreateButton("Save and Restart",515,140,180,20)
GUICtrlSetOnEvent($button_proxy_save,"_mainsocket_save")

Global $checkbox_debug = GUICtrlCreateCheckbox("Debugmode", 515 , 240, 120, 20)
Global $checkbox_debug_save = GUICtrlCreateCheckbox("Save Debug to file", 515 , 260, 120, 20)
Global $checkbox_debug_content = GUICtrlCreateCheckbox("Show traffic content", 515 , 280, 120, 20)
Global $button_debug_content = GUICtrlCreateButton("Binary to String",515,320,120,19)
GUICtrlSetOnEvent($button_debug_content,"_debug_binary")
Global $button_debug_array = GUICtrlCreateButton("show mainarray",515,340,120,19)
GUICtrlSetOnEvent(-1,"_show_array")


#Region ### START Koda GUI section ###
Global $Proxy_Form = GUICreate("Settings", 209, 190, 192, 132)
Global $PF_IP = GUICtrlCreateInput("", 8, 24, 121, 24)
Global $PF_Port = GUICtrlCreateInput("", 136, 24, 57, 24)
Global $PF_Login = GUICtrlCreateInput("", 88, 65, 105, 24)
Global $PF_Pass = GUICtrlCreateInput("", 88, 96, 105, 24)
Global $PF_OK = GUICtrlCreateButton("OK", 8, 152, 89, 25, 0)
GUICtrlSetOnEvent($PF_OK,"_close_proxy_settings")
Global $PF_Save = GUICtrlCreateButton("Save", 104, 152, 89, 25, 0)
GUICtrlSetOnEvent($PF_Save,"_save_proxy_settings")
GUICtrlCreateLabel("Pass", 16, 100, 54, 20)
GUICtrlCreateLabel("Username", 16, 65, 33, 20)
GUICtrlCreateLabel("IP Address", 16, 3, 80, 20)
GUICtrlCreateLabel("Port", 136, 3, 39, 20)
Global $PF_CheckboxUse = GUICtrlCreateCheckbox("PF_Use", 16, 128, 137, 17)
GUISetState(@SW_HIDE, $Proxy_Form)
#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE,"_quit")

Global $tray_showgui = TrayCreateItem("Show gui")
Global $tray_showproxyform = TrayCreateItem("????????? ??????")
TrayItemSetOnEvent($tray_showgui,"_gui_show")
TrayItemSetOnEvent($tray_showproxyform,"_proxy_settings")

GUISetOnEvent($GUI_EVENT_CLOSE,"_close_proxy_settings",$Proxy_Form )
GUISetState(@SW_SHOW,$gui)
_read_ini()



_mainsocket_create()

While 1
    $newclientsock  = TCPAccept($proxysocket)
    If $newclientsock <> -1 Then
        _save("] new HTTP clientconnection :" &_SocketToIP($newclientsock) &@CRLF)
        _clientconnection_to_mainarray($newclientsock,80,"HTTP")
    EndIf
    $newclientsockssl   = TCPAccept($proxysocketssl)
    If $newclientsockssl <> -1 Then
        _save("] new HTTPS clientconnection :" &_SocketToIP($newclientsockssl) &@CRLF)
        _clientconnection_to_mainarray($newclientsockssl,443,"HTTPS","start")
    EndIf
    ;--Recieving Req from Client
    For $i = 1 To UBound($mainarray) -1
        If $mainarray[$i][1] <> "" Then
            $request = TCPRecv($mainarray[$i][1],100000)
            If @error Then

                _save("] Client " & $i & " closed connection after " & Floor(TimerDiff($mainarray[$i][5])) & " ms" & @CRLF)
                _mainarray_deleteclient($i)
            EndIf

            If $request <> "" Then
                _save("] Client " & $i & " requested" & @CRLF  & @CRLF & $request & @CRLF)
                $mainarray[$i][9] += 1
                $mainarray[$i][3] = $request
                If GUICtrlRead($checkbox_debug_content) = 1 Then _save($request & @CRLF)
            EndIf
        EndIf
    Next

    ;--connecting and sending Req to Host
    For $i = 1 To UBound($mainarray) -1
        If $mainarray[$i][3] <> "" Then
            If $mainarray[$i][2] = "" Then

                IF $FUseProxy Then
                    ;
                    $forward = _Get_Address($mainarray[$i][3])
                    $forward = $mainarray[$i][3] ;????? ????? ???????? ?????? ?? ??????
                    _save("]" & $i &" ?????????? ?????? ?? ?????? : " & $forward  & @CRLF)
                    ;
                Else
                    ;
                    $forward = _Get_Address($mainarray[$i][3]) ;????? ????? ???????? ?????? ?? ??????
                    _save("]" & $i &" Got Host Address : " & $forward  & @CRLF)
                    ;
                EndIf

                $mainarray[$i][6] = 0
                $mainarray[$i][4] = $forward
                If $forward = "0" Then
                    _Send_Response($mainarray[$i][1],400)
                    _save("]" & $i &" Host is 0 , Error 400" & @CRLF)
                Else
                        IF $FUseProxy Then
                            ;
                            $serverip   = GUICtrlRead($PF_IP)
                            $mainarray[$i][0]=GUICtrlRead($PF_Port)
                            ;
                        Else
                            ;
                            $serverip   = TCPNameToIP($forward)
                            ;
                        ENDIF

                        $serversock = TCPConnect($serverip,$mainarray[$i][0])
                        If $serversock <> -1 Then
                            _save("]" & $i &" Connected to Host: " & $forward & @CRLF)
                            $mainarray[$i][2] = $serversock

                        Else
                            _save("]" & $i &" Not Connected to Host: " & $forward & @CRLF)
                            _Send_Response($mainarray[$i][1],400)
                            _mainarray_deleteclient($i)
                        EndIf
                EndIf
            Else
                $forward = _Get_Address($mainarray[$i][3])
                If $forward <> $mainarray[$i][4] Then
                    _save("]" & $i &" Host Address changed from: " & $mainarray[$i][4] & " to: " & $forward & @CRLF)
                    $mainarray[$i][4] = $forward
                    TCPCloseSocket($mainarray[$i][2])
                    $mainarray[$i][2] = ""
                EndIf
            EndIf
            If $mainarray[$i][2] <> "" Then
                $prevlen = StringLen($mainarray[$i][3])
                $mainarray[$i][3] = _request_modify($mainarray[$i][3],$mainarray[$i][4])
                If $mainarray[$i][7] = "" Then
                    ;$mainarray[$i][3] = _request_modify($mainarray[$i][3],$mainarray[$i][4])
                    TCPSend($mainarray[$i][2] , $mainarray[$i][3])
                        If Not @error Then
                            _save("]" & $i &" Sending HTTP to Host " & $mainarray[$i][4] & " successfull prevlen:" & $prevlen & " now:" & StringLen($mainarray[$i][3]) & @CRLF)
                            $mainarray[$i][3] = ""
                        Else
                            _save("]" & $i &" Error Sending HTTP to Host " & @CRLF)
                        EndIf
                EndIf
            EndIf
        EndIf
    Next
    ;--Waiting for Response from Host and Sending to client
    For $i = 1 To UBound($mainarray) -1
        If $mainarray[$i][2] <> "" Then
            $serverresponse     = TCPRecv($mainarray[$i][2],400000,1)
            If @error Then
                _mainarray_hostkillclient($i)
            EndIf
            If $serverresponse <> Binary("") Then
                If $mainarray[$i][6] = 0 Then
                    _save("]" & $i &" Got Host response" & @CRLF)
                    If  $mainarray[$i][1] <> "" And $mainarray[$i][7] = "" Then
                        TCPSend($mainarray[$i][1],$serverresponse)
                        If Not @error Then
                            _save("]" & $i &" Sent data to Client " & @CRLF)

                            If GUICtrlRead($checkbox_debug_content) = 1 Then _save(BinaryToString($serverresponse) & @CRLF)
                        EndIf
                    EndIf
                ElseIf $mainarray[$i][6] = 1 Then
                    TCPSend($mainarray[$i][1],"HTTP/1.1 " & "403")
                    _mainarray_hostkillclient($i)
                EndIf
            EndIf
        EndIf
    Next
    ;---only for HTTPS
    For $i = 1 To UBound($mainarray) -1
        If $mainarray[$i][1] <> "" And $mainarray[$i][3] <> "" And $mainarray[$i][8] = "HTTPS" And $mainarray[$i][7] = "start" Then
            _Send_Response($mainarray[$i][1],200) ;,$data="")
            $mainarray[$i][3] = ""
            $mainarray[$i][7] = ""
        EndIf
    Next

WEnd



Func _proxy_settings()
    ;
    _read_ini()
    GUISetState(@SW_SHOW, $Proxy_Form)
    ;
EndFunc

Func _close_proxy_settings()
    ;
    GUISetState(@SW_HIDE, $Proxy_Form)

    ;
EndFunc

Func _read_ini()
    ;
    _GUICtrlEdit_SetText($PF_Port, IniRead($ini, "PROXY", "PROXYPORT", ""))
    _GUICtrlEdit_SetText($PF_IP, IniRead($ini, "PROXY", "PROXYIP", ""))
    _GUICtrlEdit_SetText($PF_Login, IniRead($ini, "PROXY", "PROXYUSER", ""))
    _GUICtrlEdit_SetText($PF_Pass, IniRead($ini, "PROXY", "PROXYPASS", ""))
    IF IniRead($ini, "PROXY", "PROXYUSE", 0) = 1 Then
        ;
        GUICtrlSetState ($PF_CheckboxUse, $GUI_CHECKED)
        $FUseProxy=True

        $SProxyAuthCode=_Base64Encode(IniRead($ini, "PROXY", "PROXYUSER", "") & ":" & IniRead($ini, "PROXY", "PROXYPASS", ""))
        ; $SProxyAuthCode=B64Encode(IniRead($ini, "PROXY", "PROXYUSER", "") & ":" & IniRead($ini, "PROXY", "PROXYPASS", ""))
        ;
    Else
        ;
        GUICtrlSetState ($PF_CheckboxUse, $GUI_UNCHECKED)
        $FUseProxy=False
        ;
    ENDIF
    ;
EndFunc

Func _save_proxy_settings()
    ;
    IniWrite($ini,"PROXY","PROXYPORT",GUICtrlRead($PF_Port))
    IniWrite($ini,"PROXY","PROXYIP",GUICtrlRead($PF_IP))
    IniWrite($ini,"PROXY","PROXYUSER",GUICtrlRead($PF_Login))
    IniWrite($ini,"PROXY","PROXYPASS",GUICtrlRead($PF_Pass ))

    ;
    IF GUICtrlRead($PF_CheckboxUse)=$GUI_CHECKED Then
        ;
        $FUseProxy=True
        IniWrite($ini,"PROXY","PROXYUSE",1)
        $SProxyAuthCode=_Base64Encode(GUICtrlRead($PF_Login) & ":" & GUICtrlRead($PF_Pass ))
        _mainsocket_create()
        ;
    Else
        ;
        $FUseProxy=False
        IniWrite($ini,"PROXY","PROXYUSE",0)
        _mainsocket_create()
        ;
    ENDIF
    ;
EndFunc

Func _show_array()
    _ArrayDisplay($mainarray)
EndFunc

Func _mainsocket_save()
    IniWrite($ini,"SYSTEM","PROXYPORT",GUICtrlRead($input_proxyport))
    IniWrite($ini,"SYSTEM","PROXYIP",GUICtrlRead($input_proxyip))
    IniWrite($ini,"SYSTEM","PROXYPORTSSL",GUICtrlRead($input_proxyportssl))
    _mainsocket_create()
EndFunc

Func _mainsocket_create()
    TCPShutdown()
    TCPStartup()
    $IP = IniRead($ini,"SYSTEM","PROXYIP","127.0.0.1")
    $PORT = IniRead($ini,"SYSTEM","PROXYPORT","8080")
    $PORTSSL = IniRead($ini,"SYSTEM","PROXYPORTSSL","8043")
    GUICtrlSetData($input_proxyip, $IP)
    GUICtrlSetData($input_proxyport,$PORT)
    GUICtrlSetData($input_proxyportssl,$PORTSSL)
    $proxysocket        = TCPListen($IP,$PORT)
    If @error Then
        _GUICtrlEdit_AppendText($DEBUG , "] Error HTTP Proxy couldn't bind socket on IP :" & $IP & " Port :" & $PORT & @CRLF)
    Else
        _GUICtrlEdit_AppendText($DEBUG , "] HTTP Proxy listening on IP :" & $IP & " Port :" & $PORT & @CRLF)
    EndIf
    $proxysocketssl     = TCPListen($IP,$PORTSSL)
    If @error Then
        _GUICtrlEdit_AppendText($DEBUG , "] Error HTTPS Proxy couldn't bind socket on IP :" & $IP & " Port :" & $PORTSSL & @CRLF)
    Else
        _GUICtrlEdit_AppendText($DEBUG , "] HTTPS Proxy listening on IP :" & $IP & " Port :" & $PORTSSL & @CRLF)
    EndIf
EndFunc


Func _Get_Address($text)
    If IsBinary($text) Then
        $text = BinaryToString($text)
    EndIf
        $serversock=StringSplit($text , @CRLF,1)
        For $i=1 To $serversock[0]
            If StringLeft($serversock[$i],6)="Host: " Then
                Return StringTrimLeft($serversock[$i],6)
            EndIf
        Next
    Return 0
EndFunc

Func _clientconnection_to_mainarray($sock,$port = 80,$type = "HTTP",$state = "")
    For $i = 1 To UBound($mainarray) -1
        If $mainarray[$i][1] = "" And $mainarray[$i][2] = "" Then
            $mainarray[$i][1] = $sock
            $mainarray[$i][0] = $port
            $mainarray[$i][5] = TimerInit()
            $mainarray[$i][7] = $state
            $mainarray[$i][8] = $type
            _save("] Added new client to mainarray , pos: " & $i & @CRLF)
            If $i + 5 > UBound($mainarray) Then ReDim $mainarray[UBound($mainarray)+5][10]
            Return
        EndIf
    Next
EndFunc

Func _mainarray_deleteclient($line)
    TCPCloseSocket($mainarray[$line][1])
    $mainarray[$line][0] = ""
    $mainarray[$line][1] = ""
    $mainarray[$line][3] = ""
    $mainarray[$line][4] = ""
    $mainarray[$line][5] = ""
    $mainarray[$line][6] = ""
    $mainarray[$line][7] = ""
    $mainarray[$line][8] = ""
    $mainarray[$line][9] = ""
    If $mainarray[$line][2]<> "" Then
        TCPCloseSocket($mainarray[$line][2])
        $mainarray[$line][2] = ""
    EndIf
EndFunc

Func _mainarray_hostkillclient($line)
    _save("]" & $line &" Connection Closed by Host after " & Floor(TimerDiff($mainarray[$line][5])) & " ms" & @CRLF)
    $mainarray[$line][2] = ""
    $mainarray[$line][4] = ""
    $mainarray[$line][5] = ""
    If $mainarray[$line][1]<> "" Then
        TCPCloseSocket($mainarray[$line][1])
        _mainarray_deleteclient($line)
    EndIf
EndFunc

Func _Send_Response($browsersock,$code,$data="")
    If $data="" Then
        $data=@CRLF & @CRLF
    Else
        $data=@CRLF & $data & @CRLF & @CRLF
    EndIf
    TCPSend($browsersock , "HTTP/1.0 " & $code & " Message" & $data)
EndFunc


Func _quit()
    TCPShutdown()
    Exit
EndFunc

Func _gui_show()
    If $GUISHOW = 0 Then
        Local $pw = InputBox("Enter Password","Enter Password","","*",150,130)
        If Not @error Then
            If $pw = "1234" Then
                GUISetState(@SW_SHOW)
                $GUISHOW = 1
                Return
            EndIf
        EndIf
    ElseIf $GUISHOW = 1 Then
        GUISetState(@SW_HIDE)
        $GUISHOW = 0
        Return
    EndIf
EndFunc

Func _save($text)
    If GUICtrlRead($checkbox_debug_save) = 1 Then
        $file = FileOpen(@ScriptDir & "\log\" & @Year & @MON & @MDAY & "-log.txt",9)
        FileWrite ($file,$text)
        FileClose($file)
    Endif
    If GUICtrlRead($checkbox_debug) = 1 Then _GUICtrlEdit_AppendText($DEBUG , $text)
Endfunc

Func _SocketToIP($SHOCKET)
    Local $sockaddr, $aRet
    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")
    $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf
    $sockaddr = 0
    Return $aRet
EndFunc   ;==>SocketToIP

Func _debug_binary()
    Local $aSel = _GUICtrlEdit_GetSel($DEBUG)
    Local $text = StringMid(GUICtrlRead($DEBUG),$aSel[0]+1,$aSel[1]-$aSel[0])
    If $text <> "" Then

    Else
        $text = InputBox("Binary to String","Enter Binary Data")

    EndIf
    If StringLower(StringLeft($text,2)) <> "0x" Then $text = "0x" & $text
    $tempfile = FileOpen(@ScriptDir & "\temp.txt",2)
    FileWrite($tempfile,BinaryToString($text))
    FileClose($tempfile)
    ShellExecute(@ScriptDir & "\temp.txt")
EndFunc

Func _debug_clear()
    GUICtrlSetData($DEBUG,"")
EndFunc



Func _request_modify($req,$host)
Local $encoding = "Accept-Encoding: identity" ;deflate, gzip, compress,
Local $reqsplit
Local $modified_method = 0 , $modified_connection = 0 , $modified_encoding = 0
    ;

    If $req <> "" And Not IsBinary($req) Then
        $reqsplit = StringSplit($req,@CRLF,1)
        If IsArray($reqsplit) Then
            For $i = 1 to $reqsplit[0] - 1
                _save("] modifying :" & $i & " " & $reqsplit[$i])
                IF Not $FUseProxy Then ; ???? ???????? ??? ??????
                    If StringLeft($reqsplit[$i],3) = "GET" Or StringLeft($reqsplit[$i],4) = "POST" Or StringLeft($reqsplit[$i],7) = "CONNECT" And $modified_method = 0 Then
                        $reqsplit[$i] = StringReplace($reqsplit[$i],$host,"")
                        $reqsplit[$i] = StringReplace($reqsplit[$i],"http://","")
                        $reqsplit[$i] = StringReplace($reqsplit[$i],":443","")
                        $modified_method = 1
                    EndIf
                    If StringInStr(Stringlower($reqsplit[$i]),"proxy-connection: keep-alive") And $modified_connection = 0 Then
                        $reqsplit[$i] = "Connection: keep-alive"
                        $modified_connection = 1
                    EndIf
                    If StringInStr(Stringlower($reqsplit[$i]),"accept-encoding") And $modified_encoding = 0 Then
                        $reqsplit[$i] = $encoding
                        $modified_encoding = 1
                    EndIf
                EndIf




                _save(" -> to :" & $reqsplit[$i] & @CRLF)
            Next
            $req = _ArrayToString($reqsplit, @CRLF , 1 , Ubound($reqsplit)-1)
            IF $FUseProxy Then  $req=StringReplace($req, @CRLF & @CRLF,  @CRLF & "Proxy-Authorization: Basic " & $SProxyAuthCode & @CRLF & @CRLF,-1) ; ???? ???????? ????? ?????? ????????? ???????????
        EndIf
        If GUICtrlRead($checkbox_debug_content) = 1 Then
            _save("] Request modified to:" & @CRLF)
            _save($req &@CRLF)
        EndIf
    EndIf
    Return $req
EndFunc

Share this post


Link to post
Share on other sites

stalliont,

Are you planning on running a local proxy server to an external proxy,

permanently?

I personally have not attempted it, nor do I have a need for an external proxy,

so I have nothing to test with to see if it is working properly or not.

Can you elaborate why you need an external proxy with this script?

Do you know for sure that the proxy only accepts a Base64 Encoded login?

I ask these questions out of curiosity - so I might contemplate how to go

about it and be stable - and to find out what your goal is concerning it.


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

hi ripdad, thanks for quick reply.

I am trying to setup this local proxy under coorporate network and the only way to get to internet is through this proxy. Once i can get this working. Then my next step to run on a server with set commands for user can choose for automated reporting as we have different external websites that need to get source data for manipulation.

Ah 'Base64 Encoded login' you mentioned might be the culprit. I might starting checking which encode type login the proxy is using could fix my problem.

It could be better to have this with your version of proxy server as its so simple and clean.

Share this post


Link to post
Share on other sites

The next question would be - is the corporate proxy a 1:1 pass-through type

or does it handle https connections separately, etc?

The reason I ask this is because the local proxy server discards the initial

request after it has connected to the host server. (Line: 237)

Afterwards, it passes the following requests to the host as they are received.

It seems to me that there would have to be some inter-action here to make

a secure connection. If this is the case, then the script would have to

be modified to handle it.

-edit-

The script would also need to know how the corporate proxy responds

if a connection could not be made, etc.

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

hi ripdad, thanks for answering my queries. I got the autenticate working, connecting thru my corporate proxy using http, but https would not work, getting an error bad request.

Things getting a little more technical trying to find out how my corporate proxy works handling https

Here is an example log connect to https://www.yahoo.com, as what you are saying that you are probably right about my corporate proxy handling https connection differently not 1 on 1 passthru.

] HTTP Proxy listening on IP :10.44.27.36 Port :8081
] HTTPS Proxy listening on IP :10.44.27.36 Port :8082
] new HTTPS clientconnection :10.44.27.36
] Added new client to mainarray , pos: 1
] Client 1 requested

CONNECT www.yahoo.com:443 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0
Proxy-Connection: keep-alive
Connection: keep-alive
Host: www.yahoo.com:443


CONNECT www.yahoo.com:443 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0
Proxy-Connection: keep-alive
Connection: keep-alive
Host: www.yahoo.com:443


]1 Proxy Server : CONNECT www.yahoo.com:443 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0
Proxy-Connection: keep-alive
Connection: keep-alive
Host: www.yahoo.com:443


]1 Connected to Host: CONNECT www.yahoo.com:443 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0
Proxy-Connection: keep-alive
Connection: keep-alive
Host: www.yahoo.com:443


] modifying :1 CONNECT www.yahoo.com:443 HTTP/1.1 -> to :CONNECT www.yahoo.com:443 HTTP/1.1
] modifying :2 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0 -> to :User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0
] modifying :3 Proxy-Connection: keep-alive -> to :Proxy-Connection: keep-alive
] modifying :4 Connection: keep-alive -> to :Connection: keep-alive
] modifying :5 Host: www.yahoo.com:443 -> to :Host: www.yahoo.com:443
] modifying :6  -> to :
] Request modified to:
CONNECT www.yahoo.com:443 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0
Proxy-Connection: keep-alive
Connection: keep-alive
Host: www.yahoo.com:443
Proxy-Authorization: Basic ZmFsXHRyYW5sOiFwaXNzb2ZmOTkh



] Client 1 requested

0x16030100AF010000AB03030104FAE2AEAF84659D21029E3DA34074AE396AFE653FC6809FE294A1E2D02A0000002EC02BC02FC00AC009C013C014C012C007C0110033003200450039003800880016002F004100350084000A000500040100005400000012001000000D7777772E7961686F6F2E636F6DFF01000100000A00080006001700180019000B000201000023000033740000000500050100000000000D0012001004010501020104030503020304020202
0x16030100AF010000AB03030104FAE2AEAF84659D21029E3DA34074AE396AFE653FC6809FE294A1E2D02A0000002EC02BC02FC00AC009C013C014C012C007C0110033003200450039003800880016002F004100350084000A000500040100005400000012001000000D7777772E7961686F6F2E636F6DFF01000100000A00080006001700180019000B000201000023000033740000000500050100000000000D0012001004010501020104030503020304020202
]1 Sending HTTP to Host CONNECT www.yahoo.com:443 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0
Proxy-Connection: keep-alive
Connection: keep-alive
Host: www.yahoo.com:443

 successfull prevlen:362 now:362
]1 Got Host response
]1 Sent data to Client 
HTTP/1.1 400 Bad Request ( The data is invalid.  )
Via: 1.1 SYD0364
Connection: close
Proxy-Connection: close
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Content-Length: 615

I think I just play around and do my codes with http connection, and troubleshoot https on the other thread for 'autoit proxy server',

but i like your continued work with the local proxy server, and the TCP Passive Proxy Filter, these are great alternatives...

Share this post


Link to post
Share on other sites

Updated first post  to v0.6b

---

stalliont,

I think I found your https problem with the corporate proxy -- refer to first post update notes.

From your log,

Host: www.yahoo.com:443 --> HTTP/1.1 400 Bad Request  ( The data is invalid.  )
 


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

Thanks Fire.

Have not had the time to work on it till recently. Made some changes and improvements.

If anyone has any issues with it, Now would be a good time to voice them.

Will update soon.

 


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

I just downloaded the v012b update and I must be doing something wrong.  When I attempt to execute or compile it, I get a syntax error on line 41 (screenshot attached).

The error appears below line 41 and reads:

Local Const Enum $PortNumber, $ClientSocket, $RemoteSocket, $ProtocolState, $RemoteHost, $RemoteIP, $ContentLength, $ReceivedBytes, $RemoteClose, $Inactivity
error:  syntax error
error:  Statement cannot be just an expression.

 

I'm running AutoIt v3.3.14.0

Any help or tips on what I might be doing wrong with the script would be greatly appreciated.

Thanks,

TBWalker

 

 

 

Script_v012b_Error.JPG

Share this post


Link to post
Share on other sites

Remove the Const part of that line, Enums are already constants, so it's redundant anyways.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • By tarretarretarre
      Autoit-Socket-IO
      Introduction
      Autoit-Socket-IO is a event driven TCP/IP wrapper heavily inspired from Socket.IO with focus on user friendliness and long term sustainability.
      I created this UDF because I was fascinated how Socket.IO made a such scary task "reliable and secure networking" so simple for the developer. So this was my main motivation.
      I constantly want to make this UDF faster and better, so if you have any suggestions. Do not hesitate to make requests!
      Features
      Flexiable and easy to understand API Above avarage documentation "Fully featured" examples Security in form of data encryption and middleware-support Limitations
      Speed. Because I want this UDF to be as flexible and simple as possible. Sometimes speed is sacrificed, but that does not mean i don't try to . It is not possible to emit objects mainly because autoit does not support serialization. Only 1D-arrays can be emitted (2D arrays will probably never be supported) Success story
      Since December 2017-now I have used version 1.5.0 in an production environment for 40+ clients with great success, the only downtime is planned windows updates and power outages.
      Getting started
      Download the script from AutoIt or pull it from the official github repo git@github.com:tarreislam/Autoit-Socket-IO.git and checkout the tag 2.0.0 The documentation is located at Docs\index.html Take a look in the examples/ folder Changelog
      Version 2.0.0 (This update break scripts. Please consult the upgrade.md for guidance)
      All global internal variables has been renamed. Added a bunch of new API methods: _Io_RegisterMiddleware, _Io_whoAmI, _Io_IsClient, _Io_IsServer, _Io_getAllByProperty and _Io_getFirstByProperty and some more. Read more about these in the documentation. _Io_socketGetProperty now has a setter method called _Io_socketSetProperty which can be used to set custom properties. _Io_socketGetProperty now has a third parameter "default" which is used when a property is not found Removed _Io_setEventPostScript and _Io_setEventPretScript in favor of _Io_RegisterMiddleware Improved documentation (It still needs some love though) Improved the verbosity of _Io_DevDebug  
      Newest version (2019-09-29!)
      Autoit-Socket-IO-2.0.0.zip
      Older versions (Not supported anymore)
      Autoit-Socket-IO-1.0.0.zip Autoit-Socket-IO-1.1.0.zip Autoit-Socket-IO-1.3.0.zip Autoit-Socket-IO-1.4.0.zip Autoit-Socket-IO-1.5.0.zip
    • By AoRaToS
      I started working on this program in the summer of 2008 then I stopped cause I faced some problems I couldn't overcome back then. Now that I've practiced more and have become a better scripter/programmer I'm releasing the program to the public to get some opinions. I know it's not a new concept but it's the first program I started besides some small stuff I did just for practice! I won't post the source code yet because it's still under construction, although I'm sure I've posted early stages of the code with bugs in the past in some topic...
      What I wanted was a simple, small, serverless program that would work without installation cause I wanted it for where I work, so I ended up with this!
      I have attached some images of various versions, also visit the forum thread.
      The package includes s!mpL3 LAN Messenger and the full change log.
      Current version 2.9.9.1! [04/07/2019]
      Check the Change Log below!
       
       
      http://www.autoitscript.com/forum/index.php?showtopic=88782
       
       
       
      Read the license before using this software.
       
    • By HansHenrik
      ----------
      edit: this is probably in the wrong place, can a moderator move it to wherever it belongs?
      ----------

      is there any way to completely disable TCPTimeout and make TCPRecv() wait indefinitely? maybe setting it to 0 or -1 or something? 
      the docs doesn't seem to mention any way to disable it

      - the underlying C code would set SO_RCVTIMEO to 0 , aka

      DWORD timeout=0;
      setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
    • By ripdad
      I have had several people ask for this, so I decided to work the algorithm for it and this is the result.
      What is it?
      A Gateway Proxy Sends and Receives Data Unmodified.
      https://en.wikipedia.org/wiki/Proxy_server
      What is it used for?
      You can use it as a gateway, relay or router between two known static IP addresses.
      More information is in the header of the script.
      Download: LocalGatewayProxy.au3
      You will need WSA_NBTCP.au3 from here:
      https://www.autoitscript.com/forum/topic/191954-wsa_nbtcp-v100-udf/
      If you have any questions or problems, let me know.
       
    • By ripdad
      WSA_NBTCP.au3  (Windows Sockets API - Non-Blocking Transmission Control Protocol)
      Version: 1.00
      Type: UDF
      This is an accumulation of WSA code from many sources and modified to suit myself.
      These functions have been thoroughly tested using a Local Proxy Server, which
      is about the most strenuous test you can use.
      Includes my rendition of how a TCPRecv Timeout should work. Also includes a
      timewait/timeout using Select for TCP Send, which works great for that function.
      You will need a loop to use _WSA_TCPRecv(). An example will be forthcoming in a second post.
      Functions:
      #CURRENT_USER_FUNCTIONS
      _WSA_Cleanup
      _WSA_FormatMessage
      _WSA_GetLastError
      _WSA_TCPAccept
      _WSA_TCPCloseSocket
      _WSA_TCPConnect
      _WSA_TCPListen
      _WSA_TCPRecv
      _WSA_TCPSend

      #INTERNAL_FUNCTIONS
      __TimeoutManager
      __TimeoutReset

      #EXTRA_FUNCTIONS
      _WSA_GetAddrInfo
      _WSA_GetHostByAddr
      _WSAAsyncGetHostByName
      _WSAAsyncGetHostByName_Callback
      _WSA_GetNameInfo
       
      Requirements:
      - AutoIt Versions: 3.3.8.1 thru 3.3.15.0 (32Bit only).
      - TCPStartup() at beginning of script on startup.
      - TCPShutDown() and _WSA_Cleanup() on exit.
      Download UDF: WSA_NBTCP.au3
       
×
×
  • Create New...