home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Mib / CMESOUR.ZIP / CRUEME.ASM < prev    next >
Encoding:
Assembly Source File  |  1999-02-13  |  13.5 KB  |  516 lines

  1. ;-----------------------------------------------------------------------------------
  2. ; Title:              : CrueMe v1.0
  3. ; Author              : Cruehead
  4. ; Creation date       : 98-06-02
  5. ; Source release date : 99-02-13
  6. ;
  7. ; Description:
  8. ; This is the source code for yet another "CrackMe" program. This one
  9. ; has proven to be fairly hard to beat, and it took approx 8 months before
  10. ; I received five solutions. The most interesting among those solutions is the one I got
  11. ; from "MerCuur". He wrote a generic brute forcer based on mutations and life forms.
  12. ; I included his source code (in C) in this zip archive...It's really interesting.
  13. ;
  14. ; The crackme features some polymorphic code to hide the real
  15. ; encryption and check routine. As soon as the real check has been executed
  16. ; the code will be overwritten with useless code, and a fake
  17. ; encryption/check routine will be executed. Every time the "Check It!"
  18. ; button is pressed the real encryption/check routine is beeing written
  19. ; to the correct place again. Before the real encryption/check routine is executed
  20. ; the string is fetched through the GetText message beeing sent.
  21. ; A breakpoint detection is made on the "GetDlgItemTextA" function as this
  22. ; is the routine that is used to fetch the string and then execute the fake test.
  23. ; All of this just to confuse the cracker into thinking he's on the right path
  24. ; when seeing the "No breakpoint allowed..." message. Also the file called "CRUEME.DAT" has
  25. ; nothing to do what so ever with the real check - it's only used as a red herring.
  26. ; Knowing this one can easily figure out that the "FileMon" detection is also only
  27. ; used as a red herring to distract the user from the real interesting piece of
  28. ; the code.
  29. ; Another thing is that all the functions used in the program are stored in a
  30. ; separate place thus making it a lookup table. This is only to confuse
  31. ; dead-listing crackers (and perhaps to cause some headaches for Sice users as well).
  32. ; Conclusion: Alot of things to draw the cracker's attention to other useless
  33. ; pieces of the code. Also the ability to hide the real psw checking routine so the
  34. ; cracker wont see anything suspicious when browsing through the program using softice.
  35. ;
  36. ; I wont comment much of the code, and it might be a bit hard to follow everything
  37. ; but the program works as I described above and that is - if you ask me - the really
  38. ; interesting thing to know.
  39. ;
  40. ;
  41. ;
  42. ; Oh yeah! Perhaps you'd be interested to know that the password I choosed was
  43. ; "Cracking4U". Alot of other passwords will pass as well though, and I doubht
  44. ; that it's even possible to find the password I had in mind.
  45. ;-----------------------------------------------------------------------------------
  46.  
  47. .386
  48. locals
  49. jumps
  50. .model flat,STDCALL
  51.  
  52. ;----------------------------------------------------------
  53. ;Structure, EQU, Includefiles declaration
  54. ;----------------------------------------------------------
  55.  
  56. include win32.inc           ; some 32-bit constants and structures
  57. L equ <LARGE>
  58.  
  59. IDD_STAT         EQU 1010
  60. IDD_CLOSE         EQU 1004
  61. IDD_GO             EQU 1003
  62. IDD_EDIT1         EQU 1002
  63. IDI_ICON1         EQU 100
  64.  
  65. TRUE             EQU 1
  66. FALSE              EQU 0
  67. NULL             EQU 0
  68.  
  69. ;----------------------------------
  70. ; Our Variables
  71. ;----------------------------------
  72.  
  73. .data
  74.  
  75. szTitleName      db '',0
  76. szClassName      db 'ASMCLASS32',0
  77. lppaint          PAINTSTRUCT <?>
  78. msg              MSGSTRUCT   <?>
  79. wc               WNDCLASS    <?>
  80. tm                 TEXTMETRIC  <?>
  81. RC                 RECT         <?>
  82. Systime             SYSTEMTIME  <?>
  83.  
  84. dlg_start        db 'DLG_START',0
  85. Buffert             db 7,41,25,22,37,6,1,12,35,24,11,8,23,14,5,42,33,38,27,3,21,4,39,10,20,26,19,28,32,40,31,29,34,9,17,36,15,18,13,30,2,16
  86.  
  87. psw                 db 14 dup (0)
  88. fakebuff         db 8 dup (0)
  89. loopindex         db 0ffh
  90.  
  91. FileFakePsw         db 0ffh,077h,088h,066h,099h,055h,0aah,044h,0bbh,033h,0cch,022h,0ddh,011h,0eeh
  92.  
  93. Flagst             dd 0c0h            ; Open with these flags! (RWE)
  94. FileMon             db 05dh,0a5h,0b9h,0e4h,0d4h,080h,019h,0a5h,0b1h,095h,080h,035h,0bdh,0b9h,0a5h,0d1h,0bdh,0c9h,0
  95. ProcID             dd 0
  96. handle             dd 0
  97.  
  98. WhyNot1             dd 015263748h
  99. WhyNot2             dd 0596a7b8ch
  100. NoNeed1             dd 0
  101. NoNeed2             dd 0
  102. length             dd 0
  103.  
  104. Filename         db 'CRUEME.DAT',0
  105. filehandle         dd 0
  106. readbuffer         db 15 dup (0)
  107. somanyread         dd 0
  108.  
  109. NotUsedYet1         dd 0
  110. NotUsedYet2         dd 0
  111.  
  112. FileHeader         db "This is the end - My only friend the end!",0
  113. FileMissing         db 'AAARGH! Where is my CRUEME.DAT file???',13
  114.                  db '    I cant go on without my beloved file!',0
  115.  
  116. tempflag         db 0
  117. statwait         db 'Status: Waiting for input',0
  118. statyes             db 'Correct password - Good work!',0
  119. statno             db 'False password - Try again',0
  120. statyescopy         db 30 dup (0)
  121.  
  122. siceHeader         db 'Breakpoints - just say no!',0
  123. nosice             db "So - You're trying to put a breakpoint on GetDlgItemTextA, eh?",13
  124.                  db "You know - I cant allow you to do that... that would make",13
  125.                  db "things easy for you, so...sorry mate - This has to end right now!",0
  126.  
  127. XorSeed             db 0
  128. chooseofs         dd 0
  129. para1              dd 0
  130. para2              dd 0
  131. return             dd 0
  132.  
  133. oldprot             dd 0
  134. paddress          dd 0400000h
  135. pseudo             dd 0
  136. patchhere         dd 0802448h                        ; / 2 = 0401224h
  137. regsize              dd 4096
  138. byteswritten     dd 0
  139.  
  140. RealRoutine         db 052h,06ah,00eh,06ah,00dh,068h,0eah,003h,000h,000h,0ffh,075h,008h,0b0h,025h
  141.                  db 0ffh,015h,064h,023h,040h,000h,0e8h,035h,009h,000h,000h,050h,0bfh,001h,000h
  142.                  db 000h,000h,0e8h,0fdh,008h,000h,000h
  143.  
  144. FakeRoutine         db 0b1h,096h,055h,08bh,0ech,051h,083h,0ech,03ch,066h,0ffh,075h,008h,0ffh,075h,00ch,098h,0b1h,095h,08bh
  145.                  db 0ech,08bh,075h,00ch,00bh,0f6h,08dh,07dh,0b8h,057h,00bh,0ffh,0c1h,0e0h,004h,003h,0c2h
  146. hInst             dd 0
  147. hMenu             dd 0
  148. hDlg              dd 0
  149.  
  150. ;-----------------------------------
  151. ; Startup
  152. ;-----------------------------------
  153.  
  154. .code
  155.  
  156. ;---------------------------------------------------------
  157. ; This is where control is received from the loader.
  158. ;---------------------------------------------------------
  159.  
  160. start:
  161.         mov        chooseofs,offset choose
  162.  
  163.         push    offset Systime
  164.         call    GetLocalTime
  165.         lea        ebx,[ebx*4]
  166.         shr        patchhere,1
  167.         mov        ax, Systime.wMilliseconds        ;Get Milliseconds in AX
  168.         mov        XorSeed,al                        ;AL = our XorSeed
  169.         call    XorBuffer
  170.  
  171.         add        eax,5
  172.         lea        eax,[eax*4]
  173.         add        eax,5
  174.  
  175.         call    FixShutDown
  176.  
  177.         push    L 0
  178.         push    L 080h
  179.         push     L 3
  180.         push    L 0
  181.         push    L 0
  182.         push    0C0000000h
  183.         push    offset Filename
  184.         mov        al,31
  185.         call    [chooseofs]                        ;CreateFileA = 8
  186.         cmp        eax,-1
  187.         jnz        Goon
  188.  
  189.         push    L MB_ICONEXCLAMATION
  190.         push    offset FileHeader
  191.         push    offset FileMissing
  192.         push    0
  193.         mov        al,26
  194.         call    [chooseofs]                        ;MessageBoxA = 33
  195.  
  196.         push    [msg.msWPARAM]
  197.         mov        al,10
  198.         call    [chooseofs]                        ;ExitProcess = 34
  199.  
  200.         Goon:
  201.         mov        filehandle,eax
  202.         mov     eax,15
  203.         mov     ebx,offset readbuffer
  204.         push     L 0
  205.         push     offset somanyread
  206.         push     eax
  207.         push     ebx
  208.         push     [filehandle]
  209.         mov        al,29
  210.         call    [chooseofs]                        ;ReadFile = 14
  211.  
  212.         push    [filehandle]
  213.         mov        al,42
  214.         call    [chooseofs]                        ;CloseHandle = 7
  215.  
  216.         push    L 0
  217.         mov        al,19
  218.         call    [chooseofs]                          ;GetModuleHandle = 10
  219.         mov        [hInst], eax
  220.  
  221.         push    L 0
  222.         push    offset szClassName
  223.         mov        al,39
  224.         call    [chooseofs]                          ;FindWindow = 22
  225.         or      eax,eax                 
  226.         jz      reg_class                       ;More programs than one?
  227.         ret                                     ;No, only one open at time
  228.  
  229. reg_class:
  230.  
  231.         mov     [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS
  232.         mov     [wc.clsLpfnWndProc], offset WndProc
  233.         mov     [wc.clsCbClsExtra], 0
  234.         mov     [wc.clsCbWndExtra], 0
  235.  
  236.         mov     eax, [hInst]
  237.         mov     [wc.clsHInstance], eax
  238.  
  239.         push    IDI_ICON1
  240.         push    eax
  241.         mov        al,5
  242.         call    [chooseofs]                        ;LoadIcon = 18
  243.         mov     [wc.clsHIcon], eax
  244.  
  245.         push    L IDC_ARROW             
  246.         push    L 0
  247.         mov        al,14
  248.         call    [chooseofs]                        ;LoadCursor = 32
  249.         mov     [wc.clsHCursor], eax
  250.  
  251.         push    L 0                     
  252.         push    offset Main_DlgProc     
  253.         push    L 0
  254.         push    offset dlg_start                ;Startup dlg resource (main resource)
  255.         push    [hInst]
  256.         mov        al,18
  257.         call    [chooseofs]                        ;DialogBoxParamA = 20
  258.         jmp     finish                          ;Back main window
  259.  
  260. msg_loop:
  261.         push    L 0
  262.         push    L 0
  263.         push    L 0
  264.         push    offset msg
  265.         mov        al,36
  266.         call    [chooseofs]                        ;GetMessage = 1
  267.         call    choose
  268.  
  269.         cmp     ax, 0
  270.         je      end_loop
  271.  
  272.         push    offset msg
  273.         mov        al,9
  274.         call    [chooseofs]                        ;TranslateMessage = 9
  275.  
  276.         push    offset msg
  277.         mov        al,6
  278.         call    [chooseofs]                        ;DispatchMessage = 15
  279.  
  280.         jmp     msg_loop
  281.  
  282. end_loop:
  283.         push    [msg.msWPARAM]
  284.         mov        al,10
  285.         call    [chooseofs]                        ;ExitProcess = 34
  286.  
  287. ;----------------------------------------------------------------------------
  288. ; WARNING: Win32 requires that EBX, EDI, and ESI be preserved!  
  289. ;
  290. ; In this part we will put the events we want to respond on.
  291. ; Key, MouseButtons, Resize, Menu, Commands.... (look at the win32.inc)
  292. ; You can leave the above without changes a modify the next part only
  293. ;----------------------------------------------------------------------------
  294.  
  295. WndProc proc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  296.         push    esi
  297.         push    edi
  298.         push    ebx
  299.         jmp     defwndproc
  300. defwndproc:
  301.         push    [lparam]
  302.         push    [wparam]
  303.         push    [wmsg]
  304.         push    [hwnd]
  305.         call    DefWindowProc
  306.         jmp     finish
  307.  
  308. finish:
  309.         pop     ebx                             ;Remember we must restore these registers
  310.         pop     edi                             ;Because the OS need them
  311.         pop     esi
  312.         ret
  313.  
  314. WndProc          endp
  315.  
  316. public WndProc
  317.  
  318.  
  319. ;----------------------
  320. ;Start Dialog
  321. ;----------------------
  322.  
  323. Main_DlgProc proc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  324.  
  325.         push    ebx
  326.         push    esi
  327.         push    edi
  328.  
  329.         cmp     [wmsg],WM_COMMAND                ;Respond to buttons
  330.         je      main_command
  331.         cmp     [wmsg], WM_CLOSE                ;Respond to if we want to shut it down
  332.         je      main_dlgdestroy
  333.                        
  334.         mov     eax,FALSE
  335.  
  336. main_finish:
  337.         pop     edi
  338.         pop     esi
  339.         pop     ebx
  340.         ret
  341.  
  342. updatestat:
  343.         Call     PolySetup
  344.  
  345.         push    offset statwait
  346.         push    IDD_STAT
  347.         push    [hwnd]
  348.         mov        al,21
  349.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  350.  
  351.         mov        tempflag,1        
  352.         mov        eax,TRUE
  353.         jmp        main_finish
  354.         
  355. ;---------------------------------
  356. ;HERE IS WHERE THE FUN PART BEGINS
  357. ;---------------------------------
  358.  
  359. main_go:                        
  360.  
  361.         mov        edx,offset psw
  362.         lea        ebx,[eax*4]
  363.         add        ebx,5
  364.         add        ebx,edx
  365.  
  366.         push    edx
  367.         push    L 14
  368.         push    L WM_GETTEXT
  369.         push    L IDD_EDIT1
  370.         push    [hwnd]
  371.         mov        al,37
  372.         call    [chooseofs]                        ;SendDlgItemMessageA = 6
  373.         call    RealProt
  374.         push    eax
  375.  
  376.         mov        edi,1                            ;Edi=1 --> Write FakeCode
  377.         call    PolyWrite
  378.  
  379.         mov        ecx,8
  380.         lea        edi,readbuffer
  381.         lea        esi,FileFakePsw        
  382.         fakefake:
  383.         mov        al, byte ptr [edi]
  384.         mov        bl, byte ptr [esi]
  385.         xor        al,bl
  386.         rol        al,1
  387.         mov        byte ptr [esi],al
  388.         inc        edi
  389.         inc        esi
  390.         loop    fakefake
  391.  
  392.  
  393.         pop        eax
  394.         test    eax,eax
  395.         je        Noneedforthis
  396.  
  397.         lea        edi,GetDlgItemTextA
  398.         push    10
  399.         push    offset psw        
  400.         push    IDD_EDIT1
  401.         push    [hwnd]
  402.  
  403.         push    ds
  404.         push    cs
  405.         pop        ds
  406.         mov        edi,[edi+2]                        ;Get DLL function jmp address
  407.         mov        edi,[edi]                        ;Get DLL function real address
  408.         mov        eax,[edi]                        ;Get first bytes of DLL function
  409.         pop        ds
  410.         and     eax,0FFh                        ;Save only the first byte
  411.         cmp        eax,0CCh                        ;It this function BPX'ed?
  412.         jne        NoBPX
  413.  
  414.         push    L MB_ICONEXCLAMATION
  415.         push    offset siceHeader
  416.         push    offset nosice
  417.         push    0
  418.         mov        al,26
  419.         call    [chooseofs]                        ;MessageBoxA = 33
  420.  
  421.         push    [msg.msWPARAM]
  422.         mov        al,10
  423.         call    [chooseofs]                        ;ExitProcess = 34
  424.  
  425.         NoBPX:
  426.         call    edi
  427.  
  428.         call    fakeprot
  429.         test    eax,eax
  430.         je        fakenotvalid
  431.  
  432.         push    offset statyes
  433.         push    IDD_STAT+1
  434.         push    [hwnd]
  435.         mov        al,21
  436.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  437.  
  438.         fakenotvalid:
  439.         push    offset statno
  440.         push    IDD_STAT
  441.         push    [hwnd]
  442.         mov        al,21
  443.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  444.         
  445.         Noneedforthis:
  446.         xor        edi,edi
  447.         call    PolyWrite                        ;Edi=0 --> Write RealProtScheme
  448.         mov        eax,TRUE
  449.         jmp        main_finish
  450.  
  451.  
  452. main_command:
  453.         cmp        tempflag,0
  454.         je        updatestat
  455.         cmp        [wparam],IDD_GO                    ;User clicked on "check" button?
  456.         je        main_go
  457.         cmp     [wparam],IDD_CLOSE
  458.         jne     main_nothing
  459.  
  460. main_dlgdestroy:
  461.         push    L 0             
  462.         push    [hwnd]
  463.         mov        al,3
  464.         call    [chooseofs]                         ;CloseDialog = 30
  465.  
  466.         mov     eax,TRUE        
  467.         jmp     main_finish
  468.  
  469. main_nothing:
  470.  
  471.         push    offset FileMon
  472.         push     L 0
  473.         mov        al,39
  474.         call    [chooseofs]                          ;FindWindow = 22
  475.         test    eax,eax        
  476.         jz        noclose
  477.  
  478.         push     offset ProcID
  479.         push     eax            
  480.         mov        al,30
  481.         call    [chooseofs]                        ;GetWindowThreadProcessId = 23
  482.         test     eax,eax
  483.         jz       noclose
  484.  
  485.         push     [ProcID]                        ;Owner process ID
  486.         push     L 0
  487.         push     offset Flagst                    ;Flags = Read/Write
  488.         mov        al,8
  489.         call    [chooseofs]                        ;OpenProcess = 17
  490.         test     eax,eax
  491.         jz         noclose
  492.         mov        handle,eax
  493.  
  494.         push    offset ProcID
  495.         push    eax
  496.         mov        al,32
  497.         call    [chooseofs]                        ;GetExitCodeProcess = 11
  498.         test    eax,eax
  499.         jz        noclose
  500.             
  501.         push    [ProcID]
  502.         push    [handle]
  503.         mov        al,13
  504.         call    [chooseofs]                        ;TerminateProcess = 40
  505.  
  506. noclose:
  507.  
  508.         mov     eax,FALSE
  509.         jmp     main_finish
  510.  
  511. Main_DlgProc    endp
  512. public Main_DlgProc
  513.        include morefunc.asm
  514.  
  515. end start
  516.