Links

Linux General

Manipulación de Archivos

Ver tamaño de un archivo

du -hs $FILE

Buscar las diferencias

diff $FILE1 $FILE2 # Muy útil para modificaciones de código en la OSCP

Hacer backup con RSync

# Syncronizar (Con borrado de archivos inclusive) CarpetaA con CarpetaB
sudo rsync -avh --delete $SOURCE/ $DEST

Insertar contenido en archivo desde la consola

# One liner. Sustituye todo el contenido actual del archivo
echo "esto es el contenido" > $FILE
# One liner. Añade al final del contenido actual del archivo
echo "esto es el contenido" >> $FILE
# Añadir varias líneas
cat <<EOT > $FILE
>Esto
>es el
>contenido
EOT

Encriptación

Crear partición con LUKS

cryptsetup -y -v luksFormat /dev/xvdc
cryptsetup luksOpen /dev/xvdc backup2
mkfs.ext4 /dev/mapper/backup2
mount /dev/mapper/backup2 /backup2

Servicios y Procesos

Con systemctl

# Iniciar servicio
systemctl start $SERVICE
# Ver status servicio
systemctl status $SERVICE
# Añadir servicio al startup
systemctl enable $SERVICE
# Quitar servicio del startup
systemctl disable $SERVICE
# Listar todos los servicios
systemctl list-units --type=service

Con Journalctl

# Ver los logs en busca de un servicio
journalctl -u ssh.service --no-pager

Terminar un proceso con Kill

# Ver listado de métodos
kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
# Los métodos más usados
1 SIGHUP - This is sent to a process when the terminal that controls it is closed.
2 SIGINT - Sent when a user presses [Ctrl] + C in the controlling terminal to interrupt a process.
3 SIGQUIT - Sent when a user presses [Ctrl] + D to quit.
9 SIGKILL - Immediately kill a process with no clean-up operations.
15 SIGTERM - Program termination.
19 SIGSTOP - Stop the program. It cannot be handled anymore.
20 SIGTSTP - Sent when a user presses [Ctrl] + Z to request for a service to suspend. The user can handle it afterward.
# Matar un proceso si se freezea
kill 9 $PID

Gestión del Background y Foreground de procesos

# Suspender un proceso
Ctrl + Z
# Ver todos los procesos en background
jobs
# Para que un proceso continue ejecutandose en background
bg
$COMANDO_A_EJECUTAR & # Segunda opción
# Traer un proceso al foreground
jobs
fg $NUMBER

Búsqueda de Archivos

# Si sabemos el tipo de archivo exacto que necesitamos y no neceistamos manipularlo
locate $FILE
# Si no sabemos muy bien que necesitamos y además necesitamos manipular el resultado
find / -type f -name *.conf -user root -size +20k -newermt 2020-03-03 -exec ls -al {} \; 2>/dev/null

Permisos

# Cambiar permisos de un archivo
chmod $OCTAL_VALUE $FILE
Binary Notation: 4 2 1 | 4 2 1 | 4 2 1
----------------------------------------------------------
Binary Representation: 1 1 1 | 1 0 1 | 1 0 0
----------------------------------------------------------
Octal Value: 7 | 5 | 4
----------------------------------------------------------
Permission Representation: r w x | r - x | r - -
# Cambiar propietario
chown $USER:$GROUP $FILE

Hardening

Borrar historiales de consolas

# Desactivar historiales y rastros de consola
unset HISTFILE; unset SAVEFILE
rm ~/.bash_history
ln -s /dev/null ~/.bash_history
export HISTFILE=/dev/null
export SAVEFILE=/dev/null
rm ~/.zsh_history
ln -s /dev/null ~/.zsh_history

Desactivar Blueetooth (Ubuntu)

sudo vim /etc/bluetooth/main.conf
> AutoEnable=false

Spoofing

Spoofear MAC

# Change MAC address
sudo macchanger -r $IFACE

Spoofear Hostname

# Cambiar hostname correctamente
#!/bin/bash
HOSTNAME="hostname"
LOCALHOST="127.0.0.1 ${HOSTNAME}"
/bin/hostname ${HOSTNAME} && /bin/hostnamectl set-hostname ${HOSTNAME} && /bin/echo "${HOSTNAME}" > /etc/hostname && /bin/sed -i "3s/.*/$LOCALHOST/" /etc/hosts