Friday, 26 February 2016

Linux Hacks 1.1: Leave no Trace on the Terminal

  1. Are you doing something you are unauthorized to do? 
  2. Are you using the terminal?
  3. Do you want to leave no trace on the terminal?

If the answer is yes here's the article. For those who are in a hurry. Here's your command


kill -9 $$
type this before you exit the terminal. No history will be saved.


Linux Terminal History

Linux Terminal stores the history of commands you fired. This is indeed a great feature as long your answer to the above three features is no.
If you wish to see the last fired command just press the up arrow key , press it twice and you'll see the last but one command and so on.
Press the down arrow key to see more recent commands and up arrow key for the older commands.
Apart from this type the history command in your terminal and you'll get an output like this:-
history

    1  history -w
    2  history -w
    3  history -d 1
    4  history
    5  history -d all
    6  history -d 1,2,3,5
    7  history -d 1 2
    8  history

Just imagine doing a malicious activity and the system admin typing this command. Well since you are here, you are on the right track to avoid this from happening. I will now list out one of the alternative. I personally don't prefer this method.

history -c
this command will flush out the current history. Now just press your favourite panic button ctrl+D. This will get you out of the terminal. And there will be no history or trace for the current session.

My Method

 kill -9 $$
  • kill command is used to terminate a process, technically it actually stands for sending a signal.
  • $$ expands to the pid of the bash shell.
Try these commands to get an idea:-
  1. echo $$
  2. ps $$
  • -9 stands for  kill all processes you can kill. Don't worry it will just kill your bash process leaving no trace.
  • The default kill switch is 15. The switch allows the to kill the process gently with proper cleanup. However -9 option tells the Operating System to kill it immediately without cleanup or in short kill the process immediately.
  • Actually bash history is saved only after proper termination of your terminal window.
  • Generally I have this copied and quickly paste it with mouse. Since Ctrl+v doesn't work on the terminal. Press the mouse middle button to quickly paste the last highlighted text.Which means you are supposed to type this command somewhere and then highlight it. And the ensure that you do not highlight any thing else.

Mistake Made 

In case you made the mistake of not pressing this command before using the panic button. Well I still got you covered.
If you are short on time. Then here's the unsafe method since this will make you appear suspicious. This method will leave no terminal history.

HISTSIZE=0
history -w
kill -9 $$

Note:- I recently tested this command sequence on a older fedora machine. However it seemed to leave some history.Do perform tests n leave a comment if you find any problems with this method. The method given below however always works without any issues.


In case you have got the time then use the safer approach.Here the current history after typing the history command.

history
    1  needs to be deleted
    2  waka wake
    3  weproi
    4  delete this also
    5  history
so here's what you need to do. Locate the bash_history file. Terminal command
locate bash_history
Output will be one or more lines but you only need to edit the lines of the current user's bash file.
/home/pc/.bash_history

Please use GUI now and close all terminals. Remove the lines which are to be removed using a text editor. And save the file.

Note:- This file is hidden which implies it cannot be seen in GUI. So enable the show hidden files option. If you are an nautilus file manager(File Manger for Ubuntu,Fedora,etc ) just use Ctrl+H. And you will be able to see it.

I have taken all care to ensure that all these methods are working.Just in case any method is not working. Leave a comment immediately so that i can update this article. I will be further adding a part 2 to this article. So do look back here. 

Suggestions

  1. Improve your typing speed. Mine is 60 wpm and improving
  2. Practice these commands before itself. These should always be on your finger tips. You better develop some muscle memory for these commands.

Next in the Series

The next article in the series offers a even better way for leaving no trace. This method is way safer and better. If this article taught you how to remove a bullet after being shot, the next one will tell you how to avoid being shot.




* Warning
      Messing with history(if caught) will land you up in trouble with the system admin. This will not work if your key log is stored and your keystrokes were being monitored. This article is strictly written for educational purposes. I take no responsibility for your actions or any damage that you cause to the system. I do not in any way promote malicious or unauthorized activity. Let me repeat:- STRICTLY FOR EDUCATIONAL PURPOSES.






 

No comments:

Post a Comment