.NET Reflection, RCE and Hard Coded Keys

Sometimes you need to extract some data out of another application but the data stored as encrypted. As you might guess generally keys are just hardcoded, but mostly algorithm is custom. Since there is no such a thing as "client-side security", there are so many ways to do decrypt this data.

You can go and reverse the code which is decompiling the application and copy, paste then tweak the code to compile. But this can be a real pain when dependencies and obfuscated code comes into the play.  Since new obfuscators taking the advantage of IL tricks, generally it's not easy to use decompiler generated high-level code without heavy modification.

Unless you are a masochist I'd suggest you to use the application's code to do the job.

  1. Find the decryption point and the DLL,
  2. Invoke the related decryption function using reflection.

We use reflection instead of simply referencing the dll because this way it's possible to call any method within any scope such as private and friend which wouldn't be possible otherwise. Also it allows us to easily bypass Strong Name restrictions without touching to the original binary.

Here is the code:

   1: Function Decrypt(ByVal data As String) As String
   2:     'Load Assembly
   3:     Dim CustomAssembly As Assembly = Assembly.Load("DLL.To.Load")
   4:     Dim CustomType As Type = CustomAssembly.GetType("DLL.To.Load.SecretClass", True, False)
   5:  
   6:     Dim CopyObj As Object = CustomAssembly.CreateInstance(CustomType.FullName)
   7:     Dim Res As Object = CustomType.InvokeMember("Decrypt", BindingFlags.InvokeMethod, Nothing, CopyObj, New Object() {data})
   8:  
   9:     Return Res.ToString
  10: End Function
anahtar kelimeler : english reflection code snippet decryption encryption reverse engineering rce development net

Muhammed Köroglu - 16.12.2008


Kesinlikle sinan arkadasimiza katiliyorum,

bir tesekkür edebilirdin, zira bunu oturup buraya yazmak bile bir zaman aliyor.

Senin ihtiyacin olmayabilir ama tesekkür, bilgi paylasimini arttiracaktir.

Cihan - 16.09.2008

Konuyla ilgili olarak, metotlarinizin reflection ile disaridan çagirilmasinin tek yolu var ki o da obfuscation ile zorlastirmak. Bazi obfucatorlar gelismis tekniklerle metadayi bozabiliyor, metotlari çok karmasik isimlere sokabiliyor veya native koda çevirerek decompilation'i tamamen engelliyor. Su ana kadar gördügüm en basarili uygulama :http://www.eziriz.com/dotnet_reactor.htm

Cihan - 15.09.2008

cihan kardes adam fistik gibi kisa ve öz anlatmis kendisine tesekkür ederiz, ilk yoruma laf etmissin ama sende laf geçirmek için yorum yazmis gibisin, açiklamissin türkçesini birak öyle kalsin
, laf sokmak?? arkadasim, saçma sapan bir yorum yazmissin. Bir kere ben "javaci" veya java hayrani vs. degilim. Bunu ekstra bir bilgi olarak verdim. Kralci bir tavir söz konusu degil. Anlamadan etmeden yorumlar yazmayalim istersen.

sinan - 15.09.2008

cihan kardes adam fistik gibi kisa ve öz anlatmis kendisine tesekkür ederiz, ilk yoruma laf etmissin ama sende laf geçirmek için yorum yazmis gibisin, açiklamissin türkçesini birak öyle kalsin

Bu trick Java dünyasinda da birkaç asirdir uygulaniyor
demeye ne gerek var ?
bunu ferruh simdimi yazdi framework çikali kaç sene oldu ? ...
java da .net de babamin oglu degil ama böyle kraldan çok kralci tavirlar, firsatini buldun geçir lafi tarzinda yaklasimlar zinirlerimi siplatiyor kusura bakma

ferruh yorumlari böyle kisisel bi duruma alet ettigim için de sen kusura bakma:)

Cihan - 14.09.2008

Güzel makele olmus da Türkçe meali nedir bu yazinin?
Anlamadan makalenin güzel olduguna karar veriyorsun?:) Mealine gelince: Baska uygulamalara ait olan metotlari kullanmak için reflection yöntemini kullanmaktan bahsediyor. Binary dosyayi decompile etmeden (ki yeni obfuscator'lar ile bunu gerçeklestirmek gerçekten zor), reflection ile ilgili objenin sakli metotlarina ulasarak bu metotlari çalistirabiliriz. Bu trick Java dünyasinda da birkaç asirdir uygulaniyor.

Gazanya - 13.09.2008

Güzel makele olmus da Türkçe meali nedir bu yazinin?

Yorum Yazın


Tüm yorumlar onaydan geçmektedir, bu işlem en uzun 30 dk. sürecektir. E-mail adresleri yeni yorumları bildirme harici hiç bir başka amaçla kullanılmamaktadır ve sitede gözükmemektedir.



Captcha Kodu