Hello, security detective! You have learned the basics of MySQL, advanced queries, and how to combine tables. Now, in Module Six, we will use MySQL to hunt for threats! Threat hunting means actively searching for hidden dangers in your data. We will learn how to use MySQL to find suspicious patterns, detect attacks, and protect our systems.
In Module Four, you learned the basics of MySQL โ how to create tables, add data, read data, update data, and delete data. In Module Five, you learned advanced skills like JOIN, GROUP BY, HAVING, subqueries, LIKE, and LIMIT. Now, in Module Six, we will put all of these skills together to hunt for threats.
Threat hunting is like being a detective. Instead of waiting for an alarm to go off, you actively search for clues that something is wrong. MySQL is a powerful tool for threat hunting because it can search through millions of records quickly. By the end of this module, you will be able to use MySQL to find suspicious activities, investigate incidents, and keep systems safe.
Remember: The best hunters are always looking for clues. Let's start hunting!
After this module, you will be able to:
Ade is 10 years old and lives in Ibadan. His father works at a bank. One morning, Ade's father told him that someone had been trying to log into the bank's system late at night. The security team was worried, but they couldn't find the culprit.
Ade had just learned MySQL in his SOC Analyst course. He asked his father, "Can I see the login logs?" His father gave him a copy of the logs. Ade opened MySQL and started writing queries. He searched for failed logins after 10 PM. He found dozens of failed attempts โ all from the same IP address!
He then used a JOIN to combine the login logs with the user table. He found that the IP address belonged to a former employee who had left the company. The security team blocked the IP address and improved their security. Ade's father was so proud of him.
Ade said, "MySQL is like a superpower! It helped me find the bad guy."
Question for you: What would you do if you found suspicious activity in a system?
Definition: Threat hunting is actively searching for hidden threats in a system. It's not waiting for an alarm โ it's looking for clues.
Why it is important: Many attacks go unnoticed for months. Threat hunting helps us find them early.
Simple explanation: It's like being a detective who looks for clues before a crime happens.
Real-life example: A security team searches for unusual logins every day.
School example: A teacher checks who is accessing the school's computer system late at night.
Home example: A parent checks who is using their smart devices at odd hours.
Nigerian example: A bank searches for suspicious transactions.
Threat Hunting = Active Search - Look for patterns - Find anomalies - Investigate suspicious activities
Mini summary: Threat hunting is actively searching for hidden dangers.
Definition: A security database is a collection of security-related data, like login logs, access logs, and system events.
Why it is important: We need a place to store and organise security data so we can search it.
Simple explanation: It's like having a detective's notebook to write down all the clues.
Real-life example: A company creates a table to store all login attempts.
School example: A school creates a table to track who uses the computer lab.
Home example: A family creates a table to track who logs into their smart devices.
Nigerian example: A bank creates a table to track all transactions.
Security Database Tables: - login_logs (id, user_id, login_time, success, ip_address) - users (id, name, email, role) - system_events (id, event_type, description, time)
Mini summary: A security database helps us store and organise security data.
Definition: Failed login attempts are times when someone tries to log in but gets the password wrong. This can be a sign of an attack.
Why it is important: Many failed attempts might mean someone is trying to break into the system.
Simple explanation: It's like someone trying to open a locked door with the wrong key again and again.
Real-life example: A hacker tries 100 different passwords to get into a system.
School example: A student tries to guess a teacher's password.
Home example: Someone tries to guess your smart device password.
Nigerian example: A fraudster tries to guess a customer's bank password.
Query for failed logins: SELECT * FROM login_logs WHERE success = false;
Mini summary: Failed login attempts can indicate an attack.
Definition: Logins that happen after normal working hours can be suspicious.
Why it is important: Most employees don't log in at 2 AM. If someone does, it might be an attacker.
Simple explanation: It's like hearing someone in your house at midnight โ it's not normal.
Real-life example: An employee logs in at 3 AM from a different country.
School example: A student logs into the school system at 1 AM.
Home example: A family member logs into a streaming service at 4 AM.
Nigerian example: A bank employee logs in at 2 AM from an unusual location.
Query for after-hours failed logins: SELECT * FROM login_logs WHERE success = false AND TIME(login_time) > '22:00:00';
Mini summary: After-hours logins can be a sign of an attack.
Definition: An IP address is a unique number that identifies a device on the internet. Suspicious IP addresses are those from unknown or suspicious locations.
Why it is important: Attackers often use IP addresses from other countries to hide their identity.
Simple explanation: It's like a stranger coming to your house โ you don't know who they are.
Real-life example: An IP address from a country where the company doesn't operate.
School example: An IP address from a different city accessing the school system.
Home example: An unknown device connecting to your Wi-Fi.
Nigerian example: A transaction from an IP address outside Nigeria.
Query for suspicious IPs: SELECT * FROM login_logs WHERE ip_address NOT LIKE '192.168.%' AND ip_address NOT LIKE '10.%';
Mini summary: Suspicious IP addresses can indicate an attack.
Definition: Unusual behaviour means a user is doing something they don't normally do, like logging in at odd times or from different locations.
Why it is important: Unusual behaviour can mean an account has been hacked.
Simple explanation: It's like your friend suddenly acting differently โ something might be wrong.
Real-life example: An employee who always logs in from Lagos suddenly logs in from London.
School example: A student who always logs in during school hours suddenly logs in at midnight.
Home example: A family member who never uses the TV suddenly starts streaming at 3 AM.
Nigerian example: A bank customer who always uses a specific branch suddenly uses a branch in another state.
Query for unusual behaviour: SELECT user_id, COUNT(*) AS login_count FROM login_logs WHERE login_time BETWEEN '00:00:00' AND '05:00:00' GROUP BY user_id HAVING login_count > 3;
Mini summary: Unusual behaviour can mean an account is compromised.
Definition: A brute force attack is when an attacker tries many passwords in a short time to guess the right one.
Why it is important: Brute force attacks are very common. They can break into systems if the passwords are weak.
Simple explanation: It's like trying every key in a keyring until you find the right one.
Real-life example: An attacker tries 10,000 passwords in one hour.
School example: A student tries 100 different passwords to get into the school system.
Home example: Someone tries to guess your Wi-Fi password.
Nigerian example: A fraudster tries to guess a bank customer's PIN.
Query for brute force: SELECT user_id, COUNT(*) AS attempts FROM login_logs WHERE success = false AND login_time BETWEEN NOW() - INTERVAL 1 HOUR AND NOW() GROUP BY user_id HAVING attempts > 50;
Mini summary: Brute force attacks try many passwords quickly.
Definition: If many failed logins come from the same IP address, it could be an attacker.
Why it is important: Attackers often try many accounts from the same IP address.
Simple explanation: It's like someone trying all the doors in a building to find one that is unlocked.
Real-life example: An attacker uses one computer to try to hack into many accounts.
School example: A student from one computer tries to access many student accounts.
Home example: A device on your network tries to access many services.
Nigerian example: An attacker uses one IP to try to hack into a bank's customer accounts.
Query for same IP failed logins: SELECT ip_address, COUNT(*) AS attempts FROM login_logs WHERE success = false GROUP BY ip_address HAVING attempts > 5;
Mini summary: Multiple failed logins from the same IP can indicate an attack.
Definition: Unusual locations are places where a user doesn't normally log in from.
Why it is important: If a user logs in from a different country, their account might be hacked.
Simple explanation: It's like your friend suddenly calling you from a different country.
Real-life example: A user logs in from Nigeria and then 10 minutes later from the UK.
School example: A student logs in from home and then from a different city.
Home example: A family member logs into their email from two different places.
Nigerian example: A bank customer logs in from Lagos and then from Kano in 5 minutes.
Query for unusual locations: SELECT user_id, ip_address, login_time FROM login_logs WHERE ip_address NOT LIKE '192.168.%' ORDER BY user_id, login_time;
Mini summary: Logins from unusual locations can indicate account compromise.
Definition: Combining clues means using multiple queries to find a pattern.
Why it is important: A single clue might not mean anything, but several clues together can reveal an attack.
Simple explanation: It's like putting together a jigsaw puzzle โ each piece is a clue.
Real-life example: Failed logins + unusual IP + after-hours = likely attack.
School example: Failed logins + late at night + different city = suspicious.
Home example: Multiple failed logins + unknown device = security threat.
Nigerian example: Failed logins + unusual location + after-hours = fraud attempt.
Combined Query: SELECT users.name, logs.ip_address, logs.login_time FROM login_logs logs JOIN users ON logs.user_id = users.id WHERE logs.success = false AND TIME(logs.login_time) > '22:00:00' AND logs.ip_address NOT LIKE '192.168.%' ORDER BY logs.login_time DESC;
Mini summary: Combining clues helps us detect hidden attacks.
Definition: Subqueries can help us find users who have multiple suspicious activities.
Why it is important: Some attackers are very active. Subqueries help us find them.
Simple explanation: It's like asking a question, then asking another question based on the answer.
Real-life example: Find users who have had more than 3 failed logins and a login from an unusual IP.
School example: Find students who have failed logins and late-night access.
Home example: Find family members who have failed logins and unusual activity.
Nigerian example: Find customers who have failed logins and unusual transactions.
Subquery Example:
SELECT name FROM users
WHERE id IN (
SELECT user_id FROM login_logs
WHERE success = false
GROUP BY user_id
HAVING COUNT(*) > 5
);
Mini summary: Subqueries help us find users with multiple suspicious activities.
Definition: LIKE can help us find suspicious patterns in text, like email addresses or IP addresses.
Why it is important: Attackers often use patterns, like fake email addresses.
Simple explanation: It's like searching for a word in a book.
Real-life example: Finding all emails from a suspicious domain.
School example: Finding all students with fake email addresses.
Home example: Finding all devices with suspicious MAC addresses.
Nigerian example: Finding all transactions with suspicious reference numbers.
LIKE Query: SELECT * FROM users WHERE email LIKE '%hacker%'; SELECT * FROM login_logs WHERE ip_address LIKE '10.0.%';
Mini summary: LIKE helps us find patterns in text data.
Definition: Date and time functions help us analyse data over time.
Why it is important: Attacks often happen at specific times.
Simple explanation: It's like checking the clock to see when something happened.
Real-life example: Finding all logins in the last 24 hours.
School example: Finding all access to the school system in the last week.
Home example: Finding all smart device usage in the last hour.
Nigerian example: Finding all transactions in the last month.
Date/Time Queries: SELECT * FROM login_logs WHERE login_time > NOW() - INTERVAL 1 DAY; SELECT * FROM login_logs WHERE DATE(login_time) = CURDATE();
Mini summary: Date/time functions help us analyse data over time.
Definition: Practice means using your skills on real-world data.
Why it is important: Practice helps you think like a detective.
Simple explanation: Like a fire drill โ you practise so you're ready for the real thing.
Real-life example: A security team practices threat hunting every month.
School example: Students practice hunting for threats in a lab environment.
Home example: A parent practices monitoring their devices.
Nigerian example: A bank practices threat hunting on test data.
Practice Scenario: You have a login_logs table. Write queries to find: 1. All failed logins in the last 24 hours. 2. All logins after 11 PM. 3. All logins from unusual IP addresses. 4. Users with more than 10 failed logins.
Mini summary: Practice makes you a better threat hunter.
Definition: A threat hunter is someone who actively searches for hidden threats. You have become one!
Why it is important: Your skills can help protect systems and stop attacks.
Simple explanation: You are now a digital detective.
Real-life example: You can help a company find suspicious activities.
School example: You can help your school protect its network.
Home example: You can help your family protect their devices.
Nigerian example: You can help a bank detect fraud.
You โ Learned threat hunting โ Can protect systems! ๐
Mini summary: You are now a threat hunter โ congratulations!
Step 1: Set up database Step 2: Collect data Step 3: Define normal behaviour Step 4: Write queries for anomalies Step 5: Analyse results Step 6: Take action Step 7: Review and improve
Define Normal
|
V
Collect Data
|
V
Write Queries
|
V
Analyse Results
|
V
Identify Anomalies
|
V
Investigate
|
V
Take Action
|
V
Review and Improve
| Normal Activity | Suspicious Activity |
|---|---|
| Logins during working hours | Logins after midnight |
| Logins from known IPs | Logins from unknown IPs |
| Few failed logins | Many failed logins |
| Logins from one location | Logins from multiple locations |
| Query Purpose | Example Query |
|---|---|
| Failed logins | SELECT * FROM login_logs WHERE success = false; |
| After-hours logins | SELECT * FROM login_logs WHERE TIME(login_time) > '22:00:00'; |
| Unusual IPs | SELECT * FROM login_logs WHERE ip_address NOT LIKE '192.168.%'; |
| Brute force | SELECT user_id, COUNT(*) FROM login_logs WHERE success = false GROUP BY user_id HAVING COUNT(*) > 10; |
| Combined clues | SELECT users.name, logs.ip_address FROM login_logs logs JOIN users ON logs.user_id = users.id WHERE logs.success = false AND TIME(logs.login_time) > '22:00:00'; |
Lesson 1: What is threat hunting?
|
Lesson 2: Setting up a security database
|
Lesson 3: Finding failed logins
|
Lesson 4: After-hours logins
|
Lesson 5: Suspicious IP addresses
|
Lesson 6: Unusual user behaviour
|
Lesson 7: Brute force attacks
|
Lesson 8: Multiple failed logins from same IP
|
Lesson 9: Logins from unusual locations
|
Lesson 10: Combining clues
|
Lesson 11: Subqueries
|
Lesson 12: LIKE for threat hunting
|
Lesson 13: Date/time functions
|
Lesson 14: Practice
|
YOU ARE A THREAT HUNTER! ๐
Congratulations! You have completed Module Six of your Security Operation Centre Analyst training. You have learned how to use MySQL for threat hunting. You can now find failed logins, after-hours activity, suspicious IP addresses, and brute force attacks. You have learned to combine clues and use advanced queries to find hidden threats. You are now a true threat hunter!
Match the term to its description:
| Term | Description |
|---|---|
| Threat Hunting | Actively searching for threats |
| Brute Force | Trying many passwords |
| IP Address | Device identifier |
| Failed Login | Unsuccessful login attempt |
| After-Hours | Time outside normal hours |
Scenario 1: You are a SOC Analyst. You notice that there are many failed logins from a specific IP address. Write a query to find all failed logins from that IP in the last 24 hours.
Scenario 2: You have a table of login logs. You want to find all users who have more than 5 failed logins after 10 PM. Write the query.
Scenario 3: You notice that a user has logged in from two different cities in 5 minutes. Write a query to find all users with logins from different locations within a short time.
Threat Hunting Challenge: In groups of 4, you are given a sample database with login logs. Your task is to write queries to find at least 5 suspicious activities. Present your findings to the class and explain why they are suspicious.
My Threat Hunt: Create a database with sample login logs. Write queries to find failed logins, after-hours logins, and suspicious IP addresses. Write a report on your findings.
Task: Build a simple dashboard that shows the results of your threat hunting queries. Include tables for failed logins, after-hours logins, suspicious IPs, and brute force attempts. Present your dashboard to the class.
Assignment: Find a real-world dataset of security logs (or use sample data). Write at least 5 threat hunting queries and document your findings. Explain what each query does and what it found.
Challenge: Write a complex query that finds all users who have had more than 10 failed logins in the last 24 hours, and then joined by a login from an unusual IP address. Use JOIN, GROUP BY, HAVING, and subqueries.
Fill-in-the-Blank Answers: 1. Threat hunting, 2. brute force, 3. IP, 4. After, 5. Unusual, 6. false, 7. subquery, 8. Combining, 9. MySQL, 10. Practice, 11. night, 12. brute force, 13. locations, 14. Date/time, 15. threat.
True or False: 1F, 2T, 3F, 4F, 5T, 6T, 7T, 8F, 9T, 10T.
Multiple Choice Answers: 1B, 2B, 3B, 4A, 5B, 6B, 7A, 8A, 9A, 10B, 11A, 12A, 13A, 14A, 15A.
In Module Seven, we will learn about incident response โ what to do when a security incident happens. You will learn how to contain an attack, investigate it, and recover from it. We will also look at how MySQL can help in incident response.
Before next class: Think about what you would do if you discovered a security breach. We will explore this together in the next module.
๐ก๏ธ You have completed Module Six โ keep up the great work! ๐ก๏ธ