C#.NET application to expire in 30 days.

Questions about programming languages and debugging
User avatar
z3r0aCc3Ss
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 700
Joined: 23 Jun 2009, 16:00
14
Contact:

Re: C#.NET application to expire in 30 days.

Post by z3r0aCc3Ss »

cats wrote:
z3r0aCc3Ss wrote: No, not error message. Error means, that message box appears...

Ok, as everything is happening in form_load event, I put the breakpoints on those four methods. It comes to check_usage() method and gives error and then it still proceeds with rest part execution (which should not happen).
Oh alright :)

Application.Exit doesn't force the application to close.

Code: Select all

http://msdn.microsoft.com/en-us/library/system.windows.forms.application.exit%28v=vs.71%29.aspx
Try this instead

Code: Select all

http://msdn.microsoft.com/en-us/library/system.environment.exit.aspx
ok, yeah. This is also good. I didn't know this...
It forces the application to exit. Hmm... that also can be implemented.
Beta tester for major RATs, all kinds of stealers and keyloggers.
Learning NMAP

User avatar
z3r0aCc3Ss
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 700
Joined: 23 Jun 2009, 16:00
14
Contact:

Re: C#.NET application to expire in 30 days.

Post by z3r0aCc3Ss »

cats wrote: EDIT: If you are getting the desired output then you can go with that, but be aware that the application will most likely still go all the way to the end and exit there, instead of exiting at Application.Exit (in case you want to add more code later).
Yeup, kept that in mind.
But instead of using environment.exit, I made some modifications (which I stated in my previous post) and now, its working fine.
Now, the 30 day time-limit part... huh!!! Will work tomorrow now...
Still, one more thing is remaining. When it is setting the value in the registry, I want it to be encrypted. [-o<

EDIT:
Which function should I use for this? MD5 can't be used, as it's a one-way function.
Which are good algorithms that can be implemented for such kind of encryption/decryption?
Beta tester for major RATs, all kinds of stealers and keyloggers.
Learning NMAP

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: C#.NET application to expire in 30 days.

Post by ayu »

z3r0aCc3Ss wrote: Which function should I use for this? MD5 can't be used, as it's a one-way function.
Which are good algorithms that can be implemented for such kind of encryption/decryption?
AES should suit your needs

Code: Select all

http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
Long AES .Net tutorial

Code: Select all

http://msdn.microsoft.com/en-us/magazine/cc164055.aspx
Shorter example

Code: Select all

http://stackoverflow.com/questions/202011/encrypt-decrypt-string-in-net
I don't have any code that encrypts using AES in C#.Net, so can't give you any examples of my own at this moment.
"The best place to hide a tree, is in a forest"

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Re: C#.NET application to expire in 30 days.

Post by bubzuru »

ok if you want to do this its no to hard
i added comments so you could see how its done

Code: Select all

        public static bool PastExpDate()
        {
            try
            {
                DateTime Today = DateTime.Today; // Todays DateTime Object
                // Ok lets open the key where we store our exp date
                RegistryKey key = Registry.CurrentUser.CreateSubKey("datelock");
                // Load the exp date into a string 
                string expdate = (string)key.GetValue("Date");
                if (expdate != null)
                {
                    // Exp date is not null
                    // Convert our exp date string into a DateTime Object
                    DateTime ExpDate = DateTime.Parse(expdate);
                    // Check if the exp date is less than todays date
                    // if so our trial mode is over
                    if (ExpDate < Today) return true;
                }
                // Exp date key was null (first run ?)
                // lets set the exp date to 30 days from now
                key.SetValue("Date", DateTime.Today.AddDays(30).ToString());
                key.Close();
                return false;
            }
            catch { return false; } // Maybe someone fucked with the registry key ?
                                    // this should only fire if DateTime.Parse() fails
        }

Code: Select all

        static void Main(string[] args)
        {
            if (PastExpDate())
            {
                Console.WriteLine("Your Trial Is Up, Goodbye.");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("Welcome To My Super Software(trial)");
            Console.ReadKey();         
        }
the exp date is wrote in plain text encrypt it
[img]http://www.slackware.com/~msimons/slackware/grfx/shared/greymtlSW.jpg[/img]

User avatar
z3r0aCc3Ss
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 700
Joined: 23 Jun 2009, 16:00
14
Contact:

Re: C#.NET application to expire in 30 days.

Post by z3r0aCc3Ss »

Thanks a lot bubzuru. It worked perfectly fine.
I have made some changes though. Here it is:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Windows.Forms;
using System.Security.Cryptography;

namespace CheckTotalAppCount
{
    class trial_period
    {
        RegistryKey date;
        string expiry_date;

        DateTime dt = DateTime.Today;

        public void createRegVal()
        {
            date = Registry.CurrentUser.OpenSubKey("Pranav");

            if (date != null)
            {
            }
            else
            {
                date = Registry.CurrentUser.CreateSubKey("Pranav");
                date.SetValue("date", DateTime.Today.AddDays(2).ToString());
                date.Close();
            }

            expiry_date = (string)date.GetValue("date");
        }

        public void check()
        {
            if(expiry_date != null)
            {
                DateTime expdate = DateTime.Parse(expiry_date);
                if(expdate > dt)
                {
                    MessageBox.Show("Bingo!");
                }
                else
                {
                    MessageBox.Show("Trial period has expired.");
                    Environment.Exit(0);
                }
            }
            else
            {
                Environment.Exit(0);
            }
        }
    }
}
Is there any drawback of such code? (Besides encryption)
Beta tester for major RATs, all kinds of stealers and keyloggers.
Learning NMAP

User avatar
z3r0aCc3Ss
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 700
Joined: 23 Jun 2009, 16:00
14
Contact:

Re: C#.NET application to expire in 30 days.

Post by z3r0aCc3Ss »

Well, that code worked perfectly, but the only error I am getting is this:

Code: Select all

Cannot access a closed registry key.
Object name: 'HKEY_CURRENT_USER\z3r0'.
Why it is triggering this? It didn't appear when I did for counting the total number of runs for the applications.
Beta tester for major RATs, all kinds of stealers and keyloggers.
Learning NMAP

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Re: C#.NET application to expire in 30 days.

Post by bubzuru »

z3r0aCc3Ss wrote:Well, that code worked perfectly, but the only error I am getting is this:

Code: Select all

Cannot access a closed registry key.
Object name: 'HKEY_CURRENT_USER\z3r0'.
Why it is triggering this? It didn't appear when I did for counting the total number of runs for the applications.

you are trying to access a closed key. most likely 'date' (date.Close();)
will take a look at your code, explain the drawbacks when i get home
[img]http://www.slackware.com/~msimons/slackware/grfx/shared/greymtlSW.jpg[/img]

User avatar
z3r0aCc3Ss
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 700
Joined: 23 Jun 2009, 16:00
14
Contact:

Re: C#.NET application to expire in 30 days.

Post by z3r0aCc3Ss »

Also, how to create a subkey inside a subkey?
Like this:
Image

EDIT:
Done.
Beta tester for major RATs, all kinds of stealers and keyloggers.
Learning NMAP

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Re: C#.NET application to expire in 30 days.

Post by bubzuru »

iv made a bare bones class for you here:
http://code.suck-o.com/42444" onclick="window.open(this.href);return false;

i use xor encryption because no matter how strong the encryption is the
user can just delete the key anyway so hide it well. also the user could change the clock.

time for example code

Code: Select all

using Bubzuru;

Code: Select all

        static void Main(string[] args)
        {
            Bubzuru.TrialManager TrialMan = new Bubzuru.TrialManager();

            // Lets hide the key's away. make sure you hide them well
            // because this is our main week spot (apart from the clock)
            TrialMan.StoreName = "Software\\Microsoft\\TestApp";

            TrialMan.CryptKey = "PASSWORD"; // set encryption key
            TrialMan.RunLimit = 50; //50 runs 
            TrialMan.TimeLimit = 10; //10 days
            TrialMan.Init(); // Start up The Manager

            // Lets make sure we havent past run\time limit
            if (TrialMan.HasPastRunLimit() || TrialMan.HasPastExpDate())
            {
                // Has Past Run Limit ?
                if (TrialMan.HasPastRunLimit())
                {
                    Console.WriteLine(string.Format("You have run this app {0} times. the limit is {1}", TrialMan.TimesRun, TrialMan.RunLimit));
                    Console.WriteLine("Your Trial Is Up ... Goodbye !");
                    Console.ReadKey();
                }
                // Has Past Date Limit ?
                if (TrialMan.HasPastExpDate())
                {
                    Console.WriteLine(string.Format("You have had this app for more than {0} days", TrialMan.TimeLimit));
                    Console.WriteLine("Your Trial Is Up ... Goodbye !");
                    Console.ReadKey();
                }
                TrialMan.KillProgram(); // Bye
            }

            // Were fine lets run our code 
            Console.WriteLine("Welcome to my cool app trial, you have "+(TrialMan.RunLimit - TrialMan.TimesRun)+" Runs left");
            // Super cool code goes here
            Console.ReadKey();         
        }
im using all options\settings in the example code just to show you.
this would work just fine

Code: Select all

    static void Main(string[] args)
        {
            Bubzuru.TrialManager TrialMan = new Bubzuru.TrialManager();        
             if (TrialMan.HasPastExpDate()) TrialMan.KillProgram();
            Console.WriteLine("Welcome to my cool app trial");
            Console.ReadKey();         
        }
[img]http://www.slackware.com/~msimons/slackware/grfx/shared/greymtlSW.jpg[/img]

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Re: C#.NET application to expire in 30 days.

Post by bubzuru »

in HasPastExpDate()

Code: Select all

 catch { return false; }
should be

Code: Select all

 catch { return true; }
also there is a problem with Init()

Code: Select all

Convert.ToInt32(Crypt((string)key.GetValue("RunTimes"), CryptKey));
dirty solution

Code: Select all

        public void Init()
        {
            int runtimes = 0;
            RegistryKey key = Registry.CurrentUser.CreateSubKey(StoreName);
            try
            {
                runtimes = Convert.ToInt32(Crypt((string)key.GetValue("RunTimes"), CryptKey));
            }
            catch {  }
            // ^^ has the key been fucked with ? does it exist ?
            if (runtimes == 0) key.SetValue("RunTimes", "0");
            TimesRun = runtimes;
            key.SetValue("RunTimes", Crypt((runtimes + 1).ToString(),CryptKey));
            key.Close();
        }
[img]http://www.slackware.com/~msimons/slackware/grfx/shared/greymtlSW.jpg[/img]

User avatar
z3r0aCc3Ss
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 700
Joined: 23 Jun 2009, 16:00
14
Contact:

Re: C#.NET application to expire in 30 days.

Post by z3r0aCc3Ss »

Worked like a charm...
But while testing, if you carefully look at the values which change as the application runs (TimesRun and RunLimit), you can easily reverse it back.
For example, when the application runs for d 1st time, it's value is some variable, say "x".
Second time, its value changes and becomes "z". Third time it becomes "/".
I have put the RunLimit as 3. So, when u run it for 4th time, it terminates as it is exceeding the run limit. But, at the same time, it is changing the value in registry also. And if you change the value of RunTimes key in registry to some previous value, like "z", then also application starts as usual, which shudn't happen... :(
Though, we can perform this check by manipulating the user thinking and registry, this is not d correct solution.
Beta tester for major RATs, all kinds of stealers and keyloggers.
Learning NMAP

Post Reply