Trickanomicon

FreeBSD

Package Manager

Monitoring Services

#!/bin/sh

my_example_service code

Checking Network Connections

Changing File Flags

System Configuration Files

The Kernel Securelevel

Linux Persistent Iptables Service

NOTE: Using systemd

1. Creating the Backup Script

2. Creating the Service

Linux Splunk Changes

Pre-Execution Script Changes

All changes pertain to the splunk.sh script (competition-resources/Splunk/splunk.sh)

  1. Change INDEXER to the ip address of the splunk instance (receiver)
  2. Changed PASS to a different password
  3. Remove the else branch from the “if ! restart_splunk” (lines 126-128)

Post script execution

Manually add source(s) to monitor:

  1. Select a file (or entire directory) to monitor
  2. Talk to a captain to obtain the index to use (most likely either “linux” or “windows”)
  3. Change directory into the $SPLUNK_HOME/bin directory (most likely /opt/splunkforwarder)
  4. Run a command like sudo ./splunk add monitor /path/to/thing/to/monitor -index <name of index>

In the case where the chosen source is already being monitored (and you need to change something about how it is being monitored… e.g., changing the index):

  1. Change directory into the $SPLUNK_HOME/bin directory
  2. Run the command sudo ./splunk remove monitor /path/to/thing/to/monitor
  3. Follow the previous set of steps to re-add the source as a monitor

These commands edit the file at the path $SPLUNK_HOME/etc/apps/search/local/inputs.conf. Do what you will with this information. It should be noted that making manual changes usually requires a restart of the splunk daemon to take effect. To do this: sudo $SPLUNK_HOME/bin/splunk restart

Linux CCDC Basic Checklist

1. Network Scanning & Enumeration

Nmap Scanning

2. User & Password Management

Reset Passwords

(expects /etc/passwd copy with only accounts you want to reset the password for to be in the file)

Without saving passwords:

for user in $(cat ./users | awk -F: '{print $1}'); do echo "$user:m0Nk3y!m0Nk3y!" | sudo chpasswd; done

With saving passwords to a file:

for user in $(cat ./users | awk -F: '{print $1}'); do echo "$user:m0Nk3y!m0Nk3y!" | tee -a ./new_passwords | sudo chpasswd; done

Create a New User

useradd user -m -s /bin/bash -g sudo

Disable Accounts

usermod -L <user>

Enable Accounts

usermod -U <user>

3. SSH Security & Key Management

Rotate SSH Keys

Secure /etc/ssh/sshd_config

4. System & Service Management

System Logs

Systemctl Commands

5. Process & Cron Job Monitoring

Active Processes & Connections

Crontab & Scheduled Tasks

6. Security Hardening & Permissions

Remove SUID Binaries

Secure /etc/sudoers

7. Incident Response & Documentation

Kill Active Sessions

Backups

Documentation

Cisco Firepower Firewall

Note: The web interface and command line interface may be split on two different machines. Make sure that passwords are reset on both the web and command line interface.

Reset Passwords on the Web Interface

  1. Log in to the web interface as a user with administrator access.
  2. Navigate to System > Users, and click the edit icon (a pencil) for each user.
  3. Enter the new password in the Password and Confirm Password fields.
  4. Click Save. If prompted to restart the device, then restart.
  5. Verify that the passwords were changed for all users.

Reset Passwords on the Command Line Interface

  1. Log in to the administrator account over SSH or with the console.
  2. If you do not immediately boot into a Linux shell, enter the command expert to access the Linux shell.
  3. At the shell prompt enter the command sudo passwd (the name of the user) to change passwords for all users.
  4. Enter the command exit to exit the shell/interface.
  5. Verify that the passwords were changed for all users.

Keycloak

Installation

docker run -p 8080:8080 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:26.1.3 start-dev

Accounts Setup

# start production server (need to provide TLS certs)
bin/kc.sh start --bootstrap-admin-username admin --bootstrap-admin-password admin

# start development server
bin/kc.sh start-dev --bootstrap-admin-client-id tmpadm --bootstrap-admin-client-secret secret

# create temporary admin user (done without server running)
bin/kc.sh bootstrap-admin user # --username tmpadm --password:env PASS_VAR (optional)

# create temporary service user
bin/kc.sh bootstrap-admin service # --client-id tmpclient --client-secret:env=SECRET_VAR (optional)

