Skip to content

Instantly share code, notes, and snippets.

@cab404
Last active November 21, 2018 14:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cab404/d3a9dffd43e2448e8593 to your computer and use it in GitHub Desktop.
Save cab404/d3a9dffd43e2448e8593 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script for logging into MosMetro-Free in Moscow Metro
# With last updates to auth.wi-fi.ru - LUL FKN NOOOOBS THEY MADE IT EVEN EASIER
AUTHURL="http://auth.wi-fi.ru/auth?section=metro"
INITURL="http://auth.wi-fi.ru/auth/init?mode=0"
CHECKURL="http://auth.wi-fi.ru/auth/check?segment=metro"
AUTOURL="http://auth.wi-fi.ru/auto_auth?segment=metro"
CAPTCHAURL="http://auth.wi-fi.ru/rucaptcha/"
DT="$HOME/.metrologin"
mkdir $DT 2>/dev/null
FCONF="$DT/curl.conf"
FCOOK="$DT/cookies.txt"
FTOKN="$DT/token.html"
FAAUT="$DT/auto.html"
FCTCH="$DT/captcha.png"
# curl config for metro logins
echo '
user-agent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
referer "http://auth.wi-fi.ru/?segment=metro"
-b "'$FCOOK'"
-c "'$FCOOK'"
-s
header = "Accept-Language: en-GB,ru-RU;q=0.8,ru;q=0.6,en-US;q=0.4,en;q=0.2"
header = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
' > $FCONF
function main() {
if [ ! -f .cookies ]; then
echo "getting initial cookies"
curl $AUTHURL -K $FCONF > /dev/null
fi
echo "getting token"
if [ -x $1 ]; then
curl "$AUTHURL" -K $FCONF > $FTOKN
TOKEN=$( cat $FTOKN | sed 's/>/\n/g' | grep csrf-token | sed 's/.*content=\"//;s/\".*//' )
else
TOKEN=$1
fi
if [[ ! -s $FTOKN ]]; then
echo "it appears we have no connection to server :/"
exit 1
fi
if [[ -z $TOKEN ]]; then
echo "no token found, possibly we failed auto auth check :("
echo "downloading captcha"
curl "$AUTOURL" -D - -K $FCONF > $FAAUT
curl "$CAPTCHAURL" -K $FCONF > $FCTCH
display $FCTCH & read -p "now please enter this craptcha: " CAPTCHA
auth_token=$(cat $FAAUT | sed 's/>/\n/g' | grep authenticity_token | grep -Po '(?<=value=").*(?=")')
aa_body="utf8=%E2%9C%93&authenticity_token="$auth_token"&_rucaptcha=$CAPTCHA"
curl "$AUTOURL" -d $aa_body -H "Content-Type: application/x-www-form-urlencoded" -K $FCONF
main
return
fi
echo "logging with token $TOKEN"
curl "$INITURL" -K $FCONF -d "" -H "X-CSRF-Token: $TOKEN" --referer '$AUTHURL';
echo
echo "running check"
curl "$CHECKURL" -K $FCONF -s
echo
# for the sake of skipping midsession
curl -s http://ya.ru > /dev/null
}
main
@cab404
Copy link
Author

cab404 commented Dec 11, 2015

Теперь в метро всё же проверяют параметр mac, пофиксил. В идеале лучше чтобы url брался из заголовка Location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment