Skip to content

Commit

Permalink
Merge pull request #5 from h311d1n3r/cpp_rewrite
Browse files Browse the repository at this point in the history
Cpp rewrite
  • Loading branch information
h311d1n3r authored Sep 19, 2023
2 parents 5495ef8 + 07ea5da commit f91fcc6
Show file tree
Hide file tree
Showing 82 changed files with 3,336 additions and 983 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake-build*/
.cerberus*/
build/
.idea/
radare2/
Goliath/
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ jobs:
steps:
- name: clone_project
uses: actions/checkout@v3
- name: init_submodules
run: git submodule update --init --recursive
- name: apt_dependencies
run: sudo apt install binutils gcc-multilib g++-multilib
run: sudo apt -y install libarchive-dev libcurl4-openssl-dev zlib1g-dev libelf-dev gcc g++ make cmake
- name: setup_radare2
run: |
git clone https://github.com/radare/radare2.git
Expand All @@ -32,12 +34,10 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: python_dependencies
run: pip3 install -r requirements.txt
- name: compile
run: ./build.sh
run: mkdir build && cd build && cmake .. && make
- name: append_path
run: echo "`pwd`/dist" >> $GITHUB_PATH
run: echo "`pwd`/build" >> $GITHUB_PATH
- name: compile_rust_tests
run: |
echo "Installing Rust 32-bit architecture"
Expand Down
9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
__pycache__/
cmake-build*/
.cerberus*/
*.spec
build/
dist/
target/
*.lock
.idea/
radare2/
Goliath/
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[submodule "lib/Goliath"]
path = lib/Goliath
url = https://github.com/h311d1n3r/Goliath
[submodule "lib/argparse"]
path = lib/argparse
url = https://github.com/p-ranav/argparse
[submodule "lib/lief"]
path = lib/lief
url = https://github.com/lief-project/LIEF
[submodule "lib/gzip-hpp"]
path = lib/gzip-hpp
url = https://github.com/mapbox/gzip-hpp
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.22)
project(Cerberus)

set(CMAKE_CXX_STANDARD 17)

find_path(libelf.h NAMES LIBELF)

# will be included statically
add_subdirectory(lib/lief)
add_subdirectory(lib/argparse)
# will be included dynamically
find_package(CURL REQUIRED)
find_package(ZLIB REQUIRED)
find_package(LibArchive REQUIRED)

include_directories(lib/argparse/include lib/lief/include lib/gzip-hpp/include ${LIBELF} src)

add_executable(Cerberus src/main.cpp src/utils/logger.h src/utils/logger.cpp src/utils/arg_parser.h src/utils/config.h src/utils/arg_parser.cpp src/global_defs.h src/langs/lang_manager.h src/langs/lang_manager.cpp src/types/value_ordered_map.h src/binaries/bin_identifier.cpp src/user/user_prompt.cpp src/utils/convert.h src/binaries/bin_handler.h src/binaries/handlers/elf_handler.h src/binaries/handlers/elf_handler.cpp src/binaries/bin_extractor.h src/binaries/bin_types.h src/binaries/extractors/lief_extractor.h src/binaries/extractors/lief_extractor.cpp src/binaries/extractors/radare_extractor.h src/binaries/extractors/radare_extractor.cpp src/binaries/handlers/pe_handler.h src/binaries/handlers/pe_handler.cpp src/binaries/bin_handler.cpp src/langs/lib_regex.h src/utils/search.h src/utils/search.cpp src/langs/lang_types.h src/langs/lib_regex.cpp src/utils/convert.cpp src/binaries/lib/lib_manager.h src/binaries/lib/lib_manager.cpp src/binaries/lib/install/lib_installer.h src/binaries/lib/install/rust_lib_installer.h src/binaries/lib/install/go_lib_installer.h src/binaries/lib/install/rust_lib_installer.cpp src/binaries/lib/install/go_lib_installer.cpp src/utils/file_downloader.h src/utils/file_downloader.cpp src/utils/file_operations.h src/utils/file_operations.cpp src/user/dependencies/dependency_manager.h src/command/command_executor.h src/command/command_executor.cpp src/user/local_config.h src/user/local_config.cpp src/user/dependencies/dependency_manager.cpp src/algorithm/part_hash_algorithm.h src/algorithm/part_hash_algorithm.cpp src/algorithm/algorithm.h src/binaries/extractors/libelf_extractor.h src/binaries/extractors/libelf_extractor.cpp src/binaries/pe_types.h src/binaries/extractors/go_extractor.h src/binaries/extractors/go_extractor.cpp)

target_link_libraries(Cerberus PRIVATE argparse PRIVATE LIEF::LIEF PRIVATE CURL::libcurl PRIVATE ZLIB::ZLIB PRIVATE LibArchive::LibArchive PRIVATE uuid PRIVATE elf PRIVATE stdc++fs)
set_target_properties(Cerberus PROPERTIES OUTPUT_NAME cerberus)
47 changes: 34 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
# Cerberus
## Description
### A Python tool to unstrip Rust and Go binaries on Linux
**Cerberus** is the tool you want to use to make Rust and Go static analysis a lot easier.
### A C++ tool to unstrip Rust and Go binaries (ELF and PE)
**Cerberus** is the tool you want to use to make RUST and GO static analysis a lot easier.
Based on hashing and scoring systems, it can retrieve lots of symbol names.
## How does it work ?
After analyzing your ELF binary to find the used libraries, **Cerberus** will download and build them.
After analyzing your ELF/PE binary to find the used libraries, **Cerberus** will download and build them.
Then the tool will hash (in various ways) the functions in your file and in the libraries to make matches.
## Table of contents
[Build the tool](#build)
[Installation](#install)
      [Download a release](#install_release)
      [Build the tool with Docker](#install_build_docker)
      [Build the tool on host](#install_build_host)
[How to use ?](#how)
      [Syntax](#how_syntax)
      [Parameters](#how_params)
      [Flags](#how_flags)
      [Example](#how_example)
[Warning](#warning)

<a name="build"/>
<a name="install"/>

## Build the tool
1. You need to have **Python3**, **Cargo**, **Go** and the **binutils** package installed on your system.
2. Clone the repository.
3. Install Python dependencies using `pip3 install -r requirements.txt`.
4. Build the tool using `./build.sh`.
5. Add the generated `dist` directory to your path using `PATH=$PATH:~/path/to/the/repo/dist`.
## Installation

<a name="install_release"/>

### Download a release
Check the [Releases](https://github.com/h311d1n3r/Cerberus/releases/) tab on the Github project and download the latest one.

<a name="install_build_docker"/>

### Build the tool with Docker
1. Clone the repository `git clone https://github.com/h311d1n3r/Cerberus && cd cerberus`.
2. Check the available Dockerfiles under `Cerberus/docker/{OS}`.
3. Build the docker image of your choice `docker build -f ./docker/{OS}/Dockerfile-{version}`.
4. You can run **Cerberus** from inside the docker or extract the binary on your host. This second choice needs to install the libraries listed in [this section](#install_build_host).

<a name="install_build_host"/>

### Build the tool on host
1. You need to have **libarchive**, **libcurl4-openssl**, **zlib1g**, **libelf** and the **uuid-dev** libraries installed on your system.
With APT just do `apt -y install libarchive-dev libcurl4-openssl-dev zlib1g-dev libelf-dev`
2. Clone the repository `git clone https://github.com/h311d1n3r/Cerberus && cd cerberus`.
3. Create the build directory `mkdir build && cd build`.
4. Run CMake to configure the project `cmake ..`.
5. Run make to compile the project `make`.

<a name="how"/>

Expand All @@ -47,8 +68,8 @@ Increasing this value will reduce the number of matched functions but speed up e

### Flags
`help` -> Displays a help message.
`debug` -> Enable debug level of logging.
`no-prompt` -> Automatically skips user prompts
`debug` -> Displays outputs of commands.
`no-prompt` -> Automatically skips user prompts.

<a name="how_example"/>

Expand Down
3 changes: 0 additions & 3 deletions build.sh

This file was deleted.

25 changes: 25 additions & 0 deletions docker/debian/Dockerfile-10
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM debian:10

WORKDIR /root

RUN apt -y update
RUN apt -y upgrade
RUN apt -y install g++ gcc make tar wget
RUN apt -y install libarchive-dev libcurl4-openssl-dev libssl-dev zlib1g-dev libelf-dev uuid-dev

RUN wget https://github.com/Kitware/CMake/releases/download/v3.27.5/cmake-3.27.5.tar.gz
RUN tar -xzf cmake-3.27.5.tar.gz
WORKDIR cmake-3.27.5
RUN ./bootstrap
RUN make
RUN make install
WORKDIR ..

RUN mkdir -p Cerberus
WORKDIR Cerberus
ADD ./ ./
RUN mkdir -p build
WORKDIR build

RUN cmake ..
RUN make
17 changes: 17 additions & 0 deletions docker/fedora/Dockerfile-37
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM fedora:37

WORKDIR /root

RUN dnf -y update
RUN dnf -y upgrade
RUN dnf -y install g++ gcc make cmake
RUN dnf -y install libarchive-devel libcurl-devel zlib-devel elfutils-libelf-devel libuuid-devel

RUN mkdir -p Cerberus
WORKDIR Cerberus
ADD ./ ./
RUN mkdir -p build
WORKDIR build

RUN cmake ..
RUN make
25 changes: 25 additions & 0 deletions docker/ubuntu/Dockerfile-20.04
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM ubuntu:20.04

WORKDIR /root

RUN apt -y update
RUN apt -y upgrade
RUN apt -y install g++ gcc make tar wget
RUN apt -y install libarchive-dev libcurl4-openssl-dev libssl-dev zlib1g-dev libelf-dev uuid-dev

RUN wget https://github.com/Kitware/CMake/releases/download/v3.27.5/cmake-3.27.5.tar.gz
RUN tar -xzf cmake-3.27.5.tar.gz
WORKDIR cmake-3.27.5
RUN ./bootstrap
RUN make
RUN make install
WORKDIR ..

RUN mkdir -p Cerberus
WORKDIR Cerberus
ADD ./ ./
RUN mkdir -p build
WORKDIR build

RUN cmake ..
RUN make
17 changes: 17 additions & 0 deletions docker/ubuntu/Dockerfile-22.04
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:22.04

WORKDIR /root

RUN apt -y update
RUN apt -y upgrade
RUN apt -y install g++ gcc make cmake
RUN apt -y install libarchive-dev libcurl4-openssl-dev zlib1g-dev libelf-dev uuid-dev

RUN mkdir -p Cerberus
WORKDIR Cerberus
ADD ./ ./
RUN mkdir -p build
WORKDIR build

RUN cmake ..
RUN make
1 change: 1 addition & 0 deletions lib/argparse
Submodule argparse added at b0930a
1 change: 1 addition & 0 deletions lib/gzip-hpp
Submodule gzip-hpp added at 7546b3
1 change: 1 addition & 0 deletions lib/lief
Submodule lief added at 2d9855
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

Loading

0 comments on commit f91fcc6

Please sign in to comment.