Coder Social home page Coder Social logo

httptoolkit / read-tls-client-hello Goto Github PK

View Code? Open in Web Editor NEW
38.0 3.0 4.0 49 KB

A pure-JS module to read TLS client hello data and calculate TLS fingerprints from an incoming socket connection.

Home Page: https://httptoolkit.com

License: Apache License 2.0

TypeScript 97.22% JavaScript 2.78%
tls client-hello networking nodejs tls-fingerprint

read-tls-client-hello's Introduction

Read-TLS-Client-Hello Build Status Available on NPM

Part of HTTP Toolkit: powerful tools for building, testing & debugging HTTP(S)

A pure-JS module to read TLS client hello data and calculate TLS fingerprints from an incoming socket connection. Tiny, with zero runtime dependencies.

Using this, you can analyze incoming TLS connections before you start a full handshake, and using their fingerprints you can recognize certain TLS clients - e.g. specific browser, cURL, or even the specific versions of a specific programming language a client is using - regardless of the content of the request they send.

See https://httptoolkit.com/blog/tls-fingerprinting-node-js/#how-does-tls-fingerprinting-work for more background on how TLS fingerprinting works.

Be aware that fingerprinting is not a 100% reliable test. Most clients can modify their TLS fingerprint with a bit of work (though few do). In many cases, it's even possible to mimic another arbitrary fingerprint on demand (e.g. using libraries like CycleTLS). Most of the time though, for clients that aren't actively messing with you, the fingerprint will tell you what kind of client is making the connection.

Docs

TLS server helper

The easiest way to use this is to use the built-in trackClientHellos helper, which can be applied to any tls.TLSServer instance, including https.Server instances, like so:

const https = require('https');
const { trackClientHellos } = require('read-tls-client-hello');

const server = new https.Server({ /* your TLS options etc */ });

trackClientHellos(server); // <-- Automatically track everything on this server

server.on('request', (request, response) => {
    // In your normal request handler, check `tlsClientHello` on the request's socket:
    console.log('Received request with TLS client hello:', request.socket.tlsClientHello);
});

A tlsClientHello property will be attached to all sockets, containing the parsed data returned by readTlsClientHello (see below) and a ja3 property with the JA3 TLS fingerprint for the client hello, e.g. cd08e31494f9531f560d64c695473da9.

Reading a TLS client hello

To read all available data from a TLS client hello manually, pass a stream (e.g. a net.Socket) to the exported readTlsClientHello(stream), before the TLS handshake (or any other processing) starts. This returns a promise containing all data parsed from the client hello.

This method reads the initial data from the socket, parses it, and then unshifts it back into the socket, so that once the returned promise resolves the stream can be used like new, to start a normal TLS session using the same client hello.

If parsing fails, this method will throw an error, but will still ensure all data is returned to the socket first, so that non-TLS streams can also be processed as normal.

The returned promise resolves to an object, containing:

  • serverName - The server name requested in the client hello (or undefined if SNI was not used)
  • alpnProtocols - A array of ALPN protcol names requested in the client hello (or undefined if ALPN was not used)
  • fingerprintData - An array containing the raw components used for JA3 TLS fingerprinting:
    1. The TLS version number as a Uint16 (771 for TLS 1.2+)
    2. An array of cipher ids (excluding GREASE)
    3. An array of extension ids (excluding GREASE)
    4. An array of supported group ids (excluding GREASE)
    5. An array of supported elliptic curve ids

TLS fingerprinting

To calculate TLS fingerprints manually, there are a few options exported from this module:

  • getTlsFingerprintAsJa3 - Reads from a stream, just like readTlsClientHello above, but returns a promise for the JA3 hash string, e.g. cd08e31494f9531f560d64c695473da9, instead of the raw hello components.
  • readTlsClientHello(stream) - Reads the entire hello (see above). In the returned object, you can read the raw data components used for fingerprinting from the fingerprintData property.
  • calculateJa3FromFingerprintData(data) - Takes raw TLS fingerprint data, and returns the corresponding JA3 hash.

read-tls-client-hello's People

Contributors

pimterry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

read-tls-client-hello's Issues

Can we use this using next.js?

How can I use this module within next.js's new /app router?

Needed for security reasons on my platform since I want to implement a security algorithm using a person's TLS fingerprint and some more data.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.