What is Telnet command 255 236 sent by Putty on Ctrl+D? - telnet

I am connected to a Telnet server with Putty and looking at what is going on on the connection using Wireshark. The Telnet server rejects any Telnet options, so this is a pure NVT.
When I press Ctrl+D in Putty, it sends the following command to the Telnet server:
0xff 0xec
or, in decimal,
255 236
This looks a lot like a two-byte Telnet command, with the first byte (255) being IAC. However, while looking at RFC 854, I cannot find any mention of a command number 236 (0xec = 236, not to be confused with the Character Erase (EC) command).
Does anybody knows what this is? Am I missing something in the RFC or is this command defined somewhere else?

According to this, it is an End of File command.
The value is defined in RFC1116, which was in turn obsoleted by RFC1184, which defines the same EOF value.

Related

Why do I see escaped characters on the terminal?

Usually CTRL-C or CTRL-D quits a program. However, once in a while instead of quitting the program, pressing CTRL-C just escapes the characters and outputs it to the terminal screen. I've seen this happen multiple times before for different programs: Django, ssh, etc. I've noticed this happens when I've left the terminal for a long period of time.
Is there a way to revert the CTRL-C behavior back to what I would expect?
And what is the reasoning behind the escaped characters?
Here is an example output of what I mean by escaped CTRL-C and other characters:
^C^C^D^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^D^D^D^D^D^D^D^D^D^D^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^Z^D^D^D^D^D^D^D^D^D^D^D^D^D^D^D^D^D^D^D^D^D^D^D^D^D^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^D^D^D^D^D^D^D^D^D^D^D^D^D^D^[^[^D^D^D^D^Z^Z^Z^Z^Z^Z
This is because the connection to server may have been broken, so your terminal is just echoing what you do instead of being able to show you what the command or the server was responding. The way to get out of ssh in such is to use termination sequence ~ + . + Enter. Enter may not be always required
Below are the list of SSH escape sequences
~. - terminate connection (and any multiplexed sessions)
~B - send a BREAK to the remote system
~C - open a command line
~R - Request rekey (SSH protocol 2 only)
~^Z - suspend ssh
~# - list forwarded connections
~& - background ssh (when waiting for connections to terminate)
~? - this message
~~ - send the escape character by typing it twice
PS: Taken from https://lonesysadmin.net/2011/11/08/ssh-escape-sequences-aka-kill-dead-ssh-sessions/

SSH escape sequence in passphrase

I need to remove the passphrase from an SSL private key file. I'm using
openssl rsa -in in.key.pem -out out.key.pem
to do that. The issue I'm facing is that the passphrase for that keyfile (the passphrase is being generated on a different machine somewhere) looks something like this:
~Casdfghetc
As you've probably figured out, the "~C" part of that passphrase spawns a new command line and leaves me unable to correctly enter the passphrase. Quoting, double-quoting and so forth don't work.
I'm using putty to connect to this shell, hopping through a golden host (powerbroker). This is a productive, secure environment, so I cannot log into the machine any other way. Any tips on how I can get this to work?
Way 1. As http://www.jedi.be/blog/2010/08/27/ssh-tricks-the-usual-and-beyond/ points out:
Escape sequences are only recognized after a newline
So, when asked for a passphrase, you can do the following:
Type some letter before typing your passphrase, e.g. a.
Press Backspace key to undo/remove it.
Type your passphrase as usual.
Way 2. On my system, pressing "~?" shows the following help:
Supported escape sequences:
~. - terminate connection (and any multiplexed sessions)
~B - send a BREAK to the remote system
~C - open a command line
~R - request rekey
~V/v - decrease/increase verbosity (LogLevel)
~^Z - suspend ssh
~# - list forwarded connections
~& - background ssh (when waiting for connections to terminate)
~? - this message
~~ - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)
So, to insert tilde (~) right after newline, I need just to press it twice (~~). Probably, the same is true for you system: just type ~~Casdfghetc instead of ~Casdfghetc.

TELNET: Pasting a carriage return into the console

I want to issue then following requests to a telnet session:
telnet www.example.com 80
GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n
Telnet doesn't seem to recognise the '\r\n' as a carriage return and just sends the lot on to the remote host. What should I put in place of '\r\n' to render a carriage return in the telnet terminal. It does work when I paste the following into the terminal:
GET / HTTP/1.1
Host: www.example.com
Connection: close
followed by two presses of the RETURN key. Is there a hex code I can send to telnet i.e. \0x01 or something like that?
Can I change the options of the TELNET shell to show what I pasted also? I can't find a way to do SET LOCALECHO since I'm opening the TELNET shell and connecting at the same time.
Thanks for any help on this.
/r/n is a perfectly acceptable carriage return line feed character for ANSI, which is what most telnet clients communicate in. Are you applying the # sign in front of your string?
ie:
#"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n";
If you are trying to type in /r/n and pasting that input in raw, then the telnet component will often assume you wanted the characters sent as they are type(not as new lines) and do so accordingly.

Forwarding signal to remote child from local parent over ssh

I have a script which executes remote command and redirect output to local file.
Remote command just reads list of pcap files continuously and writes to stdout.
The final command is like this -
ssh root#host /sbin/path-to-utility | cat > local-file
The script which executes this remote command needs to have signal handler to save the state of overall transfer.
Also I want to send signal to remote command or process to stop reading pcap files, so that exit after finishing writing current file.
I tried -t option and signal handling works perfectly fine, but it adds some extra characters to the actual output written by remote command and disturbs my pcap data.
Either I need to handle signal without -t option over ssh or I need to find out why ssh -t is adding additional bytes to actual data.
Please help!
Thanks,
Sachin.
The -t option tells ssh to allocate a terminal. The extra characters are intended to be interpreted by your terminal.
Perhaps then you should tell ssh you are using a different terminal, one that will not generate any extra characters, but will still pass on signals. Does this work?
TERM=dumb ssh root#host /sbin/path-to-utility | cat > local-file
(I don't know what would be the best value to use for TERM.)

telnet to port 25 from AS400

I want to very SMTP connectivity from an AS400 in a VM to a mailserver on port 25
The native telnet command on the as400 does not seem to support a port specification.
Any ideas how to telnet from as400 to port 25 on my mailserver?
I can ping the mailserver from the as400
I can telnet in from other boxes (non as400)
I just tried this on an i5/OS V5R4:
TELNET RMTSYS(hostname) ASCOPRMOD(*VT100) PORT(25)
I also found an IBM manual about telnet support in V5R2 that suggests you can also specify a port in older versions.
Type "TELNET" on the command line, press F4, fill out the remote system name, press F10, page down, page down, locate "Port" field. Change it from "*DFT" to "25". Press Enter.
When done, press F9 to get the corresponding command line invocation.