martedì 23 aprile 2019

WindowsFormsProtector2, a software to defend the source code in .Net

WindowsFormsProtector2 adds, compared to WindowsFormsProtector, the possibility to read the password to encrypt-decrypt your executable from a pendrive,the password must be written in the first line of the text file created by you for this purpose with the Notepad starting from the top left corner, for this functionality you must click on the "Get password from pendrive" button, the password can be written partly using the "virtual" keyboard and partly using the file in the pendrive, this makes more difficult to appropriate the "overall" password,in the test-release phase after reading the password you can remove the pendrive using the "safe removal".

For the features of the program and how to use it you can read the post https://gianmarcocastagna.blogspot.com/2019/04/protect-source-code-in-net.html ,
the software is under the "New Bsd" license, to download the sources you can go here https://sourceforge.net/projects/windowsformsprotector2/



Protect source code in .net

In this post you will find a procedure to add some protection to your c # source related to windows forms applications, under certain conditions the application renders both decompilers and de-obfuscators useless and protects the non-obfuscated source code.
here the project https://sourceforge.net/projects/winformsprotector/

A possible scenario: we have an executable to be tested by others but we don't want to sell it for the moment, so we can encrypt the executable and go to the test machine with our encrypted exe and the software to decrypt it, enter the password to decrypt it and upload it in memory,

 proceed as follows using the WinFormsProtector software:
  1) after selecting the executable file to be protected (with the "choose executable to encrypt" button) and choosing the password and pressing the "choose path file to encrypt" button to choose the path where to save the file, you can then proceed to creation of the encrypted file by pressing the "encrypt file into path" button, the file created is called "encryptedExe.encrypt"
  2) installation of WinFormsProtector on the test machine on which the above encrypted file will be loaded
  3) entering the password used to encrypt the file
  4) selection of the file to be decrypted by pressing the "choose file to decrypt" button
  5) press the "decrypt file, load in ram and run" button



then we load the file in memory and here we decrypt and execute it, in practice we load the Assembly in this way:

Assembly assembly1 = Assembly.Load(exe);

where exe is the array of bytes that makes up the executable
in this way the file that we intend to protect in clear does not exist on the machine but exists only encrypted or in memory,
in the executable file that it intends to protect (the called exe) is necessary to modify the main in this way:
in practice add a Start () method that calls the first Form of your application

namespace Ethical_Hacking
{
    static class Program
   {
     [STAThread]
     static void Main()
    {
       Application.EnableVisualStyles();
       Application.SetCompatibleTextRenderingDefault(false);
     Start();
    }

   public static void Start()
  {
   Form1 f = new Form1();
   f.ShowDialog();
   }

 }
}

in the calling exe we will have:

Assembly assembly1 = Assembly.Load(exe);
var programType1 = assembly1.GetTypes().FirstOrDefault(c => c.Name == "Program");
MethodInfo method1 = programType1.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
method1.Invoke(null, new object[] { });

that is, the Start () method is invoked.

If the exe file to be protected uses packages you must add these packages in the calling project (executable), for example if we use NewtonSoft.json in the program to be protected also the calling program must have NewtonSoft.Json in its packages.

In the source code you will find two zipped projects: WindowsFormsProtector and Ethical_Hacking, the first is the calling exe the second is the called exe (or the protected one), here the code and the installer: https://sourceforge.net/projects/ winformsprotector /

sabato 23 marzo 2019

WindowsFormsProtector2 , un software per difendere il codice sorgente in .Net

WindowsFormsProtector2 aggiunge , rispetto a WindowsFormsProtector ,la possibilità di leggere anche da una pendrive la password per crittografare-decrittografare il vostro eseguibile , la password va scritta nella prima linea del file di testo da voi creato allo scopo  con BloccoNote partendo dall'angolo in alto a sinistra,per questa funzionalità dovete cliccare sul bottone "Get password from pendrive"  ,la password può essere scritta in parte usando la tastiera "virtuale" ed in parte sul file nella pendrive ,questo rende più difficile appropriarsi della password "complessiva" , in fase di test-rilascio dopo aver letto la password potete rimuovere la chiavetta utilizzando la "rimozione sicura"


