• Stars
    star
    742
  • Rank 61,120 (Top 2 %)
  • Language Max
  • License
    Other
  • Created about 11 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build Status

TLSH - Trend Micro Locality Sensitive Hash

TLSH is a fuzzy matching library. Given a byte stream with a minimum length of 50 bytes 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.

What's New in TLSH 4.10.x

22/09/2021

Release version 4.8.x - merged in pull requests for more stable installation.

Release version 4.9.x - added -thread and -private options.

  • Both versions are faster than previous versions, but they set the checksum to 00.
  • This loses a very small part of the functionality.
  • See 4.9.3 in the Change_History to see timing comparisons.

Release version 4.10.x - a Python clustering tool.

  • See the directory tlshCluster.

2020

TLSH has gained some traction. It has been included in STIX 2.1 and been ported to a number of langauges.

We have added a version identifier ("T1") to the start of the digest so that we can cleary distinguish between different variants of the digest (such as non-standard choices of 3 byte checksum). This means that we do not rely on the length of the hex string to determine if a hex string is a TLSH digest (this is a brittle method for identifying TLSH digests). We are doing this to enable compatibility, especially backwards compatibility of the TLSH approach.

The code is backwards compatible, it can still read and interpret 70 hex character strings as TLSH digests. And data sets can include mixes of the old and new digests. If you need old style TLSH digests to be outputted, then use the command line option '-old'

Dedication

Thanks to Chun Cheng, who was a humble and talented engineer.

Minimum byte stream length

The program in default mode requires an input byte stream with a minimum length of 50 bytes (and a minimum amount of randomness - see note in Python extension below).

For consistency with older versions, there is a -conservative option which enforces a 256 byte limit. See notes for version 3.17.0 of TLSH

Computed hash

The computed hash is 35 bytes of data (output as 'T1' followed 70 hexidecimal characters. Total length 72 characters). The 'T1' has been added as a version number for the hash - so that we can adapt the algorithm and still maintain backwards compatibility. To get the old style 70 hex hashes, use the -old command line option.

Bytes 3,4,5 are used to capture the information about the file as a whole (length, ...), while the last 32 bytes are used to capture information about incremental parts of the file. (Note that the length of the hash can be increased by changing build parameters described below in CMakeLists.txt, which will increase the information stored in the hash. For some applications this might increase the accuracy in predicting similarities between files.)

Executables and library

Building TLSH (see below) will create a static library in the lib directory, and the tlsh executable (a symbolic link to tlsh_unittest). 'tlsh' links to the static library, in the bin directory. The library has functionality to generate the hash value from a given file, and to compute the similarity between two hash values.

tlsh is a utility for generating TLSH hash values and comparing TLSH hash values to determine similarity. Run it with no parameters for detailed usage.

Ports

  • A JavaScript port available in the js_ext directory.
  • A Java port is available in the java directory.

3rd Party Ports

We list these ports just for reference. We have not checked the code in these repositories, and we have not checked that the results are identical to TLSH here. We also request that any ports include the files LICENSE and NOTICE.txt exactly as they appear in this repository.

  • Another Java port is available here.
  • Another Java port is available here.
  • A Golang port is available here.
  • A Ruby port is available here

Downloading TLSH

Download TLSH as follows:

wget https://github.com/trendmicro/tlsh/archive/master.zip -O master.zip
unzip master.zip
cd tlsh-master

or

git clone git://github.com/trendmicro/tlsh.git
cd tlsh
git checkout master

Building TLSH

Edit CMakeLists.txt to build TLSH with different options.

  • TLSH_BUCKETS: determines using 128 or 256 buckets use the default 128 buckets unless you are an expert and know you need 256 buckets
  • TLSH_CHECKSUM_1B: determines checksum length, longer means less collision use the default 1 byte unless you are an expert and know you need a larger checksum

Linux

Execute:

make.sh

Note: Building TLSH on Linux depends upon cmake to create the Makefile and then make the project, so the build will fail if cmake is not installed. To install cmake/gcc compiler on CentOs or Amazon Linux: $ sudo yum install cmake $ sudo yum install gcc-c++

Windows (MinGW)

Added in March 2020. See the instructions in README.mingw

Windows (Visual Studio)

Use the version-specific tlsh solution files (tlsh.VC2005.sln, tlsh.VC2008.sln, ...) under the Windows directory.

See tlsh.h for the tlsh library interface and tlsh_unittest.cpp and simple_unittest.cpp under the test directory for example code.

Using TLSH in Python

Python Package

We have recently created a Python package on PyPi: https://pypi.org/project/py-tlsh/
The py-tlsh replaces the python-tlsh package. For details see issue 94
To install this package

	$  pip install py-tlsh

Python Extension

If you need to build your own Python package, then there is a README.python with notes about the python version

(1) compile the C++ code
	$./make.sh
(2) build the python version
	$ cd py_ext/
	$ python ./setup.py build
(3) install - possibly - sudo, run as root or administrator
	$ python ./setup.py install
(4) test it
	$ cd ../Testing
	$ ./python_test.sh

Python Usage

import tlsh

tlsh.hash(data)

Note data needs to be bytes - not a string. This is because TLSH is for binary data and binary data can contain a NULL (zero) byte.

In default mode the data must contain at least 50 bytes to generate a hash value and that it must have a certain amount of randomness. To get the hash value of a file, try

tlsh.hash(open(file, 'rb').read())

Note: the open statement has opened the file in binary mode.

Python Example

import tlsh

h1 = tlsh.hash(data)
h2 = tlsh.hash(similar_data)
score = tlsh.diff(h1, h2)

h3 = tlsh.Tlsh()
with open('file', 'rb') as f:
    for buf in iter(lambda: f.read(512), b''):
        h3.update(buf)
    h3.final()
# this assertion is stating that the distance between a TLSH and itself must be zero
assert h3.diff(h3) == 0
score = h3.diff(h1)

Python Extra Options

The diffxlen function removes the file length component of the tlsh header from the comparison.

tlsh.diffxlen(h1, h2)

If a file with a repeating pattern is compared to a file with only a single instance of the pattern, then the difference will be increased if the file lenght is included. But by using the diffxlen function, the file length will be removed from consideration.

Python Backwards Compatibility Options

If you use the "conservative" option, then the data must contain at least 256 characters. For example,

import os
tlsh.conservativehash(os.urandom(256))

should generate a hash, but

tlsh.conservativehash(os.urandom(100))

will generate TNULL as it is less than 256 bytes.

If you need to generate old style hashes (without the "T1" prefix) then use

tlsh.oldhash(os.urandom(100))

The old and conservative options may be combined:

tlsh.oldconservativehash(os.urandom(500))

Design Choices

  • To improve comparison accuracy, TLSH tracks counting bucket height distribution in quartiles. Bigger quartile difference results in higher difference score.
  • Use specially 6 trigrams to give equal representation of the bytes in the 5 byte sliding window which produces improved results.
  • Pearson hash is used to distribute the trigram counts to the counting buckets.
  • The global similarity score distances objects with significant size difference. Global similarity can be disabled. It also distances objects with different quartile distributions.
  • TLSH can be compiled to generate 70 or 134 characters hash strings. The longer version has been created to use of the 70 char hash strings is not working for your application.

TLSH similarity is expressed as a difference score:

  • A score of 0 means the objects are almost identical.
  • For the 72 characters hash, there is a detailed table of experimental Detection rates and False Positive rates based on the threshhold. see Table II on page 5

Clustering

  • See the Python code and Jupyter notebooks in tlshCluster.
  • We provide Python code for the HAC-T method. We also provide code so that users can use DBSCAN.
  • We show users how to create dendograms for files, which are a useful diagram showing relationships between files and groups.
  • We provide tools for clustering the Malware Bazaar dataset, which contains a few hundred thousand samples.
  • The HAC-T method is described in HAC-T and fast search for similarity in security

Publications

Current Version

4.11.2

23/10/2021
	resolve issue #116
	Library will not compile on CENTOS 7 (use of threads)

Change History

see Change_History.md

More Repositories

1

defplorex

defplorex for BlackHat Arsenal
Python
113
star
2

telfhash

Symbol hash for ELF files
Python
102
star
3

ais

Toolkit for research purposes in AIS. See the website for the paper.
Python
95
star
4

RFQuack

RFQuack: the versatile RF-analysis tool that quacks!
C++
90
star
5

cloudone-filestorage-plugins

Trend Micro Cloud One File Storage Security plugins reference code.
Python
42
star
6

serverless-survey-forms

To create a google-style survey forms, authorized users could design surveys and collect anonymous feedbacks.
JavaScript
25
star
7

thus

Trend Micro Hybrid Cloud Security Command Line Interface
Python
22
star
8

research

Resources from Trend Micro Research teams
YARA
22
star
9

cloudone-container-security-helm

Helm chart for Trend Micro Cloud One Container Security
Mustache
18
star
10

cloudone-community

Collection of Trend Micro Open Source Community Projects
Python
17
star
11

cloudone-filestorage-deployment-templates

HCL
16
star
12

tm-v1-api-cookbook

Trend Vision One API cookbook sample code
Python
12
star
13

tm-v1

Trend Vision One Open Source Community Projects
11
star
14

terraform-provider-conformity

Conformity Terraform provider
Go
10
star
15

RadioHAL

RadioHAL is a fork of the famous RadioHead library that makes zero assumptions on the payload structure. It's the radio driver of RFQuack https://github.com/trendmicro/RFQuack
C++
8
star
16

tmas-scan-action

Vision One Container Security Scan Action
Shell
8
star
17

cloudone-antimalware-python-sdk

Python library for the Cloud One Antimalware API.
Python
7
star
18

conformity-migration-tool

Migrates your visiblity information in cloudconformity.com to cloudone.trendmicro.com
Python
6
star
19

new-release-version

Go
5
star
20

c1ws-mitre-policy

5
star
21

terraform-provider-vision-one

Go
4
star
22

cloudone-conformity-controltower-lifecycle

Python
3
star
23

v1-cloud-community

About Collection of Trend Micro Open Source Community Projects related to Trend Vision One
Shell
3
star
24

cloudone-workload-controltower-lifecycle

Python
2
star
25

cloudone-network-security-deployments

HCL
2
star
26

tm-v1-fs-golang-sdk

Trend Vision One File Security Go SDK
Go
2
star
27

NLP-SecureSpacy

Python
2
star
28

cloudone-antimalware-golang-sdk

Go library for the Cloud One Antimalware API.
Go
1
star
29

tm-v1-detection-models

Trend Vision One Detection Models
1
star
30

cloudone-network-security-samples

HCL
1
star
31

tm-v1-containersecurity

Trend Vision One Container Security Samples and Examples
Shell
1
star
32

tm-v1-customscripts

Trend Vision One Custom Script Samples and Examples
PowerShell
1
star
33

tm-v1-fs-java-sdk

Trend Vision One File Security Java SDK
Java
1
star
34

cloudone-antimalware-java-sdk

Java library for the Cloud One Antimalware API.
Java
1
star
35

tm-v1-hunting-queries

Trend Vision One Hunting Query Examples
1
star