Skip to content

Instantly share code, notes, and snippets.

View lawndoc's full-sized avatar
🤓
Learning

C.J. May lawndoc

🤓
Learning
View GitHub Profile
@lawndoc
lawndoc / OS-Version-Sort-All.ps1
Last active July 1, 2021 03:29
Query AD for Windows Versions and Export to CSV
### Global Variables (edit these)
$DOMAIN = "DC=example,DC=com"
$CSVPATH = ".\\"
### Begin Script
$windowsXP = [System.Collections.ArrayList]@()
$windows7 = [System.Collections.ArrayList]@()
$windows10 = [System.Collections.ArrayList]@()
$server03 = [System.Collections.ArrayList]@()
$server08 = [System.Collections.ArrayList]@()
@lawndoc
lawndoc / HiveNightmareFix.ps1
Created July 21, 2021 18:28
HiveNightmare ACL Fix (and Shadow Copies)
#change permissions and delete shadows
$checkPermissions = icacls c:\Windows\System32\config\sam
if ($checkPermissions -like '*BUILTIN\Users:(I)(RX*)*') {
icacls c:\windows\system32\config\*.* /inheritance:e
vssadmin delete shadows /quiet /all
$vulnerable = $true
}
else {
$vulnerable = $false
}
@lawndoc
lawndoc / pa-silent-registration.kql
Created August 15, 2022 18:19
Detect silent registration of Power Automate to a remote MDM
DeviceProcessEvents
| where FileName =~ "PAD.MachineRegistration.Silent.exe"
@lawndoc
lawndoc / cloc-gh
Last active October 24, 2024 09:00
Count the total lines of code for a user or organization in GitHub (excludes forks)
#!/usr/bin/env bash
# Author: C.J. May @lawndoc
# Usage: cloc-gh <username>
# Prereqs: cloc gh
cloc_repo () {
gh repo clone "$1" temp-linecount-repo -- --depth 1 > /dev/null 2>&1 &&
cloc temp-linecount-repo | grep SUM | awk '{ print $5 }' >> line_count.txt &&
rm -rf temp-linecount-repo
@lawndoc
lawndoc / RareService.kusto
Last active May 16, 2023 19:24
Globally Rare Service Installation
// credit to mRr3b00t @UK_Daniel_Card for the idea and starting point
// Globally Rare Service Installation
// Matches service executables to their file info and looks at global prevalence
let PrevalenceThreshold = 1000; // adjust as needed
DeviceEvents
| where ActionType == "ServiceInstalled"
| where FileName != "" // Defender not capturing service executable sometimes -- needs investigation
//-- false positives
| where not (
(FileName startswith "svchost.exe -k " // lots of these
@lawndoc
lawndoc / DeviceUsers.kusto
Last active May 23, 2023 12:25
Custom tabular function to enrich user info for each device in the results
// Advanced Hunting custom function
// ------------------------------------
// DeviceUsers()
// This function enriches a table with the users who use each device including full name, email, job title, etc.
// Example usage:
// ...
// | invoke DeviceUsers()
// ------------------------------------
let DeviceUsers = (T:(DeviceName:string)) {
T
@lawndoc
lawndoc / WSL2_VPN_Workaround_Instructions.md
Last active November 22, 2023 17:31 — forked from machuu/WSL2_VPN_Workaround_Instructions.md
Workaround for WSL2 network broken on VPN

Overview

Internet connection and DNS routing are broken from WSL2 instances, when some VPNs are active. The workaround breaks down into two problems:

  1. Network connection to internet
  2. DNS in WSL2

This problem is tracked in multiple microsoft/WSL issues including, but not limited to:

@lawndoc
lawndoc / spam_creds.py
Last active February 18, 2024 20:00
Punish Phisher
#!/usr/bin/env python3
import argparse
import grequests
import random
import requests
import string
import sys
from urllib.request import urlopen
@lawndoc
lawndoc / New-DevDrive.ps1
Last active October 14, 2024 11:47
Scripted Dev Drive Setup
<#
.SYNOPSIS
Script to create a new Dev Drive
.DESCRIPTION
This script will create a new Dev Drive on a Windows system. By default, it will create a 100GB dynamically sized VHDX file located in C:\ProgramData\Custom Dev Drive\drive.vhdx that will be mounted to the V: letter drive. For more information about Dev Drives, please see https://learn.microsoft.com/en-us/windows/dev-drive/
.EXAMPLE
.\New-DevDrive.ps1
<#
.SYNOPSIS
Enable PowerShell Remoting on a remote host and connect to a PsSession
.DESCRIPTION
This script requires PsExec.exe in ./Tools local to where the script is run from. It will utilize PsExec to enable
Powershell Remoting, and then it will use PsSession to enter an interactive session. When the PsSession is closed, the
script will use PsExec again to disable Powershell Remoting.