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

Updated to v0.4b

This should be enough code for anyone to develop further.

 


"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

Glad to hear you got the http authentication working.

Good luck to you with the https part of 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

Updated first post  to v0.5b


"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

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

You are most welcome -- although "dedicated" might be too strong a word.


"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

Updated first post  to v0.7b


"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

Updated to v012b -- see first post.

 


"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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By TheXman
      Purpose (from Microsoft's website)
      The HTTP Server API enables applications to communicate over HTTP without using Microsoft Internet Information Server (IIS). Applications can register to receive HTTP requests for particular URLs, receive HTTP requests, and send HTTP responses. The HTTP Server API includes SSL support so that applications can exchange data over secure HTTP connections without IIS.
      Description
      There have been several times in the past that I wanted to either retrieve information from one of my PCs or execute commands on one of my PCs, whether it was from across the world or sitting on my couch.  Since AutoIt is one of my favorite tools for automating just about anything on my PC, I looked for ways to make to make it happen.  Setting up a full blown IIS server seemed like overkill so I looked for lighter weight solutions.  I though about creating my own AutoIt UDP or TCP server but that just wasn't robust enough,  Then I found Microsoft's HTTP Server API and it looked very promising.  After doing a little research into the APIs, I found that it was flexible & robust enough to handle just about any of the tasks that I required now and in the future.  So a while back I decided to wrap the API functionality that I needed into an AutoIt UDF file to allow me to easily create the functionality I needed at the time.  It has come in very handy over the years.  Of course it wasn't all wrapped up with a nice little bow like it is now.  That only happened when I decided to share it with anyone else who could use it or learn from it.
      The example file that I included is a very granular example of the steps required to get a lightweight HTTP Server up and listening for GET requests.  The UDF is a wrapper for the Microsoft APIs.  That means to do anything over and above what I show in the example, one would probably have to have at least a general knowledge of APIs or the ability to figure out which APIs/functions to use, what structures and data is needed to be passed to them, and in what order.  However, the UDF gives a very solid foundation on which to build upon.  Of course, if anyone has questions about the UDF or how to implement any particular functionality, I would probably help to the extent that I could or point you in the right direction so that you can figure out how to implement your own solution.
      The APIs included in the UDF are the ones that I needed in the past to do what I needed to do.  If any additional APIs need to be added to the UDF file, please make those suggestions in the related forum topic.
      Being that this is basically an AutoIt wrapper for the Microsoft API functions, there's no need to create AutoIt-specific documentation.  All of the UDF functions, structures, constants, and enumerations are named after their Microsoft API counterparts.  Therefore, you can refer to Microsoft's extensive documentation of their HTTP Server API.  As stated earlier, if there is one or more APIs that you find yourself needing for your particular solution, please suggest it in the related Example Scripts forum topic.
      Related Links
      Microsoft HTTP Server API - Start Page
      Microsoft HTTP Server API - API v2 Reference
      Microsoft HTTP Server API - Programming Model
    • By YogendraAtluri
      Hi, 
      I am new to AutoIT scripting and I am still learning. I am trying to communicate with a Labview application that acts like a server. it basically takes commands from the client. But for some commands, it also send back some data. 
      When i am sending commands from my script, i can see that the labview is getting them. But i am not able to get anything back. I tried different code pieces that are available online in the forum.
      This is the working piece of code which i been using to send data.
      #cs This module is used to establish tcp connection with lab view #ce #include <File.au3> Func SendCmd($cmd) TCPStartup() Local $IpAddress="192.168.10.101" Local $Port="5353" $Labview = TCPConnect($IpAddress,$Port) If @error Then ConsoleWrite('!--> TCPConnect error number ( ' & @error & ' ).' & @CRLF) TCPCloseSocket($Labview) TCPShutdown() Exit EndIf TCPSend($Labview, $cmd & @CRLF) TCPCloseSocket($Labview) TCPShutdown() EndFunc SendCmd("wt42d")  
      This is slightly modified code to send and receive data, which is not working. I am not getting any response back
      SendCmd("galil") Func SendCmd($cmd) TCPStartup() Local $IpAddress="192.168.10.101" Local $Port="5353" $Labview = TCPConnect($IpAddress,$Port) If @error Then ConsoleWrite('!--> TCPConnect error number ( ' & @error & ' ).' & @CRLF) TCPCloseSocket($Labview) TCPShutdown() Exit EndIf TCPSend($Labview, $cmd & @CRLF) $ip = @IPAddress1 ;create listening socket $Listensocket = TCPListen($ip, $Port) ConsoleWrite("Listening to Socket - " & $Listensocket & @CRLF) If $Listensocket = -1 Then ConsoleWrite("Exiting..." & @CRLF) Exit EndIf ;Accept incoming clients and recieve info While 1 $connectedsocket = TCPAccept($Listensocket) ConsoleWrite("Connecting to Socket - " & $connectedsocket & "Error -" & @error & @CRLF) If $ConnectedSocket >= 0 Then $ip2 = TCPRecv($connectedsocket,1000000) EndIf WEnd TCPCloseSocket($connectedsocket) TCPCloseSocket($Labview) TCPShutdown() EndFunc I am not getting anything back. I am getting the following output in the console
      +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. Listening to Socket - 544 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 Connecting to Socket - -1Error -0 its going through that loop forever. i need to force stop it.
      But when i open putty and send the same command, i am getting response right away. 
      Can someone please help me with that.
      Thanks in advance
      Regards
      Yogendra
    • By argumentum
      I can TCP/IP in AutoIt, hence, make a HTTP deamon. Now, how can I HTTPS to use SSL !??
      Well, Apache has this "mod_proxy.so" module that can let me have SSL and what not is in Apache.
      All that is needed is to tell Apache what I wanna do by editing httpd.conf .
      # Implements a proxy/gateway for Apache. # 1. Open /Applications/XAMPP/etc/httpd.conf # 2. Enable the following Modules by removing the # at the front of the line. # - LoadModule rewrite_module modules/mod_rewrite.so # - LoadModule proxy_module modules/mod_proxy.so # - LoadModule proxy_http_module modules/mod_proxy_http.so # # 3. Copy and Paste below to the bottom of httpd.conf # <IfModule mod_proxy.c> ProxyRequests On <Proxy *> Order deny,allow Allow from all </Proxy> ProxyVia Off ProxyPreserveHost Off ProxyPass /home/ http://127.0.0.1:84/home/ ProxyPassReverse /home/ http://127.0.0.1:84/home/ SetEnv proxy-nokeepalive 1 # ..since we are not using "keep-alive", we are using "close" </IfModule> ...et voila  
      I'm using XAMPP ( https://www.apachefriends.org/download.html )
      and this is my solution to avoid coding in PHP, as I feel more comfortable coding in AutoIt.
      A "muli-thread or concurrency" can be done by forking the socket ( https://www.autoitscript.com/forum/topic/199177-fork-udf-ish/ )
      but responses are under 20 ms., so I feel fine with a single thread.
      I modified an example ( attached below ), so can try out the concept.
      PS: I am not an Apache guru. I just discovered this and it opens a world of possibilities. In my case, I'm thinking of an API to query SQLite 
      PS2: I'm not gonna make Poll but do click like if you do  
       
      201673-json-http-post-serverlistener.au3
    • 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.
       
×
×
  • Create New...