Skip to content

Instantly share code, notes, and snippets.

View kim4apple's full-sized avatar

kim4apple kim4apple

  • Shenzhen, China
View GitHub Profile
@cjlawson02
cjlawson02 / Remove-WiFi.command
Created September 23, 2021 16:38
macOS Cal Poly Eduroam removal
#!/bin/bash
# Script created by Vince Hunter
# Script updated by Chris Lawson 9/23/21
### This allows the administrator password to be called, and used in the script where sudo is required
### Beware: the inputted password is used in echo commands
### Usage: Use `sudo` without a path to ensure the `sudo` function is called rather than the actual command
# Dialog Title
@marcan
marcan / m1cat.c
Last active October 26, 2023 15:42
m1cat: a PoC for the M1RACLES covert channel vulnerability in the Apple M1
/*
* m1cat: a proof of concept for the M1RACLES vulnerability in the Apple M1.
*
* This program implements a covert channel that can be used to transmit data
* between two processes when run on the Apple Silicon "M1" CPUs.
*
* The channel is slightly lossy due to (presumably) the scheduler sometimes
* scheduling us on the wrong CPU cluster, so this PoC sends every byte twice
* together with some metadata/framing bits, which is usually good enough.
* A better approach would be to use proper FEC or something like that.
@dhoerl
dhoerl / gist:57fe946f95b647184c38b5c3942fc32c
Last active September 7, 2021 20:04
Combine Sample Publisher for Medium Article
enum SPErrors: Error {
case inputStringWasEmpty
}
struct StringPublisher: Publisher {
typealias Output = [Character]
typealias Failure = Error
private let data: [Character]
@bwmorales
bwmorales / setpreferredwirelessnetwork.sh
Last active November 29, 2021 17:17
for macOS, set your preferred wireless network
#!/bin/bash
preferredNetwork="$1"
securityType="$2"
# For securityType,
# use OPEN for none,
# WPA for WPA Personal,
# WPA2 for WPA2 Personal,
# WPA/WPA2 for WPA/WPA2 Personal,
# WPAE for WPA Enterprise,
@Omar-Ikram
Omar-Ikram / EndpointSecurityDemo.m
Last active April 4, 2025 15:29
A demo of using Apple's EndpointSecurity framework - tested on macOS Monterey 12.2.1 (21D62)
//
// main.m
// EndpointSecurityDemo
//
// Created by Omar Ikram on 17/06/2019 - macOS Catalina 10.15 Beta 1 (19A471t)
// Updated by Omar Ikram on 15/08/2019 - macOS Catalina 10.15 Beta 5 (19A526h)
// Updated by Omar Ikram on 01/12/2019 - macOS Catalina 10.15 (19A583)
// Updated by Omar Ikram on 31/01/2021 - macOS Big Sur 11.1 (20C69)
// Updated by Omar Ikram on 07/05/2021 - macOS Big Sur 11.3.1 (20E241)
// Updated by Omar Ikram on 04/07/2021 - macOS Monterey 12 Beta 2 (21A5268h)
@dhoerl
dhoerl / Asymmetric.swift
Last active September 7, 2021 19:56
Implement asymmetric cryptography for distributed app where keys can both be stored as strings
//
// Asymmetric.swift
//
// Created by David Hoerl on 12/23/18.
// Copyright © 2018 David Hoerl. All rights reserved.
//
/*
This is the portion you need in the distributed app, which uses the public key that can appear in plain text
*/
@KyNorthstar
KyNorthstar / Elevate Permissions.swift
Created August 8, 2018 21:51
Elevates permissions in non-sandboxed Swift apps
import Foundation
private func gainPermissions() {
var authorizationRef: AuthorizationRef? = nil
var authItem = AuthorizationItem(name: kSMRightBlessPrivilegedHelper, valueLength: 0, value: nil, flags: 0)
var authRights = AuthorizationRights(count: 1, items: &authItem)
let flags: AuthorizationFlags = [.interactionAllowed, .preAuthorize, .extendRights]
var environment = AuthorizationEnvironment()
@Freccia
Freccia / osx-pw-policies.sh
Created June 29, 2017 13:34
Sets Os X Password Policies
#!/bin/sh
###################################################################################
## Create a pwpolicy XML file based upon variables and options included below.
## Policy is applied and then file gets deleted.
## Use "sudo pwpolicy -u <user> -getaccountpolicies"
## to see it, and "sudo pwpolicy -u <user> -clearaccountpolicies" to clear it.
##
## Tested on: OS X 10.10 10.11 10.12
####################################################################################
@pvieito
pvieito / amfid_patch.py
Created December 27, 2016 00:14
This script can patch macOS 10.12.2 amfid daemon on memory to allow arbitrary entitlements in Developer ID signed binaries.
#!/usr/bin/env python3
'''amfid_patch.py - Pedro José Pereira Vieito © 2016
This script can patch macOS 10.12.2 amfid daemon on memory
to allow arbitrary entitlements in Developer ID signed binaries.
Killing amfid will make the patch disapear:
$ sudo kill -9 `pgrep amfid`
You must run the script as a root (sudo) and with SIP disabled.
@MatiMax
MatiMax / DNSResolve3.swift
Last active October 9, 2021 09:44
This Playground shows how to use Core Foundation's CFHost in *Swift 3* to try to produce an array of Strings containing the host name and all its aliases for a given IP address. Unfortunately, CFHostGetNames() does not supply the aliases of a host, so we're left alone with the gethostbyaddr() C function.
//: # How to retrieve a host name and associated aliases from an IP address using Core Fondation's `CFHost` in Swift 3
import Foundation
import PlaygroundSupport
//: In order to get the callback working we use a simple class to implement the showcase.
class DNSResolve {
//: The IP address may be a Swift `String` thanks to the toll-free bridging to C strings.
let ip: String = "17.172.224.47"
//: We use an optional `CFHost` variable because CFHost neither comes with an initializer nor is conforming to the Nullable protocol.
var host: CFHost?
//: We use this array of `String`s to store the resolved host names.