Search code examples
x11vncxterm

Xterm control sequence to 'T' output to a file


I swear there used to be a way in X to start capturing all terminal traffic to a file on your host. It may have been a HummingBird extension, but I thought it was standard. Now, I can't find the trick. Am I hallucinating (happens when you get old), or is it possible?

I'm not talking about 'tee'. I want to be able to send a xterm control-sequence to stdout, giving a file name, and have everthing shown in the window from that time onward saved to the file (until the bookend cancel is issued).


Solution

  • This feature is called logging and exists in the source code but is disabled by default for security reasons. Do you really want everyone with the ability to write control sequences to your terminal (e.g., the author of any file you might one day cat) to be able to write arbitrary data to arbitrarily-named files under your account?

    For example, an attacker could easily use this functionality to modify your ~/.ssh/authorized_keys to grant the attacker access, and change your ~/.profile to ping the attacker with your IP address.

    That said, if you compile xterm with --enable-logging AND you #define ALLOWLOGFILECHANGES, then according to the Xterm Control Sequences manual, you will gain access to the following control sequences:

    ^[[?46h            Start logging
    ^[[?46l            Stop logging
    ^[]46;filename\007 Change log file to `filename`
    

    The log file name will by default be called Xterm.log.hostname.yyyy.mm.dd.hh.mm.ss.XXXXXX.

    There is also an option to enable logging through a pipe, which is also very dangerous if you allow changing the logger via control sequences. That would also allow anyone to execute their code on your system.