Skip to content

Instantly share code, notes, and snippets.

@Lekensteyn

Lekensteyn/hotel-wifi.sh Secret

Created Sep 16, 2017
Embed
What would you like to do?
Automatically login through the captive portal (as used by Handlery Union Square Hotel SFO)
#!/bin/sh
# Automates login.
# TODO fill this in (free Wi-Fi account)
FIRSTNAME=...
LASTNAME=...
ROOM=123
do_curl() {
#gwaddr=$(ip route show default dev wlan0 | awk '/via/{print $3}')
#if ! [[ "$gwaddr" =~ ^[0-9.]+$ ]]; then
# echo "Invalid IP found: '$gwaddr', failing!"
# return 1
#fi
gwaddr=4.2.2.1
curl -A Mozilla/5.0 \
--resolve login.globalsuite.net:80:$gwaddr \
"$@"
}
process_login() {
do_curl -so /dev/null \
http://login.globalsuite.net/v2/globalnet/ProcessLogin \
-d firstname="$FIRSTNAME" \
-d lastname="$LASTNAME" \
-d companyname="$ROOM" \
-d option=0 \
-d package-value-0=0.00
}
do_login() {
do_curl -so /dev/null \
http://login.globalsuite.net/v2/nonscript/StartSession \
-d accept-submit=I+Accept \
-d lang=
process_login
}
do_renew() {
# Renew followed by Process
do_curl -so /dev/null \
http://login.globalsuite.net/v2/globalnet/RenewLogin \
-d ''
process_login
}
do_logoff() {
# Log off when done (warning: will result in ArrayIndexOufOfBoundsException on
# server when invoking twice...). Oh, and also vulnerable to CSRF WTF.
do_curl \
http://login.globalsuite.net/v2/Logoff?confirm=true
}
get_time() {
secs=$(do_curl -s \
http://login.globalsuite.net/v2/InitPage |
grep -Po 'timer-value#_#AJAX#_#\K\d+' -m1)
if ! [[ $secs =~ ^[0-9]+$ ]]; then
echo "Unknown expirity: '$secs'"
return 2
fi
printf "Remaining time: %02d:%02d:%02d\n" \
$((secs/3600)) \
$((secs/60%60)) \
$((secs%60))
# Fail if it expires too fast.
[[ $secs -ge $((3600*12)) ]]
}
get_time
case $? in
0) # Up-to-date
echo "No need to renew"
;;
1) # Too old
echo "Trying to renew"
do_renew
get_time
;;
2) # Not logged in
echo "Trying to login..."
do_login
get_time
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment