Skip to content

Instantly share code, notes, and snippets.

@davidecavestro
Created April 5, 2018 13:10
Show Gist options
  • Save davidecavestro/5c9becd69fbef0f28553bbbadc1befaa to your computer and use it in GitHub Desktop.
Save davidecavestro/5c9becd69fbef0f28553bbbadc1befaa to your computer and use it in GitHub Desktop.
Validate vpn user credentials using `openconnect` command from groovy
/*
* Uses `openconnect` to validate vpn user credentials
* (tested on Debian GNU/Linux 9, where openconnect must be called as root user)
*/
credentials = [ //TODO set credentials here
user1 : 'pass1',
user2 : 'pass2'
]
def host = '127.0.0.1' //TODO set vpn server address here
def args = '' //TODO add optional args, i.e. '--mtu=1300 --servercert sha256:abcde...'
def valid = []
def invalid = []
print 'Checking credentials'
credentials.each {def user, def password->
def process = "echo -n $password".execute() | "/usr/sbin/openconnect -u ${user} ${args} --passwd-on-stdin ${host}".execute()
process.waitForOrKill (1000) //wait 1 sec
process.exitValue().with {def exitValue ->
if (exitValue==143) {//SIGTERM: consider the process killed after a success
valid << user
} else {
invalid << user
}
print '.'
}
}
println ''
println 'CHECK COMPLETED'
println "Valid credentials: ${valid}"
println "Invalid credentials: ${invalid}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment