Skip to content

Commit

Permalink
Merge pull request #214 from jtpereyda/some-fixes
Browse files Browse the repository at this point in the history
CLI open command
  • Loading branch information
jtpereyda authored Oct 2, 2018
2 parents 3ec3a41 + 421a58b commit 7a977d7
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 250 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Upcoming
========
v0.1.1
======
Features
--------
- New `boo open` command can open and inspect saved database log files.
- Unix procmon now saves coredumps by default.
- Improved "Cannot connect to target" error message.
- Improved API for registering callbacks.
- Made the global `REQUESTS` map available in top level boofuzz package.

Fixes
-----
- Handle exceptions when opening crash bin files in process monitor.
Expand Down
13 changes: 6 additions & 7 deletions boofuzz/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
from __future__ import absolute_import

import functools

from . import blocks
from . import legos
from . import pedrpc
from . import primitives
from . import sex

from .blocks.request import Request
from .blocks import REQUESTS
from .blocks.block import Block
from .blocks.checksum import Checksum
from .blocks.repeat import Repeat
from .blocks.request import Request
from .blocks.size import Size
from .constants import BIG_ENDIAN, LITTLE_ENDIAN
from .constants import BIG_ENDIAN, LITTLE_ENDIAN, DEFAULT_PROCMON_PORT
from .event_hook import EventHook
from .fuzz_logger import FuzzLogger
from .fuzz_logger_text import FuzzLoggerText
from .fuzz_logger_csv import FuzzLoggerCsv
from .fuzz_logger_text import FuzzLoggerText
from .ifuzz_logger import IFuzzLogger
from .ifuzz_logger_backend import IFuzzLoggerBackend
from .itarget_connection import ITargetConnection
Expand All @@ -28,9 +29,7 @@
from .sex import SullyRuntimeError, SizerNotUtilizedError, MustImplementException
from .socket_connection import SocketConnection

__version__ = '0.1.0'

DEFAULT_PROCMON_PORT = 26002
__version__ = '0.1.1'


# REQUEST MANAGEMENT
Expand Down
40 changes: 40 additions & 0 deletions boofuzz/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
from __future__ import print_function
import logging
import time

import click
from . import constants
from . import sessions


@click.group()
def cli():
pass


@cli.command(name='open')
@click.option('--debug', help='Print debug info to console', is_flag=True)
@click.option('--ui-port',
help='Port on which to serve the web interface (default {0})'.format(constants.DEFAULT_PROCMON_PORT),
type=int, default=constants.DEFAULT_WEB_UI_PORT)
@click.option('--ui-addr', help='Address on which to serve the web interface (default localhost). Set to empty '
'string to serve on all interfaces.', type=str, default='localhost')
@click.argument('filename')
def open_file(debug, filename, ui_port, ui_addr):
if debug:
logging.basicConfig(level=logging.DEBUG)

sessions.open_test_run(db_filename=filename, port=ui_port, address=ui_addr)

print('Serving web page at http://{0}:{1}. Hit Ctrl+C to quit.'.format(ui_addr, ui_port))
while True:
time.sleep(.001)


def main():
cli()


if __name__ == "__main__":
main()
19 changes: 19 additions & 0 deletions boofuzz/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
BIG_ENDIAN = ">"
LITTLE_ENDIAN = "<"

DEFAULT_WEB_UI_PORT = 26000
DEFAULT_PROCMON_PORT = 26002

RESULTS_DIR = 'boofuzz-results'

ERR_CONN_FAILED_TERMINAL = "Cannot connect to target; target presumed down. Stopping test run. Note: This likely " \
"indicates a failure caused by the previous test case. "

ERR_CONN_FAILED = "Cannot connect to target; target presumed down. Note: This likely " \
"indicates a failure caused by the previous test case. "

ERR_CONN_ABORTED = "Target connection lost (socket error: {socket_errno} {socket_errmsg}): You may have a " \
"network issue, or an issue with firewalls or anti-virus. Try " \
"disabling your firewall."

ERR_CONN_RESET = "Target connection reset."

ERR_CONN_RESET_FAIL = "Target connection reset -- considered a failure case when triggered from post_send"
17 changes: 14 additions & 3 deletions boofuzz/fuzz_logger_db.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import print_function
import collections
import datetime
import sqlite3

from . import constants
from . import helpers
from . import ifuzz_logger_backend
from . import data_test_case
Expand Down Expand Up @@ -31,9 +33,8 @@ def get_time_stamp():
class FuzzLoggerDb(ifuzz_logger_backend.IFuzzLoggerBackend):
"""Log fuzz data in a sqlite database file."""

def __init__(self):
timestamp = datetime.datetime.utcnow().replace(microsecond=0).isoformat().replace(':', '-')
self._database_connection = sqlite3.connect('boofuzz-run-{0}.db'.format(timestamp), check_same_thread=False)
def __init__(self, db_filename):
self._database_connection = sqlite3.connect(db_filename, check_same_thread=False)
self._db_cursor = self._database_connection.cursor()
self._db_cursor.execute('''CREATE TABLE cases (name text, number integer, timestamp TEXT)''')
self._db_cursor.execute(
Expand Down Expand Up @@ -142,3 +143,13 @@ def get_test_case_data(self, index):
steps.append(data_test_step.DataTestStep(type=row[1], description=row[2], data=data, timestamp=row[4]))
return data_test_case.DataTestCase(name=test_case_row[0], index=test_case_row[1], timestamp=test_case_row[2],
steps=steps)

@property
def failure_map(self):
c = self._database_connection.cursor()
failure_steps = c.execute('''SELECT * FROM steps WHERE type="fail"''')

failure_map = collections.defaultdict(list)
for step in failure_steps:
failure_map[step[0]].append(step[2])
return failure_map
10 changes: 10 additions & 0 deletions boofuzz/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from __future__ import unicode_literals

import ctypes
import errno
import os
import platform
import re
import signal
Expand Down Expand Up @@ -400,3 +402,11 @@ def hex_to_hexstr(input_bytes):
str: Printable string
"""
return hex_str(input_bytes) + " " + repr(input_bytes)


def mkdir_safe(directory_name):
try:
os.makedirs(directory_name)
except OSError as e:
if e.errno != errno.EEXIST:
raise
Loading

0 comments on commit 7a977d7

Please sign in to comment.