简体   繁体   English

nmap由非ROOT用户扫描远程计算机的MAC地址

[英]nmap to scan MAC address for remote machine by non-ROOT user

Env- Centos 7 , nmap 6.40 Env- Centos 7,nmap 6.40

Currently I'm trying to fetch MAC/HW addresses for few list of IP's via nmap command utility and with root user its working perfectly. 目前,我正在尝试通过nmap命令实用程序来获取IP的一些列表的MAC / HW地址,并以root用户的身份正常运行。

As root user 以root用户身份

nmap -sP -PE   -iL <list-of-IPs> 

Starting Nmap 6.40 ( http://nmap.org ) at 2018-06-19 07:05 EDT Nmap scan report for 192.168.xx.xx Host is up (0.0015s latency). 从2018年6月19日07:05 EDT 192.168.xx.xx EDT Nmap扫描报告开始Nmap 6.40( http://nmap.org )主机已启动(0.0015s延迟)。 MAC Address: XX:XX:XX:XX:XX:XX MAC地址:XX:XX:XX:XX:XX:XX

As non-root user 作为非root用户

nmap -sP -PE   -iL <list-of-IPs>

Warning: You are not root -- using TCP pingscan rather than ICMP 警告:您不是root用户-使用TCP pingscan而不是ICMP

Starting Nmap 6.40 ( http://nmap.org ) at 2018-06-19 07:19 EDT Note: Host seems down. 在美国东部时间2018-06-19 07:19开始启动Nmap 6.40( http://nmap.org )注意:主机似乎已关闭。 If it is really up, but blocking our ping probes, try -Pn Nmap done: 1 IP address (0 hosts up) scanned in 2.01 seconds 如果确实启动,但阻止了我们的ping探测,请尝试-Pn Nmap完成:在2.01秒内扫描了1个IP地址(0台主机已启动)

Requesting your suggestion/help how the same to be achieve via normal user. 请求您的建议/帮助,如何通过普通用户实现。

Thanks 谢谢

It is possible to run nmap as non-root user. 可以以非root用户身份运行nmap This Wiki describes pretty good how to set everything up to run it as an unprivileged user. 该Wiki非常好地描述了如何设置所有内容以无特权的用户身份运行它。 The linked tutorial also describes this for Ubuntu and Red Hat systems, which should be good for you since you are on CentOS. 链接的教程还针对Ubuntu和Red Hat系统对此进行了描述,由于您使用的是CentOS,因此对您来说应该是有益的。

I think it is important to keep this security warning in mind: 我认为牢记此安全警告很重要:

WARNING: This is dangerous. 警告:这很危险。 The Nmap Scripting Engine (NSE) allows scripts to sniff the network, change firewall roules and interface configuration, or exploit vulnerabilities including on localhost. Nmap脚本引擎(NSE)允许脚本嗅探网络,更改防火墙规则和接口配置或利用本地主机上的漏洞。 It's possible, especially with elevated capabilities, for a clever person to use Nmap and NSE to escalate to full root privileges. 聪明的人可能会使用Nmap和NSE升级到完整的root特权,尤其是在功能增强的情况下。 If you do not understand these risks, do not do this. 如果您不了解这些风险,请不要这样做。

Summary from the Wiki: Wiki的摘要:

1. Restrict access to certain groups, for example adm . 1.限制访问某些组,例如adm Make sure that you use the right location of nmap . 确保使用正确的nmap位置。 In my case, this was /usr/bin/nmap : 就我而言,这是/usr/bin/nmap

sudo chgrp adm /usr/bin/nmap
sudo chmod 750 /usr/bin/nmap

2. Make sure the setcap command is installed ( more information about capabilities here ): 2.确保已安装setcap命令( 有关功能的更多信息,setcap 此处 ):

sudo yum install libcap

3. Now, set the capabilities. 3.现在,设置功能。 Once again, make sure to use the right location. 再一次,请确保使用正确的位置。

sudo setcap cap_net_raw,cap_net_admin,cap_net_bind_service+eip /usr/bin/nmap

4. Finally, you are able to run nmap as unprivileged user. 4.最后,您可以以非特权用户身份运行nmap But, you have to explicitly define that you want to do so. 但是,您必须明确定义您要这样做。 You can define it as an argument of nmap 您可以将其定义为nmap的参数

nmap --privileged -sP -PE -iL <list-of-IPs>

or as an environmental variable: 或作为环境变量:

export NMAP_PRIVILEGED=""

Edit: I don't exactly know why this answer is being down-voted since this is one possible answer to the question (although the question is of course better suited for Super User or Unix & Linux Stack Exchange). 编辑:我不完全知道为什么这个答案会被否决,因为这是该问题的一个可能答案(尽管该问题当然更适合于超级用户或Unix&Linux Stack Exchange)。 I added the results from my own systems with and without --privileged below: 我添加了来自我自己的系统的结果(带有和不--privileged

$ nmap -sP -PE 192.168.0.1
Warning:  You are not root -- using TCP pingscan rather than ICMP

Starting Nmap 7.60 ( https://nmap.org ) at 2018-06-20 08:52 CEST
Nmap scan report for <HOST NAME> (192.168.0.1)
Host is up (0.0011s latency).
Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds

$ nmap --privileged -sP -PE 192.168.0.1

Starting Nmap 7.60 ( https://nmap.org ) at 2018-06-20 08:52 CEST
Nmap scan report for <HOST NAME> (192.168.0.1)
Host is up (0.0014s latency).
MAC Address: XX:XX:XX:XX:XX:XX (<MANUFACTURER NAME>)
Nmap done: 1 IP address (1 host up) scanned in 0.32 seconds

Nmap must be run as root in order to retrieve this information. Nmap必须以root用户身份运行才能检索此信息。 Fortunately, there are other sources of MAC address information on a Linux system: the system's ARP tables. 幸运的是,Linux系统上还有其他MAC地址信息源:系统的ARP表。 After making an attempt to contact an IP address (either using Nmap or some other tool like ping ), run arp -n to print the table of IP-to-MAC address mappings. 尝试联系IP地址(使用Nmap或其他诸如ping工具)后,运行arp -n打印IP到MAC地址映射表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM