如何使用 nmcli 将暴力破解密码写入 WiFi 脚本?

如何使用 nmcli 将暴力破解密码写入 WiFi 脚本?

以下脚本的目的是在文件中查找正确的密码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.

netssid在哪里。我的 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)?

相关内容