Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

airmon-ng.linux: in a for loop, replace ls with a glob #2551

Merged
merged 3 commits into from
Jul 19, 2023
Merged

airmon-ng.linux: in a for loop, replace ls with a glob #2551

merged 3 commits into from
Jul 19, 2023

Conversation

wileyhy
Copy link
Contributor

@wileyhy wileyhy commented Jul 10, 2023

The [ -e syntax covers the case of when the glob produces no matches and sh uses the glob pattern itself as a value for "$i".

xtrace comparison:

original

set -x; 
for i in $(ls /sys/class/ieee80211/); do 
  if [ ! -d "/sys/class/ieee80211/${i}/device/net" ]; then 
    MISSING_INTERFACE="${i}"; 
    echo "$MISSING_INTERFACE" :: "$i"; 
  fi; 
done; 
set - 

++ ls --color=auto /sys/class/ieee80211/
+ for i in $(ls /sys/class/ieee80211/)
+ '[' '!' -d /sys/class/ieee80211/phy0/device/net ']'
+ set -

change added

set -x; 
for i in /sys/class/ieee80211/*; do 
  if [ -e "${i}" ] && [ ! -d "${i}/device/net" ]; then 
    MISSING_INTERFACE="${i}"; 
    echo "$MISSING_INTERFACE" :: "$i"; 
  fi; 
done; 
set -

+ for i in /sys/class/ieee80211/*
+ '[' -e /sys/class/ieee80211/phy0 ']'
+ '[' '!' -d /sys/class/ieee80211/phy0/device/net ']'
+ set -

Edit 1: formatting
Edit 2: note re [ -e syntax

xtrace comparison:

# original
[root@localhost-live bug_airmon-ng-email]# set -x; for i in $(ls /sys/class/ieee80211/); do if [ ! -d "/sys/class/ieee80211/${i}/device/net" ]; then echo "$MISSING_INTERFACE" :: "$i"; fi; done; set -
++ ls --color=auto /sys/class/ieee80211/
+ for i in $(ls /sys/class/ieee80211/)
+ '[' '!' -d /sys/class/ieee80211/phy0/device/net ']'
+ set -

# change added
[root@localhost-live bug_airmon-ng-email]# set -x; for i in /sys/class/ieee80211/*; do if [ -e "${i}" ] && [ ! -d "${i}/device/net" ]; then MISSING_INTERFACE="${i}"; echo "$MISSING_INTERFACE" :: "$i"; fi; done; set -
+ for i in /sys/class/ieee80211/*
+ '[' -e /sys/class/ieee80211/phy0 ']'
+ '[' '!' -d /sys/class/ieee80211/phy0/device/net ']'
+ set -
@ZeroChaos-
Copy link
Collaborator

This is a good start, but unfortunately it entirely breaks the function

+ iw phy /sys/class/ieee80211/phy0 interface add wlan0mon type monitor
+ IW_ERROR='command failed: No such file or directory (-2)' 
+ '[' -z 'command failed: No such file or directory (-2)' ']'
+ printf '\n\n ERROR adding %s mode interface: %s\n' monitor 'command failed: No such file or directory (-2)'

Also, please remove the two comments above your change since the comments are suggesting to do exactly what you are trying to do :-)

Copy link
Collaborator

@ZeroChaos- ZeroChaos- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix setting MISSING_INTERFACE to the expected value. You changed the meaning of ${i} but didn't update it's use everywhere

Comments had read...

    #this should be fixed, but it's not going to be right now
    # shellcheck disable=2045

...which referred to...

https://www.shellcheck.net/wiki/SC2045
Fix setting MISSING_INTERFACE to the expected value, from commit e833818.
@wileyhy
Copy link
Contributor Author

wileyhy commented Jul 19, 2023

You're right; thank you. Two fixes have commits up for review.

Copy link
Collaborator

@ZeroChaos- ZeroChaos- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested on zsh, dash, bash, and mksh

Looks great, thanks!

@ZeroChaos-
Copy link
Collaborator

merging, one unrelated check failure

@ZeroChaos- ZeroChaos- merged commit 68f9e13 into aircrack-ng:master Jul 19, 2023
36 of 37 checks passed
@ZeroChaos-
Copy link
Collaborator

thanks @wileyhy

@wileyhy
Copy link
Contributor Author

wileyhy commented Jul 19, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants