Gallopsled / pwntools

CTF framework and exploit development library
http://pwntools.com
Other
11.74k stars 1.67k forks source link

Deprecate direct commandline scripts invocation and exclude nonsense ones #2364

Open tkmikan opened 4 months ago

tkmikan commented 4 months ago

Deprecate the direct invocations to scripts before refactoring all tools to have a single entry point (Not finished in #660) Check #2361

Arusekk commented 4 months ago

I would keep checksec, asm, disasm, constgrep, cyclic and errno, honestly, but most distros (pentoo, kali, AUR, not sure what else) already use the flag anyway.

peace-maker commented 4 months ago

We can add the inverse of the current pwn-only flag for users who wish to keep the wrapper scripts. I too think you can discover the other commands more easily when using the pwn wrapper. I use the tools you listed frequently as well, but do you suggest to keep them as is since distros already remove the scripts and users installing through pip expect them to be available?

peace-maker commented 1 month ago

I would keep checksec, asm, disasm, constgrep, cyclic and errno, honestly, but most distros (pentoo, kali, AUR, not sure what else) already use the flag anyway.

Hm, I think keeping those is benefitial or at least leaving an option to have them installed. I frequently use those tools and always typing pwn feels annoying. Removing main and update etc. is a no-brainer.

Arusekk commented 3 weeks ago

I thought about something like this, but removing the flag might annoy distro maintainers, as it force-reintroduces the deprecated scripts to those using the magic flag:

From baf9b8532a2f54f47035af0c792bf7e30e5cf1cd Mon Sep 17 00:00:00 2001
From: Arusekk <arek_koz@o2.pl>
Date: Mon, 24 Jun 2024 21:47:13 +0200
Subject: [PATCH] Clean up entry points

---
 pyproject.toml | 24 +++++++++++++++++++++++-
 setup.py       |  2 +-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index ce59233f..a3320880 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,7 +3,7 @@ requires = ["setuptools>=44.0", "wheel", "toml; python_version<'3.4'"]
 build-backend = "setuptools.build_meta"

 [project]
-dynamic = ["version", "scripts"]
+dynamic = ["version"]

 name = "pwntools"
 description = "Pwntools CTF framework and exploit development library."
@@ -63,6 +63,28 @@ dependencies = [
 homepage = "https://pwntools.com"
 download = "https://github.com/Gallopsled/pwntools/releases"

+[project.scripts]
+pwn = "pwnlib.commandline.main:main"
+asm = "pwnlib.commandline.common:deprecated_main"
+checksec = "pwnlib.commandline.common:main"
+constgrep = "pwnlib.commandline.common:main"
+cyclic = "pwnlib.commandline.common:deprecated_main"
+debug = "pwnlib.commandline.common:deprecated_main"
+disablenx = "pwnlib.commandline.common:deprecated_main"
+disasm = "pwnlib.commandline.common:deprecated_main"
+elfdiff = "pwnlib.commandline.common:deprecated_main"
+elfpatch = "pwnlib.commandline.common:deprecated_main"
+errno = "pwnlib.commandline.common:deprecated_main"
+hex = "pwnlib.commandline.common:deprecated_main"
+libcdb = "pwnlib.commandline.common:main"
+phd = "pwnlib.commandline.common:main"
+pwnstrip = "pwnlib.commandline.common:main"
+scramble = "pwnlib.commandline.common:deprecated_main"
+shellcraft = "pwnlib.commandline.common:main"
+template = "pwnlib.commandline.common:deprecated_main"
+unhex = "pwnlib.commandline.common:deprecated_main"
+
+
 [tool.distutils.bdist_wheel]
 universal = 1

diff --git a/setup.py b/setup.py
index 812a0121..104b5fda 100755
--- a/setup.py
+++ b/setup.py
@@ -51,6 +51,7 @@ if sys.version_info < (3, 4):
     compat['packages'] = find_packages()
     compat['install_requires'] = project['dependencies']
     compat['name'] = project['name']
+    compat['entry_points'] = {'console_scripts': project['scripts']}
     # https://github.com/pypa/pip/issues/7953
     site.ENABLE_USER_SITE = "--user" in sys.argv[1:]

@@ -77,6 +78,5 @@ setup(
             'data/templates/*.mako',
         ] + templates,
     },
-    entry_points = {'console_scripts': console_scripts},
     **compat
 )
-- 
2.45.2

I'd like to remove all the useless scripts (as the PR does for main, common etc.), and for sure deprecate template, scramble & debug, and also maybe deprecate direct invocation of the tools that are not strictly pwntools-specific; the rest should stay non-deprecated for now, especially constgrep, shellcraft, phd, checksec.

Later on, we can use python packaging extras for those scripts, see #2245 (sadly, deps can only be positive, and I would honestly love pwntools[slim] vs pwntools over pwntools vs pwntools[full], but whatever). I'm getting ready for cutting a release, and removing the truly useless scripts would be a great feature to have in it. I think that the 'bigger' changes to the scripts, deprecation or removal of the quasi-useful ones, can be coupled with the other PR to reduce the burden on distro maintainers, and just annoy them once.