• Stars
    star
    153
  • Rank 243,368 (Top 5 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created over 7 years ago
  • Updated over 4 years ago

Reviews

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

Repository Details

Detect silent (unwanted) changes to files on your system

binsnitch.py

binsnitch can be used to detect silent unwanted changes to files on your system. It will scan a given directory recursively for files and keep track of any changes it detects, based on the SHA256 hash of the file. You have the option to either track executable files, or all files.

Requirements

  • python >= 3

Running and usage

usage: binsnitch.py [-h] [-v] [-s] [-a] [-n] [-b] [-w] dir

positional arguments:
  dir               the directory to monitor

optional arguments:
  -h, --help        show this help message and exit
  -v, --verbose     increase output verbosity
  -s, --singlepass  do a single pass over all files
  -a, --all         keep track of all files, not only executables
  -n, --new         alert on new files too, not only on modified files
  -b, --baseline    do not generate alerts (useful to create baseline)
  -w, --wipe        start with a clean db.json and alerts.log file

Example: monitor all executable files on the system and enable verbose logging

python3.5 binsnitch.py -v / 

Example: monitor all files in the current directory and enable verbose logging

python3.5 binsnitch.py -v -a . 

How it works

Once binsnitch.py is running, it will scan all files in dir (provided through a required command line argument) recursively, and create a SHA256 hash of each file it finds. It then does the following:

  • If a file is not known yet by binsnitch.py, its details will be added to binsnitch_data/db.json (file name, file type and hash).
  • If a file is already known but the calculated hash is different from the one in binsnitch_data/db.json, an alert will be logged to data/alert.log. In addition, the new hash will be added to the appropriate entry in binsnitch_data/db.json.
  • If a file is already known and the hash is identical to the one already in binsnitch_data/alert.log, nothing happens.

Example output

binsnitch_data/alerts.log
05/15/2017 02:46:17 AM - INFO - Scanning system for new and modified files, this can take a long time
05/15/2017 02:53:38 AM - INFO - Modified file detected: /Applications/Cyberduck.app/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/Autoupdate.app/Contents/MacOS/Autoupdate - new hash: a897613ab9ecd8ead7b697012036b2ef683a9df7afe99d9013e5dd6c3e08af10
05/15/2017 02:53:39 AM - INFO - Modified file detected: /Applications/Cyberduck.app/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/Autoupdate.app/Contents/MacOS/fileop - new hash: cdad8d7b1cce37547223a198e9fbbe256aed3919b58e1b2305870aeaac33c966
05/15/2017 02:53:41 AM - INFO - Modified file detected: /Applications/Cyberduck.app/Contents/MacOS/Cyberduck - new hash: 3941de0b9001c616c6fcfdb76108fa5da46bdcdd3089e1feb65578c2d251eeec
binsnitch_data/db.json
[
    {
        "path": "/Applications/1Password 6.app/Contents/Frameworks/AgileLibrary.framework/Versions/A/Resources/pngquant",
        "sha256": [
            "47ecd7d9978a291de70aaf5e4392664d5c697cd0867bb59f3d6833671b83d448"
        ],
        "type": "Mach-O 64-bit executable x86_64"
    }
]

Internals

Checking if a file is executable is done by checking it against a fixed list of dangerous file extensions (check binsnitch.py source for details).

In its current version, binsnitch.py eats up a lot of CPU. This is caused by the recursive walk through the filesystem and the calculation of SHA256 hashes for each and every file it encounters.

Ideas for improvement

  • Include a switch to start with a new alerts and db file upon start β˜‘
  • Include a switch to also process new files β˜‘
  • Enable a switch to process all files instead of executables only β˜‘
  • Include a switch for a single pass instead of running forever β˜‘
  • Remove dependency on file command to check for file type information β˜‘
  • Be nicer to system resources (IO and CPU)

Why binsnitch?

Malware will often settle itself by overwriting existing executable applications in order to avoid detection. Recent malware cases (May 2017) do this, including HandBrake being hacked to drop new variant of the Proton malware and the WannaCry ransomware overwriting C:\WINDOWS\system32\tasksche.exe. This triggered us to write a simple tool that could be used to detect this.

binsnitch can also be used during malware analysis, to detect silent changes to files (i.e. replacement of a trusted Windows executable by a trojaned version).

References and comparison to other tools

Similar tools:

These tools are either OS-dependent or require installation of libraries. In addition, binsnitch.py can be used to detect changes to the file system after an infection has taken place (not depending on intercepting API calls during the infection itself) - for example, when analyzing a disk image against a "known good" baseline.

binsnitch.py has no dependencies other than python >= 3.

Community

Bug reports and feature requests are welcome in the issues tab!

Contact us: [email protected].

binsnitch is developed and maintained by Daan Raman (@daanraman).

More Repositories

1

MagiskTrustUserCerts

A Magisk/KernelSU module that automatically adds user certificates to the system root CA store
Shell
1,519
star
2

posh-dsc-windows-hardening

Windows OS Hardening with PowerShell DSC
PowerShell
257
star
3

disable-flutter-tls-verification

A Frida script that disables Flutter's TLS verification
C++
241
star
4

CobaltWhispers

CobaltWhispers is an aggressor script that utilizes a collection of Beacon Object Files (BOF) for Cobalt Strike to perform process injection, persistence and more, leveraging direct syscalls (SysWhispers2) to bypass EDR/AV
C
218
star
5

ee-outliers

Open-source framework to detect outliers in Elasticsearch events
Python
205
star
6

pyCobaltHound

pyCobaltHound is an Aggressor script extension for Cobalt Strike which aims to provide a deep integration between Cobalt Strike and Bloodhound.
Python
136
star
7

frida-ios-playground

An iOS app that lets you practice your Frida skills
Swift
126
star
8

evtx-hunter

evtx-hunter helps to quickly spot interesting security-related activity in Windows Event Viewer (EVTX) files.
Python
125
star
9

Interceptor

Interceptor is a kernel driver focused on tampering with EDR/AV solutions in kernel space
C++
115
star
10

brown-bags

C#
108
star
11

IOXY

MQTT intercepting proxy
Go
97
star
12

decompile-py2exe

Decompile py2exe Python 3 generated EXEs
Python
92
star
13

DInvisibleRegistry

DInvisibleRegistry
C#
81
star
14

blogposts

A repo to house files for our blogposts on blog.nviso.eu
C++
60
star
15

cs2br-bof

C
59
star
16

codasm

Payload encoding utility to effectively lower payload entropy.
Python
53
star
17

cyber-security-llm-agents

A collection of agents that use Large Language Models (LLMs) to perform tasks common on our day to day jobs in cyber security.
Jupyter Notebook
52
star
18

nviso-cti

YARA
40
star
19

nexus_5_bootloader_unpacker

A bootloader imgdata unpacker for Nexus 4, 5 and 7 smartphones as well as imgdata tool for Nexus 5.
C
25
star
20

FileSearcher

C#
22
star
21

logalert.py

Smart piping of command output to email for alerting.
Python
21
star
22

DLLoader

C++
16
star
23

SEC599-Resources

16
star
24

SEC599

SEC599 supporting GitHub repository
Shell
15
star
25

VerifiedBootRPi3

Verified Boot for RPi3
14
star
26

cobalt-strike-notifier

Python
13
star
27

YARA

Repository of YARA rules developed by NVISO
11
star
28

ansible-velociraptor

Ansible role for Velociraptor EDR
9
star
29

cloud-security-automation

PowerShell scripts used in the "Incident response in the cloud/ foggy with a ray of sunshine" conference talk
PowerShell
8
star
30

ansible-sysmon

Ansible role for sysmon
7
star
31

ansible-auditbeat

Ansible role for auditbeat install
7
star
32

ansible-thehive

Ansible role for installing The Hive & Cortex
6
star
33

BitSight-Automation-Tool

BitSight Automation was developed to automate certain manual procedures and extract information such as ratings, assets, findings, etc. This tool also provides the possibility to collaborate with Scheduled Tasks and cronjobs.
Python
6
star
34

ansible-windowslogconfig

Ansible role for configuring Windows security logs
5
star
35

ansible-caldera

Ansible role for MITRE caldera
5
star
36

assemblyline-service-cape

Assemblyline service build for CAPE's API
Python
4
star
37

ansible-elk

Ansible role for ELK stack install
4
star
38

ansible-winlogbeat

Ansible role for WinLogBeat
4
star
39

assemblyline-service-python-exe-unpacker

Python exe unpacker service
Python
3
star
40

ansible-covenant

Ansible role for Covenant
3
star
41

assemblyline-service-urlscanio

URLScan.io AL service
Python
3
star
42

assemblyline-service-clamav

Assemblyline service which submits a file to ClamAV and displays the result
Python
2
star
43

assemblyline-service-msg-extractor

Simple MSG extractor AssemblyLine service
Python
2
star
44

ansible-nexusrepo

Ansible role for Nexus Repository OSS
2
star
45

assemblyline-service-steg-finder

AssemblyLine service which scans for embedded data in image using StegExpose
Python
2
star
46

assemblyline-service-malware-bazaar

Assemblyline service fetching Malware Bazaar report
Python
2
star
47

caldex

Caldera exportation plugin to the MITRE ATT&CKβ„’ Navigator.
Python
2
star
48

assemblyline-service-autoit-ripper

AutoIt unpacker service
Python
1
star
49

assemblyline-service-unfurl

Assemblyline service parsing a submitted URL to unshorten it.
Python
1
star
50

cortex.xsoar

The cortex.xsoar collection includes Ansible modules to help automate the management of Palo Alto Cortex XSOAR.
Python
1
star