Mycroft skill for nmap scan


#1

I wrote a simple skill for Mycroft that will scan targets using nmap

Usage: scan TARGET IP

e.g scan 127.0.1.1

Currently only simple scan on TCP is available, if you have suggestion or want to contribute feel free to drop a PR or open an issue

Skill repo: https://github.com/Nhoya/skill-nmap


#2

Did a Skill Test for you:

nmap scan test by Kathy Reid March 22 0108hrs AEDT

  • Platform: Mark 1
  • Device version: 18.2.2b
  • Language and dialect of tester: English native speaker, Australian accent

Skill installation

  • Installed on Mark 1 using msm install https://github.com/Nhoya/skill-nmap
  • Skill installed successfully TEST PASSED

Steps to test the Skill

  • Speak hey mycroft, scan 168.192.0.1 -> I'm sorry, I don't understand
  • Speak hey mycroft, scan 168.192.0.1 -> Now scanning 168.102.0.1 with N M A P skill -> An error occurred while processing a request in N M A P skill

Tried again

  • Speak hey mycroft, scan 168.192.0.5 -> I'm sorry I don't understand
  • Speak hey mycroft, scan 168.192.0.5 -> I'm sorry I don't understand

Tried again

  • Speak hey mycroft, scan 168.192.0.12 -> I'm sorry I don't understand
  • Speak hey mycroft, scan 168.192.0.12 -> I don't know what that means

Did a grep of mycroft-skills.log, grepping for nmap, pasted below.

Best, Kathy

pi@mark_1:/var/log $ cat mycroft-skills.log | grep -i nmap
14:04:49.888 - SKILLS - DEBUG - {"type": "msm.install.succeeded", "data": {"skill": "skill-nmap"}, "context": null}
14:04:59.311 - mycroft.skills.core:load_skill:106 - INFO - ATTEMPTING TO LOAD SKILL: skill-nmap with ID 1767657979
14:04:59.323 - mycroft.skills.core:init_dialog:838 - DEBUG - No dialog loaded, /opt/mycroft/skills/skill-nmap/dialog/en-us does not exist
14:04:59.332 - mycroft.skills.core:load_skill:124 - INFO - Loaded skill-nmap
14:04:59.338 - mycroft.skills.core:load_skill:129 - INFO - First run of skill-nmap
14:04:59.391 - SKILLS - DEBUG - {"type": "mycroft.skills.loaded", "data": {"folder": "skill-nmap", "id": 1767657979, "name": "NmapSkill", "modified": 1521641074.0372655}, "context": null}
14:12:27.435 - SKILLS - DEBUG - {"type": "mycroft.skill.handler.start", "data": {"name": "NmapSkill.handle_scan_intent"}, "context": null}
14:12:27.772 - SKILLS - DEBUG - {"type": "speak", "data": {"expect_response": false, "utterance": "An error occurred while processing a request in Nmap Skill"}, "context": {"client_name": "mycroft_listener", "ident": "1521641540.011881538090", "target": null}}
14:12:27.776 - mycroft.skills.core:wrapper:607 - ERROR - An error occurred while processing a request in Nmap Skill
  File "/opt/mycroft/skills/skill-nmap/__init__.py", line 19, in handle_scan_intent
    nm=nmap.PortScanner()
  File "/usr/local/lib/python2.7/site-packages/nmap/nmap.py", line 131, in __init__
PortScannerError: 'nmap program was not found in path. PATH is : /usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games'
14:12:27.787 - SKILLS - DEBUG - {"type": "mycroft.skill.handler.complete", "data": {"exception": "", "name": "NmapSkill.handle_scan_intent"}, "context": null}

#3

Hi Kathy and thanks for the accurate review,
The problem is caused by a missing dependency that is python-nmap.
It is listed in requirements.txt but for some reason it is not installed in your system, you can solve this issue installing python-nmap with pip


#4

So, I’d rather track down why python-nmap is not installing rather than manually install it - otherwise others will have similar issues.


#5

Hey @w00t,

From:

  File "/usr/local/lib/python2.7/site-packages/nmap/nmap.py", line 131, in __init__
PortScannerError: 'nmap program was not found in path. PATH is : /usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games'