Authentication & Usage of Keycloak

MariaDB and MySQL

MySQL Config File

When installed, the mysql service will automatically start and run upon system startup on port 3306. The config file is stored in /etc/mysql/mysql.conf.d/mysqld.cnf.

MariaDB Config File

When installed, the mysql service will automatically start and run upon system startup on port 3306. The config files are stored in /etc/mysql/my.cnf and /etc/mysql/mariadb.conf.d/50-server.cnf (this file contains Maria-DB server specific settings).

Securing the Services and Databases

The config file:

The service files:

Passwords:

Auditing Users:

Removing unwanted users:

Backing up the databases:

Restoring the databases:

MariaDB and MySQL Hardening

  1. Log in to the mysql/mariadb console with sudo mysql -u root -p
  2. Root’s password may be blank if it is not provided during the competition
  3. If you can not log in, ensure the mysql service has properly started without logging errors (broken config file, networking error, etc.)
  4. In MySQL, run USE mysql;
  5. Change root user’s password
  6. Run FLUSH PRIVILEGES;
  7. Verify/edit the appropriate config file
  8. Audit users
  9. Create backups

PostgreSQL Hardening

  1. Log in to the PostgreSQL console with sudo psql
  2. Root’s password may be blank if it is not provided during the competition
  3. If you can not log in, ensure the PostgreSQL service has properly started without logging errors (broken config file, networking error, etc.)
  4. Change root user’s password
  5. Verify/edit the config files in /etc/postgresql/(version number)/main
  6. Audit users
  7. Create backups

PostgreSQL

Config Files

The service files:

Passwords:

Auditing Users:

Removing unwanted users:

Backing up the databases:

Restoring the databases:

Salt

https://docs.saltproject.io/en/latest/topics/tutorials/walkthrough.html

Commands (Execution Modules)

Basics

# ping minions
sudo salt '*' test.ping

# list version
sudo salt -v '*' test.version

# install command
sudo salt -v '*linux*' pkg.install vim

# apply /srv/salt/test.sls
sudo salt -v '*linux*' state.apply test

# run commands (can use pipes, command substitution, etc.)
sudo salt '*linux*' cmd.run 'uptime'

# execute other code
sudo salt '*' cmd.exec_code perl 'print("hello")'
sudo salt '*' cmd.exec_code ruby 'puts "cheese"' args='["arg1", "arg2"]' env='{"FOO": "bar"}'

Copying Files

# put files into /srv/salt to use salt://
sudo salt '*linux*' cp.get_file salt://files/reset_passwords.pl /tmp/reset_passwords.pl

sudo salt '*linux*' cp.get_dir salt://files /tmp/files
sudo salt '*win*' cp.get_dir salt://files C:/ # no \

sudo salt-cp '*linux*' src dest # slower

# push files from minion; /var/cache/salt/master/minions/minion-id/files
sudo salt '*linux*' cp.push_dir /var/www/html/index.html
sudo salt '*linux*' cp.push_dir /var/www/html

User Administration

# user management
sudo salt 't*' user.add jp2

# get users
sudo salt '*' ps.get_users

# add/remove user to group
sudo salt '*' group.adduser group user 
sudo salt '*' group.deluser group user

# delete group
sudo salt '*' group.delete group

# get all group info
sudo salt '*' group.getent

# set group members (replaces users)
sudo salt '*' group.members group 'user1,user2,user3'

# set password
sudo salt '*' shadow.gen_password 'password'
sudo salt '*' shadow.set_password someuser 'hash'

System Info

# get disk partitons
sudo salt '*' ps.disk_partitions

# get running processes
sudo salt '*' ps.status running
sudo salt '*' ps.top
sudo salt 'linux*' ps.aux '.*'
sudo salt '*' ps.get_pid_list

Services & More

# crontabs!!! (list/add/remove)
sudo salt '*' cron.ls user
sudo salt '*' cron.set_job root '*' '*' '*' '*' '*' cmd
sudo salt '*' cron.set_special root @hourly 'echo foobar'

# install wordpress
sudo salt '*' wordpress.install /var/www/html apache dwallace password123 [email protected] "Daniel's Awesome Blog" https://blog.dwallace.com

