在 C# 中将字符暴力破解到文本框中

发布于 2024-08-27 14:09:25 字数 636 浏览 14 评论 0原文

我想制作一个“测试密码”的程序,看看通过基本的暴力攻击需要多长时间才能破解密码。所以我所做的是制作两个文本框。 (textbox1textbox2)并编写了程序,因此如果文本框有输入,则会出现“正确密码”标签,但我想编写程序以便textbox2 将在其中运行暴力算法,当遇到正确的密码时,它将停止。我真的需要帮助,如果您可以发布我所附的代码,其中包含正确的添加剂,那就太好了。到目前为止,该程序非常简单,但我对此很陌生,所以。

private void textBox2_TextChanged(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{


    if (textBox2.Text == textBox1.Text)
    {
        label1.Text = "Password Correct";
    }
    else
    {
        label1.Text = "Password Wrong";

    }

}


private void label1_Click(object sender, EventArgs e)
{

}

I want to make a program that "test passwords" to see how long they would take to break with a basic brute force attack. So what I did was make 2 text boxes.
(textbox1 and textbox2) and wrote the program so if the text boxes had the input, a "correct password" label would appear, but i want to write the program so that textbox2 will run a brute force algorithm in it, and when it comes across the correct password, it will stop. I REALLY need help, and if you could just post my attached code with the correct additives in it that would be great. The program so far is extremely simple, but I am very new to this, so.

private void textBox2_TextChanged(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{


    if (textBox2.Text == textBox1.Text)
    {
        label1.Text = "Password Correct";
    }
    else
    {
        label1.Text = "Password Wrong";

    }

}


private void label1_Click(object sender, EventArgs e)
{

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

埋葬我深情 2024-09-03 14:09:25

使用这个简单的暴力类来“破解”您的密码。我已将此处的最大尺寸设置为3,因此我不必等待太久。如果你有一整天的时间,就增加这个!

private class BrutePasswordGuesser
{
    private const int MaxAscii = 126;
    private const int MaxSize = 3;
    private const int MinAscii = 33;

    private int _currentLength;

    public BrutePasswordGuesser()
    {
        //Init the length, and current guess array.
        _currentLength = 0;
        CurrentGuess = new char[MaxSize];
        CurrentGuess[0] = (char) MinAscii;
    }

    public char[] CurrentGuess { get; private set; }

    public bool NextGuess()
    {
        if (_currentLength >= MaxSize)
        {
            return false;
        }

        //Increment the previous digit (Uses recursion!)
        IncrementDigit(_currentLength);

        return true;
    }

    /// <summary>
    /// Increment the character at the index by one. If the character is at the maximum 
    /// ASCII value, set it back to the minimum, and increment the previous character.
    /// Use recursion to do this, so that the proggy will step all the way back as needed.
    /// If the very bottom of the string is reached, add another character to the guess.
    /// </summary>
    /// <param name="digitIndex"></param>
    private void IncrementDigit(int digitIndex)
    {
        //Don't fall out the bottom of the array.
        //If we're at the bottom of the array, add another character
        if (digitIndex < 0)
        {
            AddCharacter();
        }
        else
        {
            //If the current character is max ASCII, set to min ASCII, and increment the previous char.
            if (CurrentGuess[digitIndex] == (char) MaxAscii)
            {
                CurrentGuess[digitIndex] = (char) MinAscii;
                IncrementDigit(digitIndex - 1);
            }
            else
            {
                CurrentGuess[digitIndex]++;
            }
        }
    }

    private void AddCharacter()
    {
        _currentLength++;
        //If we've reached our maximum guess size, leave now and don't come back.
        if (_currentLength >= MaxSize)
        {
            return;
        }
        //Initialis as min ASCII.
        CurrentGuess[_currentLength] = (char) (MinAscii);
    }
}

在上面的示例中,使用这样的类:

private void button1_Click(object sender, EventArgs e)
{
    var guesser = new BrutePasswordGuesser();

    var guess = new String(guesser.CurrentGuess);
    while (textBox1.Text != guess)
    {
        textBox2.Text = guess;
        if (!guesser.NextGuess())
        {
            label1.Text = "Maximum guess size reached.";
            break;
        }
        guess = new String(guesser.CurrentGuess);
    }

    if (textBox1.Text == textBox2.Text)
    {
        Label1.Text = "Password Correct";
    }
}

Use this simple, brute force class to 'crack' your password. I've set the maximum size here to 3, so I didn't have to wait too long. Increase this if you've got all day!

private class BrutePasswordGuesser
{
    private const int MaxAscii = 126;
    private const int MaxSize = 3;
    private const int MinAscii = 33;

    private int _currentLength;

    public BrutePasswordGuesser()
    {
        //Init the length, and current guess array.
        _currentLength = 0;
        CurrentGuess = new char[MaxSize];
        CurrentGuess[0] = (char) MinAscii;
    }

    public char[] CurrentGuess { get; private set; }

    public bool NextGuess()
    {
        if (_currentLength >= MaxSize)
        {
            return false;
        }

        //Increment the previous digit (Uses recursion!)
        IncrementDigit(_currentLength);

        return true;
    }

    /// <summary>
    /// Increment the character at the index by one. If the character is at the maximum 
    /// ASCII value, set it back to the minimum, and increment the previous character.
    /// Use recursion to do this, so that the proggy will step all the way back as needed.
    /// If the very bottom of the string is reached, add another character to the guess.
    /// </summary>
    /// <param name="digitIndex"></param>
    private void IncrementDigit(int digitIndex)
    {
        //Don't fall out the bottom of the array.
        //If we're at the bottom of the array, add another character
        if (digitIndex < 0)
        {
            AddCharacter();
        }
        else
        {
            //If the current character is max ASCII, set to min ASCII, and increment the previous char.
            if (CurrentGuess[digitIndex] == (char) MaxAscii)
            {
                CurrentGuess[digitIndex] = (char) MinAscii;
                IncrementDigit(digitIndex - 1);
            }
            else
            {
                CurrentGuess[digitIndex]++;
            }
        }
    }

    private void AddCharacter()
    {
        _currentLength++;
        //If we've reached our maximum guess size, leave now and don't come back.
        if (_currentLength >= MaxSize)
        {
            return;
        }
        //Initialis as min ASCII.
        CurrentGuess[_currentLength] = (char) (MinAscii);
    }
}

In your example above, use the class like this:

private void button1_Click(object sender, EventArgs e)
{
    var guesser = new BrutePasswordGuesser();

    var guess = new String(guesser.CurrentGuess);
    while (textBox1.Text != guess)
    {
        textBox2.Text = guess;
        if (!guesser.NextGuess())
        {
            label1.Text = "Maximum guess size reached.";
            break;
        }
        guess = new String(guesser.CurrentGuess);
    }

    if (textBox1.Text == textBox2.Text)
    {
        Label1.Text = "Password Correct";
    }
}
天荒地未老 2024-09-03 14:09:25

需要更多信息;您是随机猜测密码吗?字典攻击?您是否按顺序猜测密码?对密码中使用的长度/字符集还有哪些其他限制?

我假设您的程序在 UI 中自动调用这些尝试,而不是您作为用户。如果是这样的话,我会放弃 UI 策略并采用控制台实现。

“随机”猜测问题很重要的一个原因是,如果您按顺序猜测,所需的时间长度与您选择的密码直接相关。我不确定您正在寻找什么结果。

More information is needed; are you guessing passwords at random? Dictionary attack? Are you guessing the passwords sequentially? What other constraints on the length/charset used in the password are there?

I'm going to assume your program is invoking these attempts automatically, rather than you as the user, in the UI. If that's the case, I would ditch the UI strategy and go with a console implementation.

A reason why the 'random' guessing question is important is because if you guess sequentially, the length of time it will take is directly related to what password you choose. I'm not sure what result you are looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文