It looks like the python library (python-nmap) was installed (the exception comes from /usr/local/lib/python2.7/site-packages/nmap/nmap.py), but that that library depends on having nmap installed on the system. You can use a requirements.sh script to install that (see https://mycroft.ai/documentation/skills/skill-submission/#msm-compliance)

-Chris


#6

@KathyReid, if you want to test my theory that it’s not that the python library wasn’t installed, and instead that the system package is missing, you could try running sudo apt-get install nmap, and testing the skill again.


#7

Hi @Christopher_Rogers, you are right, this is not said clearly on the library page but looking at the Debian Package we can see that nmap is needed, i added nmap installation in this commit


#8

So, I’ve tried multiple times now to install this Skill, and each attempt has failed with msm error 122 - Running requirements.sh failed.

I did a bit of digging to see why requirements.sh failed and couldn’t figure it out - I tried both msm install https://github.com/Nhoya/skill-nmap.git and sudo msm install https://github.com/Nhoya/skill-nmap.git but both throw msm error 122.

So I took a look at requirements.sh. Using the bash script, the command that it tries to run is
pi@mark_1:~ $ sudo apt install nmap
If I run this manually, it asks to confirm. I don’t want to run it, because then the msm install will work, but we won’t find out why requirements.sh doesn’t work.

So next I manually tried to execute requirements.sh. I couldn’t do this at all, with permission denied errors. I tried to do sudo su mycroft, and tried again. Still no good. Then I dook a look at the filesystem permissions:

pi@mark_1:/opt/mycroft/skills/skill-nmap $ ls -las
total 48
4 drwxr-xr-x  5 mycroft mycroft 4096 Mar 22 12:30 .
4 drwxrwxrwx 42 mycroft mycroft 4096 Mar 22 12:30 ..
4 drwxr-xr-x  8 mycroft mycroft 4096 Mar 22 12:30 .git
4 -rw-r--r--  1 mycroft mycroft 1143 Mar 22 12:30 __init__.py
4 -rw-r--r--  1 mycroft mycroft 1870 Mar 22 12:30 __init__.pyc
4 -rw-r--r--  1 mycroft mycroft 1057 Mar 22 12:30 LICENSE
4 -rw-r--r--  1 mycroft mycroft   67 Mar 22 12:30 README.md
4 drwxr-xr-x  3 mycroft mycroft 4096 Mar 22 12:30 regex
4 -rw-r--r--  1 mycroft mycroft  665 Mar 22 12:30 requirements.sh
4 -rw-r--r--  1 mycroft mycroft   12 Mar 22 12:30 requirements.txt
4 -rw-r--r--  1 mycroft mycroft   35 Mar 22 12:30 settings.json
4 drwxr-xr-x  3 mycroft mycroft 4096 Mar 22 12:30 vocab

The requirements.sh file is set to 644 - it’s not executable. So I changed it to 744, which added the executable flag, but I still couldn’t get it to execute manually.

I’m going to ping King @forslund here in case he has any ideas.

TL;DR - I think this is a permissions issue and that’s why requirements.sh is not executing.


#9

Yea, I think I have the solution, in requirements.sh i’m missing #!/bin/bash since I usually run calling it with the interpreter (bash requirements.sh) Calling bash inside requirements.sh should fix the issue

I fixed the issue


#10

Also the mycroft user hasn’t got privileges to run apt directly on the mycroft (and I assume picroft but haven’t checked)

Instead, on these platforms pkcon (which can be limited by policykit) can be used to install packages.


#11

Still failing for me. msm error 122.


#12

So we need a way to detect which platform has pkcon, any suggestion?


#13

We’ve been using the following code snippet

found_exe() {
    hash "$1" 2>/dev/null
}

# On a Mark 1 the installation process is often running under a limited
# user named 'mycroft'.  So avoid apt-get for installing packages.

# polkit uses pkcon instead of apt-get; pkcon will then run apt-get
if found_exe pkcon; then
  pkcon package
fi

#14

we need a template for requirements,sh, here is the version i have been using


#15

Yea, i saw but this will break in multiple cases, I added a new template that is more comprehensive, but is still missing some distros


#16

I just tried this on a mark1, 18.08r9. Same error. Is this a problem that has been solved, but requires changes to requirements.sh? Or is this still an unsolved problem?

I think this could be a really great skill, and help demonstrate one the key differences between Mycroft and the competition (i.e., intent fulfillment from the device itself is possible, even normal/default case).


#17

I tried to replicate this too;

(mycroft-core) pi@mark_1:~ $ sudo msm install https://github.com/Nhoya/nmap-skill
WARNING - No such default skill: plasma-user-control-skill
INFO - Downloading skill: https://github.com/Nhoya/nmap-skill
Resolving                     [=========================]         
Installing                    [=========================]         
Loading cache                 [=========================]         
Finished                      [=========================]         
Fatal error: The following packages have unmet dependencies:
  nmap: Depends: liblinear1 (>= 1.6) but it is not going to be installed
        Recommends: ndiff but it is not going to be installed

Resolving                     [=========================]         
Installing                    [=========================]         
Loading cache                 [=========================]         
Finished                      [=========================]         
Fatal error: The following packages have unmet dependencies:
  liblinear1: Depends: libblas3 but it is not going to be installed or
                       libblas.so.3

Resolving                     [=========================]         
Installing                    [=========================]         
Loading cache                 [=========================]         
Finished                      [=========================]         
Fatal error: The following packages have unmet dependencies:
  libblas3: Depends: libgfortran3 (>= 4.3) but it is not going to be installed

ERROR - Requirements.sh failed with error code: 7
SystemRequirementsException: 7

Yes, I think this Skill needs some changes to requirements.sh - unfortunately I don’t have time to dig into this at the moment.