migrate to git.charlotte.sh
This commit is contained in:
commit
fbd588721e
412 changed files with 13750 additions and 0 deletions
9
db-security-sec300/README.md
Normal file
9
db-security-sec300/README.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Database Security
|
||||
Fall 2024 - 1 credit course
|
||||
|
||||
- [Week1](https://git.charlotte.sh/lotte/ChamplainTechJournals/src/branch/main/db-security-sec300/week1.md): mySQL
|
||||
- [Week2](https://git.charlotte.sh/lotte/ChamplainTechJournals/src/branch/main/db-security-sec300/week2.md): DB-Webserver connection
|
||||
- [Week3](https://git.charlotte.sh/lotte/ChamplainTechJournals/src/branch/main/db-security-sec300/week3.md): filtering at database
|
||||
- [Week4](https://git.charlotte.sh/lotte/ChamplainTechJournals/src/branch/main/db-security-sec300/week4.md): log analysis
|
||||
- [Week5](https://git.charlotte.sh/lotte/ChamplainTechJournals/src/branch/main/db-security-sec300/week5.md): emailing logs
|
||||
|
55
db-security-sec300/week1.md
Normal file
55
db-security-sec300/week1.md
Normal file
|
@ -0,0 +1,55 @@
|
|||
# Week1
|
||||
|
||||
Summary: Set up mysql, basic queries
|
||||
|
||||
### Install mysql-server:
|
||||
|
||||
* `sudo apt-get install mysql-server`
|
||||
|
||||

|
||||
|
||||
* change bind address via `/etc/mysql/mysql.conf.d/mysqld.cnf`
|
||||
* remember! `sudo systemctl restart mysql`
|
||||
* default password is found in `/etc/mysql/debian.cnf`
|
||||
* first login: `sudo mysql -u root -p`
|
||||
* show current users/DBs: `USE mysql;`, `SELECT User, Host FROM mysql.user;`, `SHOW DATABASES;`
|
||||
* create registration DB: `CREATE DATABASE registration;`
|
||||
* `USE registration;`
|
||||
* create requests table:
|
||||
|
||||
```
|
||||
CREATE TABLE requests(
|
||||
id INT unsigned NOT NULL AUTO_INCREMENT,
|
||||
fname VARCHAR(50) NOT NULL,
|
||||
email VARCHAR(50) NOT NULL,
|
||||
rdate DATE NOT NULL,
|
||||
uid VARCHAR(15) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
```
|
||||
|
||||
* show table: `DESCRIBE requests;`
|
||||
|
||||

|
||||
|
||||
* add data to table: `INSERT INTO requests (fname, email, rdate, uid) VALUES ( 'dummy', 'dummy@dummy.edu', '2024-11-12', 'nsk31fhenfJF024');`
|
||||
|
||||
### HW
|
||||
|
||||

|
||||
|
||||
1: Write an SQL query that displays name and birth of cats whose names are Siggy
|
||||
|
||||

|
||||
|
||||
2: Write an SQL query that displays name and birth of cats whose owners names are starting with the letter 'F'
|
||||
|
||||

|
||||
|
||||
3: Write an SQL query that displays the cat names, their owners names, and the birth of cats in single table for cats born in year 2020
|
||||
|
||||

|
||||
|
||||
4: Write an SQL query that displays names of owners who has no cats
|
||||
|
||||

|
41
db-security-sec300/week2.md
Normal file
41
db-security-sec300/week2.md
Normal file
|
@ -0,0 +1,41 @@
|
|||
# Week2
|
||||
|
||||
## DB Webserver Connection
|
||||
|
||||
* create user for remote access:
|
||||
|
||||

|
||||
|
||||
* allow connections through firewall: `sudo ufw allow from 0.0.0.0 to 0.0.0.0 port 3306 proto tcp`
|
||||
* get python dependencies: `sudo apt update && sudo apt install python3 python3-pip python3-venv`
|
||||
* `cd /home/champuser/proj/`
|
||||
* create virtual environment: `python3 -m venv .venv` activate: `. .venv/bin/activate`
|
||||
|
||||
install flask: `pip install flask`
|
||||
|
||||
Create directory for Flask: `mkdir Flask, cd Flask`
|
||||
|
||||
dependencies `pip install Flask-MySQLdb pip install flask-mysql pip install cryptography`
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
if localhost doesn't work, change bind-address in /etc/mysql/mysql.conf.d/mysqld.cnf
|
||||
|
||||
## Filter from application
|
||||
|
||||
* add form action 
|
||||

|
||||
|
||||
* add python form processing
|
||||
|
||||
 
|
||||
|
||||
## for pets db
|
||||
|
||||

|
12
db-security-sec300/week3.md
Normal file
12
db-security-sec300/week3.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Week3
|
||||
Filtering at the Database
|
||||
|
||||
|
||||
- Create a trigger that will replace numbers entered to the cats name with the character 'X'.
|
||||

|
||||
|
||||
- Alter the table cats to add a CHECK that will not allow any cat birthday after 2024-11-23.
|
||||

|
||||
|
||||
- Add another CHECK into cats that restricts the cat's name to 12 characters.
|
||||

|
17
db-security-sec300/week4.md
Normal file
17
db-security-sec300/week4.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Week4
|
||||
Log analysis
|
||||
|
||||
- `sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf`
|
||||
|
||||

|
||||
|
||||
|
||||
- Display failed connect logs, display only date, time, and user
|
||||
```
|
||||
cat /var/log/mysql/query.log | awk -F"[[:space:]T]+" '/Access denied/ {print $1,$2,$9}'
|
||||
```
|
||||
|
||||
- Display successful connect logs, display only date, time, and user
|
||||
```
|
||||
cat /var/log/mysql/query.log | awk -F"[[:space:]T]+" '/Connect/ {print $1,$2,$5}' | grep -v 'Access'
|
||||
```
|
37
db-security-sec300/week5.md
Normal file
37
db-security-sec300/week5.md
Normal file
|
@ -0,0 +1,37 @@
|
|||
# Week5
|
||||
Emailing failed login attempts
|
||||
|
||||
- create App password at: https://security.google.com/settings/security/apppasswordsLinks to an external site.
|
||||
- install ssmtp
|
||||
- `sudo apt-get update && sudo apt-get install ssmtp`
|
||||
|
||||
- edit `/etc/ssmtp/ssmtp.conf`
|
||||
```
|
||||
root=charlotte.croce@mymail,champlain.edu
|
||||
mailhub=smtp.gmail.com:587
|
||||
AuthUser=charlotte.croce@mymail.champlain.edu
|
||||
AuthPass=YourAuthPass
|
||||
UseSTARTTLS=Yes
|
||||
```
|
||||
|
||||
|
||||
- Testing email functionality
|
||||
```
|
||||
echo "To: charlotte.croce@mymail,champlain.edu" > emailform.txt
|
||||
echo "Subject: Database Incident" >> emailform.txt
|
||||
echo "Incident of Database" >> emailform.txt
|
||||
cat emailform.txt | ssmtp charlotte.croce@mymail,champlain.edu
|
||||
```
|
||||
|
||||
- Script to send email with failed login attempts
|
||||
|
||||

|
||||
|
||||
crontab
|
||||
- add permissions so crontab can execute the script
|
||||
- `chmod +x dbsec.bash`
|
||||
- `crontab -l` : list scheduled tasks
|
||||
- `crontab -e` : edit scheduled tasks
|
||||
- run the script every day at 3:35pm
|
||||
- `35 15 * * * /bin/bash -c "/root/dbsec.bash"`
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue