<?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>Web Cash &#187; database</title>
	<atom:link href="http://www.earn-web-cash.com/tag/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.earn-web-cash.com</link>
	<description>Writing, Designing, and Making Money Online</description>
	<lastBuildDate>Sun, 04 Dec 2011 22:52:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Exploring WordPress &#8211; Database Structure Explained</title>
		<link>http://www.earn-web-cash.com/2008/02/03/wordpress-database-structure/</link>
		<comments>http://www.earn-web-cash.com/2008/02/03/wordpress-database-structure/#comments</comments>
		<pubDate>Sun, 03 Feb 2008 15:50:54 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Sundry Musings]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[structure]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/03/wordpress-database-structure/</guid>
		<description><![CDATA[While reading some forums this morning, I came upon an interesting question.  Where is the category information stored in the Wordpress database?

I opened up phpmyadmin, expecting to see a "categories" table.  No dice.  After a few minutes I figured it out - and I decided it might be a good idea to explain how the Wordpress database is structured.]]></description>
			<content:encoded><![CDATA[<p>While reading some forums this morning, I came upon an interesting question.  Where is the category information stored in the WordPress database?</p>
<p>I opened up phpmyadmin, expecting to see a &#8220;categories&#8221; table.  No dice.  After a few minutes I figured it out &#8211; and I decided it might be a good idea to explain how the WordPress database is structured.<br />
<span id="more-97"></span><br />
When I first opened the database, I was impressed with its size.  It&#8217;s made up of only ten tables.  The other CMS I&#8217;ve used (CMS Made Simple) uses dozens of tables &#8211; so this seemed pretty compact.</p>
<p>Part of how this is done is that things are compressed into the pre-existing tables, rather than given their own tables.  As a result you&#8217;ve got a more compact, more efficient database structure &#8211; but not necessarily the most intuitive structure.</p>
<p><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/02/wordpress-database.png' title='Wordpress Database Structure'><img class="alignright" src='http://www.earn-web-cash.com/wp-content/uploads/2008/02/wordpress-database.thumbnail.png' alt='Wordpress Database Structure' /></a>To the right, you&#8217;ll see an map of the basic database structure.  In the middle is the most important table &#8211; wp_posts.</p>
<h5>Post Information &#8211; wp_posts</h5>
<p>This is the heart and sole of your WordPress blog.  It contains the basic information about each post and this is how other information is linked to your posts.</p>
<p>There is a lot of information here, but the major fields are ID, post_content, and post_title.  The ID is used to link your post to other fields (like comments), and the content and title fields make up the actual post.</p>
<p>That&#8217;s what is read and displayed for the user to read.</p>
<h5>Comments &#8211; wp_comments</h5>
<p>This table is connected to the wp_posts table, and it contains all of the comment and trackback information for your blog.</p>
<p>Each comment has a &#8220;comment_post_ID&#8221; field &#8211; which matches up with the individual ID of the post it is attached to.  There are a number of other fields that contain the comment data &#8211; like comment_author, comment_author_url, and comment_content.</p>
<h5>Category and Tag Information &#8211; wp_terms</h5>
<p>The original question was, &#8220;Where is the category information stored?&#8221;</p>
<p>This used to be in a &#8220;category&#8221; field in the wp_posts table.  However, a more efficient way to do this was to create a new table with all the category information and a third table to link a post with a category &#8211; since each post can have multiple categories.</p>
<p>Each category and tag is defined in the wp_terms field.  This includes the name, an id, and a description.  In the wp_terms_taxonomy field, each &#8220;term&#8221; is defined as either a tag or a category.</p>
<p>Then, the wp_terms_relationships includes two numbers &#8211; a term id and a post id.  By grabbing every term that uses a post&#8217;s id, WordPress can immediately identify all of the appropriate categories and tags to use.</p>
<p>For performance sake (but not necessarily readability), the tags and categories have been made synonymous in the database.  They&#8217;re all &#8220;terms&#8221; &#8211; which cuts down on the number of queries WordPress needs to make to build a page.</p>
<h5>Non-sequitors &#8211; wp_links, wp_users, and wp_options</h5>
<p>The last few tables are non-sequitors.  They aren&#8217;t attached to the wp_posts table, and they define random things about your blog.</p>
<p>For example, wp_links contains the information about links that are displayed in your &#8220;Links&#8221; section&#8230; if you use it.</p>
<p>The wp_users table identifies the user accounts that are registered for your blog.  Chances are that that includes you &#8211; and no one else.  The wp_usermeta table is attached to this, and it includes some options for each user (like whether or not they use the WYSIWYG editor for writing posts).</p>
<p>The only really important table here is wp_options.</p>
<p>This defines all of the major options of your blog &#8211; like the url, the title, the description, etc.  Anything you set in the Dashboard is stored in a row in this table.</p>
<p>This also stores all of the plugin and widget information.  WordPress uses a nifty trick to store widgets &#8211; it simply serializes them and stores them in a textfield in the database.  Then, it can put the widget back together with by deserializing it.</p>
<p>This way a widget can be stored and reconstructed from one database row in one table, rather than creating a whole new table for each widget.  It makes the information in the database pretty unintelligible &#8211; but it cuts down massively on the number of queries needed to create and use the widgets.</p>
<h5>Start Messing Around</h5>
<p>The purpose of this, of course, is to understand the database structure so that you can mess around with it yourself.  That is, after all, the point of open source programs.</p>
<p>So lurk around in the database a bit.  This is very useful information for writing plug-ins that need to interact with the WordPress database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/03/wordpress-database-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Use the Crypt() Function to Encrypt and Check Passwords</title>
		<link>http://www.earn-web-cash.com/2008/01/22/crypt-function-php/</link>
		<comments>http://www.earn-web-cash.com/2008/01/22/crypt-function-php/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 02:48:13 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/01/22/how-to-use-the-crypt-function-to-encrypt-and-check-passwords/</guid>
		<description><![CDATA[Every php-script that involves some kind of user login and database interaction has one very important feature &#8211; password checking and encryption. There are a bunch of ways you could create and check passwords &#8211; from an insecure string in a database to an encrypted &#8220;hash&#8221; that you check against user input. This tutorial will [...]]]></description>
			<content:encoded><![CDATA[<p>Every php-script that involves some kind of user login and database interaction has one very important feature &#8211; password checking and encryption.</p>
<p>There are a bunch of ways you could create and check passwords &#8211; from an insecure string in a database to an encrypted &#8220;hash&#8221; that you check against user input.  This tutorial will show you how to use the <a href="http://us.php.net/manual/en/function.crypt.php" title="Crypt() function on php.net"><code>crypt()</code></a> function to store and check passwords in a php script.<br />
<span id="more-57"></span></p>
<h5>What Does the Crypt() Function Do?</h5>
<p>The <code>crypt()</code> function takes two parameters &#8211; the first parameter is the actual input (the password to test) and the second parameter is a &#8220;salt&#8221; or encryption key that is used to encrypt the password phrase.</p>
<p>Let&#8217;s take a look at what the <code>crypt()</code> function does with some input.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Gobble&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;xt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Would yield the output&#8230;</p>
<pre><code>xt0iPj3UKFQSM</code></pre>
<p>The function used the encryption key &#8220;xt&#8221; to turn &#8220;Gobble&#8221; into an encrypted mess.  Now, a person looking through the database won&#8217;t be able to find out a person&#8217;s password.  They&#8217;ll only find the encrypted password &#8211; which won&#8217;t work if you enter it into a script.</p>
<h5>The Crypt() Function Stores the Encryption Key in the Output</h5>
<p>There&#8217;s an important pattern here, though, that we can see if we look at a couple of <code>crypt()</code> calls in a row.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Gobble&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ab&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Gobble&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;td&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Gobble&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;pz&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Would yield the output&#8230;</p>
<pre><code>ab30/okS7bRdo
tdylLlJ9zwOss
pz0u5z5fgyCK.</code></pre>
<p>You can break each piece of output into two pieces &#8211; the first two characters and the last 11 characters.</p>
<p>The first two characters &#8220;ab,&#8221; &#8220;td,&#8221; and &#8220;pz&#8221; are the three &#8220;salts&#8221; or encryption keys that we used in our <code>crypt()</code> calls.  The last 11 characters are the actual encrypted pass phrases.</p>
<p>This simple point is crucial to the functioning of <code>crypt()</code>.  It stores the encryption key inside the encrypted phrase, so that you can use it to encrypt a new phrase &#8211; and compare them.  If you use the encrypted phrase as your &#8220;salt&#8221; (the second parameter for <code>crypt()</code>), the function will isolate the encryption key and ignore the rest.</p>
<p>So this example would output &#8220;Passwords match!&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Gobble&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// User input</span>
<span style="color: #000088;">$salt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ab&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Encryption key</span>
<span style="color: #000088;">$encrypted</span> <span style="color: #339933;">=</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$salt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$encrypted</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> 
    <span style="color: #000088;">$encrypted</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Passwords match!&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this case we&#8217;re using the encrypted password ($encypt) to perform the encryption algorithm on the user&#8217;s input ($password) to see if they match.  Normally, you would have $encrypted stored in the database to perform comparisons in your script.</p>
<h5>Use an MD5 Hash Salt to Encrypt Phrases Over 8 Characters</h5>
<p>The final thing to keep in mind about <code>crypt()</code> is that it can use different kinds of salts or encryption keys.  The two-character salt we&#8217;ve been using is pretty weak.  It also has a flaw in functionality &#8211; using a two-character encryption key, the <code>crypt()</code> function will ignore everything past the first 8 characters of the phrase to be encrypted.</p>
<p>So both of these statements would have the same output.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Gobbledeygook&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ab&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Gobbledeygah&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ab&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The <code>crypt()</code> function is only encrypting the first eight characters &#8211; &#8220;Gobblede&#8221;.  The rest is ignored.</p>
<p>You can change this by using a special type of encryption key &#8211; a md5 hash.  Under normal circumstances, this is enabled in php, but you can double check by seeing if the constant <code>CRYPT_MD5</code> is set to &#8217;1&#8242;.</p>
<p>An md5 hash salt is formatted like this &#8211; <code>$1$xxxxxxxx$</code>.  &#8220;$1$&#8221;, followed by eight random characters, followed by a closing &#8220;$&#8221;.  You could create one yourself to use as a salt.</p>
<p>However, in most cases if you provide no salt or encryption key at all, php will generate a random salt for you.  So, for example, when you are entering a new password into the database you can use this statement&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Gobble&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This variable ($password) can now be stored in the database.  Remember that $password holds both the encrypted phrase (Gobble) and the random encryption key.  So to check if a user entered the correct password you would fetch $password from the database and use this statement&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">crypt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$userInput</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//  Ok, the passwords matched }</span></pre></div></div>

<p>Now that you know how <code>crypt()</code> works, get to it.  Start creating user-authentication scripts and work your encryption magic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/01/22/crypt-function-php/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Protect Against Shell Script Hacks</title>
		<link>http://www.earn-web-cash.com/2008/01/12/protect-shell-script/</link>
		<comments>http://www.earn-web-cash.com/2008/01/12/protect-shell-script/#comments</comments>
		<pubDate>Sat, 12 Jan 2008 14:57:11 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Redirected]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/01/12/protect-shell-script/</guid>
		<description><![CDATA[While browsing through Technorati, I just stumbled on a post about a shell script attack. It seems the poor chap got a shell script uploaded to his server, and the attacker used it to create a bunch of bogus files full of hyperlinks. The original post has some header information about this particular hack (a [...]]]></description>
			<content:encoded><![CDATA[<p>While browsing through Technorati, I just stumbled on a post about a <a href="http://cocaman.ch/wp/2008/01/websites-injected-cool-little-tool/" title="Post about Shell Script Attack, by Geekness">shell script attack</a>.  It seems the poor chap got a shell script uploaded to his server, and the attacker used it to create a bunch of bogus files full of hyperlinks.</p>
<p>The original post has some header information about this particular hack (a modified c100 shell), as well as a link to some search results about the file.  I looked through the <a href="http://www.leetupload.com/database/UNIX/shell.txt">source code for the shell script</a> and tested it out on my local server &#8211; getting some link-filled files is the least that this script could do.<br />
<span id="more-31"></span><br />
Once the script is loaded on your server, anyone can access it remotely and have full access to your system.</p>
<p>The script allows you to navigate through the server&#8217;s directories like any remote file-manager.  I noticed that it could even go up out of the web server root and into my local folders as well.</p>
<p><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/01/shell_script_utils.png' title='Screenshot of Shell Script Utilities'><img class='alignright' src='http://www.earn-web-cash.com/wp-content/uploads/2008/01/shell_script_utils.thumbnail.png' alt='Screenshot of Shell Script Utilities' /></a>The script gathers up all the details on your computer &#8211; like operating system build, running processes, ip address, etc.  The user can run shell commands, create files, upload files, and do other kinds of nasty things.</p>
<p>It would be pretty easy for someone to use this to find the mysql username/password, hack your database, do whatever they want, and pretty wreck your entire site.  Or worse, they could use this to do some nasty things to the server itself &#8211; potentially wrecking other peoples&#8217; sites.</p>
<p>So how do you protect against this?  Well, I&#8217;m not sure what you would do to protect against the shell script once it&#8217;s loaded up.  It looks like it&#8217;s built to bypass most security precautions and give the hacker access to whatever he or she wants.</p>
<p>Your best bet is to be vigilant in restricting front-end uploads to your site.  If you&#8217;ve got an upload script, be sure you restrict what file extensions can be uploaded.  </p>
<p>This script needs to be named with a file extension that is read as php &#8211; so you should never allow users to upload php files (or html if you set up your server to execute those as php).</p>
<p>Being more restrictive is better than less restrictive &#8211; so ban all file extensions <strong>except</strong> the ones you know are safe.  So, for example, you might allow &#8220;.jpg, .gif, .png&#8221; for pictures, and &#8220;.doc, .odt, .pdf, .txt, .rtf&#8221; for documents.</p>
<p>If you&#8217;ve got any other suggestions for security against this sort of thing, please comment away.  Otherwise, take a look at the script so that you are aware of what it can do.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/01/12/protect-shell-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

