MyKings / python-masscan

python-masscan is a python library which helps in using masscan port scanner.
https://pypi.org/project/python-masscan/
GNU General Public License v3.0
281 stars 60 forks source link

Exception on Ubuntu #7

Closed tiaotiaolong closed 5 years ago

tiaotiaolong commented 6 years ago

xml.etree.ElementTree.ParserError:None on Ubuntu where nothing with google

But it's Ok on Mac

MyKings commented 6 years ago

Please give detailed error message or screenshot.

chentdy commented 6 years ago

I have the same error, but it's not ok on mac. the detail error:

Traceback (most recent call last):
  File "/Users/user/.local/share/virtualenvs/AssertSec-12yGsf5S/lib/python3.6/site-packages/masscan/masscan.py", line 371, in analyse_masscan_xml_scan
    dom = ET.fromstring(self._masscan_last_output)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/etree/ElementTree.py", line 1315, in XML
    return parser.close()
xml.etree.ElementTree.ParseError: no element found: line 1, column 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 14, in <module>
    mas.scan('192.168.1.110')
  File "/Users/user/.local/share/virtualenvs/AssertSec-12yGsf5S/lib/python3.6/site-packages/masscan/masscan.py", line 317, in scan
    masscan_warn_keep_trace=masscan_warn_keep_trace
  File "/Users/user/.local/share/virtualenvs/AssertSec-12yGsf5S/lib/python3.6/site-packages/masscan/masscan.py", line 375, in analyse_masscan_xml_scan
    raise ET.ParseError
xml.etree.ElementTree.ParseError: None
MyKings commented 6 years ago

The issue is the same as #8, so closed.

MyKings commented 6 years ago

@chentdy hi, can you provide py scripts or test commands written below?

Oneiroi commented 6 years ago

As a notice for future readers of this I get this error when running the python code under WSL (Windows Subsystem Linux)

>>> import masscan
>>> mas = masscan.PortScanner()
>>> mas.scan("192.168.1.0/24")
[2018-09-05 16:59:18,317] [DEBUG] [masscan.py 10 line] Scan parameters: "masscan -oX - 192.168.1.0/24 -p <snipped for brevity>"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/masscan/masscan.py", line 317, in scan
    masscan_warn_keep_trace=masscan_warn_keep_trace
  File "/usr/local/lib/python2.7/dist-packages/masscan/masscan.py", line 375, in analyse_masscan_xml_scan
    raise ET.ParseError
xml.etree.ElementTree.ParseError: None
>>> import sys
>>> sys.platform
'linux2'
>>>

This however is due to the limitations of WSL not having native device capability; running masscan standalone throws the error

    HINT: you must install libpcap or WinPcap
FAIL: libpcap not loaded
adapter[eth0].init: failed

See related WSL issue here https://github.com/Microsoft/WSL/issues/2150 as such the error thrown is missleading as this does not directly relate to xml processing it is related to the masscan process having thrown an error and attemtping to move directly onto the xml processing.

MyKings commented 6 years ago

@Oneiroi

I built a WSL environment and failed to run masscan.

$ masscan -p80 192.168.0.1/24
FAIL: socket for SIOCETHTOOL (ETHTOOL_GET_TS_INFO): Socket type not supported
Adapter[eth0].init: failed

Test environment:

Seeing Microsoft/WSL#2150, this question is about the problem of SOCK_PACKET, but I checked the source of masscan, which is not using SOCK_PACKET.

When I use ethool to view the NIC information, I get the following error:

~$ ethtool -i eth0
Cannot get driver information: Invalid argument

Finally I fixed the error message for python-masscan 726b1a56.

arbazkiraak commented 6 years ago

Try and catch in this case.


    mas = masscan.PortScanner()
    mas.scan(ip_range,ports='443')
    for host in mas.all_hosts:
        subs_ssl.append(host)
except (xml.etree.ElementTree.ParseError,masscan.masscan.NetworkConnectionError) as e:
    pass
MyKings commented 5 years ago

You can't use pass here, you should provide enough error tips for developers to handle problems.

ghost commented 5 years ago

@MyKings @arbazkiraak @tiaotiaolong @chentdy Hi, You should access to root permission for execute masscan

MyKings commented 5 years ago

@arbazkiraak You can use sudo python example.py to execute.