Skip to content

Instantly share code, notes, and snippets.

@rnbguy
Last active September 8, 2021 09:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnbguy/6f574caa6b3535162a20750cb1777a09 to your computer and use it in GitHub Desktop.
Save rnbguy/6f574caa6b3535162a20750cb1777a09 to your computer and use it in GitHub Desktop.
bypass WifiCity(CIUP WiFi) Captive Portal
#!/bin/bash
# https://wiki.archlinux.org/index.php/NetworkManager#Captive_portals
# README : make sure these binaries are available on your distribution.
# curl sed
login_wificity() {
# wificity authentication server
authserver="http://10.254.0.254:1000"
# 204 http status code generation url to detect captive portal
# can be any http address, eg. http://neverssl.com
# but change the "$status" != "204" with correct status code
# ref. https://github.com/NickSto/uptest/blob/master/captive-portals.md
gen204="http://www.google.com/gen_204"
# wificity username password
username=$1
password=$2
# grabbing http response to detect captive portal
gen204_resp=$(curl -si "$gen204")
# parsing http status code
status=$(sed -n '1s/^[^\s]\+ \([0-9]\+\)\(\s.*\)\?$/\1/p' <<< "$gen204_resp")
# if http status code is not expected
if [ "$status" != "204" ]; then
# captive portal is detected
# assuming wificity network
# parsing magic code to generate the wificity authentication form
magic=$(sed -n 's/^Location.*?\([a-zA-Z0-9]\+\).*$/\1/p' <<< "$gen204_resp")
# generate the authentication form
curl -so /dev/null "${authserver}/fgtauth?${magic}"
# submit credentials with magic code to wificity server for authentication
curl -so /dev/null "$authserver" --data "magic=${magic}&username=${username}&password=${password}"
fi
}
# change to your correct USERNAME PASSWORD
login_wificity USERNAME PASSWORD
# eg. login_wificity CFB_001 qweRT6YU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment