Skip to content

Commit

Permalink
Improved Logging in emulators (#345)
Browse files Browse the repository at this point in the history
* debug logs

* path

* add logs
  • Loading branch information
rjt-gupta authored and afeena committed Aug 10, 2019
1 parent 75b7386 commit 2d4c601
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tanner/emulators/mysqli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import logging
from tanner.utils import mysql_db_helper


class MySQLIEmulator:
def __init__(self, db_name):
self.logger = logging.getLogger('tanner.mysqli_emulator')
self.db_name = db_name
self.helper = mysql_db_helper.MySQLDBHelper()

Expand Down Expand Up @@ -32,5 +34,6 @@ async def execute_query(self, query, db_name):
for row in rows:
result.append(list(row))
except Exception as mysql_error:
self.logger.debug('Error while executing query: %s', mysql_error)
result = str(mysql_error)
return result
3 changes: 2 additions & 1 deletion tanner/emulators/php_code_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, loop=None):

async def get_injection_result(self, code):
vul_code = '<?php eval(\'$a = {code}\'); ?>'.format(code=code)

self.logger.debug('Getting the code injection results of %s from php sandbox', code)
code_injection_result = await self.helper.get_result(vul_code)

return code_injection_result
Expand All @@ -27,5 +27,6 @@ def scan(self, value):
async def handle(self, attack_params, session=None):
result = await self.get_injection_result(attack_params[0]['value'])
if not result or 'stdout' not in result:
self.logger.exception('Error while getting the injection results from php sandbox..')
return dict(status_code=504)
return dict(value=result['stdout'], page=False)
2 changes: 2 additions & 0 deletions tanner/emulators/php_object_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async def get_injection_result(self, code):
"$cmd = unserialize(\'%s\');" \
"?>" % code

self.logger.debug('Getting the object injection results of %s from php sandbox', code)
object_injection_result = await self.helper.get_result(vul_code)

return object_injection_result
Expand All @@ -57,5 +58,6 @@ async def handle(self, attack_params):

result = await self.get_injection_result(attack_params[0]['value'])
if not result or 'stdout' not in result:
self.logger.exception('Error while getting the injection results from php sandbox..')
return dict(status_code=504)
return dict(value=result['stdout'], page=False)
4 changes: 3 additions & 1 deletion tanner/emulators/rfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import aiohttp
import yarl

from tanner import config
from tanner.utils.php_sandbox_helper import PHPSandboxHelper
from tanner.utils import patterns

Expand Down Expand Up @@ -50,6 +49,7 @@ async def download_file(self, path):
tmp_filename = url.name + str(time.time())
file_name = hashlib.md5(tmp_filename.encode('utf-8')).hexdigest()
with open(os.path.join(self.script_dir, file_name), 'bw') as rfile:
self.logger.debug('Saving the RFI script %s', os.path.join(self.script_dir, file_name))
rfile.write(data.encode('utf-8'))
return file_name

Expand All @@ -64,6 +64,7 @@ def download_file_ftp(self, url):
tmp_filename = name + str(time.time())
file_name = hashlib.md5(tmp_filename.encode('utf-8')).hexdigest()
with open(os.path.join(self.script_dir, file_name), 'wb') as ftp_script:
self.logger.debug('Saving the FTP file as %s', os.path.join(self.script_dir, file_name))
ftp.retrbinary('RETR %s' % name, ftp_script.write)
except ftplib.all_errors as ftp_errors:
self.logger.exception("Problem with ftp download %s", ftp_errors)
Expand All @@ -74,6 +75,7 @@ def download_file_ftp(self, url):
async def get_rfi_result(self, path):
rfi_result = None
await asyncio.sleep(1, loop=self._loop)
self.logger.info('Downloading the file has started from %s', path)
file_name = await self.download_file(path)
if file_name is None:
return rfi_result
Expand Down
3 changes: 3 additions & 0 deletions tanner/emulators/sqli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import pylibinjection

from tanner.config import TannerConfig
Expand All @@ -6,6 +7,7 @@

class SqliEmulator:
def __init__(self, db_name, working_dir):
self.logger = logging.getLogger('tanner.sqli_emulator')
if TannerConfig.get('SQLI', 'type') == 'MySQL':
self.sqli_emulator = mysqli.MySQLIEmulator(db_name)
else:
Expand Down Expand Up @@ -49,6 +51,7 @@ async def get_sqli_result(self, attack_value, attacker_db):
else:
error_result = 'SQL ERROR: near {}: syntax error'.format(attack_value['id'])

self.logger.debug('Error while executing: %s', error_result)
result = dict(value=error_result, page=True)
else:
execute_result = await self.sqli_emulator.execute_query(db_query, attacker_db)
Expand Down
3 changes: 3 additions & 0 deletions tanner/emulators/sqlite.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
import sqlite3
import logging

from tanner.utils import sqlite_db_helper


class SQLITEEmulator:
def __init__(self, db_name, working_dir):
self.logger = logging.getLogger('tanner.sqlite_emulator')
self.db_name = db_name
self.working_dir = os.path.join(working_dir, 'db/')
self.helper = sqlite_db_helper.SQLITEDBHelper()
Expand Down Expand Up @@ -36,5 +38,6 @@ async def execute_query(self, query, db):
for row in cursor.execute(query):
result.append(list(row))
except sqlite3.OperationalError as sqlite_error:
self.logger.debug('Error while executing query: %s', sqlite_error)
result = str(sqlite_error)
return result
3 changes: 3 additions & 0 deletions tanner/emulators/xxe_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async def get_injection_result(self, code):
echo $data;
?>''' % code

self.logger.debug('Getting the XXE injection results of %s from php sandbox', code)
xxe_injection_result = await self.helper.get_result(vul_code)

return xxe_injection_result
Expand All @@ -55,8 +56,10 @@ async def handle(self, attack_params):

result = await self.get_injection_result(attack_params[0]['value'])
if not result or 'stdout' not in result:
self.logger.exception('Error while getting the injection results from php sandbox..')
return dict(status_code=504)

if TannerConfig.get('XXE_INJECTION', 'OUT_OF_BAND'):
self.logger.debug('Out of Band XXE injection detected..')
return dict(value='', page=False)
return dict(value=result['stdout'], page=False)

0 comments on commit 2d4c601

Please sign in to comment.