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

Ported the thing to Kali 2020 - you need to install python3-docker pa… #62

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jaubin
Copy link

@jaubin jaubin commented Apr 18, 2020

Hi,

I've ported the thing to run on Kali 2020.

To make it work :

  • sudo apt install -y python3-docker
  • sudo python3 w4sp_webapp.py

The bad news is I'm stuck with docker start-limit-hit startup issue from time to time, preventing the setup phase to work from the web page.

@giacomomangelli
Copy link

giacomomangelli commented May 6, 2020

hi, thanks for the fixes, now all starts quite well. I have just another issue, it happens that the lab can't complete the setup. When i launch the program w4sp-lab@w4sp:~/Scaricati/w4sp-lab-master$ sudo python3 w4sp_webapp.py

it gives me this:

['which', 'dumpcap']
['getcap', b'/usr/bin/dumpcap']
[*] Caps set correctly on dumpcap
[*] Not enough w4sp/labs images found, building now
/home/w4sp-lab/Scaricati/w4sp-lab-master/images
['docker', 'build', '-t', 'w4sp/labs:base', 'base']
['docker', 'build', '-t', 'w4sp/labs:switch', 'switch']
['docker', 'build', '-t', 'w4sp/labs:ftp_tel', 'ftp_tel']
['docker', 'build', '-t', 'w4sp/labs:elk', 'elk']
['docker', 'build', '-t', 'w4sp/labs:victims', 'victims']
['docker', 'build', '-t', 'w4sp/labs:vrrpd', 'vrrpd']
['docker', 'build', '-t', 'w4sp/labs:temp', 'temp']
['docker', 'build', '-t', 'w4sp/labs:inet', 'inet']
['docker', 'build', '-t', 'w4sp/labs:samba', 'samba']
['docker', 'build', '-t', 'w4sp/labs:wireless', 'wireless']
['docker', 'ps', '-aq', '--filter', 'label=w4sp=true']
['ifconfig', '-a']
['ip', 'link', 'delete', b'docker0:']
['ip', 'link', 'delete', b'eth0:']
 RTNETLINK answers: Operation not supported
 ['ip', 'link', 'delete', b'lo:']
 RTNETLINK answers: Operation not supported
 ['ip', 'netns']
 ['pkill', 'dhclient']
 ['ifconfig', '-a']
 ['service', 'network-manager', 'start']
 ['service', 'networking', 'restart']
 ['service', 'docker', 'restart']
  * Serving Flask app "w4sp_webapp" (lazy loading)
  * Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.                                                                   
    Use a production WSGI server instead.
  * Debug mode: off
  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 [*] Lab Launched, Starting Browser
 [*] Do not close this terminal. Closing Terminal will terminate lab.
 Error: no DISPLAY environment variable specified

Than when i open the browser link and click on setup it gives me this:

['docker', 'ps', '-aq', '--filter', 'label=w4sp=true']
{'nodes': [{'id': 1, 'label': ' kali ', 'color': 'rgb(204,0,0)', 'title': 'eth0 : 10.0.2.15 <br>docker0 : 172.17.0.1 <br>'}], 'edges': []}
127.0.0.1 - - [06/May/2020 17:08:15] "GET /getnet HTTP/1.1" 200 -
[2020-05-06 17:08:15,736] ERROR in app: Exception on /is_ips [GET]
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "w4sp_webapp.py", line 213, in is_ips
    if psef('suricata'):
  File "w4sp_webapp.py", line 70, in psef
    if grep in cmd:
TypeError: a bytes-like object is required, not 'str'
127.0.0.1 - - [06/May/2020 17:08:15] "GET /is_ips HTTP/1.1" 500 -
['ifconfig', '-a']
['ip', 'link', 'delete', b'docker0:']
['ip', 'link', 'delete', b'eth0:']
RTNETLINK answers: Operation not supported
['ip', 'link', 'delete', b'lo:']
RTNETLINK answers: Operation not supported
['ip', 'netns']
['pkill', 'dhclient']
['ifconfig', '-a']
['service', 'network-manager', 'start']
['service', 'networking', 'restart']
['service', 'docker', 'restart']
['docker', 'ps', '-aq', '--filter', 'label=w4sp=true']
['ifconfig', '-a']
['ip', 'link', 'delete', b'docker0:']
['ip', 'link', 'delete', b'eth0:']
RTNETLINK answers: Operation not supported
['ip', 'link', 'delete', b'lo:']
RTNETLINK answers: Operation not supported
['ip', 'netns']
['pkill', 'dhclient']
['ifconfig', '-a']
['service', 'network-manager', 'start']
['service', 'networking', 'restart']
['service', 'docker', 'restart']
['docker', 'run', '-id', '--privileged', '--name', 'sw1', '--hostname', 'sw1', '--net=none', 'w4sp/labs:switch']
['docker', 'inspect', '-f', "'{{.State.Pid}}'", b'acef782ac095a1cd9b32da735232805faa0a7925651277b8ae9ca89406941260']
Traceback (most recent call last):
  File "w4sp_webapp.py", line 164, in setup
    w4sp.setup_network2('eth0')
  File "/home/w4sp-lab/Scaricati/w4sp-lab-master/w4sp.py", line 69, in setup_network2
    create_netx(net_1)
  File "/home/w4sp-lab/Scaricati/w4sp-lab-master/w4sp_app/lab_helper.py", line 249, in create_netx
    ns_root.register_ns(name, d_image)
  File "/home/w4sp-lab/Scaricati/w4sp-lab-master/w4sp_app/container.py", line 52, in register_ns
    self.ns.append(container(name, image))
  File "/home/w4sp-lab/Scaricati/w4sp-lab-master/w4sp_app/container.py", line 228, in init
    self.mnt_fd = open(self.proc_path + 'mnt')
FileNotFoundError: [Errno 2] No such file or directory: "/proc/b'5494'/ns/mnt"

['docker', 'rm', '-f', b'acef782ac095a1cd9b32da735232805faa0a7925651277b8ae9ca89406941260']
127.0.0.1 - - [06/May/2020 17:08:28] "GET /setup HTTP/1.1" 200 -

and all the buttons on the right are freezed and i can just click setup again o shutdown

If I understood is a known problem, so what shoud i do to make it work?

@jaubin
Copy link
Author

jaubin commented May 7, 2020 via email

@giacomomangelli
Copy link

i checked a bit and manually enabling the docker service it starts, by the why in container.py there is an issue that i don't know how to solve:

class container(root_ns):

    def init(self, name, image):

        self.nics = []
        self.name = name

        #start the container and record the container id sleeping randomly to try and improve performance at start
        #time.sleep(random.uniform(1,3))
        self.id = r('docker run -id --privileged --name $name --hostname $name --net=none $image').strip()

there is a problem specifically here at line 227:

      self.pid = r("docker inspect -f '{{.State.Pid}}' $self.id").strip().strip(b"'")
  
      self.proc_path = '/proc/%s/ns/' % self.pid
      self.mnt_fd = open(self.proc_path + 'mnt')

when the sequence of bytes is composed the strip function doesn't deleate the "b" and the " ' " cause the output is this:

self.mnt_fd = open(self.proc_path + 'mnt')
FileNotFoundError: [Errno 2] No such file or directory: "/proc/b'6440'/ns/mnt"

what can i do to solve it?

@jaubin
Copy link
Author

jaubin commented May 7, 2020 via email

@giacomomangelli
Copy link

giacomomangelli commented May 8, 2020

yeah I tryied it too, but it seems that can't recognize it if its not a Byte object before the strip method. i'll try a little bit more, but anyway it won't work for anyone if there is not an official solution

@jaubin
Copy link
Author

jaubin commented May 8, 2020 via email

@giacomomangelli
Copy link

oh my bad, sorry, I thought you were one of the authors of the book or similar.
thanks for all your work than

@giacomomangelli
Copy link

excuse me, do you have push rights for this repository? i'm trying to upload the last changes that makes the code works, but i can't do anything else than create a new file

@jaubin
Copy link
Author

jaubin commented May 11, 2020 via email

@rokigithub
Copy link

I need help ...
I made the changes to the code listed in this "Pull request" .. but it stops when I press the "Setup" button, changing the wording from "Setup" to "ERROR" ...
and this is what he writes to me in the terminal:

$ sudo python3 w4sp_webapp.py
['which', 'dumpcap']
['getcap', b'/usr/bin/dumpcap']
[] Caps set correctly on dumpcap
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[
] Not enough w4sp/labs images found, building now
/home/w4sp-lab/Desktop/w4sp-lab-master/images
['docker', 'build', '-t', 'w4sp/labs:base', 'base']
['docker', 'build', '-t', 'w4sp/labs:temp', 'temp']
['docker', 'build', '-t', 'w4sp/labs:switch', 'switch']
['docker', 'build', '-t', 'w4sp/labs:samba', 'samba']
['docker', 'build', '-t', 'w4sp/labs:inet', 'inet']
['docker', 'build', '-t', 'w4sp/labs:victims', 'victims']
['docker', 'build', '-t', 'w4sp/labs:wireless', 'wireless']
['docker', 'build', '-t', 'w4sp/labs:ftp_tel', 'ftp_tel']
['docker', 'build', '-t', 'w4sp/labs:elk', 'elk']
['docker', 'build', '-t', 'w4sp/labs:vrrpd', 'vrrpd']
['docker', 'ps', '-aq', '--filter', 'label=w4sp=true']
['ifconfig', '-a']
['ip', 'link', 'delete', b'docker0:']
['ip', 'link', 'delete', b'eth0:']
RTNETLINK answers: Operation not supported
['ip', 'link', 'delete', b'lo:']
RTNETLINK answers: Operation not supported
['ip', 'netns']
['pkill', 'dhclient']
['ifconfig', '-a']
['service', 'network-manager', 'start']
['service', 'networking', 'restart']
['service', 'docker', 'restart']

  • Serving Flask app "w4sp_webapp" (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: off
  • Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
    [] Lab Launched, Starting Browser
    [
    ] Do not close this terminal. Closing Terminal will terminate lab.

I manually open the browser and enter the address for viewing the Lab.
[] Lab Launched, Starting Browser
[
] Do not close this terminal. Closing Terminal will terminate lab.
Error: no DISPLAY environment variable specified
127.0.0.1 - - [19/May/2020 10:43:05] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [19/May/2020 10:43:05] "GET /static/css/bootstrap.min.css HTTP/1.1" 200 -
{'nodes': [{'id': 1, 'label': ' kali ', 'color': 'rgb(204,0,0)', 'title': 'eth0 : 10.0.2.15
docker0 : 172.17.0.1
'}], 'edges': []}
127.0.0.1 - - [19/May/2020 10:43:05] "GET /getnet HTTP/1.1" 200 -
[2020-05-19 10:43:05,273] ERROR in app: Exception on /is_ips [GET]
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python3/dist-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python3/dist-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3/dist-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/lib/python3/dist-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python3/dist-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "w4sp_webapp.py", line 213, in is_ips
if psef('suricata'):
File "w4sp_webapp.py", line 70, in psef
if grep in cmd:
TypeError: a bytes-like object is required, not 'str'
127.0.0.1 - - [19/May/2020 10:43:05] "GET /is_ips HTTP/1.1" 500 -

The screen with the SETUP key appears ...
I press it and ..... ERROR

['ifconfig', '-a']
['ip', 'link', 'delete', b'docker0:']
['ip', 'link', 'delete', b'eth0:']
RTNETLINK answers: Operation not supported
['ip', 'link', 'delete', b'lo:']
RTNETLINK answers: Operation not supported
['ip', 'netns']
['pkill', 'dhclient']
['ifconfig', '-a']
['service', 'network-manager', 'start']
['service', 'networking', 'restart']
['service', 'docker', 'restart']
['docker', 'ps', '-aq', '--filter', 'label=w4sp=true']
['ifconfig', '-a']
['ip', 'link', 'delete', b'docker0:']
['ip', 'link', 'delete', b'eth0:']
RTNETLINK answers: Operation not supported
['ip', 'link', 'delete', b'lo:']
RTNETLINK answers: Operation not supported
['ip', 'netns']
['pkill', 'dhclient']
['ifconfig', '-a']
['service', 'network-manager', 'start']
['service', 'networking', 'restart']
['service', 'docker', 'restart']
['docker', 'run', '-id', '--privileged', '--name', 'sw1', '--hostname', 'sw1', '--net=none', 'w4sp/labs:switch']
['docker', 'inspect', '-f', "'{{.State.Pid}}'", b'1d90b25b3e1a1f57ebee67b4bf6c6ab11e2b99e05e2ef1deebf394e82daccf97']
Traceback (most recent call last):
File "w4sp_webapp.py", line 164, in setup
w4sp.setup_network2('eth0')
File "/home/w4sp-lab/Desktop/w4sp-lab-master/w4sp.py", line 69, in setup_network2
create_netx(net_1)
File "/home/w4sp-lab/Desktop/w4sp-lab-master/w4sp_app/lab_helper.py", line 249, in create_netx
ns_root.register_ns(name, d_image)
File "/home/w4sp-lab/Desktop/w4sp-lab-master/w4sp_app/container.py", line 52, in register_ns
self.ns.append(container(name, image))
File "/home/w4sp-lab/Desktop/w4sp-lab-master/w4sp_app/container.py", line 228, in init
self.mnt_fd = open(self.proc_path + 'mnt')
FileNotFoundError: [Errno 2] No such file or directory: "/proc/b'27611'/ns/mnt"

['docker', 'rm', '-f', b'1d90b25b3e1a1f57ebee67b4bf6c6ab11e2b99e05e2ef1deebf394e82daccf97']
127.0.0.1 - - [19/May/2020 10:44:22] "GET /setup HTTP/1.1" 200 -
.....

and I ... :-(

@mdimuzio
Copy link

Kali 2020

Hi @jaubin ... from what I understand, you managed to start the laboratory without problems even on KALI 2020 or am I wrong? If I have not misinterpreted, can I ask you exactly what version of KALI, and whether or not you upgraded before starting the procedure that Vaibhav Raj points out in his article? (Can't you send me an updated installation guide - or directions to pay attention to - by writing me on diemmezlab@protonmail.com)? Thank you

@jaubin
Copy link
Author

jaubin commented May 21, 2021 via email

@mdimuzio
Copy link

mdimuzio commented May 21, 2021

Le vendredi 21 mai 2021, 08:50:30 CEST mdimuzio a écrit :

Kali 2020 Hi @jaubin ... from what I understand, you managed to start the laboratory without problems even on KALI 2020 or am I wrong? If I have not misinterpreted, can I ask you exactly what version of KALI, and whether or not you upgraded before starting [the procedure that Vaibhav Raj @./setting-up-the-w4sp-lab-in-2020-d4df6a3d2 a5e)points out in his article? (Can't you send me an updated installation guide - or directions to pay attention to - by writing me on @.**)? Thank you
Hi, I used the Kali version which dates back to one year ago. With the fixed I did on my github the thing ended up starting. However I hit another problem I could not solve, towards Docker interactions. I stopped there and played then with my local network wherever possible.

-- Julien AUBIN

Wonderful... so my own problem! Look at this error screenshot
Is it the same as you too?

@zen9ya0
Copy link

zen9ya0 commented Nov 24, 2021

I have something issus on ubuntu 18.4,have someone can help me,THX
w4sp-lab@w4sp:~/w4sp-lab-master$ sudo python2.7 w4sp_webapp.py
['which', 'dumpcap']
['getcap', '/usr/bin/dumpcap']
[] Caps set correctly on dumpcap
[
] Not enough w4sp/labs images found, building now
/home/w4sp-lab/w4sp-lab-master/images
['docker', 'build', '-t', 'w4sp/labs:base', 'base']
The command '/bin/sh -c pip install netifaces' returned a non-zero code: 1
Traceback (most recent call last):
File "w4sp_webapp.py", line 500, in
w4sp.docker_build('images/')
File "/home/w4sp-lab/w4sp-lab-master/w4sp_app/utils.py", line 95, in docker_build
r('docker build -t w4sp/labs:base base')
File "/home/w4sp-lab/w4sp-lab-master/w4sp_app/utils.py", line 83, in r
return subprocess.check_output(cmd)
File "/usr/lib/python2.7/subprocess.py", line 223, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['docker', 'build', '-t', 'w4sp/labs:base', 'base']' returned non-zero exit status 1

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

Successfully merging this pull request may close these issues.

5 participants