Skip to content

Instantly share code, notes, and snippets.

View joshfinley's full-sized avatar
💭
yeet

Josh Finley joshfinley

💭
yeet
View GitHub Profile
# Import the required module if not already imported
Import-Module AzureAD
# Login to Azure AD
Connect-AzureAD
# Get the 'Application Admin' role
$appAdminRole = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq 'Application Admin'}
# If the role hasn't been instantiated, instantiate it
# Install the AzureAD PowerShell module
Install-Module AzureAD# Authenticate to the tenant
$username = "[email protected]"
$password = 'YourVeryStrongPassword'
$SecurePassword = ConvertTo-SecureString “$password” -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential($username, $SecurePassword)
Connect-AzureAD -Credential $Credential# Build our users and roles object
$UserRoles = Get-AzureADDirectoryRole | ForEach-Object {
$Role = $_
# Authenticate to Azure AD as an Application Administrator user
$username = "alice" # Username for authentication
$password = "asdf" # Password for authentication
# Convert password to a secure string
$securePass = ConvertTo-SecureString "$password" -AsPlainText -Force
# Create a credential object
$cred = New-Object System.Management.Automation.PSCredential($username, $securePass)
# Connect to Azure AD with the provided credentials
Connect-AzureAd -Credential $cred
import paramiko
import socket
def http_connect_proxy(proxy_host, proxy_port, target_host, target_port):
"""
Establish a socket connection through an HTTP proxy.
"""
proxy = (proxy_host, proxy_port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(proxy)
import socket
import threading
import socks # PySocks
def handle_client(client_socket):
# Establish a tunnel through the corporate proxy using CONNECT
remote_socket = socks.socksocket()
remote_socket.set_proxy(socks.PROXY_TYPE_HTTP, "corporate_proxy_ip", corporate_proxy_port)
try:
@joshfinley
joshfinley / proxy.py
Last active September 28, 2023 19:12
Version 3 is current working version
import socket
import threading
import re
def establish_tunnel(remote_socket, target_host, target_port):
connect_req = f"CONNECT {target_host}:{target_port} HTTP/1.1\r\n\r\n".encode()
remote_socket.send(connect_req)
# Read the response. In a production setting, you'd want to actually parse the response.
response = remote_socket.recv(4096)
print(f"Received response from corporate proxy: {response.decode()}")
# Import the Active Directory module if not already loaded
Import-Module ActiveDirectory
# Create a script block to process the piped input
filter CheckADUser {
# Assume $_ is the object passed from the pipeline, attempt to select the Name property
$name = $_.Name
# If Name property is found, check the AD
if ($null -ne $name) {
# Import the Active Directory module if not already loaded
Import-Module ActiveDirectory
# Get the path to the text file from the script arguments
param (
[string]$groupFile
)
# If no path is provided, exit the script
if ([string]::IsNullOrWhiteSpace($groupFile)) {
# Function to flatten the object for CSV output
Function Flatten-AzureArchitecture {
param (
[Parameter(Mandatory=$true)]
$AzureArchitecture
)
$flattenedData = @()
foreach ($sub in $AzureArchitecture) {
# Initialize an empty array to hold firewall information
$allFirewalls = @()
# Get all subscriptions in the tenant
$subscriptions = Get-AzSubscription
# Loop through each subscription to gather Azure Firewall information
foreach ($subscription in $subscriptions) {
# Select the subscription for the Azure context
Set-AzContext -Subscription $subscription.Id