alaphate Posted July 22, 2012 Posted July 22, 2012 I built a simple dialog using c#.There are two textbox controls.One is readonly.Question is how to set the readonly property to false given only the released exe file.I used reshacker to open the exe, however no dialog resource displayed.Thank you for helping.Attchment is the exe application.hackForm.zip
mrexodia Posted July 22, 2012 Posted July 22, 2012 You should try CFF Explorer, it has better .net support..Greetings
alaphate Posted July 22, 2012 Author Posted July 22, 2012 c sharp dialogs seem not resources.Therefore, I have to decomile the exe using reflector or other decomiling tools.
mrexodia Posted July 22, 2012 Posted July 22, 2012 I loaded the binary in reflector and found this code:private void InitializeComponent(){ this.textBox1 = new TextBox(); this.textBox2 = new TextBox(); base.SuspendLayout(); this.textBox1.Location = new Point(0x10, 8); this.textBox1.Name = "textBox1"; this.textBox1.Size = new Size(0xe0, 0x15); this.textBox1.TabIndex = 0; this.textBox1.Text = "textBox1"; this.textBox2.Location = new Point(0x10, 0x30); this.textBox2.Name = "textBox2"; this.textBox2.ReadOnly = true; //Just set this to false or simply delete the instruction(s) this.textBox2.Size = new Size(0xe0, 0x15); this.textBox2.TabIndex = 1; this.textBox2.Text = "textBox2"; this.AutoScaleBaseSize = new Size(6, 14); base.ClientSize = new Size(0x100, 0x55); base.Controls.Add(this.textBox2); base.Controls.Add(this.textBox1); base.Name = "Form1"; base.StartPosition = FormStartPosition.CenterScreen; this.Text = "Form1"; base.ResumeLayout(false);}Attached the fixed file..Greetings,Mr. eXoDiahackForm.Patched.rar
alaphate Posted July 23, 2012 Author Posted July 23, 2012 (edited) I got a small app for debuging local aspx files, a small developer server.However, it has a readonly textbox which is not for convenient use.I used reflector to open it, but got errors.App's Interface:Local Path: C:\Inetpub\wwwroot [browse]Virtual Path: / [close]Port:8080 [start]webserver ip: ...Any buddies could help me to remove the readonly property of the 1st textbox?Thank you.dev_webhost.zip Edited July 23, 2012 by alaphate
mrexodia Posted July 23, 2012 Posted July 23, 2012 (edited) Hi,I looked at your file and it came out that it's protected with XenoCode 2007...Extracting the main EXE goes as follows:1) Open dev_webhost.exe in Olly2) Run3) Search in memory for BeginForm4) Scroll up untill you see "PE"5) Dump that region to retrieve the main EXEIf you run it you'll notice that you need a DLL. Because I'm not really familiar with XenoCode I decided to inline patch the EXE.Open the EXE in Reflector and navigate to WeDev.WebServer2.BeginForm.InitializeComponent()Somewhere in that code (IL+Bytes) you'll see this:ldfld class System.Windows.Forms.TextBox WebDev.WebServer2.BeginForm::physicalPathTextBox //7B22000004ldc.i4.1 //17 <- this should change to 16callvirt instance void System.Windows.Forms.TextBoxBase::set_ReadOnly(bool) //6F5300000Aldarg.0 //02ldfld class System.Windows.Forms.TextBox WebDev.WebServer2.BeginForm::physicalPathTextBox //7B22000004I open the protected file in OllyDbg again and break on MapViewOfFile. We are looking for the 3rd break. (So run three times)If you return to the code you'll see something like this:push ebxpush ebxpush ebxpush 2push dword ptr ss:[ebp-14]mov dword ptr ss:[ebp-24],eaxcall dword ptr ds:[MapViewOfFile]cmp dword ptr ss:[ebp-24],0b7 <- EIPmov edi,eaxje l013push esimov ecx,edicall 00a94353 <- this is the important calll013:mov eax,dword ptr ss:[ebp-14] <- code cave jump heremov dword ptr ds:[esi+3c],edimov dword ptr ss:[ebp-14],ebxmov dword ptr ds:[esi+40],eaxmov byte ptr ss:[ebp-4],2If you follow EAX in dump you'll notice that it's filled with zeroes...The call I marked important writes the original EXE in the memory. My idea was to simply place a jump to the code cave at the marked place. (I used pattern 7B22000004176F5300000A02 to find the good place)Problem is that the memory address is dynamic so I had to hook just before the call to the allocated memory:je l021push eaxcall dev_webh.00401358mov edi,eaxcmp edi,ebxpop ecxjnz l014mov esi,dev_webh.00402010push dev_webh.004010e0mov eax,esicall dev_webh.004018fdpush dev_webh.004011e0call dev_webh.004018c4jmp l021l014:push ebxcall GetModuleHandleWpush dword ptr ss:[esp+10] <- jump to hooking code here (0040182B)push esipush eaxcall edi <- this calls the extraction code (in dynamic memory)add esp,0cl021:push 10We place some inline code (use MultimateAssembler 1.6) at some free space (00401B0E):<00401B0E> ;addresspushad ;preserve registerslea eax,dword ptr ds:[edi-0A81E] ;the place we want to put a jump (after the important call)lea ebx,dword ptr es:[@patch_exe] ;destination of our jumpsub ebx,eax ;substract thoselea ebx,dword ptr ds:[ebx-5] ;minus five (length of long JMP or CALL)mov byte ptr ds:[eax],0E8 ;we use CALL because that saves a lot of code (we can do RETN)mov dword ptr ds:[eax+1],ebx ;our calculated dest dwordmov byte ptr ds:[eax+5],90 ;nop just after the call (the original code is 6 bytes)popad ;restore registerspush dword ptr ss:[esp+10] ;original codepush esi ;original codejmp 00401830 ;jump away from our codecave@patch_exe: ;place that changes the bytescmp byte ptr ds:[@done], 0 ;make sure we only patch once (NOTE : make EP section ReadWrite!)jne short @skipinc byte ptr ds:[@done] ;to ensure we only patch oncedec byte ptr ds:[edi+1DB7] ;17 -> 16 (ldc.i4.1 -> ldc.i4.0)@skip:mov eax,dword ptr ss:[ebp-14] ;original codemov dword ptr ds:[esi+3c],ediretn@done:"\0"Just ask when something's unclear. I attached the fixed file and the .net opcode table (for seeing the byte codes)Greetings,Mr. eXoDiadev_webhost_patched.rar Edited July 23, 2012 by Mr. eXoDia
alaphate Posted July 23, 2012 Author Posted July 23, 2012 (edited) Mr. eXoDiaGreat work! Thank you so much for the tutorial.The patched file got some bugs:Run it twice (two windows), I'll get a readonly textbox again.Run it 4 times, the application will crash, and get an unhandled exception error message.BTW, how you detected it's packed with XenoCode 2007?I used PEiD and FastScanner with no correct result.Thanks. Edited July 23, 2012 by alaphate
mrexodia Posted July 23, 2012 Posted July 23, 2012 I used protectionId to find that out.. searching for all referenced text strings will also show you that its xenocode though.About those crashes: i have no idea how to fix that, maybe creating a loader with dup will solve the errors..Greetings,Mr. eXoDia
alaphate Posted July 24, 2012 Author Posted July 24, 2012 Mr. eXoDia,Thank you so much for the suggestions.
e_z_minded_guy Posted October 15, 2012 Posted October 15, 2012 Mr. eXoDia, if I had half of your knowledge about not just reverse engineering but especially unpacking -- damn, you've got skillz. I've seen your tutorials and comments before and I love that you're so involved in helping others learn. Thanks for your time and keep up the great work!!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now