Tag: security

  • Does TDE really work on MDF files?

    Yes, it does. However, let’s prove it. First let’s create a database, a table, and enter some data:

    -- create a database
    CREATE DATABASE TDE_Primer
    ;
    GO
    -- create and populate a table
    USE TDE_Primer
    go
    CREATE TABLE MyTable
    ( myid INT
    , myname VARCHAR(20)
    , mychar VARCHAR(200)  
    )
    ;
    go
    DECLARE @i INT = 65;
    WHILE @i < 92
     begin
      INSERT mytable SELECT @i, 'Steve Jones', REPLICATE(CHAR(@i), 200);
      SELECT @i = @i + 1;
     END
    ;
    GO
    SELECT * FROM Mytable;
    go

    If I look at the table, I see my name with lots of data:

    Capture_030

    Now let’s detach the database and examine the results with a hex editor:

    -- detach database
    USE [master]
    GO
    EXEC master.dbo.sp_detach_db @dbname = N'TDE_Primer'
    ;
    
    GO

    I use XVI32 as an editor. It’s free, and you can download it. If I open up my MDF in this utility, here’s what I see:

    Capture_031

    If I search for my name:

    Capture_032

    I find it:

    Capture_033

    This is what I expect, and you should as well. Even without SQL Server, your data files are readable, which is why you must protect them.

    Now let’s attach the file and enable TDE.

    USE [master]
    GO
    CREATE DATABASE [TDE_Primer] ON 
    ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TDE_Primer.mdf' ),
    ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TDE_Primer_log.ldf' )
     FOR ATTACH
    GO
    
    USE TDE_Primer
    go
    SELECT * FROM mytable
    ;
    go
    
    -- begin encryption setup
    -- from http://msdn.microsoft.com/en-us/library/bb934049.aspx
    USE master;
    GO
    -- create master key for master
    CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'AlwaysU$eaStr0ngP@ssword4This'
    ;
    go
    
    -- create certificate to secure TDE
    CREATE CERTIFICATE TDEPRimer_CertSecurity WITH SUBJECT = 'TDE_Primer DEK Certificate';
    go
    
    USE TDE_Primer;
    GO
    -- Create DEK
    CREATE DATABASE ENCRYPTION KEY
    WITH ALGORITHM = AES_128
    ENCRYPTION BY SERVER CERTIFICATE TDEPRimer_CertSecurity;
    GO
    
    -- backup TDE cert
    USE master
    ;
    go
    BACKUP CERTIFICATE TDEPRimer_CertSecurity
     TO FILE = 'tdeprimer_cert'
      WITH PRIVATE KEY (
                   FILE = 'tdeprimer_cert.pvk',
                   ENCRYPTION BY PASSWORD = 'AStr0ngB@ckUpP@ssw0rd4TDEcERT%')
    ;
    go
    
    -- check encryption status
    SELECT
        db.name,
        db.is_encrypted,
        dm.encryption_state,
        dm.percent_complete,
        dm.key_algorithm,
        dm.key_length
    FROM
        sys.databases db
        LEFT OUTER JOIN sys.dm_database_encryption_keys dm
            ON db.database_id = dm.database_id;
    GO
    
    -- enable encryption
    USE TDE_Primer
    ;
    GO
    ALTER DATABASE TDE_Primer
      SET ENCRYPTION ON;
    GO
    -- check encryption status
    SELECT
        db.name,
        db.is_encrypted,
        dm.encryption_state,
        dm.percent_complete,
        dm.key_algorithm,
        dm.key_length
    FROM
        sys.databases db
        LEFT OUTER JOIN sys.dm_database_encryption_keys dm
            ON db.database_id = dm.database_id;
    GO
    -- TDE_PRimer and tempdb encrypted
    
    -- detach database again.
    -- detach database
    USE [master]
    GO
    EXEC master.dbo.sp_detach_db @dbname = N'TDE_Primer'
    ;
    
    GO

    I won’t go into all the code, but this encrypts the database, backs up the certificate and then detaches it again. There are a few other things, but I cover them in another post.

    Now let’s open up the file in the hex editor again.

    Capture_034

    It looks the same. It’s not in the image, but just below this you can see the database name. There is a header, which is not encrypted. However when I search for my name, it fails.

    Capture_035

    If you scroll further around, you’ll see that most of the file is now encrypted.

    Capture_036

    Play with this and prove to yourself that TDE does really encrypt things.

  • Development, Operations, or Accounting

    These kinds of problems should not happen in the cloud.
    These kinds of problems should not happen in the cloud.

    I think the idea of a platform of services, such as Windows Azure provides, is a great idea. I’d love to be able to stop worrying about hardware in many cases, and even skip some of the infrastructure of networking and managing specific machines. Just having services that I could deploy to that run my database and code, would smooth out some of the hassles of Information Technology in many companies.

    However the services have to work and work well.

    I’ve had concerns with AWS and their outages, though Netflix has run a thriving business on that platform and learned to work within that service. I think the Azure platform is similar, and they’ve had a few outages, I do have concerns over where their outages have occurred. There was an expired certificate, then supposedly maintenance, later revealed to be heat issues.

    These issues bother me. Some are unavoidable, but some aren’t. I’m particularly concerned about the expiration of security certificates. This happened again recently to Azure, and it shouldn’t. I don’t know if this was a problem with the development groups that build applications using certificates, the operations groups that administer systems, or the accounting groups that might need to purchase new certificates, but part of what the “cloud” should bring is expertise and better qualities of service from the people doing the work.

    I can hire semi-competent people that don’t pay attention to details and suffer my own outages. At least then I know I’m to blame and I can replace them. However moving to a service like Azure or AWS means giving up a lot of control. If I can’t count on better services than I get in-house, I’m not sure there are many advantages to moving.

    Steve Jones


    The Voice of the DBA Podcasts

    We publish three versions of the podcast each day for you to enjoy.

  • The Command Shell

    Security holes are all around. Are there any in xp_cmdshell?
    Security holes are all around. Are there any in xp_cmdshell?

    Recently I heard a few people arguing over the use of xp_cmdshell in a particular situation. One person was adamant that there was a security risk in using this feature. Many of you probably feel the same way, and even the SQL Server platform has recognized there could be dangers with this feature and has it disabled by default, as part of the secure by default installation.

    However the security around this procedure has been improved over the years. Non system administrators cannot execute xp_cmdshell by default. Administrators can open up access using a proxy account, but this requires specific configuration changes by administrators. This means that a lot of the danger of using xp_cmdshell for administrative tasks has been removed.

    Or has it? This Friday I wanted to poll you and find out what you think. Many of you are creative in how you use SQL Server and will think of possibilities that many of us would not consider.

    Is there a security risk in allowing xp_cmdshell to be used by members of the sysadmin role?

    I’m not looking for potential issues if a proxy account exists. Instead I’m asking if there are real dangers in allowing administrators to use this tool? I assume you trust your administrators and they will not maliciously use this tool to cause issues in your SQL Server. Let us know how you feel this week.

    Steve Jones


    The Voice of the DBA Podcasts

    We publish three versions of the podcast each day for you to enjoy.

  • A Good Security Response

    I'm glad Evernote acted quickly and decisively with this incident.
    I’m glad Evernote acted quickly and decisively with this incident.

    Security will become more and more important in the future, at least in my mind. As we become more interconnected and dependent on digital services, if the level of fraud and security failures do not fall, many people will hesitate to use these services. I think certificates will be the future of digital security, but until we get better support for managing them built into all our OSes, I’m not sure we’ll move beyond passwords. I do think we need to move past passwords, but we’re stuck with them for now.

    Recently Evernote had a security breach and they forced all users to reset their passwords. It was slightly annoying, but it was a comforting response for me. Two week after the incident I had to change the password on my iPad, which I rarely use. It was ironic since I was working on this particular piece when I reset my password.

    I wasn’t the only one that thought this was a good response. In this article from Enterprise Security, a number of security professionals praised the way Evernote handled this incident. They note that Evernote had implemented good security practices (from what we know) and notified people immediately. I certainly appreciate Evernote moving quickly on this and am glad I had to deal with the annoying password change. I don’t use the same password on other sites, and this was a good reminder to me that I shouldn’t. It also served as a reminder to tell my family to do the same thing.

    I’m not sure any company I’ve worked for would handle things this way. I haven’t had many security incidents at my previous employers, but I know in one case we were told not to disclose anything and fix issues. I’d like to think that most companies would disclose this, and I do think they should, but most wouldn’t. These things happen, just like break-ins happen in physical buildings. Companies should accept that, diagnose the issues, repair them, and move on. Customers will understand the problem and remediation steps. What customers don’t understand, or accept, is a company failing to inform them. Or failing to improve security when they know there are issues.

    Steve Jones


    The Voice of the DBA Podcasts

    We publish three versions of the podcast each day for you to enjoy.