Giter Club home page Giter Club logo

create-ipsec-policies's Introduction

IpSec-Extraction

Introduction - You Document Nothing, Jon Snow

This is (currently) an ongoing project where I try to extract netsh ipsec commands from their relative DLLs and create a wrapper to use them. Currently, there is no documented way to create IPSec filters via .Net or C++ without calling on the Windows Shell or using the WFP. As this is a progressive project, I have decided to do a write-up as I go, so when I come back to it I'm not lost in progress.

What's The Point?

The point is that ipsec rules differ in how they are handled from the Windows Firewall. For example, when a Windows Firewall is created that blocks port 443, any open connection that uses 443 is immediately terminated. When a rule is created using an ipsec filter, the connection remains in place but is blocked, and will continue to try and reconnect until it times out.

Identifying The DLLs

To identify the DLLs required for this job, we'll first need to work out what functions netsh ipsec is calling when it executes it's various commands. To do this, we're going to use an API Monitor.

By spinning up a netsh prompt and attaching API Monitor we're able to see what functions and DLLs are called to:

Straight away, we can see that calls to NSHIPSEC.DLL and POLSTORE.DLL are made. Furthermore, we can also see that there are enumerations of registry keys, so it's likely that the policy information is actually stored in the registry.

For context normally creating, and assigning, a simple ipsec policy via the command line goes like this:

  1. netsh ipsec static add policy ExamplePolicy
  2. netsh ipsec static add filterlist ExampleFilterList
  3. netsh ipsec static add filter filterlist=ExampleFilterList srcaddr=any dstaddr=any protocol=tcp dstport=8080
  4. netsh ipsec static add filteraction ExampleFilterAction action=block
  5. netsh ipsec static add rule name=ExampleRule policy=ExamplePolicy filterlist=ExampleFilterList filteraction=ExampleFilterAction
  6. netsh ipsec static set policy ExamplePolicy assign=y

With this in mind, we can execute each function and have a gander at APIMonitor further:

Straight away we can see that attributes for the policy are created, and that there is more registry activity. By searching the registry for these attributes, we can indeed confirm that the details of the policy are written:

While this isn't overly important, it's handy to know.

Anyway, as M&M said once, snap back to reality and lets have a look in these DLLs.

Nshipsec

DeletePolicy

__int64 __fastcall DeletePolicy(struct _IPSEC_POLICY_DATA *a1, void *a2)

Param 1

Param 1 takes a IPSEC_POLICY_DATA struct, which doesn't seem to be documented anywhere. During runtime, upon calling the function with at least one valid policy in place, we can observe that the struct is a representation of the registry information for the policy. As it's running as x64, the first parameter, being an integer, is passed to RCX:

Leakages

At this point, I realised that the Windows XP Source Code had recently leaked online and the struct definitions would be present there.

create-ipsec-policies's People

Contributors

evulpes 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.