bash Shell 脚本密码暴力破解

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12614318/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:23:29  来源:igfitidea点击:

Shell script password bruteforcing

linuxbash

提问by user1702184

Hi first of all apologies if this is poorly worded, will try to explain clearly.

嗨,首先很抱歉,如果这措辞不好,将尽力解释清楚。

I have a binary named testpassword, usage is probably fairly explanatory. goes as follows

我有一个名为 testpassword 的二进制文件,用法可能相当有说明性。如下

./testpassword hello

if hello is correctpassword then output will be

如果 hello 是正确的密码,则输出将是

pass=correct

if hello is incorrectpassword, output will be

如果 hello 是不正确的密码,输出将是

pass=incorrect

I'm a complete beginner at Linux and shell scripting but made a very crude + simple script called bruteforce.sh. to perform a 'brute force' attack with a list of words. contents is as follows

我是 Linux 和 shell 脚本的完整初学者,但制作了一个非常粗糙且简单的脚本,称为 bruteforce.sh。使用单词列表执行“蛮力”攻击。内容如下

./testpassword hello
./testpassword jelly
./testpassword watermelon
./testpassword anotherword  
etc..

I ran the following in a new script after quite a bit of goggling for a very rough way to notify me when it's successful

我在一个新脚本中运行了以下内容,经过相当多的思考,以一种非常粗略的方式在成功时通知我

./bruteforce.sh 2 2>&1 >/dev/null | grep -n pass=correct

the output will be something like 12: pass=correct. where 12 is the line number in bruteforce.sh

输出将类似于12: pass=correct. 其中 12 是 bruteforce.sh 中的行号

when I see this on screen I can ctrl-c and run

当我在屏幕上看到这个时,我可以按 ctrl-c 并运行

awk 'NR==12' bruteforce.sh

to get the correct pass corresponding to the line number. I was just wondering if there is an easier or cleaner way to do any part of this

以获得与行号对应的正确传递。我只是想知道是否有更简单或更干净的方法来做这件事的任何部分

Thanks in advance for any suggestions

在此先感谢您的任何建议

采纳答案by nneonneo

Something like this, perhaps.

大概是这样的吧。

for i in {1..1000}; do
    (echo -n "$i: " && ./testpassword $i) | grep pass=correct
done

This just echos the current password before the script output. Of course, {1..1000}can be replaced with the list of words you intend to use.

这只是在脚本输出之前回显当前密码。当然,{1..1000}可以替换为您打算使用的单词列表。