Target: timeleg’s CrackMe2
URL: http://www.crackmes.de/users/timeleg/crackme2/
Protection: Serial number
Description: Crackme with a serial protection.
Tools: .NET Decompiler.

Load the crackme in your .NET decompiler and lets take a look at what happens when we press the ‘Check’ button.

    private void button1_Click(object sender, EventArgs e)
    {
      if (this.reg.Testuj(this.textBox1.Text))
      {
        this.label2.Visible = false;
        this.button1.Visible = false;
        this.textBox1.Visible = false;
        Label label = this.label3;
        string str = label.Text + this.reg.ZistiMeno();
        label.Text = str;
        this.label3.Visible = true;
      }
      else
      {
        int num = (int) MessageBox.Show("     Wrong password !", "Unregistered", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
      }
      if ((int) this.reg.VratPocetPokusov() == 0)
        this.Close();
      else
        this.reg.Odober();
    }

If the reg.Testuj method returns true we succeed, else it’s an invalid password. Lets check out the reg.Testuj method.

    public bool Testuj(string heslo)
    {
      string strB = Environment.MachineName 
                    + "-" 
                    + DateTime.Now.Year.ToString() 
                    + DateTime.Now.Hour.ToString() 
                    + "-" 
                    + Environment.UserName.ToUpper();
      return string.Compare(heslo, strB, false) == 0;
    }

So all the serial check routine does is generating a string containing of the machine name, the current year, the current hour and the current user name and then compares that to the entered password.

Following is the C# code for a keygen.

using System;
using System.Windows.Forms;

namespace timelegs_CrackMe2
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            var serial = Environment.MachineName 
                        + "-" 
                        + DateTime.Now.Year 
                        + DateTime.Now.Hour 
                        + "-" 
                        + Environment.UserName.ToUpper();
            Clipboard.SetText(serial);
            Console.WriteLine("Serial: " + serial);
            Console.WriteLine("Serial copied to the clipboard.");
            Console.ReadKey();
        }
    }
}