Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ~/.bashrc

# Enable colorful ls and grep output
export CLICOLOR=1
export LS_COLORS='di=34:fi=0:ln=35:pi=33:so=32:bd=46:cd=43:ex=31'

# Helpful aliases
alias ll='ls -alF'
alias la='ls -A'
alias ..='cd ..'
alias cls='clear'

# Enable color for grep
alias grep='grep --color=auto'

# Make prompt user-friendly
PS1='\[\e[32m\]\u@\h\[\e[m\]:\[\e[34m\]\w\[\e[m\]\$ '

# Only add to PATH if it isn't already there
if [[ ":$PATH:" != *":$(pwd)/bin:"* ]]; then
export PATH="$PATH:$(pwd)/bin"
fi

./bin/repo.sh
48 changes: 25 additions & 23 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{
"editor.bracketPairColorization.enabled": true,
"editor.cursorBlinking": "solid",
"editor.fontFamily": "ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace",
"editor.fontLigatures": false,
"editor.fontSize": 22,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.lineNumbers": "on",
"editor.matchBrackets": "always",
"editor.minimap.enabled": false,
"editor.smoothScrolling": true,
"editor.tabSize": 2,
"editor.useTabStops": true,
"emmet.triggerExpansionOnTab": true,
"explorer.openEditors.visible": 0,
"files.autoSave": "afterDelay",
"screencastMode.onlyKeyboardShortcuts": true,
"terminal.integrated.fontSize": 18,
"workbench.activityBar.visible": true,
"workbench.colorTheme": "Visual Studio Dark",
"workbench.fontAliasing": "antialiased",
"workbench.statusBar.visible": true
}
"editor.bracketPairColorization.enabled": true,
"editor.cursorBlinking": "solid",
"editor.fontFamily": "ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace",
"editor.fontLigatures": false,
"editor.fontSize": 22,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.lineNumbers": "on",
"editor.matchBrackets": "always",
"editor.minimap.enabled": false,
"editor.smoothScrolling": true,
"editor.tabSize": 2,
"editor.useTabStops": true,
"emmet.triggerExpansionOnTab": true,
"explorer.openEditors.visible": 0,
"files.autoSave": "afterDelay",
"screencastMode.onlyKeyboardShortcuts": true,
"terminal.integrated.fontSize": 18,
"workbench.colorTheme": "Visual Studio Dark",
"workbench.fontAliasing": "antialiased",
"workbench.statusBar.visible": true,
"githubPullRequests.ignoredPullRequestBranches": [
"main"
]
}
7 changes: 7 additions & 0 deletions bin/clean_temp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

TARGET="/home/user/downloads"

find $TARGET -type f -name "*.tmp" -delete

echo "Temporary files removed!"
84 changes: 84 additions & 0 deletions bin/create_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

#!/bin/bash

# ----------------------------------------------------------------------
# Codespaces User Creation Script
# Usage: ./create_user.sh <username> <group> <password>
#
# This script creates a new user, adds them to the specified groups (sudo, adm, <group>),
# and sets a non-interactive password. It uses a temporary directory for the home
# path to avoid Codespaces permission issues.
# ----------------------------------------------------------------------

# --- 1. Argument Validation ---
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <username> <group> <password>"
echo "Example: $0 kirk trek abc123"
exit 1
fi

USERNAME=$1
EXTRA_GROUP=$2
PASSWORD=$3
USER_GROUPS="sudo,adm,${EXTRA_GROUP}" # Dynamically include the passed-in group
HOME_DIR="/tmp/${USERNAME}_home" # Codespaces workaround for home directory

# --- 1b. Validate extra group exists ---
if ! getent group "${EXTRA_GROUP}" > /dev/null; then
echo "🛑 Error: Group '${EXTRA_GROUP}' does not exist."
echo "Create it with: sudo groupadd ${EXTRA_GROUP}"
exit 5
fi

echo "Starting user creation script for user: ${USERNAME}"

# --- 2. Check if User Exists ---
# 'id -u' returns 0 if the user exists, and non-zero (1) if they don't.
if id -u "${USERNAME}" &> /dev/null; then
echo "🛑 User '${USERNAME}' already exists. Exiting."
exit 2
fi

# --- 3. User Creation ---

# Create the user:
# -m: Create the home directory (in /tmp/...)
# -d: Specify the custom home directory (the Codespaces workaround)
# -G: Specify secondary groups (sudo, adm, <group>)
# -s: Specify the login shell (/bin/bash)
# Note: Using 'sudo' is mandatory for these administrative commands.

echo "1. Creating user '${USERNAME}' with home directory at ${HOME_DIR}..."
sudo useradd \
-m \
-d "${HOME_DIR}" \
-G "${USER_GROUPS}" \
-s /bin/bash \
"${USERNAME}"

if [ $? -ne 0 ]; then
echo "🛑 Error: Failed to create user. Check sudo permissions."
exit 3
fi

# --- 4. Password Setting (Non-Interactive) ---

# Use chpasswd to set the password without prompting.
echo "2. Setting non-interactive password..."
echo "${USERNAME}:${PASSWORD}" | sudo chpasswd

if [ $? -ne 0 ]; then
echo "🛑 Error: Failed to set password. Check chpasswd command."
# Clean up the user if password fails
sudo userdel -r "${USERNAME}" &> /dev/null
exit 4
fi

# --- 5. Confirmation ---

echo ""
echo "✅ SUCCESS: User '${USERNAME}' created and configured."
echo " - Groups: ${USER_GROUPS}"
echo " - Home: ${HOME_DIR}"
echo ""
echo "Try logging in: su - ${USERNAME}"
100 changes: 100 additions & 0 deletions bin/find_users.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash

# ----------------------------------------------------------------------
# Pattern Matching Lab Setup Script
# Usage: sudo ./find_users.sh <user1,user2,...> <group_name>
#
# Creates users, assigns them to groups, and injects random security issues
# to be found by the 'grep' and 'find' commands.
# ----------------------------------------------------------------------

# --- Configuration ---
# The string we'll search for with grep
SUSPECT_KEYWORD="[UNAUTHORIZED_MODIFICATION_ALERT_X9]"
# The permission we'll search for with find
VULNERABLE_PERM="777"
DEFAULT_PERM="755"
DEFAULT_PASSWORD="abc123"


# --- 1. Input Validation ---
if [ "$#" -ne 2 ]; then
echo "Error: Two arguments are required."
echo "Usage: sudo $0 <user1,user2,...> <group_name>"
echo "Example: sudo $0 kirk,spock,uhura trek"
exit 1
fi

USER_CSV="$1"
GROUP_NAME="$2"
QUOTE_MESSAGE="I'm in the ${GROUP_NAME} group!"

echo "--- Starting Setup for Group: ${GROUP_NAME} ---"

# --- 2. Group Management (Silent Creation) ---
# The -f (force) flag prevents an error if the group already exists.
groupadd -f "${GROUP_NAME}" 2> /dev/null
if [ $? -eq 0 ]; then
echo "Group '${GROUP_NAME}' checked/created successfully."
fi

# --- 3. User Creation and Injection Loop ---
IFS=',' read -ra USERS_ARRAY <<< "$USER_CSV"
CREATED_COUNT=0

for USER in "${USERS_ARRAY[@]}"; do
echo "Processing user: ${USER}"

# A) Pre-creation Cleanup (User Deletion)
if id "${USER}" &> /dev/null; then
echo " -> WARNING: User ${USER} already exists. Deleting user and home directory..."
userdel -r "${USER}" 2> /dev/null
fi

# B) User Creation
# -m: Create home directory
# -d /tmp/${USER}_home: Use a temporary path for Codespaces compatibility
# -G sudo,adm,${GROUP_NAME}: Add user to necessary groups
# -s /bin/bash: Set default shell
useradd -m -d "/tmp/${USER}_home" -G sudo,adm,"${GROUP_NAME}" -s /bin/bash "${USER}"

# C) Set Password (Non-interactive)
echo "${USER}:${DEFAULT_PASSWORD}" | chpasswd

# D) Home Directory Setup (quotes.txt)
USER_HOME="/tmp/${USER}_home"
QUOTE_FILE="${USER_HOME}/${USER}_quotes.txt"
echo "${QUOTE_MESSAGE}" > "$QUOTE_FILE"

# Ensure ownership is correct
chown "${USER}:${USER}" "$QUOTE_FILE"
chmod "${DEFAULT_PERM}" "$QUOTE_FILE"

echo " -> Created user, set password, and created ${QUOTE_FILE}"

# E) Random Vulnerability Injection (60% chance for Grep)
# $RANDOM % 100 generates a number from 0 to 99.
if [ $(( RANDOM % 100 )) -lt 60 ]; then
echo "${SUSPECT_KEYWORD}" >> "$QUOTE_FILE"
echo " -> VULNERABILITY INJECTED (Grep search target)."
grep_target_count=$((grep_target_count + 1))
fi

# F) Random Permission Setting (50% chance for Find)
if [ $(( RANDOM % 100 )) -lt 50 ]; then
chmod "${VULNERABLE_PERM}" "$QUOTE_FILE"
echo " -> PERMISSION SET TO ${VULNERABLE_PERM} (Find search target)."
find_target_count=$((find_target_count + 1))
fi

CREATED_COUNT=$((CREATED_COUNT + 1))
done

# --- 4. Completion Summary ---
echo "----------------------------------------------------"
echo "Setup Complete for ${CREATED_COUNT} Users in Group ${GROUP_NAME}."
echo "Login password for all users: ${DEFAULT_PASSWORD}"
echo "Injected Keyword Search Targets: ${grep_target_count} files."
echo "World-Writable Permission Targets: ${find_target_count} files."
echo "----------------------------------------------------"
echo "Let the search begin!"
7 changes: 7 additions & 0 deletions bin/hal-9000.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
# A simple script to demonstrate user input and variable use.
echo "Hello. I'm Hal 9000. What is your name?"

read USERNAME
echo "I'm sorry $USERNAME, I'm afraid I can't open the pod bay doors."

44 changes: 44 additions & 0 deletions bin/repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

#!/bin/bash

# Codespaces repo symlink script

# ----------------------------------------------------------------------
# 1. Define Variables
# ----------------------------------------------------------------------

# $PWD holds the current path, which should be the workspace root when
# the user executes this script from the default terminal location.
WORKSPACE_ROOT="$PWD"
SYMLINK_PATH="$HOME/repo"

echo "Starting Codespaces setup..."
echo "----------------------------------------------------"

# ----------------------------------------------------------------------
# 2. Create Symlink (Shortcut)
# ----------------------------------------------------------------------

# Check if the symlink already exists to prevent an error
if [ -L "$SYMLINK_PATH" ]; then
echo "Symlink '~/repo' already exists. Removing old link..."
rm "$SYMLINK_PATH"
elif [ -d "$SYMLINK_PATH" ]; then
echo "Warning: A directory named 'repo' already exists in home. Skipping symlink creation."
exit 1
fi

# Create the new symlink
echo "Creating symlink: ~/repo -> $WORKSPACE_ROOT"
ln -s "$WORKSPACE_ROOT" "$SYMLINK_PATH"

if [ $? -eq 0 ]; then
echo "SUCCESS: Symlink '~/repo' created."
else
echo "ERROR: Failed to create symlink."
fi

echo "----------------------------------------------------"

echo "Setup complete. You can now use 'cd ~/repo' from anywhere, or 'cd repo' once you are in the home directory (~)."

Loading