-
Notifications
You must be signed in to change notification settings - Fork 0
/
ic-hotspot
executable file
·105 lines (98 loc) · 3.46 KB
/
ic-hotspot
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
#! /bin/bash
# ic-hotspot: a commandline utility to log into PKP InterCity's hotspot network
#
# Copyright (C) 2024 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
PORTAL_IP="10.231.0.1"
PORTAL_NAME="hotspot_pesa"
echo "Hotspot type: IC PESA"
elif grep "https://hotspot.intercity.pl:8443/cc/hotspot_fps/" $TMPDIR/headers0;
then
HOTSPOT_TYPE=2
PORTAL_IP="10.230.0.1"
PORTAL_NAME="hotspot_fps"
echo "Hotspot type: IC FPS"
else
echo "Unknown hotspot type"
exit 1
fi
curl -L -c $TMPDIR/cookies -b "" --connect-to "hotspot.intercity.pl::$PORTAL_IP:" --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="\w+' | cut -f 2 -d '"'`
if [[ -z "$CSRF_TOKEN" ]];
then
echo "No CSRF token found";
exit 1
fi
echo "Sending request #2"
curl -L -b $TMPDIR/cookies --connect-to "hotspot.intercity.pl::$PORTAL_IP:" -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 "https://hotspot.intercity.pl:8443/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 "hotspot.intercity.pl::$PORTAL_IP:" "http://hotspot.intercity.pl:8080/cc/hotspot_pesa/_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"
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!"