Last active
February 22, 2024 11:18
-
-
Save fnordomat/5f7b14a9bcb0ebfbed2472e573ff4f1b to your computer and use it in GitHub Desktop.
Automatic negotiation of a captive portal: connect to icomera wifi in DB ICE trains (Germany) without having to jump through hoops.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Deutsche Bahn / icomera AB offers "free wifi" (ESSID: "WIFIonICE") with internet access via | |
# mobile networks on some high-speed (ICE) trains. | |
# | |
# This takes care of the WIFIonICE captive portal. | |
# | |
# Please drop me a note if this script is insecure for some reason. It probably is. | |
# | |
DUMMY=http://google.com | |
LOGIN=http://wifionice.de/de | |
DOC=$(mktemp) | |
HDR=$(mktemp) | |
LOG=$(mktemp /tmp/konnektlog.XXXXXXXXXXX) | |
# set a user agent if you like | |
UA='' | |
curl -vsLA "${UA}" -D "${HDR}" -o "${DOC}" "${DUMMY}" --stderr - >> ${LOG} | |
echo "Headers: ${HDR}" | |
CSRFToken=$(cat "${DOC}" | perl -ne '/CSRFToken\" value=\"([a-f0-9]+)\"/ && print $1;') | |
#COOKIE=$(cat "${HDR}" | perl -ne '/^Set-Cookie: (PHPSESSID=[0-9a-z]+;)/ && print "$1";') | |
# something changed | |
COOKIE=$(cat "${HDR}" | perl -ne '/^Set-Cookie: ((?:PHPSESSID)|(?:csrf)=[0-9a-z]+;)/ && print "$1";') | |
LOCATION=$(cat "${HDR}" | perl -ne '/Location: (.*)$/ && print "$1";') | |
echo "$CSRFToken" | |
echo "$COOKIE" | |
echo "$LOCATION" | |
REFERER=http://wifionice.de | |
curl -vLA "${UA}" --post301 --post302 --post303 -e "${REFERER}" "${LOGIN}" -F login=true --form-string CSRFToken="${CSRFToken}" -b "${COOKIE}" --stderr - >> "${LOG}" | |
echo "Log at ${LOG}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment