<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:18pt"><div><span>Thanks for share this, but still it is not easy to get in. check the script below</span></div><div style="color: rgb(0, 0, 0); font-size: 24px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><span><span style="font-family: monospace; font-size: 13px;">$password = md5($password);</span><br style="font-family: monospace; font-size: 13px;"><span style="font-family: monospace; font-size: 13px;"> $sql = "SELECT username, password from users where</span><br style="font-family: monospace; font-size: 13px;"><span style="font-family: monospace; font-size: 13px;"> username = '$username' and password = '$password'";</span><br
style="font-family: monospace; font-size: 13px;"><span style="font-family: monospace; font-size: 13px;"> $result = mysql_query($sql);</span><br style="font-family: monospace; font-size: 13px;"><span style="font-family: monospace; font-size: 13px;"> $row = mysql_fetch_array($result))</span><br style="font-family: monospace; font-size: 13px;"><span style="font-family: monospace; font-size: 13px;"> if ( $_POST['username'] = $row['username'] )</span><br style="font-family: monospace; font-size: 13px;"><span style="font-family: monospace; font-size: 13px;"> {</span><br style="font-family: monospace; font-size: 13px;"><span style="font-family: monospace; font-size: 13px;"> $login =
1;</span><br style="font-family: monospace; font-size: 13px;"><span style="font-family: monospace; font-size: 13px;"> }</span><br></span></div><div style="color: rgb(0, 0, 0); font-size: 24px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><span><span style="font-family: monospace; font-size: 13px;">from above script the line:</span></span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: monospace; background-color: transparent; font-style: normal;"><span><span style="font-family: monospace; font-size: 13px;">if ( $_POST['username'] = $row['username'] )<br></span></span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: monospace; background-color: transparent; font-style: normal;"><span><span style="font-family: monospace; font-size:
13px;"><br></span></span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: monospace; background-color: transparent; font-style: normal;"><span><span style="font-family: monospace; font-size: 13px;">will mean you are assigning value of </span></span>$row['username'] to $_POST['username'] variable and not comparing, hence $login will be assigned 1.(bad usage of if() statement) </div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: monospace; background-color: transparent; font-style: normal;">But if you change '=' into '==' it will compare between user supplied from form and that from database where it will always be not valid since the query returned true with empty username because no such username in the database. So for me such type of sql injection won't work.</div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: monospace; background-color: transparent; font-style: normal;"><br></div><div
style="color: rgb(0, 0, 0); font-size: 13px; font-family: monospace; background-color: transparent; font-style: normal;">Yahaya Abdallah.</div><div class="yahoo_quoted" style="display: block;"> <br> <br> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 18pt;"> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Tuesday, January 21, 2014 8:10 PM, Andreas Tauscher <ta@geuka.net> wrote:<br> </font> </div> <div class="y_msg_container">Hello list!<br><br>I think this post will follow some others, but then on a blog.<br><br>Some days ago somebody asked me to have a look on his self coded CMS.<br>They guy was really proud about it. But now he might use on the<br>established ones or starting from scratch again:<br><br>So even without having an look on the code itself I
simply started the<br>nice browser plugin "SQL inject me".<br><br>Only seconds later: Tata! I had a list of all usernames an passwords<br>nicely presented in the browser.<br><br>He did one of the biggest mistakes: Trusting the user. A later look on<br>the code was then a real horror show.<br>What else then the username and the password somebody should enter in<br>fields named Login and Password?<br>If he is an evil guy, he will enter there anything else but not an<br>username: Java script, HTML code and many other things.<br>SQL inject me is entering there SQL queries.<br>The code for the login form looked somehow like this:<br><br> $username = $_POST['username'];<br> $password = $_POST['password'];<br><br> if ($username=='' || $password=='')<br> {<br> $error = "Enter Username and
Password";<br> }<br> else<br> {<br> $password = md5($password);<br> $sql = "SELECT username, password from users where<br> username = '$username' and password = '$password'";<br> $result = mysql_query($sql);<br> $row = mysql_fetch_array($result))<br> if ( $_POST['username'] = $row['username'] )<br> {<br> $login = 1;<br> }<br><br>As long somebody enters only a username and a password: Everything is<br>fine. But what happens if enter instead the
username something like this:<br>' OR '1=1 as username and password?<br><br>The query looks then a little bit different:<br>SELECT username, password from users where username = '' OR '1=1' and<br>password = '' OR '1=1'";<br><br>This query is always true. It will return all users. So I'm logged in as<br>the last user. With an additional limit statement I try now all users<br>until I get an administrator. With a few lines script using nice stuff<br>like WWW::Mechanize this is only a question of seconds: This website is<br>under my control. Or should I add instead a limit statement maybe a drop<br>statement? Hope you have a backup of your database.<br><br>How to prevent such things?<br><br>1: Any input is evil! Don't trust any input. If it comes from the local<br>PC, the LAN or from the internet. Don't trust any input the user can<br>manipulate. No cookie, no browser string, no referer, nothing you can<br>trust. And not only the user might manipulate
input. Maybe your since<br>1000 years not updated router is doing it (different story how to abuse<br>your old router to hijack you). Any input must be validated. Any<br>sensitive information usernames, passwords, session IDs and and and must<br>be encrypted. (This is then for later when we see SQL injection is fixed<br>and we use other injecions) For the username and the password this would<br>be at least: What is the minimum and the maximum length of the string?<br>Which characters are allowed in the string?<br><br>2: Don't deal with the database direct. In PHP don't use mysql use<br>mysqli or PDO. They support a nice feature available in MySQL since<br>version 4.1: prepared statements.<br>Prepared statements having two big benefits: Much faster, and SQL<br>injection is much more difficult.<br><br>Usage of prepared statements is easy:<br>// New connection to DB<br>$db = new mysqli(localhost, user, password, database);<br>// Prepare statement<br>$stmt
= $db->prepare("SELECT username, password FROM users WHERE<br>username = ? and password = ?;");<br>// Replace the spaceholders<br>$stmt->bind_param(ss,$username,$password);<br>//execute query<br>$stmt->execute();<br><br>$db->prepare is handing over the query to MySQL. MySQL now verifies the<br>query if the syntax is ok, all tables existing ans so on. If yes the<br>statement is stored in a buffer and reference is returned. Here is the<br>reason why the queries are faster: The parsing of the query is done only<br>once when I prepare the statement.<br>With bind_params I replace now the ? placeholders. The ss is telling:<br>both are strings. Other possible values are i for integer, d for<br>double/float and b for blob.<br>Only the placehoder data is sent to the database and inserted in the<br>query. The ' I injected in the query will not longer change the query:<br>It is already parsed. The executed query now will be equal to:<br>SELECT
username, password from users where username = '\' OR \'1=1' and<br>password = '\' OR \'1=1'";<br>I query if the user ' OR '1=1 exists.<br>But this does not mean you don't have to verify the input. It will not<br>prevent other injections.<br><br>To be continued.... Then we abuse the comment option of the CMS a<br>little bit to install some nice male ware on your PC.<br><br>Andreas<br>_______________________________________________<br>The Arusha Linux User Group: <a href="http://unix.or.tz/" target="_blank">http://unix.or.tz</a><br>Linux mailing list<br><a ymailto="mailto:Linux@lists.habari.co.tz" href="mailto:Linux@lists.habari.co.tz">Linux@lists.habari.co.tz</a><br><a href="http://lists.habari.co.tz/cgi-bin/mailman/listinfo/linux" target="_blank">http://lists.habari.co.tz/cgi-bin/mailman/listinfo/linux</a><br><br>The Arusha LUG mailing list is generously hosted by Habari Node Ltd: <a href="http://www.habari.co.tz/"
target="_blank">http://www.habari.co.tz/</a><br><br>The above comments and data are owned by whoever posted them (including attachments if any). The mailing list host is not responsible for them in any way.<br><br><br></div> </div> </div> </div> </div></body></html>