Skip to content

Instantly share code, notes, and snippets.

@jborean93
jborean93 / Remove-LongPath.ps1
Last active August 8, 2019 23:23
Deletes files and folders that exceed max path
Add-Type -TypeDefinition @'
using Microsoft.Win32.SafeHandles;
using System;
using System.IO;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
namespace FileIO
{
public class NativeHelpers
@jborean93
jborean93 / parse_negotiate_token.py
Last active March 28, 2020 03:04
Parse a raw Negotiate authentication token and create an easy to understand dict of it's key/values
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# PYTHON_ARGCOMPLETE_OK
# Copyright: (c) 2018, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
"""
Script that can be used to parse a Negotiate token and output a human readable structure. You can pass in an actual
SPNEGO token or just a raw Kerberos or NTLM token, the script should be smart enough to detect the structure of the
@jborean93
jborean93 / ServiceRecovery.ps1
Last active February 28, 2024 03:27
Get and Set the Windows service recovery options
# Copyright: (c) 2018, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Add-Type -TypeDefinition @'
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
@jborean93
jborean93 / Get-ServiceCredential.ps1
Last active February 5, 2024 14:32
Get's the username and password for installed Windows services
# Copyright: (c) 2019, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Function Get-ServiceCredential {
<#
.SYNOPSIS
Retrieve the username and plaintext password for all services installed on the local computer.
.DESCRIPTION
Will retrieve the username and plaintext password for the service(s) specified. This must be run as an
@jborean93
jborean93 / get_microsoft_updates.py
Last active April 17, 2024 03:00
Cross platform way to search for and download updates listed in the Microsoft Update catalog
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright: (c) 2019, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
# Script to search for updates in the Microsoft Update Catalog. Works on both Python 2 and 3 but requires BeautifulSoup
# to be installed - https://www.crummy.com/software/BeautifulSoup/#Download
import contextlib
import datetime
@jborean93
jborean93 / SetupAPI.cs
Last active February 6, 2023 16:13
Manage Windows devices in .NET, can enumerate, start, stop, disable, enable, and remove devices
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Text;
using System.Text.RegularExpressions;
@jborean93
jborean93 / PSRunas.psm1
Last active December 23, 2019 05:22
Quick and dirty PowerShell module that implements Start-Process using CreateProcessWithToken
# Copyright: (c) 2019, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
$pinvokeParams = @{
IgnoreWarnings = $true
WarningAction = 'Ignore'
TypeDefinition = @'
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections;
@jborean93
jborean93 / Get-ServiceInfo.ps1
Last active October 24, 2021 21:37
Expands on the info returned by Get-Service
$servicePInvokeParams = @{
TypeDefinition = @'
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
using System.Security.AccessControl;
namespace ServiceManager
@jborean93
jborean93 / Get-ItemWithCredential.ps1
Created February 3, 2020 03:21
Basic example of how to access network paths with custom credentials
# Copyright: (c) 2020, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Add-Type -Namespace LogonUtil -Name NativeMethods -MemberDefinition @'
[DllImport("Kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(
IntPtr hObject);
[DllImport("Advapi32.dll", SetLastError = true)]
public static extern bool ImpersonateLoggedOnUser(
@jborean93
jborean93 / Get-BetterFileHash.ps1
Last active October 24, 2021 21:37
Like Get-FileHash but will honour the SeBackupPrivilege privilege if set
Function Get-BetterFileHash {
<#
.SYNOPSIS
Computes the hash value for a file by using a specified hash algorithm.
.DESCRIPTION
The Get-FileHash cmdlet computes the hash value for a file by using a specified hash algorithm. This cmdlet is
identical in functionality to the Get-FileHash but will work in some cases where the user does not have permissions
to access a file.