Coder Social home page Coder Social logo

rafwu / ransomwatch Goto Github PK

View Code? Open in Web Editor NEW
73.0 8.0 34.0 47.81 MB

Ransomware detection application for Windows using Windows Minifilter driver

C 7.81% C++ 92.19%
minifilter-driver minifilter cppcli azure-blob ransomware-detection ransomware-recovery ransomware-applications ransomware-mitigation

ransomwatch's Introduction

RansomWatch

RansomWatch is a solution which monitors and analyses data collected from the file system in real time in order to identify suspicious ransomware behavior on the file system. RansomWatch autonomously stops ransomware applications and backups data in order to prevent data loss.

User-mode GUI application is responsible for handling all data of running applications based on their GID* given by the driver, reporting to user, backup, sending kill requests to driver with GIDs detected as malicious and restoring changed files.

The driver collects file system usage, calculates entropy for read/write operations, gives multi-process applications a unique GID for tracking. It is also responsible for killing malicious applications based on their GID (system processes do not have GID, thus will not be killed).

Application operations are passed to RansomWatch application based on user-mode application request for IRPs (I/O Request Packet) with filterSendMessage. System applications are not recorded, which reduces a significant overhead. Our application records IRP operations usage. After each recording of IRP operation for application, RansomWatch application checks if the state of some applications has changed to malicious.

GID is given by the driver each time a new application is interduced to the system by registering to process creation and ending (PsSetCreateProcessNotifyRoutine). The driver evaluates the image file loaded and decides whether it is a system process - if not, a new GID is assigned and every process generated from this process is given the same GID.

After detecting malicious application and stopping it with our driver, RansomWatch application tries to recover files that were changed using Azure storage. The application can only recover areas that were selected to be protected from the application. The application restores based on last known valid snapshot known (based on dates of first ransomware detection in system and snapshot time).

The user-mode application is written in C++/CLI.


*GID - Group Identifier. Not to be confused with Linux's GID, which is something completely different. It is the name of the unique identifier the driver assigns to a set of all PIDs (process identiders) that are related to one another by process creation. For example, if a process A creates a process B, A and B will share a common GID (the GID that was assigned to process A).

Examples

Detecting WannaCry
Detecting Jigsaw

Open issues

  1. Backup service is incomplete. Backup is done only once, when the user selects new folders to protect. A complete solution should at the very least support periodical backup.
  2. Only dynamic detection is done. Static detectiong should also be used, for example in order to find patterns in exacutables and check for known malicious signatures.
  3. Detection model should consider time as a factor.
  4. Currently the solution does not remove the identified malicious applications from startup folder of Windows, Windows Registry and tasks added to task scheduler.
  5. Our driver save image file loaded for each PID it tracks. This data can be used to clean ransomware.
  6. There is no serialization of data - protected areas and traps should be saved so that RansomWatch application would be able to restore its state after shut down.
  7. The solution does not protect itself. That is, a malicious application can change RansomWatch files and alter its behavior.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Dependencies

  1. Microsoft Visual Studio version 2019 (2017 should be OK as well but we have not tested it).
  2. Windows Driver Kit (WDK).
  3. .NET 4.7.2 or newer.
  4. Windows SDK.
  5. Visual studio build tools 1.4.2 or newer.
  6. C++/CLI support for Visual Studio build tools 1.4.2 or newer.
  7. Microsoft WindowsAzure Storage 9.3.3.

Building

  1. Clone or download this project and load RWatch.sln with Visual Studio.
  2. Make sure that the configuration manager is set to x64.
  3. Replace the Azure blob storage connection string in BackupService.h.
  4. Build the solution. This builds both the driver and the application.

Installing

  1. Our driver uses test signing so before using it Windows should be set to install and run test signed drivers.

    Enable test signed drivers can be done in elevated command prompt with the following command:

    bcdedit /set testsigning on
    

    Restart Windows for changes to take effect.

  2. Copy the solution application (application.exe) and the DLL next to it (Microsoft.WindowsAzure.Storage.dll) to the target machine. those files are generated under: \<project location>/x64/Release

  3. Copy driver files: FsFilter.inf, FsFilter.sys, FsFilter.cer to the target machine and place them in the same directory. Those files are generated under: \<project location>/x64/Debug

  4. Install the driver using .inf file (requires elevated command prompt)

    RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 132 \<Driver files location>\FsFilter.inf
    
  5. Start the driver using fltmc command or by sc command. We tested our solution with service control manager sc:

    sc start FsFilter
    
  6. Stopping the driver by using the command:

    sc stop FsFilter
    
  7. Removing the driver by using the command:

    sc delete FsFilter
    
  8. Run the application, we recommend to run it as Admin.

Prerequisites for running

For running the application, Visual Runtime for Windows is required. The application requires the driver to run to work properly.

Testing

Testing ransomwares requires a VM (well, unless you do not mind testing it on your machine) and a ransomware applications.

  1. After installing the driver and running the application, add a directory to the protected areas with the application.
  2. The application will generate trap files for each extension in the sub-directories of the protected areas and snapshot files to an Azure storage.
  3. Run a ransomware.
  4. After detection, the application generates a log file under system drive with the application GID. Detection information is also written to a log viewer inside the application.

Authors

  • Rafael Wurf
  • Aviad Gafni

License

This project is licensed under the MIT License - see MIT for details

ransomwatch's People

Contributors

acamol avatar rafwu 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ransomwatch's Issues

Error on setting parameters

In function
<BOOLEAN DeletionTrigger()>
addNumOfDirsProtected(0);>
I think need change it to
addNumOfDirsProtected --> need to change to -->addNumOfFilesProtected

IRQL_NOT_LESS_OR_EQUAL BSOD

Hi,

I'm very new to driver dev and there is a good chance I miss something obvious.

I'm able to install the minifilter as described in the README. The application launches successfully for a minute or so and then Windows Crash with a IRQL_NOT_LESS_OR_EQUAL BSOD.

I think I understand what it means but I have no idea how to debug it.

Here are the details of the minidump. If you have an idea, I would greatly appreciate it.

0: kd> !analyze -v


  •                                                                         *
    
  •                    Bugcheck Analysis                                    *
    
  •                                                                         *
    

IRQL_NOT_LESS_OR_EQUAL (a)
An attempt was made to access a pageable (or completely invalid) address at an
interrupt request level (IRQL) that is too high. This is usually
caused by drivers using improper addresses.
If a kernel debugger is available get the stack backtrace.
Arguments:
Arg1: 0000000000000001, memory referenced
Arg2: 0000000000000002, IRQL
Arg3: 0000000000000000, bitfield :
bit 0 : value 0 = read operation, 1 = write operation
bit 3 : value 0 = not an execute operation, 1 = execute operation (only on chips which support this level of status)
Arg4: fffff803562aef58, address which referenced memory

Debugging Details:

KEY_VALUES_STRING: 1

Key  : Analysis.CPU.Sec
Value: 2

Key  : Analysis.DebugAnalysisProvider.CPP
Value: Create: 8007007e on DESKTOP-U9J03LL

Key  : Analysis.DebugData
Value: CreateObject

Key  : Analysis.DebugModel
Value: CreateObject

Key  : Analysis.Elapsed.Sec
Value: 2

Key  : Analysis.Memory.CommitPeak.Mb
Value: 101

Key  : Analysis.System
Value: CreateObject

DUMP_FILE_ATTRIBUTES: 0x8
Kernel Generated Triage Dump

BUGCHECK_CODE: a

BUGCHECK_P1: 1

BUGCHECK_P2: 2

BUGCHECK_P3: 0

BUGCHECK_P4: fffff803562aef58

READ_ADDRESS: fffff803567733b8: Unable to get MiVisibleState
Unable to get NonPagedPoolStart
Unable to get NonPagedPoolEnd
Unable to get PagedPoolStart
Unable to get PagedPoolEnd
fffff8035662a3b8: Unable to get Flags value from nt!KdVersionBlock
fffff8035662a3b8: Unable to get Flags value from nt!KdVersionBlock
unable to get nt!MmSpecialPagesInUse
0000000000000001

BLACKBOXBSD: 1 (!blackboxbsd)

BLACKBOXNTFS: 1 (!blackboxntfs)

BLACKBOXPNP: 1 (!blackboxpnp)

BLACKBOXWINLOGON: 1

CUSTOMER_CRASH_COUNT: 1

IRP_ADDRESS: ffffffffffffff88

DEVICE_OBJECT: ffff848600000000

TRAP_FRAME: fffffd8b3ed4ee40 -- (.trap 0xfffffd8b3ed4ee40)
NOTE: The trap frame does not contain all registers.
Some register values may be zeroed or incorrect.
rax=0000000000000001 rbx=0000000000000000 rcx=fffffd8b3ed4e4a8
rdx=0000000000000001 rsi=0000000000000000 rdi=0000000000000000
rip=fffff803562aef58 rsp=fffffd8b3ed4efd0 rbp=fffffd8b3ed4f119
r8=0000000000000002 r9=ffff848624402000 r10=fffff80356672b00
r11=ffff84863d5e84e0 r12=0000000000000000 r13=0000000000000000
r14=0000000000000000 r15=0000000000000000
iopl=0 nv up ei pl nz na po cy
nt!IopCompleteRequest+0xbe8:
fffff803562aef58 488b00 mov rax,qword ptr [rax] ds:0000000000000001=????????????????
Resetting default scope

