精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
void SetPrivilege( const ATL::CStringT< <TCHAR, ATL::StrTraitATL< <TCHAR> > &lpszPrivilege, bool bEnablePrivilege) { ATL::CAccessToken ProcToken; ProcToken.GetEffectiveToken(TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES); if(bEnablePrivilege) { ProcToken.EnablePrivilege(lpszPrivilege); } else { ProcToken.DisablePrivilege(lpszPrivilege); } }
Figure 12: Enabling a group policy privilege.
Group policy privileges are turned off by default, even when enabled in group policy. You have to turn them on by changing your access token. You should be prepared to handle the case when the privilege is disabled in group policy (and you can't turn it on, no matter how hard you try). When you've finished with the privilege, don't forget to turn it back off.即使在组策略中启用了组策略特权,默认情况下也会将其关闭。您必须通过更改访问令牌来打开它们。当组策略中的特权被禁用时,您应该准备好处理这种情况(无论您如何努力,都无法将其打开)。完成特权后,别忘了将其关闭。
This is a Whoami clone. To make life easier, we won't decrypt the attributes from a number to text (unlike what Whoami does).
这是Whoami克隆。为了使生活更轻松,我们不会解密从数字到文本的属性(与Whoami有所不同)。
void DoWhoAmI(void) { size_t i = 0; ATL::CAccessToken ProcToken; ATL::CSid SidUser; ProcToken.GetEffectiveToken(TOKEN_QUERY); /* First print off the user. */ ProcToken.GetUser(&SidUser); std::wcout << _T("Owner: ") << SidUser.AccountName() << _T("\r\n"); /* Now print the groups */ ATL::CTokenGroups pGroups; ProcToken.GetGroups(&pGroups); ATL::CSid::CSidArray pSids; ATL::CAtlArraypAttributes; pGroups.GetSidsAndAttributes(&pSids, &pAttributes); /* Iterate both pSids and pAttributes simultaneously */ std::wcout << _T("\r\nGroups\r\n"); for(i = 0; i < pGroups.GetCount() ; i++) std::wcout << pSids[i].AccountName() << _T(": ") << pAttributes.GetAt(i) << _T("\r\n"); /* Get the list of Privileges */ ATL::CTokenPrivileges pPrivileges; ProcToken.GetPrivileges(&pPrivileges); ATL::CTokenPrivileges::CNames pNames; ATL::CTokenPrivileges::CAttributes pGroupAttributes; pPrivileges.GetNamesAndAttributes(&pNames, &pGroupAttributes); /* Printing Privileges is very similar to */ std::wcout << _T("\r\nPrivileges\r\n"); for(i = 0; i < pGroups.GetCount() ; i++) std::wcout << static_cast (pNames.GetAt(i)) << _T(": ") << pGroupAttributes.GetAt(i) << _T("\r\n"); /** TODO: the DWORDs are printed out as numbers. Convert these * DWORDs into text, the same text that whoami displays. **/ }
Figure 13: Regenerating the information from Whoami.
This technique only applies to just Windows XP and Server 2003. The next version of Windows will change this technique.
该技术仅适用于Windows XP和Server2003。Windows的下一版本将更改此技术。
For method 2, I wrapped the SAFER routines into a class (to abstract object management from the caller).对于方法2,我将SAFER例程包装到一个类中(以从调用方抽象对象管理)。
class SaferRaiiWrapper { public: /** Error handling has been added in the *downloadable version of this class **/ explicit SaferRaiiWrapper( const DWORD dwScopeIdIn = SAFER_LEVELID_NORMALUSER, const HANDLE hTokenIn = NULL) : hToken(hTokenIn), LevelHandle(NULL), dwScopeId(dwScopeIdIn) { ::SaferCreateLevel(SAFER_SCOPEID_USER, this->dwScopeId, SAFER_LEVEL_OPEN, &LevelHandle, NULL); ::SaferComputeTokenFromLevel(this->get_LevelHandle(), NULL, &hToken, NULL, NULL); } ; virtual PROCESS_INFORMATION CreateProcessAsUser(const const std::basic_string&lpCommandLine, STARTUPINFO *lpStartupInfoIn = NULL, DWORD dwCreationFlags = CREATE_NEW_CONSOLE, const std::basic_string &lpApplicationName = _T(""), const std::basic_string &lpCurrentDirectory = _T(""), LPVOID lpEnvironment = NULL, BOOL bInheritHandles = FALSE, SECURITY_ATTRIBUTES *lpProcessAttributes = NULL, SECURITY_ATTRIBUTES *lpThreadAttributes = NULL) { STARTUPINFO StartupInfoAlt = {0}; LPSTARTUPINFO lpStartupInfoActual = (lpStartupInfoIn != NULL) ? lpStartupInfoIn : &StartupInfoAlt; PROCESS_INFORMATION Result = {0}; TCHAR *lpCmdLineWritable = new TCHAR[sCmdLine.capacity() + 1]; /** The command line needs to be writable. * So make a writable copy of our command line. **/ sCmdLine.copy(lpCmdLineWritable, sCmdLine.size()); lpCmdLineWritable[sCmdLine.size()] = _T('\0'); lpStartupInfoActual->cb = sizeof(STARTUPINFO); lpStartupInfoActual->lpDesktop = NULL; ::CreateProcessAsUser(this->hToken, (sAppName.empty() ? NULL : sAppName.c_str()), lpCmdLineWritable, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, (sCurDir.empty() ? NULL : sCurDir.c_str()), lpStartupInfoActual, &Result); delete [] lpCmdLineWritable; return Result; } ; HANDLE get_hToken(void) const { return hToken; } ; virtual ~SaferRaiiWrapper() { ::CloseHandle(this->hToken); ::SaferCloseLevel(this->LevelHandle); } ; protected: const SAFER_LEVEL_HANDLE &get_LevelHandle(void) const { return LevelHandle; } ; void set_LevelHandle(const SAFER_LEVEL_HANDLE &LevelHandleIn) { this->LevelHandle = LevelHandleIn; } ; void set_hToken(const HANDLE hToken) { this->hToken = hToken; } ; private: HANDLE hToken; SAFER_LEVEL_HANDLE LevelHandle; const DWORD dwScopeId; };
Figure 14: Creating a restricted token using the Software Restriction Policies.
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州市文化路47号院1号楼4层(47-1楼位于文化路和红专路十字路口东北角,郑州大学工学院招待所南边,工学院科技报告厅西边。)