-
Notifications
You must be signed in to change notification settings - Fork 855
Add jax_fingerprint plugin #12995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
maskit
wants to merge
23
commits into
apache:master
Choose a base branch
from
maskit:jax
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add jax_fingerprint plugin #12995
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
1b34950
Add jax_fingerprint plugin
maskit 4735816
Add license headers
maskit 0cd2ceb
Add the new documentation to the toc
maskit 6d194ca
Include limit.h
maskit dcad0ef
Include sha.sh instead of sha2.h
maskit 2b6218c
Don't use std::copy
maskit 27346e9
Use heterogeneous lookup only if it's available
maskit a4a71a7
Fix documentation format
maskit 9ab0323
Fix documentation
maskit a4d582e
Fix documentation format
maskit 0d579cc
Don't use std::ranges::equal
maskit 9a20fcd
Fix memory leak
maskit 6a742e2
Fix logic error
maskit d6876e3
Adjust type difference
maskit 09b7d69
Address some copilot comments
maskit c259136
Address some more comments
maskit 497671a
Address some more comments
maskit ad829a6
Address some more comments
maskit 5d450e2
Address some more comments
maskit bcff63e
Fix the keep mode
maskit cb655d3
Add a missing break
maskit c228c7d
Address some more comments
maskit a2ad4a1
Address comments
maskit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| .. Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
|
|
||
| .. include:: ../../common.defs | ||
|
|
||
| .. _admin-plugins-jax-fingerprint: | ||
|
|
||
| JAx Fingerprint Plugin | ||
| ********************** | ||
|
|
||
| Description | ||
| =========== | ||
|
|
||
| The JAx Fingerprint plugin generates client fingerprints based on the JA4+ or JA3 algorithms designed by John Althouse. | ||
|
|
||
| Fingerprints can be used for: | ||
|
|
||
| * Client identification and tracking | ||
| * Bot detection and mitigation | ||
| * Security analytics and threat intelligence | ||
| * Understanding client implementation patterns | ||
|
|
||
|
|
||
| Plugin Configuration | ||
| ==================== | ||
|
|
||
| You can use the plugin as a global plugin, a remap plugin, or both. | ||
|
|
||
| To use the plugin as a global plugin, add the following line to :file:`plugin.config`:: | ||
|
|
||
| jax_fingerprint.so --standalone | ||
|
|
||
| To use the plugin as a remap plugin, append the following line to a remap rule on :file:`remap.config`:: | ||
|
|
||
| @plugin=jax_fingerprint.so @pparam=--standalone | ||
|
|
||
| To use the plugin in a hybrid setup (both global and remap plugin), configure it in both :file:`plugin.config` and | ||
| :file:`remap.config` without `--standalone` option. | ||
|
|
||
|
|
||
| .. option:: --standalone | ||
|
|
||
| This option enables you to use the plugin as either a global plugin, or a remap plugin. In other | ||
| words, the option needs to be specified if you do not use the hybrid setup. | ||
|
|
||
| .. option:: --method <JA4|JA4H|JA3> | ||
|
|
||
| Fingerprinting method (e.g. JA4, JA3, etc.) to use. | ||
|
|
||
| .. option:: --mode <overwrite|keep|append> | ||
|
|
||
| This option specifies what to do if requests from clients have the header names that are specified | ||
| by `--header` and/or `--via-header`. Available setting values are "overwrite", "keep" and "append". | ||
|
|
||
| .. option:: --servernames <servername1,servername2,...> | ||
|
|
||
| This option specifies server name(s) for which the plugin generates fingerprints. | ||
| The value must be provided as a single comma separated value (no space) of server names. | ||
|
|
||
| .. option:: --header <header_name> | ||
|
|
||
| This option specifies the name of the header field where the plugin stores the generated fingerprint value. If not specified, header generation will be suppressed. | ||
|
|
||
| .. option:: --via-header <via_header_name> | ||
|
|
||
| This option specifies the name of the header field where the plugin stores the generated fingerprint-via value. If not specified, header generation will be suppressed. | ||
|
|
||
| .. option:: --log-filename <filename> | ||
|
|
||
| This option specifies the filename for the plugin log file. If not specified, log output will be suppressed. | ||
|
|
||
|
|
||
| Plugin Behavior | ||
| =============== | ||
|
|
||
| Global plugin setup | ||
| ------------------- | ||
|
|
||
| Global plugin setup is the best if you: | ||
| * Need a fingerprint on every request | ||
|
|
||
| Remap plugin setup | ||
| ------------------ | ||
|
|
||
| Remap plugin setup is the best if you: | ||
| * Need a fingerprint only on specific paths, or | ||
| * Cannot use Global plugin setup | ||
|
|
||
| .. note:: For JA3 and JA4, fingerprints are always generated at the beginning of connections. Using remap plugin setup only reduces the overhead of adding HTTP headers and logging. | ||
|
|
||
| Hybrid setup | ||
| ------------ | ||
|
|
||
| Hybrid setup is the best if you: | ||
| * Need a fingerprint only for specific server names (in TLS SNI extension), and | ||
| * Need a fingerprint only on specific paths | ||
|
|
||
|
|
||
| Log Output | ||
| ========== | ||
|
|
||
| The plugin outputs a log file in the Traffic Server log directory (typically ``/var/log/trafficserver/``) if a log filename is | ||
| specified by ``--log-filename`` option. | ||
|
|
||
| **Log Format**:: | ||
|
|
||
| [timestamp] Client: <address> <method_name>: <fingerprint> | ||
|
|
||
| **Example**:: | ||
|
|
||
| [Jan 29 10:15:23.456] Client: 192.168.1.100 JA4: t13d1516h2_8daaf6152771_b186095e22b6 | ||
| [Jan 29 10:15:24.123] Client: 10.0.0.50 JA4: t13d1715h2_8daaf6152771_02713d6af862 | ||
|
|
||
|
|
||
| Using HTTP Headers in Origin Requests | ||
| ===================================== | ||
|
|
||
| Origin servers can access the generated fingerprint through the injected HTTP header. | ||
| This allows the origin to: | ||
|
|
||
| * Make access control decisions based on client fingerprints | ||
| * Log fingerprints for security analysis | ||
| * Track client populations and TLS implementation patterns | ||
|
|
||
| The fingerprint-via header allows origin servers to track which Traffic Server proxy handled the request when multiple proxies are deployed. | ||
|
|
||
|
|
||
| Debugging | ||
| ========= | ||
|
|
||
| To enable debug logging for the plugin, set the following in :file:`records.yaml`:: | ||
|
|
||
| records: | ||
| diags: | ||
| debug: | ||
| enabled: 1 | ||
| tags: jax_fingerprint | ||
|
|
||
|
|
||
| Requirements | ||
| ============ | ||
|
|
||
| * Traffic Server must be built with TLS support (OpenSSL or BoringSSL) if you use JA3 or JA4 | ||
|
|
||
|
|
||
| See Also | ||
| ======== | ||
| * JA3 Technical Specification: https://github.com/FoxIO-LLC/ja3 | ||
| * JA4+ Technical Specification: https://github.com/FoxIO-LLC/ja4 | ||
|
|
||
|
|
||
| Example Configuration | ||
| ===================== | ||
|
|
||
| Enable JA4 fingerprinting by hybrid (global + remap) setup | ||
| ---------------------------------------------------------- | ||
|
|
||
| This configuration adds x-my-ja4 header if a connection is established for either abc.example or xyz.example. | ||
|
|
||
| **plugin.config**:: | ||
|
|
||
| jax_fingerprint.so --method JA4 --servernames abc.example,xyz.example | ||
|
|
||
| **remap.config**:: | ||
|
|
||
| map / http://origin.example/ @plugin=jax_fingerprint.so @pparam=--method=JA4 @pparam=--header=x-my-ja4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| ####################### | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||
| # agreements. See the NOTICE file distributed with this work for additional information regarding | ||
| # copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with the License. You may obtain | ||
| # a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software distributed under the License | ||
| # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
| # or implied. See the License for the specific language governing permissions and limitations under | ||
| # the License. | ||
| # | ||
| ####################### | ||
|
|
||
| add_atsplugin( | ||
| jax_fingerprint | ||
| plugin.cc | ||
| context.cc | ||
| userarg.cc | ||
| header.cc | ||
| log.cc | ||
| ja3/ja3_method.cc | ||
| ja3/ja3_utils.cc | ||
| ja4/ja4_method.cc | ||
| ja4/ja4.cc | ||
| ja4/tls_client_hello_summary.cc | ||
| ja4h/ja4h_method.cc | ||
| ja4h/ja4h.cc | ||
| ) | ||
| target_link_libraries(jax_fingerprint PRIVATE OpenSSL::Crypto OpenSSL::SSL) | ||
| verify_global_plugin(jax_fingerprint) | ||
|
|
||
| if(BUILD_TESTING) | ||
| add_executable(test_jax ja3/test_ja3.cc ja3/ja3_utils.cc ja4/test_ja4.cc ja4/ja4.cc ja4/tls_client_hello_summary.cc) | ||
| target_link_libraries(test_jax PRIVATE Catch2::Catch2WithMain) | ||
|
|
||
| add_catch2_test(NAME test_jax COMMAND test_jax) | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /** @file | ||
|
|
||
| @section license License | ||
|
|
||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "ts/ts.h" | ||
| #include "method.h" | ||
|
|
||
| #include <string> | ||
| #include <unordered_set> | ||
|
|
||
| enum class Mode : int { | ||
| OVERWRITE, | ||
| KEEP, | ||
| APPEND, | ||
| }; | ||
|
|
||
| enum class PluginType : int { | ||
| GLOBAL, | ||
| REMAP, | ||
| }; | ||
|
|
||
| // This hash function enables looking up the set by a string_view without making a temporary string object. | ||
| struct StringHash { | ||
| // Enable heterogeneous lookup | ||
| using is_transparent = void; | ||
|
|
||
| size_t | ||
| operator()(std::string_view sv) const | ||
| { | ||
| return std::hash<std::string_view>{}(sv); | ||
| } | ||
| }; | ||
|
|
||
| struct PluginConfig { | ||
| PluginType plugin_type = PluginType::GLOBAL; | ||
| Mode mode = Mode::OVERWRITE; | ||
| struct Method method = {"uninitialized", Method::Type::CONNECTION_BASED, nullptr, nullptr}; | ||
| std::string header_name = ""; | ||
| std::string via_header_name = ""; | ||
| std::string log_filename = ""; | ||
| int user_arg_index = -1; | ||
| TSCont handler = nullptr; // For remap plugin | ||
| bool standalone = false; | ||
| std::unordered_set<std::string, StringHash, std::equal_to<>> servernames; | ||
| TSTextLogObject log_handle = nullptr; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /** @file | ||
|
|
||
| @section license License | ||
|
|
||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| #include "plugin.h" | ||
| #include "context.h" | ||
|
|
||
| JAxContext::JAxContext(const char *method_name, sockaddr const *s_sockaddr) : _method_name(method_name) | ||
| { | ||
| _addr[0] = '\0'; | ||
|
|
||
| if (s_sockaddr == nullptr) { | ||
| return; | ||
| } | ||
|
|
||
| switch (s_sockaddr->sa_family) { | ||
| case AF_INET: | ||
| inet_ntop(AF_INET, &reinterpret_cast<const sockaddr_in *>(s_sockaddr)->sin_addr, _addr, INET_ADDRSTRLEN); | ||
| break; | ||
| case AF_INET6: | ||
| inet_ntop(AF_INET6, &reinterpret_cast<const sockaddr_in6 *>(s_sockaddr)->sin6_addr, _addr, INET6_ADDRSTRLEN); | ||
| break; | ||
| case AF_UNIX: | ||
| strncpy(_addr, reinterpret_cast<const sockaddr_un *>(s_sockaddr)->sun_path, sizeof(_addr) - 1); | ||
| _addr[sizeof(_addr) - 1] = '\0'; | ||
maskit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| const std::string & | ||
| JAxContext::get_fingerprint() const | ||
| { | ||
| return this->_fingerprint; | ||
| } | ||
|
|
||
| void | ||
| JAxContext::set_fingerprint(const std::string &fingerprint) | ||
| { | ||
| this->_fingerprint = fingerprint; | ||
| Dbg(dbg_ctl, "Fingerprint: %s", this->_fingerprint.c_str()); | ||
| } | ||
|
|
||
| const char * | ||
| JAxContext::get_addr() const | ||
| { | ||
| return this->_addr; | ||
| } | ||
|
|
||
| const char * | ||
| JAxContext::get_method_name() const | ||
| { | ||
| return this->_method_name; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.