Per le caratteristiche del programma e come usarlo potete leggere il post https://gianmarcocastagna.blogspot.com/2018/03/proteggere-il-codice-sorgente-in-net.html
il software è sotto la licenza "New Bsd" ,per scaricare i sorgenti  potete andare qua https://sourceforge.net/projects/windowsformsprotector2/



domenica 10 febbraio 2019

Proteggere il codice sorgente in .net

In questo post trovate illustrata una procedura per aggiungere un po' di protezione ai vostri sorgenti c# relativi ad applicazioni windows forms, in certe condizioni l'applicazione rende inutili sia decompilatori che deoffuscatori e protegge il codice sorgente anche non offuscato,
qui il progetto https://sourceforge.net/projects/winformsprotector/






Uno scenario possibile : abbiamo un eseguibile da far testare da altri ma non vogliamo cederlo per il momento, possiamo quindi crittografare l' eseguibile ed andare sulla macchina di prova con il nostro exe crittografato ed il software per decrittografarlo ovvero inserire la password per decrittografarlo e caricarlo in memoria .

 Si può procedere nel modo seguente mediante il software  WinFormsProtector :
 1) dopo aver selezionato il file eseguibile da proteggere (con il bottone "choose executable to encrypt") e scelta la password e premuto il bottone "choose path file to encrypt" per scegliere il percorso dove salvare il file, si può quindi procedere alla creazione del file crittografato premendo il bottone "encrypt file into path" ,il file creato si chiama "encryptedExe.encrypt"
 2) installazione di WinFormsProtector sulla macchina di test sul quale verrà caricato il file crittografato di cui sopra
 3) inserimento della password utilizzata per crittografare il file
 4) selezione del file da decrittografare premendo il bottone "choose file to decrypt"
 5) premere il pulsante  "decrypt file,load in ram and run"

quindi carichiamo il file in memoria e qui lo decrittografiamo e lo eseguiamo,in pratica carichiamo l'Assembly in questo modo :

Assembly assembly1 = Assembly.Load(exe);
dove exe è l'array di bytes che compone l'eseguibile
in questo modo sulla macchina non esiste il file che intendiamo proteggere in chiaro ma esiste solo crittografato oppure in memoria ,

nel file eseguibile che s' intende proteggere(l'exe chiamato) bisogna modificare il main in questo modo:
in pratica aggiungete un metodo Start() che chiama il primo Form della vostra applicazione

namespace Ethical_Hacking
{
    static class Program
   {
     [STAThread]
     static void Main()
    {
       Application.EnableVisualStyles();
       Application.SetCompatibleTextRenderingDefault(false);
     Start();
    }

//il metodo seguente permette di superare gli eventuali problemi con il metodo SetCompatibleTextRenderingDefault
   public static void Start()
  {
   Form1 f = new Form1();
   f.ShowDialog();
   }

 }
}

nell'exe chiamante avremo quindi :
Assembly assembly1 = Assembly.Load(exe);
var programType1 = assembly1.GetTypes().FirstOrDefault(c => c.Name == "Program");
MethodInfo method1 = programType1.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
method1.Invoke(null, new object[] { });

ovvero viene invocato il metodo Start() .

Se il file exe da proteggere usa dei riferimenti bisogna aggiungere questi riferimenti nel progetto (eseguibile) chiamante , ad esempio ,se usiamo NewtonSoft.json nel programma da proteggere anche il programma chiamante deve avere NewtonSoft.json nei suoi riferimenti

Nel codice sorgente troverete due progetti zippati :WindowsFormsProtector e Ethical_Hacking ,l primo è l'exe chiamante il secondo è l'exe chiamato (ovvero quello protetto) , qui il codice  https://sourceforge.net/projects/winformsprotector/

Qui altri programmi con lo stesso scopo

Crittografia e WCF per passare una password ( od una qualsiasi altra stringa (xml,json, etc.etc.) ) da un applicazione ad un' altra in relativa sicurezza

 Il codice che segue è da considerarsi in alpha e da non utilizzare in un ambiente di produzione , qui potete trovare il  "progetto&quo...