Skip to content

Commit

Permalink
Merge pull request #82 from wllm-rbnt/cmake
Browse files Browse the repository at this point in the history
cmake
  • Loading branch information
adulau authored Aug 13, 2023
2 parents a933d5b + ae16d57 commit 00f968e
Show file tree
Hide file tree
Showing 24 changed files with 409 additions and 273 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,22 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install macOS autogen prerequisites
run: brew install autoconf automake
if: ${{ runner.os == 'macOS' }}
- name: ./autogen.sh
run: ./autogen.sh
- name: Compiler version
run: $CC -v
env:
CC: ${{ matrix.compiler }}
- name: Install Linux dependencies
run: sudo apt install autoconf libssl-dev libpcap-dev libnet1-dev libjson-c-dev
run: sudo apt install cmake ninja-build libssl-dev libpcap-dev libnet1-dev libjson-c-dev
if: ${{ runner.os == 'Linux' }}
- name: Install macOS dependencies
run: |
brew install openssl@3 libpcap libnet json-c
brew install cmake ninja openssl@3 libpcap libnet json-c
echo "LDFLAGS=-L$(brew --prefix openssl@3)/lib" >> $GITHUB_ENV
echo "CPPFLAGS=-I$(brew --prefix openssl@3)/include" >> $GITHUB_ENV
if: ${{ runner.os == 'macOS' }}
- name: ./configure
run: ./configure
- name: cmake -B ${{github.workspace}}/build -G Ninja
run: cmake -B ${{github.workspace}}/build -G Ninja
env:
CC: ${{ matrix.compiler }}
- name: make
run: make
- name: ninja -C ${{github.workspace}}/build
run: ninja -C ${{github.workspace}}/build
7 changes: 3 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ jobs:
languages: ${{ matrix.language }}
- name: Build Application using script
run: |
./autogen.sh
sudo apt install autoconf libssl-dev libpcap-dev libnet1-dev libjson-c-dev
./configure
make
sudo apt install cmake ninja-build libssl-dev libpcap-dev libnet1-dev libjson-c-dev
cmake -B ${{github.workspace}}/build -G Ninja
ninja -C ${{github.workspace}}/build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
Expand Down
117 changes: 117 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
cmake_minimum_required(VERSION 3.16.3)
include(CheckSymbolExists)

project(
ssldump
VERSION 1.8
DESCRIPTION 20230811
LANGUAGES C
)

configure_file(base/pcap-snoop.c.in base/pcap-snoop.c)

set(SOURCES
${CMAKE_BINARY_DIR}/base/pcap-snoop.c
base/network.c
base/proto_mod.c
base/tcppack.c
base/tcpconn.c
null/null_analyze.c
common/lib/r_data.c
common/lib/r_assoc.c
common/lib/r_errors.c
common/lib/debug.c
ssl/ssl_analyze.c
ssl/ssldecode.c
ssl/sslprint.c
ssl/ssl.enums.c
ssl/sslxprint.c
ssl/ciphersuites.c
ssl/ssl_rec.c
pcap/logpkt.c
pcap/pcap_logger.c
pcap/sys.c
)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules/" ${CMAKE_MODULE_PATH})

find_package(OpenSSL)
if(NOT OPENSSL_FOUND)
message( FATAL_ERROR
"Unable to find OpenSSL development files on this system
On Debian and Ubuntu systems you can install the required library and header files with
apt install libssl-dev
On Fedora systems, with
dnf install openssl-devel" )
endif()

#dnf install openssl-devel libpcap-devel libnet-devel json-c-devel

find_package(PCAP)
if(NOT PCAP_FOUND)
message( FATAL_ERROR
"Unable to find libpcap development files on this system
On Debian and Ubuntu systems you can install the required library and header files with
apt install libpcap-dev
On Fedora systems, with
dnf install libpcap-devel" )
endif()

find_package(LIBNET)
if(NOT LIBNET_FOUND)
message( FATAL_ERROR
"Unable to find libnet development files on this system
On Debian and Ubuntu systems you can install the required library and header files with
apt install libnet1-dev
On Fedora systems, with
dnf install libnet-devel" )
endif()

find_package(JSONC)
if(NOT JSONC_FOUND)
message( FATAL_ERROR
"Unable to find libjson-c development files on this system
On Debian and Ubuntu systems you can install the required library and header files with
apt install libjson-c-dev
On Fedora systems, with
dnf install json-c-devel" )
endif()

add_executable(${PROJECT_NAME} ${SOURCES})

check_symbol_exists(strdup "string.h" HAVE_STRDUP)
if(HAVE_STRDUP)
add_definitions(-DHAVE_STRDUP)
endif()

add_definitions(-DLINUX)
add_definitions(-DOPENSSL)
add_definitions(-D_DEFAULT_SOURCE=1)

target_include_directories(ssldump
PRIVATE
${PROJECT_SOURCE_DIR}/common/include
${PROJECT_SOURCE_DIR}/common/lib
${PROJECT_SOURCE_DIR}/null
${PROJECT_SOURCE_DIR}/ssl
${PROJECT_SOURCE_DIR}/base
${PROJECT_SOURCE_DIR}/pcap
${OPENSSL_INCLUDE_DIR}
${PCAP_INCLUDE_DIR}
${LIBNET_INCLUDE_DIR}
${JSONC_INCLUDE_DIR}
)

target_link_libraries(ssldump
PRIVATE
${OPENSSL_LIBRARIES}
${PCAP_LIBRARY}
${LIBNET_LIBRARY}
${JSONC_LIBRARIES}
)

set(CMAKE_INSTALL_PREFIX "/usr/local")
install(TARGETS ssldump DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

set(CMAKE_INSTALL_MANDIR "/usr/local/share/man")
install(FILES ssldump.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
37 changes: 0 additions & 37 deletions Makefile.am

This file was deleted.

50 changes: 24 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ includes a JSON output option, supports [JA3](https://github.com/salesforce/ja3)

# How to do I run ssldump?

`./ssldump -j -ANH -n -i any | jq` will run ssldump on all interfaces and output the result in JSON format including ja3 hashes.
`./ssldump -j -ANH -n -i any | jq` will run ssldump on all interfaces and output the result in JSON format including ja3 hashes.

For more details, check the man page.

## How can I lookup ja3 hashes?

This example will query ja3er.com service to display the known ja3 hashes from the TLS handshaked in the pcap.

`ssldump -r yourcapture.pcap -j | jq -r 'select(.ja3_fp != null) | .ja3_fp' | parallel 'curl -s -X GET 'https://ja3er.com/search/{}' | jq .'`
`ssldump -r yourcapture.pcap -j | jq -r 'select(.ja3_fp != null) | .ja3_fp' | parallel 'curl -s -X GET 'https://ja3er.com/search/{}' | jq .'`

# Why do you maintain this repository?

Expand All @@ -53,41 +53,39 @@ other too (but this is just a collateral damage).

# Build instructions

On Debian & Ubuntu:
Install dependencies on Debian & Ubuntu (as root):
```
apt install build-essential autoconf libssl-dev libpcap-dev libnet1-dev libjson-c-dev
./autogen.sh
./configure --prefix=/usr/local
make
(optional) make install
apt install build-essential git cmake ninja-build libssl-dev libpcap-dev libnet1-dev libjson-c-dev
```

On Fedora, CentOS, RHEL & Rocky:
On Fedora, CentOS, RHEL & Rocky (as root):
```
dnf install autoconf automake gcc make openssl-devel libpcap-devel libnet-devel json-c-devel
./autogen.sh
./configure --prefix=/usr/local
make
(optional) make install
dnf install git cmake ninja-build gcc openssl-devel libpcap-devel libnet-devel json-c-devel
```

Optional configuration features (aka ./configure options):
On OpenBSD (as root):
```
--disable-optimization disable compiler optimizations (change from -O2 to -O0)
--enable-debug enable debug info (add "-g -DDEBUG" to CFLAGS)
--enable-asan enable AddressSanitizer and other checks
add "-fsanitize=address,undefined,leak -Wformat -Werror=format-security
-Werror=array-bounds" to CFLAGS
use libasan with GCC and embedded ASAN with Clang
pkg_add git cmake ninja json-c libnet
```

Configuration examples:
On FreeBSD (as root):
```
pkg install git cmake ninja json-c libnet
```
- Use GCC with libasan, debug info and custom CFLAGS:
./configure CC=/usr/bin/gcc --enable-asan --enable-debug CFLAGS="-Wall"

- Use Clang with ASAN and no optimizations (-O0)
./configure CC=/usr/bin/clang --enable-asan --disable-optimization
On MacOS (as root):
```
brew install cmake ninja openssl@3 libpcap libnet json-c
```

Compile & install:
```
git clone https://github.com/adulau/ssldump.git
cd ssldump
cmake -G Ninja -B build
ninja -C build
./build/ssldump -v
(optional, as root) ninja -C build install
```

# Notes
Expand Down
5 changes: 0 additions & 5 deletions autogen.sh

This file was deleted.

Empty file removed base/Makefile.am
Empty file.
4 changes: 3 additions & 1 deletion base/pcap-snoop.c → base/pcap-snoop.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@

#include <pcap.h>
#include <unistd.h>
#ifndef __OpenBSD__
#include <pcap-bpf.h>
#endif
#ifndef _WIN32
#include <sys/param.h>
#endif
Expand Down Expand Up @@ -118,7 +120,7 @@ int usage()

int print_version()
{
printf(PACKAGE_STRING "\n");
printf("Version: @ssldump_VERSION@ (@ssldump_DESCRIPTION@)\n");
printf("Maintained by a bunch of volunteers, see https://github.com/adulau/ssldump/blob/master/CREDITS\n");
printf("Copyright (C) 2015-2023 the aforementioned volunteers\n");
printf("Copyright (C) 1998-2001 RTFM, Inc.\n");
Expand Down
49 changes: 49 additions & 0 deletions cmake/modules/FindJSONC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# From https://github.com/fastogt/cmake/blob/master/FindJSON-C.cmake
# Copyright (c) 2018, FastoGT
# License: BSD 3-Clause
# Modified by: Micah Snyder

# JSONC_FOUND - true if library and headers were found
# JSONC_INCLUDE_DIRS - include directories
# JSONC_LIBRARIES - library directories

if(JSONC_USE_STATIC)
add_library(jsonc STATIC IMPORTED GLOBAL)
else()
add_library(jsonc SHARED IMPORTED GLOBAL)
endif(JSONC_USE_STATIC)

find_package(PkgConfig QUIET)
PKG_CHECK_MODULES(PC_JSONC QUIET json-c)

find_path(JSONC_INCLUDE_DIR json.h
HINTS ${PC_JSONC_INCLUDEDIR} ${PC_JSONC_INCLUDE_DIRS} PATH_SUFFIXES json-c json)

if(JSONC_USE_STATIC)
find_library(JSONC_LIBRARY NAMES libjson-c.a libjson-c-static.a
HINTS ${PC_JSONC_LIBDIR} ${PC_JSONC_LIBRARY_DIRS})
else()
find_library(JSONC_LIBRARY NAMES json-c libjson-c
HINTS ${PC_JSONC_LIBDIR} ${PC_JSONC_LIBRARY_DIRS})
endif(JSONC_USE_STATIC)

set(JSONC_LIBRARIES ${JSONC_LIBRARY})
set(JSONC_INCLUDE_DIRS ${JSONC_INCLUDE_DIR})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(JSONC DEFAULT_MSG JSONC_LIBRARIES JSONC_INCLUDE_DIRS)

if(JSONC_FOUND AND NOT TARGET JSONC::jsonc)
add_library(JSONC::jsonc UNKNOWN IMPORTED)
set_target_properties(JSONC::jsonc PROPERTIES
IMPORTED_LOCATION "${JSONC_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_JSONC_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${JSONC_INCLUDE_DIRS}"
)
endif()

mark_as_advanced(
JSONC_INCLUDE_DIR
JSONC_LIBRARY
)

Loading

0 comments on commit 00f968e

Please sign in to comment.