soumik.com Blog

March 20, 2009

Kerberos, GINA and SmartCards – III

Filed under: Uncategorized — Sarkar Soumik @ 6:10 am

Introduction to Kerberos

The Kerberos protocol is primarily based on shared secrets. It involves the following message exchanges (in a highly simplified form – from RFC4120):

  1. The Authentication Service (AS) Exchange

The client obtains an “initial” ticket from the Kerberos authentication server (AS aka KDC – Key Distribution Center), typically a Ticket Granting Ticket (TGT). The KDC encrypts its reply with a symmetric key shared between the KDC and the client. This key is derived from the client’s password (and the cause of the weakness mentioned above)

  1. The Ticket Granting Service (TGS) Exchange

The client subsequently uses the TGT to authenticate and request a service ticket for a particular service, from the Kerberos ticket-granting server (TGS aka KDC).

  1. The Client/Server Authentication Protocol (AP) Exchange

The client then makes a request to the service provider, consisting of a service ticket and an authenticator that certifies the client’s possession of the ticket session key.

Authentication across domain boundaries

In addition to the above ticket types, there is another type of ticket known as a referral ticket. Referral tickets are used to allow clients to authenticate across domain boundaries as follows:

When a client in domain A (say client-A) needs to access a resource in domain B, it sends it’s TGT to it’s home domain – A. the KDC for domain A determines that the resource is in fact under domain B. So, instead of sending back a service ticket, KDC-A returns a referral ticket for KDC-B – which is very similar to a TGT ticket.

Client-A then uses the referral ticket to obtain an actual service ticket from KDC-B.

For cross domain login to work, there should be a key shared between the two domains. This is done when establishing a trust relationship between the two domains.

Kerberos and service registration

The TGS maintains a list of services for which it can grant tickets. By default, this list includes all the computers that are members of the domain, the krbtgt service for it’s domain and other domains that it trusts.

Other services like web sites needing authentication needs to be explicitly registered with the TGS. If not done so, Windows will use NTLM behind the scene. This is also the case when accessing file system shares on computers in the domain when accessing them with the IP address instead of DNS names.

Next : How Kerberos works on windows with smart cards.

March 12, 2009

Kerberos, GINA and SmartCards – II

Filed under: security — Sarkar Soumik @ 6:14 am

 

MSGINA and Smartcards

When Winlogon detects the insertion of the smart card, it calls the following function in the GINA dll:

WlxLoggedOutSAS(dwSasType = WLX_SAS_TYPE_SC_INSERT)

Msgina.dll displays the following dialog asking for the user’s smart card PIN.


When the user enters the PIN and clicks enter, GINA calls the LsaLogonUses() function in LSA.

Role of LSA

The LSA is responsible for selecting a Security Support Provider (SSP) for network logon and passing the credential to it. In an AD domain, with Windows 2000 client and higher, the default SSP is the Kerberos SSP. It is also responsible for storing cached credentials for offline login.

Terminal services and GINA

Smart card logon is supported in a terminal services (TS) environment in Windows 2003 server. In this environment, the scard API calls made by the smart card CSP are remoted to the TS client. On the client, these calls are then passed on to the smart card driver.

GINA chaining

Though no explicit support is provided to chain GINA by the OS, in practice, this is a very popular. GINA chaining is achieved by individual GINA by remembering the previously installed GINA DLL and passing on calls to it after it’s own processing.

Next up : How does kerberos tie into all this.

March 11, 2009

Kerberos, GINA and SmartCards – I

Filed under: security — Sarkar Soumik @ 6:25 am

There is a lot of information on the web about the Kerberos protocol, Windows GINA and Smart cards. However, I could not find any place which brings all these items together in an easy to understand way. Understanding them together is important if you are developing a smart card like system and want to hook into windows GINA. Remember, GINA is already outdated in Vista by credential providers. But several concepts in this series will still be useful otherwise.

How GINA works

GINA is implemented as a DLL which is loaded by the winlogon process. The winlogon process runs with LocalSystem privileges. It registers the CTRL-ALT-DEL Secure Attention Sequence (SAS) and invokes the GINA DLL when a user presses this key combination. It also monitors the insertion of a smart-card and calls the GINA when one is inserted.

Winlogon defines three states which it can be in at any given point : Logged off, Logged On and Workstation Locked.

For every state, it has set of callback functions that it calls into the GINA with. For example, it calls WlxLoggedOnSAS when the SAS is pressed when a user is logged on. Refer to the MSDN documentation for further details.

Windows allows third parties to write their own GINA replacement to provide interactive login to the Windows desktop. The default implementation of GINA is provided by Microsoft and is called msgina.dll

In addition to allowing third parties to replace msgina completely, msgina itself provides hooks to allow third parties to change it’s default behavior. This is known as a gina-hook.

Most third-party implementation of GINA use a thin GINA replacement called gina-stub and offload the main work to msgina. This technique of gina-stubbing combined with gina-hooks makes the GINA quiet configurable without the necessity to rewrite an entire GINA module from scratch.

Next, I will write about how MSGINA interacts with smart cards. Stay tuned.

    

March 7, 2009

Starting to blog again

Filed under: Uncategorized — Sarkar Soumik @ 7:06 am

It has been a long time that I blogged. Have been too busy the last year or so. My notes are piling up so, I guess it is time to start blogging again.

See you soon.

September 21, 2007

Template template parameters

Filed under: c++ — Sarkar Soumik @ 12:59 am

These days, I am reading Modern C++ design by Anderi Alexendrescu. This book is very heavy on templates so much so that it mentions template template parameters in the first chapter itself. So, I took a pause and decided to review my notes on template parameters. I cannot believe I knew this much about templates at one point of time J. Anyway, the following is from my notes that I have taken over the years.

Templates can take the following types of parameters:

  • POD – plain old data
  • Built in types
  • Classes
  • Other templates – aka template template parameters

POD

Yes, templates can take plain old data. This is how most functors work with the C++ standard library.

Notice how 100 is being passed as the template parameter. This program prints “Hello World 1200″

Built in types / Classes

There is no real difference as far as the compiler is concerned between built in type template parameters and user defined type (classes) template parameters. But I still like to differentiate between them since it helps the users of my class (which is myself most of the times) understand more about the template class. Which is to use typename
for specifying any type is will do and class
to denote that only classes (user defined type) will satisfy a template parameter.

So, for example:

The point I want to illustrate here is that when any type will do (i.e. built in as well as user defined) you should use typename.

And when only classes will fit the bill, use class
as follows:

Now, what happenes when you mix and match?

Ops! The above will give you an error like : ‘T’ is not a legal base class

So, save yourself and your code maintainers some trouble and use the naming convention. Of course, this is nothing new. I am just restating a well known convention in the C++ programming community.

Template template parameters

This is the most interesting one. It is the case where the parameter itself is a template. The best way to see it at work is with a policy class. Policy classes are template parameters which change the way a template class behaves.

Say you have a policy class which looks like this:

And you have a Host class which needs to be derived from the above policy class. You would write something like the following:

The first template parameter T is our normal “anytype” parameter. The second parameter is a template – and hence is called a template template parameter. The policy parameter in turn, uses the first parameter T during instantiation.

Now, you would instantiate the Host class as follows:

Host<int, MyPolicy> h;

Notice that the second parameter is just the name of the template – MyPolicy. It is not MyPolicy<int>. This distinction is important since the compiler is taking over the job of instantiating MyPolicy with the int parameter. This helps in two ways : less errors and less typing.

 

Thinking about template parameters

Talking about template parameters, the best way to think about them is to compare them to normal function parameters. So, just like you can omit all parameter names in function declaration, so can you for template parameters. So, instead of writing

template <typename T, template <class U> class Policy> class Host : public Policy<T>

You can write

template <typename T, template <class> class Policy> class Host : public Policy<T>

Notice the missing U. This is OK since U is not being used anywhere. It just tells the compiler that the Policy class is a template which takes one template parameter.

 

 

September 13, 2007

VMTools Backdoor?

Filed under: security — Sarkar Soumik @ 8:40 pm

VMware open sourced the code for their VMTools. This is the piece of software that you install inside the VM guest to do things like synchronize time between the guest and the host, attach host devices to the guest etc. I have always wondered how this application running inside the guest OS communicates with the VMWare application which is running on the host. There must be a backdoor I thought.

So, the first thing I did after downloading it was to search for “backdoor”. And lo and behold there is an entire library called backdoor.

The backdoor.c file has the following comment at the top

Wow! I had to look further. The main function in backdoor.c library is also called BackDoor().

This function takes an argument of type Backdoor_proto which is a union used for both input and output. So, when you want to send something to VMWare host program, you use the in part of the union.

It gets more interesting. The cx member of the in part or the union takes one of a number of commands defined in \lib\include\backdoor_def.h

The command the jumps out is BDOOR_CMD_INT13. Now, Int 13 is used for disk IO. Does it mean you can do arbitrary disk IO on the host machine from the guest VM? I hope not J

 

September 11, 2007

OSXVnc as a KVM switch

Filed under: productivity — Sarkar Soumik @ 4:24 am

This is something that I discovered by accident a few days ago. Perhaps might be useful to someone out there.

I usually work with both a Mac running OSX as well as my laptop running Windows (actually, it is a Server 2003 64 bit edition – I will blog on why I use a server flavor and why 64 bit if I have some time later). I don’t have too much space on my desk so am stuck with just one monitor. The monitor does accept two inputs so both my machines are plugged into it. It also has a button on the front using which I can switch the input between the two machine. All this is nice but I still have to take care of the keyboard and mouse. Have been thinking of getting a KVM switch for some time but have been lazy so far J. Also, none of the KVM switches that I have used in the past were very reliable so, have developed some kind of a dislike for them.

For the time being, I have been using the OSXVNC server on the Mac and connecting to it from the Windows laptop using the RealVNC viewer. Given it is free, it does a pretty good job of getting the work done. But it is pretty slow on the rendering front – even on the Gigabit Ethernet switch that I have in my office now.

So, most of the time, I am actually switching the display and using the Mac wireless keyboard and mouse combo to work on the Mac and another set of keyboard/mouse for the windows laptop.

Now the interesting part (if I have not put you to sleep already that is J). A lot of the times when switching machines, I forget to use the different keyboard causing some frustration. However, today I when I made the same “mistake” while switching from Windows to Mac, I was shocked to see that my windows keyboard and mouse continued to work on the Mac! What? How is that possible? My mouse is connected to the Windows laptop! How is it controlling the mouse cursor on the Mac?

After 10 seconds of head scratching, it dawned on me that I have been running RealVNC on the Windows machine as the foreground window and then switched the display to Mac. This resulted in my Windows keyboard input going to RealVNC and on to the Mac. Wow!

What this means is that I don’t really need a KVM switch. All I need to do is run RealVNC on the Windows machine as the foreground window and then switch the monitor. What? You already knew this? J

September 10, 2007

User Account Protection in Vista

Filed under: win32 — Sarkar Soumik @ 7:57 am

(I wrote this article almost a year back – when I got a beta version of Vista to play with. So, beware some of it might have changed)

Most rootkits, keyloggers and some spyware install on Windows using features which require administrator rights. Therefore, it would be much safer for users if they run without administrator rights. But the problem is that even now, it is quite difficult to find applications that can run properly with standard user rights. Most of the applications written today assume that the user has administrator rights.

A new security feature in vista is User Account Protection (UAP). The primary goal of this feature is to prevent users from unnecessarily running applications with administrator rights, thereby preventing inadvertent damage to their machine.

UAP is an intermediate step towards the goal of running all programs with standard user rights. Though this is the ideal case, today, most of the applications are written assuming administrator rights. As a result, users are forced to run as administrators. In fact, the first users that the windows setup program lets you create are members of the administrators group. This is where UAP is useful. It runs administrators as standard users by default.

UAP provides several configuration options, including the following:

1. By default, UAP runs all apps as standard user. This can be turned off – in which case all users will run with their full privileges. Interactive applications that request elevation of privileges can be optionally checked for a valid signature.

2. When an app tries to run as administrator, UAP can be configured to ask for the user’s credentials, answer a consent dialog, or silently allow the operation (only if it has the required privileges).

3. Users can mark their applications as requiring administrative privileges by using the app compatibility database or the application manifest. They can also explicitly run an app as the administrator from the right click context menu.

4. For legacy apps that run as standard user but still try to write to %Program Files%
%Windows%, or HKLM\Software\
there is a redirection mechanism which will trap registry and file system write failures and redirect the write to HKU\<SID>\Software\Classes\VirtualStore
and
C:\Users\<name>\AppData\Local\VirtualStore\ respectively.

On windows, every process has a security token which represents the user’s permission. UAP reduces the power of the token in the following ways:

  • The administrators SID (Security Identifier) is changed into a deny-only SID.
  • The token is deprived of all privileges.
  • Depending on the trust level of the program (also known as Mandatory Integrity Control or MIC), one or more group SIDs are added to the token.
    Before we look into the above items in detail, let us go over some of the terminology used in windows security.  

    Access Control Entry (ACE)

    ACEs are associated with resources like files and registry entries. They dictate what kind of access a trustee has on the resource. An ACE contains three things – the SID for which it specifies the permission, a bitmask denoting the permissions, and a bit specifying whether to allow or deny permission.

    Deny Only SID

    When you change an SID to a deny-only SID, the SID will never be used to gain access to a resource. The SID is still kept in the token to make sure that it is used to deny access to resources that explicitly deny access to that trustee. In other words, the deny-only SID is never checked against an allow-ACE of a resource.

    Privileges

    Privileges are used to control the user’s global rights. In other words, they are not tied to any particular resource and apply to the computer in general. SeDebugPrivilege is an example of a privilege. It lets users debug (look inside) other processes.

    Mandatory Integrity Control (MIC)

    MIC is a means of restricting access to resources based on the trustworthiness of the application. It is implemented in Vista using restricted SIDs – which permits resources to allow access not only based on the user but also the trustworthiness of the process.

    Now let us discuss the implications of the restrictions imposed on apps that are run as standard users.

    When the Administrators group SID is turned into a deny-only SID, the process can no longer use its administrator’s group membership to gain access to a resource. This means that the process needs to prove its rights over the resource using a different SID. A process cannot revert to its deny-only SIDs.

    In the second step, UAP strips the process token of all privileges other than SeChangeNotifyPrivilege. SeChangeNotifyPrivilege lets the OS bypass checking permission on every file while traversing directories – which is required for fast traversal of directories.

    Finally, UAP adds two new group SIDs to the token. These new group SIDs depend on the MIC of the application (which we will get to shortly). Both the new SIDs are in fact the same except for their attributes. The first one has GroupIntegrity and GroupIntegrityEnabled attributes while the second one has GroupIntegrity and GroupIntegrityEnabledDesktop.

    Applications in the current vista beta (Build 5303) are categorized into 7 different groups – Secure Process, UI Access, System, High, Medium, Low, and Untrusted. System is the most trustworthy group and Untrusted – the least. Depending on the group, the process is marked with the following MIC labels (they are actually group SIDs in the process access token).

    • Secure Process – Mandatory Label\Secure Process Mandatory Level – S-1-16-20480.

      This indicates the highest trust level. There is no information from Microsoft yet on the resources that this level can access.

    • UI Access – Mandatory Label\UI Access Mandatory Level – S-1-16-16640.

      There is no information from Microsoft yet on the resources that this level can access.

    • System – Mandatory Label\System Mandatory Level – S-1-16-16384.

      There is no information from Microsoft yet on the resources that this level can access.

    • High – Mandatory Label\High Mandatory Level – S-1-16-12288.

      Processes at this level can install files to the program files folder and write to the HKY_LOCAL_MACHINE registry key.

    • Medium – Mandatory Label\Medium Mandatory Level – S-1-16-8192.

      Processes at this level can create and modify files in the user-specific areas of the system. The default label for processes is Mandatory Label\Medium Mandatory Level. All files and registry keys in Vista have a default MIC label of Medium.

    • Low – Mandatory Label\Low Mandatory Level – S-1-16-4096.

      These processes are deemed untrustworthy. They can only access very limited sets of resources on the system like the “Temporary Internet Files” directory.

      IE 7 in protected mode, for example, runs with the Low MIC label and as a result, has access to only to the “”C:\Users\<username>\AppData\Local\Microsoft\Windows\Temporary Internet Files\Low” folder which also has the MIC label set to Low.

    • Untrusted – Mandatory Label\Untrusted Mandatory Level – S-1-16-0

      This is the lowest possible trust level. There is no information from Microsoft yet on the resources that this level can access.

    In addition to the segregation of resources, applications with a lower MIC are prevented from opening the handle to processes with a higher MIC. This mitigates several problems including injection of code into the higher privilege process.

    Resources created by an app will get the app’s MIC label.

    Any child process started by a process will run with the MIC label of its parent. This is normal since the process token is inherited from its parent.

    So far we saw how MIC is used to group applications according to their trustworthiness. This was possible by using the new group SIDs in the applications’ access token. Note that this mechanism is possible only while protecting securable objects (objects that have an associated security descriptor).

    What about objects that are not securable? Things like windows on the same desktop? To address this problem, Vista has another new feature called User Interface Privilege Isolation (UIPI).

    UIPI uses MIC to protect apps from one another. Apps with a lower MIC cannot perform the following operations on apps with higher MIC.

    • Cannot start a DDE (Dynamic Data Exchange) conversation.
    • Cannot insert keyboard or mouse input into the input stream.
    • Cannot hook into (inject DLL).

    To conclude, I think that UAP is a good compromise between no users having the administrative privileges vs. all users running as administrators.

September 4, 2007

Hello world!

Filed under: Uncategorized — Sarkar Soumik @ 3:48 pm

Welcome to my blog!

Powered by WordPress