public DataEventArgs(byte[] buffer, int count, SocksRequest req = null) { //Client = client; Buffer = buffer; Count = count; Offset = 0; Request = req; }
public SocksTunnel(SocksClient p, SocksRequest req, SocksRequest req1, int packetSize, int timeout) { RemoteClient = new Client(new Socket(SocketType.Stream, ProtocolType.Tcp), PacketSize); Client = p; Req = req; ModifiedReq = req1; PacketSize = packetSize; Timeout = timeout; }
public void Start(int PacketSize, int Timeout) { Client.ClientDisconnecting += ClientClientDisconnecting; SocksEncryption w = null; if (Client == null) { this.Dispose(); return; } Authenticated = AuthenticateConnection(ref w); //Request Site Data. if (Authenticated == 1) { w = new SocksEncryption(); w.SetType(AuthTypes.Login); SocksRequest req = Socks5.RequestTunnel(this, w); if (req == null) { Client.Disconnect(); return; } req1 = new SocksRequest(req.StreamType, req.Type, req.Address, req.Port); //call on plugins for connect callbacks. foreach (ConnectHandler conn in PluginLoader.LoadPlugin(typeof(ConnectHandler))) if (conn.Enabled) if (conn.OnConnect(req1) == false) { req.Error = SocksError.Failure; Client.Send(req.GetData(true)); Client.Disconnect(); return; } //Send Tunnel Data back. SocksTunnel x = new SocksTunnel(this, req, req1, PacketSize, Timeout); x.TunnelDisposing += x_TunnelDisposing; x.Open(); } else if (Authenticated == 2) { SocksRequest req = Socks5.RequestTunnel(this, w); if (req == null) { Client.Disconnect(); return; } req1 = new SocksRequest(req.StreamType, req.Type, req.Address, req.Port); if (PluginLoader.LoadPlugin(typeof(ConnectHandler)).Cast<ConnectHandler>().Where(conn => conn.Enabled).Any(conn => conn.OnConnect(req1) == false)) { req.Error = SocksError.Failure; Client.Send(req.GetData(true)); Client.Disconnect(); return; } //Send Tunnel Data back. SocksSpecialTunnel x = new SocksSpecialTunnel(this, w, req, req1, PacketSize, Timeout); x.TunnelDisposing += x_TunnelDisposing; x.Start(); } }
public SocksSpecialTunnel(SocksClient p, SocksEncryption ph, SocksRequest req, SocksRequest req1, int packetSize, int timeout) { RemoteClient = new Client(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), PacketSize); Client = p; Req = req; ModifiedReq = req1; PacketSize = packetSize; Timeout = timeout; se = ph; isDisposing = false; }
public void Dispose() { if (isDisposing) { return; } isDisposing = true; disconnected = true; this.Client = null; this.RemoteClient = null; this.ModifiedReq = null; this.Req = null; }
public static SocksError SendRequest(Client cli, SocksEncryption enc, string ipOrDomain, int port) { AddressType type; IPAddress ipAddress; if (!IPAddress.TryParse(ipOrDomain, out ipAddress)) //it's a domain. :D (hopefully). type = AddressType.Domain; else type = AddressType.IP; SocksRequest sr = new SocksRequest(StreamTypes.Stream, type, ipOrDomain, port); //send data. byte[] p = sr.GetData(false); p[1] = 0x01; //process data. cli.Send(enc.ProcessOutputData(p, 0, p.Length)); byte[] buffer = new byte[512]; //process input data. int recv = cli.Receive(buffer, 0, buffer.Length); if(recv == -1) { return SocksError.Failure; } byte[] buff = enc.ProcessInputData(buffer, 0, recv); return (SocksError)buff[1]; }
/// <summary> /// Override the connection, to do whatever you want with it. Client is a wrapper around a socket. /// </summary> /// <param name="sr">The original request params.</param> /// <returns></returns> public abstract Client OnConnectOverride(SocksRequest sr);
/// <summary> /// Handle request callback. /// </summary> /// <param name="Request"></param> /// <returns>Return true to allow the connection, return false to deny it.</returns> public abstract bool OnConnect(SocksRequest Request);
public void Start(int PacketSize, int Timeout) { Client.ClientDisconnecting += ClientClientDisconnecting; SocksEncryption w = null; if (Client == null) { this.Dispose(); return; } Authenticated = AuthenticateConnection(ref w); //Request Site Data. if (Authenticated == 1) { w = new SocksEncryption(); w.SetType(AuthTypes.Login); SocksRequest req = Socks5.RequestTunnel(this, w); if (req == null) { Client.Disconnect(); return; } req1 = new SocksRequest(req.StreamType, req.Type, req.Address, req.Port); //call on plugins for connect callbacks. foreach (ConnectHandler conn in PluginLoader.LoadPlugin(typeof(ConnectHandler))) { if (conn.Enabled) { if (conn.OnConnect(req1) == false) { req.Error = SocksError.Failure; Client.Send(req.GetData(true)); Client.Disconnect(); return; } } } //Send Tunnel Data back. SocksTunnel x = new SocksTunnel(this, req, req1, PacketSize, Timeout); x.TunnelDisposing += x_TunnelDisposing; x.Open(); } else if (Authenticated == 2) { SocksRequest req = Socks5.RequestTunnel(this, w); if (req == null) { Client.Disconnect(); return; } req1 = new SocksRequest(req.StreamType, req.Type, req.Address, req.Port); if (PluginLoader.LoadPlugin(typeof(ConnectHandler)).Cast <ConnectHandler>().Where(conn => conn.Enabled).Any(conn => conn.OnConnect(req1) == false)) { req.Error = SocksError.Failure; Client.Send(req.GetData(true)); Client.Disconnect(); return; } //Send Tunnel Data back. SocksSpecialTunnel x = new SocksSpecialTunnel(this, w, req, req1, PacketSize, Timeout); x.TunnelDisposing += x_TunnelDisposing; x.Start(); } }
public void Dispose() { if (Client != null) { Client.Disconnect(); } Client = null; req1 = null; }