Click here to Skip to main content
14,334,974 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

Disclaimer

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.

Image 1

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".

Image 2

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.

Image 3

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

Image 4

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

Image 5

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

Image 6

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

Image 7

8. Now follow the specifications as below.

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

9. You should have something like this:

Image 8

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

Image 9

11. Now add this code into the event:

Image 10

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

Image 11

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.

Image 12

It fulfills (iii).

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

Image 13

It fulfills (ii).

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

Image 14

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 /out=CrackingIL.il

Image 15

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

Image 16

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

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

Image 17

25. Scroll down until you get this.

Image 18

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.

Image 19

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

Image 20

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

Image 21

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

Conclusion

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.

References

License

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

Share

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 
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 
Hi punkrock,

Thanks again for all this information.

For the "Building Security Awareness in .Net Assemblies" series of articles are created to build some awareness to the public about protection of commercial source code (which includes the pitfalls - possibilities of cracking and also solutions for it).

Yeah, I heard of CAS. I am working an article on it. Again, give me some time Poke tongue | ;-P

Lastlt, thanks for all this. I believe i can improve my writing article skills in coming future.

Cheers.

Regards,
Chua Wen Ching
Visit us at http://www.necoders.com

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.

Article
Posted 31 Oct 2004

Stats

164.1K views
2.3K downloads
121 bookmarked