Implementing nCurses over telnet/ssh - ruby

I am currently attempting to implement a small telnet server which spawns a PTY on a connection from a client, and transmits the output of a small nCurses application to the client. I am working in ruby but the question is language-agnostic. My use case does not require users of the application to log into user accounts, so I would prefer not to delegate proper transmission of the screen to system tools such as telnetd.
Given a TCP connection, what are the requirements for transmitting a textual nCurses interface over telnet or ssh? What types of buffering or encoding are necessary for ensuring that screen refreshes on the client side appropriately render the application? This is obviously handled during a typical ssh session, however how is it done?
Thanks in advance.

You need to set the TERM, LINES and COLUMNS environment variables (which you get the correct values for by the NVT protocol). Then you are ready to go and simply spawn an ncurses applications (with your PTY as it's stdin/stdout obviously). You do not need to buffer or otherwise tamper with the character streams (other than in your NVT implementation).

Related

What os difference websocket vs ssh-tunnel?

we are replacing websocket instead of ssh-tunnel. May i know how websocket is better than ssh-tunnel?
WebSocket is a protocol designed for 2-way real-time communication between browsers and servers to replace hacky solutions like long polling and XHR streaming.
SSH is a protocol designed for operating network services securely over an insecure network. Usually it's used for remote logins, file transfers, however it can be used for any protocol, however a few modifications need to be made.
The difference between them is, well, WebSocket is designed to be used for the browser and has support there. However, SSH is a more general protocol and can be used for more however it is not supported by browsers directly, but through proxies which bridge WebSocket to SSH.
There is nothing inherently "better" about WebSocket against SSH. It just depends on your use case, if you want to make a remote terminal or something for your sysadmins, use SSH. If you want to use it for, say, a real time chat in the browser, use WebSocket.

Integration of Shenzhen Concox Information Technology Tracker GT06 with EC2

I have a concox GT06 device from which I want to send tracking data to my AWS Server.
The coding protocol manual that comes with it only explains the data structure and protocol.
How does my server receive the GPS data collected by my tracker?
Verify if your server allows you to open sockets, which most low cost solutions do NOT allow for security reasons (i recommend using an Amazon EC2 virtual machine as your platform).
Choose a port on which your application will listen to incoming data, verify if it is open (if not open it) and code your application (i use C++) to listen to that port.
Compile and run your application on the server (and make sure that it stays alive).
Configure your tracker (usually by sending an sms to it) to send data to your server's IP and to the port which your application is listening to.
If you are, as i suspect you are, just beginning, consider that you will invest 2 to 3 weeks to develop this solution from scratch. You might also consider looking for a predeveloped tracking platform, which may or may not be acceptable in terms of data security.
You can find examples and tutorials online. I am usually very open with my coding and would gladly send a copy of the socket server, but, in this case, for security reasons, i cannot do so.
Instead of direct parsing of TCP or UDP packets you may use simplified solution putting in-between middleware backends specialized in data parsing e.g. flespi.
In such approach you may use HTTP REST API to fetch each new portion of data from trackers sent to you dedicated IP:port (called channel) or even send standardized commands with HTTP REST to connected devices.
At the same time it is possible to open MQTT connection using standard libraries and receive converted into JSON messages from devices as MQTT in real time, which is even better then REST due to almost zero latency.
If you are using python you may take a look at open-source flespi_receiver library. In this approach with 10 lines of code you may have on your EC2 whole parsed into JSON messages from Concox GT06.

What exactly is X11 Channel

In all the documentations of X11 that I've found so far something like this is written
Communication between server and clients is done by exchanging packets over a channel. The connection is established by the client (how the client is started is not specified in the protocol). (from wikipedia)
I haven't been able to find what is this channel exactly? A network channel for example? Is it on a port? Is it a memory map? Any help is appreciated.
The phrasing of 'channel' is intentionally vague as it can be either over a local socket, a remote connection (such as SSH), a named pipe, or another method that allows client/server bidirectional communication. Which is to say, a 'channel' is simply a connection between two points that facilitates exchange of data.
When perform X11 forwarding over SSH, the channel is the SSH connection. See the SSH man page for example:
$ man ssh
X11 connections and arbitrary TCP/IP ports can also be forwarded over the secure channel.
or per the x.org documentation:
The communications channel between an X client and server is full-duplex: either side can send a message to the other at any time. This is canonically implemented over a TCP/IP socket interface, though other communications channels are often used, including Unix domain sockets, named pipes and shared memory. The channel must provide a reliable, ordered byte stream---the X protocol provides no mechanism for reordering or resending packets.
X11 support multiple forms of communication between client and server. These so called channels can be TCP sockets, UNIX sockets, and a bunch of other network mechanisms, such as DECnet, token ring etc. TCP and UNIX sockets are really the only ones used today.
The X server is a process that has access to the graphics hardware, keyboard, and mouse. Any application that produces graphics on the computer screen is called a client. Usually, a workstation has on X server running, and multiple X clients. The applications (clients) need to connect to the X-Server via a TCP socket (identified by IP address and port number) or via a UNIX socket (identified by a file name, e.g. /tmp/X0)
If both, server and clients, run on the same system they usually connect through the UNIX socket. However, one of great features of X11 is that server and clients do not have the reside on the same system, but rather connect through the network via TCP sockets. This allows us to run applications on different computers on the network, and bring their graphics output on a single screen. (A single application may also connect to multiple X server and distribute graphics content on multiple screens.)

In Windows, how do I find out which process is on the other end of a local network socket?

That is to say, if I have a server listening on 127.0.0.1, and a TCP connection comes in, how can I determine the process id of the client?
Also if there isn't an API for this, where would I be able to extract the information from in a more hackish manner?
(The purpose of this is to modify a local HTTP proxy server to accept or deny requests based on the requesting process.)
Edit: palacsint's answer below led me to find this answer to a similar question which is just what's needed
netstat -a -o
prints it. I suppose they are on the same machine becase you are listening on 127.0.0.1.
The only way to do this is if the connecting process sends some sort of custom headers which contains identifier. This is due to the fact that the networking layer is completely separated from the application layer (hint: OSI MODEL. This way it is possible to write lower layers software without caring what happens above as long as the messages exchanged (read: networking packets) follow a pre-determined format (read: use the same protocol).

Monitor socket with ngrep or perl for activity, then issue command

I'd like to use ngrep and/or perl to monitor the incoming data stream on a socket, then, when the appropriate characters arrive, like in this case, the string "192.168.1.101:8080", input to the data stream a redirect to another ipaddress, such as "192.168.1.102"
Is this even possible?
Sure, thats possible.
Algorithm/application would require:
MiM listenning server (creating sockets session sockets)
hand-shake on MiM:
(best thing would be if there would be a text stream not binary protocol used)
recv from client, parse message then:
if IP comes in, open or use already opened socket to the target server/port
send message or rest of the message to target server
provide communication beteween client and target sever (operate as gateway)
recv() client or server and send() back to appropriate side
General advice:
operate on select() or epoll(), approach more advanced but better.
This can done easily in Perl.
Take a look at perldoc perlipc, IO::Socket and IO::Select for examples.
You might find Beej's Guide to Network Programming helpful, too. The examples are all in C, but Perl's networking API is pretty close to the C flavor.

Resources