Skip to content

Instantly share code, notes, and snippets.

@ejholmes
ejholmes / git.md
Created August 31, 2018 01:27 — forked from briceburg/git.md
git - checking fast-forward-ness
git merge-base --is-ancestor master HEAD

from man git merge-base

A common idiom to check "fast-forward-ness" between two commits A and B is (or at least used to be) to compute the merge base between A and B, and check if it is the same as A, in which case, A is an ancestor of B. You will see this idiom used

@ejholmes
ejholmes / main.go
Created May 26, 2018 01:50
Satisfying interfaces in Go using struct members and packages
package main
import "time"
type Time interface {
Now() time.Time
}
type fakeTime struct {
Now func() time.Time
@ejholmes
ejholmes / walkthrough.md
Last active September 3, 2021 22:48
Vulnerable Docker: 1 (Walkthrough)

Start with a portscan

$ nmap -v -A -T5 $ip

Starting Nmap 7.60 ( https://nmap.org ) at 2017-10-06 06:31 EDT
NSE: Loaded 146 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 06:31
Completed NSE at 06:31, 0.00s elapsed
@ejholmes
ejholmes / main.go
Created September 28, 2017 00:12
Credentials in Go error messages
package main
import (
"log"
"net/http"
)
func main() {
_, err := http.Get("http://notso:secret@wdjkwakdjwalkdjk.awdwad.fooo")
if err != nil {
@ejholmes
ejholmes / parse.sh
Last active August 20, 2017 14:16
Generate dogstatsd metrics from iStats
#!/bin/bash
#
# while true; do istats --no-graphs; sleep 10; done | ./parse.sh > /dev/udp/127.0.0.1/8125
fan_speed="Fan ([[:digit:]]+) speed: (.*) RPM"
cpu_temp="CPU temp: (.*)°C"
battery_temp="Battery temp: (.*)°C"
current_charge="Current charge: (.*) mAh (.*)%"
max_charge="Maximum charge: (.*) mAh (.*)%"
@ejholmes
ejholmes / build.py
Created July 20, 2017 22:40
Run a stacker build with python
from stacker.context import Context
from stacker.actions import build
from stacker.providers.aws.default import Provider
env = {"namespace": "namespace-here"}
config = {
"stacks": []}
context = Context(environmnet=env, config=config)
action = build.Action(context, provider=Provider("us-east-1"))
@ejholmes
ejholmes / main.go
Created June 24, 2017 03:43
Get a SessionToken with MFA, then assume role with those credentials.
package main
import (
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
@ejholmes
ejholmes / cloudbleed.sh
Last active February 24, 2017 05:28
Check if a website is served through CloudFlare.
#!/bin/bash
domain=$1
if [[ -z "$(dig +short NS $domain | grep cloudflare)" ]]; then
printf "\033[0;32mOK\033[0m\n"
else
printf "\033[0;31mAFFECTED\033[0m\n"
exit 1
fi
@ejholmes
ejholmes / dnsmasq_parser.py
Created December 8, 2016 05:39
A DataDog log parser to extract metrics from DNSMASQ
import time
import re
from datetime import datetime
DATE_REGEX = re.compile(r"(.*?) dnsmasq\[.*?\]:.*$")
FORWARDED_REGEX = re.compile(r".*: forwarded (.*?) to (.*?)$")
QUERY_REGEX = re.compile(r".*: query\[(.*?)\] (.*?) from (.*?)$")
REPLY_REGEX = re.compile(r".*: reply (.*?) is (.*?)$")
CACHE_HITS_REGEX = re.compile(r".*: queries forwarded (\d+), queries answered locally (\d+)$")
QUERIES_REGEX = re.compile(r".*: server .*?: queries sent (\d+), retried or failed (\d+)$")
@ejholmes
ejholmes / debug.md
Created March 8, 2016 23:52
Steps to debug docker
  • Enable -D flag in /etc/default/docker
  • socat -d -d TCP-LISTEN:8080,fork,bind=$(hostname) UNIX:/var/run/docker.sock
  • docker run -it golang go tool pprof http://$(hostname):8080/debug/pprof/profile