![如何使用 nmcli 将暴力破解密码写入 WiFi 脚本?](https://linux22.com/image/215194/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20nmcli%20%E5%B0%86%E6%9A%B4%E5%8A%9B%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81%E5%86%99%E5%85%A5%20WiFi%20%E8%84%9A%E6%9C%AC%EF%BC%9F.png)
以下脚本的目的是在文件中查找正确的密码list-of-pwds
以便连接到 WiFi。一旦找到正确的密码,就不再寻找该密码。
#!/usr/bin/bash
nmcli d wifi list
echo "Give me the SSID."
read ssid
if [[ -f $HOME/list-of-pwds ]]; then
:
else
>>$HOME/list-of-pwds
fi
echo -e "Place the passwords in $HOME/list-of-pwds.\nPress 'y' when ready to proceed?[Y/n]"
read proceed
if [[ "${proceed}" == 'y' ]]; then
while IFS="" read -u 7 -r l || [[ -n "${l}" ]]; do
nmcli connection add type wifi ifname wlp3s0 ssid "${ssid}" con-name "${ssid}" +802-11-wireless-security.key-mgmt WPA-PSK +802-11-wireless-security.psk "${l}"
if [[ "${?}" -eq 0 ]]; then
echo "Found password for ${ssid}: ${l}."
break
fi
done 7<$HOME/list-of-pwds
fi
#nmcli con show --active seems to return always 0 irrespectively on the connection status
#but nmcli con show --active|grep whatever returns 0 only when there is an active connection
list-of-pwds
看起来像这样:
ana
game
bondage
domination
submission
masochism
thecorrrectPassword
tordfasre
当正确的密码不在第一行时,
list-of-pwds
我得到以下输出:
Error: Failed to add 'net' connection: 802-11-wireless-security.psk: property is invalid
Error: Failed to add 'net' connection: 802-11-wireless-security.psk: property is invalid
Error: Failed to add 'net' connection: 802-11-wireless-security.psk: property is invalid
Connection 'net' (66ab5db1-a662-43a0-bfbe-ee353a7e14d6) successfully added.
Found password for net: domination.
net
ssid在哪里。我的 WiFi 的安全性是 WPA2。当密码长度正确但不正确时, 出现询问密码的弹出窗口。当脚本遇到正确的密码时,不会出现此类弹出窗口,例如,domination
虽然密码长度正确(弹出窗口显示),但不是正确的密码(弹出窗口显示),
thecorrrectPassword
是正确的密码(弹出窗口不显示)。正是这个弹出窗口让我替换nmcli d wifi connect "${ssid}" password "${l}"
了nmcli connection add type wifi ifname wlp3s0 ssid "${ssid}" con-name "${ssid}" +802-11-wireless-security.key-mgmt WPA-PSK +802-11-wireless-security.psk "${l}"
,但问题仍然存在。
按照@tripleee的提示,我尝试将带有密码的文件作为命令行参数传递,我对其进行了修改,使其看起来像这样:
802-11-wireless-security.psk:ana
802-11-wireless-security.psk:game
802-11-wireless-security.psk:bondage
802-11-wireless-security.psk:domination
802-11-wireless-security.psk:submission
802-11-wireless-security.psk:masochism
802-11-wireless-security.psk:thecorrectPassword
802-11-wireless-security.psk:torture
重写脚本:
#!/usr/bin/bash
nmcli d wifi list
echo "Give me the SSID."
read ssid
if [[ -f $HOME/list-of-pwds ]]; then
:
else
>>$HOME/list-of-pwds
fi
echo -e "Place the passwords in $HOME/list-of-pwds.\nReady to proceed?[Y/n]"
read proceed
if [[ "${proceed}" == 'y' ]]; then
nmcli con add type wifi con-name "${ssid}" ssid "${ssid}"
nmcli con mod "${ssid}" wifi-sec.key-mgmt wpa-psk
nmcli connection up "${ssid}" ifname wlp3s0 passwd-file "$HOME/list-of-pwds"
fi
我收到弹出窗口,要求进行身份验证和以下标准输出:
Connection 'net' (dcaab1be-4d54-49f6-ac3b-30bc153806ae) successfully added.
Error: Connection activation failed: Secrets were required, but not provided
Hint: use 'journalctl -xe NM_CONNECTION=dcaab1be-4d54-49f6-ac3b-30bc153806ae + NM_DEVICE=wlp3s0' to get more details.
我知道脚本nmcli
不太可能成为一个好的暴力破解工具。也就是说,我想知道是否可以重写我的脚本,使其行为类似于暴力破解工具。问题分布是否特定(我使用的是 Ubuntu Desktop 22.04 LTS)?