Ejemplo n.º 1
0
        private void BGW_ArpScanListener_DoWork(object sender, DoWorkEventArgs e)
        {
            ArpScanConfig arpScanConfig = null;
            ReplyListener replyListener = null;

            try
            {
                arpScanConfig = this.GetArpScanConfig();
                replyListener = new ReplyListener(arpScanConfig);
            }
            catch (Exception ex)
            {
                LogCons.Inst.Write(LogLevel.Error, $"BGW_ArpScanListener(EXCEPTION1): {ex.Message}");
                return;
            }

            try
            {
                replyListener.AddObserver(this);
                replyListener.StartReceivingArpPackets();
            }
            catch (Exception ex)
            {
                LogCons.Inst.Write(LogLevel.Error, $"BGW_ArpScanListener(EXCEPTION2): {ex.Message}");
                return;
            }

            LogCons.Inst.Write(LogLevel.Info, "BGW_ArpScanListener(): Background worker is started");
        }
Ejemplo n.º 2
0
        private ArpScanConfig GetArpScanConfig()
        {
            var startIp = string.Empty;
            var stopIp  = string.Empty;

            if (this.rb_Netrange.Checked == true)
            {
                startIp = this.tb_Netrange1.Text;
                stopIp  = this.tb_Netrange2.Text;
            }
            else
            {
                startIp = this.tb_Subnet1.Text;
                stopIp  = this.tb_Subnet2.Text;
            }

            ArpScanConfig arpScanConfig = new ArpScanConfig()
            {
                InterfaceId            = this.interfaceId,
                GatewayIp              = this.gatewayIp,
                LocalIp                = this.localIp,
                LocalMac               = this.localMac?.Replace('-', ':'),
                NetworkStartIp         = startIp,
                NetworkStopIp          = stopIp,
                MaxNumberSystemsToScan = -1,
                ObserverClass          = this,
                Communicator           = this.communicator
            };

            return(arpScanConfig);
        }
Ejemplo n.º 3
0
        private ArpScanConfig GetArpScanConfig()
        {
            DataTypes.Struct.MinaryConfig minaryConfig = this.minaryObj.MinaryTaskFacade.CurrentMinaryConfig;
            var tmpStartIpLong = IpHelper.CastIp(minaryConfig.StartIp);
            var tmpStopIpLong  = IpHelper.CastIp(minaryConfig.StopIp);

            // Populate ArpScanConfig object with values
            var arpScanConfig = new ArpScanConfig()
            {
                InterfaceId        = minaryConfig.InterfaceId,
                GatewayIp          = minaryConfig.GatewayIp,
                LocalIp            = minaryConfig.LocalIp,
                LocalMac           = minaryConfig.LocalMac?.Replace('-', ':'),
                NetworkStartIpUint = tmpStartIpLong,
                NetworkStopIpUint  = tmpStopIpLong,
                NetworkStartIp     = minaryConfig.StartIp,
                NetworkStopIp      = minaryConfig.StopIp,
                TotalSystemsToScan = tmpStopIpLong - tmpStartIpLong,
                IsDebuggingOn      = Minary.Common.Debugging.IsDebuggingOn,
//        OnArpScanStopped = this.SetArpScanGuiOnStopped,
//        OnDataReceived
//        StartStopCounter = 0
            };

            return(arpScanConfig);
        }
