Skip to content

Instantly share code, notes, and snippets.

@thotypous
Created January 8, 2015 03:14
Show Gist options
  • Select an option

  • Save thotypous/82dae4686767e7478423 to your computer and use it in GitHub Desktop.

Select an option

Save thotypous/82dae4686767e7478423 to your computer and use it in GitHub Desktop.
MyAuth Login Daemon
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# This used to be useful in a time when Altamira-Brazil had only Wireless ISPs
# which were connected to the Internet through VSAT links. The only WISP at
# the time which was stable enough for a small commercial link used to employ
# as its authentication method a captive portal from a product named MyAuth,
# which they acquired from a third party. This was a script to keep it always
# logged in.
#
# I doubt someone is still using this version of MyAuth, but anyway, uploading
# it here for historical purposes :)
#
#
# myauth login
# Copyright (c) 2009 Paulo Matias
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
import urllib, re, md5, time, traceback, os, sys
def login():
# configurações
url = 'http://200.241.244.4:1881/?myauth3'
usuario = 'usuario'
senha = 'senha'
#
cnx = urllib.urlopen(url)
response = cnx.read()
cnx.close()
if 'logout' in response:
return 'Já estava logado'
elif 'CHALLENGE' in response:
challenge = re.search(r'CHALLENGE\s*=\s*"([^"]+)"', response).group(1)
request = { 'username': usuario,
'password': md5.md5(senha + challenge).hexdigest(),
'action': 'auth',
'authtype': 'chap',
'popup': 'true',
'save': '0' }
cnx = urllib.urlopen(url, urllib.urlencode(request))
response = cnx.read()
cnx.close()
if 'Erro' in response:
return re.search(r'Erro:<br><b>([^<]+)</b>', response).group(1)
return 'Login efetuado'
return 'Status desconhecido'
def main():
# drop privileges
try: os.setuid(99) # nobody
except: print("Couldn't drop privileges.")
# detach
pid = os.fork()
if pid != 0:
print('Starting at pid %d.' % pid)
sys.exit(0)
os.setsid()
os.close(0)
os.close(1)
os.close(2)
# loop
while True:
try: status = login()
except: status = traceback.format_exc()
f = open('/var/log/myauth/myauth.log', 'a')
f.write('%s: %s\n' % (time.strftime('%a, %d %b %Y %H:%M:%S %z'), status))
f.close()
time.sleep(600)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment