Skip to content

Commit

Permalink
Merge branch 'mac'. Resolves #2
Browse files Browse the repository at this point in the history
  • Loading branch information
falkecarlsen committed Mar 15, 2019
2 parents ec2a0a2 + 000f1ce commit 700db47
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 44 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# chwifi
This tool automates network-switching for users who connect wirelessly at home and at a workplace employing a rolling-password model for their wireless networks by automatically configuring network profiles according to locally cached passwords.
This tool automates network-switching for users who connect wirelessly at home and at a workplace employing a rolling-password model for their wireless networks by automatically configuring network profiles according to locally cached passwords. Device-specific bytes of MAC-address are randomised during each connection routine.

Through scripting CAS-login, downloading currently available passwords, caching them locally, and matching daily password with given date, automatic network-manager profile configuration is achieved for following days specified by service.
In the case of Aalborg University; if `chwifi` has been invoked within the previous three days, the current daily password will be cached and available for automatic configuration, thus ensuring no manual input for consecutive five-day workweeks.
Expand Down Expand Up @@ -32,6 +32,11 @@ network_manager_home_profile="home"
network_manager_work_profile="work"
```

Options for macchanger, `-e` is default, which randomises only device-specific bytes and retains vendor-information.
```shell
macchanger_options="-e"
```

Settings for `passwordhandler.sh`, edit if other CAS-destination or temp-filenames are desired.
```shell
dest="https://wifipassword.aau.dk/oneday"
Expand Down Expand Up @@ -73,8 +78,9 @@ Example shows call from another directory, with work keyword, printing cached pa
user@hostname ~> projects/chwifi/chwifi work
Work-keyword found, checking for cached password
Daily work password is: amount42wind
Disconnecting from home (profile: home)
Connecting to work (profile: work)
Disconnecting from profile: home
New MAC-address: 00:1a:e9:cb:55:ef
Connecting to profile: work
Waiting for network connection...
Connection took: 5.293s
Network connection established, updating cached passwords
Expand All @@ -92,4 +98,5 @@ Following lists dependencies with most recently tested version of commands appen
- `perl` `rev5 v28 subv1` required for regex search and replace
- `curl` `v7.64.0` required for accessing CAS-secured password-list and testing for network connection
- `libxml` `v1.8.17-1` supplies `xmllint` which is required for parsing resulting password-page html
- `macchanger` `1.7.0` required for MAC-address spoofing

65 changes: 26 additions & 39 deletions chwifi
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,27 @@ source passwordhandler.sh
# source config for user-specific variables
source config

# quick functions for home/work actions on network manager
disconnect_home() {
printf '%s\n' "Disconnecting from home (profile: $network_manager_home_profile)"
$sudo $network_manager $network_manager_disconnect $network_manager_home_profile
}

connect_home() {
printf '%s\n' "Connecting to home (profile: $network_manager_home_profile)"
$sudo $network_manager $network_manager_connect $network_manager_home_profile
}

disconnect_work() {
printf '%s\n' "Disconnecting from work (profile: $network_manager_work_profile)"
$sudo $network_manager $network_manager_disconnect $network_manager_work_profile
}

connect_work() {
printf '%s\n' "Connecting to work (profile: $network_manager_work_profile)"
$sudo $network_manager $network_manager_connect $network_manager_work_profile
}

connect() {
printf '%s\n' "Connecting to $1"
printf '%s\n' "Connecting to profile: $1"
$sudo $network_manager $network_manager_connect $1
}

disconnect() {
printf '%s\n' "Disconnecting from profile: $1"
$sudo $network_manager $network_manager_disconnect $1
}
# safely kill adapter between profiles to ensure smooth dis- and connection, also print ip link status
set_adapter_down() {
$sudo ip link set $wireless_adapter down
}

print_adapter_status() {
ip link | grep $wireless_adapter
# disconnect and connect routine, takes disconnect profile as first parameter, and connect profile as second
connection_routine() {
disconnect $1
set_adapter_down
change_mac
connect $2
update_routine
}

# perl regex; find "Key=" and replace all chars after, on given line, with parameter $2, do this on file at $1
Expand Down Expand Up @@ -72,6 +60,12 @@ update_routine() {
update_passwords
}

# change MAC-address according to sourced options and print new MAC-address
change_mac() {
printf "New MAC-address: "
$sudo macchanger $macchanger_options $wireless_adapter | grep New | grep -o '\(\([0-9a-f]\{2\}\):\)\{5\}[0-9a-f]\{2\}'
}

display_help() {
printf "chwifi is released under GPL-2.0 and comes with ABSOLUTELY NO WARRANTY, for details read LICENSE\n\n"
printf "Usage: ./chwifi <profile>\n"
Expand All @@ -89,11 +83,8 @@ elif [[ $# -eq 1 ]]; then
# if home, then connect and update cached passwords when connection is given
if [[ "$1" =~ home ]]; then
printf '%s\n' "Home-keyword found, connecting to home"
disconnect_work
set_adapter_down
connect_home
update_routine

connection_routine $network_manager_work_profile $network_manager_home_profile

# if work, then find password, connect and update cached passwords when connection is given
elif [[ "$1" =~ work ]]; then
printf '%s\n' "Work-keyword found, checking for cached password"
Expand All @@ -108,22 +99,18 @@ elif [[ $# -eq 1 ]]; then
# print daily password, if found
printf '%s\n' "Daily work password is: $daily_password"
fi

# perform connection routine
disconnect_home
set_adapter_down

# change work profile password and do connection routine
change_profile_password $network_manager_work_profile $daily_password
connect_work
update_routine
connection_routine $network_manager_home_profile $network_manager_work_profile

# if alpha, num, alpha regex, then work password
elif [[ "$1" =~ $password_syntax ]]; then
printf '%s\n' "Connecting to work with given password: $1"
disconnect_home
set_adapter_down
# change work profile password and do connection routine
change_profile_password $network_manager_work_profile $daily_password
connect_work
update_routine
connection_routine $network_manager_home_profile $network_manager_work_profile
else
printf '%s\n' "$1 doesn't seem to be an work password, please check"
fi
Expand Down
8 changes: 6 additions & 2 deletions config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Configuration for chwifi. Note that this file contains your credentials in plaintext, be careful with whom and what you allow to read this file, no responsibility is taken by author for any issues, security or otherwise. Please refer to the README.md for further information and license information.
# Configuration for chwifi. Note that this file contains your credentials in plaintext, be careful with whom and what you allow to read this file.
# No responsibility is taken by author for any issues, security or otherwise. Please refer to the README.md for further information and license information.

# Host to ping for network connection test. Set to organisations homepage, since if network is restricted to organisation's local network and password-portal is still available, update of local cache is still possible during outage of public network access.
# Host to ping for network connection test. Set to work organisations homepage, since if network is restricted to organisation's local network and password-portal is still available,# update of local cache is still possible during outage of public network access.
network_up_host="aau.dk"

# Credentials for CAS-authentication system.
Expand All @@ -22,6 +23,9 @@ network_manager_disconnect="stop"
network_manager_home_profile="home"
network_manager_work_profile="work"

# Options for macchanger, -e, which randomises only device-specific bytes
macchanger_options="-e"

# Settings for passwordhandler, edit for other CAS-destination, if desired.
dest="https://wifipassword.aau.dk/oneday"
password_html_file="passwords.html"
Expand Down

0 comments on commit 700db47

Please sign in to comment.