Skip to content

Instantly share code, notes, and snippets.

View brunerd's full-sized avatar

Joel Bruner brunerd

View GitHub Profile
@brunerd
brunerd / BTSharingStates
Last active November 7, 2020 04:35
Report the states of Bluetooth Sharing services in macOS using jpt to parse JSON output from system_profiler
#!/bin/bash
#Joel Bruner
#BTSharingStateas - report bluetooth sharing states from system_profiler using jpt to parse output
#if jpt is not installed locally, embed function from jpt.min into this script: https://github.com/brunerd/jpt
#get all the data once
SPBluetooth=$(system_profiler -json SPBluetoothDataType 2>/dev/null)
#get the paths related to service state
statePaths=$(jpt -jd '$..service_state' <<< "${SPBluetooth}")
@brunerd
brunerd / EAGrabber.sh
Last active January 29, 2022 16:20
Grab Jamf Extension Attributes (including recovery key) as they come down during recon
#!/bin/bash
# Joel Bruner - EA Grabber: Surreptitiously grabs Jamf Extension Attributes (EAs) during recon
#touch file for debug
[ -f /tmp/debug ] && set -x
#############
# VARIABLES #
#############
#!/bin/bash
#fixJSON-TrailersComments - fix JSON with trailing commas and comments (JS, Shell and * style)
: <<-LICENSE_BLOCK
Copyright (c) 2020 Joel Bruner (https://github.com/brunerd)
Licensed under the 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 permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HO
# hash comments from: shell, Perl, PHP, Python, R, Ruby, MySQL
// Line comments from: Javascript, Java, Swift, C(99)
/* single line block comment: C, Java, Javascript, Swift */
/*
multi-line block comment
can be either whole line or in-line
from: C, Java, Javascript, Swift
@brunerd
brunerd / jsonParsingReportCSV-macOS
Last active December 17, 2020 22:48
this will crawl mostly system areas of macOS and attempt to parse any JSON found, it will produce a CSV as well as echo the result to the console
#!/bin/bash
#jsonReport-macOS (c) Joel Bruner 2020, MIT License
#this will crawl mostly system areas of macOS and attempt to parse JSON found
#it will produce a CSV as well as echo out to the console the result
#############
# VARIABLES #
#############
#malformed JSON (according to json_pp) by macOS version
#jpt (https://github.com/brunerd/jpt) can parse all of these now
## NOTES on the Files ##
# USD generated JSON contains # comments
# /private/var/db/ionodecache.json - has a single *** COMMENT *** line at the top
# /System/Library/PrivateFrameworks/CoreAnalytics.framework/Versions/A/Resources/defaultConfig.json i - is "JSON Lines" aka "concatenated JSON"
# Most of the others have trailing commas after the final member of arrays and objects
## SPECIAL Note ##
@brunerd
brunerd / Malformed-macOS-10.15.csv
Last active December 16, 2020 23:20
macOS JSON files that fail to parse with json_pp (but jpt can parse them)
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 4 columns, instead of 3. in line 5.
Status,Issue Notes,Path,Error Output
ERROR,"""JSON Lines""/Concatenated",/System/Library/PrivateFrameworks/CoreAnalytics.framework/Versions/A/Resources/defaultConfig.json,"garbage after JSON object, at character offset 143 (before """"addTransform"":{""uui..."") at /usr/bin/json_pp5.18 line 45."
ERROR,Trailing Comma,/Library/Developer/CommandLineTools/usr/lib/swift/migrator/overlay4.json,"malformed JSON string, neither array, object, number, string or atom, at character offset 41290 (before ""]\n"") at /usr/bin/json_pp5.18 line 45."
ERROR,Trailing Comma,/Library/Developer/CommandLineTools/usr/lib/swift/migrator/overlay42.json,"malformed JSON string, neither array, object, number, string or atom, at character offset 608 (before ""]\n"") at /usr/bin/json_pp5.18 line 45."
ERROR,*** Comment ***,/private/var/db/ionodecache.json,"malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before ""*** Device Tree ***\n..."") at /usr/bin/json_pp5.18 line 45."
ERROR,Trailing Commas,/S
@brunerd
brunerd / Malformed-macOS-11.1.csv
Created December 16, 2020 23:21
macOS JSON files that fail to parse with json_pp (but jpt can parse them)
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 5.
Status,Issue Notes,Path,Error Output
ERROR,"""JSON Lines""/Concatenated",/System/Library/PrivateFrameworks/CoreAnalytics.framework/Versions/A/Resources/defaultConfig.json,"garbage after JSON object, at character offset 143 (before """"addTransform"":{""uui..."") at /usr/bin/json_pp5.28 line 44."
ERROR,*** Comment ***,/private/var/db/ionodecache.json,"malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before ""*** Device Tree ***\n..."") at /usr/bin/json_pp5.28 line 44."
ERROR,# comment,/System/Library/CoreServices/Pass Viewer.app/Contents/Library/SharedWebCredentials/wallet.apple.com.json,"malformed JSON string, neither array, object, number, string or atom, at character offset 210 (before ""]\n }]\n }..."") at /usr/bin/json_pp5.28 line 44."
ERROR,# comment,/System/Library/Frameworks/GameController.framework/Versions/A/Resources/XboxHapticCapabilityGraph.json,"unexpected end of string while parsing JSON string, at character offset 500 (before "",\n {\
@brunerd
brunerd / csv2csv.function.min.sh
Last active December 18, 2020 21:53
Minified, functionalized version of Lorance Stinson's csv2csv shell utility
#!/bin/sh
# csv2csv.function.min
# csv2csv by Lorance Stinson, 2007
# This file is in the public domain.
# For more information email LoranceStinson+csv@gmail.com.
# Or see http://lorance.freeshell.org/csvutils/
# Additions by Joel Bruner, 2020 (https://github.com/brunerd)
#csv2csv function minified
function csv2csv { IFS=$' \t\n'; local NL=$'\n'; local TAB=$'\t';local CSV_ESCAPE=${CSV_ESCAPE:='"'}; local CSV_SEPARATOR=${CSV_SEPARATOR:=","}; local CSV_QUOTE=${CSV_QUOTE:='"'}; local OCSV_ESCAPE=${CSV_ESCAPE:='"'}; local OCSV_SEPARATOR=${CSV_SEPARATOR:=","}; local OCSV_QUOTE=${CSV_QUOTE:='"'}; local FILE="-"; local NL_TEXT=""; local NUM_COLS=""; local OUTPUT=""; local QUOTE_LEVEL="0"; local SKIP_ROWS="0"; local TAB_TEXT=""; while [ "$#" -gt 0 ] ; do case "$1" in -c) [ "$2" ] && local COL_LIST="$2" || usage="$1 requires an argument."; shift 2;; -e) [ "$2" ] && CSV_ESCAPE="$2" || usage="$1 requires an argument."; shift 2;; -E) [ "$2" ] && OCSV_ESCAPE="$2" || usage="$1 requires an argument."; shift 2;; -h) usage=
@brunerd
brunerd / csv2csv.function.min.no_help.sh
Last active December 18, 2020 21:53
Minified, functionalized version of Lorance Stinson's csv2csv shell utility minus the help, truly a one-liner
#!/bin/sh
# csv2csv.function.min.no_help
# csv2csv by Lorance Stinson, 2007
# This file is in the public domain.
# For more information email LoranceStinson+csv@gmail.com.
# Or see http://lorance.freeshell.org/csvutils/
# Additions by Joel Bruner, 2020 (https://github.com/brunerd)
#csv2csv function minified
function csv2csv { IFS=$' \t\n'; local NL=$'\n'; local TAB=$'\t';local CSV_ESCAPE=${CSV_ESCAPE:='"'}; local CSV_SEPARATOR=${CSV_SEPARATOR:=","}; local CSV_QUOTE=${CSV_QUOTE:='"'}; local OCSV_ESCAPE=${CSV_ESCAPE:='"'}; local OCSV_SEPARATOR=${CSV_SEPARATOR:=","}; local OCSV_QUOTE=${CSV_QUOTE:='"'}; local FILE="-"; local NL_TEXT=""; local NUM_COLS=""; local OUTPUT=""; local QUOTE_LEVEL="0"; local SKIP_ROWS="0"; local TAB_TEXT=""; while [ "$#" -gt 0 ] ; do case "$1" in -c) [ "$2" ] && local COL_LIST="$2" || usage="$1 requires an argument."; shift 2;; -e) [ "$2" ] && CSV_ESCAPE="$2" || usage="$1 requires an argument."; shift 2;; -E) [ "$2" ] && OCSV_ESCAPE="$2" || usage="$1 requires an argument."; shift 2;; -h