Вверх ↑
Этот топик читают: Гость
Ответов: 632
Рейтинг: 4
#1: 2017-12-25 18:38:57 ЛС | профиль | цитата
На днях искал возможность создавать прокси сервера.
В Hiasm нашёл компонент Proxy, сделал программу.
Пробовал в интернете, все отлично работает, в интернете проверял прокси.
Проверка показала, что прокси, максимально анонимно "элитный прокси" и очень быстро работает, но больше половины сайт работают через https и уже ценность Proxy пропадает.

Нашёл EasyProxy, которые поддерживает Socket (Socks поддерживает все протоколы, включая HTTP, HTTPS, FTP.) , но имею только .pas, не знаю, как создать ini. Кто может помочь? Заранее огромное спасибо!

unit EasyProxy;

interface

uses
kol,
Windows,
Winsock;

type
TCompletionPort = class
public
FHandle:THandle;
constructor Create(dwNumberOfConcurentThreads:DWORD);
destructor Destroy;override;
function AssociateDevice(hDevice:THandle;dwCompKey:DWORD):boolean;
end;


TThread = class
private
Thread:PThread;
function _Execute(Sender:PThread): Integer;
protected
procedure Execute(Sender:PThread);virtual;abstract;
constructor Create;
destructor Destroy;override;
end;

TProxy = class;

TAcceptThread = class(TThread)
private
FListenSocket:TSocket;
FListenPort:Word;
FClientList:PList;
FParent:TProxy;

procedure GarbageCollect;
protected
procedure Execute(Sender:PThread);override;
public
constructor Create(AListenPort:Word; Proxy:TProxy);reintroduce;
destructor Destroy;override;
function Count:integer;
end;


TClientThread=class(TThread)
private
FParent:TProxy;
public
constructor Create(Proxy:TProxy);
procedure Execute(Sender:PThread);override;
end;


TClient = class
private
FParent:TProxy;
FSocket:TSocket;
FEvent:THandle;
ov:POVERLAPPED;
Buffer:Pointer;
BufSize:Cardinal;
procedure Write(Buf:Pointer;Size:Cardinal);
public
FOppositeClient:TClient;
FLastActivity:double;
constructor Create(Proxy:TProxy);
destructor Destroy;override;
procedure Connect(ARequest:string);
procedure Disconnect;
procedure Complete(dwNumBytes:Cardinal);virtual;abstract;
end;


TInternalClient = class(TClient)
public
procedure Complete(dwNumBytes:Cardinal);override;
end;


TExternalClient = class(TClient)
public
procedure Complete(dwNumBytes:Cardinal);override;
end;

TOnHost = procedure(Sender:TProxy; const Host:string) of object;
TOnIsAuth = function(Sender:TProxy; const LoginPass:string):boolean of object;

TProxy = class
private
AF:TAcceptThread;
FClients:PList;
public
FCompPort:TCompletionPort;
OnHost:TOnHost;
OnIsAuth:TOnIsAuth;

constructor Create;
destructor Destroy; override;

procedure Init(Port:integer; Count:integer);
procedure Stop;

function Count:integer;
end;

implementation

uses hiCharset,Share;

{ TCompletionPort }

constructor TCompletionPort.Create(dwNumberOfConcurentThreads: DWORD);
begin
FHandle:=CreateIoCompletionPort(INVALID_HANDLE_VALUE,0,0,dwNumberOfConcurentThreads);
end;

function TCompletionPort.AssociateDevice(hDevice: THandle;
dwCompKey: DWORD): boolean;
begin
result:=CreateIoCompletionPort(hDevice,FHandle,dwCompKey,0)=FHandle;
end;

destructor TCompletionPort.Destroy;
begin
CloseHandle(FHandle);
inherited;
end;

{ TThread }

constructor TThread.Create;
begin
inherited;
Thread := {$ifdef F_P}NewThreadforFPC{$else}NewThread{$endif};
Thread.OnExecute := _Execute;
Thread.Resume;
end;

destructor TThread.Destroy;
begin
Thread.Free;
inherited;
end;

function TThread._Execute;
begin
Execute(Sender);
Result := 0;
end;

{ TAcceptThread }

constructor TAcceptThread.Create;
begin
inherited Create;
FListenPort := AListenPort;
FClientList := NewList;
FParent := Proxy;
end;

destructor TAcceptThread.Destroy;
begin
closesocket(FListenSocket);
FClientList.Free;
inherited;
end;

function TAcceptThread.Count;
begin
Result := FClientList.Count;
end;

procedure TAcceptThread.GarbageCollect;
var
AClient:TClient;
i:integer;
begin
for i := 0 to FClientList.Count-1 do
begin
AClient := TClient(FClientList.Items[i]);
if Assigned(AClient) then
if (AClient.FSocket = INVALID_SOCKET) and ((now-AClient.FLastActivity)›2E-4) then
begin
FClientList.Items[i] := nil;
if Assigned(AClient.FOppositeClient) then AClient.FOppositeClient.Destroy;
AClient.Destroy;
end;
end;
//FClientList.Pack;
i := 0;
while i ‹ FClientList.Count do
if FClientList.Items[i] = nil then
FClientList.Delete(i)
else inc(i);
FClientList.Capacity := FClientList.Count;
end;


procedure TAcceptThread.Execute;
var
FAddr: TSockAddrIn;
Len: Integer;
ClientSocket:TSocket;
InternalClient:TClient;
begin
FListenSocket := socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
FAddr.sin_family := PF_INET;
FAddr.sin_addr.s_addr := INADDR_ANY;
FAddr.sin_port := htons(FListenPort);
bind(FListenSocket, FAddr, SizeOf(FAddr));
listen(FListenSocket, SOMAXCONN);
try
while not Sender.Terminated do begin
Len:=sizeof(FAddr);
ClientSocket:=accept(FListenSocket, @FAddr, @Len);
try
GarbageCollect;
if ClientSocket‹›INVALID_SOCKET then begin
InternalClient:=TInternalClient.Create(FParent);
InternalClient.FSocket:=ClientSocket;
FClientList.Add(InternalClient);
FParent.FCompPort.AssociateDevice(InternalClient.FSocket,Cardinal(InternalClient));
InternalClient.Complete(0);
end;
except end;
end;
finally
shutdown(FListenSocket,2);
closesocket(FListenSocket);
end;
end;


{ TClientThread }

constructor TClientThread.Create;
begin
inherited Create;
FParent := Proxy;
end;

procedure TClientThread.Execute;
var
CompKey,dwNumBytes:Cardinal;
ov:POVERLAPPED;
begin
try
while not Sender.Terminated do begin
if GetQueuedCompletionStatus(FParent.FCompPort.FHandle,dwNumBytes,CompKey,ov,INFINITE) and (dwNumBytes›0) then
begin
if TClient(CompKey).FSocket‹›INVALID_SOCKET then begin
TClient(CompKey).Complete(dwNumBytes);
TClient(CompKey).FLastActivity:=now;
end;
end else
TClient(CompKey).Disconnect;
end;
except
//TClientThread.Create(FParent);
end;
end;

{ TClient }

constructor TClient.Create;
begin
FSocket:=INVALID_SOCKET;
BufSize:=8192;
GetMem(Buffer,BufSize);
new(ov);
ov.Internal:=0;
ov.InternalHigh:=0;
ov.Offset:=0;
ov.OffsetHigh:=0;
ov.hEvent:=0;
FEvent:=CreateEvent(nil,true,false,nil);
FLastActivity := Now;
FParent := Proxy;
end;


destructor TClient.Destroy;
begin
Disconnect;
CloseHandle(FEvent);
FreeMem(Buffer);
Dispose(ov);
inherited;
end;


////////////////////////////////////////////////////////////////////////////////
//
// ????? ??????? ?? ??????????? ? ?????????? ?????

procedure TClient.Connect(ARequest: string);
var
f,t:integer;
ARemoteAddress:string;
ARemotePort,s:string;
he:PHostEnt;
FAddr:TSockAddrIn;
auth:boolean;
begin
f:=Pos('/',ARequest)+2;
t:=Pos('HTTP',ARequest)-1;
ARemoteAddress:=Copy(ARequest,f,t-f);
t:=Pos('/',ARemoteAddress);
if t‹›0 then ARemoteAddress:=Copy(ARemoteAddress,0,t-1);
t:=Pos(':',ARemoteAddress);
if t‹›0 then begin
ARemotePort:=Copy(ARemoteAddress,t+1,Length(ARemoteAddress)-t);
ARemoteAddress:=Copy(ARemoteAddress,0,t-1);
end else
ARemotePort:='80';
if assigned(FParent.onHost) then
FParent.OnHost(FParent, ARemoteAddress);

if Assigned(FParent.OnIsAuth) then
begin
auth := false;
f := Pos('Proxy-Authorization: ', ARequest);
if f › 0 then
begin
delete(ARequest, 1, f + 20);
f := pos(#13, ARequest);
s := copy(ARequest, 1, f-1);
if copy(s,1,6) = 'Basic ' then
begin
delete(s,1,6);
s := Base64_Decode(s);
auth := FParent.OnIsAuth(FParent, s);
end;
end;

if not auth then
begin
s := 'HTTP/1.0 407 Proxy authentication required'#13#10'Proxy-Authenticate: Basic realm="HiAsm proxy"'#13#10#13#10'Proxy authentication required';
FOppositeClient.Write(@s[1], length(s));
Disconnect;
exit;
end;
end;

he:=GetHostByName(PChar(ARemoteAddress));
if not Assigned(he) then exit;
ARemoteAddress:=inet_ntoa(PInAddr(he.h_addr_list^)^);

FSocket:=socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
FAddr.sin_family:=PF_INET;
FAddr.sin_addr.s_addr :=inet_addr(PChar(ARemoteAddress));
try
FAddr.sin_port := htons(Str2Int(ARemotePort));
if WinSock.connect(FSocket, FAddr, SizeOf(FAddr))=SOCKET_ERROR then FSocket:=INVALID_SOCKET;
except
//WriteLn('Connection failed');
end;
end;


procedure TClient.Disconnect;
begin
if FSocket‹›INVALID_SOCKET then begin
shutdown(FSocket,2);
closesocket(FSocket);
FSocket:=INVALID_SOCKET;
if Assigned(FOppositeClient) then FOppositeClient.Disconnect;
end;
end;

procedure TClient.Write(Buf: Pointer; Size: Cardinal);
var
BytesWrite:Cardinal;
begin
ov.hEvent:=FEvent or 1;
WriteFile(FSocket,Buf^,Size,BytesWrite,ov);
ov.hEvent:=0;
end;


{ TInternalClient }

procedure TInternalClient.Complete(dwNumBytes: Cardinal);
var
BytesRead:Cardinal;
begin
if dwNumBytes›0 then begin
if not Assigned(FOppositeClient) then begin
FOppositeClient:=TExternalClient.Create(FParent);
FOppositeClient.FOppositeClient:=self;
FOppositeClient.Connect(PChar(Buffer));
if FOppositeClient.FSocket=INVALID_SOCKET then begin
Disconnect;
exit;
end;
FParent.FCompPort.AssociateDevice(FOppositeClient.FSocket,Cardinal(FOppositeClient));
FOppositeClient.Complete(0);
end;
FOppositeClient.Write(Buffer,dwNumBytes);
end;
ReadFile(FSocket,Buffer^,BufSize,BytesRead,ov);
end;

{ TExternalClient }

procedure TExternalClient.Complete(dwNumBytes: Cardinal);
var
BytesRead:Cardinal;
begin
if dwNumBytes›0 then FOppositeClient.Write(Buffer,dwNumBytes);
ReadFile(FSocket,Buffer^,BufSize,BytesRead,ov);
end;

constructor TProxy.Create;
begin
inherited Create;
end;

destructor TProxy.Destroy;
begin
Stop;
inherited;
end;

procedure TProxy.Init;
var i:integer;
begin
FCompPort := TCompletionPort.Create(Count);
FClients := NewList;
for i := 0 to Count-1 do
FClients.Add(TClientThread.Create(Self));
AF := TAcceptThread.Create(Port, Self);
end;

procedure TProxy.Stop;
var i:integer;
begin
if FCompPort = nil then exit;

FCompPort.Destroy;
FCompPort := nil;
AF.Destroy;
for i := 0 to FClients.Count-1 do
TClientThread(FClients.Items[i]).Destroy;
FClients.Free;
end;

function TProxy.Count;
begin
if FCompPort = nil then
Result := 0
else Result := AF.Count;
end;

end.

Редактировалось 2 раз(а), последний 2017-12-25 19:01:02
карма: 0

0
Ответов: 1328
Рейтинг: 69
#2: 2017-12-26 09:22:36 ЛС | профиль | цитата
Vadimluk1, этот pas не для Hiasm
карма: 2

0
Ответов: 632
Рейтинг: 4
#3: 2017-12-26 14:30:50 ЛС | профиль | цитата
Konst писал(а):
Вадимлук1 , этот пас не для Хиазма

Что он делает в репозиторий: http://svn.hiasm.com/packs ?(EasyProxy.pas) Его там нашёл!

Редактировалось 1 раз(а), последний 2017-12-26 14:33:06
карма: 0

0
Ответов: 2059
Рейтинг: 132
#4: 2017-12-26 14:39:39 ЛС | профиль | цитата
Что он делает в репозиторий: http://svn.hiasm.com/packs ?(EasyProxy.pas) Его там нашёл!

Он живёт там в качестве библиотеки.
unit hiProxy;
interface
uses Kol,Share,Windows,Debug,hiCharset,EasyProxy;

Правильней было сказать не
Konst писал(а):
Vadimluk1, этот pas не для Hiasm

а то, что это не листинг компонента, а uses-библиотека.

Редактировалось 4 раз(а), последний 2017-12-26 15:08:13
карма: 6

0
Ответов: 632
Рейтинг: 4
#5: 2017-12-26 15:14:05 ЛС | профиль | цитата
flint2 писал(а):
Что он делает в репозиторий: http://svn.hiasm.com/packs ?(EasyProxy.pas) Его там нашёл!

Он живёт там в качестве библиотеки.
unit hiProxy;
interface
uses Kol,Share,Windows,Debug,hiCharset,EasyProxy;

Правильней было сказать не
Konst писал(а):
Vadimluk1, этот pas не для Hiasm

а то, что это не листинг компонента, а uses-библиотека.

Насколько возможно добавить поддержку socket5?
карма: 0

0
Ответов: 2059
Рейтинг: 132
#6: 2017-12-26 16:42:35 ЛС | профиль | цитата
Вот здесь в IC то, что нужно.
эта схема для тестирования, так что надо переделать IC и добавить точки.

Add(MainForm,16089989,231,182)
{
}
Add(InlineCode,15441213,378,182)
{
WorkPoints=#3:get|
Code=#15:unit HiAsmUnit;|0:|9:interface|0:|38:uses kol,Share,Debug,Windows, Winsock;|0:|4:type|28: THiAsmClass = class(TDebug)|10: private|0:|9: public|46: procedure get(var _Data:TData; Index:word);|5: end;|0:|14:implementation|0:|0:|4: VAR|21: IsAuth : Boolean;|20: Username : string;|20: Password : string;|20: IP : string;|21: Port : integer;|21: i : integer;|21: bool : boolean;|23: SpecialBind: boolean;|0:|17: WSA : TWSAData;|23: servsocket : TSocket;|21: addr : sockaddr_in;|41: hostname : array [0..MAX_PATH] of Char;|18: host : PHostEnt;|0:|4:type|26: TSocks5AuthData = record|15: ver : Char;|17: nmthd : Char;|16: mthd : Char;|6: end;|0:|4:type|25: TSocks5Request = record|15: ver : Char;|17: code : record|19: case Integer of|24: 0 : (cmd : Char;);|24: 1 : (rep : Char;);|8: end;|15: rsv : Char;|16: atyp : Char;|34: addr : array [0..255] of Char;|4:end;|0:|5:const|32: USER_PASS_AUTH_VERSION = #$01;|32: USER_PASS_AUTH_SUCCESS = #$00;|32: USER_PASS_AUTH_FAILED = #$ff;|0:|5:const|24: SOCKS5_VERSION = #$05;|33: SOCKS5_METHOD_AUTH_NONE = #$00;|33: SOCKS5_METHOD_USER_PASS = #$02;|42: SOCKS5_METHOD_AUTH_NOT_SUPPORTED = #$ff;|28: SOCKS5_CMD_CONNECT = #$01;|20: SOCKS5_RSV = #$00;|26: SOCKS5_ATYP_IPv4 = #$01;|33: SOCKS5_ATYP_DOMAIN_NAME = #$03;|23: SOCKS5_REP_OK = #$00;|33: SOCKS5_REP_SERVER_ERROR = #$01;|32: SOCKS5_REP_HOST_FAILED = #$04;|38: SOCKS5_REP_CMD_NOT_SUPPORTED = #$07;|39: SOCKS5_REP_ADDR_NOT_SUPPORTED = #$08;|2: |0:|60:procedure SendErrorCode(sock : TSocket; ErrorCode : String);|5:begin|49: send(sock, ErrorCode[1], Length(ErrorCode), 0);|20: CloseSocket(sock);|4:end;|0:|50:procedure DataTransfer(clsock,trgtsock : TSocket);|3:var|33: buff : array [0..1023] of Char;|16: tv : TTimeVal;|15: fds : TFDSet;|17: brcv : Integer;|5:begin|15: while True do|7: begin|17: FD_ZERO(fds);|24: FD_SET(clsock, fds);|26: FD_SET(trgtsock, fds);|20: tv.tv_sec := 15;|20: tv.tv_usec := 0;|46: if Select(0, @fds, nil, nil, @tv) > 0 then|9: begin|35: if FD_ISSET(clsock, fds) then|11: begin|40: ZeroMemory(@buff, SizeOf(buff));|52: brcv := recv(clsock, buff, SizeOf(buff), 0);|24: if brcv > 0 then|39: send(trgtsock, buff, brcv, 0)|12: else|16: Break;|10: end;|37: if FD_ISSET(trgtsock, fds) then|11: begin|40: ZeroMemory(@buff, SizeOf(buff));|54: brcv := recv(trgtsock, buff, SizeOf(buff), 0);|24: if brcv > 0 then|37: send(clsock, buff, brcv, 0)|12: else|16: Break;|10: end;|8: end;|6: end;|4:end;|0:|81:function Socks5AcceptRequest(clsock : TSocket; var trgtsock : TSocket) : Boolean;|3:var|40: cl_request,srv_reply : TSocks5Request;|33: buff : array [0..1023] of Char;|35: dst_addr,self_addr : sockaddr_in;|37: len_self_addr,len_domain : Integer;|18: Host : PHostEnt;|17: brcv : Integer;|15: err : String;|5:begin|18: Result := False;|21: SetLength(err, 10);|34: ZeroMemory(@buff, SizeOf(buff));|46: brcv := recv(clsock, buff, SizeOf(buff), 0);|50: ZeroMemory(@cl_request, SizeOf(TSocks5Request));|39: CopyMemory(@cl_request, @buff, brcv);|49: ZeroMemory(@srv_reply, SizeOf(TSocks5Request));|34: srv_reply.ver := SOCKS5_VERSION;|30: srv_reply.rsv := SOCKS5_RSV;|87: if ((cl_request.ver = SOCKS5_VERSION) and (cl_request.rsv = SOCKS5_RSV)) = False then|7: begin|50: srv_reply.code.rep := SOCKS5_REP_SERVER_ERROR;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|29: case cl_request.code.cmd of|25: SOCKS5_CMD_CONNECT : ;|6: else|55: srv_reply.code.rep := SOCKS5_REP_CMD_NOT_SUPPORTED;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|45: ZeroMemory(@dst_addr, SizeOf(sockaddr_in));|33: dst_addr.sin_family := AF_INET;|25: case cl_request.atyp of|21: SOCKS5_ATYP_IPv4 :|10: begin|59: dst_addr.sin_addr.S_un_b.s_b1 := cl_request.addr[0];|59: dst_addr.sin_addr.S_un_b.s_b2 := cl_request.addr[1];|59: dst_addr.sin_addr.S_un_b.s_b3 := cl_request.addr[2];|59: dst_addr.sin_addr.S_un_b.s_b4 := cl_request.addr[3];|89: dst_addr.sin_port := MakeWord(Byte(cl_request.addr[4]), Byte(cl_request.addr[5]));|9: end;|28: SOCKS5_ATYP_DOMAIN_NAME :|10: begin|46: len_domain := Byte(cl_request.addr[0]);|74: Host := GetHostByName(PChar(Copy(cl_request.addr, 2, len_domain)));|25: if Host = nil then|12: begin|55: srv_reply.code.rep := SOCKS5_REP_SERVER_ERROR;|45: CopyMemory(@err[1], @srv_reply, 10);|36: SendErrorCode(clsock, err);|14: Exit;|11: end;|74: dst_addr.sin_addr.S_addr := LongInt(PLongInt(Host^.h_addr_list^)^);|115: dst_addr.sin_port := MakeWord(Byte(cl_request.addr[len_domain + 1]), Byte(cl_request.addr[len_domain + 2]));|9: end;|6: else|56: srv_reply.code.rep := SOCKS5_REP_ADDR_NOT_SUPPORTED;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|73: if Connect(trgtsock, dst_addr, SizeOf(sockaddr_in)) = SOCKET_ERROR then|7: begin|49: srv_reply.code.rep := SOCKS5_REP_HOST_FAILED;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|26: CloseSocket(trgtsock);|9: Exit;|6: end;|46: ZeroMemory(@self_addr, SizeOf(sockaddr_in));|39: len_self_addr := SizeOf(sockaddr_in);|50: GetSockName(trgtsock, self_addr, len_self_addr);|37: srv_reply.atyp := SOCKS5_ATYP_IPv4;|54: srv_reply.addr[0] := self_addr.sin_addr.S_un_b.s_b1;|54: srv_reply.addr[1] := self_addr.sin_addr.S_un_b.s_b2;|54: srv_reply.addr[2] := self_addr.sin_addr.S_un_b.s_b3;|54: srv_reply.addr[3] := self_addr.sin_addr.S_un_b.s_b4;|57: srv_reply.addr[4] := Chr(self_addr.sin_port and $00ff);|53: srv_reply.addr[5] := Chr(self_addr.sin_port shr 8);|34: ZeroMemory(@buff, SizeOf(buff));|36: CopyMemory(@buff, @srv_reply, 10);|28: send(clsock, buff, 10, 0);|17: Result := True;|4:end;|0:|50:function Socks5DoAuth(clsock : TSocket) : Boolean;|3:var|33: buff : array [0..1023] of Char;|23: _USER,_PASS : String;|22: index,len : Integer;|15: err : String;|5:begin|18: Result := False;|34: ZeroMemory(@buff, SizeOf(buff));|38: recv(clsock, buff, SizeOf(buff), 0);|43: if buff[0] <> USER_PASS_AUTH_VERSION then|7: begin|58: err := USER_PASS_AUTH_VERSION + USER_PASS_AUTH_FAILED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|13: index := 2;|22: len := Ord(buff[1]);|24: SetLength(_USER, len);|43: CopyMemory(@_USER[1], @buff[index], len);|19: index := len + 3;|28: len := Ord(buff[len + 2]);|24: SetLength(_PASS, len);|43: CopyMemory(@_PASS[1], @buff[index], len);|61: if ((_USER = Username) and (_PASS = Password)) = False then|7: begin|58: err := USER_PASS_AUTH_VERSION + USER_PASS_AUTH_FAILED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|34: ZeroMemory(@buff, SizeOf(buff));|36: buff[0] := USER_PASS_AUTH_VERSION;|36: buff[1] := USER_PASS_AUTH_SUCCESS;|27: send(clsock, buff, 2, 0);|17: Result := True;|4:end;|0:|54:function Socks5AuthVerify(clsock : TSocket) : Boolean;|3:var|30: auth_data : TSocks5AuthData;|33: buff : array [0..1023] of Char;|15: err : String;|5:begin|18: Result := False;|12: err := '';|34: ZeroMemory(@buff, SizeOf(buff));|38: recv(clsock, buff, SizeOf(buff), 0);|35: CopyMemory(@auth_data, @buff, 3);|81: if ((auth_data.ver = SOCKS5_VERSION) and (auth_data.nmthd = #$01)) = False then|7: begin|61: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|24: case auth_data.mthd of|28: SOCKS5_METHOD_AUTH_NONE :|10: begin|39: ZeroMemory(@buff, SizeOf(buff));|29: if IsAuth = False then|12: begin|35: buff[0] := SOCKS5_VERSION;|44: buff[1] := SOCKS5_METHOD_AUTH_NONE;|34: send(clsock, buff, 2, 0);|10: end|17: else begin|66: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|36: SendErrorCode(clsock, err);|14: Exit;|11: end;|9: end;|28: SOCKS5_METHOD_USER_PASS :|10: begin|21: if IsAuth then|12: begin|41: ZeroMemory(@buff, SizeOf(buff));|35: buff[0] := SOCKS5_VERSION;|44: buff[1] := SOCKS5_METHOD_USER_PASS;|34: send(clsock, buff, 2, 0);|45: if Socks5DoAuth(clsock) = False then|16: Exit;|10: end|17: else begin|66: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|36: SendErrorCode(clsock, err);|14: Exit;|11: end;|9: end;|6: else|61: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|17: Result := True;|4:end;|0:|57:function Socks5Tunnel(pParam : Pointer) : DWORD; stdcall;|3:var|21: trgtsock : TSocket;|19: clsock : TSocket;|5:begin|14: Result := 0;|28: clsock := TSocket(pParam);|56: trgtsock := Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);|34: if Socks5AuthVerify(clsock) then|49: if Socks5AcceptRequest(clsock, trgtsock) then|9: begin|37: DataTransfer(clsock, trgtsock);|28: CloseSocket(trgtsock);|26: CloseSocket(clsock);|8: end;|4:end;|0:|43:procedure Socks5Server(servsock : TSocket);|3:var|19: clsock : TSocket;|21: addr : sockaddr_in;|20: addrlen : Integer;|17: TId : Cardinal;|5:begin|15: while True do|7: begin|48: clsock := accept(servsock, @addr, @addrlen);|65: CreateThread(nil, 0, @Socks5Tunnel, Pointer(clsock), 0, TId);|6: end;|24: CloseSocket(servsock);|4:end;|1:{|23:procedure PrintUSAGE();|5:begin|21: WriteLn(' USAGE:');|121: WriteLn(' '+ExtractFileName(ParamStr(0))+' [--port <port>] [--login <login>] [--pass <password>] [--bind <IP>]'#13#10);|32: Writeln(' Use For');|53: Writeln(' --port Set special port for socks5');|44: WriteLn(' --login Set login for Auth');|47: WriteLn(' --pass Set password for Auth');|56: WriteLn(' --bind Set your special IP for listen');|104: WriteLn(#13#10' Example: '+ExtractFileName(ParamStr(0))+' --port 1080 --login admin --pass PaSsWoRd');|4:end;|1:}|55:procedure THiAsmClass.get(var _Data:TData; Index:word);|5:begin|47:{ WriteLn(' Welcome to FOS Black Hat Socks5');|32: WriteLn(' Version 1.1'#13#10);|41: if ((ParamCount=0)OR(ParamStr(1)='/?'))|40: then begin PrintUSAGE; exit; end; }|7: i:=1;|15: IsAuth:=true;|14: Port:=13066;|19: Username:='user';|23: Password:='password';|21: SpecialBind:=false;|27: { While (i<=ParamCount) do|7: begin|16: bool:=false;|142: if ParamStr(i)='--port' then begin try Port:=StrToInt(ParamStr(i+1)); except WriteLn(' ERROR: CANT INIT VAR PORT!'); end; bool:=true; end;|81: if ParamStr(i)='--login' then begin Username:=ParamStr(i+1); bool:=true; end;|80: if ParamStr(i)='--pass' then begin Password:=ParamStr(i+1); bool:=true; end;|93: if ParamStr(i)='--bind' then begin IP:=ParamStr(i+1); SpecialBind:=true; bool:=True; end;|70: if ParamStr(i)='--about' then WriteLn(' Created by Sicness for ');|23: if bool then i:=i+2|18: else i:=i+1;|68: //TODO: Доделать проверку парамертров, а то может громко рухнуть|8: end; }|0:|0:|1:{|54: Writeln(' |=========|============================');|42: Writeln(' |Port | '+IntToStr(Port));|36: Writeln(' |Login | '+Username);|36: Writeln(' |Password | '+Password);|81: Write(' |SpecBind | '); if SpecialBind then WriteLn(IP) else WriteLn(' False');|64: Writeln(' |=========|============================'#13#10); }|0:|36: if WSAStartup($101, WSA) <> 0 then|7: begin|41: showmessage('ERROR: Winsock failed');|9: Exit;|6: end;|58: servsocket := Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);|37: if servsocket = INVALID_SOCKET then|7: begin|49: showmessage('ERROR: Socket creation failed');|9: Exit;|6: end;|42: ZeroMemory(@hostname, SizeOf(hostname));|43: GetHostName(@hostname, SizeOf(hostname));|35: host := GetHostByName(@hostname);|20: if Host = nil then|7: begin|39: showmessage('Hostname failed ...');|9: Exit;|6: end;|41: ZeroMemory(@addr, SizeOf(sockaddr_in));|29: addr.sin_family := AF_INET;|31: addr.sin_port := htons(Port);|16: if SpecialBind|76: then addr.sin_addr.S_addr:=inet_addr(Pchar(IP)) //Биндим на указанный IP|92: else addr.sin_addr.S_addr := LongInt(PLongInt(host.h_addr_list^)^); //Автоопределение IP|68: if Bind(servsocket, addr, SizeOf(sockaddr_in)) = SOCKET_ERROR then|7: begin|31: showmessage('Bind failed');|9: Exit;|6: end;|47: if Listen(servsocket, 60) = SOCKET_ERROR then|7: begin|31: showmessage('List failed');|9: Exit;|5: end|6: else|109: showmessage('Socks started on [' + inet_ntoa(addr.sin_addr) + ':' + Int2Str(ntohs(addr.sin_port)) + ']');|28: IsMultiThread := True; |27: Socks5Server(servsocket);|0:|4:end;|0:|4:end.|
}
Add(Button,8623931,280,182)
{
Left=155
Top=110
link(onClick,2664651:doStart,[])
}
Add(Thread,2664651,329,182)
{
Delay=1
link(onExec,15441213:get,[])
}
В строке 358 SpecialBind:=false; надо поставить SpecialBind:=true; ( временно)
Это нужно для выбора сток 403, 404, 405. SpecialBind надо сделать integer и брать значение, например с верхней точки, или так 403 строка if 0 = ToIntegerEvent(верхняя точка) then
Можно и компонент сделать, но кто в этом будет разбираться - это главный вопрос.
Я не в теме.
Socks5, для меня дело тёмное и познанию не подлежит!

Редактировалось 3 раз(а), последний 2017-12-26 16:59:46
карма: 6

0
Ответов: 632
Рейтинг: 4
#7: 2017-12-26 17:35:04 ЛС | профиль | цитата
flint2 писал(а):
if 0 = ToIntegerEvent(верхняя точка) then


Add(MainForm,16089989,210,147)
{
}
Add(InlineCode,15441213,357,147)
{
WorkPoints=#3:get|
DataPoints=#2:ip|
Code=#15:unit HiAsmUnit;|0:|9:interface|0:|38:uses kol,Share,Debug,Windows, Winsock;|0:|4:type|28: THiAsmClass = class(TDebug)|10: private|0:|9: public|46: procedure get(var _Data:TData; Index:word);|5: end;|0:|14:implementation|0:|0:|4: VAR|21: IsAuth : Boolean;|20: Username : string;|20: Password : string;|20: IP : string;|21: Port : integer;|21: i : integer;|21: bool : boolean;|23: SpecialBind: boolean;|0:|17: WSA : TWSAData;|23: servsocket : TSocket;|21: addr : sockaddr_in;|41: hostname : array [0..MAX_PATH] of Char;|18: host : PHostEnt;|0:|4:type|26: TSocks5AuthData = record|15: ver : Char;|17: nmthd : Char;|16: mthd : Char;|6: end;|0:|4:type|25: TSocks5Request = record|15: ver : Char;|17: code : record|19: case Integer of|24: 0 : (cmd : Char;);|24: 1 : (rep : Char;);|8: end;|15: rsv : Char;|16: atyp : Char;|34: addr : array [0..255] of Char;|4:end;|0:|5:const|32: USER_PASS_AUTH_VERSION = #$01;|32: USER_PASS_AUTH_SUCCESS = #$00;|32: USER_PASS_AUTH_FAILED = #$ff;|0:|5:const|24: SOCKS5_VERSION = #$05;|33: SOCKS5_METHOD_AUTH_NONE = #$00;|33: SOCKS5_METHOD_USER_PASS = #$02;|42: SOCKS5_METHOD_AUTH_NOT_SUPPORTED = #$ff;|28: SOCKS5_CMD_CONNECT = #$01;|20: SOCKS5_RSV = #$00;|26: SOCKS5_ATYP_IPv4 = #$01;|33: SOCKS5_ATYP_DOMAIN_NAME = #$03;|23: SOCKS5_REP_OK = #$00;|33: SOCKS5_REP_SERVER_ERROR = #$01;|32: SOCKS5_REP_HOST_FAILED = #$04;|38: SOCKS5_REP_CMD_NOT_SUPPORTED = #$07;|39: SOCKS5_REP_ADDR_NOT_SUPPORTED = #$08;|2: |0:|60:procedure SendErrorCode(sock : TSocket; ErrorCode : String);|5:begin|49: send(sock, ErrorCode[1], Length(ErrorCode), 0);|20: CloseSocket(sock);|4:end;|0:|50:procedure DataTransfer(clsock,trgtsock : TSocket);|3:var|33: buff : array [0..1023] of Char;|16: tv : TTimeVal;|15: fds : TFDSet;|17: brcv : Integer;|5:begin|15: while True do|7: begin|17: FD_ZERO(fds);|24: FD_SET(clsock, fds);|26: FD_SET(trgtsock, fds);|20: tv.tv_sec := 15;|20: tv.tv_usec := 0;|46: if Select(0, @fds, nil, nil, @tv) > 0 then|9: begin|35: if FD_ISSET(clsock, fds) then|11: begin|40: ZeroMemory(@buff, SizeOf(buff));|52: brcv := recv(clsock, buff, SizeOf(buff), 0);|24: if brcv > 0 then|39: send(trgtsock, buff, brcv, 0)|12: else|16: Break;|10: end;|37: if FD_ISSET(trgtsock, fds) then|11: begin|40: ZeroMemory(@buff, SizeOf(buff));|54: brcv := recv(trgtsock, buff, SizeOf(buff), 0);|24: if brcv > 0 then|37: send(clsock, buff, brcv, 0)|12: else|16: Break;|10: end;|8: end;|6: end;|4:end;|0:|81:function Socks5AcceptRequest(clsock : TSocket; var trgtsock : TSocket) : Boolean;|3:var|40: cl_request,srv_reply : TSocks5Request;|33: buff : array [0..1023] of Char;|35: dst_addr,self_addr : sockaddr_in;|37: len_self_addr,len_domain : Integer;|18: Host : PHostEnt;|17: brcv : Integer;|15: err : String;|5:begin|18: Result := False;|21: SetLength(err, 10);|34: ZeroMemory(@buff, SizeOf(buff));|46: brcv := recv(clsock, buff, SizeOf(buff), 0);|50: ZeroMemory(@cl_request, SizeOf(TSocks5Request));|39: CopyMemory(@cl_request, @buff, brcv);|49: ZeroMemory(@srv_reply, SizeOf(TSocks5Request));|34: srv_reply.ver := SOCKS5_VERSION;|30: srv_reply.rsv := SOCKS5_RSV;|87: if ((cl_request.ver = SOCKS5_VERSION) and (cl_request.rsv = SOCKS5_RSV)) = False then|7: begin|50: srv_reply.code.rep := SOCKS5_REP_SERVER_ERROR;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|29: case cl_request.code.cmd of|25: SOCKS5_CMD_CONNECT : ;|6: else|55: srv_reply.code.rep := SOCKS5_REP_CMD_NOT_SUPPORTED;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|45: ZeroMemory(@dst_addr, SizeOf(sockaddr_in));|33: dst_addr.sin_family := AF_INET;|25: case cl_request.atyp of|21: SOCKS5_ATYP_IPv4 :|10: begin|59: dst_addr.sin_addr.S_un_b.s_b1 := cl_request.addr[0];|59: dst_addr.sin_addr.S_un_b.s_b2 := cl_request.addr[1];|59: dst_addr.sin_addr.S_un_b.s_b3 := cl_request.addr[2];|59: dst_addr.sin_addr.S_un_b.s_b4 := cl_request.addr[3];|89: dst_addr.sin_port := MakeWord(Byte(cl_request.addr[4]), Byte(cl_request.addr[5]));|9: end;|28: SOCKS5_ATYP_DOMAIN_NAME :|10: begin|46: len_domain := Byte(cl_request.addr[0]);|74: Host := GetHostByName(PChar(Copy(cl_request.addr, 2, len_domain)));|25: if Host = nil then|12: begin|55: srv_reply.code.rep := SOCKS5_REP_SERVER_ERROR;|45: CopyMemory(@err[1], @srv_reply, 10);|36: SendErrorCode(clsock, err);|14: Exit;|11: end;|74: dst_addr.sin_addr.S_addr := LongInt(PLongInt(Host^.h_addr_list^)^);|115: dst_addr.sin_port := MakeWord(Byte(cl_request.addr[len_domain + 1]), Byte(cl_request.addr[len_domain + 2]));|9: end;|6: else|56: srv_reply.code.rep := SOCKS5_REP_ADDR_NOT_SUPPORTED;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|73: if Connect(trgtsock, dst_addr, SizeOf(sockaddr_in)) = SOCKET_ERROR then|7: begin|49: srv_reply.code.rep := SOCKS5_REP_HOST_FAILED;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|26: CloseSocket(trgtsock);|9: Exit;|6: end;|46: ZeroMemory(@self_addr, SizeOf(sockaddr_in));|39: len_self_addr := SizeOf(sockaddr_in);|50: GetSockName(trgtsock, self_addr, len_self_addr);|37: srv_reply.atyp := SOCKS5_ATYP_IPv4;|54: srv_reply.addr[0] := self_addr.sin_addr.S_un_b.s_b1;|54: srv_reply.addr[1] := self_addr.sin_addr.S_un_b.s_b2;|54: srv_reply.addr[2] := self_addr.sin_addr.S_un_b.s_b3;|54: srv_reply.addr[3] := self_addr.sin_addr.S_un_b.s_b4;|57: srv_reply.addr[4] := Chr(self_addr.sin_port and $00ff);|53: srv_reply.addr[5] := Chr(self_addr.sin_port shr 8);|34: ZeroMemory(@buff, SizeOf(buff));|36: CopyMemory(@buff, @srv_reply, 10);|28: send(clsock, buff, 10, 0);|17: Result := True;|4:end;|0:|50:function Socks5DoAuth(clsock : TSocket) : Boolean;|3:var|33: buff : array [0..1023] of Char;|23: _USER,_PASS : String;|22: index,len : Integer;|15: err : String;|5:begin|18: Result := False;|34: ZeroMemory(@buff, SizeOf(buff));|38: recv(clsock, buff, SizeOf(buff), 0);|43: if buff[0] <> USER_PASS_AUTH_VERSION then|7: begin|58: err := USER_PASS_AUTH_VERSION + USER_PASS_AUTH_FAILED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|13: index := 2;|22: len := Ord(buff[1]);|24: SetLength(_USER, len);|43: CopyMemory(@_USER[1], @buff[index], len);|19: index := len + 3;|28: len := Ord(buff[len + 2]);|24: SetLength(_PASS, len);|43: CopyMemory(@_PASS[1], @buff[index], len);|61: if ((_USER = Username) and (_PASS = Password)) = False then|7: begin|58: err := USER_PASS_AUTH_VERSION + USER_PASS_AUTH_FAILED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|34: ZeroMemory(@buff, SizeOf(buff));|36: buff[0] := USER_PASS_AUTH_VERSION;|36: buff[1] := USER_PASS_AUTH_SUCCESS;|27: send(clsock, buff, 2, 0);|17: Result := True;|4:end;|0:|54:function Socks5AuthVerify(clsock : TSocket) : Boolean;|3:var|30: auth_data : TSocks5AuthData;|33: buff : array [0..1023] of Char;|15: err : String;|5:begin|18: Result := False;|12: err := '';|34: ZeroMemory(@buff, SizeOf(buff));|38: recv(clsock, buff, SizeOf(buff), 0);|35: CopyMemory(@auth_data, @buff, 3);|81: if ((auth_data.ver = SOCKS5_VERSION) and (auth_data.nmthd = #$01)) = False then|7: begin|61: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|24: case auth_data.mthd of|28: SOCKS5_METHOD_AUTH_NONE :|10: begin|39: ZeroMemory(@buff, SizeOf(buff));|29: if IsAuth = False then|12: begin|35: buff[0] := SOCKS5_VERSION;|44: buff[1] := SOCKS5_METHOD_AUTH_NONE;|34: send(clsock, buff, 2, 0);|10: end|17: else begin|66: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|36: SendErrorCode(clsock, err);|14: Exit;|11: end;|9: end;|28: SOCKS5_METHOD_USER_PASS :|10: begin|21: if IsAuth then|12: begin|41: ZeroMemory(@buff, SizeOf(buff));|35: buff[0] := SOCKS5_VERSION;|44: buff[1] := SOCKS5_METHOD_USER_PASS;|34: send(clsock, buff, 2, 0);|45: if Socks5DoAuth(clsock) = False then|16: Exit;|10: end|17: else begin|66: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|36: SendErrorCode(clsock, err);|14: Exit;|11: end;|9: end;|6: else|61: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|17: Result := True;|4:end;|0:|57:function Socks5Tunnel(pParam : Pointer) : DWORD; stdcall;|3:var|21: trgtsock : TSocket;|19: clsock : TSocket;|5:begin|14: Result := 0;|28: clsock := TSocket(pParam);|56: trgtsock := Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);|34: if Socks5AuthVerify(clsock) then|49: if Socks5AcceptRequest(clsock, trgtsock) then|9: begin|37: DataTransfer(clsock, trgtsock);|28: CloseSocket(trgtsock);|26: CloseSocket(clsock);|8: end;|4:end;|0:|43:procedure Socks5Server(servsock : TSocket);|3:var|19: clsock : TSocket;|21: addr : sockaddr_in;|20: addrlen : Integer;|17: TId : Cardinal;|5:begin|15: while True do|7: begin|48: clsock := accept(servsock, @addr, @addrlen);|65: CreateThread(nil, 0, @Socks5Tunnel, Pointer(clsock), 0, TId);|6: end;|24: CloseSocket(servsock);|4:end;|1:{|23:procedure PrintUSAGE();|5:begin|21: WriteLn(' USAGE:');|121: WriteLn(' '+ExtractFileName(ParamStr(0))+' [--port <port>] [--login <login>] [--pass <password>] [--bind <IP>]'#13#10);|32: Writeln(' Use For');|53: Writeln(' --port Set special port for socks5');|44: WriteLn(' --login Set login for Auth');|47: WriteLn(' --pass Set password for Auth');|56: WriteLn(' --bind Set your special IP for listen');|104: WriteLn(#13#10' Example: '+ExtractFileName(ParamStr(0))+' --port 1080 --login admin --pass PaSsWoRd');|4:end;|1:}|55:procedure THiAsmClass.get(var _Data:TData; Index:word);|5:begin|47:{ WriteLn(' Welcome to FOS Black Hat Socks5');|32: WriteLn(' Version 1.1'#13#10);|41: if ((ParamCount=0)OR(ParamStr(1)='/?'))|40: then begin PrintUSAGE; exit; end; }|7: i:=1;|16: IsAuth:=false;|11: Port:=83;|19: Username:='user';|23: Password:='password';|20: SpecialBind:=true;|27: { While (i<=ParamCount) do|7: begin|16: bool:=false;|142: if ParamStr(i)='--port' then begin try Port:=StrToInt(ParamStr(i+1)); except WriteLn(' ERROR: CANT INIT VAR PORT!'); end; bool:=true; end;|81: if ParamStr(i)='--login' then begin Username:=ParamStr(i+1); bool:=true; end;|80: if ParamStr(i)='--pass' then begin Password:=ParamStr(i+1); bool:=true; end;|93: if ParamStr(i)='--bind' then begin IP:=ParamStr(i+1); SpecialBind:=true; bool:=True; end;|70: if ParamStr(i)='--about' then WriteLn(' Created by Sicness for ');|23: if bool then i:=i+2|18: else i:=i+1;|68: //TODO: Доделать проверку парамертров, а то может громко рухнуть|8: end; }|0:|0:|1:{|54: Writeln(' |=========|============================');|42: Writeln(' |Port | '+IntToStr(Port));|36: Writeln(' |Login | '+Username);|36: Writeln(' |Password | '+Password);|81: Write(' |SpecBind | '); if SpecialBind then WriteLn(IP) else WriteLn(' False');|64: Writeln(' |=========|============================'#13#10); }|0:|36: if WSAStartup($101, WSA) <> 0 then|7: begin|41: showmessage('ERROR: Winsock failed');|9: Exit;|6: end;|58: servsocket := Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);|37: if servsocket = INVALID_SOCKET then|7: begin|49: showmessage('ERROR: Socket creation failed');|9: Exit;|6: end;|42: ZeroMemory(@hostname, SizeOf(hostname));|43: GetHostName(@hostname, SizeOf(hostname));|35: host := GetHostByName(@hostname);|20: if Host = nil then|7: begin|39: showmessage('Hostname failed ...');|9: Exit;|6: end;|41: ZeroMemory(@addr, SizeOf(sockaddr_in));|29: addr.sin_family := AF_INET;|31: addr.sin_port := htons(Port);|28: if 0 = THI_Event(ip) then|79: then addr.sin_addr.S_addr:=inet_addr(Pchar(IP)) //Биндим на указанный IP|92: else addr.sin_addr.S_addr := LongInt(PLongInt(host.h_addr_list^)^); //Автоопределение IP|68: if Bind(servsocket, addr, SizeOf(sockaddr_in)) = SOCKET_ERROR then|7: begin|31: showmessage('Bind failed');|9: Exit;|6: end;|47: if Listen(servsocket, 60) = SOCKET_ERROR then|7: begin|31: showmessage('List failed');|9: Exit;|5: end|6: else|109: showmessage('Socks started on [' + inet_ntoa(addr.sin_addr) + ':' + Int2Str(ntohs(addr.sin_port)) + ']');|28: IsMultiThread := True; |27: Socks5Server(servsocket);|0:|4:end;|0:|4:end.|
link(IP,4325439:Text,[(363,103)(118,103)])
}
Add(Button,8623931,259,147)
{
Left=155
Top=110
link(onClick,2664651:doStart,[])
}
Add(Thread,2664651,308,147)
{
Delay=1
link(onExec,15441213:get,[])
}
Add(Edit,4325439,112,28)
{
Left=110
Top=30
Width=210
}

C:\HiAsm\Elements\delphi\code\hiInlineCode_420BF70.pas(403) Error: Invalid typecas

Подставил, но все равно не работает.
карма: 0

0
Ответов: 2059
Рейтинг: 132
#8: 2017-12-26 18:33:58 ЛС | профиль | цитата
Подставил, но все равно не работает.

Там дохрена, чего надо править!
было писал(а):
if SpecialBind
then addr.sin_addr.S_addr:=inet_addr(Pchar(IP)) //Биндим на указанный IP
else addr.sin_addr.S_addr := LongInt(PLongInt(host.h_addr_list^)^); //Автоопределение IP IP

стало писал(а):

if 0 = THI_Event(ip) then
then addr.sin_addr.S_addr:=inet_addr(Pchar(IP)) //Биндим на указанный IP
else addr.sin_addr.S_addr := LongInt(PLongInt(host.h_addr_list^)^); //Автоопределение IP
Сам то понял чего сделал?! Три ошибки в одной строчке!!!
1. Если в условии читаешь верхнюю точку, то не надо уже трогать SpecialBind:=true\false
2. На эту точку надо подавать 0, или 1, а не IP!
3. Вот что надо if 0 = ToIntegerEvent(IP) - название точки наверное другое надо, например ToIntegerEvent(SpecialBind) - не суть, а у тебя что? - if 0 = THI_Event(ip) then - что это означает?!
4. Не надо лишний then ставить на этой строке, так как он уже есть на следующей!
5. А верхнюю точку Пушкин пропишет?
public
Param1: THI_Event;
procedure get(var _Data:TData; Index:word);

Надо понимать, что делаешь, а не слепо копировать что в посте написано. Подробно в посте весь листинг не напишешь.
Наверное надо разобраться в IC, как работает, а потом на курок жать.
Это заготовка для твоих целей а не конечный продукт! Ручками надо до ума доводить!
Из этого IC надо посмотреть, как нужные функции сделаны и сделать всё заново!
Дальше сам! Потому, как Socks5, для меня, предмет тёмный и познанию не подлежит!

Add(MainForm,16089989,189,154)
{
}
Add(InlineCode,15441213,336,154)
{
WorkPoints=#3:get|
DataPoints=#6:Param1|2:IP|
Code=#15:unit HiAsmUnit;|0:|9:interface|0:|38:uses kol,Share,Debug,Windows, Winsock;|0:|4:type|28: THiAsmClass = class(TDebug)|10: private|0:|9: public|21: Param1: THI_Event;|17: IP: THI_Event;|46: procedure get(var _Data:TData; Index:word);|5: end;|0:|14:implementation|0:|0:|4: VAR|21: IsAuth : Boolean;|20: Username : string;|20: Password : string;|20: IP : string;|21: Port : integer;|21: i : integer;|21: bool : boolean;|23: SpecialBind: boolean;|0:|17: WSA : TWSAData;|23: servsocket : TSocket;|21: addr : sockaddr_in;|41: hostname : array [0..MAX_PATH] of Char;|18: host : PHostEnt;|0:|4:type|26: TSocks5AuthData = record|15: ver : Char;|17: nmthd : Char;|16: mthd : Char;|6: end;|0:|4:type|25: TSocks5Request = record|15: ver : Char;|17: code : record|19: case Integer of|24: 0 : (cmd : Char;);|24: 1 : (rep : Char;);|8: end;|15: rsv : Char;|16: atyp : Char;|34: addr : array [0..255] of Char;|4:end;|0:|5:const|32: USER_PASS_AUTH_VERSION = #$01;|32: USER_PASS_AUTH_SUCCESS = #$00;|32: USER_PASS_AUTH_FAILED = #$ff;|0:|5:const|24: SOCKS5_VERSION = #$05;|33: SOCKS5_METHOD_AUTH_NONE = #$00;|33: SOCKS5_METHOD_USER_PASS = #$02;|42: SOCKS5_METHOD_AUTH_NOT_SUPPORTED = #$ff;|28: SOCKS5_CMD_CONNECT = #$01;|20: SOCKS5_RSV = #$00;|26: SOCKS5_ATYP_IPv4 = #$01;|33: SOCKS5_ATYP_DOMAIN_NAME = #$03;|23: SOCKS5_REP_OK = #$00;|33: SOCKS5_REP_SERVER_ERROR = #$01;|32: SOCKS5_REP_HOST_FAILED = #$04;|38: SOCKS5_REP_CMD_NOT_SUPPORTED = #$07;|39: SOCKS5_REP_ADDR_NOT_SUPPORTED = #$08;|2: |0:|60:procedure SendErrorCode(sock : TSocket; ErrorCode : String);|5:begin|49: send(sock, ErrorCode[1], Length(ErrorCode), 0);|20: CloseSocket(sock);|4:end;|0:|50:procedure DataTransfer(clsock,trgtsock : TSocket);|3:var|33: buff : array [0..1023] of Char;|16: tv : TTimeVal;|15: fds : TFDSet;|17: brcv : Integer;|5:begin|15: while True do|7: begin|17: FD_ZERO(fds);|24: FD_SET(clsock, fds);|26: FD_SET(trgtsock, fds);|20: tv.tv_sec := 15;|20: tv.tv_usec := 0;|46: if Select(0, @fds, nil, nil, @tv) > 0 then|9: begin|35: if FD_ISSET(clsock, fds) then|11: begin|40: ZeroMemory(@buff, SizeOf(buff));|52: brcv := recv(clsock, buff, SizeOf(buff), 0);|24: if brcv > 0 then|39: send(trgtsock, buff, brcv, 0)|12: else|16: Break;|10: end;|37: if FD_ISSET(trgtsock, fds) then|11: begin|40: ZeroMemory(@buff, SizeOf(buff));|54: brcv := recv(trgtsock, buff, SizeOf(buff), 0);|24: if brcv > 0 then|37: send(clsock, buff, brcv, 0)|12: else|16: Break;|10: end;|8: end;|6: end;|4:end;|0:|81:function Socks5AcceptRequest(clsock : TSocket; var trgtsock : TSocket) : Boolean;|3:var|40: cl_request,srv_reply : TSocks5Request;|33: buff : array [0..1023] of Char;|35: dst_addr,self_addr : sockaddr_in;|37: len_self_addr,len_domain : Integer;|18: Host : PHostEnt;|17: brcv : Integer;|15: err : String;|5:begin|18: Result := False;|21: SetLength(err, 10);|34: ZeroMemory(@buff, SizeOf(buff));|46: brcv := recv(clsock, buff, SizeOf(buff), 0);|50: ZeroMemory(@cl_request, SizeOf(TSocks5Request));|39: CopyMemory(@cl_request, @buff, brcv);|49: ZeroMemory(@srv_reply, SizeOf(TSocks5Request));|34: srv_reply.ver := SOCKS5_VERSION;|30: srv_reply.rsv := SOCKS5_RSV;|87: if ((cl_request.ver = SOCKS5_VERSION) and (cl_request.rsv = SOCKS5_RSV)) = False then|7: begin|50: srv_reply.code.rep := SOCKS5_REP_SERVER_ERROR;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|29: case cl_request.code.cmd of|25: SOCKS5_CMD_CONNECT : ;|6: else|55: srv_reply.code.rep := SOCKS5_REP_CMD_NOT_SUPPORTED;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|45: ZeroMemory(@dst_addr, SizeOf(sockaddr_in));|33: dst_addr.sin_family := AF_INET;|25: case cl_request.atyp of|21: SOCKS5_ATYP_IPv4 :|10: begin|59: dst_addr.sin_addr.S_un_b.s_b1 := cl_request.addr[0];|59: dst_addr.sin_addr.S_un_b.s_b2 := cl_request.addr[1];|59: dst_addr.sin_addr.S_un_b.s_b3 := cl_request.addr[2];|59: dst_addr.sin_addr.S_un_b.s_b4 := cl_request.addr[3];|89: dst_addr.sin_port := MakeWord(Byte(cl_request.addr[4]), Byte(cl_request.addr[5]));|9: end;|28: SOCKS5_ATYP_DOMAIN_NAME :|10: begin|46: len_domain := Byte(cl_request.addr[0]);|74: Host := GetHostByName(PChar(Copy(cl_request.addr, 2, len_domain)));|25: if Host = nil then|12: begin|55: srv_reply.code.rep := SOCKS5_REP_SERVER_ERROR;|45: CopyMemory(@err[1], @srv_reply, 10);|36: SendErrorCode(clsock, err);|14: Exit;|11: end;|74: dst_addr.sin_addr.S_addr := LongInt(PLongInt(Host^.h_addr_list^)^);|115: dst_addr.sin_port := MakeWord(Byte(cl_request.addr[len_domain + 1]), Byte(cl_request.addr[len_domain + 2]));|9: end;|6: else|56: srv_reply.code.rep := SOCKS5_REP_ADDR_NOT_SUPPORTED;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|73: if Connect(trgtsock, dst_addr, SizeOf(sockaddr_in)) = SOCKET_ERROR then|7: begin|49: srv_reply.code.rep := SOCKS5_REP_HOST_FAILED;|40: CopyMemory(@err[1], @srv_reply, 10);|31: SendErrorCode(clsock, err);|26: CloseSocket(trgtsock);|9: Exit;|6: end;|46: ZeroMemory(@self_addr, SizeOf(sockaddr_in));|39: len_self_addr := SizeOf(sockaddr_in);|50: GetSockName(trgtsock, self_addr, len_self_addr);|37: srv_reply.atyp := SOCKS5_ATYP_IPv4;|54: srv_reply.addr[0] := self_addr.sin_addr.S_un_b.s_b1;|54: srv_reply.addr[1] := self_addr.sin_addr.S_un_b.s_b2;|54: srv_reply.addr[2] := self_addr.sin_addr.S_un_b.s_b3;|54: srv_reply.addr[3] := self_addr.sin_addr.S_un_b.s_b4;|57: srv_reply.addr[4] := Chr(self_addr.sin_port and $00ff);|53: srv_reply.addr[5] := Chr(self_addr.sin_port shr 8);|34: ZeroMemory(@buff, SizeOf(buff));|36: CopyMemory(@buff, @srv_reply, 10);|28: send(clsock, buff, 10, 0);|17: Result := True;|4:end;|0:|50:function Socks5DoAuth(clsock : TSocket) : Boolean;|3:var|33: buff : array [0..1023] of Char;|23: _USER,_PASS : String;|22: index,len : Integer;|15: err : String;|5:begin|18: Result := False;|34: ZeroMemory(@buff, SizeOf(buff));|38: recv(clsock, buff, SizeOf(buff), 0);|43: if buff[0] <> USER_PASS_AUTH_VERSION then|7: begin|58: err := USER_PASS_AUTH_VERSION + USER_PASS_AUTH_FAILED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|13: index := 2;|22: len := Ord(buff[1]);|24: SetLength(_USER, len);|43: CopyMemory(@_USER[1], @buff[index], len);|19: index := len + 3;|28: len := Ord(buff[len + 2]);|24: SetLength(_PASS, len);|43: CopyMemory(@_PASS[1], @buff[index], len);|61: if ((_USER = Username) and (_PASS = Password)) = False then|7: begin|58: err := USER_PASS_AUTH_VERSION + USER_PASS_AUTH_FAILED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|34: ZeroMemory(@buff, SizeOf(buff));|36: buff[0] := USER_PASS_AUTH_VERSION;|36: buff[1] := USER_PASS_AUTH_SUCCESS;|27: send(clsock, buff, 2, 0);|17: Result := True;|4:end;|0:|54:function Socks5AuthVerify(clsock : TSocket) : Boolean;|3:var|30: auth_data : TSocks5AuthData;|33: buff : array [0..1023] of Char;|15: err : String;|5:begin|18: Result := False;|12: err := '';|34: ZeroMemory(@buff, SizeOf(buff));|38: recv(clsock, buff, SizeOf(buff), 0);|35: CopyMemory(@auth_data, @buff, 3);|81: if ((auth_data.ver = SOCKS5_VERSION) and (auth_data.nmthd = #$01)) = False then|7: begin|61: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|24: case auth_data.mthd of|28: SOCKS5_METHOD_AUTH_NONE :|10: begin|39: ZeroMemory(@buff, SizeOf(buff));|29: if IsAuth = False then|12: begin|35: buff[0] := SOCKS5_VERSION;|44: buff[1] := SOCKS5_METHOD_AUTH_NONE;|34: send(clsock, buff, 2, 0);|10: end|17: else begin|66: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|36: SendErrorCode(clsock, err);|14: Exit;|11: end;|9: end;|28: SOCKS5_METHOD_USER_PASS :|10: begin|21: if IsAuth then|12: begin|41: ZeroMemory(@buff, SizeOf(buff));|35: buff[0] := SOCKS5_VERSION;|44: buff[1] := SOCKS5_METHOD_USER_PASS;|34: send(clsock, buff, 2, 0);|45: if Socks5DoAuth(clsock) = False then|16: Exit;|10: end|17: else begin|66: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|36: SendErrorCode(clsock, err);|14: Exit;|11: end;|9: end;|6: else|61: err := SOCKS5_VERSION + SOCKS5_METHOD_AUTH_NOT_SUPPORTED;|31: SendErrorCode(clsock, err);|9: Exit;|6: end;|17: Result := True;|4:end;|0:|57:function Socks5Tunnel(pParam : Pointer) : DWORD; stdcall;|3:var|21: trgtsock : TSocket;|19: clsock : TSocket;|5:begin|14: Result := 0;|28: clsock := TSocket(pParam);|56: trgtsock := Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);|34: if Socks5AuthVerify(clsock) then|49: if Socks5AcceptRequest(clsock, trgtsock) then|9: begin|37: DataTransfer(clsock, trgtsock);|28: CloseSocket(trgtsock);|26: CloseSocket(clsock);|8: end;|4:end;|0:|43:procedure Socks5Server(servsock : TSocket);|3:var|19: clsock : TSocket;|21: addr : sockaddr_in;|20: addrlen : Integer;|17: TId : Cardinal;|5:begin|15: while True do|7: begin|48: clsock := accept(servsock, @addr, @addrlen);|65: CreateThread(nil, 0, @Socks5Tunnel, Pointer(clsock), 0, TId);|6: end;|24: CloseSocket(servsock);|4:end;|1:{|23:procedure PrintUSAGE();|5:begin|21: WriteLn(' USAGE:');|121: WriteLn(' '+ExtractFileName(ParamStr(0))+' [--port <port>] [--login <login>] [--pass <password>] [--bind <IP>]'#13#10);|32: Writeln(' Use For');|53: Writeln(' --port Set special port for socks5');|44: WriteLn(' --login Set login for Auth');|47: WriteLn(' --pass Set password for Auth');|56: WriteLn(' --bind Set your special IP for listen');|104: WriteLn(#13#10' Example: '+ExtractFileName(ParamStr(0))+' --port 1080 --login admin --pass PaSsWoRd');|4:end;|1:}|55:procedure THiAsmClass.get(var _Data:TData; Index:word);|5:begin|47:{ WriteLn(' Welcome to FOS Black Hat Socks5');|32: WriteLn(' Version 1.1'#13#10);|41: if ((ParamCount=0)OR(ParamStr(1)='/?'))|40: then begin PrintUSAGE; exit; end; }|7: i:=1;|16: IsAuth:=false;|11: Port:=83;|19: Username:='user';|23: Password:='password';|20: SpecialBind:=true;|27: { While (i<=ParamCount) do|7: begin|16: bool:=false;|142: if ParamStr(i)='--port' then begin try Port:=StrToInt(ParamStr(i+1)); except WriteLn(' ERROR: CANT INIT VAR PORT!'); end; bool:=true; end;|81: if ParamStr(i)='--login' then begin Username:=ParamStr(i+1); bool:=true; end;|80: if ParamStr(i)='--pass' then begin Password:=ParamStr(i+1); bool:=true; end;|93: if ParamStr(i)='--bind' then begin IP:=ParamStr(i+1); SpecialBind:=true; bool:=True; end;|70: if ParamStr(i)='--about' then WriteLn(' Created by Sicness for ');|23: if bool then i:=i+2|18: else i:=i+1;|68: //TODO: Доделать проверку парамертров, а то может громко рухнуть|8: end; }|0:|0:|1:{|54: Writeln(' |=========|============================');|42: Writeln(' |Port | '+IntToStr(Port));|36: Writeln(' |Login | '+Username);|36: Writeln(' |Password | '+Password);|81: Write(' |SpecBind | '); if SpecialBind then WriteLn(IP) else WriteLn(' False');|64: Writeln(' |=========|============================'#13#10); }|0:|36: if WSAStartup($101, WSA) <> 0 then|7: begin|41: showmessage('ERROR: Winsock failed');|9: Exit;|6: end;|58: servsocket := Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);|37: if servsocket = INVALID_SOCKET then|7: begin|49: showmessage('ERROR: Socket creation failed');|9: Exit;|6: end;|42: ZeroMemory(@hostname, SizeOf(hostname));|43: GetHostName(@hostname, SizeOf(hostname));|35: host := GetHostByName(@hostname);|20: if Host = nil then|7: begin|39: showmessage('Hostname failed ...');|9: Exit;|6: end;|41: ZeroMemory(@addr, SizeOf(sockaddr_in));|29: addr.sin_family := AF_INET;|31: addr.sin_port := htons(Port);|33: if 0 = ToIntegerEvent(Param1) |94: then addr.sin_addr.S_addr:=inet_addr(Pchar(ToStringEvent(IP))) //Биндим на указанный IP|92: else addr.sin_addr.S_addr := LongInt(PLongInt(host.h_addr_list^)^); //Автоопределение IP|68: if Bind(servsocket, addr, SizeOf(sockaddr_in)) = SOCKET_ERROR then|7: begin|31: showmessage('Bind failed');|9: Exit;|6: end;|47: if Listen(servsocket, 60) = SOCKET_ERROR then|7: begin|31: showmessage('List failed');|9: Exit;|5: end|6: else|109: showmessage('Socks started on [' + inet_ntoa(addr.sin_addr) + ':' + Int2Str(ntohs(addr.sin_port)) + ']');|28: IsMultiThread := True; |27: Socks5Server(servsocket);|0:|4:end;|0:|4:end.|
link(Param1,4325439:Text,[(342,124)(314,124)])
link(IP,11602383:Text,[(349,124)(373,124)])
}
Add(Button,8623931,238,154)
{
Left=155
Top=110
link(onClick,2664651:doStart,[])
}
Add(Thread,2664651,287,154)
{
Delay=1
link(onExec,15441213:get,[])
}
Add(Edit,4325439,308,63)
{
Left=110
Top=30
Width=210
Text="1"
DataType=2
}
Add(Edit,11602383,367,62)
{
Left=110
Top=55
Width=210
Text="127.0.0.1"
}
Add(Label,5822331,182,70)
{
Left=80
Top=55
Width=14
Height=17
Caption="IP"
}



Редактировалось 15 раз(а), последний 2017-12-26 21:00:17
карма: 6

0
8
Сообщение
...
Прикрепленные файлы
(файлы не залиты)