Skip to main content

capture credentials from bash history | .bash_history | ~/.bash_history | clear history or clear bash history in linux

https://attack.mitre.org/techniques/T1552/003/

 

attacker may search bash command history on compromised systems because sometimes users tend to pass username and password over command line to the program. 

when user logs out then all the commands are flushed out to .bash_history file. for each user the file resides in the same location. ~/.bash_history 

attacker can abuse this by looking through the file for potential credentials. 

 

Mitigation:

there are multiple methods of preventing a users command history from being flushed to their .bash_history file, including use of the following commands:

off logging:

set +o history

and set -o history to start logging again. 

 

another way:

clean command history:

history -c

to make sure changes are written to disk, use:

history -w 

to make more sure the history is cleared when existing a session, the following command comes in handy:

cat /dev/null > ~/.bash_history && history -c && exit

 

 

 

 

 

permanently disable bash history:

echo 'set +o history' >> ~/.bashrc

next time when user login to the shell it will not store any commands to a history file .bash_history

to apply this settings immediately for the current shell session execute the .bashrc file:

. ~/.bashrc

 

disable a command history system wide:

echo 'set +o history' >> /etc/profile

it will be effective for the new users created after this.

 

 

if you dont have write permission on .bash_profile file then run the below command:

commands are written to the HISTFILE environment variable, which is usually .bash_history. we can echo it to see the location:

echo $HISTFILE

/root/.bash_history (this is the location)

we can use the unset command to remove the variable:

unset HISTFILE

now if we echo it then nothing will shows up. 

 

we can also make sure the command history is not stored by sending it to /dev/null

or export HISTFILE=/dev/null 

or HISTFILE=/dev/null

and now history will now be sent to /dev/null

echo $HISTFILE

/dev/null

then all commands afterwards wont be logged within that session. 

or if you have write permission, and want this behavior in each login then:

echo 'unset HISTFILE' >> ~/.bash_profile

echo 'unset HISTFILE' >> ~/.bashrc

 

ln -s /dev/null ~/.bash_history

 

 

 

Comments

Popular posts from this blog

Install Nessus from docker

The below two commands you need to run first one by one:  docker run -itd --name=ramisec_nessus -p 8834:8834 ramisec/nessus docker exec -it ramisec_nessus /bin/bash /nessus/update.sh Username: admin And you need to change the password: #Enter the command line of the docker container docker exec -it ramisec_nessus bash #Execute the following commands in sequence # Enter this directory cd /opt/nessus/sbin # List logged in users ./nessuscli lsuser # Modify the password of the specified user (take admin as an example) ./nessuscli chpasswd admin After access to the nessus, make sure you turn off the automatic updates otherwise crack will not work after some time. Before any scan you need to run the update.sh command (shown above) to have the latest plugins. Now everytime your system reboots, your docker instance will be shutdown. You need to up it again manually. Here are the commands.  1. docker ps -a    Now note down the container id. 2. docker start <container id> C

net command cheat sheet

  To see what users present in the system: net user To see local groups in the system: net localgroup To see domain groups. This should be run on a domain controller: net group To see the details of a user along with his/her group membership: net user mahim To see who are the members of a particular group (local machine): net localgroup "administrators"    (These are not case sensitive. You can use administrators or Administrators. Both will give you same result. To see who are the members of a particular group (domain machine): net group "domain admins" Create a local user: net user localuser1 MyP@ssw0rd /add Create a domain user: net user domainuser1 MyP@ssw0rd /add /domain Add the local user to local admin group: net localgroup Administrators localuser1 /add Add the user to domain admin group: net group "Domain Admins" domainuser1 /add /domain Avi