views:

1503

answers:

3

Hello,

I am trying to find a way to decode the REG_BINARY value for "HKLM\Software\Microsoft\Ole\DefaultLaunchPermission" to see which users have permissions by default, and if possible, a method in which I can also append other users by their username.

At work we make use of DCOM and for the most part we always give the same users permission but in some cases we are forced to accommodate our clients and add custom users/groups to suit their needs. Unfortunately the custom users we need to add are random usernames so I am unable to just add all the users and copy the value from the key like I have done with the default users we use 95% of the time.

I am currently working on a command-line executable application where I have a command to set permissions for pre-defined users but I would also like to be able to add an option to append a custom user(s) to add to the default permission along with our predefined default users list.

Currently, to set the default users list with my application I would just type:

MyTool.exe Policies

But I would like to be able to make it a bit more verbose, closer to how NET command is used for windows users, something like:

MyTool.exe Policies /ADD:"MyCustomUsername"

The problem is that the data stored in the REG_BINARY value doesn't seem to be easily decoded. I was able to decode the hex portion in python but I am left with some sort of binary data which I don't have a clue what to do with as I don't even know what kind of encoding was used in the first place to know what to use to decode it. :P

I have done quite a bit of googling but I think my lack of understanding the terminology around this topic has probably caused me to overlook the answer without recognizing it for what it is.

I guess my first real question would have to be what kind of encoding is used for the above key after it has been decoded from hex?

Or better yet, is it even possible to obtain/modify the key's value programmatically so that I can obtain a list of the users that are currently set, and if necessary, append additional users/groups?

I would prefer to keep this application written strictly in Python if possible (or WMI/WMIC), but if necessary I can attempt to implement other types of code into my python application if it means getting the job finally done! I guess it would also be useful to mention that this application is primarily used on Windows XP Professional and most Windows Server versions so I am not worried if any possible solution will not be compatible with earlier Windows OS version(s).

Any assistance, code or just some simple help with getting familiar with this topic, would be GREATLY appreciated!

Thanks in advance for any help you can provide!! :D

A: 

Well REG_BINARY isn't any particular format, it's just a way to tell the registry the data is a custom binary format. So you're right about needing to find out what's in there.

Also, what do you mean by converting the data from hex? Are you unpacking it? I doubt you're interpreting it correctly until you know what has been saved in there in the first place.

Once you find out what's in that registry field, python's struct module will be your best friend.

http://docs.python.org/library/struct.html

Further reading (you've probably already seen these)

Trey Stout
Thanks for your prompt response :Dyeah well see this is what happens when you over google yourself with too many random posts and not enough information regarding your topic.. ;)From some of the posts I read, It implied that the data stored within the key is some sort of binary data which has then been encoded to hex. The posts seemed to imply this to be standard for these type of binary entries. One of them also mentioned something about md5 encoding although I'm probably way off.
AWainb
You are right about your "Further reading" section, I am familiar with both links, and I use _winreg a lot although I just discovered struct today while I was researching this topic. you're probably correct to assume that I am interpreting it incorrectly as I am unsure of what kind of binary data I am dealing with and I have been unable to find anything dumbed down enough for me to understand.Any ideas as to how I can figure out "what is saved in there" so I can move on to the next step?
AWainb
It appears that an ACL goes in that value. You'll need to find the structure of registry ACLs to know how to build one in binary and shove it in there. - http://msdn.microsoft.com/en-us/magazine/cc982153.aspx - http://isg.ee.ethz.ch/tools/realmen/det/dacl.en.htmlI would grab ProcMon from sysinternals. Run it on a process that you know sets that registry key properly, and watch for that event in ProcMon. You could then probably catch what another program is putting in there.
Trey Stout
A: 

We came across similar issues when installing a COM server that was hosted by our .NET service, i.e. we wanted to programmatically alter the the COM ACLs in our install logic. I think you'll find that it's just a binary ACL format that you can manipulate in .NET using the class:

System.Security.AccessControl.CommonSecurityDescriptor

So sorry I can't help you in getting a Python solution, but if your back is to the wall and you can manage .NET, some sample code would look like:

int launchMask = (int) (COM_RIGHTS.EXECUTE | COM_RIGHTS.EXECUTE_LOCAL | COM_RIGHTS.ACTIVATE_LOCAL);

SecurityIdentifier sidAdmins = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
SecurityIdentifier sidInteractive = new SecurityIdentifier(WellKnownSidType.InteractiveSid, null);

DiscretionaryAcl launchAcl = new DiscretionaryAcl(false, false, 3);
launchAcl.AddAccess(AccessControlType.Allow, sidAdmins, launchMask, InheritanceFlags.None, PropagationFlags.None);
launchAcl.AddAccess(AccessControlType.Allow, sidInteractive, launchMask, InheritanceFlags.None, PropagationFlags.None);

CommonSecurityDescriptor launchSD = new CommonSecurityDescriptor(false,
                                                                    false,
                                                                    ControlFlags.DiscretionaryAclPresent | ControlFlags.SelfRelative,
                                                                    sidAdmins,
                                                                    sidAdmins,
                                                                    null,
                                                                    launchAcl);


byte[] launchPermission = new byte[launchSD.BinaryLength];
launchSD.GetBinaryForm(launchPermission, 0);

You then take the launch permission byte array and write it to the registry. If .NET is a non-starter you can at least have a look at how the .NET classes work and see what win32 functions they use. You can either use the reflector tool to look at the relevant assembly, or MSFT actually publish the .NET source.

donovan
A: 

Hi donovan,

I am new to ACL and ACEs and in my C# assignment, I have to add 'EveryOne' and 'Anonymous Logon' users to the existing set of users in Default Access Permission (at 'My Computer' level). Could you please, help me. Thanks in Advance!

Don't post questions as answers to other questions. There's the **Ask Question** button in the upper right for adding new questions.
Helen