Giter Club home page Giter Club logo

tlsh-js's Introduction

Logo

JavaScript port of TLSH (Trend Micro Locality Sensitive Hash)

Build Status Total Downloads

TLSH is a fuzzy matching library designed by Trend Micro (Hosted in GitHub)

Given a byte stream with a minimum length of 512 characters (and a minimum amount of randomness), TLSH generates a hash value which can be used for similarity comparisons. Similar objects will have similar hash values which allows for the detection of similar objects by comparing their hash values. Note that the byte stream should have a sufficient amount of complexity. For example, a byte stream of identical bytes will not generate a hash value.

The computed hash is 70 hexadecimal characters long. The first 6 characters are used to capture the information about the file as a whole (length, ...), while the last 64 characters are used to capture information about incremental parts of the file.

Installation

Although originally designed for use with Node.js and installable via npm using npm install --save tlsh, it can also be used directly in the browser (see browserify task defined in Gruntfile.js).

How it's used

With TLSH mainly you can calculate a hash using supported Strings and compute the difference between two resultant hashes.

How-To calculate a Hash

To compute a Hash using TLSH, you should do the following:

// Quote extracted from 'The UNIX-HATERS Handbook'
var str = "The best documentation is the UNIX source. After all, this is what the " +
            "system uses for documentation when it decides what to do next! The " +
            "manuals paraphrase the source code, often having been written at " +
            "different times and by different people than who wrote the code. " +
            "Think of them as guidelines. Sometimes they are more like wishes... " +
            "Nonetheless, it is all too common to turn to the source and find " +
            "options and behaviors that are not documented in the manual. Sometimes " +
            "you find options described in the manual that are unimplemented " +
            "and ignored by the source.";

var hash = hash(str);   

The resultant hash will be 6FF02BEF718027B0160B4391212923ED7F1A463D563B1549B86CF62973B197AD2731F8 as is described in the TLSH unit tests.

Requirements

The input data must contain:

  • At least 512 characters.
  • A certain amount of randomness.

to generate a hash value. In other case an InsufficientComplexityError will be thrown.

How-To compute difference between two hashes

  1. You should to create two digests using the Digest Hash Builder with hashes as inputs:
var digest1 = new DigestHashBuilder().withHash("09F05A198CC69A5A4F0F9380A9EE93F2B927CF42089EA74276DC5F0BB2D34E68114448").build();
var digest2 = new DigestHashBuilder().withHash("301124198C869A5A4F0F9380A9AE92F2B9278F42089EA34272885F0FB2D34E6911444C").build();
  1. You can compute the difference using one Digest against the other one
// Should be equals to digest1.calculateDifference(digest2, true);
digest2.calculateDifference(digest1, true);

The computed difference should be 121 as is described in Digest unit tests.

Note: Computing the difference using a digest against itself should return no difference.

How to measure the difference?

  • A difference of 0 means the objects are almost identical.
  • A difference of 200 or higher means the objects are very different.

Ignoring the input data length

The difference should be calculated using the file length component or removing it (giving false as second parameter). If an input with a repeating pattern is compared to an input with only a single instance of the pattern, then the difference will be increased if the length is included. Giving a false value to the second parameter, the input data length will be removed from consideration.

Requirements

The library has been tested with Node.js v8.12.0, npm 6.4.1 and grunt v1.0.3. Newer versions should work but could also present issues.

Design choices

We have adopted the original Trend Locality Sensitive Hashing design choices to build this JavaScript port.

TODO

  • Complete Data Tests using input data and resulting digests from Trend Micro official repository.

License

Read LICENSE attached to the project

tlsh-js's People

Contributors

dortegau avatar dpoetzsch avatar jmonterrubio avatar johnhenry 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  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  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  avatar  avatar  avatar  avatar

Watchers

 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

tlsh-js's Issues

LICENSE and NOTICE file need to updated to respect original TLSH LICENSE

Prerequisites

Description

The LICENSE is incorrect - it needs to be the original LICENSE file from
https://github.com/trendmicro/tlsh/blob/master/LICENSE
The NOTICE file from https://github.com/trendmicro/tlsh/blob/master/NOTICE.txt has been removed. The Apache LICENSE requires that the NOTICE file be kept.

Steps to Reproduce

Read the LICENSE file here
Read the LICENSE file at https://github.com/trendmicro/tlsh/blob/master/LICENSE

Versions

all

Additional Information

see above

Update browserify due to CVE-2018-16472 in transitive dependency (cached-path-relative)

Prerequisites

Description

Fix https://nvd.nist.gov/vuln/detail/CVE-2018-16472 notified by GitHub (there is no potential security issues because is used by browserify, but it's a good moment to update) in cached-path-relative library

Versions

versions <= 1.0.6

Additional Information

Update grunt-browserify to 5.3.0

There are some vulnerabilities related to grunt-browserify 5.0.0 dependencies marked as High.

npm recommends updating to grunt-browserify 5.3.0

Error creating minified dist lib

Prerequisites

Description

The minified lib is not created in the dist folder

Steps to Reproduce

  1. npm install

Expected behavior: Create the minified lib in dist folder

Actual behavior: No dist folder is created

Reproduces how often: Always

Versions

1.0.5

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

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.