Commits

Tim Tomes committed 0073e98

added the to_unicode_str framework method and fixed a minor encoding bug in the jigsaw module.

Comments (0)

Files changed (3)

                 tdata.append([table.title(), count])
         self.table(tdata, header=True)
 
-    def to_unicode(self, obj, encoding='utf-8'):
-        # checks if obj is unicode and converts if not
-        if isinstance(obj, (int, long, float)):
+    def to_unicode_str(self, obj, encoding='utf-8'):
+        # checks if obj is a string and converts if not
+        if not isinstance(obj, basestring):
             obj = str(obj)
-        #if isinstance(obj, basestring):
-        if not isinstance(obj, unicode):
-            obj = unicode(obj, encoding)
+        obj = self.to_unicode(obj, encoding)
+        return obj
+
+    def to_unicode(self, obj, encoding='utf-8'):
+        # checks if obj is a unicode string and converts if not
+        if isinstance(obj, basestring):
+            if not isinstance(obj, unicode):
+                obj = unicode(obj, encoding)
         return obj
 
     def ascii_sanitize(self, s):
         lens = []
         cols = len(tdata[0])
         for i in range(0,cols):
-            lens.append(len(max([self.to_unicode(x[i]) if x[i] != None else '' for x in tdata], key=len)))
+            lens.append(len(max([self.to_unicode_str(x[i]) if x[i] != None else '' for x in tdata], key=len)))
         # build ascii table
         if len(tdata) > 0:
             separator_str = '%s+-%s%%s-+' % (self.spacer, '%s---'*(cols-1))
                 print data_str % data_sub
                 print separator
                 # build column names for database table out of header row
-                if table: columns = [self.to_unicode(x).lower() for x in rdata]
+                if table: columns = [self.to_unicode_str(x).lower() for x in rdata]
             for rdata in tdata:
-                data_sub = tuple([self.to_unicode(rdata[i]).ljust(lens[i]) if rdata[i] != None else ''.ljust(lens[i]) for i in range(0,cols)])
+                data_sub = tuple([self.to_unicode_str(rdata[i]).ljust(lens[i]) if rdata[i] != None else ''.ljust(lens[i]) for i in range(0,cols)])
                 print data_str % data_sub
             # bottom of ascii table
             print separator
         if self.options:
             pattern = '%s%%s  %%s  %%s  %%s' % (spacer)
             key_len = len(max(self.options, key=len))
-            val_len = len(max([self.to_unicode(self.options[x]['value']) for x in self.options], key=len))
+            val_len = len(max([self.to_unicode_str(self.options[x]['value']) for x in self.options], key=len))
             if val_len < 13: val_len = 13
             print ''
             print pattern % ('Name'.ljust(key_len), 'Current Value'.ljust(val_len), 'Req', 'Description')
                 value = self.options[key]['value'] if self.options[key]['value'] != None else ''
                 reqd = self.options[key]['reqd']
                 desc = self.options[key]['desc']
-                print pattern % (key.upper().ljust(key_len), self.to_unicode(value).ljust(val_len), reqd.ljust(3), desc)
+                print pattern % (key.upper().ljust(key_len), self.to_unicode_str(value).ljust(val_len), reqd.ljust(3), desc)
             print ''
         else:
             if params != 'info': print ''

modules/discovery/info_disclosure/http/interesting_files.py

                             if download:
                                 filepath = '%s/%s_%s_%s' % (self.workspace, proto, host, filename)
                                 dl = open(filepath, 'wb')
-                                content = resp.text.encode(resp.encoding) if resp.encoding else resp.text
-                                dl.write(content)
+                                dl.write(resp.text.encode(resp.encoding) if resp.encoding else resp.text)
                                 dl.close()
                             cnt += 1
                         else:

modules/recon/contacts/gather/http/web/jigsaw.py

             lname = self.html_unescape(re.search('<span id="lastname">(.+?)</span>', content).group(1))
             title = self.html_unescape(re.search('<span id="title" title=".*?">(.*?)</span>', content).group(1))
             city = self.html_unescape(re.search('<span id="city">(.+?)</span>', content).group(1)).title()
-            state = self.html_unescape(re.search('<span id="state">(.+?)</span>', content))
+            state = re.search('<span id="state">(.+?)</span>', content)
             if state: state = self.html_unescape(state.group(1)).upper()
             region = []
             for item in [city, state]: