bon c'est quoi un serveur proxy SOCKS ? : https://fr.wikipedia.org/wiki/SOCKS
ça fait un ans que j'ai crée ce code pour sécurisé mes connections vers internet et surfer en mode anonyme sur le net ....
je partage le code pour peut être que quelqu'un trouve ca outil ou pour le développer plus .
le proxy support tous les versions "SOCKS v 5,4,4a", et c'est très simple a utiliser
code :
Code : Tout sélectionner
; By Celtic88 (c) 2016
;about Proxy Socks ====> https://en.wikipedia.org/wiki/SOCKS
;Work on Version pb demo ;)
Structure TSocks5Request;Socks 5 Request;
Version.a ;SOCKS version, 1 byte (0x05 for this version)
Command.a ; command code, 1 byte://0x01 = establish a TCP/IP stream connection//0x02 = establish a TCP/IP port binding//0x03 = associate a UDP port
reserved.a ;reserved
addresstype.a ;address type, 1 byte://0x01 = IPv4 address//0x03 = Domain name//0x04 = IPv6 address
IpAndPort.a[#MAX_PATH+2];Request Ip and port in max size
EndStructure ;
Structure TSocks5authenticationRequest;;Socks 5 authentication Request
Version.a ;version number, 1 byte (must be 0x01)
AuthenticationLoginAndPass.a[(#MAX_PATH*2)+2] ;Request authentication login and password in max size
EndStructure
Structure TSocks5Methods;Socks 5 Methods
Version.a ;SOCKS version, 1 byte (0x05 for this version)
Methods.a ;authentication methods supported are numbered as follows://0x00: No authentication//0x01: GSSAPI[13]//0x02: Username/password[14]//0x03–0x7F: methods assigned by IANA[15]//0x80–0xFE: methods reserved For private use
lenMethods.a ;authentication methods, variable length, 1 byte per method supported
EndStructure
Structure TSocks4Request
Version.a;SOCKS version number, 1 byte, must be 0x04 for this version
Command.a;command code, 1 byte://0x01 = establish a TCP/IP stream connection//0x02 = establish a TCP/IP port binding
IpAndPort.a[6];Request Ip and port
sInfo.a ;the user ID string
EndStructure
;________________________________________________________________________________________________________________________
; Name...........: Proxy_Socks_4_4a_5
; Description ...: Get Client Request and connect to Remote server
; Parameters ....: LocalConnectionID - Client connection ID
; *ProxySocksMemWork : Point to Client Request
; SocksUser : Proxy username
; ProxySocksPassword : Proxy Password
; Socks5NegotiationLevel : The level of authentication , code return:
; -1 : accepted authentication methods
; -2 : authentication Successfully, Start the connection
; Return values .: Success - Remote server connection id or Socks5NegotiationLevel
; Failure - Returns 0
; Author ........: Celtic88
;_________________________________________________________________________________________________________________________
Procedure Proxy_Socks_4_4a_5(LocalConnectionID.i,*ProxySocksMemWork,SocksUser.s,ProxySocksPassword.s,Socks5NegotiationLevel.a)
Protected IP.s ="",Port.u=0,UserName.s,Password.s,IsSocks_4A.b=0,RemoteConnectionID.i=0,*Version.Ascii,LenUser.l=0,LenPass.l=0,LenIP.l=0,S5FixSize.l=OffsetOf(TSocks5Request\IpAndPort)
Protected *TSocks4Request.TSocks4Request,*TSocks5Methods.TSocks5Methods,*TSocks5Request.TSocks5Request,*TSocks5authenticationRequest.TSocks5authenticationRequest
*Version = *ProxySocksMemWork
If *Version\a = $04 ; is a proxy Socks 4x
*TSocks4Request=*ProxySocksMemWork
With *TSocks4Request
Select \Command ; get command
Case $01 ;establish a TCP/IP stream connection
;Ok
Case $02 ; 0x02 = establish a TCP/IP port binding :::::: currently not supported
EndSelect
Port = (\IpAndPort[0]) * 256 ;Get Port
Port + (\IpAndPort[1])
IP = Str(\IpAndPort[2]) + "." + Str(\IpAndPort[3] ) + "." ;Get Ip
IP + Str(\IpAndPort[4]) + "."
If IP ="0.0.0." And (\IpAndPort[5] ) <> $00:IsSocks_4A = 1:EndIf ; If first three bytes of DSTIP is "0" and the last byte to a non-zero value ::: is a proxy Socks 4A
IP + Str(\IpAndPort[5] )
UserName = PeekS(@\sInfo,-1,#PB_UTF8 );Peek user name
If IsSocks_4A
IP=""
IP = PeekS(@\sInfo+1+Len(UserName),-1,#PB_UTF8 ) ; if is a proxy Socks 4A get the ip after NULL byte terminating USER ID
EndIf
\Version=0 ;null byte
If SocksUser = "" Or SocksUser =UserName ; check username
If IP <> "" And \Command = $01 ; check if all is ok
\Command = $5A ; 0x5A = request granted
RemoteConnectionID=OpenNetworkConnection(IP,Port); Connect to remote server
EndIf
If Not RemoteConnectionID
\Command = $5b; if not connected send 0x5B = request rejected or failed
EndIf
Else
\Command = $5d; request failed because client's identd could not confirm the user ID string in the request
EndIf
SendNetworkData(LocalConnectionID, *TSocks4Request,8); send Request
EndWith
ElseIf *Version\a= $05 Or Socks5NegotiationLevel =-1 ; else if is a proxy Socks 5 or Socks5NegotiationLevel is -2
If Socks5NegotiationLevel =0
;Get Connection method
*TSocks5Methods = *ProxySocksMemWork
If *TSocks5Methods\Methods <> $02 Or *TSocks5Methods\lenMethods <> $02:*TSocks5Methods\Methods =$FF:EndIf; support only 0x02: Username/password
SendNetworkData(LocalConnectionID, *TSocks5Methods,2)
If *TSocks5Methods\Methods = $02 :ProcedureReturn -1 :EndIf ; return next level Negotiation
ElseIf Socks5NegotiationLevel =-1
;Get authentication
*TSocks5authenticationRequest=*ProxySocksMemWork
With *TSocks5authenticationRequest
If \Version = $01 ; if the Method is accepted
LenUser = \AuthenticationLoginAndPass[0]
UserName = PeekS(@\AuthenticationLoginAndPass[1],LenUser,#PB_UTF8 ) ;user
LenPass = \AuthenticationLoginAndPass[1+LenUser]
Password = PeekS(@\AuthenticationLoginAndPass[1+LenUser+1],LenPass,#PB_UTF8 ); pass
\Version=$05
\AuthenticationLoginAndPass[0] =$00 ; ok authentication
If SocksUser="":UserName="":EndIf:If ProxySocksPassword="":Password="":EndIf
If UserName <> SocksUser Or Password <> ProxySocksPassword ; check username and Password
\AuthenticationLoginAndPass[0] =$FF ; send authentication failed and close connection
EndIf
SendNetworkData(LocalConnectionID, *TSocks5authenticationRequest,2)
If \AuthenticationLoginAndPass[0] = $00:ProcedureReturn -2:EndIf; if ok return next level Negotiation
EndIf
EndWith
ElseIf Socks5NegotiationLevel =-2
;Get ip and port
*TSocks5Request=*ProxySocksMemWork
With *TSocks5Request
Select \Command
Case $01;establish a TCP/IP stream connection
;Ok
Case $02;establish a TCP/IP port binding :: currently not supported
Case $03;associate a UDP port :: currently not supported
EndSelect
Select \addresstype
Case $01 ; is a ipv4
IP = Str(\IpAndPort[0] ) + "." + Str(\IpAndPort[1] ) + "."
IP + Str(\IpAndPort[2] ) + "." + Str(\IpAndPort[3] )
Port = (\IpAndPort[4] ) * 256
Port + (\IpAndPort[5] )
S5FixSize +6
Case $03 ;is a Domain name
LenIP = \IpAndPort[0]
IP = PeekS(@\IpAndPort[1],LenIP,#PB_UTF8 )
Port = (\IpAndPort[LenIP+1] ) * 256
Port + (\IpAndPort[LenIP+2] )
S5FixSize +LenIP+2
Case $04 ; is a ipv6 ; currently not supported
For LenIP = 0 To 15
IP + Str(\IpAndPort[LenIP] ) + "."
Next
Port = (\IpAndPort[16] ) * 256
Port + (\IpAndPort[17] )
S5FixSize +16+2
EndSelect
If \Command =$01
If IP <> ""
If \addresstype = $04
\Command =$08; fail
Else
RemoteConnectionID=OpenNetworkConnection(IP,Port)
If Not RemoteConnectionID
\Command = $03; fail
Else
\Command= $00;request granted
EndIf
EndIf
Else
\Command =$01; fail
EndIf
Else
\Command =$07; fail
EndIf
SendNetworkData(LocalConnectionID, *TSocks5Request,S5FixSize)
EndWith
EndIf
EndIf
ProcedureReturn RemoteConnectionID; return Remote server connection id
EndProcedure
salutations,,,