static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                int bitness;
                if (Environment.Is64BitProcess)
                {
                    bitness = 64;
                }
                else
                {
                    bitness = 32;
                }
                string aa     = "Double Pulsar Detection Tool";
                string myname = $"{aa} - v{Assembly.GetExecutingAssembly().GetName().Version.ToString()} {bitness}bits";
                Console.WriteLine(myname);
                Console.WriteLine("------------------------------------------------");
                Console.WriteLine("Usage: DoublepuslarDetectionCmd.exe ip_address|ip_range --check|--uninstall");
                return(-1);
            }
            string      ip2     = args[0];
            int         counter = 0;
            List <Task> tasks   = new List <Task>();
            string      input   = ip2.Replace(",", " ").Replace(";", " ");
            bool        clean   = (args[1] == "--uninstall");

            foreach (string r in input.Split(null))
            {
                if (string.IsNullOrWhiteSpace(r))
                {
                    continue;
                }
                try {
                    IPRange ips = new IPRange(r);
                    foreach (IPAddress ip in ips.GetAllIP())
                    {
                        Task t = new Task(() => { counter++; Check(ip.ToString(), clean); counter--; });

                        tasks.Add(t);
                        t.Start();
                    }
                } catch (Exception ex) {
                    _l.Warn($"Exception occured for '{r}': {ex.Message}");
                }
            }
            Task.WaitAll(tasks.ToArray());
            return(0);
        }
