diff --git a/lib/listeners/http_com.py b/lib/listeners/http_com.py index 0db86ca..1ddeccd 100644 --- a/lib/listeners/http_com.py +++ b/lib/listeners/http_com.py @@ -7,7 +7,7 @@ import time import copy import sys from pydispatch import dispatcher -from flask import Flask, request, make_response +from flask import Flask, request, make_response, send_from_directory # Empire imports from lib.common import helpers @@ -137,17 +137,86 @@ class Listener: # set the default staging key to the controller db default self.options['StagingKey']['Value'] = str(helpers.get_config('staging_key')[0]) + # randomize the length of the default_response and index_page headers to evade signature based scans + self.header_offset = random.randint(0,64) def default_response(self): + """ + Returns an IIS 7.5 404 not found page. + """ + + return '\n'.join([ + '', + '', + '', + '', + '404 - File or directory not found.', + '', + '', + '', + '', + '
', + '
', + '

404 - File or directory not found.

', + '

The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

', + '
', + '
', + '', + '', + ' ' * self.header_offset, # randomize the length of the header to evade signature based detection + ]) + + def index_page(self): """ Returns a default HTTP server page. """ - page = "

It works!

" - page += "

This is the default web page for this server.

" - page += "

The web server software is running but no content has been added, yet.

" - page += "" - return page + return '\n'.join([ + '', + '', + '', + '', + 'IIS7', + '', + '', + '', + '
', + 'IIS7', + '
', + '', + '', + ]) def validate_options(self): """ @@ -563,7 +632,7 @@ class Listener: """ if not self.mainMenu.agents.is_ip_allowed(request.remote_addr): dispatcher.send("[!] %s on the blacklist/not on the whitelist requested resource" % (request.remote_addr), sender="listeners/http_com") - return make_response(self.default_response(), 200) + return make_response(self.default_response(), 404) @app.after_request @@ -581,6 +650,24 @@ class Listener: response.headers['Expires'] = "0" return response + @app.route('/') + @app.route('/index.html') + def serve_index(): + """ + Return default server web page if user navigates to index. + """ + + static_dir = self.mainMenu.installPath + "data/misc/" + return make_response(self.index_page(), 200) + + @app.route('/welcome.png') + def serve_index_helper(): + """ + Serves image loaded by index page. + """ + + static_dir = self.mainMenu.installPath + "data/misc/" + return send_from_directory(static_dir, 'welcome.png') @app.route('/', methods=['GET']) def handle_get(request_uri): @@ -624,7 +711,7 @@ class Listener: print helpers.color("[*] Orphaned agent from %s, signaling retaging" % (clientIP)) return make_response(self.default_response(), 401) else: - return make_response(self.default_response(), 200) + return make_response(self.default_response(), 404) else: # actual taskings @@ -632,13 +719,13 @@ class Listener: return make_response(base64.b64encode(results), 200) else: # dispatcher.send("[!] Results are None...", sender='listeners/http_com') - return make_response(self.default_response(), 200) + return make_response(self.default_response(), 404) else: - return make_response(self.default_response(), 200) + return make_response(self.default_response(), 404) else: dispatcher.send("[!] %s requested by %s with no routing packet." % (request_uri, clientIP), sender='listeners/http_com') - return make_response(self.default_response(), 200) + return make_response(self.default_response(), 404) @app.route('/', methods=['POST']) @@ -676,16 +763,16 @@ class Listener: elif results[:10].lower().startswith('error') or results[:10].lower().startswith('exception'): dispatcher.send("[!] Error returned for results by %s : %s" %(clientIP, results), sender='listeners/http_com') - return make_response(self.default_response(), 200) + return make_response(self.default_response(), 404) elif results == 'VALID': dispatcher.send("[*] Valid results return by %s" % (clientIP), sender='listeners/http_com') - return make_response(self.default_response(), 200) + return make_response(self.default_response(), 404) else: return make_response(base64.b64encode(results), 200) else: - return make_response(self.default_response(), 200) + return make_response(self.default_response(), 404) else: - return make_response(self.default_response(), 200) + return make_response(self.default_response(), 404) try: certPath = listenerOptions['CertPath']['Value']