<?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>Adam Palmer, Linux, PHP Programmer, MySQL Developer, Website Security Consultant &#187; Development</title>
	<atom:link href="http://www.adamsinfo.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adamsinfo.com</link>
	<description>Adam Palmer MBCS CITP, Linux, PHP Programmer, MySQL Developer, Website Security Consultant</description>
	<lastBuildDate>Mon, 26 Jul 2010 22:16:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Why test or scan?</title>
		<link>http://www.adamsinfo.com/why-test-or-scan/</link>
		<comments>http://www.adamsinfo.com/why-test-or-scan/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 01:36:29 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security Consultant]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=1058</guid>
		<description><![CDATA[Yesterday, I offered a free website security scan.  Why would you need a scan?  I went into a little detail then, but I&#8217;d like to expand on what I wrote about, that being my offering my services as a PHP programmer.
If you&#8217;re an online merchant, your server needs to be PCI compliant.  [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I offered <a href="http://www.adamsinfo.com/free-website-security-scan/">a free website security scan</a>.  Why would you need a scan?  I went into a little detail then, but I&#8217;d like to expand on what I wrote about, that being my offering my services as a <a href="http://www.adamsinfo.com/">PHP programmer</a>.</p>
<p>If you&#8217;re an online merchant, your server needs to be PCI compliant.  Otherwise, you not only run the risk of being hacked and losing customer data, but you also run the risk of facing major fines.  One fine would be enough to wipe just about any small business out.</p>
<p>New security challenges arise every day.  In fact, they arise every hour, it seems.  Will your site stand up to the challenge?  Will it meet that challenge?  Only by regular security scans will you know.  Even if you&#8217;re not a merchant, you need scans, because I am willing to bet that you don&#8217;t want to be hacked.  All sorts of unsavory things can occur if that happens.</p>
<p>You could lose your databases.  You could lose all data on your server.  Your users&#8217; information could be compromised.  There are many things that could happen, and none of them are pleasant.</p>
<p>So, <a href="http://www.adamsinfo.com/contact-me/">contact me</a> for your free security scan today.  As I wrote earlier, all I ask in return is that you have a sincere intent of using my services.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/why-test-or-scan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The importance of redirects</title>
		<link>http://www.adamsinfo.com/the-importance-of-redirects/</link>
		<comments>http://www.adamsinfo.com/the-importance-of-redirects/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 21:41:18 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security Consultant]]></category>
		<category><![CDATA[301 redirects]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php programmer]]></category>
		<category><![CDATA[search engine]]></category>
		<category><![CDATA[traffic]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=1051</guid>
		<description><![CDATA[Yesterday, I discussed how you can redirect your HTML files to PHP files.  Why is it important to do so?
There are certainly no security concerns involved here, but you probably don&#8217;t want to lose your visitors who may bookmark certain pages, nor do you want to lose search engine traffic, because the HTML links [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I <a href="http://www.adamsinfo.com/redirecting-all-html-files-to-php-files/">discussed how you can</a> redirect your HTML files to PHP files.  Why is it important to do so?</p>
<p>There are certainly no security concerns involved here, but you probably don&#8217;t want to lose your visitors who may bookmark certain pages, nor do you want to lose search engine traffic, because the HTML links will still show up in those engines until they crawl your changes.</p>
<p>That&#8217;s where the 301 redirect comes in.  This is the best sort of redirect to use, because it is search engine friendly.  What it tells search engines is that the page has moved permanently to the forwarding location you provide, which in this case is a PHP file.  Essentially, if you do it this way, the search engines won&#8217;t skip a beat, and you&#8217;ll keep your traffic.  The last thing you want to do is let search engines crawl 404 errors.</p>
<p>If you need help with these sorts of things, or if you need a skilled PHP programmer to help you sort out your conversion, I would be more than happy to take a look at your specific needs, and devise a plan for you.  This includes making sure that your PHP code and your setup is secure, as PHP is a valuable tool, but a potential security risk if not handled correctly.</p>
<p>My rates are reasonable, and I offer a wealth of experience that can benefit you.  Simply <a href="http://www.adamsinfo.com/contact-me">get in touch with me</a> for a custom quote!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/the-importance-of-redirects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A PHP programmer indeed</title>
		<link>http://www.adamsinfo.com/a-php-programmer-indeed/</link>
		<comments>http://www.adamsinfo.com/a-php-programmer-indeed/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 00:55:09 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security Consultant]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[php programmer]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[website security consultant]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=1045</guid>
		<description><![CDATA[You may be browsing through my site, or maybe you came here because you&#8217;re looking for a PHP programmer.  Allow me to introduce myself.  I am Adam Palmer, and I&#8217;m a freelance website security consultant, developer, and, of course, a PHP programmer.  I&#8217;m willing and able to do most any web, Linux, [...]]]></description>
			<content:encoded><![CDATA[<p>You may be browsing through my site, or maybe you came here because you&#8217;re looking for a PHP programmer.  Allow me to introduce myself.  I am Adam Palmer, and I&#8217;m a freelance website security consultant, developer, and, of course, a PHP programmer.  I&#8217;m willing and able to do most any web, Linux, or hosting-related project.</p>
<p>If you have something along those lines that needs to be done, <a href="http://www.adamsinfo.com/contact-me">simply contact me</a>, and we can discuss your needs in greater detail.</p>
<p>In addition to doing this sort of work, I run <a href="http://www.apnicsolutions.com">APNIC Solutions, Ltd.</a>, which is a leader in network and business integration.  You can be confident that when you hire me for your PHP, web, or other needs, you are getting a competent, skilled industry leader who will do a smashing job for a reasonable fee.</p>
<p>Feel free to browse through my blog and read my articles on a variety of PHP and security topics.  Then, get in touch with me to see what I can do for you!  If all you need is a consultant to point you in the right direction and help you get to to the finish line, I would be more than happy and honoured to be that person.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/a-php-programmer-indeed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another PHP tip</title>
		<link>http://www.adamsinfo.com/another-php-tip/</link>
		<comments>http://www.adamsinfo.com/another-php-tip/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 22:25:32 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php programmer]]></category>
		<category><![CDATA[php programmer resume]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[trust]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=1041</guid>
		<description><![CDATA[While it&#8217;s all well and good to spend considerable time securing your PHP applications, there is something else that you can do, or rather not do.  As a PHP programmer, I see people do one alarming thing: they download and install PHP applications from questionable sources.
While there are a lot of honourable programmers who [...]]]></description>
			<content:encoded><![CDATA[<p>While it&#8217;s all well and good to spend considerable time securing your PHP applications, there is something else that you can do, or rather not do.  As a PHP programmer, I see people do one alarming thing: they download and install PHP applications from questionable sources.</p>
<p>While there are a lot of honourable programmers who offer their scripts for free, there are plenty of hackers who enjoy deploying applications that cause harm to others.  I <a href="http://www.adamsinfo.com/keeping-your-site-secure/">discussed this</a> earlier, but it bears repeating: trust your source.  Know your source.<br />
<span id="more-1041"></span><br />
This includes scripts that people offer for download on forums you may visit.  There are plenty of good people out there who merely want to share their scripts and help, but your server&#8217;s security is very important.</p>
<p>A hacker doesn&#8217;t even need to gain access to your server.  He or she can write a script and gain satisfaction from knowing their work is causing damage around the world.</p>
<p>Just be careful.  Download from known and trusted sources, or if you have a script you&#8217;re unsure of, run it by someone you trust.  You can even contact me, and I&#8217;d be more than happy to share my resume, and show you what I can do to help you secure your scripts and keep your server safe.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/another-php-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securing PHPMyAdmin and SQL</title>
		<link>http://www.adamsinfo.com/securing-phpmyadmin-sql/</link>
		<comments>http://www.adamsinfo.com/securing-phpmyadmin-sql/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 21:40:09 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[attacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php programmer resume]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[website security consultant]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=1039</guid>
		<description><![CDATA[PHP is of course a valuable tool, and PHPMyAdmin is an equally valuable asset for those that don&#8217;t like command line administration.  The problem is that because it&#8217;s a valuable tool, it&#8217;s a security exposure.  As a website security consultant, I see the problem often: people don&#8217;t secure the one thing that, if [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is of course a valuable tool, and PHPMyAdmin is an equally valuable asset for those that don&#8217;t like command line administration.  The problem is that because it&#8217;s a valuable tool, it&#8217;s a security exposure.  As a website security consultant, I see the problem often: people don&#8217;t secure the one thing that, if accessed by a malicious party, can give carte blanche for destruction.</p>
<p>One simple way to secure your installation is to slightly modify your config.inc.php file:</p>
<p>Look for this line:</p>
<p>$cfg['Servers'][$i]['auth_type'] = &#8216;config&#8217;;</p>
<p>Change &#8220;config&#8221; to &#8220;http&#8221;.  By doing this, you will require that the database information (username and password) be entered  prior to accessing PHPMyAdmin.  Of course, this only addresses attacks over the web.  If someone tries to remotely connect to your database and knows the root password, or the credentials for any of your database, then you&#8217;re still vulnerable.</p>
<p>One way to address the security of your config.inc.php file is to <a href="http://www.adamsinfo.com/an-easy-way-to-reduce-attacks/">secure the directory</a> that it&#8217;s stored in.  This is especially important if you should be on a shared server.</p>
<p>Of course, there is still the matter of your SQL port, 3306, being open to remote attacks.  The solution to this problem can be found in the /etc/my.cnf file.</p>
<p>You need to add this line to make it so that only your server can connect to the SQL server.</p>
<p>Ensure that it&#8217;s under the &#8220;[mysqld]&#8221; section:</p>
<p>bind-address = 127.0.0.1</p>
<p>This sets it so that the SQL daemon only listens for connections locally, i.e. on your server.  Anyone who tries to connect remotely will be denied.  Now, the argument could be made that you could also try to add &#8220;skip-networking&#8221; to your my.cnf file, and then specify the path to your socket file, but you still need a way to administer your SQL, preferably via SSH.  By adding the &#8220;bind-address&#8221; command, you can do just that.</p>
<p>The name of the game is security, and assumption.  You have to assume that everyone&#8217;s out to attack you.  If you think like that, you&#8217;ll narrow down all the ports that are exposed, and secure your server.  Your SQL server is, like your DNS server, vital.  It most likely powers your site.  If the database is attacked, the damage can be considerable.  Do understand that if a hacker is intent enough, they will find a way in, but by making it as difficult as possible, you reduce the chances of that happening.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/securing-phpmyadmin-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validate your input</title>
		<link>http://www.adamsinfo.com/validate-your-input/</link>
		<comments>http://www.adamsinfo.com/validate-your-input/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 21:25:12 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[injection]]></category>
		<category><![CDATA[malicious code]]></category>
		<category><![CDATA[php programer]]></category>
		<category><![CDATA[php programmer resume]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=1037</guid>
		<description><![CDATA[An important thing to consider when accepting input from users is validation.  When PHP is used, powerful functions can be performed.  The problem is that it can also do powerful and bad things if a malicious user is entering data which isn&#8217;t validated.
Consider this: you accept input asking for a month or year. [...]]]></description>
			<content:encoded><![CDATA[<p>An important thing to consider when accepting input from users is validation.  When PHP is used, powerful functions can be performed.  The problem is that it can also do powerful and bad things if a malicious user is entering data which isn&#8217;t validated.</p>
<p>Consider this: you accept input asking for a month or year.  The problem is that a user decides to enter &#8220;&#8221;;rm -rf *&#8221; after the year, and in so doing could cause the deletion of your whole website.  Obviously, this is not a good thing, so what to do?  Data validation is the answer.  As the name suggests, it validates or verifies data, ensuring that it complies to form.<br />
<span id="more-1037"></span><br />
In other words, when you validate data, you ensure that a user entered numbers for a year, and not a malicious command as shown above.  Unfortunately, many webmasters have fallen victim to this, all because they didn&#8217;t tighten security on their server.</p>
<p>One solution would be to enter data in this manner:</p>
<p>$month = $_GET['month'];<br />
$year = $_GET['year'];</p>
<p>if (!preg_match(&#8221;/^[0-9]{1,2}$/&#8221;, $month)) die(&#8221;Invalid entry.  Please try again.&#8221;);<br />
if (!preg_match(&#8221;/^[0-9]{4}$/&#8221;, $year)) die(&#8221;Invalid entry.  Please try again.&#8221;);</p>
<p>exec(&#8221;cal $month $year&#8221;, $result);<br />
print &#8220;
<pre>";
foreach ($result as $r) { print "$r<BR>"; }
print "</pre>
<p>&#8220;;</p>
<p>What this code does is this: it allows your user to enter a month and a year, say for a credit card or date of birth, but it also double checks the data, ensuring that it is in fact numeric data that a user entered, and not code that could cause you hours of grief.  </p>
<p>Of course, there is more extensive code you can write which will validate further, but this data pertains strictly to the security of your server.  You can, of course, add code that will ensure that a year is between, say 1900 and 2020, and that a month is between 1 and 12.</p>
<p>As an administrator or webmaster, you need to consider all data that a user enters questionable.  By using this mindset, you&#8217;ll be in a position to prevent yourself from being vulnerable to malicious injection attacks.  Too often, a webmaster has chosen not to take security measures because he or she assumed that no one would try something so awful as to delete someone&#8217;s data.  As we see every day, however, there are people who think nothing of ruining peoples&#8217; hard work, data, and electronic property.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/validate-your-input/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The importance of secure PHP code</title>
		<link>http://www.adamsinfo.com/the-importance-of-secure-php-code/</link>
		<comments>http://www.adamsinfo.com/the-importance-of-secure-php-code/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 14:08:26 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[compromised]]></category>
		<category><![CDATA[php programmer]]></category>
		<category><![CDATA[resume]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=1035</guid>
		<description><![CDATA[In recent days, I&#8217;ve talked about the importance of server hardening and security, but there&#8217;s another aspect of the integrity of your server that must not be ignored: PHP code.
If you don&#8217;t have secure PHP code, you may find yourself the victim of numerous type of attacks, including SQL injection attacks, which as the name [...]]]></description>
			<content:encoded><![CDATA[<p>In recent days, I&#8217;ve talked about the importance of server hardening and security, but there&#8217;s another aspect of the integrity of your server that must not be ignored: PHP code.</p>
<p>If you don&#8217;t have secure PHP code, you may find yourself the victim of numerous type of attacks, including SQL injection attacks, which as the name suggest, goes directly after your database, which in most cases is the very heart of your website or application.<br />
<span id="more-1035"></span><br />
Sometimes, the most basic adjustments will go along way.  One example is this variable:</p>
<p>register_globals</p>
<p>If you look in your php.ini file, and find that this variable is enabled, you may be putting yourself at risk, for all anyone has to do is add &#8220;?authorized=1&#8243; to a URL on your site, and they will then gain access to sensitive information that you likely don&#8217;t want the average user to see.  </p>
<p>The best solution here is to simply set register_globals to &#8220;off&#8221;.</p>
<p>Another mistake that many people make is that they fail to suppress PHP errors.  When a PHP error occurs, and error reporting is fully enabled, a user can see a lot of information about your site, including exact paths.  Of course, you don&#8217;t want this information to be readily available, so it would be a wise decision to suppress the errors so that they do not display in the web browser.</p>
<p>You actually need not change the error_reporting variable itself, because you still want to be able to see errors as the administrator.  You just don&#8217;t the whole world to see them, too.  To accomplish this goal, simply look for the &#8220;display_errors&#8221; variable, and set it to &#8220;Off&#8221;.  </p>
<p>You will also want to set the &#8220;log_errors&#8221; variable to &#8220;ON&#8221;, so that the errors show up in your error log.  If you turn both logging and display off, the potential exists for errors to still display, because the errors do need to be reported somewhere.  But by confining it to the error_log, you and anyone else you grant administrative powers to will be the only ones who see them.</p>
<p>By doing this, you will prevent error messages from showing up on a user&#8217;s web browser, potentially giving them a detailed road map to the compromising of your server.</p>
<p>Also, make sure that there are no settings for error reporting in your .htaccess file, because these settings could override your default php.ini settings for that particular website.</p>
<p>These are just two examples of easy ways that you can secure PHP.  There are, of course, many others.  Though these solutions are simple, they go a long way, and the time invested in making these adjustments will pay dividends in the form of a secure server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/the-importance-of-secure-php-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Developer &#8211; Base64</title>
		<link>http://www.adamsinfo.com/php-developer-base64/</link>
		<comments>http://www.adamsinfo.com/php-developer-base64/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 18:07:30 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[base64]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=876</guid>
		<description><![CDATA[Base64 is a type of encoding (NOT encryption). Essentially, you can take any binary data and encode it into one of 64 characters for more information on the encoding process and how this is done, visit http://en.wikipedia.org/wiki/Base64.
It is useful for a variety of things, specifically encoding non standard characters that may not be safe to [...]]]></description>
			<content:encoded><![CDATA[<p>Base64 is a type of encoding (NOT encryption). Essentially, you can take any binary data and encode it into one of 64 characters for more information on the encoding process and how this is done, visit <a href="http://en.wikipedia.org/wiki/Base64" target="_blank">http://en.wikipedia.org/wiki/Base64</a>.</p>
<p>It is useful for a variety of things, specifically encoding non standard characters that may not be safe to pass around such as in a browser address bar or in a plaintext email..</p>
<p>Here&#8217;s one example..</p>
<p>&lt;?php<br />
$obj = new stdClass();<br />
$obj-&gt;a = &#8220;test&#8221;;<br />
$obj-&gt;b = &#8220;string&#8221;;<br />
$obj-&gt;c = 12345;<br />
$output = base64_encode(serialize($obj));<br />
echo $output;</p>
<p>?&gt;</p>
<p>This returns &#8216;Tzo4OiJzdGRDbGFzcyI6Mzp7czoxOiJhIjtzOjQ6InRlc3QiO3M6MToiYiI7<br />
czo2OiJzdHJpbmciO3M6MToiYyI7aToxMjM0NTt9&#8242;</p>
<p>We could now pass this as an HTTP safe string between pages; decoding using $v = unserialize(base64_decode());</p>
<p>This is obviously not an optimal way of storing or passing this example data between various pages however is one example of how base64 encoding can be used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-developer-base64/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP, MySQL and memcached</title>
		<link>http://www.adamsinfo.com/php-mysql-and-memcached/</link>
		<comments>http://www.adamsinfo.com/php-mysql-and-memcached/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 17:55:41 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[memcached]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=956</guid>
		<description><![CDATA[According to memcached is a distributed object memory caching system. It can be used to set and get data by keys by any application that supports sockets.
As a website security consultant I advise you to ensure that your memcache server runs on 127.0.0.1 only and that you secure your server. Anyone with access to the [...]]]></description>
			<content:encoded><![CDATA[<p>According to memcached is a distributed object memory caching system. It can be used to set and get data by keys by any application that supports sockets.</p>
<p>As a <a href="http://www.adamsinfo.com/website-security-consultant">website security consultant</a> I advise you to ensure that your memcache server runs on 127.0.0.1 only and that you secure your server. Anyone with access to the server can telnet to the server&#8217;s local interface and get/set your memcache data. </p>
<p>I&#8217;ve used memcached for a number of PHP/MySQL projects, where I want greater cache control on database queries, than just relying on MySQL&#8217;s inbuilt caching abilities.</p>
<p>Now, whilst memcached should not be used to mask bad database design and optimization, or badly written SQL queries, it can help dramatically with queries that simply take a long time and have already been optimized as far as possible.</p>
<p>Assume that you had a simple database query wrapper:<br />
<span id="more-956"></span><br />
function db_getrows($query)<br />
{</p>
<p style="padding-left: 30px;">$rows = Array();<br />
$resource = mysql_query($query);<br />
while ($rows[] = mysql_fetch_object($resource))<br />
{</p>
<p style="padding-left: 60px;">//do nothing</p>
<p style="padding-left: 30px;">}<br />
return $rows;</p>
<p>}</p>
<p>If you have no idea what queries are going to get passed to this, but simply want to cache all SELECT output, then modify as follows:</p>
<p>function db_getrows($query)<br />
{</p>
<p style="padding-left: 30px;">$rows = Array();<br />
//Get the MD5 hash of the query, which we can use to identify it:<br />
$hash = md5($query);<br />
$memcache_obj = memcache_connect(&#8221;localhost&#8221;, 11211); //connect to memcached<br />
$mem_get = memcache_get($memcache_obj, $hash); //If we had this query key stored in memcache, $mem_get will now contain the data, otherwise, it will be empty.</p>
<p style="padding-left: 30px;">if (empty($mem_get))<br />
{</p>
<p style="padding-left: 60px;">$resource = mysql_query($query);<br />
while ($rows[] = mysql_fetch_object($resource))<br />
{</p>
<p style="padding-left: 90px;">//do nothing</p>
<p style="padding-left: 60px;">}<br />
memcache_add($memcache_obj, $hash, serialize($rows), false, (60*60)); //add it to memcache for next time, have it expire in 1 hour (60*60 seconds)</p>
<p style="padding-left: 30px;">} else {</p>
<p style="padding-left: 60px;">$rows = unserialize($mem_get);</p>
<p style="padding-left: 30px;">}<br />
return $rows;</p>
<p>}</p>
<p>What will happen now, is that when a query is provided, we take the <a href="http://www.adamsinfo.com/creating-an-md5-on-linux-with-md5sum/">MD5 sum</a> of that query. We then check to see if we have that query response in memcache already. If so, great, unserialize it and return it. If not, run the query, get the data, and add it to memcache with an expiry time of 1 hour.</p>
<p>Any queries to memcache will of course bypass the database alltogether therefore alleviating the load. Your only consideration is what to cache and the expiry time. If you cache the output of a SELECT query on say, the number of posts on your forum, it may not just keep that out of date for an hour, but could infact cause erroneous data to be inserted by your forum into your database. In that case, you can take a look through the code and find any instances where your forum post count may be updated, and add memcache_delete($memcache_obj, &#8216;key_to_delete&#8217;, 10); which will automatically delete &#8216;key_to_delete&#8217; after 10 seconds.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-mysql-and-memcached/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; Running Processes</title>
		<link>http://www.adamsinfo.com/mysql-running-processes/</link>
		<comments>http://www.adamsinfo.com/mysql-running-processes/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 02:12:28 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[processes]]></category>
		<category><![CDATA[processlist]]></category>
		<category><![CDATA[show]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=982</guid>
		<description><![CDATA[Showing running processes is easy, just log in to the MySQL command line and issue &#8216;SHOW PROCESSLIST;&#8217;
mysql> SHOW PROCESSLIST;
+&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+
&#124; Id       &#124; User &#124; Host                    &#124; db     [...]]]></description>
			<content:encoded><![CDATA[<p>Showing running processes is easy, just log in to the MySQL command line and issue &#8216;SHOW PROCESSLIST;&#8217;<br />
mysql> SHOW PROCESSLIST;<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| Id       | User | Host                    | db         | Command | Time | State    | Info                                                                                          |<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| 66041116 | root | localhost               | NULL       | Query   |    0 | NULL     | SHOW PROCESSLIST                                                                              |<br />
| 66042322 | sql  | www.adamsinfo.com:57281 | websonline | Query   |    1 | Updating | UPDATE `video_tags` SET `quantity` = &#8216;27&#8242; WHERE CONVERT( `tag` USING utf8 ) = &#8217;sport&#8217; LIMIT 1 |<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
2 rows in set (0.00 sec)
</pre>
<p>You can also use 'SHOW' to display a wide range of information: http://dev.mysql.com/doc/refman/5.0/en/show.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/mysql-running-processes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP and curl</title>
		<link>http://www.adamsinfo.com/php-and-curl/</link>
		<comments>http://www.adamsinfo.com/php-and-curl/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 13:05:45 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=962</guid>
		<description><![CDATA[Using curl with PHP is incredibly easy. Firstly you&#8217;ll need to make sure that you have the PHP curl library installed on your system. On Debian, this is as easy as apt-get install php5-curl
Now you can try the following:
&#60;?php
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, &#8220;http://www.google.com/&#8221;);
curl_setopt($handle, CURLOPT_HEADER, 0);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($handle);
curl_close($handle);
print_r($output);
?&#62;
You can also check http://uk.php.net/manual/en/function.curl-setopt.php to take [...]]]></description>
			<content:encoded><![CDATA[<p>Using curl with PHP is incredibly easy. Firstly you&#8217;ll need to make sure that you have the PHP curl library installed on your system. On Debian, this is as easy as <strong>apt-get install php5-curl</strong></p>
<p>Now you can try the following:</p>
<p>&lt;?php<br />
$handle = curl_init();<br />
curl_setopt($handle, CURLOPT_URL, &#8220;http://www.google.com/&#8221;);<br />
curl_setopt($handle, CURLOPT_HEADER, 0);<br />
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);<br />
$output = curl_exec($handle);<br />
curl_close($handle);</p>
<p>print_r($output);<br />
?&gt;</p>
<p>You can also check <a href="http://uk.php.net/manual/en/function.curl-setopt.php">http://uk.php.net/manual/en/function.curl-setopt.php</a> to take a look at the other options that curl_setopt can take.</p>
<p>curl can also post data to the remote server via POST or GET and also has the ability to save and retransmit cookies.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-and-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Communicating with the Twitter API via curl</title>
		<link>http://www.adamsinfo.com/communicating-with-the-twitter-api-via-curl/</link>
		<comments>http://www.adamsinfo.com/communicating-with-the-twitter-api-via-curl/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 18:35:01 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=958</guid>
		<description><![CDATA[Twitter provides an extensive API that allows developers to write interactive applications. Utilizing this API is deceptively simple, and here is an example with curl:
curl -u username:password http://api.twitter.com/1/statuses/friends_timeline.xml
Which will get the statuses of all your friends. You can of course use PHP&#8217;s curl library just as easily as the command line, and my next post [...]]]></description>
			<content:encoded><![CDATA[<p>Twitter provides an extensive API that allows developers to write interactive applications. Utilizing this API is deceptively simple, and here is an example with curl:</p>
<p>curl -u username:password http://api.twitter.com/1/statuses/friends_timeline.xml</p>
<p>Which will get the statuses of all your friends. You can of course use PHP&#8217;s curl library just as easily as the command line, and my next post will focus on using php5-curl</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/communicating-with-the-twitter-api-via-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Website Security Scan</title>
		<link>http://www.adamsinfo.com/website-security-scan/</link>
		<comments>http://www.adamsinfo.com/website-security-scan/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 00:54:13 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security Consultant]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[cross site scripting]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[mod_security]]></category>
		<category><![CDATA[php security]]></category>
		<category><![CDATA[rate limit]]></category>
		<category><![CDATA[restrict limit]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[sniffing]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[website security scan]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=912</guid>
		<description><![CDATA[Websites get hacked every day, customers details taken, and it&#8217;s usually REALLY EASY to do. As a security consultant,  I often get a call after a Google search turns up with my details as the guy to contact when this happens.
Shameless plug: Why not contact me BEFORE this happens for a FREE basic web scan.
Shameless [...]]]></description>
			<content:encoded><![CDATA[<p>Websites get hacked every day, customers details taken, and it&#8217;s usually REALLY EASY to do. As a <a href="http://www.adamsinfo.com/security-consultant/">security consultant</a>,  I often get a call after a Google search turns up with my details as the guy to contact when this happens.</p>
<p><strong>Shameless plug: </strong>Why not <a href="http://www.adamsinfo.com/contact-me/">contact me</a> BEFORE this happens for a FREE basic web scan.</p>
<p>Shameless plug over, why not consider some of the things that can be done to help prevent a website breach..<br />
<span id="more-912"></span></p>
<p>First, concentrate on the box and LAMP environment as a whole. Here&#8217;s a top 10:</p>
<ol></ol>
<ul>
<li>Restrict or disable .htaccess type files. A lot of sites these days allow uploading of files, in whatever form that may come. Often, the code can be tricked into allowing an attacker to upload htaccess files to certain directories which could allow for scripts to be executed, or visitors to be redirected.</li>
</ul>
<ol></ol>
<ul>
<li>Check your apache config, after tightening up/disabling htaccess, disabling cgi directories you might not need, and modifying limits.</li>
</ul>
<ol></ol>
<ul>
<li>Consider mod_security</li>
</ul>
<ol></ol>
<ul>
<li>Check your apache, php, mysql and related modules are up to date</li>
</ul>
<ol></ol>
<ul>
<li>Firewall mysql externally and any other services that should not be accessed directly from the outside or are not necessary.</li>
</ul>
<ol></ol>
<ul>
<li>Check your list of mysql users and make sure you only have the necessary privileges assigned to the various users.</li>
</ul>
<ol></ol>
<ul>
<li>It&#8217;s common to find users on their own webservers connecting to mysql from their web code as the root user. Don&#8217;t do it. Create a user account for that particular site/database and assign it the tightest privileges. Do not connect to mysql as root unless necessary.</li>
</ul>
<ol></ol>
<ul>
<li>Take multi day backups of database, code AND logs.</li>
</ul>
<ol></ol>
<ul>
<li>Check the machine for word readable/writable directories.</li>
</ul>
<ol></ol>
<ul>
<li>Restrict limits on hits/sec from IPs</li>
</ul>
<ol></ol>
<p>Next, look to your web code, here&#8217;s a top 5:</p>
<ol></ol>
<ul>
<li>Look for <a href="http://www.adamsinfo.com/security-consultant-php-developer-sql-injection-attacks/">SQL Injection</a> opportunities. SQL Injection is NOT just prevented with escaping incoming strings..</li>
</ul>
<ol></ol>
<ul>
<li>Check all input areas for XSS (Cross Site Scripting)</li>
</ul>
<ol></ol>
<ul>
<li>See my <a href="../php-security/">PHP Security</a> post</li>
</ul>
<ol></ol>
<ul>
<li>Session ID Protection &#8211; can users overwrite cookie/session variables that you have set and taken for granted the fact that they shouldn&#8217;t be changed by the user? This is easy to do overwrite/exploit with &#8216;curl&#8217; or &#8216;wget&#8217;</li>
</ul>
<ol></ol>
<ul>
<li>How are you handling user data input? <a href="some-simple-filtering-and-sniffing-with-tcpdump/">Sniffing</a> plaintext HTTP or plaintext anything for that matter is very simple. All sensitive data should be sent over HTTPS. On that matter, are you storing the data safely afterwards?</li>
</ul>
<ol></ol>
<p>Anything to add to this list? Please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/website-security-scan/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Embedded Linux Programmer</title>
		<link>http://www.adamsinfo.com/embedded-linux-programmer/</link>
		<comments>http://www.adamsinfo.com/embedded-linux-programmer/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 20:13:13 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[assembler]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[mips]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=799</guid>
		<description><![CDATA[As an embedded linux programmer, I&#8217;ve had the opportunity to work on a number of different platforms, MIPS being one of my favorites.
There are a few general limitations that you&#8217;ll find. You have limited CPU power available, you have very little RAM available, and for more advanced operations and optimizations, your CPU will generally have [...]]]></description>
			<content:encoded><![CDATA[<p>As an embedded linux programmer, I&#8217;ve had the opportunity to work on a number of different platforms, MIPS being one of my favorites.</p>
<p>There are a few general limitations that you&#8217;ll find. You have limited CPU power available, you have very little RAM available, and for more advanced operations and optimizations, your CPU will generally have a limited function set.</p>
<p>The usual good programming practices apply, but are of much greater importance. Specifically, don&#8217;t allocate memory that you don&#8217;t need, and dont put the CPU under undue stress with unnecessary or badly optimized loops. Taking C syntax and some pseudo code;<br />
<span id="more-799"></span><br />
char *myvar = malloc(10240);<br />
strcpy(myvar, somevar);<br />
&#8230;</p>
<p>Where somevar has previously been limited to say 16 bytes of data, why just allocate an arbitrary large number (10KB) to myval?</p>
<p>Here&#8217;s another:</p>
<p>int ctr = 0;<br />
int maxlen = 0;<br />
for (ctr = 0; ctr &lt; get_count(data); ctr++) { &#8230; }</p>
<p>Although this looks nice and tidy, why are we calling get_count to get the number of records each time the loop runs when it will never change?</p>
<p>int data_count = get_count(data);<br />
for (ctr = 0; ctr &lt; data_count; ctr++) { &#8230; }</p>
<p>makes much more sense.</p>
<p>Years ago, there was also a lot of manual assembler optimization that you could do before compiling. A popular one was replacing &#8220;movl %eaX, 0&#8243; with &#8220;xorl %eax %eax&#8221; as the exclusive or result of two of the same value will be 0 and requires less processor time than the movl operation. Now, not only can most of this be done for you by passing the -OX flag to gcc, but a loop of 1 million movl&#8217;s took no more time than 1 million xorl&#8217;s on my processor, and I&#8217;m guessing the processor deals with this for you now anyway. Today, if you&#8217;re on a nonstandard platform and you&#8217;ve got the information that certain instructions are favored over others on your target, you&#8217;d be able to better optimize the assembler code before compile time.</p>
<p>The main thing to remember, is that sloppy programming that would have gone unnoticed on your super powerful CPU will bring your embedded application to a halt.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/embedded-linux-programmer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Security</title>
		<link>http://www.adamsinfo.com/php-security/</link>
		<comments>http://www.adamsinfo.com/php-security/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 20:43:35 +0000</pubDate>
		<dc:creator>Adam Palmer</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[cross site scripting]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[error reporting]]></category>
		<category><![CDATA[magic quotes]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql_real_escape_string]]></category>
		<category><![CDATA[php security]]></category>
		<category><![CDATA[safe mode]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.adamsinfo.com/?p=914</guid>
		<description><![CDATA[As a PHP programmer, there are a couple of things you can do quickly and easily to increase the security of your PHP code installation.
Look into PHP&#8217;s &#8220;safe mode&#8221; feature, ESPECIALLY if you&#8217;re running a webserver that takes the general public can upload scripts to. Here you&#8217;ll find a list of the functions disabled or [...]]]></description>
			<content:encoded><![CDATA[<p>As a PHP programmer, there are a couple of things you can do quickly and easily to increase the security of your PHP code installation.</p>
<p>Look into PHP&#8217;s &#8220;safe mode&#8221; feature, ESPECIALLY if you&#8217;re running a webserver that takes the general public can upload scripts to. <a href="http://www.php.net/manual/en/features.safe-mode.functions.php" target="_blank">Here</a> you&#8217;ll find a list of the functions disabled or restricted by safe mode. It is not strictly PHP&#8217;s job to restrict these types of functions, however unless you really know what you&#8217;re doing, the list of functions restricted by safemode is a good starting point for building secure applications. These are generally functions that allow file and directory manipulation, and socket manipulation. If it&#8217;s not possible within your environment to disable them all, disable as many of these functions as possible.</p>
<p>Although not that common, if I&#8217;m writing an application that heavily relies on functions that manipulate directories or sockets, I&#8217;ll prefer to create a C daemon or similar to handle this side of things and simply use PHP to communicate with it.<span id="more-914"></span><br />
Within your code, do not ever assume any type of input given by a user or with the possibility of being manipulated by a user is safe. Take the following example:</p>
<p>readfile.php?file=&#8230;<br />
&lt;?php<br />
$fh = fopen($_GET['file'], &#8220;r&#8221;);<br />
&#8230;<br />
?&gt;</p>
<p>The attacker can specify ?file=/etc/passwd or anything else for that matter readable by the web user. Instead:</p>
<p>readfile.php?file_id=1<br />
&lt;?php<br />
switch($_GET['file_id'])<br />
{<br />
case &#8220;1&#8243;:<br />
$filename=&#8221;/tmp/myfile&#8221;;<br />
&#8230;<br />
}</p>
<p>Next, make sure register_globals is turned OFF in PHP&#8217;s config file. In all newer versions of PHP this is already done. register_globals automatically creates a variable called $username from a page called with page.php?username=adam. With register_globals off, this is only accessible via $_GET['username'] or $_REQUEST['username'].</p>
<p>This means that I could call page.php?user_id=1&amp;username=admin. Your code should accomodate register_globals being turned on, and automatically check for this kind of variable poisoning however this is often overlooked.</p>
<p>Magic Quotes is a depreciated feature of PHP helping beginners write more secure code. All incoming input would automatically have the quotes escaped thus preventing <a href="http://www.adamsinfo.com/security-consultant-php-developer-sql-injection-attacks/">SQL Injection</a>. More advanced users that know what they&#8217;re doing can find this annoying, as it is not strictly PHP&#8217;s job to interfere with the input variables like this. Instead you should escape all input yourself with addslashes() or mysql_real_escape_string()</p>
<p>PHP error reporting is another important issue to consider. By default, any warnings and errors are printed out to the user. This often gives away directory paths, filenames, variables and all sorts of other information about the server and the script that should not be printed out to an anonymous user. <a href="http://uk2.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting" target="_blank">Turn off error reporting</a> to the screen and instead dump any errors to a log file an perhaps trigger an email to an admin.</p>
<p>These are just a few basic things to keep in mind to get started. User input can come in a variety of formats, and not just via the variables $_GET, $_SESSION, etc, etc. XSS (Cross Site Scripting) is another common attack method and something that will be covered in future articles.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamsinfo.com/php-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
