From f0ad260c13fd99f5032d9cd730075ff83aaea6e2 Mon Sep 17 00:00:00 2001 From: Maximilian Lindner <46794237+sr4ven@users.noreply.github.com> Date: Sun, 24 Sep 2023 14:45:27 +0200 Subject: [PATCH 1/4] Switch to poetry build system --- .gitignore | 1 + MANIFEST.in | 14 ----- boofuzz/__init__.py | 2 - boofuzz/fuzz_logger_curses.py | 2 +- boofuzz/helpers.py | 15 ++--- pyproject.toml | 114 ++++++++++++++++++++++++++++++++++ setup.cfg | 23 ------- setup.py | 97 ----------------------------- tox.ini | 2 +- 9 files changed, 121 insertions(+), 149 deletions(-) delete mode 100644 MANIFEST.in delete mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 56c04fd8..afff20dd 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,7 @@ venv/ ENV/ env.bak/ venv.bak/ +poetry.lock # Sphinx documentation docs/_build/ diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index fc4538eb..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,14 +0,0 @@ -include *.py *.rst *.toml *.txt tox.ini -include docs/Makefile - -recursive-include _static *.png -recursive-include artwork *.eps *.ico *.png *.svg -recursive-include boofuzz/doc *.md -recursive-include docs *.bat *.css *.html *.png *.py *.rst -recursive-include examples *.md *.py -recursive-include request_definitions *.html *.py -recursive-include unit_tests *.feature *.py -recursive-include utils *.py - -exclude .readthedocs.yml .travis.yml codecov.yml -prune docs/_build diff --git a/boofuzz/__init__.py b/boofuzz/__init__.py index 42916d38..f50f4fe6 100644 --- a/boofuzz/__init__.py +++ b/boofuzz/__init__.py @@ -187,8 +187,6 @@ "Word", ] -__version__ = "0.4.1" - # REQUEST MANAGEMENT def s_get(name=None): diff --git a/boofuzz/fuzz_logger_curses.py b/boofuzz/fuzz_logger_curses.py index 2c7c7235..1dfd52fb 100644 --- a/boofuzz/fuzz_logger_curses.py +++ b/boofuzz/fuzz_logger_curses.py @@ -106,7 +106,7 @@ def __init__( self._current_num_mutations = 0 self._format_raw_bytes = bytes_to_str - self._version = helpers.get_boofuzz_version(helpers) + self._version = helpers.get_boofuzz_version() # Resize console to minimum size self._width, self._height = get_terminal_size() diff --git a/boofuzz/helpers.py b/boofuzz/helpers.py index d00d4b88..16358073 100644 --- a/boofuzz/helpers.py +++ b/boofuzz/helpers.py @@ -1,4 +1,5 @@ import errno +import importlib.metadata import os import re import signal @@ -424,22 +425,14 @@ def path_exists(path): return os.path.exists(path) -def get_boofuzz_version(boofuzz_class): +def get_boofuzz_version(): """ - Parses __init__.py for a version string and returns it like 'v0.0.0' - - :type boofuzz_class: class - :param boofuzz_class: Any boofuzz class in the same dir as the __init__ class. + Gets the currently installed boofuzz version :rtype: str :return: Boofuzz version as string """ - path = os.path.dirname(boofuzz_class.__file__) - with open(os.path.join(path, "__init__.py")) as search: - for line in search: - if line.find("__version__ = ") != -1: - return "v" + re.search(r'"(.*?)"', line).group(1) # pytype: disable=attribute-error - return "v-.-.-" + return "v" + importlib.metadata.version("boofuzz") def str_to_bytes(value, encoding="utf-8", errors="replace"): diff --git a/pyproject.toml b/pyproject.toml index 55ec8d78..d1435b73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,116 @@ +[tool.poetry] +name = "boofuzz" +version = "0.4.1" +description = "A fork and successor of the Sulley Fuzzing Framework" +authors = ["Joshua Pereyda "] +license = "GPL-2.0-only" +readme = ["README.rst", "CHANGELOG.rst"] +repository = "https://github.com/jtpereyda/boofuzz" +documentation = "https://boofuzz.readthedocs.io/" +keywords = ["security", "fuzzing"] +classifiers = [ + "Development Status :: 4 - Beta", + "Environment :: Console", + "Environment :: Console :: Curses", + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "Natural Language :: English", + "Operating System :: OS Independent", + "Topic :: Security", + "Topic :: System :: Networking", + "Topic :: Software Development :: Testing :: Traffic Generation", +] + +include = [ + { path = "*.py", format = "sdist" }, + { path = "*.rst", format = "sdist" }, + { path = "*.toml", format = "sdist" }, + { path = "*.txt", format = "sdist" }, + { path = "tox.ini", format = "sdist" }, + { path = "_static", format = "sdist" }, + { path = "artwork", format = "sdist" }, + { path = "docs", format = "sdist" }, + { path = "examples", format = "sdist" }, + { path = "request_definitions", format = "sdist" }, + { path = "unit_tests", format = "sdist" }, + { path = "utils", format = "sdist" }, +] + +[tool.poetry.dependencies] +attrs = "*" +click = "*" +colorama = "*" +Flask = "*" +funcy = "*" +psutil = "*" +pydot = "*" +pyserial = "*" +python = "^3.8" +tornado = "*" + +# dev extras +black = { version = "*", optional = true } +flake8 = { version = "*", optional = true } +ipaddress = { version = "*", optional = true } +mock = { version = "*", optional = true } +netifaces = { version = "*", optional = true } +pytest = { version = "*", optional = true } +pytest-bdd = { version = "*", optional = true } +pytest-cov = { version = "*", optional = true } +tox = { version = "*", optional = true } +wheel = { version = "*", optional = true } + +# docs extras +pygments = { version = ">=2.4.0", optional = true } +sphinx = { version = "*", optional = true } +sphinx_rtd_theme = { version = "*", optional = true } + +[tool.poetry.extras] +dev = [ + "black", + "flake8", + "ipaddress", + "mock", + "netifaces", + "pygments", + "pytest", + "pytest-bdd", + "pytest-cov", + "sphinx", + "sphinx_rtd_theme", + "tox", + "wheel", +] +docs = [ + "sphinx", + "sphinx_rtd_theme", + "pygments", +] + +[tool.poetry.scripts] +boo = 'boofuzz.cli:main' + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" + [tool.black] line-length = 120 + +[tool.pytest.ini_options] +testpaths = ["unit_tests"] +filterwarnings = [ + "ignore:SocketConnection is deprecated:FutureWarning", +] + +[tool.pytype] +disable = [ + "import-error", +] +exclude = [ + "**/ida_fuzz_library_extender.py", + "examples/*.py", + "**/*_test_*.py", + "request_definitions/*.py", + "utils/*.py", +] diff --git a/setup.cfg b/setup.cfg index 54eee441..69d21f72 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,3 @@ -[easy_install] -zip_ok = False - -[zest.releaser] -python-file-with-version = boofuzz/__init__.py - [flake8] ignore = F403, F405, W503, E203 per-file-ignores = utils/ida_fuzz_library_extender.py:F821 @@ -11,22 +5,5 @@ max-complexity = 15 max-line-length = 120 extend-exclude = env,venv,.env,.venv -[check-manifest] -ignore = .stickler.yml - -[tool:pytest] -testpaths = unit_tests -filterwarnings = - ignore:SocketConnection is deprecated:FutureWarning - -[pytype] -disable = - import-error -exclude = - **/ida_fuzz_library_extender.py - examples/*.py - request_definitions/*.py - utils/*.py - [coverage:run] source = ./boofuzz diff --git a/setup.py b/setup.py deleted file mode 100644 index fd195a5f..00000000 --- a/setup.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -import ast -import os -import re -from io import open - -from setuptools import find_packages, setup - -setup_dir = os.path.abspath(os.path.dirname(__file__)) - - -def find_version(*path_elements): - """Search a file for `__version__ = 'version number'` and return version. - - @param path_elements: Arguments specifying file to search. - - @return: Version number string. - """ - path = os.path.join(setup_dir, *path_elements) - for line in open(path): - for match in re.finditer(r"__version__\s*=\s(.*)$", line): - return ast.literal_eval(match.group(1)) - raise RuntimeError("version string not found in {0}".format(path)) - - -def get_long_description(): - descr = [] - for fname in "README.rst", "CHANGELOG.rst": - with open(os.path.join(setup_dir, fname), encoding="utf-8") as f: - descr.append(f.read()) - return "\n\n".join(descr) - - -extra_requirements = { - "dev": [ - "black", - "tox", - "flake8", - "check-manifest", - "mock", - "pytest", - "pytest-bdd", - "pytest-cov", - "netifaces", - "ipaddress", - "wheel", - ], - "docs": ["sphinx", "sphinx_rtd_theme", "pygments>=2.4.0"], -} -extra_requirements["dev"] += extra_requirements["docs"] - -setup( - name="boofuzz", - version=find_version("boofuzz", "__init__.py"), - description="A fork and successor of the Sulley Fuzzing Framework", - long_description=get_long_description(), - long_description_content_type="text/x-rst", - maintainer="Joshua Pereyda", - maintainer_email="joshua.t.pereyda@gmail.com", - url="https://github.com/jtpereyda/boofuzz", - packages=find_packages(exclude=["docs", "examples", "request_definitions", "unit_tests", "utils"]), - package_data={"boofuzz.web": ["static/*", "static/*/*", "templates/*", "templates/*/*"]}, - install_requires=[ - "attrs", - "click", - "colorama", - "Flask", - "funcy", - "psutil", - "pyserial", - "pydot", - "tornado", - ], - extras_require=extra_requirements, - python_requires=">=3.7", - entry_points={"console_scripts": ["boo=boofuzz.cli:main"]}, - classifiers=[ - "Development Status :: 4 - Beta", - "Environment :: Console", - "Environment :: Console :: Curses", - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", - "Natural Language :: English", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Topic :: Security", - "Topic :: System :: Networking", - "Topic :: Software Development :: Testing :: Traffic Generation", - ], -) diff --git a/tox.ini b/tox.ini index c5f1ad5e..89d9d397 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,6 @@ [tox] minversion=2.0 +isolated_build = true skip_missing_interpreters = True envlist = py{38,39,310,311}-{Linux,Windows,macOS}, docs, lint @@ -14,7 +15,6 @@ commands = pip check Linux: sh -ec "if ! getcap $(realpath {envpython}) | grep -q cap_net_admin,cap_net_raw+eip; then sudo setcap cap_net_admin,cap_net_raw+eip $(realpath {envpython}); fi" pytest --cov --cov-report=xml - check-manifest commands_post = - python -c "import shutil; shutil.rmtree('./boofuzz-results/')" From b46d8e1f45fa8660a2c9a04e5e6efa8a18cd7aaa Mon Sep 17 00:00:00 2001 From: Maximilian Lindner <46794237+sr4ven@users.noreply.github.com> Date: Sun, 24 Sep 2023 20:25:40 +0200 Subject: [PATCH 2/4] Build and publish to PyPI using Poetry --- .github/workflows/deploy.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2d924660..1e8d8e10 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -17,11 +17,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install poetry - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - python setup.py sdist bdist_wheel - twine upload dist/* + poetry publish --build -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} From 7e04e69262ecb040afd16c37c65c1a532d1765f3 Mon Sep 17 00:00:00 2001 From: Maximilian Lindner <46794237+sr4ven@users.noreply.github.com> Date: Wed, 4 Oct 2023 23:36:12 +0200 Subject: [PATCH 3/4] Update docs --- CHANGELOG.rst | 3 ++- CONTRIBUTING.rst | 4 ++-- INSTALL.rst | 28 +++++++++++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ef429ef8..1139eb17 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -16,10 +16,11 @@ Fixes - Specified encoding on file write rather than assuming default encoding - Changed type of `default_value` from string to bytes for `FromFile`. - `s_update` primitive was out of date. -- The minimum supported Python version is now 3.7. +- The minimum supported Python version is now 3.8. - Removed duplicates from `BitField` primitive. - Fixed unwanted deprecation warning when using `Session.fuzz(name=name)`. - Changed type of `dep_value` argument of `Block` to bytes and added type checks. +- Using poetry as package build system. v0.4.1 ------ diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 7e58a996..68003fec 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -18,7 +18,7 @@ See installation instructions for details on installing boofuzz from source with Pull Request Checklist ---------------------- -1. Install python version 3.7+ +1. Install python version 3.8+ 2. Verify tests pass: @@ -75,7 +75,7 @@ Prep 2. Increment version number from last release according to PEP 0440 and roughly according to the Semantic Versioning guidelines. - 1. In ``boofuzz/__init__.py``. + 1. In ``pyproject.toml``. 2. In ``docs/conf.py``. diff --git a/INSTALL.rst b/INSTALL.rst index af137710..86824e16 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -58,11 +58,9 @@ environment beforehand. From Source ----------- - - 1. Like above, it is recommended to set up a virtual environment. Depending on your concrete setup, this is largely equivalent to the steps outlined above. Make sure - to upgrade ``setuptools`` and ``pip``. + to upgrade ``setuptools`` and ``pip`` or ``poetry``. 2. Download the source code. You can either grab a zip from https://github.com/jtpereyda/boofuzz or directly clone it with git: @@ -70,8 +68,28 @@ From Source $ git clone https://github.com/jtpereyda/boofuzz.git -3. Install. Run ``pip`` from within the boofuzz directory after activating the virtual - environment: +Install with Poetry +~~~~~~~~~~~~~~~~~~~ +Poetry will automatically create a virtual environment for you and install the required dependencies. The installation +will be editable by default, meaning that changes to the source code will be seen directly without reinstalling. + +Simply execute the following command inside the boofuzz source dir: + + .. code-block:: bash + + $ poetry install + +To install with extra dependencies like `dev` or `docs`, specify them in one of the following ways: + + .. code-block:: bash + + $ poetry install --extras "dev docs" + $ poetry install -E dev -E docs + $ poetry install --all-extras + +Install with Pip +~~~~~~~~~~~~~~~~ +Run ``pip`` from within the boofuzz directory after activating the virtual environment: .. code-block:: bash From d0ee5ebe38173c81ebb8e24d7d2fd3a7905980cc Mon Sep 17 00:00:00 2001 From: Maximilian Lindner <46794237+sr4ven@users.noreply.github.com> Date: Fri, 6 Oct 2023 22:24:22 +0200 Subject: [PATCH 4/4] Don't suggest installing dev and docs extra requirements concurrently docs extras are already included in dev extras --- INSTALL.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/INSTALL.rst b/INSTALL.rst index 86824e16..69e15a47 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -83,8 +83,8 @@ To install with extra dependencies like `dev` or `docs`, specify them in one of .. code-block:: bash - $ poetry install --extras "dev docs" - $ poetry install -E dev -E docs + $ poetry install --extras "dev" + $ poetry install -E docs $ poetry install --all-extras Install with Pip