Exemplo n.º 1
0
        private MitmSession ProvideMitm(Input input, IPEndPoint client, IPEndPoint remote)
        {
            Zitm this_obj = this;

            MitmSession rmitm = mitmSessions.GetOrAdd(
                GetKey(client, remote),
                _ => {
                MitmSession mitm = Common.CreateMitmSession(input, this_obj);

                if (input.TlType == TransportLayerType.Udp)
                {
                    Task.Run(() => Traffic.T_UdpReceiver(mitm));
                }

                if (input.TlType == TransportLayerType.Tcp)
                {
                    Task.Run(() => Traffic.T_TcpReceiver(mitm));
                }

                return(mitm);
            }
                );

            return(rmitm);
        }
Exemplo n.º 2
0
        //******************************************************************************//

        public static MitmSession CreateMitmSession(Input input, Zitm zit)
        {
            TransportLayerType tltype = input.TlType;

            if (tltype != TransportLayerType.Tcp && tltype != TransportLayerType.Udp)
            {
                throw new NotImplementedException();
            }

            string stltype = "";

            if (tltype == TransportLayerType.Tcp)
            {
                stltype = "tcp";
            }
            if (tltype == TransportLayerType.Udp)
            {
                stltype = "udp";
            }

            MitmSession ret = new MitmSession();

            ret.tltype  = tltype;
            ret.zit     = zit;
            ret.r_allow = new System.Threading.ManualResetEvent(false);

            if (tltype == TransportLayerType.Tcp)
            {
                ret.client = new IPEndPoint(
                    IPAddress.Parse(input.IPv4_source_ip),
                    input.TCP_source_port);

                ret.remote = new IPEndPoint(
                    IPAddress.Parse(input.IPv4_destination_ip),
                    input.TCP_destination_port);

                Socket     stcp = new Socket(zit._local.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                IPEndPoint ep   = new IPEndPoint(zit._local.Address, 0);
                stcp.Bind(ep);

                ret.local = new IPEndPoint(
                    zit._local.Address,
                    Common.GetPort(stcp));

                ret.binded_socket = stcp;
            }

            if (tltype == TransportLayerType.Udp)
            {
                ret.client = new IPEndPoint(
                    IPAddress.Parse(input.IPv4_source_ip),
                    input.UDP_source_port);

                ret.remote = new IPEndPoint(
                    IPAddress.Parse(input.IPv4_destination_ip),
                    input.UDP_destination_port);

                Socket     sudp = new Socket(zit._local.Address.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
                IPEndPoint ep   = new IPEndPoint(zit._local.Address, 0);
                sudp.Bind(ep);

                ret.local = new IPEndPoint(
                    zit._local.Address,
                    Common.GetPort(sudp));

                ret.binded_socket = sudp;
            }

            ret.workSocket = input.workSocket;

            //***//

            ret.addr_send = new WinDivertAddress();
            ret.addr_send.Reset();
            ret.addr_send.Direction = WinDivertDirection.Outbound;

            ret.addr_recv = new WinDivertAddress();
            ret.addr_recv.Reset();
            ret.addr_recv.Direction = WinDivertDirection.Outbound;

            ret.forward_handle = WinDivert.WinDivertOpen("false", WinDivertLayer.Network, 0, WinDivertOpenFlags.None);

            //***//

            UInt32 ulocal_ip  = Common.IpToUint32(ret.local.Address.ToString());
            UInt32 uremote_ip = Common.IpToUint32(ret.remote.Address.ToString());

            string filter =
                "ip.DstAddr == " + ulocal_ip.ToString() +
                " and ip.SrcAddr == " + uremote_ip.ToString() +
                " and " + stltype + ".DstPort == " + ret.local.Port.ToString() +
                " and " + stltype + ".SrcPort == " + ret.remote.Port.ToString();

            ret.listener_handle = WinDivert.WinDivertOpen(filter, WinDivertLayer.Network, 0, WinDivertOpenFlags.None);
            ret.listener_buffer = new WinDivertBuffer();

            return(ret);
        }
Exemplo n.º 3
0
 public Listener(IPEndPoint server, Zitm zit)
 {
     localEndPoint = server;
     _zit          = zit;
 }