KeServiceDescriptorTable/Shadow

So from everything I read, the KeServiceDescriptorTable /
KeServiceDescriptorTableShadow point to 4 Service Tables
(which are fixed length data structures as far as I can tell.
(16 bytes long possibly?)

While exploring the memory with a kernel debug, I noticed a
problem with this:

In Windows 2003 Sever Standard Edition, everything seems fine,
in the kernel table there 1 one entry and 3 blanks, and in the
shadow there are 2 entries and 2 blanks.

However on the computer with Windows 2003 Server Standard R2
SP1, there would appear to be only space for two entries in
each table. Since The tables are placed end to beginning, that
would mean that the table at an offset of +2 in the 1st table
is really the offset of +0 in the 2nd table.

Essentially, why would the table’s starting address be
offset by 0x40 in the first situation and only x20 in the 2nd
situation. Wouldn’t that cause problems if one wanted to add
tables?

If anyone could help me make sense of this, or point out my
beginner mistake it would be much appreciated.

J.J.

Maybe some data will help to clarify why I am confused…

Here is the data for Win 2003 R2 SP1:

KeServiceDescriptorTable: 808aeee0
KeServiceDescriptorTableShadow: 808aeec0

808aeec0: 4c fc 83 80 00 00 00 00 28 01 00 00 18 36 80 80
808aeed0: 00 30 9a bf 00 00 00 00 99 02 00 00 08 3d 9a bf
808aeee0: 4c fc 83 80 00 00 00 00 28 01 00 00 18 36 80 80
808aeef0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Here is the data for Win 2003 Standard

KeServiceDescriptorTable: 8057a420
KeServiceDescriptorTableShadow: 8057a3e0

8057a3e0: ec d0 4e 80 00 00 00 00 27 01 00 00 80 62 54 80
8057a3f0: 24 35 9a bf 00 00 00 00 97 02 00 00 f4 a1 99 bf
8057a400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a420: ec d0 4e 80 00 00 00 00 27 01 00 00 80 62 54 80
8057a430: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a440: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Obviously something changed from one version to the next, but
this change is fairly signifigant isn’t it? It would require
changing the number of service tables in each overall table.
Can anyone explain this difference?

J.J.

Nah, we understand your problem.

You might want to trouble yourself to first search the archives under system service table and hooking.

Nobody on this list is likely to answer your query, given that it leads down a path which is at best dubious and at worst the mechanism by which malware is created.

Peter
OSR

While you might consider this “significant,” I have observed over the
years that the size of this specific table has oscillated between two
and four. To find out the definitive reason why would require going and
asking the right person (ahem, that would be the person who own Ke.)
I’d suggest that you don your asbestos armor when you approach the
dragon’s den to ask your question, since I suspect his position will be
that if you have to ask the question you don’t know enough to understand
the answer.

Bottom line: You shouldn’t be using this table at all, nor should you
rely upon it size. It belongs entirely absolutely and totally to the
OS. Your dependence upon an OS internal structure is that you can break
from any update - hot fix, service pack, security patch, or anything
else that changes the OS.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@uiuc.edu
Sent: Wednesday, June 21, 2006 12:30 PM
To: ntdev redirect
Subject: Re:[ntdev] KeServiceDescriptorTable/Shadow

Maybe some data will help to clarify why I am confused…

Here is the data for Win 2003 R2 SP1:

KeServiceDescriptorTable: 808aeee0
KeServiceDescriptorTableShadow: 808aeec0

808aeec0: 4c fc 83 80 00 00 00 00 28 01 00 00 18 36 80 80
808aeed0: 00 30 9a bf 00 00 00 00 99 02 00 00 08 3d 9a bf
808aeee0: 4c fc 83 80 00 00 00 00 28 01 00 00 18 36 80 80
808aeef0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Here is the data for Win 2003 Standard

KeServiceDescriptorTable: 8057a420
KeServiceDescriptorTableShadow: 8057a3e0

8057a3e0: ec d0 4e 80 00 00 00 00 27 01 00 00 80 62 54 80
8057a3f0: 24 35 9a bf 00 00 00 00 97 02 00 00 f4 a1 99 bf
8057a400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a420: ec d0 4e 80 00 00 00 00 27 01 00 00 80 62 54 80
8057a430: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a440: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Obviously something changed from one version to the next, but
this change is fairly signifigant isn’t it? It would require
changing the number of service tables in each overall table.
Can anyone explain this difference?

J.J.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

>I have observed over the years that the size of this specific table has

oscillated between two and four.

Given the dire warnings from both you and Peter, just why were you looking?
:slight_smile:

----- Original Message -----
From: “Tony Mason”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, June 21, 2006 10:57 AM
Subject: RE: [ntdev] KeServiceDescriptorTable/Shadow

While you might consider this “significant,” I have observed over the
years that the size of this specific table has oscillated between two
and four. To find out the definitive reason why would require going and
asking the right person (ahem, that would be the person who own Ke.)
I’d suggest that you don your asbestos armor when you approach the
dragon’s den to ask your question, since I suspect his position will be
that if you have to ask the question you don’t know enough to understand
the answer.

Bottom line: You shouldn’t be using this table at all, nor should you
rely upon it size. It belongs entirely absolutely and totally to the
OS. Your dependence upon an OS internal structure is that you can break
from any update - hot fix, service pack, security patch, or anything
else that changes the OS.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@uiuc.edu
Sent: Wednesday, June 21, 2006 12:30 PM
To: ntdev redirect
Subject: Re:[ntdev] KeServiceDescriptorTable/Shadow

Maybe some data will help to clarify why I am confused…

Here is the data for Win 2003 R2 SP1:

KeServiceDescriptorTable: 808aeee0
KeServiceDescriptorTableShadow: 808aeec0

808aeec0: 4c fc 83 80 00 00 00 00 28 01 00 00 18 36 80 80
808aeed0: 00 30 9a bf 00 00 00 00 99 02 00 00 08 3d 9a bf
808aeee0: 4c fc 83 80 00 00 00 00 28 01 00 00 18 36 80 80
808aeef0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Here is the data for Win 2003 Standard

KeServiceDescriptorTable: 8057a420
KeServiceDescriptorTableShadow: 8057a3e0

8057a3e0: ec d0 4e 80 00 00 00 00 27 01 00 00 80 62 54 80
8057a3f0: 24 35 9a bf 00 00 00 00 97 02 00 00 f4 a1 99 bf
8057a400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a420: ec d0 4e 80 00 00 00 00 27 01 00 00 80 62 54 80
8057a430: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a440: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Obviously something changed from one version to the next, but
this change is fairly signifigant isn’t it? It would require
changing the number of service tables in each overall table.
Can anyone explain this difference?

J.J.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

I actually just happened to have noticed this while working on
a project involving hooking the Native API. I don’t know that
it particularly effects me since I will only be using the
first 2 entries anyways, but I thought it would be interesting
to find out since I have now read quite a bit about the
Service Tables and none seem to have referenced this
possibility (other than saying different versions have
different tables, subject to change during hotfixes etc.)

I had searched through the archives for info about this, but I
will give it another go with Peter’s keywords.

To be more specific with what I am doing, (so everyone doesn’t
think I just have malicious intentions) I am doing this
project sort of as a learning exercise to delve deeper into
understanding the Windows OS. The project is supposed to be
sort of an API monitor that will monitor what Native API
functions are called (by hooking in the service table.) And
then *possibly*, having some playback functionality. Obviously
there will be some dynamic structures passed to the
functions, however hopefully I will be able to pull enough
data from them to create new ones at playback time that will
result in a very similar function call.

I understand that this is not a proper way to do things, but
unless someone can suggest another way to hook all native API
calls, this is the option I have right now. If someone wants
to suggest an alternative, I am open to that as well.

I’m sure I will still get the “Don’t do this, it is not a very
good idea” response since I have read many threads along these
lines, but responses with useful information or even just
things to think about in such a project are greatly appreciated.

I also admit to being a complete beginner at Windows
internals, but I am trying to *learn*, not just get things
done. Therefore I value the responses where it is explained
what is very difficult about the idea, rather than just saying
“its too difficult, don’t try it.”

Thanks for the help,
J.J.

I notice because someone complains about it and I confirm that “yep,
this has changed [again].”

One of the advantages of being an old man in this field. Remember, any
change worth making is worth oscillating between two different
solutions.

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Dan Kyler
Sent: Wednesday, June 21, 2006 2:07 PM
To: ntdev redirect
Subject: Re: [ntdev] KeServiceDescriptorTable/Shadow

I have observed over the years that the size of this specific table has

oscillated between two and four.

Given the dire warnings from both you and Peter, just why were you
looking?
:slight_smile:

----- Original Message -----
From: “Tony Mason”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, June 21, 2006 10:57 AM
Subject: RE: [ntdev] KeServiceDescriptorTable/Shadow

While you might consider this “significant,” I have observed over the
years that the size of this specific table has oscillated between two
and four. To find out the definitive reason why would require going and
asking the right person (ahem, that would be the person who own Ke.)
I’d suggest that you don your asbestos armor when you approach the
dragon’s den to ask your question, since I suspect his position will be
that if you have to ask the question you don’t know enough to understand
the answer.

Bottom line: You shouldn’t be using this table at all, nor should you
rely upon it size. It belongs entirely absolutely and totally to the
OS. Your dependence upon an OS internal structure is that you can break
from any update - hot fix, service pack, security patch, or anything
else that changes the OS.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@uiuc.edu
Sent: Wednesday, June 21, 2006 12:30 PM
To: ntdev redirect
Subject: Re:[ntdev] KeServiceDescriptorTable/Shadow

Maybe some data will help to clarify why I am confused…

Here is the data for Win 2003 R2 SP1:

KeServiceDescriptorTable: 808aeee0
KeServiceDescriptorTableShadow: 808aeec0

808aeec0: 4c fc 83 80 00 00 00 00 28 01 00 00 18 36 80 80
808aeed0: 00 30 9a bf 00 00 00 00 99 02 00 00 08 3d 9a bf
808aeee0: 4c fc 83 80 00 00 00 00 28 01 00 00 18 36 80 80
808aeef0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Here is the data for Win 2003 Standard

KeServiceDescriptorTable: 8057a420
KeServiceDescriptorTableShadow: 8057a3e0

8057a3e0: ec d0 4e 80 00 00 00 00 27 01 00 00 80 62 54 80
8057a3f0: 24 35 9a bf 00 00 00 00 97 02 00 00 f4 a1 99 bf
8057a400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a420: ec d0 4e 80 00 00 00 00 27 01 00 00 80 62 54 80
8057a430: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a440: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
8057a450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Obviously something changed from one version to the next, but
this change is fairly signifigant isn’t it? It would require
changing the number of service tables in each overall table.
Can anyone explain this difference?

J.J.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

wrote in message news:xxxxx@ntdev…
> I understand that this is not a proper way to do things, but
> unless someone can suggest another way to hook all native API
> calls, this is the option I have right now. If someone wants
> to suggest an alternative, I am open to that as well.
>
As long as you never think of this as something for a commercial program
(i.e. only as a research project) the this is doable, though you are likely
to have problems as you move between service packs let alone OS’es. Some
things to be aware of:

1. You are going to have to be very careful in validating buffers, since
you are putting yourself infront of the OS validation, you can easily cause
crashes. Note: there are commercial hooking programs that have bugs, and
try to claim that is it is lousy user space programs, sorry not the case if
you hook you have to verify everything, and that is not easy.

2. You need to understand that some calls such a ZwTerminateThread expect a
certain stack structure. You will have to restore the stack to exactly what
it was on entry if you want these calls to work.

3. Be aware that you are opening yourself up to a lot potential recursion
problems depending on what you do with the data.

You are taking on a huge project, I did most of this for a customer on
Windows 2000 and to have finished it would have easily been 2 years or more.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply

Dan Kyler wrote:

> I have observed over the years that the size of this specific table
> has oscillated between two and four.

Given the dire warnings from both you and Peter, just why were you
looking? :slight_smile:

Ah, Grasshopper, one can seek to understand the mind of the assassin
without actually becoming an assassin.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

>1. You are going to have to be very careful in validating

buffers, since you are putting yourself infront of the OS
validation, you can easily cause crashes. Note: there are
commercial hooking programs that have bugs, and try to claim
that is it is lousy user space programs, sorry not the case if
you hook you have to verify everything, and that is not easy.

How do you mean validating data? Does this mean making sure
data is correctly stored / retrieved? Is there a good source
for figuring out what proper validation is?

  1. You need to understand that some calls such a
    ZwTerminateThread expect a certain stack structure. You will
    have to restore the stack to exactly what it was on entry if
    you want these calls to work.

Is there a good place to figure out which functions these are?

  1. Be aware that you are opening yourself up to a lot
    potential recursion problems depending on what you do with the
    data.

recursion as in calling the service by name, and thus calling
itself?

You are taking on a huge project, I did most of this for a
customer on Windows 2000 and to have finished it would have
easily been 2 years or more.

Would a record/playback program really take a full 2 years? I
don’t need extensive system support, really if it works on
this computer it will be fine.

Thanks for all the ideas though!
J.J.

This is such a long and hotly debated topic on this list, and it’s so open to abuse, it’s not a topic I’m really happy to see discussed in depth.

If you want to “hook” the API function for fun, have you considered something like the MSR Detours project?

Why not choose another topic that we’d be more happy to help you with. Whacking OS datastructures for fun just isn’t cool. And, at the end of the day, what IS it that you’ve learned? The format of a table? Duh…

Peter
OSR

wrote in message news:xxxxx@ntdev…
> >1. You are going to have to be very careful in validating
>>buffers, since you are putting yourself infront of the OS
>>validation, you can easily cause crashes. Note: there are
>>commercial hooking programs that have bugs, and try to claim
>>that is it is lousy user space programs, sorry not the case if
>>you hook you have to verify everything, and that is not easy.
>
> How do you mean validating data? Does this mean making sure
> data is correctly stored / retrieved? Is there a good source
> for figuring out what proper validation is?

I mean you are going to have to validate that buffer pointers and lengths
are valid before you access the data. This includes all the problems of
wrapping and other hacks that malware can use. Try to find the old
Carnagie-Melon CRASHME program and modify it for the Windows API (note:
Microsoft has this in their testing).

>
>>2. You need to understand that some calls such a
>>ZwTerminateThread expect a certain stack structure. You will
>>have to restore the stack to exactly what it was on entry if
>>you want these calls to work.
>
> Is there a good place to figure out which functions these are?

Unfortunately, there is not. In 2000 the terminate functions were constant
on this, but there were others that varied with the service pack.

>
>>3. Be aware that you are opening yourself up to a lot
>>potential recursion problems depending on what you do with the
>>data.
>
> recursion as in calling the service by name, and thus calling
> itself?

Yep, a lot of things pass through the table, and now they pass through you
driver.

>>You are taking on a huge project, I did most of this for a
>>customer on Windows 2000 and to have finished it would have
>>easily been 2 years or more.
>
>
> Would a record/playback program really take a full 2 years? I
> don’t need extensive system support, really if it works on
> this computer it will be fine.

Note, I was basically supplying a bunch of data to a service that was doing
the analysis. I spent close to a year and had most calls hooked. I was
continually finding corner cases and other problems that kept me fixing
things.

One of the problems is that you will find a number of calls, such as the
ZwQueryXXX calls which have an argument telling the call what the data is,
even with the Nebbett book there are undocumented values. The same is true
on a lot of the flag words, all the books and web stuff list the bottom 8
bits of a 32 bit word as flags, but what is this stuff in top bits,
sometimes it is garbage and sometimes it is a modifier that is undocumented.

I am one of the people who screams against hooking, the reason being is the
effort can bury you, and it is extremely easy to open security holes. Yes
it is the only way to do certain things, but for many of the uses if the
developer were to back off and think, they would realize that maybe they
could achieve their goal without doing that certain thing.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply

J. J.:

You’re on the right track from an information standpoint.

Here are the basics of what you ask. For more complete details, head
to your local bookstore (in addition to the aforementioned book,
“Undocumented Windows NT” goes in to this is much more detail; it also
includes fairly complete code that would serve as a good paradigm for
what you are trying to do; however, I think that it is out of print, and
only goes up to W2K (as far as I know))).

PRE WIN2K3SP1:

Windows supports up to four service descriptor tables. The two you
mentioned (KeServiceDescriptorTable and KeServiceDescriptorTableShadow)
are mandatory. KeServiceDescriptorTable does what you think it does.
KeServiceDescriptorTableShadow was added in NT4 to allow for the kernel
mode implementation of the USER and GDI services (Win32K) formerly
provided as user mode subsystem based on LPC (CSRSS). [Strictly
speaking, even though 3.51 did not have Win32K, it did contain most of
the structures necessary to support it in future versions (i. e. -
KeServiceDescriptorTableShadow, et. c.).] The other two entries you
asked about are used to allow the addition of up to two additional
tables via KeAddSystemServiceTable. When a table is added, its values
are copied in to one of the slots in both KeServiceDescriptorTable and
KeServiceDescriptorTableShadow. Microsoft Internet Information Server’s
Spud Driver does this.

W2K3SP1+:

As quite correctly pointed out, this feature/security issue is the
basis for most malware. To prevent this manipulation the ability to add
service descriptor tables was removed (except for the case of Win2K),
and this is why there are now only two entries.

ON A PERSONAL NOTE:

I make no assumptions about your intentions, because:

(1) as I can not read minds, I do not know what they are;

(2) I do not care what they are, both because it is not my business and
it doesn’t affect me;

(3) while the dangers of methods such as this are very real, so are the
occasional situations which either require them or they have documented
alternatives that are unwieldly and/or crippled;

(4) as a general rule, everything on this list that taboo to ask about
was, minimally, at one time considered, while undocumented, acceptable.
In this particular case, Microsoft used to have articles pertaining to
this in the MSDN a long time ago; in fact, this security issue was once
marketed as a feature in official Microsoft publications (like Helen
Custer’s book); even the more recent version (albeit with a very
different purpose) (Russinovich) mentions much of this. Details to
follow below, but the basic answer to your question supports this - the
bytes missing in W2K3SP1 were removed as a result of removing the
support to add new system services tables, which was both a security
issue and as well as a feature.

(5) most of the verboten subject matter on this list, while very
complicated, is, from a realistic security standpoint, at this point in
time (NT + something like 15), pedestrian. In fact, this is a
requirement for a mechanism to be included on the do not discuss list.
Presumably, no one discloses anything really good.

Three pieces of Advice:

(1) Unless asked to provide information, don’t waste your time
appologizing/explaining what you intend to do with this information.
You’re going to get the same response, and it just generates a flood of
nonsense like what I’m writing here; on bad days, that would seem to be
the point of these lists.

(2) Try not to take the suspicion personally, or, for that matter,
seriously. In fact, turn about is fair play; that is, everyone on this
list has his or her own intentions, including myself, which you may or
may not trust. Many of this list’s members have very real constraints
on what they say, because it may impact them professionally in a variety
of ways. I don’t mean this in a sinster way; that’s just life.

