
Biblioteca y cliente de Python para manipulaciones de tokens y suplantaciones para escalada de privilegios en Windows
PYTMIPE (biblioteca de Python para Manipulación de Tokens y Suplantación para Escalada de Privilegios) es una biblioteca de Python 3 para manipular tokens de Windows y gestionar suplantaciones con el fin de obtener más privilegios en Windows. TMIPE es el cliente de Python 3 que utiliza la biblioteca pytmipe.
Diapositivas "Windows Token Manipulation, Impersonation & Privilege Escalation" (Inglés): enlace
Artículo en MISC 112 (Francés): enlace
| Método | Privilegio(s) Requerido(s) | SO (no exhaustivo) | Objetivo directo (máx) |
|---|---|---|---|
| Creación y suplantación de token | nombre de usuario y contraseña | Todos | administrador local |
| Suplantación/Robo de token | SeDebugPrivilege | Todos | nt authority\system |
| Suplantación de PID padre (herencia de identificadores) | SeDebugPrivilege | >= Vista | nt authority\system |
| Servicio (SCM) | Administrador local (y nivel de integridad alto si UAC está habilitado) | Todos | nt authority\system o cuenta de dominio |
| Evento WMI | Administrador local (y nivel de integridad alto si UAC está habilitado) | Todos | nt authority\system |
| « Printer Bug » LPE | SeImpersonatePrivilege (cuenta de servicio) | Windows 8.1, 10 & Server 2012R2/2016/2019 | nt authority\system |
| Servicio RPCSS LPE | SeImpersonatePrivilege (cuenta de servicio) | Windows 10 & Server 2016/2019 | nt authority\system |
La siguiente lista no exhaustiva muestra algunas características implementadas en la biblioteca pytmipe:
ctypes se utiliza la mayor parte del tiempo. Muchas características de pywin32 han sido re-desarrolladas en pytmipe para evitar el uso de pywin32 y obtener mejor portabilidad. Sin embargo, el módulo del Programador de tareas aún utiliza pywin32 (más precisamente pythoncom) por falta de tiempo. Todos los demás módulos usan solo ctypes.
Para el cliente python (llamado tmipe):
python.exe tmipe.py -h
usage: tmipe.py [-h] [--version]
{cangetadmin,printalltokens,printalltokensbyname,printalltokensbypid,printsystemtokens,searchimpfirstsystem,imppid,imptoken,printerbug,rpcss,spoof,impuser,runas,scm}
...
**
888888 8b d8 88 88""Yb 888888
88 88b d88 88 88__dP 88__
88 88YbdP88 88 88""" 88""
88 88 YY 88 88 88 888888
-------------------------------------------
Token Manipulation, Impersonation and
Privilege Escalation (Tool)
-------------------------------------------
By Quentin HARDY ([email protected])
positional arguments:
{cangetadmin,printalltokens,printalltokensbyname,printalltokensbypid,printsystemtokens,searchimpfirstsystem,imppid,imptoken,printerbug,rpcss,spoof,impuser,runas,scm}
Choose a main command
cangetadmin Check if user can get admin access
printalltokens Print all tokens accessible from current thread
printalltokensbyname
Print all tokens accessible from current thread by account name
printalltokensbypid Print all tokens accessible from current thread by pid
printsystemtokens Print all system tokens accessible from current
searchimpfirstsystem
search and impersonate first system token
imppid impersonate primary token of selected pid and try to spawn cmd.exe
imptoken impersonate primary or impersonation token of selected pid/handle and try to spawn cmd.exe
printerbug exploit the "printer bug" for getting system shell
rpcss exploit "rpcss" for getting system shell
spoof parent PID Spoofing ("handle inheritance)"
impuser create process with creds with impersonation
runas create process with creds as runas
scm create process with Service Control Manager
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
Para la biblioteca python (llamada pytmipe), consulte el código fuente y los ejemplos. Normalmente, he documentado bien el código fuente... La mayoría de las funciones están documentadas.
Para los ejemplos de pyinstaller y ejecutables independientes, consulte los archivos en las carpetas src/examples/.
Si desea saber cómo usar la biblioteca pytmipe, consulte la carpeta src/examples para ver muchos ejemplos.
Para suplantar el primer token system y obtener un símbolo del sistema cmd.exe como system desde el cliente python (tmipe):
python.exe tmipe.py searchimpfirstsystem -vv
Para hacer lo mismo directamente con la biblioteca pytmipe, consulte src/examples/searchAndImpersonateFirstSystemToken.py:
from impersonate import Impersonate
from utils import configureLogging