<?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>Not A n00b &#187; login</title>
	<atom:link href="http://notan00b.com/tag/login/feed/" rel="self" type="application/rss+xml" />
	<link>http://notan00b.com</link>
	<description>Tutorials, Scripts, and Rants</description>
	<lastBuildDate>Wed, 12 May 2010 08:08:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP PDO and SQL injections</title>
		<link>http://notan00b.com/2009/08/php-pdo-and-sql-injections/</link>
		<comments>http://notan00b.com/2009/08/php-pdo-and-sql-injections/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 18:22:42 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bypass]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[injections]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[MsSQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PDO]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=179</guid>
		<description><![CDATA[SQL Injections o_O???]]></description>
			<content:encoded><![CDATA[<p>MySQL and MsSQL are huge when it comes to internet sites.  They are probably the easiest databases to set up and the most universal when it comes to internet apps.  The only problem is that programmers are sometimes lazy and forget to think about things like security when it comes to programming the forms and site.  When people are lazy, they leave their sites open to SQL injections.  I don&#8217;t really want to make this an SQL injection tutorial, but just want to touch on it briefly.  Lets start with a standard SQL statement that a form uses to find an Administrator password:<br />
<code>mysql&gt; SELECT * FROM Users WHERE Name='Admin' AND Pass='MyP4ssw0rd';</code><br />
Now if we add a login form and use php, we might have code structured similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$name</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pass</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SELECT * FROM Users WHERE Name='<span style="color: #006699; font-weight: bold;">$name</span>' AND Pass='<span style="color: #006699; font-weight: bold;">$pass</span>'&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This would work perfectly, and would allow people to log in.  It would also allow people to SQL inject it.  What if they typed this in:</p>
<table>
<tr>
<td>Name:</td>
<td>
<input type="text" value="admin"></td>
</tr>
<tr>
<td>Pass:</td>
<td>
<input type="text" value="admin' OR 'x'='x"></td>
</tr>
</table>
<p>
Well our SQL statement ends up looking like this:<br />
<code>SELECT * FROM Users WHERE Name='admin' AND Pass='admin' OR 'x'='x'</code><br />
&#8216;x&#8217;='x&#8217; is a TRUE statement 100% of the time, so as long as &#8216;x&#8217;='x&#8217;, it will pull up all the info you needed, and suddenly you are logged in.  This is probably the easiest SQL injection around, and does work on occasion.  There are hundreds of SQL injections, and a poorly coded site will always be susceptible.  Not only are people able to log into a site as an administrator, but they can display login info using UNION statements.<br />
One other way good programmers tend to get lazy is through their &#8220;GET&#8221; variables.  A lot of times programmers will pass variables in the URL bar: http://www.mysite.com/view.php?id=123.  There is nothing wrong with this, in fact, everyone does it and will continue to do it because it is efficient and easy to do.  The problem comes when people SQL inject that variable: view.php?id=123&#8242; and &#8216;x&#8217;='y.  This particular injection allows a hacker to test your site for susceptibility to injections in the URL bar.  If you didn&#8217;t protect your variables, your SQL statement would look like this if it wasn&#8217;t protected: <code>"SELECT * FROM Info WHERE Id='123' and 'x'='y'"</code>.  If it wasn&#8217;t protected, the hacker would see a page with NO info on it, or an error because &#8216;x&#8217; NEVER equals &#8216;y&#8217; and is a FALSE statement.  If they see a blank page or an error, they know they can continue their attack and eventually gain access to all of your information.</p>
<p>My goal is not to teach you how to hack, but rather how a simple PHP object exists and will help you avoid these types of attacks.  That object is PDO.  It comes standard with the latest releases of PHP and can be used to prevent SQL injections very simply.  PDO is a database object, that allows you to connect to a variety of different databases, send queries, and display the results.  It actually is a bit easier to code than actual mysql in PHP, but it is a complete 180 from what you have been taught using w3schools and tizag.com.  I don&#8217;t really want to get into a tutorial of PDO either because there are quite a few on the internet that explain it much better than I can right now.  I recommend checking out <a href="http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html">http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html</a> to get a grip on the basics of how PDO works.  The one thing that this tutorial does NOT explain is the &#8220;prepare&#8221; function.  He only goes into it slightly, but doesn&#8217;t describe what it does exactly.  Prepare() simply checks for all types of quotes and makes sure that no SQL injections can get through.  Here is a quick example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$mysql_host</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql_user</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql_pass</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mysql_database</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;epco&quot;</span><span style="color: #339933;">;</span>
try <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$dbh</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mysql:host=<span style="color: #006699; font-weight: bold;">$mysql_host</span>;dbname=<span style="color: #006699; font-weight: bold;">$mysql_database</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysql_pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** create the statement ***/</span>
    <span style="color: #000088;">$stmt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM users WHERE user = :user AND pass = :pass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** bind the paramaters ***/</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':user'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> PDO<span style="color: #339933;">::</span><span style="color: #004000;">PARAM_STR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':pass'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> PDO<span style="color: #339933;">::</span><span style="color: #004000;">PARAM_STR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** execute the prepared statement ***/</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*** close the database connection ***/</span>
    <span style="color: #000088;">$dbh</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>    
<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>PDOException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</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></div></div>

<p>When we prepare our statement, we use a place-holder that will later assign a variable to.  When that statement is executed, all our quotes are removed or slashed.  <code>$_POST['user']="admin' OR 1=1";</code> typically becomes <code>$_POST['user']="admin\' OR 1=1";</code> and your database is protected from the attacks.</p>
<p>In conclusion, I am not advocating PDO and saying only to use that and nothing else.  I use a database class that is much smaller and does what I need it to do.  I have spoken with other programmers who have created their own class to add/strip slashes, rawurlencode/decode, and htmlspecialcharacters and connect to their databases.  PDO was created as a &#8220;universal&#8221; database object that can do whatever you want it to do with several different databases.  It is awesome and will go a long way to protect your site from SQL injections if used properly.  The prepare statement is simple, but doesn&#8217;t protect against EVERY type of attack.  Don&#8217;t be fooled into a false sense of security just because you are using a PHP object.  XSS, javascript injections, and bruteforce, attacks are all still possible even if you use this class.  Be careful in what you code, and fix any code when the holes are found by users or when you are hacked.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/08/php-pdo-and-sql-injections/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Login Script Posted</title>
		<link>http://notan00b.com/2009/07/login-script-posted/</link>
		<comments>http://notan00b.com/2009/07/login-script-posted/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 00:02:41 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[customizable]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=175</guid>
		<description><![CDATA[Check out the code bin for a simple, very customizable login script! Code Bin
]]></description>
			<content:encoded><![CDATA[<p>Check out the code bin for a simple, very customizable login script! <a href="/code-bin/">Code Bin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/07/login-script-posted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting around Vista&#8217;s Login</title>
		<link>http://notan00b.com/2009/07/getting-around-vistas-login/</link>
		<comments>http://notan00b.com/2009/07/getting-around-vistas-login/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 23:49:42 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[account]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[administrator]]></category>
		<category><![CDATA[bootload]]></category>
		<category><![CDATA[bypass]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[NTPASSWD]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vista]]></category>
		<category><![CDATA[xp]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=60</guid>
		<description><![CDATA[Had a problem a while back, where I needed to get some information of my brothers laptop.  He wasn&#8217;t around, and I couldn&#8217;t contact him.  He had one account &#8220;Todd&#8221;, which was password protected.  Try as I might, I couldn&#8217;t break into it.  I came across a nifty bootloader that could [...]]]></description>
			<content:encoded><![CDATA[<p>Had a problem a while back, where I needed to get some information of my brothers laptop.  He wasn&#8217;t around, and I couldn&#8217;t contact him.  He had one account &#8220;Todd&#8221;, which was password protected.  Try as I might, I couldn&#8217;t break into it.  I came across a nifty bootloader that could enable the Administrator account.  Check out the <a href="/tutorials/">Tutorials page</a> for more info.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/07/getting-around-vistas-login/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