(3) All of that being said, generally, the advice given regarding
security/stability issues is excellent for most cases.

MM

>> xxxxx@uiuc.edu 2006-06-21 14:29:25 >>>
I actually just happened to have noticed this while working on
a project involving hooking the Native API. I don’t know that
it particularly effects me since I will only be using the
first 2 entries anyways, but I thought it would be interesting
to find out since I have now read quite a bit about the
Service Tables and none seem to have referenced this
possibility (other than saying different versions have
different tables, subject to change during hotfixes etc.)

I had searched through the archives for info about this, but I
will give it another go with Peter’s keywords.

To be more specific with what I am doing, (so everyone doesn’t
think I just have malicious intentions) I am doing this
project sort of as a learning exercise to delve deeper into
understanding the Windows OS. The project is supposed to be
sort of an API monitor that will monitor what Native API
functions are called (by hooking in the service table.) And
then *possibly*, having some playback functionality. Obviously
there will be some dynamic structures passed to the
functions, however hopefully I will be able to pull enough
data from them to create new ones at playback time that will
result in a very similar function call.

I understand that this is not a proper way to do things, but
unless someone can suggest another way to hook all native API
calls, this is the option I have right now. If someone wants
to suggest an alternative, I am open to that as well.

I’m sure I will still get the “Don’t do this, it is not a very
good idea” response since I have read many threads along these
lines, but responses with useful information or even just
things to think about in such a project are greatly appreciated.

I also admit to being a complete beginner at Windows
internals, but I am trying to *learn*, not just get things
done. Therefore I value the responses where it is explained
what is very difficult about the idea, rather than just saying
“its too difficult, don’t try it.”

Thanks for the help,
J.J.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Martin,

Most of that book is worthless, sorry but when I find a book that has
large portions ripped off of the Intel processor manuals, I really have to
wonder about the publisher and the author. The calls they do document are
missing data (I was foolish enough once to trust this book).

It has an ok description of hooking for NT4/Windows 2000, but
otherwise forget this thing.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply

“Martin O’Brien” wrote in message
news:xxxxx@ntdev…
> J. J.:
>
> You’re on the right track from an information standpoint.
>
> Here are the basics of what you ask. For more complete details, head
> to your local bookstore (in addition to the aforementioned book,
> “Undocumented Windows NT” goes in to this is much more detail; it also
> includes fairly complete code that would serve as a good paradigm for
> what you are trying to do; however, I think that it is out of print, and
> only goes up to W2K (as far as I know))).
>
> PRE WIN2K3SP1:
>
> Windows supports up to four service descriptor tables. The two you
> mentioned (KeServiceDescriptorTable and KeServiceDescriptorTableShadow)
> are mandatory. KeServiceDescriptorTable does what you think it does.
> KeServiceDescriptorTableShadow was added in NT4 to allow for the kernel
> mode implementation of the USER and GDI services (Win32K) formerly
> provided as user mode subsystem based on LPC (CSRSS). [Strictly
> speaking, even though 3.51 did not have Win32K, it did contain most of
> the structures necessary to support it in future versions (i. e. -
> KeServiceDescriptorTableShadow, et. c.).] The other two entries you
> asked about are used to allow the addition of up to two additional
> tables via KeAddSystemServiceTable. When a table is added, its values
> are copied in to one of the slots in both KeServiceDescriptorTable and
> KeServiceDescriptorTableShadow. Microsoft Internet Information Server’s
> Spud Driver does this.
>
> W2K3SP1+:
>
> As quite correctly pointed out, this feature/security issue is the
> basis for most malware. To prevent this manipulation the ability to add
> service descriptor tables was removed (except for the case of Win2K),
> and this is why there are now only two entries.
>
> ON A PERSONAL NOTE:
>
> I make no assumptions about your intentions, because:
>
> (1) as I can not read minds, I do not know what they are;
>
> (2) I do not care what they are, both because it is not my business and
> it doesn’t affect me;
>
> (3) while the dangers of methods such as this are very real, so are the
> occasional situations which either require them or they have documented
> alternatives that are unwieldly and/or crippled;
>
> (4) as a general rule, everything on this list that taboo to ask about
> was, minimally, at one time considered, while undocumented, acceptable.
> In this particular case, Microsoft used to have articles pertaining to
> this in the MSDN a long time ago; in fact, this security issue was once
> marketed as a feature in official Microsoft publications (like Helen
> Custer’s book); even the more recent version (albeit with a very
> different purpose) (Russinovich) mentions much of this. Details to
> follow below, but the basic answer to your question supports this - the
> bytes missing in W2K3SP1 were removed as a result of removing the
> support to add new system services tables, which was both a security
> issue and as well as a feature.
>
> (5) most of the verboten subject matter on this list, while very
> complicated, is, from a realistic security standpoint, at this point in
> time (NT + something like 15), pedestrian. In fact, this is a
> requirement for a mechanism to be included on the do not discuss list.
> Presumably, no one discloses anything really good.
>
> Three pieces of Advice:
>
> (1) Unless asked to provide information, don’t waste your time
> appologizing/explaining what you intend to do with this information.
> You’re going to get the same response, and it just generates a flood of
> nonsense like what I’m writing here; on bad days, that would seem to be
> the point of these lists.
>
> (2) Try not to take the suspicion personally, or, for that matter,
> seriously. In fact, turn about is fair play; that is, everyone on this
> list has his or her own intentions, including myself, which you may or
> may not trust. Many of this list’s members have very real constraints
> on what they say, because it may impact them professionally in a variety
> of ways. I don’t mean this in a sinster way; that’s just life.
>
> (3) All of that being said, generally, the advice given regarding
> security/stability issues is excellent for most cases.
>
> MM
>
>
>
>
>>>> xxxxx@uiuc.edu 2006-06-21 14:29:25 >>>
> I actually just happened to have noticed this while working on
> a project involving hooking the Native API. I don’t know that
> it particularly effects me since I will only be using the
> first 2 entries anyways, but I thought it would be interesting
> to find out since I have now read quite a bit about the
> Service Tables and none seem to have referenced this
> possibility (other than saying different versions have
> different tables, subject to change during hotfixes etc.)
>
> I had searched through the archives for info about this, but I
> will give it another go with Peter’s keywords.
>
> To be more specific with what I am doing, (so everyone doesn’t
> think I just have malicious intentions) I am doing this
> project sort of as a learning exercise to delve deeper into
> understanding the Windows OS. The project is supposed to be
> sort of an API monitor that will monitor what Native API
> functions are called (by hooking in the service table.) And
> then possibly, having some playback functionality. Obviously
> there will be some dynamic structures passed to the
> functions, however hopefully I will be able to pull enough
> data from them to create new ones at playback time that will
> result in a very similar function call.
>
> I understand that this is not a proper way to do things, but
> unless someone can suggest another way to hook all native API
> calls, this is the option I have right now. If someone wants
> to suggest an alternative, I am open to that as well.
>
> I’m sure I will still get the “Don’t do this, it is not a very
> good idea” response since I have read many threads along these
> lines, but responses with useful information or even just
> things to think about in such a project are greatly appreciated.
>
> I also admit to being a complete beginner at Windows
> internals, but I am trying to learn, not just get things
> done. Therefore I value the responses where it is explained
> what is very difficult about the idea, rather than just saying
> “its too difficult, don’t try it.”
>
> Thanks for the help,
> J.J.
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

>This is such a long and hotly debated topic on this list, and

it’s so open to abuse, it’s not a topic I’m really happy to see
discussed in depth. If you want to “hook” the API function for
fun, have you considered something like the MSR Detours project?
I haven’t seen the MSR Detours project, although from the
brief look I just took, it seems like it could be useful. Why
would using this be better than hooking the API? and do you
think it will possible to hook the Native API functions with
that? I will admit I am still a bit hazy as far as permissions
on the memory goes, but it would appear to me that
ntoskrnl.exe probably won’t be able to have its functions
modified as detours does…what do you think? (or anyone else)

I am not solely attached to hooking the API either. I was
mainly considering it as it seemed a good level to record the
actions of User-mode programs so that they may be able to be
played back. I am definitely open to investigateing further
options.

Why not choose another topic that we’d be more happy to help you
with. Whacking OS datastructures for fun just isn’t cool. And,
at the end of the day, what IS it that you’ve learned? The
format of a table? Duh… Peter OSR

I can understand the hesitation on the subject, having read
the debates on this forum alone, I would defintely sit on the
don’t do it side for the most part (to be completely honest, I
don’t know why it is even possible, I’m not a big MS fan as it
is. However, its the platform of the times at the moment, so
its what I’m doing…)

Thank you for at least entertaining the discussion,
J.J.

Don Burn wrote:

Martin,

Most of that book is worthless, sorry but when I find a book that has
large portions ripped off of the Intel processor manuals, I really have to
wonder about the publisher and the author. The calls they do document are
missing data (I was foolish enough once to trust this book).

It has an ok description of hooking for NT4/Windows 2000, but
otherwise forget this thing.

It’s too bad the name is so close to Schreiber’s very good “Undocumented
Windows 2000 Secrets”. Schreiber’s book has some good stuff in it, but
the real gem is the CD of tools for exploring an NT-based system. It
was worth the price of the book just to get the tools, and he even
includes the source code.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

DON:

I would agree that it pretty much sucks except for hooking, although I
would add the LPC description as serviceable. I’ve never read anything
in part one; anything that describes reverse engineering in one chapter,
or, for that matter, as a discrete process at all, is guaranteed to be a
waste of time. I’ve also never used any of the code directly. I picked
it out of what I had in front of me, because the description of hooking
is pretty good, but, more importantly, fairly simple. I

MM

>> xxxxx@acm.org 2006-06-21 16:43:34 >>>
Martin,

Most of that book is worthless, sorry but when I find a book that
has
large portions ripped off of the Intel processor manuals, I really have
to
wonder about the publisher and the author. The calls they do document
are
missing data (I was foolish enough once to trust this book).

It has an ok description of hooking for NT4/Windows 2000, but
otherwise forget this thing.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply

“Martin O’Brien” wrote in message
news:xxxxx@ntdev…
> J. J.:
>
> You’re on the right track from an information standpoint.
>
> Here are the basics of what you ask. For more complete details,
head
> to your local bookstore (in addition to the aforementioned book,
> “Undocumented Windows NT” goes in to this is much more detail; it
also
> includes fairly complete code that would serve as a good paradigm
for
> what you are trying to do; however, I think that it is out of print,
and
> only goes up to W2K (as far as I know))).
>
> PRE WIN2K3SP1:
>
> Windows supports up to four service descriptor tables. The two you
> mentioned (KeServiceDescriptorTable and
KeServiceDescriptorTableShadow)
> are mandatory. KeServiceDescriptorTable does what you think it
does.
> KeServiceDescriptorTableShadow was added in NT4 to allow for the
kernel
> mode implementation of the USER and GDI services (Win32K) formerly
> provided as user mode subsystem based on LPC (CSRSS). [Strictly
> speaking, even though 3.51 did not have Win32K, it did contain most
of
> the structures necessary to support it in future versions (i. e. -
> KeServiceDescriptorTableShadow, et. c.).] The other two entries you
> asked about are used to allow the addition of up to two additional
> tables via KeAddSystemServiceTable. When a table is added, its
values
> are copied in to one of the slots in both KeServiceDescriptorTable
and
> KeServiceDescriptorTableShadow. Microsoft Internet Information
Server’s
> Spud Driver does this.
>
> W2K3SP1+:
>
> As quite correctly pointed out, this feature/security issue is the
> basis for most malware. To prevent this manipulation the ability to
add
> service descriptor tables was removed (except for the case of
Win2K),
> and this is why there are now only two entries.
>
> ON A PERSONAL NOTE:
>
> I make no assumptions about your intentions, because:
>
> (1) as I can not read minds, I do not know what they are;
>
> (2) I do not care what they are, both because it is not my business
and
> it doesn’t affect me;
>
> (3) while the dangers of methods such as this are very real, so are
the
> occasional situations which either require them or they have
documented
> alternatives that are unwieldly and/or crippled;
>
> (4) as a general rule, everything on this list that taboo to ask
about
> was, minimally, at one time considered, while undocumented,
acceptable.
> In this particular case, Microsoft used to have articles pertaining
to
> this in the MSDN a long time ago; in fact, this security issue was
once
> marketed as a feature in official Microsoft publications (like Helen
> Custer’s book); even the more recent version (albeit with a very
> different purpose) (Russinovich) mentions much of this. Details to
> follow below, but the basic answer to your question supports this -
the
> bytes missing in W2K3SP1 were removed as a result of removing the
> support to add new system services tables, which was both a security
> issue and as well as a feature.
>
> (5) most of the verboten subject matter on this list, while very
> complicated, is, from a realistic security standpoint, at this point
in
> time (NT + something like 15), pedestrian. In fact, this is a
> requirement for a mechanism to be included on the do not discuss
list.
> Presumably, no one discloses anything really good.
>
> Three pieces of Advice:
>
> (1) Unless asked to provide information, don’t waste your time
> appologizing/explaining what you intend to do with this information.
> You’re going to get the same response, and it just generates a flood
of
> nonsense like what I’m writing here; on bad days, that would seem to
be
> the point of these lists.
>
> (2) Try not to take the suspicion personally, or, for that matter,
> seriously. In fact, turn about is fair play; that is, everyone on
this
> list has his or her own intentions, including myself, which you may
or
> may not trust. Many of this list’s members have very real
constraints
> on what they say, because it may impact them professionally in a
variety
> of ways. I don’t mean this in a sinster way; that’s just life.
>
> (3) All of that being said, generally, the advice given regarding
> security/stability issues is excellent for most cases.
>
> MM
>
>
>
>
>>>> xxxxx@uiuc.edu 2006-06-21 14:29:25 >>>
> I actually just happened to have noticed this while working on
> a project involving hooking the Native API. I don’t know that
> it particularly effects me since I will only be using the
> first 2 entries anyways, but I thought it would be interesting
> to find out since I have now read quite a bit about the
> Service Tables and none seem to have referenced this
> possibility (other than saying different versions have
> different tables, subject to change during hotfixes etc.)
>
> I had searched through the archives for info about this, but I
> will give it another go with Peter’s keywords.
>
> To be more specific with what I am doing, (so everyone doesn’t
> think I just have malicious intentions) I am doing this
> project sort of as a learning exercise to delve deeper into
> understanding the Windows OS. The project is supposed to be
> sort of an API monitor that will monitor what Native API
> functions are called (by hooking in the service table.) And
> then possibly, having some playback functionality. Obviously
> there will be some dynamic structures passed to the
> functions, however hopefully I will be able to pull enough
> data from them to create new ones at playback time that will
> result in a very similar function call.
>
> I understand that this is not a proper way to do things, but
> unless someone can suggest another way to hook all native API
> calls, this is the option I have right now. If someone wants
> to suggest an alternative, I am open to that as well.
>
> I’m sure I will still get the “Don’t do this, it is not a very
> good idea” response since I have read many threads along these
> lines, but responses with useful information or even just
> things to think about in such a project are greatly appreciated.
>
> I also admit to being a complete beginner at Windows
> internals, but I am trying to learn, not just get things
> done. Therefore I value the responses where it is explained
> what is very difficult about the idea, rather than just saying
> “its too difficult, don’t try it.”
>
> Thanks for the help,
> J.J.
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

