OpenWrt Forum Archive

Topic: [SOLVE] HACK >>autoconnect any open wps network

The content of this topic has been archived on 21 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello
First off all sorry for my english...
I'm looking to make a script to execute a command
according to that french topic : http://www.crack-wifi.com/forum/topic-1 … tml#p75390
you can look at #7 message.
I'm trying to do the same on my TL-WR1043ND v1 with an alfa awus036NHA connected on usb.
I manage to make working wpa_supplicant with that command:

wpa_supplicant -c /var/run/wpa_supplicant-wlan1.conf -i wlan1

my wpa_supplicant-wlan1.conf look like that :

ctrl_interface=/tmp/run/wpa_supplicant/ 

update_config=1

my /etc/config/network look like that (i add 2 lines):

config interface 'wlan1'
    option _orig_ifname 'wlan1'

i lauch

wpa_cli -i wlan1

without problems : i'm in interactive mode...

But now i'm looking to do a script to execute that command: while : ; do wpa_cli -i wlan1 wps_pbc any ; sleep 120 ; done &

my script is looking like this :

#!/bin/sh

while : ;
do
wpa_cli -i wlan1 wps_pbc any ; sleep 120 ; done & 

but did not work i received a beautiful message : UNKNOWN COMMAND
oh yes i execute the script with the command

ash myscript 

edit : it seem ash does not recognize the command wpa_cli wps_pbc any... is there a way to do it?
we have the option when we are in wpa_cli but wps_pbc is not recognise ... who give the unknow command!!!
could you help me to make it work please?
I'm just beginning in scripting so sorry if you see something really bad wink
thanks in advance

(Last edited by smokeh on 5 Feb 2016, 20:40)

It is pretty hard to understand what you are trying to achieve. Always active wps connectivity?

But in any case, before any advanced scripting, you should start with basics:
make sure that you really do have a working wps setup.

Read https://wiki.openwrt.org/doc/uci/wireless#wps_options
(important to remove wpad-mini, and to install wpad & hostapd-utils)

Your /etc/config/wireless wifi-iface section should have "option wps_pushbutton 1" (for both radios, if you have several).

config wifi-iface
        option device 'radio0'
        option network 'lan'
        option mode 'ap'
        option ssid 'WLANNAME'
        option encryption 'psk2'
        option key 'secretpasword'
        option wps_pushbutton '1'

The correct command is hostapd_cli, not wpa_cli.

My /etc/rc.button/wps as an example how the wps button activates the wps functionality:

root@OpenWrt:/# cat /etc/rc.button/wps
#!/bin/sh

if [ "$ACTION" = "pressed" -a "$BUTTON" = "wps" ]; then
        logger "WPS button pressed, looking for active radios"
        echo "255" > /sys/devices/platform/leds-gpio/leds/netgear:green:wps/brightness
        cd /var/run/hostapd
        for socket in *; do
                [ -S "$socket" ] || continue
                logger "WPS activated for: $socket"
                hostapd_cli -i "$socket" wps_pbc
        done
        sleep 120
        echo "0" > /sys/devices/platform/leds-gpio/leds/netgear:green:wps/brightness
fi

return 0

Then you can attempt from console command line to activate the wps mode. You can manually trigger the wps mode, also also enquire for its status:

root@OpenWrt:/# hostapd_cli -p /var/run/hostapd -i wlan0 wps_get_status
PBC Status: Disabled
Last WPS result: None
root@OpenWrt:/# uptime
 11:22:00 up 23:57,  load average: 0.09, 0.14, 0.12

root@OpenWrt:/# hostapd_cli -p /var/run/hostapd -i wlan0 wps_pbc
OK

root@OpenWrt:/# hostapd_cli -p /var/run/hostapd -i wlan0 wps_get_status
PBC Status: Active
Last WPS result: None

root@OpenWrt:/# uptime
 11:24:09 up 23:59,  load average: 0.09, 0.13, 0.12

root@OpenWrt:/# hostapd_cli -p /var/run/hostapd -i wlan0 wps_get_status
PBC Status: Timed-out
Last WPS result: None

root@OpenWrt:/# hostapd_cli -p /var/run/hostapd -i wlan0 wps_pbc any
OK

root@OpenWrt:/# hostapd_cli -p /var/run/hostapd -i wlan0 wps_get_status
PBC Status: Active
Last WPS result: None

actually i'm looking to do this script to accept any connections of any network when the wps button is pressed by a user.
this script is looking passively to any network and accept straignt away to connect to the opened network when the wps button is press.
easy no???

EDIT: the CLI string of the OPer, wpa_cli -i wlan1 wps_pbc any ; sleep 120 ; done &, is correct. wps_pbc any is a command passed to wpa_cli sub-shell and not intended for the shell.

Excuses offered.

The string works from terminal because wpa_cli expects its input from stdin which is present as wps_pbc any.

I believe the answer is to employ here strings, '<<<'.

i'm using strace to see output of the command : i receive wps_pbc: not found . not sure why... maybe because is not recognise the any... did you try @max hopper?
but anyway thanks guys i will give it a try

(Last edited by smokeh on 31 Jan 2016, 14:21)

Max Hopper wrote:

EDIT: the CLI string of the OPer, wpa_cli -i wlan1 wps_pbc any ; sleep 120 ; done &, is correct. wps_pbc any is a command passed to wpa_cli sub-shell and not intended for the shell.

Excuses offered.

The string works from terminal because wpa_cli expects its input from stdin which is present as wps_pbc any.

I believe the answer is to employ here strings, '<<<'.


I do not understand ... you mean it's possible or not in my script? can i have some more explains ... i'm fucking french so sometime that's not clear for me ...
i tried to modify my script to :  wps_pbc <<< any but does not work ...


I manage to make it work (with command line options) on my raspberry pi ... already got some networks key around home... that's a big hole in security...

but still no luck with the script... if someone could help or help me to resolve that...

(Last edited by smokeh on 1 Feb 2016, 15:54)

By all means, write in French, we can use Google Translate (joke)

The OpenWrt images used here are built with wpad-mini that does not include wpa_cli so testing is not possible.

3.6.7 Here Strings

A variant of here documents, the format is:

<<< word
The word undergoes brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal. Pathname expansion and word splitting are not performed. The result is supplied as a single string to the command on its standard input.

N.B. the redirection operator is written before the string and perhaps the command and data string should be inside quotes.

Max Hopper wrote:

By all means, write in French, we can use Google Translate (joke)

The OpenWrt images used here are built with wpad-mini that does not include wpa_cli so testing is not possible.


N.B. the redirection operator is written before the string and perhaps the command and data string should be inside quotes.

I have wpad-mini and wpa_cli installed on my router.

thanks I just install wpad instead of wpad-mini and... it works
so my script is ok in fact.

(Last edited by smokeh on 5 Feb 2016, 20:30)

The discussion might have continued from here.