python3-nmap icon indicating copy to clipboard operation
python3-nmap copied to clipboard

sudo command is not executed

Open Luciogi opened this issue 1 year ago • 3 comments

    @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")

Luciogi avatar Aug 05 '24 09:08 Luciogi

Good suggestion, though i don't think it's a good idea to hard code sudo command like that. Any other solution is welcome

nmmapper avatar Aug 05 '24 14:08 nmmapper

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

Luciogi avatar Aug 05 '24 15:08 Luciogi

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?

nmmapper avatar Aug 08 '24 07:08 nmmapper