xxxxx@uiuc.edu wrote:

So from everything I read, the KeServiceDescriptorTable /
KeServiceDescriptorTableShadow point to 4 Service Tables
(which are fixed length data structures as far as I can tell.
(16 bytes long possibly?)

While exploring the memory with a kernel debug, I noticed a
problem with this:

In Windows 2003 Sever Standard Edition, everything seems fine,
in the kernel table there 1 one entry and 3 blanks, and in the
shadow there are 2 entries and 2 blanks.

However on the computer with Windows 2003 Server Standard R2
SP1, there would appear to be only space for two entries in
each table. Since The tables are placed end to beginning, that
would mean that the table at an offset of +2 in the 1st table
is really the offset of +0 in the 2nd table.

Essentially, why would the table’s starting address be
offset by 0x40 in the first situation and only x20 in the 2nd
situation. Wouldn’t that cause problems if one wanted to add
tables?

If anyone could help me make sense of this, or point out my
beginner mistake it would be much appreciated.

J.J.

Hi,

  1. Re-read all the warnings about hooking and how wrong this is.

  2. Remember to disable write-protection in CR0 before changing these
    pointers.

  3. Note that your code will never work on 64-bit Vista and future
    versions of Windows NT. You will bugcheck your own computer. This is
    called PatchGuard.

  4. If you want to hook native APIs for “educational purposes” and you
    are a newbie, it might help to actually hook only the NTDLL exports with
    Detours. Much much safer…

  5. Yes, one of SP1’s new kernel integrity features is removing
    KeAddSystemServiceTable (well, actually it’s still there, but only for
    user by Win32k.SYS). (Two others, btw, are to disable
    \Device\PhysicalMemory access from user-mode and NtSystemDebugControl

  • I gave a talk on this last weekend at REcon). This also changed the
    definition of NUMBER_SERVICE_TABLES in ke386.h to 2 from 4, and since
    KeServiceDescriptorTable is defined as:
    KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[NUMBER_SERVICE_TABLES];
    then this means 2 entries.

However, for the purposes of hooking, this doesn’t really have to change
your code, because it’s only “useful” for people that wanted to add
their own Native APIs.

  1. Again, don’t ever hook commercially, and if you’re doing this for
    educational purposes, you should really hook ntdll with something like
    Detours instead.

Best regards,
Alex Ionescu

> I mean you are going to have to validate that buffer pointers and lengths

are valid before you access the data.

It seems to me that MS could do itself and the kernel programming community
in general a good turn by publishing an example of exactly how a kernel call
interface should be validated.

Those that have source access can look at any random interface and see the
tricks used to validate the parameters. They are in general simple enough
and pretty straight-forward.

But they aren’t necessarily the structure someone out in the wild might
think of to perform these operations. The result is that people invent
their own techniques. And these inventions are generally either too simple,
or are needlessly complex - and STILL can have major holes in their
validations!

Simply taking the top page of code for one of the NtQuerySystemXxx
functions, strip out the calls to non-validation functions and replace them
with dummys, and publish the rest with additional comments on how the
validation is working might solve a LOT of problems for both code hookers
and MS itself.

Just an idle thought.

Loren

> KeServiceDescriptorTableShadow. Microsoft Internet Information Server’s

Spud Driver does this.

Is SPUD still here in 2003? Is it not replaced by http.sys?

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com