Skip to content

Instantly share code, notes, and snippets.

View jpda's full-sized avatar
🤔
ok

John Patrick Dandison jpda

🤔
ok
View GitHub Profile
@jpda
jpda / Thing.cs
Created January 24, 2019 15:29
Azure OCR sample
class Program
{
static void Main(string[] args)
{
// once you create a computer vision service in Azure, you'll get the region and service key
// CV OCR docs are here: https://eastus2.dev.cognitive.microsoft.com/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fc
var recognizer = new Recognizer("<REGION OF YOUR CV SERVICE>", "<CV SERVICE KEY>");
// here's an example if the image to OCR is on the internet somewhere already
recognizer.RecognizeFromImageUrl("<URL TO IMAGE, IF AVAILABLE ON INTERNET>", "ar").Wait();
@jpda
jpda / init-manual-service-principal.py
Last active June 16, 2019 23:08
Key Vault with azure functions python
import logging
import azure.functions as func
from azure.keyvault import KeyVaultClient, KeyVaultAuthentication
from azure.common.credentials import ServicePrincipalCredentials
# see https://docs.microsoft.com/en-us/python/api/overview/azure/key-vault?view=azure-python
def auth_callback(server, resource, scope):
credentials = ServicePrincipalCredentials(
client_id = '<CLIENT ID>',
@jpda
jpda / graph-nolib.py
Created January 25, 2019 20:24
Microsoft Graph from Python only using requests
import logging
import requests
import json
def main():
client_id = "<CLIENT ID>"
client_secret = "<CLIENT SECRET>"
resource_id = "https://graph.microsoft.com"
tenant = "<TENANT NAME OR GUID> (like microsoft.com or jpd.ms)"
graph_query = "<GRAPH PATH> - example: users/john@jpd.ms"
@jpda
jpda / cassl.cs
Created February 6, 2019 22:37
ca-verify
using System;
using System.Linq;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
namespace HttpPrivateCa
{
@jpda
jpda / Program.cs
Last active March 4, 2019 19:43
Decoding Azure Search document keys in .net core without asp.net
public async Task Go()
{
var response = await _client.GetStringAsync("https://<SEARCH_SERVICE>.search.windows.net/indexes/<INDEX>/docs?api-version=2017-11-11&search=*&%24top=100&%24select=metadata_storage_path");
dynamic data = JsonConvert.DeserializeObject(response);
foreach (dynamic a in data["value"])
{
string originalPath = a.metadata_storage_path.ToString();
// remove extra char
string path = originalPath.Substring(0, originalPath.Length - 1);
// fix padding - remove extra characters that the .netfx UrlTokenEncode adds
@jpda
jpda / swap-windows-colors.ps1
Created May 29, 2019 15:12
swaps windows system and apps from dark/light mode
$currentApps = (Get-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme).AppsUseLightTheme
$currentSystem = (Get-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme).SystemUsesLightTheme
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value (1 - $currentApps)
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -Value (1 - $currentSystem)
using System;
using System.Data;
using System.Linq;
using Newtonsoft.Json.Linq;
namespace ConsoleApplication8
{
public struct VmSize
{
public string Name;
@jpda
jpda / do-a-really-bad-thing.ps1
Last active June 21, 2019 20:09
don't ever actually do this. ROPC for enabling security graph to a siem programmatically
# change me
$AppId = "" # client id, with user_impersonation rights on azure svc management
$secret = "" # app secret
$Resource = "https://management.core.windows.net/"
$TenantId = "" # tenant guid
$user = "" # some global admin account, without any extra goop - e.g., no MFA, no conditional access, etc, or you'll have to use app passwords or something similar
# or, if you use a federated account, you can use the active endpoint on your STS to authenticate, which you then use to authenticate to AAD, which you can then use for oauth
$password = "lol no" # as icky as this is, at least make this SecureString
$tokenUrl = "https://login.microsoftonline.com/$TenantId/oauth2/token"
@jpda
jpda / 000-default.conf
Last active October 30, 2019 12:50
apache-jwt-to-header
# start with a redirect to 443
<VirtualHost *:80>
Redirect / https://myapp.example.com
</VirtualHost>
<VirtualHost *:443>
ServerName myapp.example.com # the DNS name users will use to connect to your app
SSLEngine on
SSLCertificateFile /etc/ssl/certs/myapp-example-com.pem # your cert path
SSLCertificateKeyFile /etc/ssl/certs/myapp-example-com-key.pem # your cert's key path
LimitRequestFieldSize 65536 # certain headers can grow larger than the default, 64K is a reasonable size
@jpda
jpda / silent-msal.hbs
Last active December 13, 2019 21:34
silent teams tab auth with graph scopes & adal
<!--
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to