Beispiel #2
0
        private void Action(bool clean)
        {
            string input = AddressBox.Text.Replace(",", " ").Replace(";", " ");

            foreach (string r in input.Split(null))
            {
                if (string.IsNullOrWhiteSpace(r))
                {
                    continue;
                }
                try {
                    IPRange ips = new IPRange(r);
                    foreach (IPAddress ip in ips.GetAllIP())
                    {
                        new Task(() => { counter++; Check(ip.ToString(), clean); counter--; }).Start();
                    }
                } catch (Exception ex) {
                    _l.Warn($"Exception occured for '{r}': {ex.Message}");
                }
            }
        }
        private void btnStart_Click(object sender, EventArgs e)
        {
            //do checks that is an ip address
            try
            {
                //get mac and replace spaces and ':'
                var MAC = txtMAC.Text;
                MAC = MAC.Replace(" ", String.Empty);
                MAC = MAC.Replace(":", String.Empty);

                var     ipAttack = IPAddress.Parse(txtAttackIp.Text);
                IPRange range    = new IPRange(txtRangeIP.Text);

                //get all the ips
                List <IPAddress> ips = range.GetAllIP();

                foreach (IPAddress t in ips)
                {
                    //get the mac of the attacking ips
                    ARPMAC(t);
                }

                var newIps = macList.Keys;
                ips = newIps.ToList();

                //break them up for the threads
                int size = ips.Count;
                IEnumerator <IPAddress> x = ips.GetEnumerator();

                if (size < 3)
                {
                    smurfThread(ips, ipAttack, MAC);
                    smurfThread(ips, ipAttack, MAC);
                }
                else if (size > 10000)
                {
                    List <IPAddress> ip1  = new List <IPAddress>();
                    List <IPAddress> ip2  = new List <IPAddress>();
                    List <IPAddress> ip3  = new List <IPAddress>();
                    List <IPAddress> ip4  = new List <IPAddress>();
                    List <IPAddress> ip5  = new List <IPAddress>();
                    List <IPAddress> ip6  = new List <IPAddress>();
                    List <IPAddress> ip7  = new List <IPAddress>();
                    List <IPAddress> ip8  = new List <IPAddress>();
                    List <IPAddress> ip9  = new List <IPAddress>();
                    List <IPAddress> ip10 = new List <IPAddress>();
                    int g = 0;
                    for (int i = 0; i < size; i++)
                    {
                        if (g == 10)
                        {
                            g = 0;
                        }
                        if (g == 0)
                        {
                            ip1.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (g == 1)
                        {
                            ip2.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (g == 2)
                        {
                            ip3.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (g == 3)
                        {
                            ip4.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (g == 4)
                        {
                            ip5.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (g == 5)
                        {
                            ip6.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (g == 6)
                        {
                            ip7.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (g == 7)
                        {
                            ip8.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (g == 8)
                        {
                            ip9.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (g == 9)
                        {
                            ip10.Add(x.Current);
                            x.MoveNext();
                        }
                        g++;
                    }

                    //build three threads for each list we split
                    Thread t1  = new Thread(() => smurfThread(ip1, ipAttack, MAC));
                    Thread t2  = new Thread(() => smurfThread(ip2, ipAttack, MAC));
                    Thread t3  = new Thread(() => smurfThread(ip3, ipAttack, MAC));
                    Thread t4  = new Thread(() => smurfThread(ip4, ipAttack, MAC));
                    Thread t5  = new Thread(() => smurfThread(ip5, ipAttack, MAC));
                    Thread t6  = new Thread(() => smurfThread(ip6, ipAttack, MAC));
                    Thread t7  = new Thread(() => smurfThread(ip7, ipAttack, MAC));
                    Thread t8  = new Thread(() => smurfThread(ip8, ipAttack, MAC));
                    Thread t9  = new Thread(() => smurfThread(ip9, ipAttack, MAC));
                    Thread t10 = new Thread(() => smurfThread(ip1, ipAttack, MAC));
                    Thread t11 = new Thread(() => smurfThread(ip2, ipAttack, MAC));
                    Thread t12 = new Thread(() => smurfThread(ip3, ipAttack, MAC));
                    Thread t13 = new Thread(() => smurfThread(ip4, ipAttack, MAC));
                    Thread t14 = new Thread(() => smurfThread(ip5, ipAttack, MAC));
                    Thread t15 = new Thread(() => smurfThread(ip6, ipAttack, MAC));

                    t1.Start();
                    t2.Start();
                    t3.Start();
                    t4.Start();
                    t5.Start();
                    t6.Start();
                    t7.Start();
                    t8.Start();
                    t9.Start();
                    t10.Start();
                    t11.Start();
                    t12.Start();
                    t13.Start();
                    t14.Start();
                    t15.Start();

                    //join them back
                    t1.Join();
                    t2.Join();
                    t3.Join();
                    t4.Join();
                    t5.Join();
                    t6.Join();
                    t7.Join();
                    t8.Join();
                    t9.Join();
                    t10.Join();
                    t11.Join();
                    t12.Join();
                    t13.Join();
                    t14.Join();
                    t15.Join();
                }
                else if (size % 2 == 0)
                {
                    List <IPAddress> ip1 = new List <IPAddress>();
                    List <IPAddress> ip2 = new List <IPAddress>();

                    for (int i = 0; i < size; i++)
                    {
                        if (i < (size / 2))
                        {
                            ip1.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (i < size)
                        {
                            ip2.Add(x.Current);
                            x.MoveNext();
                        }
                    }

                    //build three threads for each list we split
                    Thread t1 = new Thread(() => smurfThread(ip1, ipAttack, MAC));
                    Thread t2 = new Thread(() => smurfThread(ip2, ipAttack, MAC));

                    t1.Start();
                    t2.Start();

                    //join them back
                    t1.Join();
                    t2.Join();
                }

                else if (size % 3 == 0)
                {
                    List <IPAddress> ip1 = new List <IPAddress>();
                    List <IPAddress> ip2 = new List <IPAddress>();
                    List <IPAddress> ip3 = new List <IPAddress>();

                    for (int i = 0; i < size; i++)
                    {
                        if (i < (size / 3))
                        {
                            ip1.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (i < ((size / 3) * 2))
                        {
                            ip2.Add(x.Current);
                            x.MoveNext();
                        }
                        else if (i < size)
                        {
                            ip3.Add(x.Current);
                            x.MoveNext();
                        }
                    }

                    //build three threads for each list we split
                    Thread t1 = new Thread(() => smurfThread(ip1, ipAttack, MAC));
                    Thread t2 = new Thread(() => smurfThread(ip2, ipAttack, MAC));
                    Thread t3 = new Thread(() => smurfThread(ip3, ipAttack, MAC));

                    t1.Start();
                    t2.Start();
                    t3.Start();

                    //join them back
                    t1.Join();
                    t2.Join();
                    t3.Join();
                }

                txtResults.Text = results;
                results         = "";
            } catch (Exception ex)
            {
                txtResults.Text = ex.Message;
                //code for error
            }
        }
Beispiel #4
0
        public IAsyncOperation <IGetResponse> findCameras()
        {
            //Start with finding the host list to parse
            Database.SqliteDB db = new Database.SqliteDB();
            //Get current passwords.
            var validPasswordString = db.GetSetting(new Settings {
                Name = "validCameraPasswords"
            });

            string[] validPassword;
            if (validPasswordString == null)
            {
                validPassword = new string[] { "pass", "adp2013" }
            }
            ;
            else
            {
                validPassword = validPasswordString.Value.Split(new char[] { ',' });
            }
            validPasswordString = null;
            var hosts = db.GetHostLists();

            /// Value is intered like:
            /// IP Start
            /// IP End
            /// Port Start
            /// Port End
            if (hosts.Count == 0)
            {
                return(Task.FromResult <IGetResponse>(new GetResponse(GetResponse.ResponseStatus.OK, hosts)).AsAsyncOperation());
            }

            List <string> connectionUrls = new List <string>();

            foreach (DeviceHostList item in hosts)
            {
                var ips = new IPRange(item.IPRange);
                foreach (IPAddress ip in ips.GetAllIP())
                {
                    var startPort = item.StartPort;
                    while (startPort <= item.EndPort)
                    {
                        connectionUrls.Add(ip.ToString() + ":" + startPort);
                        startPort++;
                    }
                }
            }


            //Ip addresses scoped.
            foreach (string url in connectionUrls)
            {
                foreach (string password in validPassword)
                {
                    Debug.WriteLine(url);
                    AxisVapixLib.Device dev = new AxisVapixLib.Device
                    {
                        Host     = url,
                        Username = "******",
                        Password = password,
                    };
                    dev.CredentialCache = new NetworkCredential("root", password);

                    var valid = ValidateDevice(dev);
                    while (valid.Status != AsyncStatus.Completed)
                    {
                        Task.Delay(10).Wait();
                    }

                    if (valid.GetResults())
                    {
                        //Connection exists. Check if it's an Axis camera.
                        Parameter p = new Parameter(dev);

                        List <AxisParameter> parameters = new List <AxisParameter>();
                        parameters.Add(new AxisParameter()
                        {
                            Name = "Properties.System.SerialNumber"
                        });
                        parameters.Add(new AxisParameter()
                        {
                            Name = "Properties.Firmware.Version"
                        });
                        parameters.Add(new AxisParameter()
                        {
                            Name = "Brand.ProdShortName"
                        });
                        parameters.Add(new AxisParameter()
                        {
                            Name = "Brand.ProdType"
                        });
                        parameters.Add(new AxisParameter()
                        {
                            Name = "Properties.System.Architecture"
                        });



                        Debug.WriteLine("Testing Password " + password);
                        dev.Password = password;
                        bool succeed           = false;
                        var  receivedParameter = GetParameters(p, parameters);
                        while (receivedParameter.Status != AsyncStatus.Completed)
                        {
                            Task.Delay(10).Wait();
                        }
                        if (receivedParameter.GetResults() != null)
                        {
                            DeviceList device = new DeviceList();
                            foreach (AxisParameter Params in receivedParameter.GetResults())
                            {
                                switch (Params.Name)
                                {
                                case "Properties.System.SerialNumber":
                                    device.SerialNumber = Params.Value;
                                    break;

                                case "Properties.Firmware.Version":
                                    device.FirmwareVersion = Params.Value;
                                    break;

                                case "Brand.ProdShortName":
                                    device.Model = Params.Value;
                                    break;

                                case "Properties.System.Architecture":
                                    device.Architecture = Params.Value;
                                    break;

                                case "Brand.ProdType":
                                    device.DeviceType = Params.Value;
                                    break;
                                }
                            }
                            Debug.WriteLine("Password in cache " + dev.CredentialCache.Password);
                            device.Username = dev.CredentialCache.UserName;
                            device.Password = dev.CredentialCache.Password;
                            device.Host     = dev.Host;
                            Debug.WriteLine(string.Format("Found Device: {0} - {1} ({2}) - {3} {4}", device.Model, device.SerialNumber, dev.Host, dev.CredentialCache.UserName, dev.CredentialCache.Password));
                            var dbdevice = db.GetDevice(device);

                            if (dbdevice == null)
                            {
                                //Insert
                                db.SaveDevice(device);
                                Debug.WriteLine(string.Format("Inserting device: {0} {1} {2}", device.SerialNumber, device.Model, device.Host));

                                //Unknown device. Factory default.
                                Debug.WriteLine("Factory defaulting " + device.SerialNumber);
                                Task.Run(() => dev.FactoryDefault(Device.FactoryDefaultMode.Hard));
                            }
                            else
                            {
                                //Update
                                device.ID = dbdevice.ID;
                                db.SaveDevice(device);
                                Debug.WriteLine(string.Format("Updating device: {0} {1} {2}", device.SerialNumber, device.Model, device.Host));
                            }
                            dbdevice = null;
                            succeed  = true;
                        }
                        if (!succeed)
                        {
                            Debug.WriteLine("Could not connect to " + dev.Host);
                        }
                        else
                        {
                            dev.ResetHTTPClient();
                            break;
                        }
                        //TODO ADD Password checking
                        //TODO CREATE TABLE FOR POSSIBLE PASSWORDS
                    }
                    dev.ResetHTTPClient();
                }
                //Reset the HTTP client to allow connections to a new IP.
            }

            /*Debug.WriteLine("Find cameras");
             * AxisVapixLib.Device dev = new AxisVapixLib.Device
             * {
             *  Host = "96.89.207.211:5014",
             *  Username = "******",
             *  Password = "******",
             *
             * };
             *
             * var valid = ValidateDevice(dev);
             * while(valid.Status != AsyncStatus.Completed)
             * {
             *  Task.Delay(1000).Wait();
             * }
             * var result = valid.GetResults();
             *
             * return Task.FromResult<IGetResponse>(new GetResponse(GetResponse.ResponseStatus.OK, result)).AsAsyncOperation();
             * //var test = AsyncInfoFactory Task.FromResult<bool>(dev.ValidateConnect()).AsAsyncOperation<bool>(); //Task.FromResult<bool>(await dev.ValidateConnect()).AsAsyncOperation();
             */
            return(null);
        }
Beispiel #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            var MAC = txtMAC.Text;

            MAC = MAC.Replace(" ", String.Empty);
            MAC = MAC.Replace(":", String.Empty);
            //var ip = IPAddress.Parse(txtIP.Text);
            IPRange range = new IPRange(txtIP.Text);

            //get all the ips
            List <IPAddress> ips = range.GetAllIP();

            foreach (IPAddress ip in ips)
            {
                byte[] packet = new byte[42];

                //set to broadcast
                for (int i = 0; i < 6; i++)
                {
                    packet[i] = Convert.ToByte("ff", 16);
                }

                char[] cMac         = MAC.ToCharArray();
                byte[] convertedMac = new byte[6];

                int g = 6;
                for (int i = 0; i < MAC.Count(); i++)
                {
                    string t = cMac[i] + "" + cMac[i + 1];
                    packet[g]           = Convert.ToByte(t, 16);
                    convertedMac[g - 6] = packet[g];
                    t = convertedMac[g - 6].ToString("X2");
                    i++;
                    g++;
                }
                packet[g++] = Convert.ToByte("08", 16);
                packet[g++] = Convert.ToByte("06", 16);
                packet[g++] = Convert.ToByte("00", 16);
                packet[g++] = Convert.ToByte("01", 16);
                packet[g++] = Convert.ToByte("08", 16);
                packet[g++] = Convert.ToByte("00", 16);
                packet[g++] = Convert.ToByte("06", 16);
                packet[g++] = Convert.ToByte("04", 16);
                packet[g++] = Convert.ToByte("00", 16);
                packet[g++] = Convert.ToByte("02", 16);

                //sender
                packet[g++] = convertedMac[0];
                packet[g++] = convertedMac[1];
                packet[g++] = convertedMac[2];
                packet[g++] = convertedMac[3];
                packet[g++] = convertedMac[4];
                packet[g++] = convertedMac[5];

                byte[] p = ip.GetAddressBytes();

                foreach (byte b in p)
                {
                    packet[g++] = b;
                }

                //target data000c29fbc547

                //set to broadcast
                for (; g < 6; g++)
                {
                    packet[g] = Convert.ToByte("ff", 16);
                }

                byte[] bytes = ip.GetAddressBytes();

                foreach (byte b in bytes)
                {
                    packet[g++] = b;
                }

                frmCapture.device.SendPacket(packet);
            }
        }