Skip to content

Instantly share code, notes, and snippets.

@acidprime
acidprime / gist:1350393
Created November 9, 2011 04:33
BASH Hardware Test
#!/bin/bash
declare -x awk="/usr/bin/awk"
declare -x ioreg="/usr/sbin/ioreg"
declare -x sysctl="/usr/sbin/sysctl"
# Intel and future systems test
declare IOREG="$($ioreg -l |
$awk 'BEGIN {FS="[<>]"}
/.*\"system-type\".=./{
systype=$2
if ( systype == 1 )
@acidprime
acidprime / warranty.py
Created November 11, 2011 09:43
Simple warranty parser based on the work done by glarizza ./warranty.py >foo.plist ; open foo.plist
#!/usr/bin/python
import ast
import plistlib
import urllib2
import subprocess
system_profiler = "/usr/sbin/system_profiler"
# Generic system_profiler parser
def systemReport():
global spx
@acidprime
acidprime / pedit.py
Created November 23, 2011 23:35
Basic Little Script to Add Usernames & Passwords via command line arguments to a mobileconfig 802.1X profiles
#!/usr/bin/python -tt
__author__ = 'Zack Smith @acidprime'
__version__ = '0.1'
import sys
import getopt
import plistlib
global debugEnabled
global plist
global userName
@acidprime
acidprime / makehash.pl
Created December 8, 2011 02:42
Perl Shadow Hash Generator
#!/usr/bin/perl
use Digest::SHA1 qw(sha1_hex);;
$password = $ARGV[0];
sub genShadowHash($){
# get our salt integer, and it's hex value
$salt = rand(2**31-1);
$saltHex = sprintf("%X",$salt);
# get string representation of bytes
$saltStr = pack("N", $salt);
@acidprime
acidprime / readhash.py
Created December 8, 2011 04:21
PyObjC bridge code for reading shadow hashes
#!/usr/bin/python
import binascii
from Cocoa import NSDictionary,NSPropertyListSerialization
from Cocoa import NSPropertyListImmutable
user = 'acid'
path = '/var/db/dslocal/nodes/Default/users/%s.plist' % user
# Read the binary plist
plist = NSDictionary.dictionaryWithContentsOfFile_(path)
# Grab the ShadowHashData key
dataShadowHashData = plist['ShadowHashData'][0]
@acidprime
acidprime / split_dmg.sh
Created December 22, 2011 04:59
Deploy Studio Users Extract Example
#!/bin/bash
# Commands used by this script
declare -x asr="/usr/sbin/asr"
declare -x awk='/usr/bin/awk'
declare -x hdiutil='/usr/bin/hdiutil'
declare -x rm="/bin/rm"
declare -x mv="/bin/mv"
# Check any commands are included on the .nbi
for COMMAND in $asr $awk $hdutil $rm ; do
if [ ! -x "$COMMAND" ] ; then
@acidprime
acidprime / getcurrent.py
Created December 28, 2011 22:55
Some Python Airport code
#!/usr/bin/python -tt
import subprocess
airport = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport'
def getAirportInfo():
arguments = [airport,"--getinfo"]
execute = subprocess.Popen(arguments, stdout=subprocess.PIPE)
out, err = execute.communicate()
dict = {}
for line in out.split('\n'):
@acidprime
acidprime / windowsExport.sh
Created January 8, 2012 23:29
Open Directory to Active Directory LDIF export
#!/bin/bash
IFS=$'\n'
LDAP_SERVER="localhost"
ldapsearch -LLL -h "$LDAP_SERVER" -x -D uid=diradmin,cn=users,dc=example,dc=com -w password -b cn=users,dc=example,dc=com '(&(objectClass=posixAccount)(!(uid=root))(!(uid=diradmin))(!(uid=vpn_*)))' \
cn \
sn \
givenName \
uidNumber \
uid \
l \
@acidprime
acidprime / windowsGroupExport.sh
Created January 8, 2012 23:32
Open Directory to Active Directory Group LDIF Export
#!/bin/bash
LDAP_SERVER="ldap.example.com"
IFS=$'\n'
ldapsearch -LLL -h "$LDAP_SERVER" -x -D uid=diradmin,cn=users,dc=example,dc=com -w password -b cn=groups,dc=example,dc=com '(&(objectClass=posixGroup)(!(cn=Domain*))(!(cn=com.apple.*))(!(cn=admin))(!(cn=staff)))' description apple-group-realname memberUid |
sed 's/^apple-group-realname:/name:/g' |
sed 's/cn=groups,dc=example,dc=com/ou=ImportedUsers,dc=ad,dc=example,dc=com/g' |
while read line ; do
if [ "$line" != "${line/dn://}" ] ; then
declare MY_UID="$(echo "$line" | awk -F'[=,]' '/^dn:/{print $2}' )"
declare MY_CN="$(ldapsearch -LLL -h "$LDAP_SERVER" -x -D uid=diradmin,cn=users,dc=example,dc=com -w password -b cn=groups,dc=example,dc=com "(&(objectClass=posixGroup)(&(cn=$MY_UID)))" apple-group-realname |
@acidprime
acidprime / 10.4_backup.sh
Created January 9, 2012 00:18
Simple Backup Script I used for a backup pre 10.5+ upgrade
#!/bin/bash
declare -x nidump="/usr/bin/nidump"
declare -x dirname="/usr/bin/dirname"
declare -x system_profiler="/usr/sbin/system_profiler"
declare -x hdiutil="/usr/bin/hdiutil"
declare -x sharing="/usr/sbin/sharing"
declare -x serveradmin="/usr/sbin/serveradmin"
declare -x RUN_DIRECTORY="/tmp/$$backup$RANDOM"
# Find the Run Directory from the Script Path
mkdir "$RUN_DIRECTORY/Server Admin"