Commits

Tim Tomes  committed 1510244

minor bug fixes and logic changes.

  • Participants
  • Parent commits 955c867

Comments (0)

Files changed (2)

 
 var callback = function(status) {
     if (status !== 'success') {
-        console.log('Unable to load the address: ' + url);
+        //console.log('Unable to load the address: ' + url);
         phantom.exit(1)
     }
     page.render(filename);
-    console.log('Successfully rendered: ' + url);
+    //console.log('Successfully rendered: ' + url);
     phantom.exit(0);
 };
 // set connection timeout below

File peepingtom.py

 #=================================================
 
 def main():
-    # check for pre-requisites
+    # depenency check
     if not all([os.path.exists('phantomjs'), os.path.exists('/usr/bin/curl')]):
         print '[!] PhantomJS and cURL required.'
         return
-
-    # continue with options parsing
+    # parse options
     import optparse
     usage = """
 
     parser.add_option('-s', help='Single input mode. Path to target, remote URL or local path.', dest='target', type='string', action='store')
     (opts, args) = parser.parse_args()
 
+    # process options
     if opts.list_file:
         try:
             targets = open(opts.list_file).read().split()
             for item in host.iter('ReportItem'):
                 svc = item.attrib['svc_name']
                 plugname = item.attrib['pluginName']
-                #family = item.attrib['pluginFamily']
                 if (svc in ['www','http?','https?'] and plugname.lower().startswith('service detection')):
                     port = item.attrib['port']
                     output = item.find('plugin_output').text.strip()
     outfile = '%s/%s' % (directory, report)
 
     # logic to gather screenshots and headers for the given targets
-    db = {'targets': {'live': [], 'dead': []}}
-    for target in targets:
-        filename = '%s.png' % re.sub('\W','',target)
-        filepath = '%s/%s' % (directory, filename)
-        print '[*] %s' % (target)
-        if getCapture(target, filepath) == 0:
-            live_target = {}
-            live_target['url'] = target
-            live_target['path'] = filename
-            live_target['hash'] = hashlib.md5(open(filepath).read()).hexdigest()
-            live_target['headers'] = getHeaders(target)
-            db['targets']['live'].append(live_target)
-        else:
-            db['targets']['dead'].append(target)
+    db = {'targets': []}
+    try:
+        for target in targets:
+            filename = '%s.png' % re.sub('\W','',target)
+            filepath = '%s/%s' % (directory, filename)
+            print '[*] %s' % (target)
+            getCapture(target, filepath)
+            target_data = {}
+            target_data['url'] = target
+            target_data['path'] = filename
+            target_data['hash'] = hashlib.md5(open(filepath).read()).hexdigest() if os.path.exists(filepath) else 'z'*32
+            target_data['headers'] = getHeaders(target)
+            db['targets'].append(target_data)
+    except Exception as e:
+        print '[!] %s' % (e.__str__())
     
     # build the report and exit
     buildReport(db, outfile)
 def getCapture(url, filename):
     cmd = './phantomjs --ignore-ssl-errors=yes ./capture.js %s %s' % (url, filename)
     returncode, response = runCommand(cmd)
-    print '\t[PhantomJS] %s' % (response)
     return returncode
 
 def getHeaders(url):
     cmd = 'curl -sILk %s' % (url)
     returncode, response = runCommand(cmd)
-    if returncode == 0:
-        msg = 'HTTP headers retrieved'
-    elif returncode == 6:
-        msg = 'Could not resolve host'
-    elif returncode == 127:
-        msg = 'cURL not found'
-    else:
-        msg = 'Unknown error (%d)' % returncode
-    print '\t[cURL] %s: %s' % (msg, url)
     return response
 
 def runCommand(cmd):
 
 def buildReport(db, outfile):
     live_markup = ''
+    error_markup = ''
     dead_markup = ''
-    for live in sorted(db['targets']['live'], key=lambda k: k['hash']):
-        live_markup += "<tr><td class='img'><a href='{0}'><img src='{0}' /></a></td><td class='head'><a href='{1}' target='_blank'>{1}</a><br /><pre>{2}</pre></td></tr>\n".format(live['path'],live['url'],live['headers'])
-    if len(db['targets']['dead']) > 0:
-        dead_markup = '<tr><td><h2>Invalid Targets</h2></td><td>\n'
-        for dead in db['targets']['dead']:
-          dead_markup +=  "<a href='{0}' target='_blank'>{0}</a><br />\n".format(dead)
-        dead_markup += '</td></tr>\n'
+    # process markup for live targets
+    for live in sorted(db['targets'], key=lambda k: k['hash']):
+        live_markup += "<tr><td class='img'><a href='{0}'><img src='{0}' onerror=\"this.height='0';\" /></a></td><td class='head'><a href='{1}' target='_blank'>{1}</a><br /><pre>{2}</pre></td></tr>\n".format(live['path'],live['url'],live['headers'])
+    # add markup to the report
     file = open(outfile, 'w')
     file.write("""
 <!doctype html>
 </head>
 <body>
 <table>
-%s%s
+%s
 </table>
 </body>
-</html>""" % (live_markup, dead_markup))
+</html>""" % (live_markup))
     file.close()
 
 #=================================================