Linux
Last updated
Last updated
Check user (id, whoami)
Run Linux Smart Enumeration with increasing levels.
Run LinEnum & other scripts as well
Manual command -->
Strategy: Spend some time and ead over the result of the enumeration
If lse.sh
level 0 or 1 finds something interesting, make a note.
Avoid rabbit holes by creating a checklist of things need for the priv esc method to work.
have a quick look around for files in user's home, and other common locations (/var/backup, /var/logs and history file)
first method to try --> sudo, cron jobs, SUID files.
check at root process, enumerate their versions and search for exploits.
check internal port that might be able to forward to attacking machine.
stuck?
re-read full enumeration dumps and highlight anything that seems odd.
process or file name aren't familiar, an "unusual" filesystem config, a username.
still havn't the root?
Do kernel exploit.
Enum with tools
check port
the service port on the victim machine, now available for <kali port> in loopback of the kali machine.
Copy the hash to the Kali linux as root.hash
crack the hash
switch to root user
Then replace the root hash in /etc/shadow with new hash.
Login to root using hacker
as password.
The root account in /etc/passwd is usually configured like this:
the x
in the second field mean that linux must look for the password hash in the /etc/shadow file.
in some versions of linux, it is possible to simply delete the "x", and linux interprets as the user having no password:
or generate the hash password to replace the "x"
result:
replace the "x" with new hash.
a user may have created insecure backups of these files.
It is always worth exploring the file system looking fo readable backup files. some common places include user home dir, the / (root) dir, /tmp, and /var/backups.
if you can read the backup of ssh key (private key), it is a good one.
check this first before using the ssh key to login as root.
It indicate you could ssh to machine as root.
Next, copy the key to the kali machine.
then give the permission:
login ssh with the key
check the program which able to run without password as sudo. And search to gtfobins to get root shell.
If you can't see in the grfobins try to abusing the functionality to read/write a file and combine with other technique.
example: apache2
requirements: program could run by sudo in sudo -l
env_keep+=LD_PRELOAD
identification:
preload.c
compile the preload
now run any allowed program running with sudo (sudo -l).
example: find
env variable contains a set of directories where shared libraries are searched for first. print shared libraries --> ldd /usr/sbin/apache2.
exploit: create a shared library with the same name as one used by a program, and setting LD_LIBRARY_PATH to its parent directory, the program will load our shared library instead.
Identification:
pick shared library in the program (eg: libcrypt.so.1)
create a c script called libarary_path.c
comple the script:
set LD_LIBRARY_PATH to current directory:
then run this command to update .bashrc
Note:
default using /bin/sh
location of crontabs --> /var/spool/cron/
or /var/spool/cron/crontabs/
the system-wide crontab is located at /etc/crontab
If we can write to a program or script which gets run as part of a cron job, we can replace it with our own code.
Put a reverse shell or rootbash.
The crontab PATH env is by default set to /usr/bin:/bin
If a cron job program/script doesn't use an absolute path, and one of the PATH dir is writable by our user, we may able to create a program/script with the same name as the cron job.
example:
sample script:
execute the rootbash
if crontab execute a command with * (wildcards) mean all file in directory. you can put a command as a file name.
check program in the gtfobins for command to spawn a shell
In the picture above, it mean we need to injec command "--checkpoint=1 --checkpoint-action=exec=/bin/sh"
so create a fake file with that command.
SUID --> files get executed with the privileges of the file owner.
SGID --> files get executed with the privileges of the file group.
If the file owned by root, it gets executed with root privileges, and we may able to escalate privileges.
SUID
SGID
SUID + SGID (sometimes error):
search in gtfobins for uncommon binaries.
Identification
search: Uncommon setuid binaries
then enum the version and search in searchsploit or exploit db
When a program is executed, it will try to load the shared objects it requires. using program "strace", could track the system calls and determine whether any shared object were not found.
Important note: Must have access to write to the location the program tries to open, It needed to create a shared object and spawn a root shell when it is loaded.
example: /usr/local/bin/suid-so
example output: search the directory which writable for current user.
libcalc.c
compile
then re run the program
/usr/local/bin/suid-so
Finding Vulnerable Program which running other program.
example inject the service command:
service.c
compile
execute command again, to get shell.
PATH=.:$PATH /usr/local/bin/suid-env
How about if the command use an absolute path?
but the /bin/sh and /bin/bash is version < 4.2-048, then it is possible to define user function with an absolute path name.
These functions can be exported so that subprocesses have access to them, and function can take over the actual executable being called.
example: the command call other program with /usr/sbin/service
then execute the command again.
How about if the command use an absolute path?
and run another program via bash (by using system())
note: In bash version 4.4 and above, the PS4 env is not inherited by shells running as root.
work on bash version < 4.4
example : /bin/bash --version --> 4.1.5
try reuse password, weak password storage .
look at config file
If the root user re-used their password for a service, that password may be found and used to switch to the root user.
interesting files:
ovpn files
NFS shares are configured in the /etc/exports
file.
Remote users can mount shares, access, create, modifiy files.
By default, created files inherit the "remote" user's id and group id (as owner and group respectively), even if they don't exist on the NFS server.
Useful command:
Root squashing is how NFS prevents an obvious privilege escalation. If the remote user is (or claims to be) root (uid=0), NFS will instead "squash" and treat as "nobody" user, in the "nogroup" group. (default configuration)
generate shell (must as root in the kali machine)
Enumerate kernel version (uname -a)
Find matching exploit (Google, Exploit-DB, Github)
Compile and run
searchsploit
Search the service and version in the
for checking live cron job use pspy -->
generate shell.elf with msfvenom -->