Click here to Skip to main content
Click here to Skip to main content

Building Security Awareness in .NET Assemblies : Part 3 - Learn to break Strong Name .NET Assemblies

By , 31 Oct 2004
 

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

Welcome back to part 3 of the Building Security Awareness in .Net Assemblies series. In this article, I will share with you the possibility of breaking Strong Named .Net Assemblies. Make sure you have already read through part 1 and 2 before continuing on.

Questions pertaining to Strong Name

I do believe many others have the same doubts as I do on whether Strong Name keys could really protect the assembly from being tampered. I would like to share my doubts with you in this article.

Questions:

  1. Question : Is Strong Name key secure?
    • Answer : Yes, Strong Name key uses RSA 1024 bit encryption.
  2. Question : Is Strong Name key breakable?
    • Answer : If you have enough computing power, time and knowledge on how to break RSA, the answer is yes.
  3. Question : Can Strong Name key be removed from .NET assemblies?
    • Answer : Yes, it can be removed very easily if you know how.

The Demonstration Test machine specifications :

  • Windows XP Professional Edition SP 1 1

  • Intel Pentium 4 2.6GHz

  • 256MB DDR-RAM

  • Visual Studio .Net 2003 Professional Edition

  • Microsoft .Net Framework 1.1
  1. Download the executable files that come with this article.
  2. Open your Visual Studio .Net 2003 command prompt.
  3. Make sure you are inside the CrackingIL/bin/debug directory.
  4. Type “ildasm CrackingIL.exe /out=CrackingIL.il”.

  1. You must be wondering, why we are repeating what we had done in part 1 and part 2 of the series. If you notice, the way to break Strong Name keys is by manipulating the Intermediate Language. But the problem is in part 2, we did modify the Intermediate Language and at the end when we tried to convert it back to an assembly, we will receive an error. I will explain in detail on which part of the Intermediate Language that you should modified to remove the Strong Name key.
  2. Open up the CrackingIL.il with a text editor. I use notepad.

  1. Take a look at the red boxes. From what I understand, each assemblies like System.Windows.Forms, System and mscorlib contains their own public key token and version number.
  2. Now, does our assembly contain a public key? The answer is yes. Before showing it to you, I will first show you 2 screenshots; one without Strong Name key and one with Strong Name key attached.

Without Strong Name :

With Strong Name :

  1. You will notice that the difference on both sides is that the Strong Name key assembly contains a public key. In order to tamper a Strong Named .Net Assembly, just remove that highlighted section. It will look like this.

  1. Now do some modifications to the existing Intermediate Language. You have to remove the registry checking so it will not prompt you for serial number or license. Look for this code.

  1. Then remove the lines of code from IL_0000 to IL_0075. You should have an output like this.

  1. Now just edit some text to prove that you have hijacked that Strong Named key .Net Assembly. Find the code with the phrase “Welcome to NeCoders” and replace it to “You are being hijacked, Strong Names are useless here”.

Change above to:

  1. Open your Visual Studio .Net 2003 command prompt, and type “ilasm CrackingIL.il”.

  1. Try to run CrackingIL.exe. You will see this.

  1. Congratulations! You had managed to manipulate .Net assemblies with Strong Name key attached to it.

Conclusion

Again, I hope you find this series of the article to be interesting. There will be more articles under this series, in terms of breaking and securing the .Net assemblies. Do check out article 4 when it is available as it will explaining the many theories in .NET security. This in return should provide you with a better understanding in this topic.

References

None

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

About the Author

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionCareful Heremembereduardna26 Mar '12 - 22:15 
Strong names is for assigning an assembly identity to prevent name collision and provide CAS policy. Authenticode signatures would protect the file integrity and provide publisher identity and certificate revocation. Removing a strong name signature is not proving anything except that it can be done. In the ECMA spec there is details on a cleaner way to do this without even decompiling. If the assembly is part of a bigger product and that product is cryptographically tied to an Authenticode signature, all bets are off.
GeneralMy vote of 1memberJanV800017 Nov '09 - 1:40 
Author didn't succeed in altering an assembly without removing/changing the signage
RantSuperbmemberSyntaxCheck10 May '08 - 0:47 
these 3 part articles are superb.
thanks alot. Rose | [Rose]
Questionis there other parts than 1,2&3?memberZHM12 Feb '08 - 16:31 
Hello Chua,
 
thanks for this work, i really enjoyed reading your articles
but i wonder if you posted any other parts concerning this topic ?
 
Best regards
GeneralRe: is there other parts than 1,2&3?memberchuawenching4 Mar '08 - 16:19 
Dear ZHM,
 
Thanks Smile | :) I am really surprised that people are still reading my articles even it was 3 years old ++
 
Honestly, I had stopped writing articles after part 3 due to some unforeseen circumstances. I had a different focus right now in software development. When time is right, I will continue this series at later future.
 

Best Regards,
Chua Wen Ching Smile | :)

GeneralRe: is there other parts than 1,2&3?memberZHM5 Mar '08 - 11:48 
Thanks for the reply & looking forward to read any articles you're going to post in the future Smile | :)
QuestionBreak without removing?memberAriston Darmayuda4 Jul '07 - 6:53 
It's not good theory because this theory only useful on single or not more than 2 or 3 assemblies. When we face more than 3 assemblies then we have a lots to do. We must change the entire assemblies collection if we want to assign new strong name.
 
I figure out how to change some public key, and public key token using hex tools. Its easier to find and replace the public key (its only a string and hex value). But the problem is if the assembly have been sign then in that assembly also include hash for that assembly (like embedded CRC). So if we modify the assembly then when the assembly executed it will fail because invalid hash.
 
Is there any ways to avoid this up. I want to make sure that .NET assembly really secure, because first I think if I write .NET assembly it will be secured.
Questionwhat would you suggest to do when you have a strong name assembly that need to call a non strong named assembly?membervvatclor28 Aug '06 - 11:29 
Hi Chua, just want to know your thoughts on the best way to do when you have a strong named assembly that need to call a non strong named assembly.
 
Thanks!
GeneralWaiting for part 4 of this series.memberhorngsh1687 Jun '06 - 19:17 
Will it be out soon?
 
Thanks a lot.
 
======================
horngsh
======================

QuestionHow can I assign Strong Name to DLL [modified]memberNimit Patel22 May '06 - 3:13 
Hi,
 
I have try you guide line for assinging strong name to dll that strong named dll used to assign full trust. I will perform following step for that,
 
ildasm myFile.dll /output:myFile.il /* for deassembling the dll */
/* after deassembling I will add public key code which is copied from a stong named dll.
*/
 
ilasm /dll /output:myFile.dll /* used for reassembled the dll */
 
sn - vf myFile.dll /* used for veryfing strong name of dll */
/*
when I used reassembled dll for veryfing the strong name it was display :
 
myFile.dll is a delay-signed or test-signed assembly
*/
 
caspol -af myFile.dll /* used for assign fulltrust to dll */
/*
when I used above command it was diplay error message assebly couldn't load.
*/
 
so please guide me how to assign the full trust using strong name to dll
 
with reagrds,
 

 

 
Nimit Patel
 
-- modified at 9:14 Monday 22nd May, 2006
Generalwaiting 4 part 4membershystars8 Dec '05 - 19:35 
When will part 4 be posted here?
GeneralOffline threadmemberShaun Wilde25 Nov '04 - 20:56 
An interesting thread on this article has sprung up here
 
http://www.mcse.ms/message1213043.html[^]
 

GeneralRe: Offline threadmemberchuawenching25 Nov '04 - 21:29 
Thanks for the link. Yeah, I have looked into it. No worries, the later article by me or a friend of mine will help clarify things.
 
Working on article 4 now, i believe it will an interesting article... hehe Poke tongue | ;-P
 
Cheers.
 
Regards,
Chua Wen Ching
Visit us at http://www.necoders.com
QuestionPossible to change the public key?memberKing Pang12 Nov '04 - 21:59 
Your articles are very enjoyable and I look forward to reading more. One question comes into my mind is, since you can remove the public key of the assembly, do you think you can replace that public key with another public key?
 
Thanks and great work.
QuestionSecure or not?memberuTILLIty10 Nov '04 - 21:15 
Hmmm,
 
