Don't let errors stop you! This episode focuses on practical debugging techniques for both PowerShell and Bash scripts. We'll intentionally introduce common errors (like typos or wrong parameters) and walk through how to identify and fix them, building crucial troubleshooting skills.
Powershell Script:
#Script to log multiple event IDs
$BeginTime = (Get-Date).AddMinutes(-20)
Get-EventLog -LogName "Securityy" -After $BeginTime |
Where-Object { $_.EventID -in '4624', '4625'} |
Select-Object TimeGenerated, EventID, Message |
Format-Table -AutoSize |
Out-Files C:\EventLogs_MultipleEvents.txt
BASH Script:
#!/bin/bash
#Variables
USERNAME="testuser" # User accountname
PASSWORD="P@ssw0rd" # User password
GROUP="testgroup" # Custom groupname
SSH_DIR="/home/$USERNAME/.ssh"
PUB_KEY="ssh-rsa AAAAB3...your-public-key... user@kali"
#Step 1: Check ifuser already exists
if id "$USERNAME" &>/dev/null; then
echo "Error: User '$USERNAME'already exists!"
exit 1
fi
#Step 2: Create userand set password
echo "Creating user '$USERNAME'..."
useradd -m -n -s /bin/bash "$USERNAME" # Error 1: -n is an invalidoption
if [ $? -ne 0 ]; then
echo "Error: Failed to create user'$USERNAME'"
exit 1
fi
echo "$USERNAME:$PASSWORD" | chpasswd
echo "Password set for user '$USERNAME'."
#Step 3: Add user tosudoers
echo "Granting sudo access to '$USERNAME'..."
usermod -aG sudo "$USERNAME"
if [ $? -ne 0 ]; then
echo "Error: Failed to add'$USERNAME' to sudoers"
exit 1
fi
#Step 4: Createcustom group and add user
echo "Creating group '$GROUP' and adding user..."
groupadd "$GROUP" 2>/dev/null
usermod -aG "wronggroup" "$USERNAME" # Error 2:"wronggroup" does not exist
if [ $? -ne 0 ]; then
echo "Error: Failed to add'$USERNAME' to group '$GROUP'"
exit 1
fi
#Step 5: Setup SSHkey-based authentication
echo "Setting up SSH key-based authentication..."
mkdir -p "$SSH_DIR"
echo "$PUB_KEY" > "$SSH_DIR/authorized_keys"
chmod 600 "$SSH_DIR/authorized_keys"
chmod 700 "$SSH_DIR"
chown -R "$USERNAME:$USERNAME" "$SSH_DIR"
if [ $? -ne 0 ]; then
echo "Error: Failed to set up SSHkeys"
exit 1
fi
echo "SSH keys configured for '$USERNAME'."
#Step 6: Setpassword expiry to 30 days
echo "Setting password expiry policy for '$USERNAME'..."
chage -M 30 "$USERNAME"
if [ $? -ne 0 ]; then
echo "Error: Failed to setpassword expiry"
exit 1
fi
#Step 7: Logactivity to/var/log/user_setup.log
LOG_FILE="/var/log/user_setup.log"
echo "$(date) - User '$USERNAME' created and configured" >>"$LOG_FILE"
if [ $? -ne 0 ]; then
echo "Error: Failed to write logto $LOG_FILE"
exit 1
fi
#Step 8:Confirmation Message
echo "Testing SSH connection to '$USERNAME'@localhosts..."
ssh "$USERNAME@localhost"
if [ $? -ne 0 ]; then
echo "Error: SSH connection failed."
exit 1
fi
echo "User '$USERNAME' created and configured successfully!"
Master automation in Linux with Bash scripts! Discover how to create and debug scripts for user setup, including creating new users, setting passwords, adding them to groups, configuring SSH key-based login, and setting password expiry. We’ll also cover testing and verification.
Script:
#!/bin/bash
#Variables
USERNAME="Jason" # User account name
PASSWORD="P@ssw0rd" # User password
GROUP="developers" # Custom group name
SSH_DIR="/home/$USERNAME/.ssh"
PUB_KEY="ssh-rsa AAAAB3...your-public-key... user@kali" # Replace with your actual public key
#Step 1: Check if user already exists
if id "$USERNAME" &>/dev/null; then
echo "Error: User '$USERNAME' already exists!"
exit 1
fi
#Step 2: Create user and set password
echo "Creating user '$USERNAME'..."
useradd -m -s /bin/bash "$USERNAME"
if [ $? -ne 0 ]; then
echo "Error: Failed to create user '$USERNAME'"
exit 1
fi
echo "$USERNAME:$PASSWORD" | chpasswd
echo "Password set for user '$USERNAME'."
#Step 3: Add user to sudoers
echo "Granting sudo access to '$USERNAME'..."
usermod -aG sudo "$USERNAME"
if [ $? -ne 0 ]; then
echo "Error: Failed to add '$USERNAME' to sudoers"
exit 1
fi
#Step 4: Create custom group and add user
echo "Creating group '$GROUP' and adding user..."
groupadd "$GROUP" 2>/dev/null
usermod -aG "$GROUP" "$USERNAME"
if [ $? -ne 0 ]; then
echo "Error: Failed to add '$USERNAME' to group '$GROUP'"
exit 1
fi
#Step 5: Setup SSH key-based authentication
echo "Setting up SSH key-based authentication..."
mkdir -p "$SSH_DIR"
echo "$PUB_KEY" > "$SSH_DIR/authorized_keys"
chmod 600 "$SSH_DIR/authorized_keys"
chmod 700 "$SSH_DIR"
chown -R "$USERNAME:$USERNAME" "$SSH_DIR"
if [ $? -ne 0 ]; then
echo "Error: Failed to set up SSH keys"
exit 1
fi
echo "SSH keys configured for '$USERNAME'."
#Step 6: Set password expiry to 30 days
echo "Setting password expiry policy for '$USERNAME'..."
chage -M 30 "$USERNAME"
if [ $? -ne 0 ]; then
echo "Error: Failed to set password expiry"
exit 1
fi
#Step 7: Log activity to /var/log/user_setup.log
LOG_FILE="/var/log/user_setup.log"
echo "$(date) - User '$USERNAME' created and configured" >> "$LOG_FILE"
if [ $? -ne 0 ]; then
echo "Error: Failed to write log to $LOG_FILE"
exit 1
fi
#Step 8: Confirmation Message
echo "User '$USERNAME' created and configured successfully!"
Unlock automation on Windows! We'll start with PowerShell basics, showing you how to write, execute, and expand simple scripts to display messages, get dates, list processes, and manage services. Learn to automate tasks efficiently on Windows Server 2022.
Commands:
.\WelcomeScript.ps1
Get-Date
Get-Process
Get-Service | Where-Object { $_.Status -eq 'Running' }
Get-WmiObject -Class Win32_Product | Select-Object Name,Version
Get-NetIPAddress
Explore active information gathering in Linux! This episode teaches you how to enumerate a vulnerable Bee-Box machine using Kali Linux tools. You'll learn Nmap for identifying open ports and services, and Metasploit for deeper SMTP enumeration, strengthening your reconnaissance skills.
Link: Bee-Box official download page
Commands: nmap -Pn -sS –sV <Bee-Box IP Address>
nmap -Pn -sS -sV -p 25 <Bee-Box IP Address>
auxiliary/scanner/smtp/smtp_enum
set RHOSTS <IP of the Bee-Box>
set THREADS <Number of Logical Processors>
Uncover the hidden information on Windows systems! Learn how to use Microsoft's powerful PsTools suite to gather system information, track user sessions, enumerate services, and analyze event logs on a Windows Server 2022. We'll explorecommands like pslist.exe, psloglist.exe, and saving output to files.
PsTools Link: https://learn.microsoft.com/en-us/sysinternals/downloads/pstools.
Commands: .\pslist.exe
.\psloggedon.exe
.\psloglist.exe
.\psservice.exe
Save output by:
.\psloglist.exe >> C:\Logdata.txt
Get your target ready! This episodeguides you through downloading and setting up a Windows Server 2022 virtualmachine within VMware. We'll walk through the installation processstep-by-step, preparing a vulnerable environment for your ethical hacking adventures.
Link I used for myself: https://www.microsoft.com/en-us/evalcenter/download-windows-server-2022.
Episode 1: Building Your Digital Lab – VMware & Kali Linux Setup
Kick off your cybersecurity journey with the essentials! In this episode, we guide you through creating a secure virtualized environment by installing VMware Workstation and setting up your Kali Linux virtual machine for penetration testing. From downloading the ISO to configuring your VM settings, we’ll walk you through every step to build your personal digital lab.
👉 Download VMware Workstation here: https://www.techspot.com/downloads/189-vmware-workstation-for-windows.html
🎙️ Series 4: Laying the Foundations
Kickstart your cybersecurity journey with hands-on labs and real-world skills! In this series, we’ll set up virtual machines, explore Windows and Linux systems, and dive into scripting, debugging, and securing environments. Perfect for beginners and aspiring ethical hackers.
Episodes:
1️⃣ Building Your Digital Lab – Set up VMware Workstation and Kali Linux for penetration testing.
2️⃣ Deploying Your Target – Install Windows Server 2022 as a vulnerable lab machine.
3️⃣ Windows Deep Dive – Use PsTools to enumerate users, services, and event logs.
4️⃣ Linux Reconnaissance – Master Nmap and Metasploit against a Bee-Box target.
5️⃣ Powering Up with PowerShell – Learn the basics of scripting and automation on Windows.
6️⃣ Bash Scripting Essentials – Automate user management and SSH setup in Kali Linux.
7️⃣ Debugging Your Code – Fix common PowerShell and Bash scripting errors.
8️⃣ Memory Matters – Explore program memory layouts and forensic queries with PowerShell.
9️⃣ Files & Formats – Work with FAT32 and NTFS, file operations, and permissions.
🔟 Locking It Down – Restrict user access and secure folders with NTFS permissions.
Bring all concepts together and let's start working on security together
People - Both strongest and the weakest links
GRC - Governance, Risk and Compliance -> Team leading security at every organization
In this episode, we dive into building breach-ready systems with strong incident detection and response strategies. Learn how to identify threats early, contain damage, and recover fast.
Let's learn about how to secure your infrastructure
Let's start by understanding the first step of building a cyber citadel
Today, we're diving headfirst into the fascinating world of Security and Risk Management.
Get ready to refresh your memory about data protection
During the initial stages of product design, security architects usually come into the picture and perform threat analysis using threat modeling.
Understand what security architects look for in a product
It's time to make it real and start connecting the product worldwith cyber.
In Series 2, Episode 16, uncover the perils of improper authentication methods in the digital landscape. Join us as we dissect real-world cases, highlighting the consequences of weak authentication practices and providing essential guidance on fortifying online security protocols.