Unix

Tips

  • History of commands can be found under .bash_history.
  • .bashrc contains commands which are loaded or executed automatically when the terminal is opened.
  • Password calls can be found by grepping passwd from .bash_history. (if not hidden)
  • /etc/cron.daily contains scripts that are executed automatically.
  • Check /tmp and /etc/vat/tmp for interesting files.
  • Check mysql -u root to login as root in mysql servers running on linux (if not authenticated).
  • find -exec can be used for privilage escalation if it is allowed to run by other users.
  • $(command) in a line will execute command first in that line
  • sudo nmap -sP -PI -PT 192.168.1.1/24 to find the devices in a network

find

-exec

  • find /home -name .bashrc -exec grep [PATTERN] {} \;
  • The find command has -exec which can be used to chain commands.
  • Note the ending {} \;. Should not be omitted.

grep

-A

  • Show __ number of lines after the match.

chmod

File permissions:

  1. r: read
  2. w: write
  3. e: execute
  4. t: sticky bit. The sticky bit only allows the user who created a file in this directory (or the owner of the directory, ie: root) to modify this file.

Eg: -rw-rw-r-- Split that into 4:

- | rw- | rw- | r--

  1. - indicates that its a file (d for directory)
  2. rw- indicates that read and write is there for owner ‘Home’.
  3. Next rw indicates that read and write is there for any ‘Home user’.
  4. r-- indicates that there read only permission for any user.

chmod to change permissions.

Eg:

chmod 764

‘764’ absolute code says the following:

  • Owner can read, write and execute
  • Usergroup can read and write
  • World can only read

Zipping and Unzipping

TAR compressed

.tgz files

Unzip:

tar zxvf fileNameHere.tgz (notice the z)

Unzip and put into a different folder:

tar zxvf backups.tgz -C /tmp/data

  • -z : Uncompress the resulting archive with gzip command.
  • -x : Extract to disk from the archive.
  • -v : Produce verbose output i.e. show progress and file names while extracting files.
  • -f backup.tgz : Read the archive from the specified file called backup.tgz.
  • -C /tmp/data : Unpack/extract files in /tmp/data instead of the default current directory.

.tbz files

Unzip:

tar jxvf fileNameHere.tgz (notice the j)



Bzip2 compressed

.tar files

Unzip:

bzip2 -z backup.tar

.bz2 files

Unzip:

bzip2 -d file.bz2


Privilage Escalations

More on that can be read here