def probeModel(self): '''Probe specific model of the Hanlong phone To probe for the specific model, a http session is tried. After authentication, the status page reveals the phone model. ''' sModel = None # Try detecting Hanlong with updated firmware try: password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password(None, 'http://' + self._ip + '/', 'admin', 'admin') basic_auth_handler = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(basic_auth_handler) response = opener.open('http://' + self._ip + '/') htmlbody = response.read() # <TR> # <td width="220"><script> document.write(jscs.product_type);</script></td> # <td width="250">UC862</td> # <TR> m = m = re.search(r'product_type\);</script></TD>.*?<TD.*?>(\w+)', htmlbody, re.IGNORECASE | re.DOTALL) if m != None: sModel = m.group(1) except Exception, e: pass
def probeModel(self): '''Probe specific model of Aastra phone The Aastra web admin interface uses Basic authentication for access control. The authentication realm exposes the phone model like this: HTTP/1.1 401 Unauthorized Server: Aragorn WWW-Authenticate: Basic realm="Aastra 6757i" Connection: close Content-Length: 745 Content-Type: text/html ''' sModel = None try: # Do not expect this to succeed. Only interested in exception. urllib2.urlopen('http://' + self._ip + '/') except urllib2.HTTPError, e: if e.code == 401 and 'WWW-Authenticate' in e.headers: m = re.search(r'realm="Aastra (.+)"', e.headers['WWW-Authenticate']) if m != None: sModel = m.group(1) else: self._http_username = '******' self._http_password = '******' password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm( ) password_manager.add_password(None, 'http://' + self._ip + '/', self._http_username, self._http_password) basic_auth_handler = urllib2.HTTPBasicAuthHandler( password_manager) opener = urllib2.build_opener(basic_auth_handler) try: response = opener.open('http://' + self._ip + '/sysinfo.html') htmlbody = response.read() # <TR> # <TD style="BORDER-BOTTOM: 1px dashed">Platform</TD> # <TD style="BORDER-BOTTOM: 1px dashed">9112i Revision 0</TD></TR> # <TR> m = re.search(r'Platform</TD>.*?<TD.*?>(\w+)', htmlbody, re.IGNORECASE | re.DOTALL) if m != None: sModel = m.group(1) except Exception, e: pass
def test_basic_auth(self): opener = OpenerDirector() password_manager = MockPasswordManager() auth_handler = urllib2.HTTPBasicAuthHandler(password_manager) realm = "ACME Widget Store" http_handler = MockHTTPHandler( 401, 'WWW-Authenticate: Basic realm="%s"\r\n\r\n' % realm) opener.add_handler(auth_handler) opener.add_handler(http_handler) self._test_basic_auth( opener, auth_handler, "Authorization", realm, http_handler, password_manager, "http://acme.example.com/protected", "http://acme.example.com/protected", )
def _doAuthPost(self, urlpath, postvars): '''Perform an HTTP POST on a particular URL using the HTTP credentials This method is frequently used to make the phone use the Elastix server as the TFTP source for autoprovisioning. ''' password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password(None, 'http://' + self._ip + '/', self._http_username, self._http_password) basic_auth_handler = urllib2.HTTPBasicAuthHandler(password_manager) digest_auth_handler = urllib2.HTTPDigestAuthHandler(password_manager) opener = urllib2.build_opener(basic_auth_handler, digest_auth_handler) if postvars != None: opener.addheaders = [('Content-Type', 'application/x-www-form-urlencoded')] if not isinstance(postvars, str): postvars = urllib.urlencode(postvars) try: opener.open('http://' + self._ip + urlpath, postvars) except urllib2.HTTPError, e: logging.error('Endpoint %s@%s failed to authenticate - %s' % (self._vendorname, self._ip, str(e))) return False
def probeModel(self): '''Probe specific model of the Snom phone The Snom phone displays the phone model in the title screen, which is unsecured by default. ''' self._loadCustomCredentials() sModel = None try: password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() if self._http_password != None: password_manager.add_password(None, 'http://' + self._ip + '/', self._http_username, self._http_password) basic_auth_handler = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(basic_auth_handler) response = opener.open('http://' + self._ip + '/') htmlbody = response.read() if response.code == 200: # <TITLE>snom 320</TITLE> m = re.search(r'<TITLE>snom (\w+)</TITLE>', htmlbody, re.IGNORECASE) if m != None: sModel = m.group(1) else: # M300, M700 m = re.search(r'<TITLE>(M\d+)</TITLE>', htmlbody, re.IGNORECASE) if m != None: sModel = m.group(1) #except urllib2.HTTPError, e: # if e.code == 401 and 'WWW-Authenticate' in e.headers: # m = re.search(r'realm="Aastra (.+)"', e.headers['WWW-Authenticate']) # if m != None: sModel = m.group(1) except Exception, e: pass
if realm != None: self._loadCustomCredentials() if self._http_username == None: self._http_username = '******' if self._http_password == None: self._http_password = '******' # The 401 Unauthorized provided unhelpful realm. Try fetching the phone config configSources = ( ('/cgi-bin/ConfigManApp.com?Id=26', ), ( '/cgi-bin/cgiServer.exx?command=msgSendMessage(%22app_vpPhone%22,%220x30007%22,%220%22,%221%22)', '/cgi-bin/cgiServer.exx?command=getDownloadConfig(%221%22)', '/cgi-bin/cgiServer.exx?download=/tmp/config.bin', ), ) for sourceList in configSources: basic_auth_handler = urllib2.HTTPBasicAuthHandler() basic_auth_handler.add_password(realm=realm, uri='http://' + self._ip + '/', user=self._http_username, passwd=self._http_password) opener = urllib2.build_opener(basic_auth_handler) try: for sourceUrl in sourceList: response = opener.open('http://' + self._ip + sourceUrl) htmlbody = response.read() m = re.search( r'UserAgent\s*=\s*(Yealink)?\s*(\S+)', htmlbody) if (m != None): sModel = m.group(2)
m = re.search(r'type=(\w+)', text) if m != None: sModel = m.group(1) except socket.error, e: logging.error('Endpoint %s@%s connection failure - %s' % (self._vendorname, self._ip, str(e))) return False # If the model was not identified, this might be a RCA phone with the # Escene MAC prefix if sModel == None: password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password(None, 'http://' + self._ip + '/', self._http_username, self._http_password) basic_auth_handler = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(basic_auth_handler) try: response = opener.open('http://' + self._ip + '/overview.asp') htmlbody = response.read() #<tr><td align="center" valign="middle" height="80"><p class="BB"><strong><span class="style16"><font face="Arial"> # #IP115 # # </font></span></strong><br> m = re.search(r'<font face="\w+">\s+(\w+)\s+</font>', htmlbody, re.IGNORECASE | re.DOTALL) if m != None: self._saveVendor('RCA') sModel = m.group(1) except Exception, e: