Unit-4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Unit-4

Database Management Systems and Data Structures in Cybersecurity


4.1. Overview of DBMS and SQL/NOSQL
4.2. RAID, ER Models, and SQL Querying
4.3. Data Structure Basics and Their Cybersecurity Applications

4.1. Overview of DBMS and SQL/NOSQL


Database Management Systems (DBMS):
A DBMS is a system designed to store, manage, and retrieve data efficiently. It ensures data
integrity, security, and consistency while providing an interface to interact with the stored data.

Key Functions of a DBMS:

Data Storage: Organizes data in structured formats (tables, indexes).


Data Retrieval: Supports querying languages like SQL to fetch data.
Data Integrity and Security: Ensures data correctness and controlled access.
Transaction Management: Handles multiple operations, ensuring consistency (ACID
properties).

Types of DBMS:

1. Relational DBMS (RDBMS): Data is stored in tables (e.g., MySQL, PostgreSQL, Oracle).
SQL (Structured Query Language) is used for querying.
2. NoSQL DBMS: These databases handle unstructured or semi-structured data. They are
highly scalable and flexible (e.g., MongoDB, Cassandra, Redis). NoSQL databases use
varied query languages and are suitable for big data applications.

SQL vs. NoSQL:

SQL (Structured Query Language):


Standard language for RDBMS.
Focus on structure and schema (e.g., tables, rows, columns).
ACID compliance (Atomicity, Consistency, Isolation, Durability).
Examples: MySQL, PostgreSQL, Microsoft SQL Server.
NoSQL:
Non-relational and schema-less.
Designed for flexibility, scalability, and large-scale data.
Types of NoSQL: Document-based (MongoDB), Key-value stores (Redis), Column-
family stores (Cassandra), Graph databases (Neo4j).
Examples: MongoDB, Cassandra, CouchDB.

Cybersecurity Implications:

Data Integrity: SQL databases provide robust integrity constraints, while NoSQL often
lacks this feature.
Data Security: Both SQL and NoSQL databases need encryption, authentication, and
secure access protocols to protect sensitive data.
SQL Injection Attacks: A common vulnerability in SQL-based systems. Understanding
SQL querying is essential for preventing these attacks.

4.2. RAID and SQL Querying


RAID (Redundant Array of Independent Disks): RAID is a data storage virtualization
technology that combines multiple physical disk drive components into a single logical unit for
data redundancy or performance improvement.

RAID Levels:
RAID 0: Striping (no redundancy, faster performance).

RAID 1: Mirroring (data redundancy, slower performance).


RAID 5: Striping with parity (balanced redundancy and performance).

RAID 10: Combines RAID 1 and RAID 0 (high performance with redundancy).
Cybersecurity Implications of RAID:

Data Redundancy: Ensures data availability even during hardware failure.


Data Recovery: Key for disaster recovery scenarios in cybersecurity.
Performance and Security: RAID configurations should be chosen based on security
needs and data access speed.

SQL Querying: SQL is used to interact with relational databases and can be used to create,
retrieve, update, and delete data (CRUD operations).

Basic SQL Queries:


SELECT: Retrieves data from a table.
SELECT * FROM employees;
INSERT: Adds data to a table.
INSERT INTO employees (first_name, last_name, department, salary) VALUES
('John', 'Doe', 'Sales', 60000);
UPDATE: Modifies existing data.
UPDATE employees SET salary = 65000 WHERE employee_id = 101;
DELETE: Removes data from a table.
DELETE FROM employees WHERE employee_id = 101;
Advanced SQL:
JOIN: Combines rows from multiple tables based on a related column.
Inner join "employees" and "departments" on the department_id.
SELECT employees.first_name, employees.last_name,
departments.department_name FROM employees JOIN departments ON
employees.department_id = departments.department_id;
GROUP BY: Aggregates data.
Get the average salary for each department
SELECT department, AVG(salary) AS avg_salary FROM employees GROUP BY
department;
WHERE: Filters data based on conditions.
Get employees who earn more than $50,000.
SELECT first_name, last_name, salary FROM employees WHERE salary >
50000;

Cybersecurity Implications of SQL Querying:

SQL Injection: A major attack vector. Understanding SQL queries is vital for implementing
proper input validation to prevent such attacks.
Access Control: Using SQL to limit access to sensitive data and logs.

SQL injections

SQL injection is a technique where an attacker can manipulate an SQL query by inserting
malicious SQL code into an input field, typically to interact with a database in unauthorized
ways (e.g., viewing, modifying, or deleting data). Here's a basic example to illustrate how SQL
injection might work.

Scenario
Let's assume there is a simple login form with two fields:

1. username
2. password

The server processes these inputs with an SQL query like:

SELECT * FROM users WHERE username = '[username]' AND password = '[password]';

In a safe system, [username] and [password] would be replaced with the actual user inputs,
resulting in something like:

SELECT * FROM users WHERE username = 'johndoe' AND password = 'mypassword';

However, if the application does not properly validate or escape user input, an attacker could
input malicious SQL code into the form fields.

Example of SQL Injection


Malicious Input:

Username: admin' --
Password: anything

Resulting Query:
SELECT * FROM users WHERE username = 'admin' --' AND password = 'anything';

In this case:

The -- is a comment in SQL, so everything after it is ignored.


The query becomes:

SELECT * FROM users WHERE username = 'admin';

This effectively bypasses the password check and grants access to the attacker as the admin
user (if such a user exists in the database).

More Dangerous Example: Data Extraction


If the attacker wants to extract sensitive data, they might use a more complex input, like:

Username: ' OR 1=1; --


Password: anything

This would turn the query into:

SELECT * FROM users WHERE username = '' OR 1=1; --' AND password = 'anything';

Here:

The OR 1=1 condition always evaluates to true, so the query returns all records from the
users table, potentially exposing sensitive data such as usernames, passwords, and
other private information.

How to Prevent SQL Injection


To avoid SQL injection attacks, it's important to:

1. Use Prepared Statements/Parameterized Queries: This method ensures user inputs are
treated as data, not executable code.
For example, using Python's sqlite3 :
cursor.execute("SELECT * FROM users WHERE username = ? AND password = ?",
(username, password))
2. Sanitize and Escape User Input: Ensure that user input is cleaned and escaped before
being used in SQL queries.
3. Use ORM (Object-Relational Mapping) Libraries: Frameworks like Django, Ruby on
Rails, or Hibernate handle query generation in a secure way.
4. Least Privilege: Ensure database accounts used by applications have the minimum
necessary permissions.

You might also like