Ejemplo n.º 4
0
        private void BGW_ArpScanSender_DoWork(object sender, DoWorkEventArgs e)
        {
            ArpScanConfig arpScanConfig = null;
            ArpScanner    arpScanner    = null;

            try
            {
                arpScanConfig = this.GetArpScanConfig();
                arpScanner    = new ArpScanner(arpScanConfig);
            }
            catch (Exception ex)
            {
                LogCons.Inst.Write(LogLevel.Error, $"BGW_ArpScanSender(EXCEPTION): {ex.Message}\r\n{ex.StackTrace}");
                this.SetArpScanGuiOnStopped();
            }

            try
            {
                arpScanner.AddObserverArpRequest(this);
                arpScanner.AddObserverCurrentIp(this);
                arpScanner.StartScanning();
            }
            catch (Exception ex)
            {
                LogCons.Inst.Write(LogLevel.Error, $"BGW_ArpScanSender(EXCEPTION2): {ex.Message}\r\n{ex.StackTrace}");
                this.SetArpScanGuiOnStopped();
                return;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arpConfig"></param>
        public void StartArpScan(ArpScanConfig arpConfig)
        {
            this.arpScanConf = arpConfig;

            if (!File.Exists(this.arpScanBin))
            {
                throw new Exception("ArpScan binary not found");
            }

            this.arpScanProc = new Process();
            this.arpScanProc.StartInfo.FileName        = this.arpScanBin;
            this.arpScanProc.StartInfo.Arguments       = string.Format("{0} {1} {2} -x -v", this.arpScanConf.InterfaceId, this.arpScanConf.NetworkStartIp, this.arpScanConf.NetworkStopIp);
            this.arpScanProc.StartInfo.UseShellExecute = false;
            this.arpScanProc.StartInfo.CreateNoWindow  = this.arpScanConf.IsDebuggingOn ? false : true;
            this.arpScanProc.StartInfo.WindowStyle     = this.arpScanConf.IsDebuggingOn ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden;

            // set up output redirection
            this.arpScanProc.StartInfo.RedirectStandardOutput = true;
            this.arpScanProc.EnableRaisingEvents = true;

            // Set the data received handlers
            this.arpScanProc.OutputDataReceived += this.OnDataRecived;

            // Configure the process exited event
            this.arpScanProc.Exited   += this.OnArpScanExited;
            this.arpScanProc.Disposed += this.OnArpScanExited;

            this.arpScanProc.Start();
            // arpScanProc.BeginErrorReadLine();
            this.arpScanProc.BeginOutputReadLine();

            Thread.Sleep(100);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arpConfig"></param>
        public void StartArpScan(ArpScanConfig arpConfig)
        {
            IPAddress startIp;
            IPAddress stopIp;
            int       startIpInt;
            int       stopIpInt;

            // Validate input parameters.
            if (string.IsNullOrEmpty(arpConfig.InterfaceId))
            {
                throw new Exception("Something is wrong with the interface ID");
            }
            else if (!IPAddress.TryParse(arpConfig.NetworkStartIp, out startIp))
            {
                throw new Exception("Something is wrong with the start IpAddress address");
            }
            else if (!IPAddress.TryParse(arpConfig.NetworkStopIp, out stopIp))
            {
                throw new Exception("Something is wrong with the stop IpAddress address");
            }
            else if (IpHelper.Compare(startIp, stopIp) > 0)
            {
                throw new Exception("Start IpAddress address is greater than stop IpAddress address");
            }

            // If the network system range is above the defined limit change
            // the stop-address to the maximum upper limit.
            startIpInt = IpHelper.IPAddressToInt(startIp);
            stopIpInt  = IpHelper.IPAddressToInt(stopIp);
            if (stopIpInt - startIpInt > arpConfig.MaxNumberSystemsToScan && arpConfig.MaxNumberSystemsToScan > 0)
            {
                int tmpStopIpInt = startIpInt + arpConfig.MaxNumberSystemsToScan;
                arpConfig.NetworkStopIp = IpHelper.IntToIpString(tmpStopIpInt);
            }
        }
Ejemplo n.º 7
0
        //   private static ArpScanner Inst { get { return inst ?? (inst = new ArpScanner()); } set { } }

        #endregion


        #region PUBLIC

        public ArpScanner(ArpScanConfig arpScanConfig)
        {
            char[] separators = { '-', ':', ' ', '.' };
            this.config = arpScanConfig;

            // Byte arrays
            this.localMacBytes = arpScanConfig.LocalMac.Split(separators).Select(s => Convert.ToByte(s, 16)).ToArray();
            this.localIpBytes  = IPAddress.Parse(arpScanConfig.LocalIp).GetAddressBytes();

            // Byte collections
            this.localMacBytesCollection = new ReadOnlyCollection <byte>(this.localMacBytes);
            this.localIpBytesCollection  = new ReadOnlyCollection <byte>(this.localIpBytes);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arpConfig"></param>
        public void StartArpScan(ArpScanConfig arpConfig)
        {
            IPAddress startIp;
            IPAddress stopIp;
            int       startIpInt;
            int       stopIpInt;

            // Validate input parameters.
            if (string.IsNullOrEmpty(arpConfig.InterfaceId))
            {
                throw new Exception("Something is wrong with the interface ID");
            }
            else if (!IPAddress.TryParse(arpConfig.NetworkStartIp, out startIp))
            {
                throw new Exception("Something is wrong with the start IpAddress address");
            }
            else if (!IPAddress.TryParse(arpConfig.NetworkStopIp, out stopIp))
            {
                throw new Exception("Something is wrong with the stop IpAddress address");
            }
            else if (IpHelper.Compare(startIp, stopIp) > 0)
            {
                throw new Exception("Start IpAddress address is greater than stop IpAddress address");
            }

            // If the network system range is above the defined limit change
            // the stop-address to the maximum upper limit.
            startIpInt = IpHelper.IPAddressToInt(startIp);
            stopIpInt  = IpHelper.IPAddressToInt(stopIp);

            if (stopIpInt - startIpInt > arpConfig.TotalSystemsToScan &&
                arpConfig.TotalSystemsToScan > 0)
            {
                uint tmpStopIpInt = (uint)startIpInt + arpConfig.TotalSystemsToScan;
                arpConfig.NetworkStopIp = IpHelper.UIntToIpString(tmpStopIpInt);
            }

// Assign an Update and OnStop function pointers
//arpConfig.OnArpScanStopped = OnArpScanStopped;
            arpConfig.OnReplyDataReceived = this.NotifyArpResponseNewRecord;
            arpConfig.OnRequestSent       = this.NotifyProgressCurrentIp;

            this.infrastructure.StartArpScan(arpConfig);
        }
        private ArpScanConfig GetArpScanConfig()
        {
            DataTypes.Struct.MinaryConfig minaryConfig = this.minaryObj.MinaryTaskFacade.GetCurrentMinaryConfig();
            this.communicator = PcapHandler.Inst.OpenPcapDevice(this.minaryObj.CurrentInterfaceId, 1);

            // ArpScanner
            ArpScanConfig arpScanConfig = new ArpScanConfig()
            {
                InterfaceId            = minaryConfig.InterfaceId,
                GatewayIp              = minaryConfig.GatewayIp,
                LocalIp                = minaryConfig.LocalIp,
                LocalMac               = minaryConfig.LocalMac?.Replace('-', ':'),
                NetworkStartIp         = minaryConfig.StartIp,
                NetworkStopIp          = minaryConfig.StopIp,
                MaxNumberSystemsToScan = -1,
                ObserverClass          = this,
                Communicator           = this.communicator
            };

            return(arpScanConfig);
        }
Ejemplo n.º 10
0
        private ArpScanConfig GetArpScanConfig()
        {
            var startIp = string.Empty;
            var stopIp  = string.Empty;

            if (this.rb_Netrange.Checked == true)
            {
                startIp = this.tb_Netrange1.Text;
                stopIp  = this.tb_Netrange2.Text;
            }
            else
            {
                startIp = this.tb_Subnet1.Text;
                stopIp  = this.tb_Subnet2.Text;
            }

            // Populate ArpScanConfig object with values
            var tmpStartIpLong = IpHelper.CastIp(startIp);
            var tmpStopIpLong  = IpHelper.CastIp(stopIp);

            var arpScanConfig = new ArpScanConfig {
                InterfaceId        = this.interfaceId,
                GatewayIp          = this.gatewayIp,
                LocalIp            = this.localIp,
                LocalMac           = this.localMac?.Replace('-', ':'),
                NetworkStartIpUint = tmpStartIpLong,
                NetworkStopIpUint  = tmpStopIpLong,
                NetworkStartIp     = startIp,
                NetworkStopIp      = stopIp,
                TotalSystemsToScan = tmpStopIpLong - tmpStartIpLong,
                IsDebuggingOn      = Debugging.IsDebuggingOn,
                OnArpScanStopped   = this.SetArpScanGuiOnStopped,
                StartStopCounter   = 0
            };

            return(arpScanConfig);
        }
Ejemplo n.º 11
0
        public void StartArpScan(Action onScanDoneCallback = null)
        {
            // Assign callers "done event". Important! For DSL calls!
            this.onScanDoneCallback   = onScanDoneCallback;
            this.currentArpScanConfig = this.GetArpScanConfig();

            // Initiate ARP scan cancellation
            if (this.IsStopped == false &&
                this.IsCancellationPending == false)
            {
                LogCons.Inst.Write(LogLevel.Info, "ArpScan: Cancelling running ARP scan");
                this.arpScanner.StopArpScan();
            }
            else if (this.IsStopped == false &&
                     this.IsCancellationPending == true)
            {
                LogCons.Inst.Write(LogLevel.Info, "ArpScan: Cancellation running");
            }
            else
            {
                LogCons.Inst.Write(LogLevel.Info, "ArpScan: Starting ArpScan");

                this.cb_SelectAll.Checked = false;

                // Set Progress bar structure
                this.pb_ArpScan.Maximum = 100;
                this.pb_ArpScan.Minimum = 0;
                this.pb_ArpScan.Value   = 0;
                this.pb_ArpScan.Step    = 1;

                // Initialize and start ARP scan background worker
                this.TargetList.Clear();
                this.SetArpScanGuiOnStarted();
                this.bgw_ArpScanSender.RunWorkerAsync();
            }
        }
        private void SimpleGuiUserControl_VisibleChanged(object sender, EventArgs e)
        {
            if (this.Visible == false ||
                this.Disposing == true)
            {
                this.bgw_ArpScanSender.CancelAsync();
                this.bgw_ArpScanListener.CancelAsync();
                this.bgw_RemoveInactiveSystems.CancelAsync();
                this.minaryObj?.MinaryAttackServiceHandler?.StopAllServices();
                LogCons.Inst.Write(LogLevel.Info, "SimpleGuiUserControl/SimpleGuiUserControl_VisibleChanged: SimpleGUI/ARPScan/AttackServices  stopped");

                return;
            }

            // Configure ARP scan object
            //this.arpScanner.Config = this.GetArpScanConfig();
            // Instanciate ARP scanner object
            try
            {
                this.arpScanConfig = this.GetArpScanConfig();
                this.arpScanner    = new ArpScanner(this.arpScanConfig);
            }
            catch (Exception ex)
            {
                LogCons.Inst.Write(LogLevel.Error, $"SimpleGuiUserControl/SimpleGuiUserControl_VisibleChanged(EXCEPTION): {ex.Message}\r\n{ex.StackTrace}");
            }

            try
            {
                this.replyListener = new ReplyListener(this.arpScanConfig);
            }
            catch (Exception ex)
            {
                LogCons.Inst.Write(LogLevel.Error, $"SimpleGuiUserControl/BGW_ArpScanListener(EXCEPTION1): {ex.Message}");
                return;
            }

            try
            {
                this.replyListener.AddObserver(this);
            }
            catch (Exception ex)
            {
                LogCons.Inst.Write(LogLevel.Error, $"SimpleGuiUserControl/BGW_ArpScanListener(EXCEPTION2): {ex.Message}");
                return;
            }

            this.StartArpScanListener();
            this.StartArpScanSender();
            this.StartRemoveInactiveSystems();

            // Make all plugins prepare their environment before the actual attack begins.
            this.minaryObj.PrepareAttackAllPlugins();

            // After the plugins were prepared start all attack services.
            try
            {
                var currentServiceParams = this.GetCurrentServiceParamsConfig();
                this.minaryObj.StartAttackAllServices(currentServiceParams);
            }
            catch (Exception ex)
            {
                LogCons.Inst.Write(LogLevel.Error, $"SimpleGuiUserControl/BGW_ArpScanListener(EXCEPTION3): {ex.Message}");
                return;
            }

            LogCons.Inst.Write(LogLevel.Info, "SimpleGuiUserControl/SimpleGuiUserControl_VisibleChanged: SimpleGUI/ARPScan/AttackServices started");
        }
Ejemplo n.º 13
0
 public ReplyListener(ArpScanConfig arpScanConfig)
 {
     this.arpScanConfig = arpScanConfig;
 }