<?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; security</title>
	<atom:link href="http://www.codediesel.com/tag/security/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>Changing WordPress admin login error message</title>
		<link>http://www.codediesel.com/security/changing-wordpress-admin-login-error-message/</link>
		<comments>http://www.codediesel.com/security/changing-wordpress-admin-login-error-message/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 05:13:15 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2965</guid>
		<description><![CDATA[It can be surprising how easy it is to overlook security issues in software design. WordPress for example, after all the versions, still displays login error information that can be informative for a potential hacker. Rather than displaying a generic login error message, WordPress admin specifically displays whether a &#8216;username&#8217; was entered wrong or a [...]]]></description>
			<content:encoded><![CDATA[<p>It can be surprising how easy it is to overlook security issues in software design. WordPress for example, after all the versions, still displays login error information that can be informative for a potential hacker. Rather than displaying a generic login error message, WordPress admin specifically displays whether a &#8216;username&#8217; was entered wrong or a &#8216;password&#8217; as the following screenshot shows.<br />
<span id="more-2965"></span><br />
<a href="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login1.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login1.gif" alt="" title="wp-login1" width="330" height="293" class="aligncenter size-full wp-image-2966" /></a></p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login3.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login3.gif" alt="" title="wp-login3" width="333" height="307" class="aligncenter size-full wp-image-2969" /></a></p>
<p>This can be useful for a hacker to get  the username right. A good idea is to display a generic message as given below.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login2.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/12/wp-login2.gif" alt="" title="wp-login2" width="331" height="291" class="aligncenter size-full wp-image-2967" /></a></p>
<p>You can easily achieve that by adding the following line to your themes &#8216;functions.php&#8217; file.</p>

<div class="wp_codebox"><table><tr id="p29653"><td class="code" id="p2965code3"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login_errors'</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$no_login_error'</span><span style="color: #339933;">,</span> 
                            <span style="color: #0000ff;">&quot;return 'Oops! Wrong Credentials.';&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The second argument to the &#8216;add_filter&#8217; creates a anonymous callback function. This is equivalent to the following.</p>

<div class="wp_codebox"><table><tr id="p29654"><td class="code" id="p2965code4"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> no_login_error<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">'Oops! Wrong Credentials.'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login_errors'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'no_login_error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/security/changing-wordpress-admin-login-error-message/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress plugins to check for security threats</title>
		<link>http://www.codediesel.com/security/wordpress-plugins-to-check-for-security-threats/</link>
		<comments>http://www.codediesel.com/security/wordpress-plugins-to-check-for-security-threats/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 05:47:53 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2952</guid>
		<description><![CDATA[With WordPress installations on the rise, security threats are a common concern for users. Below is a small collection of WordPress plugins that I found adequate for use on most WordPress installations to keep security in check. As always security is not 100% achievable, but the following plugins will help you find any loopholes in [...]]]></description>
			<content:encoded><![CDATA[<p>With WordPress installations on the rise, security threats are a common concern for users. Below is a small collection of WordPress plugins that I found adequate for use on most WordPress installations to keep security in check. As always security is not 100% achievable, but the following plugins will help you find any loopholes in your site and help you monitor for any security breaches.<br />
<span id="more-2952"></span><br />
<strong>BulletProof Security</strong><br />
<a href="http://wordpress.org/extend/plugins/bulletproof-security/" title="BulletProof Security" target="_blank">BulletProof Security</a> protects your website from XSS, RFI, CSRF, Base64, Code Injection and SQL Injection hacking attempts. The plugin also Protects wp-config.php, bb-config.php, php.ini, php5.ini, install.php and readme.html with .htaccess security protection. BPS has built-in Backup and Restore, a File Editor, a File Uploader and a File Downloader to make managing the BPS master .htaccess files and your website security fast and simple.</p>
<p><strong>WordPress File Monitor</strong><br />
<a href="http://wordpress.org/extend/plugins/wordpress-file-monitor/" title="WordPress File Monitor" target="_blank">WFM</a> monitors your WordPress installation for any added, deleted or changed files. When a change is detected an email is sent to a specified address. Currently does not support multi-site installations.</p>
<p><strong>Ultimate Security Checker</strong><br />
<a href="http://wordpress.org/extend/plugins/ultimate-security-checker/" title="Ultimate Security Checker" target="_blank">Ultimate Security Checker</a> helps you identify security problems with your WordPress installation. It scans your WordPress blog for hundreds of known threats, then gives you a security &#8220;grade&#8221; based on how well you have protected yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/security/wordpress-plugins-to-check-for-security-threats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking your site for malicious changes</title>
		<link>http://www.codediesel.com/security/checking-your-site-for-malicious-changes/</link>
		<comments>http://www.codediesel.com/security/checking-your-site-for-malicious-changes/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 13:36:12 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2881</guid>
		<description><![CDATA[Today a couple of hours back my site got compromised. Not much changes to the code, but the .htacces was changed and some code like the below was added to the .htaccess file, which redirected the traffic coming from search engines to a malware site. It has now been removed and to prevent any such [...]]]></description>
			<content:encoded><![CDATA[<p>Today a couple of hours back my site got compromised. Not much changes to the code, but the .htacces was changed and some code like the below was added to the .htaccess file, which redirected the traffic coming from search engines to a malware site. </p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/08/htaccess_redirect.png"><img src="http://www.codediesel.com/wp-content/uploads/2011/08/htaccess_redirect.png" alt="" title="htaccess redirect" width="351" height="126" class="aligncenter size-full wp-image-2882" /></a><br />
<span id="more-2881"></span><br />
It has now been removed and to prevent any such changes to the .htaccess file in the future, I&#8217;ve written a small php script that compares the hash (SHA1) of the two major files that usually get compromised and compare them to the one originally stored. The script will run as a cron job and notify me by email if any changes are seen. This is a quick workaround which needs some more work done.</p>

<div class="wp_codebox"><table><tr id="p28816"><td class="code" id="p2881code6"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$hash1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sha1_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.htaccess'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$hash2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sha1_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hash1</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'fa7cdb22b81b0b713bfed609acc984591f9bed2f'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> 
   <span style="color: #009900;">&#40;</span><span style="color: #000088;">$hash2</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'b4bb6070800a340566d7d6872516d248d4a7aff3'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;EMAIL&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Status Ok!&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Status Ok!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;EMAIL&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Alert!&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Files have changed!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>    
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Of-course there are other ways the site can get hacked, but the last couple of times my site got compromised was for these reasons. So at-least I&#8217;ve one area covered.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/security/checking-your-site-for-malicious-changes/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Security &#8216;Challenge Questions&#8217; and the social web</title>
		<link>http://www.codediesel.com/security/security-challenge-questions-and-the-social-web/</link>
		<comments>http://www.codediesel.com/security/security-challenge-questions-and-the-social-web/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 05:39:08 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[social web]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2792</guid>
		<description><![CDATA[Lately I’ve been a little paranoid about posting details about myself on the social web, especially Facebook. In fact I’ve completely gone off it (never been a fan of it from the first). I’m surprised by the amount of personal information people post on the social web. One of my concerns is related to the [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I’ve been a little paranoid about posting details about myself on the social web, especially Facebook. In fact I’ve completely gone off it (never been a fan of it from the first). I’m surprised by the amount of personal information people post on the social web.</p>
<p>One of my concerns is related to the ‘Challenge Questions’ provided by major websites such as Gmail, Hotmail for authentication, mostly during account recovery. Take for example the Challenge Question offered by Gmail:</p>
<p>What is the name of your manager at your first job?<br />
What is the name of your best friend from childhood?<br />
What was the name of your first teacher?</p>
<p>Answers to most of the above questions can be garnered by a little digging around your social stream, making it easier for the malicious person to hack your account. Aggregators such as <a target="_blank" href="http://identengine.com/">IdentEngine</a>, a Javascript library, can make it even easier to locate your profiles around the social web. In short, the social web &#8220;leaks&#8221; security information.<br />
<span id="more-2792"></span><br />
When Scott McNealy remarked in 1999, &#8220;You have zero privacy anyway,Get over it.&#8221;, he was right on the technical front but wrong otherwise. You still have control over of how much personal information about you floats around the web; it may be a little harder but not impossible. The important point is to be alert and proactive when divulging important information around the web.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/security/security-challenge-questions-and-the-social-web/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Fix PHP Vulnerabilities (So Your Site Won&#8217;t Get Hacked)</title>
		<link>http://www.codediesel.com/php/how-to-fix-php-vulnerabilities/</link>
		<comments>http://www.codediesel.com/php/how-to-fix-php-vulnerabilities/#comments</comments>
		<pubDate>Mon, 24 May 2010 05:54:28 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2660</guid>
		<description><![CDATA[How to Fix PHP Vulnerabilities]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codediesel.com/wp-content/uploads/2010/05/the_Crooked_Man.png"><img src="http://www.codediesel.com/wp-content/uploads/2010/05/the_Crooked_Man.png" alt="" title="the_Crooked_Man" width="222" height="250" class="alignleft size-full wp-image-2662" style="border: none;" /></a></p>
<p>As a programming language, PHP has many advantages but security has always been a major issue. Partially these security problems are inherent to the language itself because PHP was meant to be an easy and powerful programming language, while security came second. However, when you add bad coding and non-adherence to even the basic security rules, the situation gets out of control. </p>
<p>Fortunately, it is possible to fix PHP vulnerabilities and make PHP applications more secure. Some of the defenses are common for all programming languages, while others are found only in PHP. Here are some of the best defenses you have when you want to fix PHP vulnerabilities and make your site more secure.<br />
<span id="more-2660"></span></p>
<h4>Defend Your Code Against SQL Injections</h4>
<p>SQL Injection is one of the most typical PHP vulnerabilities and many hackers take advantage of it. In order to prevent SQL injections, you need to always check input data and to escape characters (such as single quotes (&#8216;) or double quotes (&#8220;)). If you do it, it won&#8217;t be possible to execute malicious SQL queries, which take control over your database or compromise the security of your site in other ways. </p>
<p>The two most common defenses against SQL injections are the use of the  <a target="_blank" href="http://php.net/manual/en/function.mysql-real-escape-string.php">mysql_real_escape_string</a> and <a target="_blank" href="http://php.net/manual/en/book.pdo.php">PDO</a>. The mysql_real_escape_string prepends special characters and as a result these special characters are not sent directly to the MySQL database. It is recommendable to use <em>mysql_real_escape_string</em> on all input variables, which are sent to the MySQL database.<br />
PDO adds an abstraction layer to your code, thus making it more secure. PDO prepares a statement for execution and returns a statement object. </p>
<h4>Don&#8217;t Leave Room for Cross-Site Scripting Vulnerabilities</h4>
<p>Cross-Site Scripting (XSS) is also common in PHP. Again, the defense against XSS isn&#8217;t rocket science. If the users input HTML data is escaped properly, your code won&#8217;t be vulnerable against XSS. If you don&#8217;t do it, then a hacker can insert any HTML code (or even Javascript) he or she likes and modify your page, so that he or she can steal data from users. </p>
<p>The best defense against XSS is to use the htmlspecialchars() function. This function identifies any output you wouldn&#8217;t like to be considered as HTML output. While you can never be certain that XSS is impossible, the htmlspecialchars() function will make it harder for a hacker to succeed. </p>
<h4>Watch out for File Inclusion Vulnerabilities</h4>
<p>Of all PHP vulnerabilities, file inclusion attacks are the most severe. A file inclusion attack gives the hacker the opportunity to include a random file and to deploy it on your server. File inclusion attacks are possible when the register_globals directive is on, which means that unchecked input variables are allowed. The best defense against file inclusion vulnerabilities is to mind how you use PHP include() functions. If you are not sure you can use these functions properly, you&#8217;d better avoid any include statements – just use switch statements with hard coded strings and this will help to avoid file inclusion vulnerabilities. </p>
<h4>Don&#8217;t Forget to Initialize Variables</h4>
<p>If you program in many other languages, then you maybe don&#8217;t need to be told explicitly to initialize variables because you already have the habit of doing it. However, if you are mainly a PHP programmer, maybe you don&#8217;t always initialize variables because in PHP, unlike in many other programming languages, a variable can be used without being initialized first. From a security point of view, uninitialized variables are a huge risk and this is why you should never use them. </p>
<h4>Don&#8217;t Leave the <em>register_globals</em> Directive ON</h4>
<p>File inclusion attacks aren&#8217;t the only evil the <em>register_globals</em> directive brings to your code. The register_globals directive is very powerful but unfortunately its power is easily abused. In recent versions of PHP the directive register_globals is OFF by default and in PHP 6 it is altogether removed but if you are using earlier versions of PHP, take the time and check if it isn&#8217;t ON by accident. </p>
<h4>Encryption Always Helps</h4>
<p>No matter which programming language you use, encryption always helps. It doesn&#8217;t matter how secure your PHP code is when you send sensitive data unencrypted and anybody can read it. The safest form of encryption is end-to-end encryption but it takes a lot of resources and it might be hard to implement. This is why it is acceptable if you encrypt at least passwords, credit card numbers, and other similar data. Don&#8217;t leave sensitive data unencrypted because this is what hackers want most. </p>
<h4>Test Your PHP Code with Tools</h4>
<p>There are many PHP tools to test the security of your code with. Sure, you should do your best to write secure code, adhere to security practices, and carefully review your code for errors but an automated tool to check your code with is always useful. Some of the best tools to test PHP vulnerabilities with are <a target="_blank" href="http://phpsec.org/projects/phpsecinfo/">PhpSecInfo</a>, <a target="_blank" href="http://sourceforge.net/projects/securityscanner/">PHP Security Scanner</a>, and <a target="_blank" href="http://developer.spikesource.com/projects/phpsecaudit">Spike PHP Security Audit Tool</a>. Run them on your code and see what they will find. </p>
<h4>Further Reading</h4>
<p>These steps are just the beginning to make your PHP code secure. You must always take at least these steps because if you don&#8217;t you leave the door wide open to hackers. On the other hand, even if you do everything we described here, you can never be sure that no vulnerabilities exist. There is much more to PHP security and if you want to expand your knowledge, read the <a target="_blank" href="http://php.net/manual/en/security.php">PHP Security manual</a> and this paper. Both of them will tell you more about how to fix PHP vulnerabilities and make your site secure. </p>
<blockquote><p>
This guest article was written by Christopher Shepard of <a target="_Blank"  href="http://www.webhostgear.com/">Webhost Gear</a>, a website that provides information about hosting and reviews of the most popular web hosting services, as well as technical and website maintenance tutorials.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/how-to-fix-php-vulnerabilities/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<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="p21177"><td class="code" id="p2117code7"><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="p21178"><td class="code" id="p2117code8"><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>
		<item>
		<title>Top 25 Most Dangerous Programming Errors</title>
		<link>http://www.codediesel.com/security/top-25-most-dangerous-programming-errors/</link>
		<comments>http://www.codediesel.com/security/top-25-most-dangerous-programming-errors/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 11:19:41 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1319</guid>
		<description><![CDATA[Top 25 list of software vulnerabilities]]></description>
			<content:encoded><![CDATA[<p>Security has always been an issue in software development; mainly due to ignorance, laziness and a nonchalant attitude of programmers (I&#8217;m one of the guilty ones). &#8216;Security&#8217; is the one section in a project scope that gets consistently ignored by not only the developers but also management. In defense of myself and other programmers I would have to say that writing secure software is hard work, and with all the pressure from management and clients to get the software delivered, its no wonder that programmers turn a blind eye towards security. But that is surely not an excuse to deliver a product full of security vulnerabilities.<br />
<span id="more-1319"></span><br />
<a target="_blank" href="http://cwe.mitre.org/top25/index.html">CWE/SANS</a> recently released a updated version of their <em>Top 25 Most Dangerous Programming Errors</em> list. The document lists the most common and significant programming errors which can lead to serious software vulnerabilities. The result of collaboration between the <a target="_blank" href="http://www.sans.org/">SANS Institute</a>, <a target="_blank" href="http://cwe.mitre.org/index.html">MITRE</a>, and other top software security experts in the US and Europe, the document can help you narrow down your security fixes to a important few.</p>
<p>According to the Mitre site:</p>
<blockquote><p>The main goal for the Top 25 list is to stop vulnerabilities at the source by educating programmers on how to eliminate all-too-common mistakes before software is even shipped. The list will be a tool for education and awareness that will help programmers to prevent the kinds of vulnerabilities that plague the software industry. Software consumers could use the same list to help them to ask for more secure software. Finally, software managers and CIOs can use the Top 25 list as a measuring stick of progress in their efforts to secure their software.
</p></blockquote>
<p>The 25 vulnerabilities are divided into three main categories: <em>Insecure Interaction Between Components</em>, <em>Risky Resource Management</em> and <em>Porous Defenses</em>, details of which are listed below.</p>
<h4>Insecure Interaction Between Components</h4>
<p>These weaknesses are related to insecure ways in which data is sent and received between separate components, modules, programs, processes, threads, or systems.</p>
<p>    * Improper Input Validation<br />
    * Improper Encoding or Escaping of Output<br />
    * Failure to Preserve SQL Query Structure (&#8216;SQL Injection&#8217;)<br />
    * Failure to Preserve Web Page Structure (&#8216;Cross-site Scripting&#8217;)<br />
    * Improper Sanitization of Special Elements used in an OS Command (&#8216;OS Command Injection&#8217;)<br />
    * Cleartext Transmission of Sensitive Information<br />
    * Cross-Site Request Forgery (CSRF)<br />
    * Race Condition<br />
    * Error Message Information Leak</p>
<h4>Risky Resource Management</h4>
<p>The weaknesses in this category are related to ways in which software does not properly manage the creation, usage, transfer, or destruction of important system resources.</p>
<p>    * Failure to Constrain Operations within the Bounds of a Memory Buffer<br />
    * External Control of Critical State Data<br />
    * External Control of File Name or Path<br />
    * Untrusted Search Path<br />
    * Failure to Control Generation of Code (&#8216;Code Injection&#8217;)<br />
    * Download of Code Without Integrity Check<br />
    * Improper Resource Shutdown or Release<br />
    * Improper Initialization<br />
    * Incorrect Calculation</p>
<h4>Porous Defenses</h4>
<p>The weaknesses in this category are related to defensive techniques that are often misused, abused, or just plain ignored.</p>
<p>    * Improper Access Control (Authorization)<br />
    * Use of a Broken or Risky Cryptographic Algorithm<br />
    * Hard-Coded Password<br />
    * Incorrect Permission Assignment for Critical Resource<br />
    * Use of Insufficiently Random Values<br />
    * Execution with Unnecessary Privileges<br />
    * Client-Side Enforcement of Server-Side Security</p>
<p>The SANS Institute proclaims that the document will have four major impacts on the industry.</p>
<p>    * Software buyers will be able to buy much safer software.<br />
    * Programmers will have tools that consistently measure the security of the software they are writing.<br />
    * Colleges will be able to teach secure coding more confidently.<br />
    * Employers will be able to ensure they have programmers who can write more secure code.</p>
<p>However, it remains to be seen how fast the changes really occurs.</p>
<h4>In practice</h4>
<p>So as a PHP programmer what can you do to bring security into your development process.<br />
The first is to acknowledge that the problem exists.<br />
Second, convince management that spending time on security will be profitable to the company in the long term and will keep them from being sued by clients if a security breach occurs.<br />
Third, get some good books on secure programming. I would personally recommend:<br />
1. <a target="_blank" href="http://www.amazon.com/Pro-PHP-Security-Chris-Snyder/dp/1590595084">Pro PHP Security: by Chris Snyder, Michael Southwell</a><br />
2. <a target="_blank" href="http://www.amazon.com/Essential-PHP-Security-Chris-Shiflett/dp/059600656X/ref=pd_bxgy_b_text_b">Essential PHP Security: by Chris Shiflett</a><br />
3. <a target="_blank" href="http://www.amazon.com/php-architects-Guide-PHP-Security/dp/0973862106/ref=pd_sim_b_9">php|architect&#8217;s Guide to PHP Security: by Ilia Alshanetsky</a><br />
4. <a target="_blank" href="http://www.amazon.com/Web-Security-Testing-Cookbook-Systematic/dp/0596514832/ref=pd_sim_b_15">Web Security Testing Cookbook:  Paco Hope, Ben Walther</a><br />
5. <a target="_blank" href="http://www.amazon.com/Security-Engineering-Building-Dependable-Distributed/dp/0470068523/ref=pd_sim_b_27">Security Engineering:  Ross J. Anderson</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/security/top-25-most-dangerous-programming-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>6 Simple principles of secure website design</title>
		<link>http://www.codediesel.com/security/6-simple-priciples-of-secure-website-design/</link>
		<comments>http://www.codediesel.com/security/6-simple-priciples-of-secure-website-design/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 08:13:18 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=89</guid>
		<description><![CDATA[Simple design usually underlies a successful security mechanism on a web site. Make it more complex than required and the user suffers from a barrage of logins and redirections. Make it too simple and you risk your site being compromised. The following 6 principles draw on ideas of simplicity and restriction. In the following list [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codediesel.com/wp-content/uploads/2008/08/2294144289_a54db90ac5_m1.jpg"><img class="alignleft size-full wp-image-91" style="border:1px solid #c0c0c0;" title="2294144289_a54db90ac5_m1" src="http://www.codediesel.com/wp-content/uploads/2008/08/2294144289_a54db90ac5_m1.jpg" alt="" width="240" height="160" /></a>Simple design usually underlies a successful security mechanism on a web site. Make it more complex than required and the user suffers from a barrage of logins and redirections. Make it too simple and you risk your site being compromised.<br />
The following 6 principles draw on ideas of simplicity and restriction. In the following list the word ‘subject’ can mean program or user and the word ‘object’ can mean a  program, file, url.</p>
<p><strong>1.	Principle of least privilege:<br />
</strong>A subject should be given only those privileges that it needs in order to complete task. The principle of least privilege states that only the minimum access necessary to perform an operation should be granted, and that access should be granted only for the minimum amount of time necessary.</p>
<p><strong>2.	Fail-safe defaults:<br />
</strong>Unless a subject is given explicit access to an object, it should be denied access to that object. Design your sites so that when it fails, it fails in a secure manner. For example when an ATM fails, it should shut down, and not spew money out its slot.</p>
<p>For example take the following code in PHP:</p>

<div class="wp_codebox"><table><tr id="p8911"><td class="code" id="p89code11"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$access</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$IsAccessAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$access</span> <span style="color: #339933;">==</span> ERROR_ACCESS_DENIED<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
<span style="color: #009933; font-style: italic;">// Security check failed.</span>
<span style="color: #009933; font-style: italic;">// Inform user that access is denied. </span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #000000; font-weight: bold;">else</span> 
<span style="color: #009900;">&#123;</span> 
<span style="color: #009933; font-style: italic;">// Security check OK. </span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The code looks fine, but what if the <em>IsAccessAllowed</em> function fails. The default execution path in the above code is to grant access to the user. A better version is show below. Here the default access is set to &#8216;DENIED&#8217;. Only after  <em>IsAccessAllowed</em> is successfully executed and it returns a &#8216;NO_ERROR&#8217; message is the user allowed access.If for any reason the <em>IsAccessAllowed</em> function fails the default action is to deny access.</p>

<div class="wp_codebox"><table><tr id="p8912"><td class="code" id="p89code12"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$access</span> <span style="color: #339933;">=</span> ERROR_ACCESS_DENIED<span style="color: #339933;">;</span> 
<span style="color: #000088;">$access</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$IsAccessAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$access</span> <span style="color: #339933;">==</span> NO_ERROR<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
<span style="color: #009933; font-style: italic;">// Secure check OK. </span>
<span style="color: #009933; font-style: italic;">// Perform task. </span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #000000; font-weight: bold;">else</span> 
<span style="color: #009900;">&#123;</span> 
<span style="color: #009933; font-style: italic;">// Security check failed. </span>
<span style="color: #009933; font-style: italic;">// Inform user that access is denied. </span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>3.	Economy of mechanism:</strong><br />
Security mechanisms should be as simple as possible. Security is like a chain; the weakest link breaks it. Simplicity means fewer links and fewer points of vulnerability.</p>
<p><strong>4.	Complete mediation:</strong><br />
All access to objects be checked to ensure that they are allowed. Every access to every object must be checked for authority.</p>
<p><strong>5.	Open design:</strong><br />
Security of a mechanism should not depend on the secrecy of its design or implementation.</p>
<p><strong>6.	Psychological acceptability:</strong><br />
Security mechanisms should not make the resource more difficult top access than if the security mechanisms were not present. The security mechanism should be designed taking the user in mind. For example; If a user on your website has to set a dozen permissions on his profile page or payment preferences, he will surely give it a miss, thus opening a security hole hackers can exploit.</p>
<p>The details of security mechanism implementation can vary for various web languages like PHP or .NET, but keeping the above principle in mind can go a long way in securing you website.</p>
<p>For more detailed and excellent information you can visit <a title="buildsecurityin.us-cert.gov" href="https://buildsecurityin.us-cert.gov/daisy/bsi/home.html" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/security/6-simple-priciples-of-secure-website-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

