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

SSHy without wsProxy #26

Closed
stuicey opened this issue May 21, 2019 · 24 comments
Closed

SSHy without wsProxy #26

stuicey opened this issue May 21, 2019 · 24 comments

Comments

@stuicey
Copy link
Owner

stuicey commented May 21, 2019

I am new to this so I am sorry for a stupid question, but is it possible to install wsproxy manually, without npm or avoid it altogether? I want to use SSH only to connect to my machine (where sshy is installed) from elsewhere...

Originally posted by @kidygetnada in #24 (comment)

Moving this to a new issue for search-ability

@stuicey
Copy link
Owner Author

stuicey commented May 21, 2019

If you don't want to use wsProxy/node you can make the following modifications to the code as suggested in #4

This would enable you to use websocket proxies that operate via binary blobs ( such as websockify ). You may have issues multiplexing your connection to multiple SSH servers though unless your chosen websocket proxy also supports target servers in the URI.

e.g.
ws://${websocket_proxy}:${port}/${SSH_server}:${SSH_port}

These changes would be done in index.html or wrapper.html

// Opens the websocket!
ws = new WebSocket(wsproxyURL);
ws.binaryType = "arraybuffer";

// Send all recieved messages to SSHyClient.Transport.handle()
ws.onmessage = function(e) {
	// ArrayBuffer to String
	var enc = new TextDecoder("utf-8");
	var clearMessage = enc.decode(e.data);
	console.log(clearMessage);
	transport.parceler.handle(clearMessage);
};

ws.sendB64 = function(e){
	var enc = new TextEncoder();
	this.send(enc.encode(e)); // String to ArrayBuffer conversion
	console.log("sendB64", e);
	
	transport.parceler.transmitData += e.length;
	transport.settings.setNetTraffic(transport.parceler.transmitData, false);
};

@stuicey stuicey pinned this issue May 21, 2019
@stuicey stuicey closed this as completed May 21, 2019
@kidygetnada
Copy link

Thanks for a quick reply.. So I just need to add this or also remove something?

@kidygetnada
Copy link

The idea is just to connect to localhost:22

@stuicey
Copy link
Owner Author

stuicey commented May 21, 2019

Would be replacing websocket definition & the onmessage() / sendB64() functions which are around here:

https://github.com/stuicey/SSHy/blob/master/index.html#L221
https://github.com/stuicey/SSHy/blob/master/index.html#L232
https://github.com/stuicey/SSHy/blob/master/index.html#L258

@kidygetnada
Copy link

Uncaught TypeError: Cannot set property 'onopen' of undefined
at startSSHy (wrapper.html:226)
at HTMLInputElement.onclick (wrapper.html:491)

@stuicey
Copy link
Owner Author

stuicey commented May 21, 2019

If you're using the wrapper you'll need to modify this in SSHyClient.js and rebuild the min files (instructions in readme).

@kidygetnada
Copy link

i am actually using index.html, but I copied a modified code as per your instructions to wrapper.html... It's still throwing errors

@stuicey
Copy link
Owner Author

stuicey commented May 21, 2019

What browser are you using? and can you check what websocket proxy URL is being passed to the function? console.log(wsproxyURL) just before ws = new WebSocket(wsproxyURL);

@kidygetnada
Copy link

I am using the latest Chrome.. Even when adding that I don't see anything else in the console but this:

Uncaught TypeError: Cannot set property 'onopen' of undefined
at startSSHy (wrapper.html:226)
at HTMLInputElement.onclick (wrapper.html:492)

@stuicey
Copy link
Owner Author

stuicey commented May 21, 2019

That doesn't sound right, if you're not getting any logs out for a wsproxyURL it suggests its not set which would be why the websocket connection can't open.

Do you have your console sidebar configured to only show errors?

@kidygetnada
Copy link

No, it's showing everything.. It's not showing anything, because it's within function startSSHy(), which is not starting

@stuicey
Copy link
Owner Author

stuicey commented May 21, 2019

The stack trace indicates that the startSSHy function does start and crashes when trying to set ws.onopen. If you've replaced the code that was there with the modified version provided at the top of this chain then this shouldn't happen.

Do you want to attach the file and I'll have a look?

@kidygetnada
Copy link

Sure..
https://jsfiddle.net/3umdx2nh/

@stuicey
Copy link
Owner Author

stuicey commented May 21, 2019

You've added that code block in after ws.onopen so it will be erroring as it hasn't set ws to anything at that stage.

@kidygetnada
Copy link

Thanks, I moved it up at this point.. But now I get this error:

wrapper.html:238 WebSocket connection to 'ws://localhost:5999/localhost:22' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

@kidygetnada
Copy link

image

@kidygetnada
Copy link

@stuicey
Copy link
Owner Author

stuicey commented May 22, 2019

You'll need to change how the wsproxy URL is generated and set the new proxy URL appropriately.

Currently it expects the proxy to be on either port 5999(ws://) or 6001(wss://). Additionally it appends the IP/port of your target to the uri. This likely won't work with other websocket proxies so you will need to configure this yourself based on whatever proxy you choose.

@OoLunar
Copy link

OoLunar commented May 22, 2019

Well y'all are a lot closer to SSHing online than I am. My page keeps trying to connect to:

WebSocket connection to 'wss://wss//ebdev:6001/:6001/' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED

I'm not even sure how that happened...

Edit:
I do believe that the "ebdev:6001" is referencing my user account, webdev

@stuicey
Copy link
Owner Author

stuicey commented May 22, 2019

You probably set the full webproxy url as wsProxyURL at the top. You'll need to modify or remove the buildWSProxyURL() function.

https://github.com/stuicey/SSHy/blob/master/index.html#L74

This function constructs the URL in the form:
$protocol://$websocketProxy:$websocketURL/$SSHServer:$SshPort

@OoLunar
Copy link

OoLunar commented May 22, 2019

WebSocket connection to 'wss://ebdev:6001/' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED

Progress... I downloaded the latest commit, and I haven't touched anything either. Not quite sure if something else is wrong, or if I missed a step. Sorry if I'm being a difficult.

@OoLunar
Copy link

OoLunar commented May 22, 2019

Debugging through Chrome, and it seems to be complaining about this...

ws = new WebSocket(wsproxyURL); //PROBLEM ACCORDING TO CHROME
ws.binaryType = "arraybuffer";

// Send all recieved messages to SSHyClient.Transport.handle()
ws.onmessage = function(e) {
	// ArrayBuffer to String
	var enc = new TextDecoder("utf-8");
	var clearMessage = enc.decode(e.data);
	console.log(clearMessage);
	transport.parceler.handle(clearMessage);
};

ws.sendB64 = function(e){
	var enc = new TextEncoder();
	this.send(enc.encode(e)); // String to ArrayBuffer conversion
	console.log("sendB64", e);

@stuicey
Copy link
Owner Author

stuicey commented May 22, 2019

The error suggests it can't resolve the domain name ebdev. Have you configured a custom DNS or setup the IP for this in your hosts file?

@OoLunar
Copy link

OoLunar commented May 22, 2019

Hosts file? The only time I've touched that is to just setup my main domain. Unless if there is a hosts file in this project that I am unaware of, I have not.

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

3 participants