home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import sys
- import urllib
- import httplib
- import urlparse
- from base64 import encodestring, decodestring
- from sspi import ClientAuth
- import optparse
- options = None
-
- def open_url(host, url):
- h = httplib.HTTPConnection(host)
- h.putrequest('GET', url)
- h.endheaders()
- resp = h.getresponse()
- print 'Initial response is', resp.status, resp.reason
- body = resp.read()
- if resp.status == 302:
- url = '/' + resp.msg['location']
- resp.close()
- h.putrequest('GET', url)
- h.endheaders()
- resp = h.getresponse()
- print 'After redirect response is', resp.status, resp.reason
-
- if options.show_headers:
- print 'Initial response headers:'
- for name, val in resp.msg.items():
- print ' %s: %s' % (name, val)
-
-
- if options.show_body:
- print body
-
- if resp.status == 401:
- auth_info = None
- if options.user and options.domain or options.password:
- auth_info = (options.user, options.domain, options.password)
-
- ca = ClientAuth('NTLM', auth_info = auth_info)
- auth_scheme = ca.pkg_info['Name']
- data = None
- for s in resp.msg.get('WWW-Authenticate', '').split(','):
- schemes = _[1][s.strip()]
- for scheme in schemes:
- if scheme.startswith(auth_scheme):
- data = decodestring(scheme[len(auth_scheme) + 1:])
- break
- continue
- _[1]
- else:
- print "Could not find scheme '%s' in schemes %r" % (auth_scheme, schemes)
- break
- resp.read()
- []
- print 'Final response status is', resp.status, resp.reason
- if resp.status == 200:
- if resp.will_close:
- print 'EEEK - response will close, but NTLM is per connection - it must stay open'
-
- body = resp.read()
- if options.show_body:
- print 'Final response body:'
- print body
-
- h.putrequest('GET', url)
- h.endheaders()
- resp = h.getresponse()
- print 'Second fetch response is', resp.status, resp.reason
- if options.show_headers:
- print 'Second response headers:'
- for name, val in resp.msg.items():
- print ' %s: %s' % (name, val)
-
-
- resp.read(int(resp.msg.get('content-length', 0)))
- elif resp.status == 500:
- print 'Error text'
- print resp.read()
- elif options.show_body:
- cl = resp.msg.get('content-length')
- print resp.read(int(cl))
-
-
- if __name__ == '__main__':
- parser = optparse.OptionParser(description = __doc__)
- parser.add_option('', '--show-body', action = 'store_true', help = 'print the body of each response as it is received')
- parser.add_option('', '--show-headers', action = 'store_true', help = 'print the headers of each response as it is received')
- parser.add_option('', '--user', action = 'store', help = 'The username to login with')
- parser.add_option('', '--password', action = 'store', help = 'The password to login with')
- parser.add_option('', '--domain', action = 'store', help = 'The domain to login to')
- (options, args) = parser.parse_args()
- if not args:
- print 'Run with --help for usage details'
- args = [
- 'http://localhost/localstart.asp']
-
- for url in args:
- (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url)
- if scheme != 'http' and params and query or fragment:
- parser.error('Scheme must be http, URL must be simple')
-
- print "Opening '%s' from '%s'" % (path, netloc)
- r = open_url(netloc, path)
-
-
-