主机发现-python脚本以及记录在安装脚本过程中出现并解决的问题
注:环境是kali2022.2vmware
脚本地址:link
操作如下:
1、下载脚本
┌──(root㉿kali)-[~/Desktop]
└─# git clone https://github.com/Cyber-Forensic/nWatch.git
Cloning into 'nWatch'...
remote: Enumerating objects: 80, done.
remote: Total 80 (delta 0), reused 0 (delta 0), pack-reused 80
Receiving objects: 100% (80/80), 24.48 KiB | 2.04 MiB/s, done.
Resolving deltas: 100% (30/30), done.
┌──(root㉿kali)-[~/Desktop]
└─# cd nwatch
┌──(root㉿kali)-[~/Desktop/nwatch]
└─# ls
LICENSE nwatch.py README.md
┌──(root㉿kali)-[~/Desktop/nwatch]
└─# chmod +x nwatch.py
2、运行脚本
因为kali2022安装了python2和python3两个版本的,脚本是python2写的,运行的时候要用python2
┌──(root㉿kali)-[~/Desktop/nwatch]
└─# python2 ./nwatch.py
Traceback (most recent call last):
File "./nwatch.py", line 25, in <module>
from scapy.all import *
ImportError: No module named scapy.all
3、安装scapy模块
┌──(root㉿kali)-[~/Desktop/nwatch]
└─# pip2 install scapy
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting scapy
Downloading scapy-2.4.5.tar.gz (1.1 MB)
|████████████████████████████████| 1.1 MB 20 kB/s
Using legacy 'setup.py install' for scapy, since package 'wheel' is not installed.
Installing collected packages: scapy
Running setup.py install for scapy ... done
Successfully installed scapy-2.4.5
4、安装好scapy模块后
┌──(root㉿kali)-[~/Desktop/nwatch]
└─# python2 ./nwatch.py
Traceback (most recent call last):
File "./nwatch.py", line 27, in <module>
import nmap
ImportError: No module named nmap
5、安装nmap模块
┌──(root㉿kali)-[~/Desktop/nwatch]
└─# pip2 install python-nmap
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting python-nmap
Downloading python-nmap-0.7.1.tar.gz (44 kB)
|████████████████████████████████| 44 kB 80 kB/s
ERROR: Command errored out with exit status 1:
command: /usr/bin/python2 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-k57JwN/python-nmap/setup.py'"'"'; __file__='"'"'/tmp/pip-install-k57JwN/python-nmap/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-83vuvN
cwd: /tmp/pip-install-k57JwN/python-nmap/
Complete output (10 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-k57JwN/python-nmap/setup.py", line 21, in <module>
from nmap import *
File "nmap/__init__.py", line 41, in <module>
from .nmap import * # noqa
File "nmap/nmap.py", line 137
f"nmap program was not found in path. PATH is : {os.getenv('PATH')}"
^
SyntaxError: invalid syntax
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
6、nmap模块解决方法
经测试:选择的版本低于0.6的都无法正常调用,而pip2 install python-nmap安装的是最新版本的nmap,但是由于python2不支持安装nmap最新版的,所以我选择了0.6.1版本的
└─# pip2 install python-nmap==0.6.1
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting python-nmap==0.6.1
Downloading python-nmap-0.6.1.tar.gz (41 kB)
|████████████████████████████████| 41 kB 202 kB/s
Using legacy 'setup.py install' for python-nmap, since package 'wheel' is not installed.
Installing collected packages: python-nmap
Running setup.py install for python-nmap ... done
Successfully installed python-nmap-0.6.1
7、再次运行脚本,正常运行
┌──(root㉿kali)-[~/Desktop/nWatch]
└─# python2 ./nwatch.py
888 888 888 888
888 o 888 888 888
888 d8b 888 888 888
88888b. 888 d888b 888 8888b. 888888 .d8888b 88888b.
888 "88b 888d88888b888 "88b 888 d88P" 888 "88b
888 888 88888P Y88888 .d888888 888 888 888 888
888 888 8888P Y8888 888 888 Y88b. Y88b. 888 888
888 888 888P Y888 "Y888888 "Y888 "Y8888P 888 888
[&] Created by suraj (#r00t)
[+] Started at 01:06:04
[*] Choose a network interface
------------------------------------------------------------------------------------------
| Sl-no | Interface name | IPv4-address | IPv6-address |
------------------------------------------------------------------------------------------
| 1 | lo | 127.0.0.1 | ::1 |<= DO NOT USE LOCALHOST
| 2 | eth0 | 192.168.3.130 | fe80::20c:29ff:fe7f:21d6 |
------------------------------------------------------------------------------------------
choose an interface> 2
[*] Interface => eth0
[*] Scanning subnet(192.168.3.130/24) on eth0 interface
8、关于第5步的一些提醒
直接使用pip2 install nmap安装nmap后,出现了[-] ‘module’ object has no attribute ‘PortScanner’
要解决这个问题就必须按照第5步的操作来