Esempio n. 1
0
        /// <summary>
        /// Load the modules from the first adapter into the Help GUI
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Help_Load(object sender, EventArgs e)
        {
            try
            {
                // grab the first adapter
                NetworkAdapter first_adapter = NetworkAdapter.GetAllAdapters()[0];
                // get it's module list
                list = first_adapter.modules;

                // add it to the box
                for (int i = 0; i < list.Count; ++i)
                {
                    modBox.Items.Insert(i, list.GetModule(i).MetaData.Name);
                }

                // if there's a set idx, set it
                if (selectedItem != null)
                    modBox_SelectedIndexChanged(this, null);
            }
            catch { }
        }
Esempio n. 2
0
        /// <summary>
        /// Load the modules from the first adapter into the Help GUI
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Help_Load(object sender, EventArgs e)
        {
            try
            {
                // grab the first adapter
                NetworkAdapter first_adapter = NetworkAdapter.GetAllAdapters()[0];
                // get it's module list
                list = first_adapter.modules;

                // add it to the box
                for (int i = 0; i < list.Count; ++i)
                {
                    modBox.Items.Insert(i, list.GetModule(i).MetaData.Name);
                }

                // if there's a set idx, set it
                if (selectedItem != null)
                {
                    modBox_SelectedIndexChanged(this, null);
                }
            }
            catch { }
        }
Esempio n. 3
0
        unsafe void ProcessLoop()
        {
            // Allocate and initialize packet structures
            ETH_REQUEST Request = new ETH_REQUEST();
            INTERMEDIATE_BUFFER PacketBuffer = new INTERMEDIATE_BUFFER();

            IntPtr PacketBufferIntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(PacketBuffer));
            try
            {
                win32api.ZeroMemory(PacketBufferIntPtr, Marshal.SizeOf(PacketBuffer));

                Request.hAdapterHandle = adapterHandle;
                Request.EthPacket.Buffer = PacketBufferIntPtr;

                modules = new ModuleList(this);

                modules.LoadExternalModules();

                modules.UpdateModuleOrder();

                string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                folder = folder + System.IO.Path.DirectorySeparatorChar + "firebwall";
                if (!System.IO.Directory.Exists(folder))
                    System.IO.Directory.CreateDirectory(folder);
                folder = folder + System.IO.Path.DirectorySeparatorChar + "pcapLogs";
                if (!System.IO.Directory.Exists(folder))
                    System.IO.Directory.CreateDirectory(folder);
                string f = folder + System.IO.Path.DirectorySeparatorChar + "blocked-" + this.InterfaceInformation.Name + "-" + PcapCreator.Instance.GetNewDate() + ".pcap";
                pcaplog = new PcapFileWriter(f);

                INTERMEDIATE_BUFFER* PacketPointer;

                while (true)
                {
                    hEvent.WaitOne();
                    while (Ndisapi.ReadPacket(hNdisapi, ref Request))
                    {
                        PacketPointer = (INTERMEDIATE_BUFFER*)PacketBufferIntPtr;
                        //PacketBuffer = (INTERMEDIATE_BUFFER)Marshal.PtrToStructure(PacketBufferIntPtr, typeof(INTERMEDIATE_BUFFER));

                        Packet pkt = new EthPacket(PacketPointer).MakeNextLayerPacket();

                        if (pkt.Outbound)
                        {
                            OutBandwidth.AddBits(pkt.Length());
                        }
                        else
                        {
                            InBandwidth.AddBits(pkt.Length());
                        }

                        bool drop = false;
                        bool edit = false;

                        if (enabled)
                        {
                            for (int x = 0; x < modules.Count; x++)
                            {
                                FirewallModule fm = modules.GetModule(x);
                                PacketMainReturn pmr = fm.PacketMain(ref pkt);
                                if (pmr == null)
                                    continue;
                                if ((pmr.returnType & PacketMainReturnType.Log) == PacketMainReturnType.Log && pmr.logMessage != null)
                                {
                                    LogCenter.Instance.Push(pmr);
                                }
                                if ((pmr.returnType & PacketMainReturnType.Drop) == PacketMainReturnType.Drop)
                                {
                                    drop = true;
                                    break;
                                }
                                if ((pmr.returnType & PacketMainReturnType.Edited) == PacketMainReturnType.Edited)
                                {
                                    edit = true;
                                }
                            }
                        }

                        if (!drop)
                        {
                            if (pkt.Outbound)
                                Ndisapi.SendPacketToAdapter(hNdisapi, ref Request);
                            else
                                Ndisapi.SendPacketToMstcp(hNdisapi, ref Request);
                        }
                        else
                            pcaplog.AddPacket(pkt.Data(), (int)pkt.Length());
                    }

                    //OM NOM NOM PASTA!
                    while (processQueue.Count != 0)
                    {
                        Packet pkt = processQueue.Dequeue().MakeNextLayerPacket();

                        if (pkt.Outbound)
                        {
                            OutBandwidth.AddBits(pkt.Length());
                        }
                        else
                        {
                            InBandwidth.AddBits(pkt.Length());
                        }

                        bool drop = false;
                        bool edit = false;

                        if (enabled)
                        {
                            for (int x = 0; x < modules.Count; x++)
                            {
                                FirewallModule fm = modules.GetModule(x);
                                PacketMainReturn pmr = fm.PacketMain(ref pkt);
                                if (pmr == null)
                                    continue;
                                if ((pmr.returnType & PacketMainReturnType.Log) == PacketMainReturnType.Log && pmr.logMessage != null)
                                {
                                    LogCenter.Instance.Push(pmr.Module, pmr.logMessage);
                                }
                                if ((pmr.returnType & PacketMainReturnType.Drop) == PacketMainReturnType.Drop)
                                {
                                    drop = true;
                                    break;
                                }
                                if ((pmr.returnType & PacketMainReturnType.Edited) == PacketMainReturnType.Edited)
                                {
                                    edit = true;
                                }
                            }
                        }

                        if (!drop)
                        {
                            if (pkt.Outbound)
                                Ndisapi.SendPacketToAdapter(hNdisapi, ref Request);
                            else
                                Ndisapi.SendPacketToMstcp(hNdisapi, ref Request);
                        }
                        else
                            pcaplog.AddPacket(pkt.Data(), (int)pkt.Length());
                    }
                    hEvent.Reset();
                }
            }
            catch (Exception tae)
            {
                Marshal.FreeHGlobal(PacketBufferIntPtr);
            }
        }
Esempio n. 4
0
        unsafe void ProcessLoop()
        {
            // Allocate and initialize packet structures
            ETH_REQUEST         Request      = new ETH_REQUEST();
            INTERMEDIATE_BUFFER PacketBuffer = new INTERMEDIATE_BUFFER();

            IntPtr PacketBufferIntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(PacketBuffer));

            try
            {
                win32api.ZeroMemory(PacketBufferIntPtr, Marshal.SizeOf(PacketBuffer));

                Request.hAdapterHandle   = adapterHandle;
                Request.EthPacket.Buffer = PacketBufferIntPtr;

                modules = new ModuleList(this);

                modules.LoadExternalModules();

                modules.UpdateModuleOrder();

                string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                folder = folder + System.IO.Path.DirectorySeparatorChar + "firebwall";
                if (!System.IO.Directory.Exists(folder))
                {
                    System.IO.Directory.CreateDirectory(folder);
                }
                folder = folder + System.IO.Path.DirectorySeparatorChar + "pcapLogs";
                if (!System.IO.Directory.Exists(folder))
                {
                    System.IO.Directory.CreateDirectory(folder);
                }
                string f = folder + System.IO.Path.DirectorySeparatorChar + "blocked-" + this.InterfaceInformation.Name + "-" + PcapCreator.Instance.GetNewDate() + ".pcap";
                pcaplog = new PcapFileWriter(f);

                INTERMEDIATE_BUFFER *PacketPointer;

                while (true)
                {
                    hEvent.WaitOne();
                    while (Ndisapi.ReadPacket(hNdisapi, ref Request))
                    {
                        PacketPointer = (INTERMEDIATE_BUFFER *)PacketBufferIntPtr;
                        //PacketBuffer = (INTERMEDIATE_BUFFER)Marshal.PtrToStructure(PacketBufferIntPtr, typeof(INTERMEDIATE_BUFFER));

                        Packet pkt = new EthPacket(PacketPointer).MakeNextLayerPacket();

                        if (pkt.Outbound)
                        {
                            OutBandwidth.AddBits(pkt.Length());
                        }
                        else
                        {
                            InBandwidth.AddBits(pkt.Length());
                        }

                        bool drop = false;
                        bool edit = false;

                        if (enabled)
                        {
                            for (int x = 0; x < modules.Count; x++)
                            {
                                FirewallModule   fm  = modules.GetModule(x);
                                PacketMainReturn pmr = fm.PacketMain(ref pkt);
                                if (pmr == null)
                                {
                                    continue;
                                }
                                if ((pmr.returnType & PacketMainReturnType.Log) == PacketMainReturnType.Log && pmr.logMessage != null)
                                {
                                    LogCenter.Instance.Push(pmr);
                                }
                                if ((pmr.returnType & PacketMainReturnType.Drop) == PacketMainReturnType.Drop)
                                {
                                    drop = true;
                                    break;
                                }
                                if ((pmr.returnType & PacketMainReturnType.Edited) == PacketMainReturnType.Edited)
                                {
                                    edit = true;
                                }
                            }
                        }

                        if (!drop)
                        {
                            if (pkt.Outbound)
                            {
                                Ndisapi.SendPacketToAdapter(hNdisapi, ref Request);
                            }
                            else
                            {
                                Ndisapi.SendPacketToMstcp(hNdisapi, ref Request);
                            }
                        }
                        else
                        {
                            pcaplog.AddPacket(pkt.Data(), (int)pkt.Length());
                        }
                    }

                    //OM NOM NOM PASTA!
                    while (processQueue.Count != 0)
                    {
                        Packet pkt = processQueue.Dequeue().MakeNextLayerPacket();

                        if (pkt.Outbound)
                        {
                            OutBandwidth.AddBits(pkt.Length());
                        }
                        else
                        {
                            InBandwidth.AddBits(pkt.Length());
                        }

                        bool drop = false;
                        bool edit = false;

                        if (enabled)
                        {
                            for (int x = 0; x < modules.Count; x++)
                            {
                                FirewallModule   fm  = modules.GetModule(x);
                                PacketMainReturn pmr = fm.PacketMain(ref pkt);
                                if (pmr == null)
                                {
                                    continue;
                                }
                                if ((pmr.returnType & PacketMainReturnType.Log) == PacketMainReturnType.Log && pmr.logMessage != null)
                                {
                                    LogCenter.Instance.Push(pmr.Module, pmr.logMessage);
                                }
                                if ((pmr.returnType & PacketMainReturnType.Drop) == PacketMainReturnType.Drop)
                                {
                                    drop = true;
                                    break;
                                }
                                if ((pmr.returnType & PacketMainReturnType.Edited) == PacketMainReturnType.Edited)
                                {
                                    edit = true;
                                }
                            }
                        }

                        if (!drop)
                        {
                            if (pkt.Outbound)
                            {
                                Ndisapi.SendPacketToAdapter(hNdisapi, ref Request);
                            }
                            else
                            {
                                Ndisapi.SendPacketToMstcp(hNdisapi, ref Request);
                            }
                        }
                        else
                        {
                            pcaplog.AddPacket(pkt.Data(), (int)pkt.Length());
                        }
                    }
                    hEvent.Reset();
                }
            }
            catch (Exception tae)
            {
                Marshal.FreeHGlobal(PacketBufferIntPtr);
            }
        }