March 15, 2013

Self-changing Wi-Fi password

I'm totally addicted to coffee, and whenever I see a new coffee shop, I would stop and try their coffee. These days, most coffee shops have free Wi-Fi, and sometimes, it's easy to drink one cup of coffee, and then steal their Wi-Fi permanently since most places don't have the knowledge to change their Wi-Fi password frequently. (Might as well not set a password if you never change the password!)

Presenting... automatic WPA2-PSK password changer for Tomato firmware. Put this little script into the Init script area (Administration -> Scripts -> Init). Now whenever the router reboots, a new password will be generated. You should also put this script either into a schedule so the password can change daily, or preferably, make a schedule to reboot the router daily.

As written the password is based on the current date. If you read the script below, you can see the password is based on a very simple formula: Year x Year x Month x Date, then use only the last eight digits. So if today is March 15, 2013, the password would be 82347605. You can vary the formula, for example, by using %U (week number) instead of %d to change the password weekly, or take out %d to change the password monthly. Just make sure the password is at least eight digits. I prepend the password with 00 in case the generated password is shorter than eight digits. It would be simple to make a spreadsheet with all possible future passwords, or even manually calculate the password.

The delay at the beginning of the scripts waits for the date to be retrieved by NTP. Note that if NTP time can not be retrieved, the Wi-Fi password will be the initial password, which is whatever you saved using the Basic -> Network configuration screen. My configuration is WPA2-PSK, other security types are untested. This script is tested on the ASUS WL500gP (v1 and v2) and the ASUS RT-N16.

You may have to change the nvram line depending on your Wi-Fi chipset if you have another Tomato supported router. The reason I set both wl and wl0 is that I needed both lines to support my notebook and my Android tablet. The wl line for my ThinkPad notebook, and the wl0 line for my Android tablet. If I don't have both lines, then only one device could connect.

Oh yeah, this is not a captive portal since there's no login screen for different users, but rather for changing the Wi-Fi password. As usual, no warranties.

cat > /tmp/ << EOL
while [ \`date +%Y\` -lt 2010 ]
    sleep 10
YY=\`date +%Y\`
MM=\`date +%m\`
DD=\`date +%d\`
WIFIPW=\$(echo "00"\$SUMD | tail -c 9)
nvram set wl_wpa_psk=\$WIFIPW
nvram set wl0_wpa_psk=\$WIFIPW
service net restart
chmod a+x /tmp/
/tmp/ &

Will update this page again when I have time to test if this script also works on the DD-WRT firmware.

No comments: