## 密码列表,空格分隔
pwd_lists="passwd1 passwd2 passwd3 passwd4 passwd5"
## 记录找到的密码
psss_history_file="pwd_history.txt"
funTstPass(){
for pwd_list in ${pwd_lists}
do
sshpass -p ${pwd_list} ssh -o StrictHostKeyChecking=no centos@${test_ip} "exit" || sshpass -p ${pwd_list} ssh -o StrictHostKeyChecking=no root@${test_ip} "exit"
if [ $? -eq 0 ];then
echo -e "\n[ Success ] IP=\"$test_ip\" password=\"${pwd_list}\" "
echo "$test_ip ${pwd_list}" >> ${psss_history_file}
break
else
echo "[ Failure ] password=\"${pwd_list}\""
fi
done
}
cat hostip.txt | while read rows
do
test_ip=$rows
funTstPass
done:
+ pwd_lists="passwd1 passwd2 passwd3 passwd4 passwd5"
+ psss_history_file=pwd_history.txt
+ cat hostip.txt
+ read rows
+ test_ip=10.0.0.50
+ funTstPass
+ for pwd_list in ${pwd_lists}
+ sshpass -p 'passwd1' ssh -o StrictHostKeyChecking=no [email protected] exit
Permission denied, please try again.
+ sshpass -p 'passwd1' ssh -o StrictHostKeyChecking=no [email protected] exit
+ '[' 0 -eq 0 ']'
+ echo -e '\n[ Success ] IP="10.0.0.50" password="passwd1" '
[ Success ] IP="10.0.0.50" password="passwd1"
+ echo '10.0.0.50 passwd1'
+ break
+ read rows
1
proxychains 2022-09-09 11:22:48 +08:00
咋不加公钥
|
2
proxychains 2022-09-09 11:23:03 +08:00
抱歉我答非所问了.
|
3
mango88 2022-09-09 11:37:59 +08:00 1
不是很清楚是什么原因,换一种方式是 OK 的
``` for row in $(cat hostip.txt) do test_ip=$row funTstPass done ``` |
4
wxf666 2022-09-09 11:39:50 +08:00 1
可能 sshpass 有使用你的 stdin 吧
|
5
dbg 2022-09-09 11:42:19 +08:00 1
可能跟 IFS 有关系.提前设置下 IFS.
|
6
runwu2022 2022-09-09 16:21:47 +08:00
现成的工具 hydra ,https://github.com/vanhauser-thc/thc-hydra
|
7
hxy100 2022-09-09 21:58:17 +08:00
你代码里面 funTstPass 函数有一行加了 break ,打断了循环,你把 break 去掉就好了
|
9
hxy100 2022-09-09 22:22:56 +08:00 1
经过测试,原因就是如四楼所言,sshpass 使用你的 stdin ,可以照 3 楼代码改写你读取 txt 文件部分的逻辑,
另外一种办法:也可以简单将你贴出代码的倒数第二行由 funTstPass 改成 funTstPass</dev/null 即可; |
11
panzhc 2022-09-13 20:32:04 +08:00
我一般是这么写的
```sh exec 3<./hostip.txt while read -u 3 line; do test_ip=$line funTstPass done exec 3>&- ``` |