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

Bug: Remote Server Connections (non-localhost) are non-responsive on VueJS with connection refused #2885

Closed
iknowjason opened this issue Feb 17, 2024 · 17 comments

Comments

@iknowjason
Copy link

iknowjason commented Feb 17, 2024

Describe the bug

When trying to setup Caldera v5.0 so that remote users can connect to it over a remote IP address (not using localhost), the VueJS web application doesn't respond after submitting correct user credentials. It does nothing. In Chrome Dev Console, I see a connection refused in browser dev console because it is trying to hit a localhost api endpoint instead of accessing the endpoint over the app.contact.http configuration setting. The error is:

HEAD http://localhost:8888/api/v2/config/main net::ERR_CONNECTION_REFUSED.

Because the VueJS app functionality relies on hitting that endpoint, it looks to the user as if the login isn't working. Browser dev tools just shows it's trying to render the content by hitting the endpoint, but Caldera VueJS code is having a browser hit the localhost IP instead of the true public IP address.

To Reproduce

Steps to reproduce the behavior:

  • Spin up a fresh AWS EC2 with Ubuntu 22.04
  • Install Caldera
  • Setup EC2 security groups allowing access to all TCP and UDP ports
  • Setup your app.contact.http to look something like this:
app.contact.http: http://18.220.193.125:8888
sudo apt update
sudo apt install python3-pip

Install NodeJS

curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash - &&\
sudo apt install -y nodejs

Clone Caldera

git clone https://github.com/mitre/caldera.git --recursive
cd caldera

Install dependencies

pip3 install -r requirements.txt

Build and run the server

python3 server.py --build

Expected behavior

The VueJS web application renders content after authentication of valid user.

Screenshots

Web application is non-responsive after submitting correct credentials:
Screenshot 2024-02-16 at 4 58 46 PM

Error of connection refused, which doesn't render content and makes web app look un-responsive:
Screenshot 2024-02-16 at 5 01 40 PM

When hitting the VueJS from localhost, browser dev tools shows a successful connection to the localhost api endpoint.
Screenshot 2024-02-16 at 5 03 18 PM

Need to understand if this is a bug in VueJS (didn't have this issue in 4.x) or if there is a configuration parameter that needs to tell the application to accept or re-direct to the public IP address on that api endpoint.

Desktop (please complete the following information):

OS: Ubuntu
Browser:  Chrome
Version 5.0.0
Copy link

Looks like your first issue -- we aim to respond to issues as quickly as possible. In the meantime, check out our documentation here: http://caldera.readthedocs.io/

@alonsobsd
Copy link

it should works if you define VITE_CALDERA_URL=http://18.220.193.125:8888 into plugin/magma/.env file and trying build again. It worked for me using ssl plugin

image

@iknowjason
Copy link
Author

@alonsobsd Excellent! I will give this a try. I've been trying with both SSL and non-SSL listeners.

If this works then it might be good to have a PR on the docs. This will help whether you host Caldera remotely internally on your LAN or on a cloud provider. It impacts all non-localhost/127.0.0.1 setups.

@iknowjason
Copy link
Author

@alonsobsd This works for me with non-SSL listener on http port. I will now try with SSL.

@iknowjason
Copy link
Author

@alonsobsd SSL listener works as well. Do you have any insight if a bug needs to be filled on this to allow <REMOTE_IP> to be added to plugins/magma/.env or an update to the docs? By default no .env existed. Only .env template file.

@alonsobsd
Copy link

alonsobsd commented Feb 17, 2024

SSL listener works as well. Do you have any insight if a bug needs to be filled on this to allow <REMOTE_IP> to be added to plugins/magma/.env or an update to the docs? By default no .env existed. Only .env template file.

I think it is not a bug but it needs be documented for non-localhost settings. I guess it will be updated soon. Btw take on mind a simple replace into plugins/magma/dist/assets/index*.js file could be more quick instead of edit .env file and magma re-build.

sed -i "" -e 's|http://localhost:8888|https://ip_or_hostname_here:8443|g' plugins/magma/dist/assets/index*.js

@elegantmoose
Copy link
Contributor

Yes, we will add this to documentation.

@mevry
Copy link

mevry commented Mar 13, 2024

Was this ever added to the documentation? Also, how can we do the same thing for the Docker container?

@elegantmoose
Copy link
Contributor

Not yet. Wanted to brainstorm with some other team members on potential other solutions first. But we have all been out/busy. We are still tracking though. Apologies.

@zrquan
Copy link

zrquan commented Apr 2, 2024

Do I have to build different Docker images for different hosts, or is there a better way?

@elruedas-ops
Copy link

work for me. The key is reconf plugins/magma/.env and rebuid.

In a docker enviroment, first do the change, edit de docker-compose.yml command: --log DEBUG --build --fresh, run the docker, remove the build and stop/start the container.

Thanks

@zrquan
Copy link

zrquan commented Apr 17, 2024

@elegantmoose Hi, thank you very much for your advice. I tried the method you suggested, but it didn't work because npm is not preserved in the docker image by default. It seems that I can only build the VueJS fron-tend during "docker build".

@plaskur-365-bank
Copy link

Solution for me:
find . -type f -exec grep -l "http://localhost:8888" {} \; | xargs -I {} sed -i "s/http:\/\/localhost:8888/http:\/\/192.168.0.10:8888/g" {}

@elegantmoose
Copy link
Contributor

@plaskur-365-bank @zrquan @elruedas-ops @mevry @alonsobsd @iknowjason We think we fixed this with this PR #2977.

Please reopen if still having issues. And we are looking at dockerfile now too for an update.

@iknowjason
Copy link
Author

Re-opening this issue. Something is still broken. I was just notified by another user of my hosted Caldera tool, Automated Emulation, that Caldera magma VueJS no longer responds. Will share additional details shortly.

@idovandijk
Copy link

Solution for me: find . -type f -exec grep -l "http://localhost:8888" {} \; | xargs -I {} sed -i "s/http:\/\/localhost:8888/http:\/\/192.168.0.10:8888/g" {}

This fixed it for me, you're a lifesaver!

@jmbass
Copy link

jmbass commented Dec 10, 2024

This means that something that should be configurable, aka, the serving host, needs to be defined at build time. This is hardly a good practice in my opinion.

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

No branches or pull requests

10 participants