Software Security Presentation
Software Security Presentation
It encompasses:-
secure coding practices,
threat anticipation,
defense mechanisms to ensure data integrity,
confidentiality, and availability.
5
Solution for Buffer Overflows……...
3. Bounds Checking
Explicitly verify buffer sizes before writing data.
Example: Before copying input, check if the source
size exceeds the buffer capacity.
4. Modern Programming Practices
Use programming languages or frameworks with
built-in buffer overflow protections (e.g., Java,
Python).
Enable compiler options like fstack
protector(arbitrary code execution) or Address
Space Layout Randomization (ASLR) to mitigate
overflows.
6
2. Injection Attacks
An attacker introduces malicious code or commands into a
program by exploiting improper input handling.
Cause: Failure to sanitize or validate user input in queries or
commands.
Impact: Can lead to unauthorized data access, code execution,
or manipulation.
Example: SQL injection, where a user inputs DROP TABLE
Users
into a database query to delete critical tables.
Solution to Injection Attacks
Injection attacks can be prevented by properly validating,
sanitizing, and handling user inputs.
7
Below are key strategies to mitigate injection vulnerabilities:
a. Input Validation
Ensure user inputs conform to expected formats and reject
invalid data.
Example: Use regular expressions to validate email addresses
or phone numbers.
b. Sanitize Input
refers to the practice of cleaning and validating user input
before it is processed by a program or application.
Ensure that the input meets specific criteria (e.g., type,
length, format). Reject inputs that do not comply with
expected values.
prevents various types of attacks, such as SQL injection and
cross-site scripting (XSS).
OF-FTI-ALL -18
Issue No 1
8
c. Least Privilege Principle
Restrict application permissions to minimize potential
damage.
Example: Allow database accounts to execute queries
but not to drop tables or modify schemas.
d. Use Security Libraries or Frameworks
Leverage tools like OWASP ESAPI (Enterprise Security API)
or web frameworks with built-in protection against
injection attacks.
Example: Django ORM automatically escapes queries to
prevent SQL injection.
9
3. Race Conditions
Memory
Writing overly long data into
Lack of input size corruption, Validate input sizes and use
Buffer Overflow a buffer, overwriting adjacent
validation crashes, or code safe functions like strncpy.
memory.
execution
Unauthorized
Unsanitized or SQL injection to manipulate Use prepared statements and
Injection Attack access or code
unvalidated input or delete database records. sanitize inputs.
execution
Concurrent Data corruption Two threads withdrawing from Use locks or atomic
Race Condition access to shared or security the same bank account operations to synchronize
resources bypass without synchronization. access.
Trusting
unvalidated data Data leaks, Using predictable temp file Validate inputs, use secure
Insecure External
or improper privilege names, enabling malicious APIs, apply least privilege,
Interaction
privilege escalation overwrites. and use secure temp files.
management
16
1.1 Introducing Software Security and
Defensive Programming
Software security aims:-
to create systems that are resistant to attacks, focusing
on secure coding, risk management, and proactive
defenses.
Defensive programming
is a development approach that anticipates potential
errors or malicious activities and includes safeguards to
ensure software functions securely, even in unexpected
situations.
is a mindset that anticipates potential failures and
proactively implements safeguards.
19
2.1 Input Size and Buffer Overflow
A buffer overflow occurs when input exceeds allocated memory size,
potentially overwriting adjacent memory.
Example: A login form allows an unlimited username length, causing
memory corruption.
Solution: Validate input size and use safe functions like strncpy in C or
Prevent stack overflow in login forms by restricting username length to
20 characters.
2.2 Interpretation of Program Input
Definition: Misinterpreted input can cause unexpected behavior or
vulnerabilities.
Example: SQL injection, where input like '; DROP TABLE Users; --
manipulates database queries.
Solution: Use parameterized queries or prepared statements to prevent
malicious SQL commands.
20
2.3 Validating Input Syntax
Ensures that input matches expected formats to block
invalid or malicious entries.
Ensure input conforms to the expected format using
techniques like regular expressions.
Example: Allowing only numeric input in a phone number
field prevents injecting scripts or special characters.
Solution: Use regular expressions to validate inputs (e.g.,
for emails or dates).
Validate email inputs with patterns like `^[a-z A-Z 0-9 _%
+-]+@[a-z A-Z 0-9.-]+\.[a-z A-Z ]{2,}$`.
Example: Disallow special characters in username fields to
avoid command injection.
21
2.4 Input Fuzzing
Is a software testing technique used to identify vulnerabilities,
bugs, and unexpected behavior in software systems by
feeding them unexpected, random, or invalid inputs.
The goal is to test the robustness and security of the system
by pushing it beyond its typical operational limits.
Example: Using fuzzing tools like AFL (American Fuzzy Lop) to
find inputs that cause crashes or errors.
Solution: Incorporate fuzz testing in the development process
to discover edge cases.
Properly handling input ensures that malicious or malformed
data cannot disrupt or exploit software.
Validating input size, format, and behavior minimizes
vulnerabilities and enhances system security.
22
How Input Fuzzing Works
a/ Input Generation:
A fuzzing tool generates a wide range of inputs, often
random, malformed, or invalid.
These inputs might include oversized data, unexpected
characters, or invalid formats.
Inputs can be generated in several ways:
Random fuzzing: Completely random inputs.
Mutation-based fuzzing: Modifies valid inputs to
create test cases.
23
b/ Execution:
• The software under test is executed with these
generated inputs, simulating real-world scenarios or
edge cases.
c/ Monitoring:
• The behavior of the software is monitored to detect
crashes, errors, or unexpected outputs.
• Logs and system metrics (e.g., memory usage, CPU
activity) are analyzed for anomalies.
d/ Bug Analysis
If issues are detected, the problematic input is
recorded for further analysis to identify the root cause.
24
3. Writing Safe Program Code
Writing safe program code ensures that software
remains reliable, secure, and resistant to
vulnerabilities under all circumstances.
3.1 Correct Algorithm Implementation
Algorithms must follow precise specifications to avoid
unintended flaws or vulnerabilities.
Example:1 Incorrect cryptographic implementations can
weaken encryption (e.g., weak random number
generators).
Solution: Implement algorithms according to established
best practices and standards.
25
4. Interacting with the Operating System
and Other Programs
26
5. Handling Program Output
Securely managing program output is essential to
prevent the unintentional leakage of sensitive data and
protect systems from injection attacks.
Or Secure output handling ensures sensitive
information is not leaked.
Solution: Encode output to prevent injection attacks.
Example: Use HTML encoding to prevent XSS in web
applications (`<` instead of `<`).
Output sanitization is also critical for error messages to
avoid exposing stack traces or internal system details.