STACK_TEXT:
fffffd8b3ed4ecf8 fffff803563d41e9 : 000000000000000a 0000000000000001 0000000000000002 0000000000000000 : nt!KeBugCheckEx
fffffd8b3ed4ed00 fffff803563d0529 : 0000000000000000 0000000000000005 ffff94800caff170 0000000000000000 : nt!KiBugCheckDispatch+0x69
fffffd8b3ed4ee40 fffff803562aef58 : 0000000000000000 fffffd8b3ed4f138 ffff94800caff170 0000000000000000 : nt!KiPageFault+0x469
fffffd8b3ed4efd0 fffff803562a615d : 0000000000000000 0000000000000000 0000000000000100 0000000000000000 : nt!IopCompleteRequest+0xbe8
fffffd8b3ed4f0c0 fffff803562cf44b : 0000000000000000 0000000000000000 0000000000000000 0000000000000000 : nt!KiDeliverApc+0x19d
fffffd8b3ed4f180 fffff803562a1eb4 : 0000000000000000 0000000000000001 0000000000000000 0100000000100000 : nt!KiCheckForKernelApcDelivery+0x2b
fffffd8b3ed4f1b0 fffff8035632c8c3 : 0000000000000000 0000000000000000 0000000000000001 ffff848647d925c0 : nt!KiLeaveGuardedRegionUnsafe+0x24
fffffd8b3ed4f1e0 fffff803562639f4 : 0000000000000000 0000000000001000 0000000000001000 ffffbf82085c0000 : nt!MmWaitForCacheManagerPrefetch+0x67
fffffd8b3ed4f210 fffff803567e49f9 : 0000000000000000 0000000000000000 0000000000000001 fffffd8b3ed4f320 : nt!CcFetchDataForRead+0x104
fffffd8b3ed4f270 fffff80356263725 : ffff848643f8b370 0000000000000000 fffffd8b00040000 ffff848647c62901 : nt!CcMapAndCopyFromCache+0xd9
fffffd8b3ed4f310 fffff8035b102009 : 0000000000000000 ffffaa0d00000000 ffff848600000381 ffffaa0d00000001 : nt!CcCopyReadEx+0x135
fffffd8b3ed4f3b0 fffff8035b1171da : 0000000000000381 ffff848647d925c0 fffffd8b3ed4f610 ffff848645f6ba20 : Ntfs!NtfsCachedRead+0x179
fffffd8b3ed4f420 fffff8035b11641c : fffffd8b3ed4f620 ffff848645f6ba20 fffffd8b3ed4f620 ffff84863dbe8a18 : Ntfs!NtfsCommonRead+0xbaa
fffffd8b3ed4f5e0 fffff80356299ed9 : ffff848645d2c370 ffff848645f6ba20 ffff848645f6be08 0000000000000000 : Ntfs!NtfsFsdRead+0x20c
fffffd8b3ed4f6a0 fffff803585355de : 0000000000000000 fffffd8b3ed4f780 ffff848645f6ba20 fffffd8b3ed4f790 : nt!IofCallDriver+0x59
fffffd8b3ed4f6e0 fffff80358533f16 : fffffd8b3ed4f780 0000000000000000 0000000000000001 fffff8035680fce5 : FLTMGR!FltpLegacyProcessingAfterPreCallbacksCompleted+0x15e
fffffd8b3ed4f760 fffff80356299ed9 : ffff848645f6ba20 0000000000000478 0000000000000000 0000000000000000 : FLTMGR!FltpDispatch+0xb6
fffffd8b3ed4f7c0 fffff803568080a5 : 0000000000000000 ffff848647d925c0 ffff848647d92610 ffff848647d925c0 : nt!IofCallDriver+0x59
fffffd8b3ed4f800 fffff8035680427f : ffff848600000000 0000000000000000 0000000000000000 fffffd8b3ed4fa80 : nt!IopSynchronousServiceTail+0x1a5
fffffd8b3ed4f8a0 fffff803563d3c15 : ffff848642bf3080 0000000000000000 0000000000000000 0000000000000000 : nt!NtReadFile+0x59f
fffffd8b3ed4f990 00007ffbb585c134 : 0000000000000000 0000000000000000 0000000000000000 0000000000000000 : nt!KiSystemServiceCopyEnd+0x25
00000082e0efec88 0000000000000000 : 0000000000000000 0000000000000000 0000000000000000 0000000000000000 : 0x00007ffb`b585c134

SYMBOL_NAME: nt!KiPageFault+469

MODULE_NAME: nt

IMAGE_NAME: ntkrnlmp.exe

IMAGE_VERSION: 10.0.18362.1016

STACK_COMMAND: .thread ; .cxr ; kb

BUCKET_ID_FUNC_OFFSET: 469

FAILURE_BUCKET_ID: AV_nt!KiPageFault

OSPLATFORM_TYPE: x64

OSNAME: Windows 10

FAILURE_ID_HASH: {ec3e2762-48ae-ffe9-5b16-fbcb853e8320}

Followup: MachineOwner

unable to install driver

I have followed the Steps given by you.
But when I start the server it says'[SC] StartService FAILED 487:
Attempt to access invalid address.'
Please help me to resolve it.

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.