martes, 27 de marzo de 2012

Descomprimir archivos en Linux desde la consola

En modo gráfico tenemos el gestor de archivadores para facilitarnos la vida. Pero, ¿cómo tratar con archivos comprimidos o empaquetados como los tgz, tar, bz2 o rar en la consola?

TAR

Se trata de un archivo que combina varios archivos en uno, no hay compresión de datos. Para extraer el contenido usamos el comando tar con los flags x (extract, extraer) y f (file, desde un archivo), y opcionalmente v (verbose) para mostrar por pantalla el proceso o vv para mostrar no solo los archivos y carpetas creadas, sino información sobre estas.
tar xvf archivo.tar

GZ

Se trata de un archivo comprimido con gzip. Para descomprimir utilizamos el comando gzip con el flag -d (descomprimir) o bien el comando gunzip, que no es más que un enlace a gzip.
gunzip archivo.gz
gzip -d archivo.gz

TGZ, TAR.GZ

Un archivo empaquetado con tar y comprimido con gunzip. Se descomprime de la misma forma que los tar, añadiendo el flag z para indicarle que use gzip para descomprimir.
tar xvzf archivo.tar.gz

BZ2

Archivo comprimido con bzip2. Para descomprimir se usa el comando bzip2 con el flag -d (descomprimir) o bien el comando bunzip2, que no es más que un enlace a bzip2.
bunzip2 archivo.bz2
bzip2 -d archivo.bz2

TAR.BZ2

Similar a los archivos tar.gz, pero se usó bzip2 para comprimirlo. Para descomprimir se usa también tar, con el flag j en lugar de z:
tar xvjf archivo.tar.bz2

ZIP

Archivo comprimido con zip. Se descomprime usando el comando unzip:
unzip archivo.zip

RAR

Formato propietario de RarLab, creadores del famoso Winrar. Normalmente el comando rar no está instalado en el sistema
sudo aptitude install rar
Se descomprime con el flag -x (eXtract, extraer)
rar -x archivo.rar

linux command cheat sheet

Basic Syntax for Find command :
find (name/size/type/access or modified date) ..argument ..argument
Search for file ending .conf
find /etc/ -name *.conf
Search for directories ending with *conf
find /etc/ -type d -name *conf
Search for files ending with .doc and accessed in last 24 hours(or 1 day)
find /home/xyzuser/ -name *.doc -atime -1
Find files modified by minutes
Syntax : find /path/ -mmin
Find files 10 minutes ago
find /etc/ -mmin -10
Find files more then 10 minutes ago
find /etc/ -mmin +10
Find files modified between 10 to 20 minutes ago
find /etc/ -mmin +10 -mmin -20
Find files modified in past 2 days(48 hours)
find /etc/ -mtime -2
Search for files owned by xyz user
find /etc/ -type f -user xyz
Search for directories and change permission to 755
find /home/xyz.com/public_html/ -type d -exec chmod -v 755 {} \;
These are find command example used by every admin most frequently.
For further reading do
man find or man 1 find

viernes, 27 de enero de 2012

Linux Detecting / Checking Rootkits with Chkrootkit and rkhunter Software

Q. Most rootkits use the power of the kernel to hide themselves, they are only visible from within the kernel. How do I detect rootkits under CentOS or Debian Linux server?

A.A rootkit is a program (or combination of several programs) designed to take fundamental control (in Unix terms "root" access, in Windows terms "Administrator" access) of a computer system, without authorization by the system's owners and legitimate managers.

Detecting rootkits under Linux

You can try the following tools to detect Linux rootkits:
WARNING! These examples should run from Live CD (Linux Live Security CD) for the best result.

Zeppoo Software

Zeppoo - Zeppoo allows you to detect rootkits on i386 and x86_64 architecture under Linux, by using /dev/kmem and /dev/mem. Moreover it can also detect hidden tasks, connections, corrupted symbols, system calls and so many other things. Download source code here

Chkrootkit Software

Chkrootkit - chkrootkit is a tool to locally check for signs of a rootkit. Type the following command to install chkrootkit
$ sudo apt-get install chkrootkit
Start looking for rootkits, enter:
$ sudo chkrootkit
Look for suspicious strings, enter:
$ sudo chkrootkit -x | less
You need to specify the path for the external commands used by chkrootkit such as awk, grep and others. Mount /mnt/safe using nfs in read-only mode and set /mnt/safe binaries PATH as trusted one, enter:
$ sudo chkrootkit -p /mnt/safe

rkhunter software

rkhunter - rkhunter (Rootkit Hunter) is a Unix-based tool that scans for rootkits, backdoors and possible local exploits. rkhunter is a shell script which carries out various checks on the local system to try and detect known rootkits and malware. It also performs checks to see if commands have been modified, if the system startup files have been modified, and various checks on the network interfaces, including checks for listening applications. Type the following command to install rkhunter:
$ sudo apt-get install rkhunter
The following command option tells rkhunter to perform various checks on the local system:
$ sudo rkhunter --check
The following command option causes rkhunter to check if there is a later version of any of its text data files:
$ sudo rkhunter --update
The following option tells rkhunter which directories to look in to find the various commands it requires:
$ sudo rkhunter --check --bindir /mnt/safe

Recommended readings:

  • man pages - rkhunter and chkrootkit
  • rkhunter Project home page
  • chkrootkit Project home page