Skip to content

Instantly share code, notes, and snippets.

View tylerapplebaum's full-sized avatar
☁️
AWS + Networking

Tyler Applebaum tylerapplebaum

☁️
AWS + Networking
View GitHub Profile
@tylerapplebaum
tylerapplebaum / Get-Traceroute.ps1
Last active April 21, 2024 09:08
MTR for Powershell
<#
.SYNOPSIS
An MTR clone for PowerShell.
Written by Tyler Applebaum.
Version 2.1
.LINK
https://gist.github.com/tylerapplebaum/dc527a3bd875f11871e2
http://www.team-cymru.org/IP-ASN-mapping.html#dns
<#
.SYNOPSIS
Backup-CiscoConfig.ps1 SSHs to a Cisco device and backs up the running configuration to a TFTP server.. Utilizes the Posh-SSH module.
.DESCRIPTION
This script is not possible without darkoperator's Posh-SSH module. Thanks!
To do: Parameterize the device list. 10/05/16
Grab the output of long commands by setting the terminal length to 0 to disable pagination. "term len 0"
Log commands entered on the Cisco device to ensure they're running:
@tylerapplebaum
tylerapplebaum / Add-TestUsers.ps1
Last active April 5, 2024 11:11
Create test users in Active Directory with realistic data from https://randomuser.me
<#
.SYNOPSIS
Create realistic-looking Active Directory accounts.
Written by Tyler Applebaum.
Version 0.2
Last Updated Jun 17 2020
.LINK
https://gist.github.com/tylerapplebaum/d692d9d2e1335b8b111927c8292c5dac
https://randomuser.me/
@tylerapplebaum
tylerapplebaum / UnFUBAR-Service.ps1
Last active June 4, 2018 16:47
Kill Windows services in the Stop Pending state; Logs to Event Viewer
#Checks the status of $ServiceName and kills it if in the 'Stop Pending' state.
#Creates an event log; logs results to it
#Get-Random (Get-Service | Select-Object -ExpandProperty Name) | Kill-HungService -Verbose
Function script:Kill-HungService {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$True,Mandatory=$True,HelpMessage="Service to search for")]
[string]$script:ServiceName
)
@tylerapplebaum
tylerapplebaum / Invoke-Credentials.ps1
Last active March 26, 2018 09:19
A function to encrypt a credential object with a static key to allow for easy retrieval. It's recommended to lock down the credential folder with appropriate NTFS permissions, as the password file can be read back using the key stored in the script.
Function script:Invoke-Credentials {
[CmdletBinding()]
param(
[Parameter(HelpMessage="Specify the username for the stored credential")]
[ValidateNotNullOrEmpty()]
[string]$Script_Username = "svc.username", #Username goes here
[Parameter(HelpMessage="Specify the path to store the credential")]
[ValidateNotNullOrEmpty()]
[string]$Script_CredFolder = "C:\Automate\",
@tylerapplebaum
tylerapplebaum / Convert-ToBase64
Last active January 3, 2018 18:11
A function to convert a string to base64 encoding
Function Convert-ToBase64 {
param(
[CmdletBinding()]
[Parameter(ValueFromPipeline=$True,Mandatory=$True,HelpMessage="String to encode to base64")]
[ValidateNotNullOrEmpty()]
$String
)
$StringToByteArr = [System.Text.Encoding]::UTF8.GetBytes($String) #Converts string to byte array
$Base64String = [System.Convert]::ToBase64String($StringToByteArr) #Converts byte array to b64 string
@tylerapplebaum
tylerapplebaum / Get-StringHash
Last active January 3, 2018 18:11
A function to get the secure hash of a string
Function Get-StringHash {
param(
[CmdletBinding()]
[Parameter(ValueFromPipeline=$True,Mandatory=$True,HelpMessage="String to hash")]
$String,
[Parameter(HelpMessage="Hash algorithm")]
[ValidateSet('MD5','RIPEMD160','SHA1','SHA256','SHA384','SHA512')]
$Algorithm = "SHA1"
)
$StringBuilder = New-Object System.Text.StringBuilder
@tylerapplebaum
tylerapplebaum / UACBypass.inf
Last active March 27, 2024 19:42 — forked from api0cradle/CorpVPN.cmp
CMSTP.exe scripts and files
; No longer needed - embedded in script now
[version]
Signature=$chicago$
AdvancedINF=2.5
[DefaultInstall]
CustomDestination=CustInstDestSectionAllUsers
RunPreSetupCommands=RunPreSetupCommandsSection
[RunPreSetupCommandsSection]
@tylerapplebaum
tylerapplebaum / Get-UserGroups.ps1
Last active January 3, 2018 18:10
Enumerate user groups
Function Get-UserGroups {
<#
.EXAMPLE
PS C:\> Get-UserGroups -GroupName "Domain Admins"
.EXAMPLE
PS C:\> [bool](Get-UserGroups -GroupName "Domain")
.EXAMPLE
PS C:\> Get-UserGroups -UserName elliot.alderson@e-corp-usa.com
@tylerapplebaum
tylerapplebaum / Resolve-EstablishedConnections.ps1
Last active March 18, 2019 20:56
Just like "netstat -f | findstr ESTABLISHED" but in PowerShell
Function Resolve-EstablishedConnections {
$EstConnections = Get-NetTCPConnection -State Established
$ConnectionArr = New-Object System.Collections.ArrayList #Initialize the ArrayList
$Counter = 1
ForEach ($Connection in $EstConnections) {
Write-Progress -Activity "Resolving PTR Record" -Status "Looking up $($Connection.RemoteAddress)" -PercentComplete ($Counter / $($EstConnections.Length)*100)
$ConnectionObj = [PSCustomObject][Ordered] @{
LocalAddress = $Connection.LocalAddress