-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathic-hotspot
More file actions
executable file
·175 lines (168 loc) · 6.21 KB
/
ic-hotspot
File metadata and controls
executable file
·175 lines (168 loc) · 6.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#! /bin/bash
# ic-hotspot: a commandline utility to log into PKP InterCity's hotspot network
#
# Copyright (C) 2024-2026 mini_bomba
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
TMPDIR=`mktemp -d`
trap "rm -rf $TMPDIR" EXIT
echo "Making initial http request"
curl --dump-header $TMPDIR/headers0 -o /dev/null http://1.1.1.1
if [[ $? -ne 0 ]];
then
echo "Failed"
exit 1
fi
if grep "https://hotspot.intercity.pl:8443/cc/hotspot_pesa/" $TMPDIR/headers0;
then
HOTSPOT_TYPE=1
DNS_OVERRIDES="hotspot.intercity.pl::10.231.0.1:"
# PORTAL_IP="10.231.0.1"
PORTAL_NAME="hotspot_pesa"
PORTAL_ORIGIN="https://hotspot.intercity.pl:8443"
HTML_QUOTE='"'
echo "Hotspot type: IC PESA"
elif grep "https://hotspot.intercity.pl:8443/cc/hotspot_fps/" $TMPDIR/headers0;
then
HOTSPOT_TYPE=1
DNS_OVERRIDES="hotspot.intercity.pl::10.230.0.1:"
# PORTAL_IP="10.230.0.1"
PORTAL_NAME="hotspot_fps"
PORTAL_ORIGIN="https://hotspot.intercity.pl:8443"
HTML_QUOTE='"'
echo "Hotspot type: IC FPS"
elif grep "http://hotspot.ledatel.pl:8080/cc/hotspot/" $TMPDIR/headers0;
then
HOTSPOT_TYPE=1
DNS_OVERRIDES="hotspot.ledatel.pl::10.240.0.1:"
PORTAL_NAME="hotspot"
PORTAL_ORIGIN="http://hotspot.ledatel.pl:8080"
HTML_QUOTE="'"
echo "Hotspot type: ledatel.pl"
elif grep "portal.passengera.com" $TMPDIR/headers0;
then
HOTSPOT_TYPE=2
DNS_OVERRIDES="portal.passengera.com::172.16.2.2:"
# PORTAL_IP="172.16.2.2"
PORTAL_NAME=""
echo "Hotspot type: portal.passengera.com"
elif grep "hotspot.ente.pl" $TMPDIR/headers0;
then
HOTSPOT_TYPE=3
DNS_OVERRIDES="hotspot.ente.pl::10.5.50.1:"
PORTAL_NAME=""
echo "Hotspot type: hotspot.ente.pl (KD)"
elif grep "http://10.200.0.1:8000/?fas=" $TMPDIR/headers0
then
HOTSPOT_TYPE=4
DNS_OVERRIDES=""
PORTAL_NAME=""
echo "Hotspot type: openNDS"
elif grep "http://www.cdwifi.cz" $TMPDIR/headers0
then
HOTSPOT_TYPE=5
DNS_OVERRIDES="www.cdwifi.cz::10.200.0.1:"
PORTAL_NAME=""
echo "Hotspot type: ČD"
else
echo "Unknown hotspot type"
exit 1
fi
if [[ $HOTSPOT_TYPE -eq 1 ]]
then
curl -L -c $TMPDIR/cookies -b "" --connect-to "$DNS_OVERRIDES" --dump-header $TMPDIR/headers1 -o $TMPDIR/output1 http://1.1.1.1
echo
if [[ $? -ne 0 ]];
then
echo "Failed"
exit 1
fi
if grep "cloudflare" $TMPDIR/headers1 > /dev/null;
then
echo "Already connected!"
exit 1
fi
if grep "404 Not Found" $TMPDIR/headers1 > /dev/null;
then
echo "Got 404, retry"
exit 1
fi
CSRF_TOKEN=`grep "csrfmiddlewaretoken" $TMPDIR/output1 | grep -Po "value=$HTML_QUOTE\\w+" | cut -f 2 -d "$HTML_QUOTE"`
if [[ -z "$CSRF_TOKEN" ]];
then
echo "No CSRF token found";
exit 1
fi
echo "Sending request #2"
curl -L -b $TMPDIR/cookies --connect-to "$DNS_OVERRIDES" -F "csrfmiddlewaretoken=$CSRF_TOKEN" -F "form_type=terms" -F "accept_terms=1" -H "Referer: https://hotspot.intercity.pl:8443" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0" -o $TMPDIR/output2 "$PORTAL_ORIGIN/cc/$PORTAL_NAME/index"
HOST=`grep "host" $TMPDIR/output2 | grep -Po '\d+\.\d+\.\d+\.\d+'`
PORT=`grep "port" $TMPDIR/output2 | grep -Po '\d+'`
CHALLENGE=`grep "challenge" $TMPDIR/output2 | grep -Po '[0-9a-f]{32}'`
USERNAME=`grep "\.logon" $TMPDIR/output2 | cut -d '"' -f 2`
PASSWORD=`grep "\.logon" $TMPDIR/output2 | cut -d '"' -f 4`
echo
if [[ -z "$HOST" ]] || [[ -z "$PORT" ]] || [[ -z "$CHALLENGE" ]] || [[ -z "$USERNAME" ]] || [[ -z "$PASSWORD" ]];
then
echo "Failed to extract challenge data"
exit 1
fi
echo "Sending request #3"
curl --connect-to "$DNS_OVERRIDES" "$PORTAL_ORIGIN/cc/$PORTAL_NAME/_uamservice?username=$USERNAME&password=$PASSWORD&challenge=$CHALLENGE" | tee $TMPDIR/output3
RESPONSE=`cat $TMPDIR/output3`
echo
if [[ -z "$RESPONSE" ]];
then
echo "Failed to extract challenge response"
exit 1
fi
echo "Authenticating..."
curl "http://$HOST:$PORT/json/logon?username=$USERNAME&response=$RESPONSE"
elif [[ $HOTSPOT_TYPE -eq 2 ]]
then
echo "Requesting internet access"
curl --connect-to "$DNS_OVERRIDES" --json '{"category":"internet","bundleId":"default"}' https://portal.passengera.com/api/users
elif [[ $HOTSPOT_TYPE -eq 3 ]]
then
chmod +x $TMPDIR
echo "Fetching md5 library"
curl --connect-to "$DNS_OVERRIDES" -o $TMPDIR/md5.js http://hotspot.ente.pl/md5.js
echo "Fetching login page"
curl --connect-to "$DNS_OVERRIDES" -o $TMPDIR/login.html http://hotspot.ente.pl/login
echo "Extracting password salt"
grep "password.value" $TMPDIR/login.html | grep -Po "'.+'" | sed -e "s/'\\s*+[^']\\+'/kd/" -e 's/.\+/console.log(hexMD5(\0))/' >> $TMPDIR/md5.js
echo "Evaluating script with node.js as nobody"
HASH=`sudo -u nobody node $TMPDIR/md5.js | tr -d '\n'`
echo "Authenticating"
curl --connect-to "$DNS_OVERRIDES" -o /dev/null -d "username=kd" -d "password=$HASH" http://hotspot.ente.pl/login
elif [[ $HOTSPOT_TYPE -eq 4 ]]
then
echo "Acknowledging ToS"
TOKEN="`grep "Location:" $TMPDIR/headers0 | sed 's/.\+fas=//'`" curl -vLo /dev/null --variable %TOKEN --expand-url 'http://10.200.0.1:8000/?fas={{TOKEN:url}}&continue=clicked'
elif [[ $HOTSPOT_TYPE -eq 5 ]]
then
echo "Requesting ToS form"
curl -L --connect-to "$DNS_OVERRIDES" -o $TMPDIR/output1 http://1.1.1.1
TOKEN="`grep "secret" $TMPDIR/output1 | grep -oP 'value="[^"]+"' | grep -oP '"[^"]+"' | sed 's/"//g'`"
echo "Acknowledging ToS"
curl -L --connect-to "$DNS_OVERRIDES" -F "secret=$TOKEN" -F "eula=on" -o /dev/null http://www.cdwifi.cz/api/accept
fi
echo
echo "Checking internet connectivity"
curl --dump-header $TMPDIR/headers4 http://1.1.1.1
if ! grep "cloudflare" $TMPDIR/headers4 > /dev/null;
then
echo "Failed to authenticate!"
exit 1
fi
echo "Done!"