Win7 under Super Admin create normal permissions task

Source: Internet
Author: User

Moved to a new blog Http://www.raysoftware click the Open link. cn/?p=49

The project uses a feature that Win7 under the Super administrator to create a normal permissions task.

Tried several ways, such as obtaining token from the Resource manager, and then creating a task with CREATEPROCESSWITHTOKENW with this token. It is possible to do so.

But what if you don't currently have a resource manager or other normal permission task? Createtoken can build a token himself, but those parameters look great.

Try it. Start Task Manager with a super user to run in the menu, it is the default to create a normal permissions task, there is a complex option to start the task with superuser privileges.

Tracked it with WinDbg. The Discovery Task Manager invokes the Wdcruntaskasinteractiveuser function. function bit field Wdc.dll.

The form of the function is analyzed as follows:

Delphi statement:

[Delphi]View Plaincopy
    1. function Wdcruntaskasinteractiveuser (Pwszcmdline, Pwszpath:pwidechar;
    2. Dwdummy:dword): HResult; stdcall;  External ' Wdc.dll ';

C + + declaration:

[CPP]View Plaincopy
    1. HRESULT WINAPI wdcruntaskasinteractiveuser (lpcwstr Pwszcmdline,
    2. lpcwstr Pwszpath,
    3. DWORD dwdummy);

This is a function that Microsoft does not expose. Not available on MSDN or Google.

This function uses very few parameters and is very simple.

The last parameter to the Task Manager is 39. It should be identified by a bit. 39 should be 4 or 2 or 1 get.

I tried to give 0, open exe and so on is no problem, but open MP3 and so will fail.

Using Ida to Decompile Wdcruntaskasinteractiveuser discovers that his implementation is to create a low-privilege scheduled task, and then invoke the Run method of the scheduled task,

There is also an episode. I think Vista and Windows7 are similar, just judge Windows version >=6 with Wdcruntaskasinteractiveuser, otherwise call Shellexecuteexe.

It turns out that Vista is not working, there is no such function on Vista, and even the process manager without Wdc.dll.Vista can not create a normal process under superuser privileges, it simply calls the ShellExecuteEx.

Of course, Vista we can use the scheduled task to create the normal permissions process tasks, and then run the. That is, to realize the wdcruntaskasinteractiveuser.

I am more lazy, the project as long as GetProcAddress can not find Wdcruntaskasinteractiveuser, I use ShellExecuteEx.

Here is a code of execution that I encapsulated in my project.

[Delphi]View Plaincopy
  1. function Runtaskasinteractiveuser (cmdline, Param, dir:string): Boolean;
  2. Const
  3. WDC = ' Wdc.dll ';
  4. Type
  5. Twdcruntaskasinteractiveuser = function (pwszcmdline, Pwszpath:pwidechar;
  6. Dwdummy:dword): HResult; stdcall;
  7. Var
  8. Wdcruntaskasinteractiveuser:twdcruntaskasinteractiveuser;
  9. FullName: string;
  10. Sei:shellexecuteinfo;
  11. E:integer;
  12. hwdc:cardinal;
  13. Begin
  14. Result: = False;
  15. SetLength (FullName, Length (cmdline));
  16. CopyMemory (PChar (FullName), PChar (CmdLine), ByteLength (CmdLine));
  17. //If Windows version >=6
  18. if Win32majorversion >= 6 Then
  19. begin
  20. HWDC: = GetModuleHandle (WDC);
  21. if HWDC = 0 Then
  22. HWDC: = LoadLibrary (WDC);
  23. @WdcRunTaskAsInteractiveUser: = GetProcAddress (HWDC, ' Wdcruntaskasinteractiveuser ');
  24. //If you can find Wdcruntaskasinteractiveuser, then it should be Windows7 .
  25. if Assigned (wdcruntaskasinteractiveuser) Then
  26. begin
  27. if Length (Param) > 0 Then
  28. FullName: = Format (' "%s '%s ', [FullName, Param]);
  29. //fullname + ' + Param;
  30. ///The last parameter 39 is the reverse. I don't know what it means. Taskmgr gives a fixed
  31. //If given 0, EXE etc can be started, but the folder, MP3, etc. cannot start
  32. E: = Wdcruntaskasinteractiveuser (PChar (FullName), PChar (dir), 39);
  33. Result: = e = S_OK;
  34. end;
  35. end;
  36. //If not successful, usually there is no wdcruntaskasinteractiveuser, the system may be Vista or XP
  37. if not Result Then
  38. begin
  39. //  
  40. ZeroMemory (@sei, sizeof (SEI));
  41. Sei. cbsize: = sizeof (SHELLEXECUTEINFO);
  42. Sei. Fmask: = see_mask_nocloseprocess or see_mask_flag_no_ui;
  43. Sei. Lpfile: = PChar (fullname);
  44. Sei. Lpverb: = ' Open '; If this gives ' runas ' the ability to start with Super User privileges
  45. Sei. Nshow: = Sw_show;
  46. if Length (Param) > 0 Then
  47. Sei. Lpparameters: = PChar (Param)
  48. Else
  49. Sei. Lpparameters: = nil;
  50. Sei. Lpdirectory: = PChar (dir);
  51. ShellExecuteEx (@sei);
  52. if Sei. hprocess <> 0 Then
  53. CloseHandle (seihprocess);
  54. end;
  55. End

http://blog.csdn.net/wr960204/article/details/6600581

Win7 under Super Admin create normal permissions task

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.