排列生成
今天,我团队的一些成员正在讨论密码存储和一般安全问题。不管怎样,讨论简要讨论了 GPU 加速的暴力攻击与传统的仅 CPU 实现相比有多快。
这引起了我的兴趣,所以我决定尝试一些代码。因为我以前从未写过这样的东西,所以我决定写一个简单的(仅 CPU)暴力破解器。我最初的实现涉及固定长度(4 位数字)密码。出于测试目的,我按照 la 的方式实现了它:
for(char a = '0'; a <= '9'; ++a)
{
for(char b = '0'; b <= '9'; ++b)
{
for(char c = '0'; c <= '9'; ++c)
{
for(char d = '0'; d <= '9'; ++d)
{
candidate[0] = a; candidate[1] = b;
candidate[2] = c; candidate[3] = d;
// Test 'candidate'...
}
}
}
}
这效果很好,但显然不灵活。我试图概括上述内容以处理任何密码长度,但未能做到这一点。出于某种原因,我无法理解这些暴力破解者在给定“字母表”的情况下运行 1-n 个字符可能性的逻辑。
是否有一些通用的算法可以帮助您完成此任务?欢迎任何例子。
Some members of my team were discussing password storage and general security issues today. Anyway, the discussion briefly touched upon how quick GPU-accelerated brute-force attacks are compared to the traditional CPU-only implementations.
This got me interested, so I decided to play around with some code. Since I've never written anything like this before, I decided to write a simple (CPU-only) brute-forcer. My initial implementation dealt with a fixed length (4 digit) password. For testing purposes, I implemented it a la:
for(char a = '0'; a <= '9'; ++a)
{
for(char b = '0'; b <= '9'; ++b)
{
for(char c = '0'; c <= '9'; ++c)
{
for(char d = '0'; d <= '9'; ++d)
{
candidate[0] = a; candidate[1] = b;
candidate[2] = c; candidate[3] = d;
// Test 'candidate'...
}
}
}
}
This works well, but is obviously inflexible. I attempted to generalize the above to handle any password length but have failed to do so. For some reason, I can't get my head around the logic that these brute-forcers use to run through 1-n character possibilities given an "alphabet".
Is there some common algorithm that allows you to accomplish this? Any examples welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
搜索引擎是你的朋友:)
C++ 暴力破解示例
(向下滚动一点..)
Search engines are your friends :)
C++ Brute force example
(Scroll down a little bit..)
这是一个迭代版本......以下仅适用于小写字母,但可以轻松修改......
Here's a Iterative Version....The following works only for lowercase, but can easily be modified....