Skip to content

Instantly share code, notes, and snippets.

@coraxster
Last active January 25, 2021 08:46
Show Gist options
  • Save coraxster/c5f5ef2cbba970e2c52527462f48ec54 to your computer and use it in GitHub Desktop.
Save coraxster/c5f5ef2cbba970e2c52527462f48ec54 to your computer and use it in GitHub Desktop.
update for AnyConnect 4.*
-- 1. Create a new password entry in Keychain Access called "ExnessLDAP" with your ldap password
-- 2. Create a new password entry in Keychain Access called "Exness2Factor" with your 2factor token
-- 3. Install oath-toolkit. (brew install oath-toolkit)
-- 4. Open this script in Script Editor (both this and the above are in the Applications->Utilities folder) and "Save as.." an Application (.app) with desired name.
-- 5. Open Security & Privacy System Preferences, go to Privacy, Accessibility.
-- 6. Enable the above .app so it can access Accessibility
-- 7. Add the new .app to /Users/[yourshortname]/Applications with a shortcut to your Dock
-- 8. Enjoy the fast connection with no need to enter password and increased security of not having a sensitive password stored as plain text.
set targetApp to "Cisco AnyConnect Secure Mobility Client"
set ExnessLDAPKeyChainKey to "ExnessLDAP"
set Exness2FactorKeyChainKey to "Exness2Factor"
tell application "System Events"
set processExists to exists process targetApp
end tell
if processExists is true then
tell application targetApp
quit
end tell
end if
tell application targetApp
activate
end tell
tell application "System Events"
repeat until (window 1 of process targetApp exists)
delay 1
end repeat
repeat until (window 3 of process targetApp exists)
delay 1
end repeat
tell process targetApp
set PSWD to do shell script "/usr/bin/security find-generic-password -wl " & quoted form of ExnessLDAPKeyChainKey
set Token to do shell script "/usr/bin/security find-generic-password -wl " & quoted form of Exness2FactorKeyChainKey
set PSWD2 to do shell script "/usr/local/bin/oathtool --totp -b -d 6 " & quoted form of Token
keystroke PSWD as text
delay 1
keystroke tab
keystroke PSWD2 as text
keystroke return
end tell
end tell
@coraxster
Copy link
Author

Hope nope. But thanks :)

@dkizilov
Copy link

dkizilov commented Apr 8, 2020

Please consider also this way.
Purely console version, no gui needed

$ cat vpn.sh
#!/bin/bash

#password=***
#token=***
password=`/usr/bin/security find-generic-password -wl "ExnessLDAP"`
token=`/usr/bin/security find-generic-password -wl "Exness2Factor"`

/opt/cisco/anyconnect/bin/vpn disconnect && echo -e "connect vpn.exness.com\n0\n\n$password\n`oathtool --totp -b -d 6 "$token"`" | /opt/cisco/anyconnect/bin/vpn -s

@coraxster
Copy link
Author

Please consider also this way.
Purely console version, no gui needed

$ cat vpn.sh
#!/bin/bash

#password=***
#token=***
password=`/usr/bin/security find-generic-password -wl "ExnessLDAP"`
token=`/usr/bin/security find-generic-password -wl "Exness2Factor"`

/opt/cisco/anyconnect/bin/vpn disconnect && echo -e "connect vpn.exness.com\n0\n\n$password\n`oathtool --totp -b -d 6 "$token"`" | /opt/cisco/anyconnect/bin/vpn -s

👍

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