Skip to content

Suggestion: -oY -oJ will fail if parent directory of the new file did not exist #63

@bestutsengineer

Description

@bestutsengineer

Hi! Just a quick one here.

I was using it to scan a machine today. But since I renamed the parent directory (from scans to scans_v1), the .json output file is not created. So I will have to run enum4linux-ng again.

Command to replicate the issue:

mkdir -p ~/Vault/scans_v1
enum4linux-ng -A <ip_address> -v -oJ "~/Vault/scans/e4l-Gm"
sudo updatedb && locate -i e4l-Gm

Error message is seen in the last line of the output.
[!] Could not write JSON output to ~/Vault/scans/e4l-Gm.json

The suggested fix for -oJ, also possibly improved the edge case of no write permission

Add near line 851 and 852 of enum4linux-ng.py

def _write_json(self):
    try:
        # Make directory. Use current directory "." if only the filename is supplied
        os.makedirs(os.path.dirname(self.out_file) or ".", exist_ok=True) 
        with open(f"{self.out_file}.json", 'w') as f:
            f.write(json.dumps(self.out_dict, indent=4))
    except OSError as e: # Throws error if write permission is denied
        print(f"Failed to write JSON: {e}")
        return False
    return True

Probably you could do the same for -oY by adding the same thing near line 859 and 860.

Thank you for your time.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions