Nakiami / mellivora

Mellivora is a CTF engine written in PHP
GNU General Public License v3.0
440 stars 171 forks source link

Docker: harcoded localhost #129

Closed noraj closed 4 years ago

noraj commented 4 years ago

There is an issue with the docker deployment because the app is always taking "localhost" as a server address.

In docker-compose.dev.yml I just changes the web server ports to:

      - 8080:80
      - 4443:443

Because I they were already used.

Externally the web server is listening on :8080 either on the host (eth0) or the IP of the docker container, etc.

But from wherever I try to reach it I always end getting a HTTP 302 to http://localhost/home.

Obviously not reachable either from my machine or from the docker host but only from inside the container.

$ curl http://172.18.0.1:8080 --head
HTTP/1.1 302 Found
Date: Wed, 15 Jan 2020 18:34:38 GMT
Server: Apache/2.4.38 (Debian)
X-Powered-By: PHP/7.4.1
Set-Cookie: PHPSESSID=7d6f20b54123576bf4bcb77f4e1e6ca6; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
location: http://localhost/home
Content-Type: text/html; charset=UTF-8

It should be redirecting to http://<0.0.0.0>:8080/home instead.

noraj commented 4 years ago

Is it because of those lines ?

https://github.com/Nakiami/mellivora/blob/c2571f65a205e3266df5c952715203123c45ee30/include/config/config.default.inc.php#L42-L43

Nakiami commented 4 years ago

Most likely? I don't really have much information about your particular setup - but redirects for example will use that url.

noraj commented 4 years ago

Most likely? I don't really have much information about your particular setup - but redirects for example will use that url.

I just picked up the docker-compose and only changed the host ports, so this is not a particular setup but the default one.

If the external IP where the docker is exposed is http://10.10.10.10, you will be redirected to http://localhost/home but obviously the user is not running mellivora on its machine, redirecting to localhost only works if you are attached inside the container.

Example of docker internal network:

noraj commented 4 years ago

Step to reproduce:

Nakiami commented 4 years ago

I just picked up the docker-compose and only changed the host ports, so this is not a particular setup but the default one.

The fact that you changed the settings makes it by definition not default settings :p

If your docker container is listening to 8080, accessing localhost:8080 should serve you content from there no?

Can you change the config to be

Config::set('MELLIVORA_CONFIG_SITE_URL', 'http://localhost:8080/');
Config::set('MELLIVORA_CONFIG_SITE_URL_STATIC_RESOURCES', 'http://localhost:8080/');

? Or if what you're exposing is 10.10.10.10:8080, then set it to 10.10.10.10:8080?

noraj commented 4 years ago

If your docker container is listening to 8080, accessing localhost:8080 should serve you content from there no?

It seems you don't understand the issue here. Please re-read my first message.

The issue is the same if you don't modify the port and just git clone + docker-compose -f docker-compose.dev.yml up.

Whatever is the port if the external Ip address of the docker host is 10.0.2.15, then trying to reach http://10.0.2.15:80 will redirects to http://localhost/home, so if you are on the docker host it will works because localhost is localhost but if you try to reach http://10.0.2.15:80 externally from another machine and be redirected to http://localhost/home it will obviously not work.

In any case the site URL should not be hardcoded in config.default.inc.php.

If your docker container is listening to 8080, accessing localhost:8080 should serve you content from there no?

It seems you don't know how docker is working either, with the following config the container is still listening on port 80 and 443 only the mapped port on the host are changed so it should not change anything of the container behavior.

      - 8080:80
      - 4443:443
noraj commented 4 years ago

I think that instead of hardcoding

 Config::set('MELLIVORA_CONFIG_SITE_URL', 'http://localhost/'); 
 Config::set('MELLIVORA_CONFIG_SITE_URL_STATIC_RESOURCES', 'http://localhost/'); 

You should write something like

 Config::set('MELLIVORA_CONFIG_SITE_URL', 'http://0.0.0.0:' + <READ_PORT>); 
 Config::set('MELLIVORA_CONFIG_SITE_URL_STATIC_RESOURCES', 'http://0.0.0.0:' + <READ_PORT>); 

Where the port can be read from the docker compose file via env var or any other mean. IDK there is maybe a proper way to do it but hardcoding local host is the source of all problems.

Nakiami commented 4 years ago

It seems you don't understand the issue here. Please re-read my first message.

It seems you don't know how docker is working either, with the following config the container is still listening on port 80 and 443 only the mapped port on the host are changed so it should not change anything of the container behavior.

Hey mate, you do understand that I have no obligation to spend my free time helping you? Being rude and aggressive isn't going to make me more likely to help you, and if you want some unsolicited advice, will also only get you so far in life.

The provided docker config is, as described in the readme, meant for local development. If these don't work for you, then you'll need to change it to suit your environment, or use some other method of serving.

If you change MELLIVORA_CONFIG_SITE_URL to point to whatever external ip/url:port you're exposing, you should never be redirected to localhost. All redirects should go to whatever you've configured there. If you've changed this and are still redirected to localhost it means the changes for some reason weren't picked up.

Good luck with your issue.

noraj commented 4 years ago

Hey mate, you do understand that I have no obligation to spend my free time helping you?

I know that I'm a big OSS contributor too.

Being rude and aggressive isn't going to make me more likely to help you, and if you want some unsolicited advice, will also only get you so far in life.

Sorry mate I was a little irritated as you kept repeating the same thing that was not the issue.

The provided docker config is, as described in the readme, meant for local development. If these don't work for you, then you'll need to change it to suit your environment, or use some other method of serving.

If you change MELLIVORA_CONFIG_SITE_URL to point to whatever external ip/url:port you're exposing, you should never be redirected to localhost. All redirects should go to whatever you've configured there. If you've changed this and are still redirected to localhost it means the changes for some reason weren't picked up.

I was just trying to helping you to make the product better. Weeks ago I saw the project was not production ready when I tested it. I didn't have time to debug it so I just used RootTheBox (https://github.com/moloch--/RootTheBox) which by the way is awesome.

Cheers :heart: and sorry you took it bad.

Nakiami commented 4 years ago

I was just trying to helping you to make the product better.

As a big OSS contributor you might want to reconsider what is and is not helpful. Until then I'd like to ask you to refrain from further contributions, at least to my projects.

Weeks ago I saw the project was not production ready when I tested it.

Strange as it's somehow been used is hundreds of competitions already.

you kept repeating the same thing that was not the issue

I kept repeating the same thing because you're misunderstanding how the service works and what the configuration option does. I offered you an explanation and a solution which you don't seem willing to test.

sorry you took it bad.

In case you don't realise it - although I'm sure you do - this is not an apology but just another passive aggressive dig at me.

I'm glad you found something that works for you. Good luck with your competition.