# mysql
sudo salt '*' mysql.db_create 'dbname'
sudo salt '*' mysql.db_remove 'dbname'
sudo salt '*' mysql.query 'dbname' 'DELETE from users where id = 4 limit 1'

# services
sudo salt '*' service.get_all
sudo salt '*' service.restart service
sudo salt '*' service.start service
sudo salt '*' service.stop service

Sample .sls File

network_utilities:
  pkg.installed:
    - pkgs:
      - rsync
      - curl

nginx_pkg:
  pkg.installed:
    - name: nginx

nginx_service:
  service.running:
    - name: nginx
    - enable: True
    - require:
      - pkg: nginx_pkg

Firewall Rules

Minion Rules

sudo salt '*' iptables.build_rule match=conntrack connstate=RELATED,ESTABLISHED jump=ACCEPT

sudo salt 't*' cmd.run 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT'
sudo salt 't*' cmd.run 'iptables -A OUTPUT -d 10.3.12.150 -p tcp --dport 4505 -j ACCEPT'
sudo salt 't*' cmd.run 'iptables -A OUTPUT -d 10.3.12.150 -p tcp --dport 4506 -j ACCEPT'

Master Rules

sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

sudo iptables -A INPUT -i lo -p tcp -m multiport --dports 4505:4506 -j ACCEPT # allow salt localhost comm
sudo iptables -A INPUT -p tcp -m multiport --dports 4505:4506 -j ACCEPT # minion comm

sudo iptables -A OUTPUT -p tcp -m iprange --dst-range 10.3.12.1-10.3.12.4 -j ACCEPT

sudo iptables -A INPUT -i lo -p tcp -m multiport --dports 4505:4506 -j ACCEPT
sudo iptables -A INPUT -p tcp -m multiport --dports 4505:4506 -j ACCEPT

sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT # inbound
sudo iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT # outbound

Wordpress

Source: https://www.wpbeginner.com/wordpress-security/

Checklist

  1. Reset Password
  2. Check when wp-config.php was last edited
  3. Check for any file types of .php, .js, .exe
  4. Verify Wordpress Database Information
  5. Plugins
  6. Updates
  7. Backups
  8. Disable File editing
  9. Security Plugins

Windows Notes

By: Aaron Sprouse and Dylan Harvey

Set TLS Settings for Downloading (any download + splunk)

[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"

Require Kerberos Preauth on all Accounts

Get-ADUSer -Filter 'DoesNotRequirePreAuth -eq $true ' | Set-ADAccountControl -doesnotrequirepreauth $false

Download Sysinternals

Invoke-WebRequest -Uri "https://download.sysinternals.com/files/SysinternalsSuite.zip" -OutFile "C:\sysinternals.zip";
Expand-Archive -Path "C:\sysinternals.zip" -DestinationPath "C:\sysinternals\"

Remove WMI Event Subscribers

Get-WmiObject -Namespace root/subscription -Class CommandLineEventConsumer

Get-WmiObject -Namespace root/subscription -Class __EventFilter

Get-WmiObject -Namespace root/subscription -Class __FilterToConsumerBinding

Get-WmiObject -Class __IntervalTimerInstruction

<command> | Remove-WmiObject

Bins to Remove

Windows Splunk Changes

[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"

splunk.ps1

Once Installed

Check Config

C:\Program Files\SplunkUniversalForwarder\etc\system\local\ inputs.conf outputs.conf

Check Log

C:\Program Files\SplunkUniversalForwarder\var\log\splunk\ splunkd.log

Restart the Service (logs may not send otherwise)

Restart-Service SplunkForwarder

inputs.conf

[default]
host = ${HOSTNAME}

[WinEventLog] 
index = windows
checkpointInterval = 5

[WinEventLog://Security]
disabled = 0
index = windows

[WinEventLog://Application]
disabled = 0
index = windows

[WinEventLog://System]
disabled = 0
index = windows

[WinEventLog://DNS Server]
disabled = 0
index = windows

[WinEventLog://Directory Service]
disabled = 0
index = windows

[WinEventLog://Windows Powershell]
disabled = 0
index = windows

[WinEventLog://Microsoft-Windows-Sysmon/Operational]
current_only = 0
disabled = 0
start_from = oldest
index = windows
renderXml = false

[WinEventLog://Microsoft-Windows-Sysmon/Operational]
current_only = 0
disabled = 0
start_from = oldest
index = windows
renderXml = false