cddmp / enum4linux-ng

A next generation version of enum4linux (a Windows/Samba enumeration tool) with additional features like JSON/YAML export. Aimed for security professionals and CTF players.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Chore] setup.py

noraj opened this issue · comments

@noraj Does that help?

Looks nice but it lacks of an entry point https://python-packaging.readthedocs.io/en/latest/command-line-scripts.html

I actually used the first approach from the link you provided via scripts. So installation should work, the tool would then be called via enum4linux-ng (without the .py extension). I tested it locally and it worked fine.
Or is there a reason to prefer the entry point approach?

Edit:
I always planned to adjust the tool in a way, so that importing is easier. For this the various enumeration classes would propably need a silent parameter (which needs to be enabled by default). That way the output could be disabled by default for an enumeration object. This would allow to write own enum scripts based on enum4linux-ng. This would be a little bit of work, but not too much I guess.
One downside we have at the moment is, that the dash in the name is really a problem. Python does not like module names with dashes. The solution here would be to rename the tool enum4linuxng... not sure if that is unreadable?! Then your entry point approach can be used, since it expects module name like that:

py_modules=['enum4linuxng']
entry_points={
  'console_scripts': ['enum4linuxng']=enum4linuxng:main'],
}

The renaming could be bypassed by using this hack at the beginning of setup.py:

shutil.copyfile('enum4linux-ng.py', 'enum4linuxng.py')
py_modules=['enum4linuxng']
entry_points={
  'console_scripts': ['enum4linux-ng']=enum4linuxng:main'],
}

The tool would then still be callable via enum4linux-ng, but for the import one would need to use import enum4linuxng.

Not sure what to do for now. At the moment, scripts is the easiest solution, but it does only install the tool as a script. No other modification is need, but a module import is then not possible.
I tested the scripts approach yesterday with python setup.py install and pip install .. Both worked fine. Let me know, what you think.

Both scripts or entry_points + console_scripts are valid approaches in your case. Actually I asked for a setup.py script to make packaging easier and more maintainable because we plan to package it in BlackArch Linux. In Linux distribution pip must be avoided at all cost so without a setup.py we could have to create a dirtier jointscript. Thanks I'll try it soon.

Yeah I saw that you plan to package it. I just wondered, if for some reason the entry_point way would be better for you.

From my understanding the dependencies in the PKGBUILD file are processed first, so when setup.py is executed, all necessary dependencies should be installed already, so that nothing will be installed via pip.

I think the PKGBUILD file would propably look like that:

pkgname=enum4linux-ng
pkgver=1.0.0
pkgrel=1
groups=('blackarch' 'blackarch-recon' 'blackarch-scanner')
pkgdesc='A next generation version of enum4linux-ng.'
arch=('any')
url='https://github.com/cddmp/enum4linux-ng'
license=('GPL3')
depends=('python' 'smbclient' 'python-ldap3' 'python-yaml' 'impacket')
makedepends=('git' 'python-setuptools')
source=("git+https://github.com/cddmp/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"

  install -Dm 644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
  install -Dm 644 LICENCE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  python setup.py install --root="$pkgdir" --optimize=1 --skip-build

@noraj Thanks for adding! Will close this now. :)