ring0-new SSDT entry for communication (handy code)

Source: Internet
Author: User
Tags ssdt

http://blog.csdn.net/hgy413/article/details/7107009

The following is only for 32-bit systems, tested under XP:
Here's how XP is called in Ring3:

[CPP]View Plaincopy
  1. Xp
  2. ntdll! Ntreadfile:
  3. 7c92d9b0 b8b7000000 mov eax,0b7h
  4. 7C92D9B5 ba0003fe7f mov edx,offset shareduserdata! SystemCallStub (7ffe0300)
  5. 7c92d9ba Ff12 call DWORD ptr [edx] ds:0023:7ffe0300={ntdll! Kifastsystemcall (7C92E4F0)}
  6. 7C92D9BC c22400 ret 24h
  7. 7C92D9BF-NOP
  8. ntdll! Kifastsystemcall:
  9. 7C92E4F0 8BD4 mov edx,esp
  10. 7C92E4F2 0f34 Sysenter

So the principle is also relatively simple, imitation can be, note SSDT to remove write protection!
Ring3:

[CPP]View Plaincopy
  1. #include "stdafx.h"
  2. #include <Windows.h>
  3. __declspec (naked) void Mykifastsystemcall ()
  4. {
  5. __asm
  6. {
  7. MOV edx,esp;
  8. __emit 0x0f;
  9. __emit 0x34;
  10. }
  11. };
  12. __declspec (naked) NTSTATUS Ntapi
  13. Iosystemcontrol (
  14. in ULONG Ioctrl,
  15. in PVOID inputbuf,
  16. in ULONG Inputbuflen,
  17. Out PVOID outputbuf,
  18. in ULONG Outputlen,
  19. Out Pulong Returnlen)
  20. {
  21. __asm
  22. {
  23. mov eax, 11Ch;
  24. Call Mykifastsystemcall
  25. RETN 0x18;
  26. }
  27. }
  28. int _tmain (int argc, _tchar* argv[])
  29. {
  30. char szbuf[100] = {0};
  31. ULONG outlen = 0;
  32. Iosystemcontrol (0x12345678,"hgy413", strlen ("hgy413"), Szbuf,99,&outlen);
  33. printf ("%s-%d\n", Szbuf, Outlen);
  34. GetChar ();
  35. return 0;
  36. }

RING0:

[CPP]View Plaincopy
  1. #include "Main.h"
  2. Def
  3. typedef struct _kservice_table_descriptor
  4. {
  5. Pulong Servicetablebase; //SSTD Base Address
  6. Pulong Count; //contains a counter for the number of invocations per service in SSDT. This counter is typically updated by Sysenter
  7. ULONG tablesize; //number of services described by Servicetablebase
  8. Puchar argumenttable; //contains the base address of each system service parameter byte table-system service parameter list each table entry is a uchar that represents a function parameter length
  9. } kservice_table_descriptor, *pkservice_table_descriptor;
  10. SSDT table has been exported, and here's the routine
  11. extern Pkservice_table_descriptor keservicedescriptortable;
  12. Kservice_table_descriptor ssdt_copy;
  13. ULONG newssdtservicetablebase[1024] = {0};
  14. UCHAR newssdtservicetablenumber[1024] = {0};
  15. NTSTATUS
  16. Iosystemcontrol ( in ULONG Controlcode,
  17. in PVOID inputbuffer OPTIONAL,
  18. in ULONG inputbufferlength,
  19. Out PVOID outputbuffer OPTIONAL,
  20. in ULONG outputbufferlength,
  21. Out pulong returnlength OPTIONAL
  22. )
  23. {
  24. NTSTATUS Status = status_success;
  25. if (Outputbuffer&&mmisaddressvalid (OutputBuffer))
  26. {
  27. Kdprint (("%s\r\n", InputBuffer));
  28. memset (OutputBuffer, 0x41, outputbufferlength); //Outgoing buf becomes AAAAA ...
  29. if (returnlength&& mmisaddressvalid (returnlength))
  30. {
  31. *returnlength = 10; //Outgoing size arbitrarily set to ten
  32. }
  33. }
  34. return Status;
  35. }
  36. void Ntosaddssdtservicetable (
  37. PVOID newfunction,
  38. ULONG Newnumber
  39. )
  40. {
  41. NTSTATUS Status = status_success;
  42. Peprocess Process;
  43. //Prohibit write protection, otherwise blue screen
  44. __asm
  45. {
  46. MOV EAX, CR0;
  47. OR EAX, 10000H;
  48. MOV CR0, EAX;
  49. STI;
  50. }
  51. //Copy original service table
  52. //Copy the original table to our array
  53. memcpy
  54. Newssdtservicetablebase,
  55. Keservicedescriptortable->servicetablebase,
  56. Keservicedescriptortable->tablesize * 4
  57. );
  58. //number of primitive functions
  59. memcpy
  60. Newssdtservicetablenumber,
  61. Keservicedescriptortable->argumenttable,
  62. Keservicedescriptortable->tablesize
  63. );
  64. //Modify SSDT Table Add service function
  65. Newssdtservicetablebase[ssdt_copy. Tablesize] = newfunction;
  66. Newssdtservicetablenumber[ssdt_copy. Tablesize] = Newnumber;
  67. //update memory inside Export keservicedescriptortable SSDT table
  68. Keservicedescriptortable->servicetablebase = Newssdtservicetablebase;
  69. keservicedescriptortable->argumenttable = Newssdtservicetablenumber;
  70. Keservicedescriptortable->tablesize = ssdt_copy. Tablesize + 1;
  71. //Resume write protection
  72. __asm
  73. {
  74. MOV EAX, CR0;
  75. OR EAX, 10000H;
  76. MOV CR0, EAX;
  77. STI;
  78. }
  79. }
  80. VOID ddkunload (in Pdriver_object pdriverobject)
  81. {
  82. Kdprint (("[ddkunload]-start\n"));
  83. //Restore the original
  84. Keservicedescriptortable->servicetablebase = ssdt_copy. Servicetablebase;
  85. Keservicedescriptortable->count = ssdt_copy. Count;
  86. Keservicedescriptortable->tablesize = ssdt_copy. Tablesize;
  87. keservicedescriptortable->argumenttable = ssdt_copy. argumenttable;
  88. Kdprint (("[ddkunload]-end\n"));
  89. }
  90. NTSTATUS DriverEntry (in Pdriver_object pdriverobject,
  91. In Punicode_string Pregistrypath)
  92. {
  93. Kdprint (("[driverentry]-start\n"));
  94. Pdriverobject->driverunload = Ddkunload;
  95. //Save the original
  96. Ssdt_copy. Servicetablebase = keservicedescriptortable->servicetablebase;
  97. Ssdt_copy. Count = keservicedescriptortable->count;
  98. Ssdt_copy. Tablesize = keservicedescriptortable->tablesize;
  99. Ssdt_copy. Argumenttable = keservicedescriptortable->argumenttable;
  100. //We call the Custom function to add memory to the SSDT table
  101. Ntosaddssdtservicetable (Iosystemcontrol, 24);
  102. Kdprint (("[driverentry]-end\n"));
  103. return status_success;
  104. }

After the driver is loaded, you can see:

To run the Ring3 applet, you can see that the outbuf is aaaaa., size 10:





ring0-new SSDT entry for communication (handy code)

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.