<?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>code-diesel &#187; malware</title>
	<atom:link href="http://www.codediesel.com/tag/malware/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Scanning web pages for malicious scripts</title>
		<link>http://www.codediesel.com/php/scanning-web-pages-for-malicious-scripts-in-php/</link>
		<comments>http://www.codediesel.com/php/scanning-web-pages-for-malicious-scripts-in-php/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 05:30:18 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[malware]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2117</guid>
		<description><![CDATA[Auto scanning of selected web pages for malicious scripts]]></description>
			<content:encoded><![CDATA[<p>With the recent surge of malicious JavaScript injections on web, it has become necessary to regularly check for malicious code injections on your web sites. I created a small php script that checks a list of urls for malicious Javascript code. This can come handy if you have many client websites under your control.</p>
<p>The PHP script reads two text files &#8211; &#8216;malicious.txt and &#8216;urls.txt&#8217; : the first containing a list of web pages to be scanned and the other containing malicious script signatures. The script scans the urls for malicious scripts and if any infections are found it saves the result in the &#8216;infected.txt&#8217; file. The script needs to be run from the command line as you can easily see the progress of the scan if you are scanning a large number of urls.<br />
<span id="more-2117"></span></p>

<div class="wp_codebox"><table><tr id="p21171"><td class="code" id="p2117code1"><pre class="dos" style="font-family:monospace;">D:\localhost\test\scan&gt;php url_scan.php</pre></td></tr></table></div>

<p>A sample output of a scan is show below:</p>

<div class="wp_codebox"><table><tr id="p21172"><td class="code" id="p2117code2"><pre class="text" style="font-family:monospace;">&nbsp;
D:\localhost\test\scan&gt;php url_scan.php
&nbsp;
Checking 3 sites for malicious scripts.
3 malicious signatures in file.
---------------------------------------------------------
&nbsp;
Now scanning :http://www.amazon.com/
[OK]
---------------------------------------------------------
&nbsp;
Now scanning :http://www.google.com/
[OK]
---------------------------------------------------------
&nbsp;
Now scanning :http://www.example.com/admin.php
[OK]
---------------------------------------------------------
&nbsp;
Total 0 sites infected of 3</pre></td></tr></table></div>

<p>Note that the script only scans the url path given and not the complete web site. So if given a url like &#8216;http://www.example.com&#8217; it will only scan the index file of the site. It may happen that the index file may not be infected but some other file in a sub-directory is, in that case the malicious code will not be found. But a larger percentage of malicious script injections are usually inflicted on the index page.</p>
<h4>Setting a cron for automatic scanning</h4>
<p>The best way to regularly check for any infections is to setup the script as a cron job. This can help you in checking malicious script on a regular interval, the cron job can then send the &#8216;infected.txt&#8217; file via a email if any infections are found.</p>
<h4>Updating your malicious.txt file</h4>
<p>You cannot fight new code injections if your &#8216;malicious.txt&#8217; file is not updated. So if you find some new malicious Javascript code, then it is essential that you include a new signature in the file. Well I know I&#8217;m putting the cart before the horse but you can find various new information about infections at <a href="http://www.malware.com.br/">malware.com.br</a> or <a href="http://www.malwaredomainlist.com/mdl.php">malwaredomainlist</a>.</p>
<h4>Other ways to check malicious code injections</h4>
<p>One main problem with the script is that if some new infection occurs and the signature is not in the &#8216;malicious.txt&#8217; database then that particular infection will be missed. One other solution is to check the filesize of the particular url you are checking. The filesize needs to be added to the &#8216;urls.txt&#8217; file, so the script can check to see if the filesize of the url scanned is the same as the one given. But for that we will need to use the ftp functions of php but we will leave that to another post.</p>
<div  class="download2">
<a href="http://www.codediesel.com/downloads/urlscan">Download Source</a><br />
<span>Downloads : 1434  / File size : 1.4 kB</span>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/scanning-web-pages-for-malicious-scripts-in-php/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

