python3-nmap
python3-nmap copied to clipboard
sudo command is not executed
@user_is_root
def nmap_os_detection(self, target, arg="-O", args=None): # requires root
"""
nmap -oX - nmmapper.com -O
NOTE: Requires root
"""
xml_root = self.scan_command(target=target, arg=arg, args=args)
results = self.parser.os_identifier_parser(xml_root)
return results
@user_is_root exits control before scan_command(...) is executed (which run sudo nmap ...)
And https://github.com/nmmapper/python3-nmap/blob/3de136bc48ea8a00ae3b5074728185c67414f685/nmap3/nmap3.py#L93 should be as
return self.default_args.format(nmap="sudo "+self.nmaptool, outarg="-oX")
Good suggestion, though i don't think it's a good idea to hard code sudo command like that. Any other solution is welcome
We can make Variable PRIVILEGE_CMD="sudo".
There are other alternatives for sudo like doas
to handle that we can make condition as in pseudo code
if ( PRIVILEGE_CMD is empty):
PRIVILEGE_CMD="sudo"
else:
PRIVILEGE_CMD=readFromEnvironment()
I have not searched how can be this useful for gui apps with polkit to get root privileges
The library was designed to be a little easier to use, if possible the decorate user_is_root returns Json, is there a way you can use the returned json to determine how to use sudo?