Skip to content

Help with install / run #4

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

Closed
spastro opened this issue Aug 15, 2022 · 10 comments
Closed

Help with install / run #4

spastro opened this issue Aug 15, 2022 · 10 comments

Comments

@spastro
Copy link

spastro commented Aug 15, 2022

Just got into docker and got a instance of netbox running locally.
Trying to test this scanner.

I have docker-netbox running in the following location on my local drive.
d:/docker/container/netbox-docker

Now.
Created another folder within the container folder
d:/docker/container/docker-netbox-scanner

  1. used git clone https://github.com/casperklein/docker-netbox-scanner.git to grab the files.
  2. added nmap tag to tags on the netbox interface
  3. created new api token in netbox with write enabled. description was nmap_api
  4. edited the file netbox-scanner.conf with the netbox server address and the API key.
  5. opened networks.txt and added to networks i wanted to scan to the list.
  6. ran scan.sh and a brief box popped up but nothing else
  7. tried scan.sh --dns and a brief flash of a box came up but nothing.

What am i doing wrong?

@casperklein
Copy link
Owner

As far as I can tell, you did everything right. However, I've only tested this on Debian. Your problem is mostly the last step. Maybe you don't have BASH installed (which is a default on Debian).

You don't strictly need scan.sh. You should be able to run manually the last line of scan.sh:

docker run "$@" --rm -it -v "$PWD"/netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v "$PWD"/networks.txt:/netbox-scanner/networks.txt:ro "$TAG"

So in your example, the following should work:

  1. Run cmd.exe
  2. A command prompt window should appear
  3. Change the directory:
d:
cd \docker\container\docker-netbox-scanner
  1. Run docker-netbox scanner:
docker run --rm -it -v netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest

or with DNS-Server specified:

docker run --dns 192.168.0.1 --rm -it -v netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest

@spastro
Copy link
Author

spastro commented Aug 15, 2022

cheers , yup was running through bash window using mingw64

now getting thids error
/d/Docker/Container/docker-netbox-scanner (master)
$ docker run netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest

@casperklein
Copy link
Owner

casperklein commented Aug 15, 2022

the input device is not a TTY

You can try to omit the -it option:

docker run --rm -v netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest

Also there is an error in your netbox-scanner.conf. Make sure to include the protocol (http://) in the address field. That is a known issue.

PS: You edited the post above. I cannot see the error you are getting now.

@spastro
Copy link
Author

spastro commented Aug 15, 2022

Yeah, sorry! i was updating as i was working through the errors my self. Sure is a learning curve.

updated the conf file to include the http://127.0.0.1:8000

Tried your command above.

new error is

MINGW64 /d/Docker/Container/docker-netbox-scanner (master)
$ docker run --rm -v netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest

Send networks to Netbox..
Traceback (most recent call last):
File "/netbox-scanner/netbox-scanner.py", line 34, in
raise FileNotFoundError('Configuration file was not found.')
FileNotFoundError: Configuration file was not found.

@casperklein
Copy link
Owner

casperklein commented Aug 15, 2022

This indicates, that the file mountings are not working.
Make sure to be in the correct directory (/d/Docker/Container/docker-netbox-scanner) when executing the docker command. You can also try this:

docker run --rm -v ./netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v ./networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest

./ is added before the filename.

Edit: This should work. I could reproduce your error without the ./.

@spastro
Copy link
Author

spastro commented Aug 16, 2022

Hey Mate,

Pretty sure i am close now.

I tried your command above and got the following error.
/d/docker/container/docker-netbox-scanner (master)
$ docker run --rm -v ./netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v ./networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest
docker: Error response from daemon: .\netbox-scanner.conf;C%!(EXTRA string=is not a valid Windows path).

Can only assume the C reference is because of root.
so i changed to
$ docker run --rm -v ./netbox-scanner.conf:/d/docker/container/docker-netbox-scanner.conf:ro -v ./networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest
error
docker: Error response from daemon: .\netbox-scanner.conf;D%!(EXTRA string=is not a valid Windows path).
See 'docker run --help'.

So i changed to
$ docker run --rm -v /d/docker/container/docker-netbox-scanner.conf:/d/docker/container/docker-netbox-scanner.conf:ro -v ./networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest
Error
Error response from daemon: .\networks.txt;C%!(EXTRA string=is not a valid Windows path).
See 'docker run --help'.

So i changed to
$ docker run --rm -v /d/docker/container/docker-netbox-scanner.conf:/d/docker/container/docker-netbox-scanner.conf:ro -v /d/docker/container/docker-netbox-scanner/networks.txt:/d/docker/container/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest

Error
Error: 'networks.txt' is empty.

Now the networks.txt is not empty
It has created a new folder in
d/docker/container
folder is called docker-netbox-scanner.con;D
folder is empty

And a new folder in
d/docker/container/docker-netbox-scanner.
folder is called networks.txt;D
Folder is empty.

Which part in the statement is actually telling it where to look for networks.txt

Also, should i have a casperklein/netbox-scanner: latest folder as i don't?

@casperklein
Copy link
Owner

casperklein commented Aug 16, 2022

Can only assume the C reference is because of root.

No. The second part after the colon is the container path and must not be changed. More info in the docs.

Also, should i have a casperklein/netbox-scanner: latest folder as i don't?

This tells docker, which image to use. No folder needed..

https://stackoverflow.com/questions/50608301/docker-mounted-volume-adds-c-to-end-of-windows-path-when-translating-from-linux

Adding a / infront of the path might help:

docker run --rm -v .//netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v .//networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest

or full path

docker run --rm -v //d/Docker/Container/docker-netbox-scanner/netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v //d/Docker/Container/docker-netbox-scanner/networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest

If the extra slash does not work, you can also try MSYS_NO_PATHCONV=1 instead:

MSYS_NO_PATHCONV=1 docker run --rm -v ./netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v ./networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest

Also keep in mind, that the path might be case-sensitive:

I noticed, that you sometimes wrote /d/Docker/Container/docker-netbox-scanner and other times /d/docker/container/docker-netbox-scanner

You also used a wrong path in one case:

/d/docker/container/docker-netbox-scanner.conf, which should be /d/docker/container/docker-netbox-scanner/netbox-scanner.conf

@spastro
Copy link
Author

spastro commented Aug 16, 2022

Woah!
This one did the trick!. you my good man work wonders!
docker run --rm -v //d/Docker/Container/docker-netbox-scanner/netbox-scanner.conf:/root/.netbox-scanner.conf:ro -v //d/Docker/Container/docker-netbox-scanner/networks.txt:/netbox-scanner/networks.txt:ro casperklein/netbox-scanner:latest

the final result was some errors about not being able to split the netmask from the target.

Starting Nmap 7.80 ( https://nmap.org ) at 2022-08-16 11:41 UTC
"nable to split netmask from target expression: "192.168.121.0/24
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 0.37 seconds
Scan network 192.168.166.0/24
Starting Nmap 7.80 ( https://nmap.org ) at 2022-08-16 11:41 UTC
"nable to split netmask from target expression: "192.168.166.0/24
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 0.33 seconds

Can ping devices on those networks and perform nslookups without an issue.

@casperklein
Copy link
Owner

casperklein commented Aug 16, 2022

nmap is not able to correctly parse your networks.txt.

That's because Linux and Windows use different line endings. You edited the networks.txt from Windows (I guess), which added Windows style line endings. However nmap expects Linux line endings.

You have different options:

  1. If available, use the tool dos2unix --> dos2unix networks.txt. This converts the line endings from Windows to Linux style.
  2. Start from scratch. Delete networks.txt and create it from within your Linux shell (mingw64) with an editor of your choice, e.g. nano or vim.
  3. There are also text editors for Windows like notepad++ which allows you to convert the line endings.

More information: https://www.aleksandrhovhannisyan.com/blog/crlf-vs-lf-normalizing-line-endings-in-git/

@spastro
Copy link
Author

spastro commented Aug 17, 2022

Hey Mate.

You deserve gold'st of gold medals for your work and putting up with all these novice questions.
Its working.

Cant thank you enough

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

No branches or pull requests

2 participants