at first my reaction was - ok. SN is not to be meant for..., but then what if someone changed both, the dll, AND the exe which used it and removed the SN references from both. Then the exe would gladly use the unsigned assebmly/dll. Which still might mean, that (provided the admins do their work) at system-level/by policy, then unsigned assemblies will now not have as many OS-rights as they did have.
 
regards, Tilli
AnswerRe: Secure or not?memberhakervytas29 Nov '05 - 4:41 
Great done!!!
 
I don't find anythink better like use dotfuscator, but dotfuscator not realy protect application or assembly, so the one way is maybe possible do more secure to hide inside assembly or application code, the way is use small like VSTA engine inside and encript needed parts of code with unmanaged C++ Smile | :)

GeneralGreat ArticlememberAdam Goossens10 Nov '04 - 20:30 
Excellent series of articles - short and to the point. I like it Smile | :)
 
This space for rent!
GeneralRe: Great ArticlememberMashayekh3 Apr '05 - 23:21 
Yes, They are very nice and useful.
Of cource I knew some parts.
Rose | [Rose]
GeneralExcellent, I am eagerly awaiting future partsmemberJohn Cardinal10 Nov '04 - 6:12 
I was, prior to this, pretty confident that we could use a non-obscure licensing scheme safe in the knowledge that our interdependant assemblies could not be compromised easily, however this seems to be completely untrue in light of what you published here.
 
There is obfuscation of course, but it must be turned off for the bits that use reflection and our business apps rely heavily on reflection in the business object framework we are using so it's looking increasingly like were going to have trouble with the licensing however we go about it.
 
Hopefully you have some tricks up your sleeve?
 
Thanks again for the informative article, there is too little on this subject out there.
GeneralRe: Excellent, I am eagerly awaiting future partsmemberchuawenching10 Nov '04 - 10:03 
Hi John Cardinal,
 
Thanks. Yeah, I am working on the new articles, but have been busy lately. Furthermore, there are 6 days long holiday here.
 
Cheers.
 
Regards,
Chua Wen Ching
Visit us at http://www.necoders.com
QuestionWhat strong names domemberpunkrock9 Nov '04 - 13:55 
Strong names are not intended to prevent modification of the code at all. They are intended as a means of verifying that the assembly does indeed come from said source. If you want to modify an assembly and have programs that reference it continue to run, that's easy too, just modify the programs in the same manner as well.
 
What strong names DO prevent is outright spoofing. For instance, if a machine's code access security is set to allow code from company X (say that's your employer's company and this is the internal network) to do anything it wants while all other code is sandboxed, it makes it impossible (unless, as you say, you happen to have obscene amounts of processing power and can break the key) for a hacker (or virus, etc) to change company X's code to do something harmful. As soon as they change the code, they break the strong name and CAS refuses to give the assembly full access to the system.
 
The only way to really hack a strongly named assembly is to have the private key available (or, again, lots of computer power to break the encryption) so that the altered version can be resigned and have the same public key.
AnswerRe: What strong names domemberchuawenching9 Nov '04 - 14:31 
Hi punkrock,
 
Thanks for the clear clarification. I will bear that in mind when i write my coming articles. Hope I can write more clear and better articles in coming future.
 
Cheers.
 
Regards,
Chua Wen Ching
Visit us at http://www.necoders.com
GeneralRe: What strong names dosussSome Pathetic Slob1 Dec '04 - 10:24 
Why not fix this one? It's horribly misleading.
GeneralRe: What strong names domemberchuawenching1 Dec '04 - 12:38 
Hi there,
 
If i have to fix this one, there is no point of this article (as people will not see what are the differences):
 
http://www.codeproject.com/dotnet/StrongNameExplained.asp#xx985079xx
 
It is refering to my article. So i prefer to let it be.
 
Sorry for the inconvenience.
 
Cheers.
 
Regards,
Chua Wen Ching
Visit us at http://www.necoders.com
GeneralRe: What strong names dosussAnonymous5 Jan '05 - 23:36 
I think that you did some great work back there Chua!!! Carry on with it and hope you come up with another article soon.
The simplicity makes for such nice understanding that it is quite amazing.
Also please do keep on writing them like tihs. It is much better to read up on your opinions as they are changing. Too often understanding doesn't come because we do not understand the history behind it.

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 1 Nov 2004
Article Copyright 2004 by Chua Wen Ching
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid