Skip to content

Commit c0d3904

Browse files
authored
Merge pull request #1163 from splunk/cap_attack
CapAttack integration
2 parents 1ce6d64 + acf75ba commit c0d3904

File tree

24 files changed

+783
-101
lines changed

24 files changed

+783
-101
lines changed

attack_range.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ def init_remote_backend(args):
137137
controller.init_remote_backend(args.backend_name)
138138

139139

140+
def cap_attack(args):
141+
controller = init(args)
142+
if args.start:
143+
controller.start_cap_attack(args.target)
144+
elif args.stop:
145+
controller.stop_cap_attack(args.target)
146+
else:
147+
print("Please specify either --start or --stop")
148+
149+
140150
def main(args):
141151
"""
142152
main function parses the arguments passed to the script and calls the respctive method.
@@ -167,6 +177,9 @@ def main(args):
167177
simulate_parser = actions_parser.add_parser(
168178
"simulate", help="simulates attack techniques"
169179
)
180+
cap_attack_parser = actions_parser.add_parser(
181+
"cap_attack", help="starts and stops CAP Attack"
182+
)
170183
destroy_parser = actions_parser.add_parser(
171184
"destroy", help="destroy attack range instances"
172185
)
@@ -261,6 +274,20 @@ def main(args):
261274

262275
simulate_parser.set_defaults(func=simulate)
263276

277+
cap_attack_parser.add_argument(
278+
"-t",
279+
"--target",
280+
required=True,
281+
help="target for CAP Attack. Use the name of the Windows instance",
282+
)
283+
cap_attack_parser.add_argument(
284+
"--start", action="store_true", help="start CAP Attack threat capture"
285+
)
286+
cap_attack_parser.add_argument(
287+
"--stop", action="store_true", help="stop CAP Attack threat capture"
288+
)
289+
cap_attack_parser.set_defaults(func=cap_attack)
290+
264291
# Dump Arguments
265292
dump_parser.add_argument(
266293
"-fn", "--file_name", required=True, help="file name of the attack_data"

configs/attack_range_default.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ gcp:
112112
use_static_ip: "0"
113113
# Enable/disable usage of static IP by setting this to 1 or 0.
114114

115-
local:
116-
provider: "Virtual Box"
117-
# Attack Range Local used Virtualbox and Vagrant to build the Attack Range.
118-
119115
splunk_server:
120116

121117
install_es: "0"
@@ -339,4 +335,13 @@ simulation:
339335
# Specify the repository owner for Atomic Red Team.
340336

341337
atomic_red_team_branch: master
342-
# Specify the branch for Atomic Red Team.
338+
# Specify the branch for Atomic Red Team.
339+
340+
cap_attack: "0"
341+
# Enable/Disable CAP Attack by setting this to 1 or 0.
342+
343+
cap_attack_upload_threat_capture: "0"
344+
# Enable/Disable CAP Attack upload of threat capture by setting this to 1 or 0.
345+
346+
snapattack_api_key: ""
347+
# Specify the API key for SnapAttack.

docs/source/Cap_Attack.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# CapAttack
2+
CapAttack is a client capture agent for Windows, Mac and Linux developed by SnapAttack. It captures logs, network traffic and other information from the machine. Additionally, it can record the screen of the machine.
3+
4+
## CapAttack during attack simulation
5+
CapAttack can be enabled by setting the parameter `cap_attack` to 1 in the `attack_range.yml` file.
6+
```yml
7+
simulation:
8+
cap_attack: "1"
9+
```
10+
This will start the CapAttack agent before the attack simulation is started and capture the logs, network traffic and screen. At the end of the attack simulation, the CapAttack agent will be stopped.
11+
12+
When you want to upload the CapAttack capture to SnapAttack, you need to set the parameters `cap_attack_upload_threat_capture` and `snapattack_api_key` in the `attack_range.yml` file.
13+
```yml
14+
simulation:
15+
cap_attack: "1"
16+
cap_attack_upload_threat_capture: "1"
17+
snapattack_api_key: "your_snapattack_api_key"
18+
```
19+
20+
## Manually start and stop CapAttack
21+
You can manually start and stop CapAttack by using the following commands:
22+
```bash
23+
python attack_range.py cap_attack start --target <target>
24+
python attack_range.py cap_attack stop --target <target>
25+
```

docs/source/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Attack Range Config <Attack_Range_Config>
2020
Attack Simulation <Attack_Simulation>
2121
Attack Data <Attack_Data>
2222
Attack Range Features <Attack_Range_Features>
23+
CapAttack <Cap_Attack>
2324
Cost Explorer <Cost_Explorer>
2425
2526
```

modules/ansible/cap_attack.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: CAP Attack
3+
hosts: all
4+
gather_facts: True
5+
roles:
6+
- cap_attack
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
3+
- name: Update apt repositories
4+
apt:
5+
update_cache: yes
6+
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Debian"
7+
8+
- name: Update yum repositories
9+
yum:
10+
update_cache: yes
11+
when: ansible_os_family == "RedHat"
12+
13+
- name: Install x11-xserver-utils (Debian/Ubuntu)
14+
apt:
15+
name: x11-xserver-utils
16+
state: present
17+
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Debian"
18+
19+
- name: Install xorg-x11-server-utils (RedHat)
20+
yum:
21+
name: xorg-x11-server-utils
22+
state: present
23+
when: ansible_os_family == "RedHat"
24+
25+
- name: Install PowerShell on Debian-based systems
26+
shell: |
27+
# Download the Microsoft repository GPG keys
28+
wget -q https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb
29+
# Register the Microsoft repository GPG keys
30+
dpkg -i packages-microsoft-prod.deb
31+
# Update the list of products
32+
apt-get update
33+
# Install PowerShell
34+
apt-get install -y powershell
35+
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Debian"
36+
args:
37+
creates: /usr/bin/pwsh
38+
39+
- name: Install PowerShell on RedHat-based systems
40+
shell: |
41+
# Register the Microsoft RedHat repository
42+
curl https://packages.microsoft.com/config/rhel/$(rpm -E %{rhel})/prod.repo | tee /etc/yum.repos.d/microsoft.repo
43+
# Install PowerShell
44+
yum install -y powershell
45+
when: ansible_os_family == "RedHat"
46+
args:
47+
creates: /usr/bin/pwsh
48+
49+
- name: Install Atomic Red Team
50+
shell: |
51+
pwsh -Command "IEX (IWR 'https://raw.githubusercontent.com/redcanaryco/invoke-atomicredteam/master/install-atomicredteam.ps1' -UseBasicParsing); Install-AtomicRedTeam -getAtomics"
52+
args:
53+
creates: ~/.atomics

modules/ansible/roles/atomic_red_team/tasks/install_art_windows.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

modules/ansible/roles/atomic_red_team/tasks/run_art_linux.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
- set_fact:
44
technique: "{{ item }}"
55

6+
- name: Start threat capture with CAP Attack
7+
become: true
8+
shell: |
9+
pwsh -Command 'Import-Module "/root/capattack/capattack-ps/capattack.psd1" -Force;
10+
CapAttack-Start'
11+
when: cap_attack == "1"
12+
ignore_errors: True
13+
614
- name: Run Atomic Red Team
715
become: true
816
shell: |
@@ -11,5 +19,19 @@
1119
Invoke-AtomicTest "{{ technique }}" -Cleanup'
1220
register: output_art
1321

22+
- name: Stop threat capture with CAP Attack and upload
23+
become: true
24+
shell: |
25+
pwsh -Command 'Import-Module "/root/capattack/capattack-ps/capattack.psd1" -Force;
26+
CapAttack-Stop -Headless -Upload'
27+
when: cap_attack == "1" and cap_attack_upload_threat_capture == "1"
28+
29+
- name: Stop threat capture with CAP Attack
30+
become: true
31+
shell: |
32+
pwsh -Command 'Import-Module "/root/capattack/capattack-ps/capattack.psd1" -Force;
33+
CapAttack-Stop -Headless'
34+
when: cap_attack == "1" and cap_attack_upload_threat_capture == "0"
35+
1436
- debug:
1537
var: output_art.stdout_lines

modules/ansible/roles/atomic_red_team/tasks/run_art_test_windows.yml

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,46 @@
44
- debug:
55
var: technique
66

7-
# - name: List available Atomic Red Team Techniques
8-
# ansible.windows.win_find:
9-
# paths: C:\AtomicRedTeam\atomics
10-
# file_type: directory
11-
# patterns: T*
12-
# register: available_techniques
13-
14-
# - set_fact:
15-
# available_techniques: "{{ available_techniques | json_query('files[].filename') }}"
16-
# main_technique: "{{ technique | regex_replace('(-.)','') }}"
17-
18-
# - name: Check requested Technique is valid
19-
# fail:
20-
# msg: "The {{ main_technique }} selected technique has no atomic tests. Please ensure it it correct and that tests exist for it. See https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/Indexes/Indexes-CSV/windows-index.csv. {{ available_techniques }} "
21-
# when: "main_technique not in available_techniques"
22-
7+
- name: Start threat capture with CAP Attack
8+
win_shell: |
9+
Import-Module "C:\Program Files\ansible\capattack\capattack-ps\capattack.psd1" -Force
10+
CapAttack-Start
11+
when: cap_attack == "1"
12+
ignore_errors: True
13+
2314
- name: Get requirements for Atomic Red Team Technique
2415
win_shell: |
2516
Import-Module "C:\AtomicRedTeam\invoke-atomicredteam\Invoke-AtomicRedTeam.psd1" -Force
2617
Invoke-AtomicTest "{{ technique }}" -GetPrereqs
2718
register: requirements
2819
ignore_errors: True
2920

30-
# - debug:
31-
# var: requirements
32-
3321
- name: Run specified Atomic Red Team Technique
3422
win_shell: |
23+
Set-ExecutionPolicy bypass
3524
Import-Module "C:\AtomicRedTeam\invoke-atomicredteam\Invoke-AtomicRedTeam.psd1" -Force
3625
Invoke-AtomicTest "{{ technique }}" -Confirm:$false -TimeoutSeconds 300 -ExecutionLogPath C:\AtomicRedTeam\atc_execution.csv
3726
register: output_art
38-
39-
# - name: Save output atomic red team
40-
# set_fact:
41-
# output_art: "{{ output_art }}"
42-
# cacheable: yes
27+
ignore_errors: True
4328

4429
- debug:
4530
var: output_art.stdout_lines
4631

32+
- name: Stop threat capture with CAP Attack and upload
33+
win_shell: |
34+
Import-Module "C:\Program Files\ansible\capattack\capattack-ps\capattack.psd1" -Force
35+
CapAttack-Stop -Headless -Upload
36+
when: cap_attack == "1" and cap_attack_upload_threat_capture == "1"
37+
38+
- name: Stop threat capture with CAP Attack
39+
win_shell: |
40+
Import-Module "C:\Program Files\ansible\capattack\capattack-ps\capattack.psd1" -Force
41+
CapAttack-Stop -Headless
42+
when: cap_attack == "1" and cap_attack_upload_threat_capture == "0"
43+
4744
- name: Cleanup after execution
4845
win_shell: |
4946
Import-Module "C:\AtomicRedTeam\invoke-atomicredteam\Invoke-AtomicRedTeam.psd1" -Force
5047
Invoke-AtomicTest "{{ technique }}" -Cleanup
5148
register: cleanup
5249

53-
# - debug:
54-
# var: cleanup
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
# Default values for CAP Attack
3+
cap_attack_action: "start" # Options: start, stop
4+
cap_attack_upload_threat_capture: "0" # Options: 0 (don't upload), 1 (upload)
5+
6+
# Windows-specific defaults
7+
windows_cap_attack_path: "C:\\Program Files\\ansible\\capattack"
8+
9+
# Linux-specific defaults
10+
linux_cap_attack_path: "/root/capattack"

0 commit comments

Comments
 (0)