Wednesday, February 22, 2012

Pseudo terminal hack in Linux

Hello all,
Lets see interesting demo on posting message into pseudo terminals of another user. There may be cases where there are multiple user logged in a linux machine as a root and you want to convey some message to a user. For example, may be you require to kill a process which is owned by a terminal and you want to convey that to the terminal owner before you process. Or think about any practical use case which you might come across. You are not sure where the user is located or working from. He may be in office or at home. It is quite difficult to identify using the ip address from where he is logged in. Since the login user name is root, it is also difficult to find out who is he. Here i am trying to post a hack, please use it for ethical purpose only. since this causes inconvenience to the users logged in that machine..

First, check how many users are logged in. "who" command lists the users logged in. There are 3 users are logged in.


Currently for demo purpose I connected 3 sessions from the same machine to remote host. so it is showing same ip address in the list. ( in real case, the ip list may vary, as sending message to your terminal doesnt make sense, isnt it ? )

One way is to use 'wall' command to convey this message to all in one shot. It is shown in the picture below.

The problem with this command is, it is passing this message to all the user logged into that machine. If you want to send message to only one user, then follow these steps.

1. Identify which user you want to send message. Lets chose user with pseudo terminal "pts/2".


2. Identify the device associated with this terminal i.e pts/2. All the files associated with the pts are located at /dev/pts/. List this directory to see the files.


3.RUn the following command to post a message to pts/2.
echo "Please do not modify rsyslog.conf" > /dev/pts/2


You can see that the message sent in first window is appeared in 3rd window. The same message is not shown in middle window whose pts id is pts/1.

Hope you like it, please leave comments behind. Thanks.



Pin It
Related Posts Plugin for WordPress, Blogger...