Cryptpad 1
Cryptpad 1
�� ____ __ __ ����
�� / _/_ _ __ _ ___ ____/ /____ _/ / �� ���
�� _/ // ' \/ ' \/ _ \/ __/ __/ _ `/ / �� � �
�� /___/_/_/_/_/_/_/\___/_/ \__/\_,_/_/ �� � �
�� ____ __ __ �� � �
�� / __ \___ ___ _______ ___ ___/ /__ ____ / /____�� � �
�� / /_/ / -_|_-</ __/ -_) _ \/ _ / _ `/ _ \/ __(_-<�� � �
��/_____/\__/___/\__/\__/_//_/\_,_/\_,_/_//_/\__/___/�� � �
�� �� � �
�� Web: http://www.ImmortalDescendants.org �� � �
�� EFnet: #ImmortalDescendants �� � �
�� Author: defiler �� � �
�� Date: 04/09/00 (mm/dd/yy) �� � �
�� Topic: Adding Functionality - Notepad �� � �
�� Level: Intermediate/Advanced �� � �
�� �� � �
������������������������������������������������������� � �
������������������������������������������������������� �
�������������������������������������������������������
=======================================================================
PUBLISHER'S NOTE: the original and modified exe's used in this essay
can be found at:
www.immortaldescendants.org/database/essays/defiler/source/cryptpad.zip
=======================================================================
This essay is based on an old idea i had a year ago. I realized this idea,
but i didn't know anything of the PE-format at all, so i just overwrote some
other code. This time I will be using caves, no code gets overwritten. ;)
The idea:
We will make notepad to 'encrypt' its buffer before it'll be saved to disc.
The essay:
Now have a look at the Offset of the .data section (PhysSize ain't important):
You see, Both offsets match... hmmm but maybe there are some unused bytes anyway ?
Let's see.. select the first section (.text) and press enter.
We landed at 401000, it's the beginning of the code (.text) section (NOT the
EnytrPoint!!)
As you may remember, its physical size was 4000. Add this value to 401000 and we
have
the end of the .text section (405000). Jump to this address by pressing F5, then
enter
".405000" (don't forget the dot).
So we are directly "between" the .text and the .data section. If you scroll up a
bit,
you'll see rather lot of 0-bytes (I guess they're unused, as the characteristics
for
this section is 60000020).
You scroll up until you see the last non-crap instruction of the .text section.
You should be at 404E96 (there's a jmp GetFileTitleA), 404E9C may be the first byte
we
could use. Now press Ctrl-D to get into our beloved ring0 debugger, just to
calculate the
number of bytes we can use - type "? 405000 - 404E9C". Sice gives us:
164h = 356, a lot of bytes, at least for our purpose.
OK, we got almost all necessary stuff to start adding some code:
404E9C, the RVA of the unused bytes, where we'll insert our code and 356 bytes to
use.
Just one thing missing: The address of the routine, that reads in notepad's
textbuffer.
After reading in the textbuffer we have to jump immediately to our routine to
encrypt it.
And this is how we can get it: Create an empty textfile, run notepad.exe, open the
empty
file and write some text. Press Ctrl-D and type "bpx CreateFileA", i guess it uses
this
API to save the file. Get back to Windows again, select File/Save.
We are inside Kernel32!CreateFileA, after pressing F11 (g @ss:esp) we are back in
Notepad!.text+21E5:
LRESULT SendMessage(
We need UINT Msg, it is the 3rd parametre pushed onto stack (remember LIFO!).
In our case it is 000000C8, so we go visiting sice and typing "wmsg C8".
Sice gives us: 00C8 EM_FMTLINES
Another SendMessageA, this time with UINT Msg == 0E. Back in sice we type
"wmsg 0e" == WM_GETTEXTLENGTH, this one is good! ...but we don't want it :P
go on..
000D WM_GETTEXT
WM_GETTEXT
wParam = (WPARAM) cchTextMax; // number of characters to copy
lParam = (LPARAM) lpszText; // address of buffer for text
Return Values:
The return value is the number of characters copied.
great.here we got to insert a jump to our code somewhere. i think we'll take the
line at 4032C7, gonna insert the jump to our code (remember, our location was
404E9C).
Of course, we got to restore the overwritten bytes inside our code again.
Our jump needs 5 bytes, so the "push dword ptr [00405640]" instruction has to be
resotored again.
Press F5 (GOTO) then type ".4032C7", then F3 "EDIT" and finally F2 to switch to
ASM.
Enter "jmp 4E9C" press return, then "nop" and return, then escape.
Then press F9 and our jump is done. Now we'll code the "encryption".
We are at 4032CD now, that's where we got to jump back to.
Jump to the cave, where we'll add this code by pressing F5 and typing ".404E9C".
Now remember, edi was a pointer to the textbuffer and eax the size of the buffer in
bytes.
So we'll make an easy 'encryption', you may write your own, mine is rather cheap, a
simple
XOR plus a ROL instruction ;)
OK, we are still at 404E9C. Press F3, then F2 and enter the code above.
The label "lamecrypt" is located at 404E9E, so you won't type "loop lamecrypt",
you'll
type "loop 4E9C". Finally press F9 and we have finished the encryption-code.
We have finished now, at least part 1, i need to learn for a maths test now,
maybe i'll update this essay tomorrow.
Included are my modified version and my orginial version of notepad.
no specific order.
ultraschall, cardenal mendoza, kaparo, flwright, ratso, haldir, lightdruid,
ganjaman,
telcofix, whataduck, tornado, hutch, masta, notty, knotty, kwazy webbit, secret,
iczelion,
bisoux, MisterE, mr nop, neural noise, lazarus, peegee, random, daze, the anti
xryst,
acid burn, azzyrian, decline, blind angel, keyboard junky, reverend x, DnNuke,
Gizmo,
viny, volatility, alpine, promothee, sat0r, fli7e, targ0n, Ridlexx, novatrix,
TomTom,
WarezPup, Weazel, visionz, kaai, MagicRaph, sepulcrum, MVD, sn00pee, sinn0r and all
who contribute to the reversing spirit ;)
Group/chan greets:
all blizzard members, everyone in #win32asm, #cracking, #eliteFravias,
#reversing4newbies,
#immortaldescendants, #digital.factory, #hellforge, and #learn2crack.