WEEK 4: IAS Security Laboratory Activity - M199205zn/IAS-CS4 GitHub Wiki
To understand how encryption protects data confidentiality using the AES-256 encryption algorithm.
-
Open Terminal (Linux/macOS) or Git Bash (Windows).
- If using Windows, ensure OpenSSL is installed. If not, install OpenSSL via Git Bash (
sudo apt install openssl
for Linux).
- If using Windows, ensure OpenSSL is installed. If not, install OpenSSL via Git Bash (
-
Create a plain text file containing a secret message.
echo "This is a secret message" > message.txt
- Verify the file contents using:
cat message.txt
- Verify the file contents using:
-
Encrypt the message using AES-256 encryption.
openssl enc -aes-256-cbc -salt -in message.txt -out encrypted.txt -k mypassword
-
-aes-256-cbc
: Specifies the encryption algorithm (AES-256 in CBC mode). -
-salt
: Adds a random salt to enhance security. -
-in message.txt
: Specifies the input file. -
-out encrypted.txt
: Specifies the output file. -
-k mypassword
: Sets the encryption key (replace with a strong password).
-
-
Verify that the encrypted file is unreadable.
cat encrypted.txt
- You should see unreadable characters, confirming encryption.
-
Decrypt the message.
openssl enc -aes-256-cbc -d -in encrypted.txt -out decrypted.txt -k mypassword
-
-d
: Stands for decryption mode.
-
-
View the decrypted message.
cat decrypted.txt
- The output should match the original message.
-
Discussion Questions:
- What happens if you try to decrypt using a wrong password?
- How does encryption provide confidentiality?
To demonstrate how hashing ensures data integrity using SHA-256.
-
Create a file with important data.
echo "Important data" > data.txt
-
Generate an SHA-256 hash of the file.
sha256sum data.txt
- Output: A unique hash value for the file.
-
Modify the file (simulate an unauthorized change).
echo "New information added" >> data.txt
-
Generate a new hash after modification.
sha256sum data.txt
- The new hash will be different from the original.
-
Discussion Questions:
- Why did the hash change?
- How does hashing help detect unauthorized modifications?
To demonstrate authentication by verifying usernames and passwords using a Python script.
-
Open a text editor (VS Code, Notepad++, or terminal-based editor like nano).
nano authentication.py
-
Write the following Python authentication script.
users = {"admin": "password123", "user1": "securepass"} username = input("Enter username: ") password = input("Enter password: ") if username in users and users[username] == password: print("Access Granted") else: print("Access Denied")
-
Save the file and exit.
- In nano, press
CTRL + X
, thenY
, thenEnter
.
- In nano, press
-
Run the script.
python3 authentication.py
-
Test different login attempts.
- Enter correct credentials (
admin / password123
). - Enter incorrect credentials.
- Enter correct credentials (
-
Discussion Questions:
- What happens when the username or password is incorrect?
- How can we improve this authentication system?
- How do these security mechanisms protect data and users?
- Where are these techniques used in real-world applications?
- What are the weaknesses of basic encryption, hashing, and authentication?
💡 Prerequisites:
- Install OpenSSL for Windows: Download OpenSSL
- Use Command Prompt (CMD) or PowerShell
- Install Python (for Task 3) if not installed: Download Python
- Press
Win + R
, typecmd
, and press Enter - OR press
Win + X
, select PowerShell
cd C:\Users\YourUsername\Documents
💡 This step ensures that files are stored in an easily accessible location.
echo This is a secret message > message.txt
- To verify, type:
type message.txt
openssl enc -aes-256-cbc -salt -in message.txt -out encrypted.txt -k mypassword
📌 Explanation:
-
-aes-256-cbc
: Uses AES-256 encryption -
-salt
: Adds randomness for extra security -
-in message.txt
: Input file -
-out encrypted.txt
: Output encrypted file -
-k mypassword
: Encryption key (change the password)
type encrypted.txt
💡 You should see random unreadable characters.
openssl enc -aes-256-cbc -d -in encrypted.txt -out decrypted.txt -k mypassword
📌 Explanation:
-
-d
flag means decrypt
type decrypted.txt
💡 The output should match the original text.
- What happens if you try decrypting with the wrong password?
- How does encryption ensure confidentiality?
echo Important data > data.txt
certutil -hashfile data.txt SHA256
📌 This will output a unique hash value for the file.
echo New information added >> data.txt
certutil -hashfile data.txt SHA256
💡 The hash will change, indicating the file has been altered.
- Why did the hash change?
- How does hashing provide integrity?
- Open Notepad or VS Code
- Copy and paste the following Python code:
# Simple Authentication System
users = {"admin": "password123", "user1": "securepass"}
Get user input
username = input("Enter username: ")
password = input("Enter password: ")
Check authentication
if username in users and users[username] == password:
print("Access Granted")
else:
print("Access Denied")
-
Save the file as
authentication.py
inC:\Users\YourUsername\Documents
.
python C:\Users\YourUsername\Documents\authentication.py
💡 Test different login attempts:
-
Correct login: Enter
admin
andpassword123
. - Wrong login: Enter incorrect credentials.
- What happens when the username or password is incorrect?
- How can authentication be improved? (E.g., hashing passwords)
- Encryption (Confidentiality) – How does AES-256 encryption protect messages?
- Hashing (Integrity) – Why does a modified file have a different hash?
- Authentication – How does user authentication prevent unauthorized access?
Criteria | Description | Points |
---|---|---|
Encryption Task | Successfully encrypts and decrypts a message | 5 |
Hashing Task | Demonstrates understanding of hashing and integrity | 5 |
Authentication Task | Runs the authentication script and explains results | 5 |
Discussion & Reflection | Answers discussion questions effectively | 5 |
✅ This activity ensures students gain hands-on experience with real security services and mechanisms in a Windows environment. 🚀 Let me know if you need modifications!