Score:0

Running `sudo nmap` through snap, while allowing to write to user's home dir

gl flag

I have a problem running nmap in such a way that all the following requirements are satisfied:

  • I want to install nmap through snap
  • I want to run nmap with sudo (the scan type I want to run requires root permissions)
  • I want to write output to the current directory (in the user's home directory)

These requirements seem fairly simple, but I don't succeed in setting this up in the right way.

Just running nmap gives a permission error, even after running 'snap connect nmap:home'.

$ sudo /snap/bin/nmap -oN file
Failed to open normal output file file for writing: Permission denied (13)

Is this something that's possible to achieve?

Score:2
pl flag

If you run a snap under sudo then you're running it under root user, not your user. The home interface won't help you here. That gives the snap running as the user the ability to access that user's home.

The following works:

export FILENAME=/root/filename
sudo /snap/bin/nmap -oN "$FILENAME"
sudo mv "$FILENAME" .

Another option is to bind mount a folder.

mkdir ~/nmap
sudo mkdir /root/nmap
sudo mount -o bind /root/nmap /home/user/nmap
sudo /snap/bin/nmap -oN /root/nmap/nmapfile
ls ~/nmap
nmapfile
Matthijs Melissen avatar
gl flag
Thanks, good suggestion. However it would be great if I can write the output directly to the folder belonging to the current pentest, which is in the user's home. Is there no way to accomplish that?
pl flag
Added another option.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.