Created
September 30, 2017 15:25
-
-
Save BigNerd95/830bec47ec760379e16f0fe2de16f8fa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
##### WiIvrea Authentication for OpenWRT #### | |
is_authenticated(){ | |
local res=$(wget -q -O - http://172.172.172.1/login | grep "You are logged in" | wc -l) | |
if [ $res = "1" ] | |
then | |
return 0 # true | |
else | |
return 1 # false | |
fi | |
} | |
# authenticate user pass | |
authenticate(){ | |
local username=$1 | |
local password=$2 | |
echo "Authenticating $username $password" >&1 | |
# get chap_id and chap_challenge | |
local login_data=$(wget -q -O - http://172.172.172.1/login) | |
local id=$(echo "$login_data" | grep chap_id | cut -d '"' -f 6) | |
local challenge=$(echo "$login_data" | grep challenge | cut -d '"' -f 6) | |
# calculate chap_password | |
local md5pass=$(echo -e -n "$id$password$challenge" | md5sum | cut -d ' ' -f 1) | |
# send login request | |
local post="username=$username&password=$md5pass&dst=http%3A%2F%2Fwww.google.it%2F&popup=1" | |
local len=$(echo ${#post}) | |
local login_result=$(echo -e -n "POST /login HTTP/1.1\r\nContent-Length: $len\r\n\r\n$post" | nc 172.172.172.1 80 | grep "You are logged in" | wc -l) | |
if [ $login_result = "1" ] | |
then | |
return 0 # success | |
else | |
return 1 # failure | |
fi | |
} | |
#### main #### | |
if ! is_authenticated | |
then | |
if authenticate $1 $2 | |
then | |
echo "Logged in!" >&1 | |
else | |
echo "Error logging in!" >&1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment