Freitag, 8. September 2006

Sicherheit

Entschlüsselung von Stored Procedures bei SQL-Server 2000

Die Verschlüsslung von Stored Procedures beim SQL-Server 2000 ist seit einiger Zeit geknackt. Doch wie funktioniert die Entschlüsslung von Stored Procedures?

Da ich mich momentan mit dem SQL-Server 2000 und Stored Procedures arbeite, bin ich auf einen interessanten Artikel in einer Newsgroup gestossen. In diesem Artikel wird erklärt, wie man Stored Procedures wieder entschlüsselt.

Interessanterweise wird die Entschlüsslung der Stored Procedure komplett mit SQL abgewickelt. Der Artikel ist momentan leider nur in englischer Sprache verfügbar, doch möchte ich ihn euch nicht vorenthalten.

Entschlüsslung von Stored Procedured unter SQL 2000

So here's how stored procedure (and view and trigger) encryption works on
SQL Server 2000:
1.  Take the the database's GUID (generated when the db is created), the
object id (from sysobjects) and the colid (from syscomments) and
concatenate them.
2.  Hash the key using SHA.
3.  Use the SHA hash as an RC4 key, generate a sequence of bytes equal in
length to the stored procedure text.
4.  XOR this stream of bytes against the stored procedure text.

This is a bit short on detail and is based on a dimly remembered
conversation with an MS employee I bummed a cigarette off while visiting
the campus, so it may not be 100 % accurate.

Anyway, there are 2 ways to set about recovering the plaintext.  One is to
retrieve the components of the key (the guid is retrievable through dbcc
dbinfo, but you have to be sa to run that command) and this is the
approach taken by dSQLSRVD.

The second option is to find a way to encrypt your own plaintext with the
same key.  If you can do this, the encryption algorithm degenerates to
simple XOR encryption with a reusable pad.

It turns out that it's trivial to do this thanks to the "ALTER PROCEDURE"
statement.  Kind of makes you wonder why Microsoft chose to waste cpu cycles
with SHA and RC4 since it doesn't buy any extra security.

Anyway, here's some sample code:

Download Code!

  1.  
  2. SET NOCOUNT ON
  3. CREATE TABLE #tempcomments (
  4.    ID int PRIMARY KEY NOT NULL
  5.   ,ctext nvarchar(4000) NOT NULL
  6. )
  7. GO
  8. CREATE PROCEDURE bob
  9.    WITH ENCRYPTION
  10. AS
  11. PRINT 'I encrypted this procedure and forgot to check the source into cvs!'
  12. PRINT 'Now I don''t work here any more and you can''t find me!'
  13. GO
  14.  
  15. INSERT INTO #tempcomments
  16. SELECT 1, ctext FROM syscomments WHERE id = object_id('bob')
  17. GO
  18. ALTER PROCEDURE bob
  19.    WITH ENCRYPTION
  20. AS
  21. ------------------------------------------------------------------------------
  22. ------------------------------------------------------------------------------
  23. print 'I know a secret.'
  24. GO
  25.  
  26. INSERT INTO #tempcomments
  27. SELECT 2, ctext FROM syscomments WHERE id = object_id('bob')
  28. GO
  29.  
  30. DECLARE @origcryptstr nvarchar(4000)
  31.   ,@origplainstr nvarchar(4000)
  32.   ,@knownplainstr nvarchar(4000)
  33.   ,@knowncryptstr nvarchar(4000)
  34.  
  35. DECLARE @length int
  36.   ,@counter int
  37.  
  38. SELECT @origcryptstr = ctext FROM #tempcomments WHERE ID = 1
  39. SELECT @knowncryptstr = ctext FROM #tempcomments WHERE ID = 2
  40. SELECT @knownplainstr = N'CREATE PROCEDURE bob
  41.   WITH ENCRYPTION
  42. AS
  43. --------------------------------------------------------------------------------
  44. --------------------------------------------------------------------------------
  45. print ''I know a secret.''
  46. '
  47. SET @length = datalength(@origcryptstr)
  48. SET @origplainstr = replicate(N'A', (@length / 2))
  49. SET @counter = 1
  50. while (@counter <= (@length / 2))
  51. begin
  52.    SELECT @origplainstr = stuff(@origplainstr, @counter, 1,
  53.       NCHAR(UNICODE(substring(@origcryptstr, @counter, 1)) ^
  54.       (UNICODE(substring(@knowncryptstr, @counter, 1)) ^
  55.          UNICODE(substring(@knownplainstr, @counter, 1)))))
  56.    SET @counter = @counter + 1
  57. end
  58. SELECT @origplainstr
  59. exec('drop procedure bob')
  60. exec(@origplainstr)
  61. GO
  62. DROP TABLE #tempcomments
  63. GO
  64.  
