GithubHelp home page GithubHelp logo

tonerchamp / libwfp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mullvad/libwfp

0.0 0.0 0.0 1017 KB

C++ library for interacting with the Windows Filtering Platform (WFP)

License: MIT License

C++ 98.93% C 1.07%

libwfp's Introduction

Mullvad libwfp

libwfp is a C++ library for interacting with the Windows Filtering Platform (WFP). Notably, libwfp provides builders for defining providers, filters and sets of conditions.

Checking out the code

The code is dependent on one other repository:

  • mullvad/windows-libraries

    Specifically, the libcommon library contained herein, for general functionality not provided by the standard library.

For reasons of flexibility, this repository is not included as a submodule. It is instead required to be checked out at the same level as libwfp:

mkdir libwfp && cd libwfp
git clone https://github.com/mullvad/windows-libraries.git
git clone https://github.com/mullvad/libwfp.git

Development environment

libwfp requires Visual Studio 2022. Any edition will work, e.g. Visual Studio Community 2022 is a perfectly fine choice.

Dependencies

For dependencies required during development, see above, section Checking out the code.

For deployment there are no external dependencies beyond what is already provided by Windows itself.

libwfp is targeted at Windows 7, 8 and 10.

Example usage

Fine-grained blocking of outgoing connections

#include <libwfp/filterengine.h>
#include <libwfp/buildervalidation.h>
#include <libwfp/sublayerbuilder.h>
#include <libwfp/objectinstaller.h>
#include <libwfp/conditionbuilder.h>
#include <libwfp/conditions/conditionapplication.h>
#include <libwfp/conditions/conditionportrange.h>
#include <libwfp/conditions/comparison.h>
#include <libwfp/filterbuilder.h>
#include <memory>

int main()
{
    auto engine = wfp::FilterEngine::DynamicSession();

    wfp::SublayerBuilder sublayer(wfp::BuilderValidation::OnlyCritical);

    sublayer
        .name(L"libwfp example layer")
        .weight(MAXUINT16);

    GUID sublayerGuid;

    wfp::ObjectInstaller::AddSublayer(*engine, sublayer, &sublayerGuid);

    // Conditions are checked against the specified layer
    // To verify that they're compatible
    wfp::ConditionBuilder conditions(FWPM_LAYER_ALE_AUTH_CONNECT_V4);

    // Match on application
    conditions.add_condition(std::make_unique<wfp::conditions::ConditionApplication>( \
        L"c:\\windows\\system32\\svchost.exe"));

    // Match remote ports outside given range
    conditions.add_condition(wfp::conditions::ConditionPortRange::Remote( \
        0, 1023, wfp::conditions::CompareNeq()));

    wfp::FilterBuilder filter(wfp::BuilderValidation::OnlyCritical);

    filter
        .name(L"Svchost peer filter")
        .description(L"Block comms with remote services outside the well-known port range")
        .layer(FWPM_LAYER_ALE_AUTH_CONNECT_V4)
        .sublayer(sublayerGuid)
        .weight(wfp::FilterBuilder::WeightClass::Max)
        .block();

    wfp::ObjectInstaller::AddFilter(*engine, filter, conditions);

    //
    // <More code here>
    //

    return 0;
}

License

Copyright (C) 2022 Mullvad VPN AB

Permission to use the code, documentation and contents is granted under the conditions of the MIT license.

For the full license agreement, see the LICENSE.md file.

libwfp's People

Contributors

mvd-ows avatar dlon avatar pinkisemils avatar faern avatar

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.