Telnet client negotiation not working properly - terminal

I am designing telnet client, which negotiates telnet options. I send desired commands to server, and process server's requests and responses. But at least color terminal identification has no effect: remote Linux server continues sending data without color ESC sequences until I explicitly tell it (through its dialog) that my client supports color.
However windows telnet and hyperterminal is being fed by the color information just after telnet negotiation, and I am looking for what they do I do not. Here's what I see:
telnet
hyperterminal
I see that server performs 255 cursor right and 255 cursor down, and then requests cursor position report, and client reports ESC [ 24;80R (which is correct), and just after this server starts color communication.
Here's what my client does
It does not have ESC [ R command supported, and does not respond for reporting cursor position. I must say that server seem to wait for several seconds for something exactly at the time when it performs these right/down cursor movements.
If it the issue why I do not have color data from the server, or there's something else you can see in the operation of my client?
Interesting that I have a video of another client which also is not expected to support ESC R command, but I see server starts sending ESC color codes after negotiation. So I have a feeling that it may not be this cursor report command issue.

Answer: after implementation of the "report position" response of the client to the server, server sends ESC color sequences now. Thus this functionality was vital for the general client-server handshaking.

Related

Huawei Cdma Modem, How can send sms via C# App OR AT command

I've huawei EC156 cdma modem, I tried to send SMS via AT commands with many commands, But always received response "command not support".
I have used the following commands:
1- AT+CMGS
2- AT + GWWC
Also, I didn't find any C# Libraries dealing with cdma modems.
You definitely need to check the AT commands user manual of your device and check their syntax.
AT+CMGS has two different modes:
in PDU mode its syntax is AT+CMGS=<PDU>
in text mode it is AT+CMGS=< dest phone number>
In both cases AT+CMGS is wrong, and operation not supported is the error you get for a wrong syntax (after setting verbose error mode with AT+CMEE=2).
There are plenty of questions showing the correct AT commands sequence required to send an SMS, for example this one.
I summarize that sequence here briefly:
Some things ti check before starting:
Make sure that the SIM is inserted
Make sure that the PIN code has been correctly inserted (by issuing AT+CPIN? you have to receive the READY response)
Make sure that the device is correctly registered to the network (by issuing AT+CREG? you have to receive the +CREG: 0,1 response)
Then:
Switch to text mode by issuing AT+CMGF=1
Tell to the device the phone number you want send the SMS to, by issuing AT+CMGS=<PHONE NUMBER>. The device will output the > prompt character
Write your text
Close the SMS by providing the Ctrl-Z character (0x1A ASCII code)
On success, the response +CMGS: <N> will be displayed, with N in the range 0-255 meaning the progressive ID of sent messages

AT+CMGS - Can not excape text input mode

I am using PuTTY to connect to an industrial cellular router , to send SMS via AT-Commands.
In PuTTY, I select Telnet and connect to the IP-Address of the router on port 23:
Router loging: root
Password: ****
# gsmat ATE1 // turn echo on
OK
# gsmat AT+CMGF=1 // switch to text mode (0 = PDU mode)
OK
# gsmat AT+CMGS=\"0664XXXXXXXX" // "tel. number"
> Test message [ENTER] // new line (expected)
> [Ctrl-Z] // nothing happens, also with Alt+0026, etc.
> [Ctrl-D]
> -sh: syntax error: unterminated quoted string
#
I normaly the SMS should send on Ctrl+Z (according to documentation, forums, etc.), but nothing happens.
So i tried the following:
ASCII code: [Alt+0026] for substitute (Ctrl+Z), nothing happens, also with Hex: 0x1A
Copy and past [SUB] from Notepad++, nothing happens (copy and paste normal text into PuTTY works fine)
[Ctrl-Y] as suggested in some forum, maybe because german keyboard layout (also nothing happens)
[Ctrl-D], syntax error, input escapes, but of course sending failes
I also tried different tools like Hyperterminal, SSH from CMD, Hercules tool, ...
Has anyone an other idea how to escape this text input mode in this situation?
My goal is to send an SMS autmatically via an C# service and there I just add (char)26 to my input and it works.
inputString = message.Length > 160 ? message.Substring(0, 160) : message;
inputString += (char)26;
connector.Write(inputString);
Any suggestions are appreciated
Screenshot: PuTTY connection settings
Screenshot: PuTTY terminal input
What I do is send SMS via PDU mode. It's a little more effort, but much better for automatic SMS sending.
According to several Internet sources, such as this one CTRL+Z is a shortcut that makes you
Put whatever you are running into a suspended background process. Type fg to restore it
which seems exactly what you are experiencing: CTRL+Z character is actually never sent, and that's the reason why the modem never sends its response.
As far as I know, sending ASCII 0x1A (decimal 26) should be correctly recognized by PuTTY. But since you already tried it there must be some other issue, and a different attempt has to be done.
Fortunately, process suspend feature can be disabled: as shown in PuTTY user guide that functionality is called Keyboard sends Telnet special commands.
In order to disable it:
Open PuTTy Configuration
Category Connection -> Telnet
Unflag Keyboard sends Telnet special commands option
It seems the problem is associated with the SMSC number.
AT+CSCA="+SMSC number"\r\n solved the problem

How do I close a socket (ipv4 and ipv6) connection on Windows from any process?

How do I close tcp v4 and tcp v6 connections on Windows? I don't want to kill the entire process that has the open connection as this obviously will kick everyone else off that process. I need to do this from a separate process, and so will not have access to socket handles, etc. I am using Windows API to get tcp table, etc. so I know which connections are active.
One way might be to enumerate all open handles on the system, or at least the open handles of a given target process, until you find the SOCKET handle you are interested in (see HOWTO: Enumerate handles, Socket Handles, and C++ Get Handle of Open Sockets of a Program - though I'm not sure how you would be able to retrieve the IP/Port pairs of a SOCKET to compare to the active connection you are interested in, without injecting remote getsockname()/getpeername() calls into the owning process of the SOCKET).
Once you have found the SOCKET handle you want, you can then close it by using DuplicateHandle() with the DUPLICATE_CLOSE_SOURCE flag 1.
1: This is how the "Close Handle" feature in Process Explorer works.
Since I'm using C#, I cannot PInvoke SetTcpEntry, even as administrator with an app.manifest file, it always sends a 317 error. So I created a C++ .exe to close a comma separated list of ipv4 addresses on the command line using SetTcpEntry, works fine even without an app.manifest file. That solves kicking ipv4 connections.
I tried using the get handles approach with NtQuerySystemInformation but never could get it working quite right, and it is a private mostly undocumented API and seems unsafe to use.
So, for ipv6, I am using windivert and injecting RST flag to ipv6 packets with certain ip addresses. It is as simple as setting the RST flag of an incoming packet before sending it on through with windivert. The downside is, if the client never sends another packet, the ipv6 socket still stays open indefinitely.
Perhaps someday Microsoft will add a SetTcpEntry6 function, but until then this appears to be the only realistic way.
UPDATE 2022-05-01, found this gem at https://www.x86matthew.com/view_post?id=settcpentry6

X11 remote application timeout

I am in need of a way to decrease the timeout my X server has on remote applications. Currently X11 will keep an application on the display for a very long time (> 30min) after removing the Ethernet connection. I am needing to timeout within 10-30 seconds of loss of communication with the application.
I am running a standard Xorg server with no modification made to it. I have tried numerous methods for doing this. I have tried using the -to option on the X server but this does not seem to have any effect. I have also tried messing with the TCP properties using sysctl. I have set the tcp_keepalive_* properties to values which should give me the timeout needed but this also does not seem to have an effect on the timeout.
Also, the remote applications are not using SSH tunneling to connect to the server. It is an open sever on a secure connection so tunneling is not needed. The timeout mechanism must be done on the server side as I have no control over the applications.
Anyone have any ideas how to get the needed behavior from the X server?
The X server doesn't have client timeouts. Anything you see that looks like one is TCP's doing, not X's.
If you're lucky, the application you're talking to responds to the _NET_WM_PING protocol (most modern toolkits do this for you internally). If you can at least control the window manager you're using, you could modify it to send ping messages to all your running apps and blow them away with XKillClient if they don't respond promptly.

Mapping Port to PID for Transient Windows TCP Connections

I am trying to reverse engineer a third-party TCP client / server Windows XP, SP 3 app for which I have no source available. My main line of attack is to use WireShark to capture TCP traffic.
When I issue a certain GUI command on the client side, the client creates a TCP connection to the server, sends some data, and tears down the connection. The server port is 1234, and the client port is assigned by the OS and therefore varies.
WireShark is showing that the message corresponding to the GUI command I issued gets sent twice. The two messages bear a different source port, but they have the same destination port (1234, as mentioned previosuly).
The client side actually consists of several processes, and I would like to determine which processes are sending these messages. These processes are long-lived, so their PIDs are stable and known. However, the TCP connections involved are transient, lasting only a few milliseconds or so. Though I've captured the client-side port numbers in WireShark and though I know all of the PIDs involved, the fact the connections are transient makes it difficult to determine which PID opened the port. (If the connections were long-lived, I could use netstat to map port numbers to PIDs.) Does anybody have any suggestions on how I can determine which processes are creating these transient connections?
I can think of two things:
Try sysinternals' tcpview program. It gives a detailed listing of all tcp connections opened by all the processes in the system. If a process creates connections, you will be able to see them flash (both connect and disconnect are flashed) in tcpview and you will know which processes to start looking into.
Try running the binary under a debugger. Windbg supports multi-process debugging (so does visual studio I think). You may have only export symbols to work with but that should still work for calls made to system dlls. Try breaking on any suspected windows APIs you know will be called by the process to create the connections. MSDN should have the relevant dlls for most system APIs documented.
Start here... post a follow-up if you get stuck again.
I ended up creating a batch file that runs netstat in a tight loop and appends its output to a text file. I ran this batch file while running the system, and by combing through all of the netstat dumps, I was able to find a dump that contained the PIDs associated with the ports.

Resources