Bewertung: keine, 0 Stimme(n) 893 Klicks
Sicherheit
Von Mr.Foo in Sicherheit am 08.09.06@12:10 Uhr

Trackbacks
Trackback für spezifische URI dieses Eintrags

Keine Trackbacks

0 Kommentare
Ansicht der Kommentare: (Linear | Verschachtelt)

Noch keine Kommentare


Kommentar schreiben

Umschließende Sterne heben ein Wort hervor (*wort*), per _wort_ kann ein Wort unterstrichen werden.
Standard-Text Smilies wie :-) und ;-) werden zu Bildern konvertiert.
Die angegebene E-Mail-Adresse wird nicht dargestellt, sondern nur für eventuelle Benachrichtigungen verwendet.
Sie können [geshi lang=LANG][/lang] Tags verwenden um Quellcode abhängig von der gewählten Programmiersprache einzubinden
 
 

Mr. Foo

Entschlüsselung von Stored Procedures bei SQL-Server 2000

  • Homepage

Suche

Kategorien

  • Android (2)
  • C-Sharp (4)
  • Datenbank (30)
  • Delphi (2)
  • Entwicklung (36)
  • Flash (5)
  • Games (10)
  • Gutscheine (4)
  • Hardware (14)
  • HTML CSS (16)
  • Internet (88)
  • Java (32)
  • Javascript (24)
  • Linkdump (9)
  • Linux (102)
  • Low-Level (10)
  • Lua (8)
  • Musik (9)
  • Netzwerk (25)
  • New World Order (109)
  • Perl (3)
  • PHP (130)
  • Magento (5)
  • Symfony (3)
  • Zend Framework (7)
  • Probleme und Lösungen (26)
  • Python (22)
  • Ressourcen (23)
  • Sicherheit (91)
  • Software (60)
  • Sonstiges (47)
  • Own Stuff (48)
  • Spass (46)
  • Technik / Wissenschaft (4)
  • Tips (15)
  • Weisheiten (17)
  • Windows (23)
  • Wort des Tages (15)


Alle Kategorien

Archive

  • Mai 2012
  • April 2012
  • März 2012
  • Das Neueste ...
  • Älteres ...

Abonnieren lohnt sich!

  • XML RSS 2.0 feed
  • ATOM/XML ATOM 1.0 feed
  • XML RSS 2.0 Kommentare

Tagcloud

Datenbank Entwicklung Internet Java Javascript Linux Lösung Netzwerk News New World Order PHP Problem Probleme und Lösungen Sicherheit Software Sonstiges Spass Tipp Update Windows

Beliebte Einträge

  • Magento ist scheisse (197)
  • Plugin-container.exe deaktivieren (107)
  • BWin Betrug und Abzocke bei Minigames? (65)
  • C compiler cannot create executables unter Debian (53)
  • Scheiss Linux - USB-Platte viel zu langsam (wenns mal funktioniert) (43)
  • Sicheres Kontaktformular mit PHP - Spam verhindern (37)
  • UML-Diagramme aus Java-Klassen generieren – Java2UML (28)
  • Es konnte keine TCP/IP-Verbindung mit dem Host hergestellt werden (28)
  • Option Bug im Internet Explorer bei Nutzung von innerHTML und Javascript (24)
  • Zend Studio - Javaw.exe lastet die CPU aus (24)

Kommentare

Hugo zu BWin Betrug und Abzocke bei Minigames?
So, 20.05.2012 12:25
ich habe mich gestern auf BWIN reg [...]
Ubuntu 12.04 zu The assembly mscorlib.dll was not found or could not be loaded.
Fr, 18.05.2012 17:11
Hat bei mir leider nicht geklappt. [...]
Oliver Riske zu Es konnte keine TCP/IP-Verbindung mit dem Host hergestellt werden
Di, 15.05.2012 20:38
Super Danke!
anon zu BWin Betrug und Abzocke bei Minigames?
Sa, 05.05.2012 18:43
ihr scheiss betrüger
Jürgen zu Unable to elevate error:1814 VLC Problem
Mi, 02.05.2012 16:54
So einfach ist es bei mir jedenfal [...]
 

Kontakt/Informationen