rnk
2014-12-22, 18:58
original post is here:
http://www.hackforums.net/showthread.php?tid=3239841&highlight=gproxy
Autoit script to use a remote pc as proxy.We are compiling this script as gproxy.exe.
Then we upload gproxy.exe,plink.exe (ssh client) and config.ini to remote host.After running gproxy exe
(locally running bitwise ssh server)
plink.exe -R 8080:127.0.0.1:8080 -R 8081:127.0.0.1:8081 myip -l test -pw 123456
it connects to our ssh server with this command.It works on port 8080 for normal proxy but
ssl proxy on port 8081 doesnt work.
any idea?
config.ini:
[SYSTEM]
PROXYPORT=8080
PROXYIP=127.0.0.1
PROXYPORTSSL=8081
autoit script:
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=gproxy.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>
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
$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")
Global $tray_showgui = TrayCreateItem("Show gui")
TrayItemSetOnEvent($tray_showgui,"_gui_show")
GUISetOnEvent($GUI_EVENT_CLOSE,"_quit")
GUISetState(@SW_HIDE,$gui)
_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,4 43,"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
$forward = _Get_Address($mainarray[$i][3])
_save("]" & $i &" Got Host Address : " & $forward & @CRLF)
$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
$serverip = TCPNameToIP($forward)
$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
http://www.hackforums.net/showthread.php?tid=3239841&highlight=gproxy
Autoit script to use a remote pc as proxy.We are compiling this script as gproxy.exe.
Then we upload gproxy.exe,plink.exe (ssh client) and config.ini to remote host.After running gproxy exe
(locally running bitwise ssh server)
plink.exe -R 8080:127.0.0.1:8080 -R 8081:127.0.0.1:8081 myip -l test -pw 123456
it connects to our ssh server with this command.It works on port 8080 for normal proxy but
ssl proxy on port 8081 doesnt work.
any idea?
config.ini:
[SYSTEM]
PROXYPORT=8080
PROXYIP=127.0.0.1
PROXYPORTSSL=8081
autoit script:
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=gproxy.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>
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
$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")
Global $tray_showgui = TrayCreateItem("Show gui")
TrayItemSetOnEvent($tray_showgui,"_gui_show")
GUISetOnEvent($GUI_EVENT_CLOSE,"_quit")
GUISetState(@SW_HIDE,$gui)
_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,4 43,"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
$forward = _Get_Address($mainarray[$i][3])
_save("]" & $i &" Got Host Address : " & $forward & @CRLF)
$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
$serverip = TCPNameToIP($forward)
$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