Git Product home page Git Product logo

psmdatp's Introduction

Microsoft Defender for Endpoint PowerShell Module

Minimum Supported PowerShell Version Cross Platform PowerShell Gallery Version PowerShell Gallery

PSMDATP Logo

Welcome to the Microsoft Defender for Endpoint PowerShell module!

This module is a collection of easy-to-use cmdlets and functions designed to make it easy to interface with the Microsoft Defender for Endpoint API.

Motivation

I created this PowerShell module for MDATP for the following reasons:

  1. Advance my PowerShell skills
  2. Provide an easy way to interact with MDE through PowerShell because I prefer automation over manual tasks

Prerequisites

  • Windows PowerShell 5.1 (Testing for PowerShell 7 is in progress)
  • have configured authorization for access by registering an application in AzureAD

App Permissions

Below is an example of the App Permissions that you must grant. I will provide more details soon about the individual cmdlets and the permissions required

App permissions

Getting Started

To get started with the module, open your PowerShell terminal and install the module from the PSGallery by running this simple command:

Install-Module PSMDATP -Scope CurrentUser

App Registration

Initial Configuration

When you have installed the module and registered the App in AzureAD, you will find a file TEMPLATE_PoshMTPconfig.json in the Module folder. Rename this file to PoshMTPConfig.json and enter your API settings. Then copy the file in the root of the Module folder.

Example:

"C:\Users\User1\Documents\WindowsPowerShell\Modules\PSMDATP"
───PSMDATP
│   │   PoshMTPconfig.json
│   │
│   └───0.0.2
│           PSMDATP.psd1
│           PSMDATP.psm1
│           TEMPLATE_PoshMTPconfig.json

At present the PSMDATP PowerShell module only requires the API_MDATP information

{
    "API_MDATP":  {
                      "AppName":  "WindowsDefenderATPPSMDATP",
                      "OAuthUri":  "https://login.windows.net/<YOUR TENANT ID>/oauth2/token",
                      "ClientID":  "CLIENT ID",
                      "ClientSecret":  "<CLIENT SECRET>"
                  },
    "API_MSGRAPH":  {
                        "AppName":  "xMSGraph",
                        "OAuthUri":  "https://login.windows.net/<YOUR TENANT ID>/oauth2/token",
                        "ClientID":  "<CLIENT ID>",
                        "ClientSecret":  "<CLIENT SECRET>"
                    }
}

Important

I am going to assume that you are familiar with MDATP as such and understand the consequences of triggering actions on devices. Where applicable the cmdlets support the use the -whatif parameter. Think before pressing the key!

Running your first commands

List included cmdlets

Let's first take a look at the cmdlets included in the PSMDATP Module

get-command -Module PSMDATP | Select Name

You will see something like this

Add-MDATPDeviceTag
Add-MDATPIndicator
Get-MDATPAlert
Get-MDATPCollectionPackageUri
Get-MDATPDevice
Get-MDATPDeviceAction
Get-MDATPDeviceTag
Get-MDATPIndicator
Get-MDATPInvestigation
Get-MDATPQuery
Get-MDATPTvmRecommendation
Get-MDATPTvmVulnerability
Get-MDATPEndpointStatus
Remove-MDATPDevice
Remove-MDATPDeviceTag
Remove-MDATPIndicator
Set-MDATPAlert
Start-MDATPAppRestriction
Start-MDATPAVScan
Start-MDATPInvestigation
Start-MDATPInvestigationPackageCollection
Start-MDATPIsolation
Stop-MDATPAppRestriction
Stop-MDATPIsolation

For more details about the cmdlets included in this module check out the cmdlets documentation page

Retrieve MDATP Alerts

Run the following command to retrieve alerts from the past 30 days

Get-MDATPAlert -Severity High

List MDATP Devices

Run the following command to list all MDATP registered devices

Get-MDATPDevice -All

Contributing

If you have an idea or want to contribute to this project please submit a suggestion

Authors

Alex Verboon Twitter

Contributors

Dan Lacher Twitter


Release Notes

Version Date Notes
0.0.1 15.04.2020 Initial Release
0.0.2 03.05.2020 Added Add-MDATPIndicator and Remove-MDATPIndictor cmdlets
1.0.0 18.07.2020 Added Get-MDATPTvmRecommendation and Get-MDATPTvmVulnerability
cmdlets, updated the API uri for the Get-MDATPAlerts cmdlet
1.1.0 22.12.2020 Added Set-MDATPAlert and Get-MDATPEndpointStatus
1.1.1 22.11.2022 Added generateAlert flag to Add-MDATPIndicator

TODO

I have the following on my to-do list:

  • A better solution to store the API configuration in a more secure place
  • Add cmdlets for TVM added in version 1.0.0
  • Add cmdlets to manage custom indicators added in version 0.0.2
  • Add more query templates for advanced hunting
  • Create more Module related Pester tests

Credits

I used Catesta for this project

psmdatp's People

Contributors

alexverboon avatar danlacher 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

psmdatp's Issues

Get-MDATPDevice " with "-DeviceName" parameter can't get json format response.

Describe the bug
When I used "Get-MDATPDevice " with "-DeviceName" parameter, but can't get the json format information. Only have the following information.

PS C:\> Get-MDATPDevice -DeviceName _hostname_
VERBOSE: GET https://api.securitycenter.windows.com/api/machines?$filter=ComputerDNSName eq '_hostname_' with 0-byte payload
VERBOSE: received 93-byte response of content type application/json; odata.metadata=minimal

Can't remove Server from Defender with remove-MDATPDevice

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Powershell
  2. type "remove-MDATPDevice -DeviceName "Server of Choice"
  3. See error

Expected behavior
Successfully remove "offboard" the server with a success message

Screenshots
remove Device Server

Error is : Request to failed with HTTP Status BadRequest Bad Request
Write-Error, WriteErrorException

See Screenshot.

Help with config encryption ?

Hi,

How about I help with encryption of the conf json file ?

Possible options are ConvertTo-SecureString for the entire file, but then only the user that encrypted it can read it

or

Some sort of obfuscation to avoid plain text passwords.

Momchil

Add-MDATPIndicator

I have written an update to Add-MDATPIndicator to take into account the new API for passing a $True or $False to the generate alert flag. I have started to use the false setting for Informational level alerts. Let me know how you would like the code changes.

Start-MDATPIsolation errors on DeviceName when using DeviceID

Describe the bug
Using the Start-MDATPIsolation command with a specified DeviceID errors out when tryign to get a device name. This occurs with or without the -whatif switch.

MetadataError: C:\Users\(install location)\Documents\WindowsPowerShell\Modules\PSMDATP\1.0.0\PSMDATP.psm1:3225
Line |
3225 |          $DeviceName = $DeviceName.ToLower()
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The variable cannot be validated because the value  is not a valid value for the DeviceName variable.

VERBOSE: GET https://api.securitycenter.windows.com/api/machines with 0-byte payload
VERBOSE: received 4711333-byte response of content type application/json
VERBOSE: Content encoding: utf-8
What if: Performing the operation "Start Isolation: Full" on target "".

To Reprodce
Run a command like the below(occurs when not using -whatif switch):
Start-MDATPIsolation -DeviceID $ID -IsolationType Full -WhatIf

Desktop (please complete the following information):

  • OS: Windows 10
  • PSVersion 7.1.1

Additional context
Using version 1.0.0

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.