public ServerEntity Handle(ServerEntity request1, bool request2, ServerAcceptCallback request3) { return(_repository.ActionResult(x => x.Port == request1.Port, x => { if (x.IsRunning == request2) { throw new Exception($"server running state is already : {x.IsRunning}"); } if (request2) { ProxySocket Socket = new ProxySocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Socket.ProxyEndPoint = new IPEndPoint(IPAddress.Parse("109.248.110.177"), 24532); Socket.ProxyUser = "******"; Socket.ProxyPass = "******"; Socket.ProxyType = ProxyTypes.Socks5; x.Socket = Socket; x.Socket.Bind(new IPEndPoint(IPAddress.Any, x.Port)); x.Socket.Listen(10); x.Socket.BeginAccept(request3.Callback, x.Socket); } else { x.Socket.Dispose(); } x.IsRunning = request2; logger.Info($"server running state : {x.IsRunning}"); return x; })); }
public ProxyEntity Handle(ProxyEntity request1, bool request2, ProxyAcceptCallback request3) { return(_repository.ActionResult(x => x.Port == request1.Port && request1.ProcessId == x.ProcessId, x => { if (x.IsRunning == request2) { throw new Exception($"proxy running state is already : {x.IsRunning}"); } if (request2) { x.Socket.Bind(new IPEndPoint(IPAddress.Any, x.Port)); x.Socket.Listen(10); x.Socket.BeginAccept(request3.Callback, x.Socket); } else { x.Socket.Dispose(); } x.IsRunning = request2; logger.Info($"proxy running state : {x.IsRunning}"); return x; })); }
public HookEntity Handle(ProxyEntity request) { return(_repository.ActionResult(x => x.Port == request.Port, x => { HookElement _hook = x.Hooker.Hook; RemoteHooking.CreateAndInject( x.Hooker.ExePath, string.Empty, 0x00000004, InjectionOptions.DoNotRequireStrongName, "./SocketHook.dll", "./SocketHook.dll", out _hook.ProcessId, _hook.ChannelName, request.Port); while (_hook.ProcessId == 0) { ; } x.ProcessId = _hook.ProcessId; logger.Debug($"Process id : {_hook.ProcessId}"); return x; }).Hooker); }
public ClientEntity Handle(ClientEntity request, ClientConnectCallback request2) { return(_repository.ActionResult(x => x.RemoteIp == request.RemoteIp, x => { if (x.IsRunning) { throw new Exception("client is already connected"); } if (x.RemoteIp is null) { throw new ArgumentNullException(nameof(x.RemoteIp)); } x.Socket.BeginConnect(x.RemoteIp, request2.Callback, x.Socket); DateTime timeout_start = DateTime.Now; while (!x.IsRunning) { if ((DateTime.Now - timeout_start) is TimeSpan diff) { if (diff.TotalMilliseconds > 3000) { return x; // max timeout 3 sec } } } return x; })); }
public ProxyEntity Handle(ProxyEntity proxy, bool active, ProxyAcceptCallback callback) { return(_repository.ActionResult(x => x.Port == proxy.Port && proxy.ProcessId == x.ProcessId, x => { if (x.IsRunning == active) { throw new Exception($"proxy running state is already : {x.IsRunning}"); } if (active) { if (callback is null) { throw new ArgumentNullException(nameof(callback)); } x.Socket.Bind(new IPEndPoint(IPAddress.Any, x.Port)); x.Socket.Listen(10); x.Socket.BeginAccept(callback.Callback, x.Socket); } else { x.Socket.Dispose(); _repository.Remove(v => v.Port == x.Port); } x.IsRunning = active; logger.Info($"proxy running state : {x.IsRunning}"); return x; })); }
public ServerEntity Handle(int port) { return(_repository.ActionResult(x => true, x => { x.Port = port; return x; })); }
/// <summary> /// request1 = processId , request2 = port /// </summary> /// <param name="request1"></param> /// <param name="request2"></param> /// <returns></returns> public ProxyEntity Handle(string exePath, int port) { return(_repository.ActionResult(x => true, x => { x.Port = port; x.HookInterface.OnIpRedirected += (ip, processId, portRed) => { x.IpRedirectedStack.Enqueue(ip); }; x.Hooker = _hook_creator.Handle(exePath, x); return x; })); }
public ClientEntity Handle(ClientEntity request1, Socket request2) { return(_repository.ActionResult(x => x.IsRunning ? x.Socket?.RemoteEndPoint == request1.Socket?.RemoteEndPoint : x.RemoteIp == request1.RemoteIp, x => { if (request1 is null) { throw new ArgumentNullException(nameof(request1)); } if (request2 is null) { throw new ArgumentNullException(nameof(request2)); } x.Socket = request2; return x; })); }
public ClientEntity Handle(ClientEntity request1, ClientReceiveCallback request2) { return(_repository.ActionResult(x => x.IsRunning ? x.Socket.RemoteEndPoint == request1.Socket.RemoteEndPoint : x.RemoteIp == request1.RemoteIp, x => { if (request1 is null) { throw new ArgumentNullException(nameof(request1)); } if (request2 is null) { throw new ArgumentNullException(nameof(request2)); } x.Socket.BeginReceive(request2._buffer, 0, request2._buffer.Length, SocketFlags.None, request2.Callback, x.Socket); return x; })); }
public ClientEntity Handle(ClientEntity request1, byte[] request2) { return(_repository.ActionResult(x => x.IsRunning ? x.Socket.RemoteEndPoint == request1.Socket.RemoteEndPoint : x.RemoteIp == request1.RemoteIp, x => { if (request2 is null) { throw new ArgumentNullException(nameof(request2)); } if (!x.IsRunning) { return x; } x.Socket.BeginSend(request2, 0, request2.Length, SocketFlags.None, new ClientSendCallback(x).Callback, x.Socket); return x; })); }
public ClientEntity Handle(ClientEntity request, ClientConnectCallback request2) { return(_repository.ActionResult(x => x.RemoteIp == request.RemoteIp, x => { if (x.IsRunning) { throw new Exception("client is already connected"); } if (x.RemoteIp is null) { throw new ArgumentNullException(nameof(x.RemoteIp)); } x.Socket.BeginConnect(x.RemoteIp, request2.Callback, x.Socket); return x; })); }
public ClientEntity Handle(IPEndPoint request) { return(_repository.ActionResult(x => true, x => { if (request is null) { throw new ArgumentNullException(nameof(request)); } if (x.IsRunning) { throw new ArgumentException("client is already created"); } x.RemoteIp = request; return x; })); }
public ClientEntity Handle(ClientEntity request) { return(_repository.ActionResult(x => x.IsRunning ? x.Socket.RemoteEndPoint == request.Socket.RemoteEndPoint : x.RemoteIp == request.RemoteIp, x => { if (x is null) { throw new ArgumentNullException(nameof(x)); } logger.Info($"client leaved (was connected ? {x.IsRunning})"); if (!x.IsRunning) { return x; } x.Socket.Disconnect(false); _repository.Remove(c => x == c); x.CurrentToken = ""; return x; })); }
public HookEntity Handle(string exePath, ProxyEntity request) { return(_repository.ActionResult(x => x.Port == request.Port, x => { if (exePath is null || exePath is "") { throw new ArgumentNullException(nameof(exePath)); } if (request is null) { throw new ArgumentNullException(nameof(request)); } x.Hooker = new HookEntity() { ExePath = exePath }; x.Hooker.Hook = HookManager.CreateElement(x.HookInterface); x.Hooker = _hook_injector.Handle(x); return x; }).Hooker);