home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / hackersclub / km / library / cracking / qapla-wincrack.txt < prev    next >
Text File  |  1998-03-25  |  13KB  |  288 lines

  1.  
  2.                                          888    ,e,
  3.          e88'888 888,8,  ,"Y88b  e88'888 888 ee  "  888 8e   e88 888
  4.         d888  '8 888 "  "8" 888 d888  '8 888 P  888 888 88b d888 888
  5.         Y888   , 888    ,ee 888 Y888   , 888 b  888 888 888 Y888 888
  6.          "88,e8' 888    "88 888  "88,e8' 888 8b 888 888 888  "88 888
  7.                                                               ,  88P
  8.            Qapla's cracking tutorial, version 0.1 rel 970209  "8",P"
  9.  
  10. Introduction
  11.  
  12.      Welcome to my first attempt to write a Windows 95 cracking tutorial.
  13.  
  14.      This file is not meant as an introduction to either SoftIce, assembler
  15.      or cracking in general. I will assume that you have installed SoftIce
  16.      2.0 or 3.0 and that you are familiar with it. Some assembler and Win32
  17.      API knowledge is also useful. If you are new to cracking, before
  18.      continuing please read some of the files on cracking already available
  19.      on the net, for example ED!SON's excellent tutorial. In his tutorial
  20.      you will find an introduction to SoftIce, how to load exports and much
  21.      more.
  22.  
  23. The program
  24.  
  25.      In this tutorial, I will use a great little program that you probably
  26.      will find on the net by doing a simple search for it. The program is
  27.      called StartClean, and the version I use is 1.2. The program scans the
  28.      Windows 95 Start Menu and removes all shortcuts that don't point to
  29.      anything. This is actually a very handy utility for those with a lot
  30.      of software passing through their harddisks (like me), so this is one
  31.      of the few little utilities I actually use. Another great thing about
  32.      this program is that it is only 31kb, so it doesnt hog massive amounts
  33.      of my harddrive. You *might* find this program attached to this
  34.      tutorial.
  35.      When you start the program it will fire up with a little nag-screen
  36.      asking you to register it if you use it for more than 30 days. Even if
  37.      we will defeat this protection several times in this file, I'm asking
  38.      you that if you start using the program, please register it. The
  39.      author deserves the money he is asking for it.
  40.  
  41. The extremly simplistic approach
  42.  
  43.      In this section I will use a method that works with this program, but
  44.      it wont work with most other programs. I included it here to show you
  45.      that there is no need to make anything more difficult then nessesary.
  46.      (this is a good philosophy of life by the way :)
  47.  
  48.      Fire up the program, and press 'Register...'
  49.      The program will show you a small dialog-box, asking you to enter your
  50.      name and secret code. Now enter your name and any code. I entered
  51.      "Qapla'97" and "115522". Press OK and it will tell you that the code
  52.      was incorrect.
  53.  
  54.      Now comes the interesting part.
  55.      In the explorer press the right mouse button on the file, and select
  56.      Quick-View. A window will pop up with a lot of information about the
  57.      file. The section we are interested in is the 'Import Table'. Scroll
  58.      down until you reach this section.
  59.      You will hopefully see something like this :
  60.  
  61.      Import Table
  62.  
  63.           COMCTL32.dll
  64.           Ordinal  Function Name
  65.  
  66.           KERNEL32.dll
  67.           Ordinal  Function Name
  68.           026c     lstrcmpiA
  69.           00d7     GetFileAttributesA
  70.           026f     lstrcpyA
  71.           0045     DeleteFileA
  72.           0269     lstrcmpA
  73.           01c1     RemoveDirectoryA
  74.           .        .
  75.           .        .
  76.           .        .
  77.  
  78.      This section displays the API's the file uses. By setting a breakpoint
  79.      on any of these you will be able to intercept the program when it uses
  80.      them.
  81.      Here comes the good part. The program somewhere in the code probably
  82.      compares the code you entered with a pregenerated code, previously
  83.      calculated from the name you entered.
  84.      What does the 'lstrcmpA' function do? Lets look in the API-reference
  85.      (the file I use is called Win32.hlp from the Win95-SDK, distributed
  86.      with most real development environments, for example Borlands
  87.      excellent Delphi 2.0)
  88.  
  89.      --- From Win32.hlp ---
  90.  
  91.      The lstrcmp function compares two character strings. The comparison is
  92.      case sensitive.
  93.  
  94.        int lstrcmp(
  95.            LPCTSTR  lpString1,     // address of first string
  96.            LPCTSTR  lpString2      // address of second string
  97.        );
  98.  
  99.        Parameters
  100.  
  101.        lpString1
  102.          Points to the first null-terminated string to be compared.
  103.  
  104.        lpString2
  105.          Points to the second null-terminated string to be compared.
  106.  
  107.        Return Value
  108.  
  109.        If the function succeeds and the string pointed to by lpString1
  110.        is less than the string pointed to by lpString2, the return value
  111.        is negative; if the string pointed to by lpString1 is greater than
  112.        the string pointed to by lpString2, it is positive. If the strings
  113.        are equal, the return value is zero.
  114.  
  115.      ---- End ---
  116.  
  117.      So, lets try setting a breakpoint on 'lstrcmpA'. Press ^D, and when
  118.      the SoftIce screen appears type 'BPX lstrcmpA', now press ^D again and
  119.      press OK once more. Blam, we were kicked back to SoftIce.
  120.      ** Break due to KERNEL32!lstrcmp
  121.  
  122.      Now press F12 to return to the calling function, and you should see
  123.      something like this:
  124.  
  125.                                   .
  126.                                   .
  127.                                   .
  128.      0157:004011DD 50             PUSH EAX     <- push your code on the stack
  129.      0157:004011DE 6830604000     PUSH 406030  <- push the right code on the stack
  130.      0157:004011E3 FF1520924000   CALL [KERNEL32!lstrcmp] <- compare them
  131.      0157:004011E9 85C0           TEST EAX, EAX
  132.      0157:004011EB 0F8580000000   JNZ 00401271  <- check if they were the same
  133.                                   .
  134.                                   .
  135.  
  136.      At this point we have two options:
  137.  
  138.      a) Patch the JNZ to NOP's          This will make the program register
  139.                                         with any code. This *may* introduce
  140.                                         other problems, most noteably it
  141.                                         might have a similar unpatched
  142.                                         check in another part of the
  143.                                         program that you won't notice.
  144.      b) Find out the code it compared   This is a much better way of
  145.      your code with                     working as you dont need to change
  146.                                         the code and the serial you find
  147.                                         will probably work with the next
  148.                                         version of the software as well,
  149.                                         the crack will probably stop
  150.                                         working when you upgrade.
  151.  
  152.      Alternative (a) is left as an exercise to the reader :)
  153.  
  154.      Now type 'd 406030' <- this was the address it pushed on the stack,
  155.      remember?
  156.  
  157.      The data-window will now display the correct code, in my case
  158.      1398-13026-1211-249
  159.  
  160.      As i said in the beginning of this section, setting a breakpoint on
  161.      string-compare API's will seldom work, as most programs use their own
  162.      routine for doing this. The next section will present another, very
  163.      similar approach to the same problem, but it will not rely on the same
  164.      API.
  165.  
  166. The hmemcpy-bpm approach
  167.  
  168.      If you registered the program in the following section and wish to
  169.      'unregister' it, so you can try this approach as well, you can start
  170.      regedit, and delete the following key :
  171.      HKEY_CURRENT_USER\SOFTWARE\Start Clean\Configuration
  172.  
  173.      Do a 'BC *' to clear all your existing breakpoints, and enter your
  174.      name in the registration-box once again. (be sure to use an incorrect
  175.      code, as we dont want to register it right now). Don't press OK yet.
  176.  
  177.      Now enter 'BPX hmemcpy', and press OK in the dialog. We will be back
  178.      in SoftIce. Note that we are no longer in the flat addressing mode.
  179.      This is protected mode 16bit code, ie in another context. We need to
  180.      get back into the flat code before we can search all memory, but
  181.      before we do that we will press ^D once again. The program just
  182.      scanned our name this time, and we are just interested in is setting a
  183.      breakpoint to trap access to the code we entered.
  184.  
  185.      We will shortly be back into softice again. Now press F12 a few times
  186.      until we reach the 32bit code. You will notice this by looking at the
  187.      addresses in the code window...
  188.  
  189.      0137:9EA6      <- this is a segmented 16-bit address.
  190.      0157:004011B5  <- this is a 32-bit flat address.
  191.  
  192.      When you reach this code we can scan for the text we entered in the
  193.      code-window. (you entered something unique didn't you, as we will be
  194.      searching all physical memory, and a code like 0000 will probably be
  195.      found in a lot of unrelated locations) Enter "s 0 l ffffffff
  196.      'your_code_here'" and press enter.
  197.  
  198.      Now two things can happen. either it finds your code in a low address,
  199.      (and this is what we are looking for), or it will find it somewhere
  200.      around 0x80000000 (this is Windows internal memory-space, and not what
  201.      we are looking for (Windows reserves the upper 2gig for internal use,
  202.      and non ring 0 code will only have access to memory in the lower part
  203.      of the address space))
  204.  
  205.      When you found what looks like the right place in memory, (I found it
  206.      at 015f:0063f580), we will set a breakpoint for memory access there.
  207.  
  208.      Use 'BPM 0063f580' (or whatever address you found).
  209.  
  210.      Don't forget to 'BD hmemcpy' as well, as we will not be needing that
  211.      breakpoint any more.
  212.  
  213.      Press ^D and you it will stop right in the function that compares the
  214.      two strings.
  215.  
  216.      This method is usually much better than the previous, as it doesn't
  217.      assume that the program uses any specific API's. It is usually safe to
  218.      set a breakpoint on hmemcpy as almost all Win32-programs rely on this
  219.      function to retrieve information from dialogs.
  220.  
  221. Other ways
  222.  
  223.      So, we have now defeated this program in two similar ways, and at this
  224.      point I am starting to realize my bad choice of program as this little
  225.      program doesn't contain any strange or non-standard things. It is
  226.      rather unusually simplistic. If you feel like making a keymaker, which
  227.      is the thing any *real* cracker would do, you can find the entrypoint
  228.      to the code-generating routine just above the call to lstrcmp.
  229.  
  230. Setting breakpoints
  231.  
  232.      In ED!SON's tutorial, the author talks about the problems of setting
  233.      breakpoints, especially when Norton Commander is active. When you try
  234.      to do a BPX GetDlgItemTextA, you might get the 'No LDT' error. DOS
  235.      windows, and especially Norton Commander hogs much of the CPU and if
  236.      you are running them, there is a good chance you will end up in a VDM
  237.      instead of the PROT32-mode you want to be in. SoftIce 3.0 seems to
  238.      handle this much smarter, so if you are having problems try installing
  239.      the latest version of the debugger. This is an issue of
  240.      address-contexts and an extensive discussion on the topic can be found
  241.      in the documentation for SoftIce 3.0. If you are trying to set a
  242.      breakpoint in the code you are debugging and it doesnt work, try to
  243.      break on a general API, and press F12 until you reach the context you
  244.      are looking for, and then set the breakpoint.
  245.  
  246. Recommended reading
  247.  
  248.      The reason I wrote this tutorial is that during the last years, I have
  249.      read quite a few text on cracking by different authors. I always
  250.      wanted to make something similar to make a small contribution to this,
  251.      and hopefully make someone reach a higher level of knowledge in
  252.      cracking.
  253.  
  254.      I would like to recommend some of the great text on cracking already
  255.      available on the net :
  256.  
  257.      ED!SON's Cracking Tutorial       This is a great file that contains
  258.                                       an introduction to debugging,
  259.                                       SoftIce and cracking. If you havn't
  260.                                       read it yet, do so now. This file is
  261.                                       *very* recommended for everyone.
  262.      +ORC's Cracking Tutorials        These files are split up in lessons,
  263.                                       each one talking about a different
  264.                                       approach or side of cracking. Most
  265.                                       of the lessons are very much worth
  266.                                       reading, even if I dont agree with
  267.                                       him in the frequent discussions
  268.                                       about languages like Delphi or the
  269.                                       world in general :) They might be a
  270.                                       bit hard to find as he seems to be a
  271.                                       bit reluctant about placing all of
  272.                                       them on the net.
  273.  
  274. Thanks
  275.  
  276.      The author would like to thank the following persons for helping him
  277.      with debugging the text, and verifying the wannabee-cracker-author's
  278.      theory's...
  279.  
  280.      [prizna], odin- and kOUGER - thanks!
  281.  
  282. Contacting me
  283.  
  284.      You dont, but you *might* be able to find me on US-EFnet IRC. Check
  285.      for the nick qapla, it might be me.
  286.  
  287.      thank you for reading this far, I hope you enjoyed it. (c)1997, Qapla'
  288.