Click here to Skip to main content
14,238,591 members

Building Security Awareness in .NET Assemblies : Part 1 - Learn to break a .NET Assembly

Rate this:
4.53 (54 votes)
Please Sign up or sign in to vote.
4.53 (54 votes)
31 Oct 2004
Building Security Awareness in .NET Assemblies : Part 1 of 3


NeCoders shall not be held responsible for any cases of software/files being hacked due to the information provided in this article.

General Overview

I always believe Security is the number 1 priority in building a good software. I have been trying to make sure that security issues are considered during my design stage. But the problems with current students in tertiary education is that I can say most of them never actually consider security as a real issue. They tend to focus more on the system's features and GUI. Lecturers also hardly pay attention or encourage students to place higher security measures into their projects, which I think is something not appropriate at all.

Why should we be aware of security?

1st Scenario :

In my current smart card company, most of the information stored within our SDK are highly confidential. We do not want our SDK to be manipulated by our competitors.

2nd Scenario :

You took a year to write a software and in the process consumed a lot of resources and time for its development. Then you sell your software, you find that all your hard work in past 12 months were easily manipulated. Therefore, steps must be taken to ensure this does not happen.

3rd Scenario :

One day, my manager came to me and asked me this question.

Questions: Are .NET assemblies that secure?

Answer: Nothing is secure, but all we can do is to try to make things harder for a hacker.

Then he gave me this reply; I thought .NET is supposed to be more secure. That is why we move into Microsoft .NET. He was total upset when I showed him the .NET Reflector program by Lutz Roeder which you can decompile your binaries back to C# source code. Below is an example of how it looks like.

The Demonstration

4th Scenario :

Back in 1990s, you may have noticed that some shareware programs implements this kind of verification technique. When you install the software, it will create a key in the Windows registry. Basically what it does, is stores the serial number inside the registry as either a plain text or encrypted version. Yes, I have seen people placing plain text in registry. So when your program runs, it will check the registry to verify the existence that particular key. If you have a wrong serial number or that particular key is not there, it will prompt you an error. Right now I will try to simulate this verification technique in C# step by step.

Test machine specifications

  • Windows XP Professional Edition SP 1

  • Intel Pentium 4 2.6GHz

  • 256MB DDR-RAM

  • Visual Studio .NET 2003 Professional Edition

  • Microsoft .NET Framework 1.1

Steps to do

1. Go to Windows XP's start menu and select 'Run...'. Type "regedit" or "regedt32".

2. Navigate to \HKEY_LOCAL_MACHINE\Software, then right click and choose New > Key

3. Name the Key to NeCoders. When you are done, right click the NeCoders key, and choose New > String value. Name it to serial.

4. Double-click on the serial string and enter "1111-1111-1111-1111" as the value.

5. Okay, now launch your Visual Studio .NET 2003.

6. Create a new C# window application project and name it CrackingIL.

7. The C# window application designer will be loaded as below.

8. Now follow the specifications as below.

FormFrmSecureAppSecure App 1.0Arial, Size 10, Bold
labellblheaderWelcome to NeCoders-

9. You should have something like this:

10. Now double-click on the FrmSecureApp form. The FrmSecureApp load event will be generated.

11. Now add this code into the event:

12. Once done, build the project by pressing F5.

13. Nothing unusual. It is just a windowed form so what is so special about it?

14. When the program runs, it will check the registry for these conditions:

  1. Check the existence of HKEY_LOCAL_MACHINE\SOFTWARE\Necoders

  2. Check the existence of HKEY_LOCAL_MACHINE\SOFTWARE\Necoders\serial

  3. Checks whether the serial string value equivalent with “1111-1111-1111-1111”

15. Now open up your registry edit, and change the string value of serial to “1111-1111-1111-1112”. Now press F5 again in Visual Studio .NET 2003 to debug the software.

It fulfills (iii).

16. Next, try to delete the serial string value from NeCoders key. Press F5 again.

It fulfills (ii).

17. Finally, delete the NeCoders key. Press F5.

It fulfills (i).

18. Now I am thinking hard how to break this licensing technique. This is the fun part and hope you will like it. Right now, no matter how you run your C# windows form, it will prompt you the same error “Please acquire a license to run this!”. Please bear this in mind.

Note: There is no difference in breaking a Debug or Release mode assemblies.

19. Go to Windows Start > Programs > Microsoft Visual Studio .NET 2003 > Visual Studio .NET Tools > Visual Studio .NET 2003 Command Prompt.

20. Change to the directory where your CrackingIL.exe is resided.

21. Type ildasm CrackingIL.exe /

22. If you notice, there will be 3 files added to your debug folder.

23. Open with any text editor. I used notepad.

24. You will see some assembly codes. This is in intermediate language. Cool huh?

25. Scroll down until you get this.

The highlighted is actually your FrmSecureApp_Load event which you created earlier on in Visual Studio .NET 2003. 26.

Okay, now what we want to do is to remove the portion of code that calls the registry checking. Just remove all the codes from IL_0000 to IL_0075. You will end up with this.

27. Reopen your Visual Studio .NET 2003 command prompt and type 'ilasm'.

28. Once done, try to run CrackingIL.exe.

You should see this. If you do, congratulations for you have successfully cracked CrackingIL.exe.


I hope you like this article even though it is a simple one. See Part 2 for the next one in this series. If you still have any doubts, just email me.



This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Chua Wen Ching
Software Developer
Malaysia Malaysia
I am Chua Wen Ching and it is great to be part of CodeProject network Smile | :)

Comments and Discussions

QuestionHow do I protect my source code without an obfuscator? Pin
w2tj16-Aug-08 23:01
memberw2tj16-Aug-08 23:01 
AnswerRe: How do I protect my source code without an obfuscator? Pin
eduardna26-Mar-12 22:10
membereduardna26-Mar-12 22:10 
QuestionWhy not concentrate on productive things? Pin
DEGT9-Jul-08 22:54
memberDEGT9-Jul-08 22:54 
GeneralExcellent! Thanks! Pin
Larissa Fedora Hapsari Putri6-Sep-06 20:44
memberLarissa Fedora Hapsari Putri6-Sep-06 20:44 
QuestionHow to protect my C# source code? Pin
lpbinh10-Jul-05 16:59
memberlpbinh10-Jul-05 16:59 
I had read your paper.
I want to protect my C# source code by using Strong Name key.

by using turn on delay signing and point them to the public key file in assembly file.

Example i build a mylib.dll which have two function:
int plus(int a, int b) and int minus(int a, int b).
and i turn on delay signing such as.
[assembly: AssemblyDelaySign(true)]
and then i point to them to the public key file which have name
[assembly: AssemblyKeyFile("c:\\")]

And then i build an application that using mylib.dll.
But i don't know how to using mylib.dll in my application.
I mean how to declare in my application to call the two function (plus and minus).

In normal if i don't using Strong Name key ( i mean my dll it's can be using by any one).
I can declare such as in my application such as:

using mylib

and then i can call plus and minus function now.

But when i using Strong Name key, i don't know how to declare in my application to using it. And other one can't using it.

Could some one help me.

Generalmanipulated Pin
Radeldudel10-Nov-04 22:45
memberRadeldudel10-Nov-04 22:45 
GeneralA Common Gripe... Pin
punkrock9-Nov-04 14:01
memberpunkrock9-Nov-04 14:01 
GeneralRe: A Common Gripe... Pin
Chua Wen Ching9-Nov-04 14:42
memberChua Wen Ching9-Nov-04 14:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 31 Oct 2004


121 bookmarked