migrate to git.charlotte.sh

This commit is contained in:
Charlotte Croce 2025-04-19 23:42:08 -04:00
commit fbd588721e
412 changed files with 13750 additions and 0 deletions

View 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

View file

@ -0,0 +1,55 @@
# Week1
Summary: Set up mysql, basic queries
### Install mysql-server:
* `sudo apt-get install mysql-server`
![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdPFliHfcxJyOK9EcpTFg086E21yXVxgJZz5gXCXbOkiw8qH8kulFJy4MyjKOoJomBoFtsGkVgGWAMp5z3DMis_Hda2otT6KUCnSJhrDi6sZzykgYYmX3bsgqhLme2bggCzbXi1?key=aDi9OQh-ufWQEzuXd3URpoOQ)
* change bind address via `/etc/mysql/mysql.conf.d/mysqld.cnf`![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeGjZtbVFOHn9cjlkkew7w_A0YNNaGV5XepJ15r091W4LaWaj51D4BBdPFjT5N2TV6hhuMhYUaBPsrtPg9NfMVwhWyAK18DrNFUqG3HYBcgamPCs45LGOFHl2zGWdaO9t0-fLY?key=aDi9OQh-ufWQEzuXd3URpoOQ)
* 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;`
![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdlvLE49RvjHQiyucG79dyVIohHu3qnyrDPOEFOOvUJEhIb8bxhtCT7ba8SkgWT-nVApwqg22IDQ5w8hx1TNCiSlhA9HMIgE_4mMvw8Ji-lz7CKvN33oG-ZdxW6NzVwJk_Vkcn8?key=aDi9OQh-ufWQEzuXd3URpoOQ)
* add data to table: `INSERT INTO requests (fname, email, rdate, uid) VALUES ( 'dummy', 'dummy@dummy.edu', '2024-11-12', 'nsk31fhenfJF024');`![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXc_GuGlbOQitjuCJbrgURaAGcqcndwuWmBpjxnpkbHUQ6x58zJtF2Q_xA9PyCKEbs9aOsatZAL6u80-fQHTBI1Eca5HpWurp8hSwfLD5sL_JoQNfaYJ8u8OwWmcbtxMDlZ2yFbI?key=aDi9OQh-ufWQEzuXd3URpoOQ)
### HW
![](<../assets/63700441181267143731.png>)
1: Write an SQL query that displays name and birth of cats whose names are Siggy
![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXf_wUTuyRVkT6DUoJCL4ILqzz23ZzZlHl2PuKfbdpGRgFYAfWd2QKuyAZjJ2WRowefQSZA1Y4DIO-6YXcNZ7JyRs9LiG-F6bcGumW6MjZnod6iRY9h0Cl16AcQxEeceub1l2OZQ?key=aDi9OQh-ufWQEzuXd3URpoOQ)
2: Write an SQL query that displays name and birth of cats whose owners names are starting with the letter 'F'
![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdBbRLxx7MylSUPgkJdsIZV-g6qP4f6CCI1TmryLwcWpN8bpYK62Lda1PYeY6Mfz0gMeNFHsoheL27e9mhPo0iEhE4TjWwHWPx5F9yy_UaA-cvFWJhPmgV8q_OOQIU7IHTM8rJL?key=aDi9OQh-ufWQEzuXd3URpoOQ)
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
![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXe3LtKLAV8a8zVOgzyyKGdrXc0o7Vk60s4uTiFcImqlwAHbJRJNtDiyFZ_i8cmcmQtHPau2nJAjliZ73SJdKsW1vllJlzNDpTFBLeHtwPr086xFKktPgObUXKD5kOuHT-XijDYP?key=aDi9OQh-ufWQEzuXd3URpoOQ)
4: Write an SQL query that displays names of owners who has no cats
![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdJo5G58de6UKRTEqe56CNrodFTDxlIVWyLP0zgLAtt0AEwW8AhsGDY1-gqdlgE9xJIrva-7lhBWypYgz6-IVrlj4KFDD3h3q2NNex4gInncKzer2Khs_2IUpZj-iVGj1dRX5dd?key=aDi9OQh-ufWQEzuXd3URpoOQ)

View file

@ -0,0 +1,41 @@
# Week2
## DB Webserver Connection
* create user for remote access:
![](<../assets/92898586767705871114.png>)
* 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`
![](<../assets/03636611901023297692.png>)
![](<../assets/72766234477222890914.png>)
![](<../assets/19930188638651808078.png>)
![](<../assets/33901315023577898721.png>)
if localhost doesn't work, change bind-address in /etc/mysql/mysql.conf.d/mysqld.cnf
## Filter from application
* add form action&#x20;
![](../assets/formaction.png)
* add python form processing
&#x20;![](<../assets/62052853300074043448.png>)
## for pets db
![](<../assets/53438651249532045143.png>)

View 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'.
![image](../assets/1ae0ed12-ac5c-4a8a-bb70-cbfbe1b28a3a.png)
- Alter the table cats to add a CHECK that will not allow any cat birthday after 2024-11-23.
![image](../assets/fd5cfed4-9f89-46ea-82e9-e5f8f593a8c2.png)
- Add another CHECK into cats that restricts the cat's name to 12 characters.
![image](../assets/e7adaa35-9aaa-4f0c-8a93-4f4ded361027.png)

View file

@ -0,0 +1,17 @@
# Week4
Log analysis
- `sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf`
![image](../assets/8c9e506d-5da1-4907-8773-2ef2dc7cd53b.png)
- 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'
```

View 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
![image](../assets/9587f614-c944-4943-9d33-aedb0e477008.png)
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"`