Cyber Security-Module 2
Cyber Security-Module 2
http://www.victimsite.com/index.php?id=2 order by 1
http://www.victimsite.com/index.php?id=2 order by 2
http://www.victimsite.com/index.php?id=2 order by 3
http://www.victimsite.com/index.php?id=2 order by 4
…..
http://www.victimsite.com/index.php?id=2 order by 8(error)
so now x=8 , The number of column is x-1 i.e, 7.
Step 4: Displaying the Vulnerable columns:
◦ Using “union select columns_sequence” we can find
the vulnerable part of the table. Replace the “order
by n” with this statement.
◦ And change the id value to negative
◦ Replace the columns_sequence with the no from 1 to
x-1(number of columns) separated with commas(,).
For eg:
if the number of columns is 7 ,then the query is
as follow:
http://www.victimsite.com/index.php?id=-2
union select 1,2,3,4,5,6,7—
Blind SQL injection
Blind SQL Injection is used when a web application is
vulnerable to an SQL injection but the results of the
injection are not visible to the attacker.
The page with the vulnerability may not be one that
displays data but will display differently depending on
the results of a logical statement injected into the
legitimate SQL statement called for that page.
This type of attack can become time-intensive because
a new statement must be crafted for each bit recovered.
There are several tools that can automate these attacks
once the location of the vulnerability and the target
information has been established
How to prevent SQL Injection attacks
Input validation
◦ Replace all single quotes to two single quotes
◦ Sanitize the input: clean characters like ;, --, select, etc
◦ Numeric values should be checked while accepting a query
string value
◦ Keep all text boxes and form fields short
Modify error reports
◦ SQL errors should not be displayed to the outside world
Other preventions
◦ Never use default system accounts for SQL server 2000
◦ Isolate database server and webserver: different machines
◦ Extended stored procedures, user defined functions should be
moved to an isolated server.
10. Buffer overflow
In computer security and programming, a
buffer overflow, or buffer overrun, is an
anomaly where a program, while writing data
to a buffer, overruns the buffer's boundary
and overwrites adjacent memory. This is a
special case of violation of memory safety.
This may result in erratic program behavior
Buffer overflows are not easy to discover and
even when one is discovered, it is generally
extremely difficult to exploit.
In a classic buffer overflow exploit, the attacker sends data to
a program, which it stores in an undersized stack buffer. The
result is that information on the call stack is overwritten,
including the function's return pointer.
The data sets the value of the return pointer so that when the
function returns, it transfers control to malicious code
contained in the attacker's data.
At the code level, buffer overflow vulnerabilities usually
involve the violation of a programmer's assumptions.
Many memory manipulation functions in C and C++ do not
perform bounds checking and can easily overwrite the
allocated bounds of the buffers they operate upon.
Even bounded functions, such as strncpy(), can cause
vulnerabilities when used incorrectly.
The combination of memory manipulation and mistaken
assumptions about the size or makeup of a piece of data is the
root cause of most buffer overflows.
example
The code in this example also relies on user input to control its
behavior, but it adds a level of indirection with the use of the bounded
memory copy function memcpy().
This function accepts a destination buffer, a source buffer, and the
number of bytes to copy. The input buffer is filled by a bounded call to
read(), but the user specifies the number of bytes that memcpy() copies.
... char buf[64], in[MAX_SIZE];
printf("Enter buffer contents:\n");
read(0, in, MAX_SIZE-1);
printf("Bytes to copy:\n");
scanf("%d", &bytes);
memcpy(buf, in, bytes); ...
Note: This type of buffer overflow vulnerability (where a program
reads data and then trusts a value from the data in subsequent memory
operations on the remaining data) has turned up with some frequency in
image, audio, and other file processing libraries.
Types of buffer overflow
stack-based buffer overflow
Heap buffer overflow
NOPs
stack-based buffer overflow
A stack-based buffer overflow condition
is a condition where the buffer being
overwritten is allocated on the stack
Attack may exploit this to manipulate the
program by
◦ Changing the local variable
◦ Changing the return address
◦ Changing the function pointer or exception
handler
heap buffer overflow
A heap overflow is a type of buffer overflow that occurs in
the heap data area.
Heap overflows are exploitable in a different manner to that
of stack-based overflows.
Memory on the heap is dynamically allocated by the
application at run-time and typically contains program data.
Exploitation is performed by corrupting this data in specific
ways to cause the application to overwrite internal
structures such as linked list pointers.
The canonical heap overflow technique overwrites dynamic
memory allocation linkage (such as malloc meta data) and
uses the resulting pointer exchange to overwrite a program
function pointer.
NOP-sled
A NOP-sled is the oldest and most widely known technique for
successfully exploiting a stack buffer overflow.
It solves the problem of finding the exact address of the buffer
by effectively increasing the size of the target area.
To do this, much larger sections of the stack are corrupted with
the no-op machine instruction. At the end of the attacker-
supplied data, after the no-op instructions, the attacker places
an instruction to perform a relative jump to the top of the
buffer where the shellcode is located.
This collection of no-ops is referred to as the "NOP-sled"
because if the return address is overwritten with any address
within the no-op region of the buffer it will "slide" down the
no-ops until it is redirected to the actual malicious code by the
jump at the end.
How to minimize buffer overflow
Assessment of secure code manually
Disable stack execution
Compiler tools
Dynamic run-time checks
Various tools are used to detect/ defend
buffer overflow
◦ stackGaurd
◦ Propolice
◦ LibSafe