Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

masscan.masscan.NetworkConnectionError: network is unreachable. part deux #29

Open
sirmodok opened this issue Jan 12, 2020 · 11 comments
Open
Assignees
Labels
Milestone

Comments

@sirmodok
Copy link

When I add some output options to the scan to store the output into an XML file, the scan happens, and the file is created, but I get the output "masscan.masscan.NetworkConnectionError: network is unreachable."

Details:

Python 3.8.1 (default, Jan  3 2020, 22:44:00) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import masscan
>>> mas = masscan.PortScanner()
>>> mas.scan('192.168.1.111', ports='1-1000', arguments='--max-rate=1000 -oX testfile')
[2020-01-12 02:03:06,241] [DEBUG] [masscan.py 10 line] Scan parameters: "masscan -oX - 192.168.1.111 -p 1-1000 --max-rate=1000 -oX testfile"
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 384, in analyse_masscan_xml_scan
    dom = ET.fromstring(self._masscan_last_output)
  File "/usr/local/lib/python3.8/xml/etree/ElementTree.py", line 1321, 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 "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 325, in scan
    return self.analyse_masscan_xml_scan(
  File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 387, in analyse_masscan_xml_scan
    raise NetworkConnectionError("network is unreachable.")
masscan.masscan.NetworkConnectionError: network is unreachable.
>>> quit()
root@a23c6822251f:/opt/apps/src# cat testfile 
<?xml version="1.0"?>
<!-- masscan v1.0 scan -->
<nmaprun scanner="masscan" start="1578794586" version="1.0-BETA"  xmloutputversion="1.03">
<scaninfo type="syn" protocol="tcp" />
<host endtime="1578794586"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="445"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="80"><state state="open" reason="syn-ack" reason_ttl="61"/></port></ports></host>
<host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="139"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="111"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794588"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="22"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794588"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="53"><state state="open" reason="syn-ack" reason_ttl="61"/></port></ports></host>
<runstats>
<finished time="1578794599" timestr="2020-01-12 02:03:19" elapsed="13" />
<hosts up="6" down="0" total="6" />
</runstats>
</nmaprun>

Additionally I see you pass the arguments '-oX -' which should output in XML format, but the format comes out in JSON. I don't understand why.

@sirmodok
Copy link
Author

sirmodok commented Jan 12, 2020

Ok, I think I get the -oX - thing. You take the XML output and run it through def analyse_masscan_xml_scan which then turns it into a dictionary. Any reason why you do that rather than use -oJ?

@MyKings
Copy link
Owner

MyKings commented Jan 15, 2020

hi, @sirmodok

  • Here use "-" instead of stdin, stdout
  • -oX This is an ancient problem and I think a roadmap is needed to solve it
  • Regarding "masscan.masscan.NetworkConnectionError: network is unreachable" There is a problem with the processing method here, I think the next version will handle it well

similar to #27

@MyKings MyKings self-assigned this Jan 15, 2020
@MyKings MyKings added this to the v0.2.0 milestone Jan 15, 2020
@csskysea
Copy link

I use multiprocessing in python to invoke masscan and also find "masscan.masscan.NetworkConnectionError: network is unreachable. " exception, I don't know how to fix it.

@MyKings
Copy link
Owner

MyKings commented Aug 18, 2020

@csskysea
Please confirm that you can access the target network.

@csskysea
Copy link

csskysea commented Aug 19, 2020

@MyKings of course I can access the target network, because it's no problem using single process.

@MyKings
Copy link
Owner

MyKings commented Aug 19, 2020

Post a screenshot and operating environment description.

@0netwosix
Copy link

When I add some output options to the scan to store the output into an XML file, the scan happens, and the file is created, but I get the output "masscan.masscan.NetworkConnectionError: network is unreachable."

Details:

Python 3.8.1 (default, Jan  3 2020, 22:44:00) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import masscan
>>> mas = masscan.PortScanner()
>>> mas.scan('192.168.1.111', ports='1-1000', arguments='--max-rate=1000 -oX testfile')
[2020-01-12 02:03:06,241] [DEBUG] [masscan.py 10 line] Scan parameters: "masscan -oX - 192.168.1.111 -p 1-1000 --max-rate=1000 -oX testfile"
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 384, in analyse_masscan_xml_scan
    dom = ET.fromstring(self._masscan_last_output)
  File "/usr/local/lib/python3.8/xml/etree/ElementTree.py", line 1321, 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 "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 325, in scan
    return self.analyse_masscan_xml_scan(
  File "/usr/local/lib/python3.8/site-packages/masscan/masscan.py", line 387, in analyse_masscan_xml_scan
    raise NetworkConnectionError("network is unreachable.")
masscan.masscan.NetworkConnectionError: network is unreachable.
>>> quit()
root@a23c6822251f:/opt/apps/src# cat testfile 
<?xml version="1.0"?>
<!-- masscan v1.0 scan -->
<nmaprun scanner="masscan" start="1578794586" version="1.0-BETA"  xmloutputversion="1.03">
<scaninfo type="syn" protocol="tcp" />
<host endtime="1578794586"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="445"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="80"><state state="open" reason="syn-ack" reason_ttl="61"/></port></ports></host>
<host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="139"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794587"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="111"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794588"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="22"><state state="open" reason="syn-ack" reason_ttl="62"/></port></ports></host>
<host endtime="1578794588"><address addr="192.168.1.111" addrtype="ipv4"/><ports><port protocol="tcp" portid="53"><state state="open" reason="syn-ack" reason_ttl="61"/></port></ports></host>
<runstats>
<finished time="1578794599" timestr="2020-01-12 02:03:19" elapsed="13" />
<hosts up="6" down="0" total="6" />
</runstats>
</nmaprun>

Additionally I see you pass the arguments '-oX -' which should output in XML format, but the format comes out in JSON. I don't understand why.

I encountered a similar error. The reason that you can't connect, seems to be you don't have permission to do so. Try giving sudo=True.

mas.scan('192.168.1.111', ports='1-1000', arguments='--max-rate=1000 -oX testfile',sudo=True)

In my case it worked.

@kordup
Copy link

kordup commented May 23, 2021

hi, @sirmodok

  • Here use "-" instead of stdin, stdout
  • -oX This is an ancient problem and I think a roadmap is needed to solve it
  • Regarding "masscan.masscan.NetworkConnectionError: network is unreachable" There is a problem with the processing method here, I think the next version will handle it well

similar to #27

The problem I've noticed is

        try:
        dom = ET.fromstring(self._masscan_last_output)
        except Exception:
            if "found=0" in masscan_err:
                raise NetworkConnectionError("network is unreachable.")
            if len(masscan_err_keep_trace) > 0:
                raise PortScannerError(masscan_err)
            else:
                raise PortScannerError(self._masscan_last_output)

will spit out "network is unreachable" if the xml list is empty, even though the network is reachable - the ports I've looked for just aren't open.

Great module though, I'm still playing with it :). Keep up the good work.

@PadraigEire
Copy link

Still encountering this issue in version 1.3.2 with -oG, -oJ and -oX

@M1BBB
Copy link

M1BBB commented Sep 21, 2022

Still masscan.masscan.NetworkConnectionError: network is unreachable.

@kordup
Copy link

kordup commented Sep 21, 2022

Still masscan.masscan.NetworkConnectionError: network is unreachable.

I believe the error of "Network is Unreachable" should really read "No ports found" and is just a simple typo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants