Skip to content

Instantly share code, notes, and snippets.

View sstelfox's full-sized avatar

Sam Stelfox sstelfox

View GitHub Profile
@sstelfox
sstelfox / test_ssh_key.sh
Last active January 3, 2016 14:29
A means to test whether or not the user has an SSH key installed for a remote system
#!/bin/bash
USER=$1
HOST=$2
function test_ssh_key_setup() {
ssh -q -q -o "BatchMode=yes" -o "ConnectTimeout 5" ${USER}@${HOST} "echo 2>1"
[ $? ] && return 0 || return 1
}
@sstelfox
sstelfox / general_request.sh
Created January 21, 2014 15:14
A quick bash common function that can be used to ask multiple choice questions and ensure an answer.
#!/bin/bash
function ask_multi_choice() {
local QUESTION=$1
while [ -z "$CHOICE" ]; do
echo
for S in ${!POSSIBLE_ANSWERS[*]}; do
echo " ${S}) ${POSSIBLE_ANSWERS[$S]}"
done
@sstelfox
sstelfox / test.rb
Created March 4, 2014 15:48
Ruby Bin Pattern
#!/usr/bin/env ruby
module SomeLibrary
def something
puts "Weee"
end
module_function :something
end
@sstelfox
sstelfox / vagrant-debug.log
Created March 14, 2014 22:50
Debug log from vagrant demonstrating the hardcoded exportfs path
INFO global: Vagrant version: 1.5.0
INFO global: Ruby version: 2.0.0
INFO global: RubyGems version: 2.0.14
INFO global: VAGRANT_EXECUTABLE="/opt/vagrant/bin/../embedded/gems/gems/vagrant-1.5.0/bin/vagrant"
INFO global: VAGRANT_INSTALLER_EMBEDDED_DIR="/opt/vagrant/bin/../embedded"
INFO global: VAGRANT_INSTALLER_VERSION="2"
INFO global: VAGRANT_DETECTED_OS="Linux"
INFO global: VAGRANT_INSTALLER_ENV="1"
INFO global: VAGRANT_INTERNAL_BUNDLERIZED="1"
INFO global: VAGRANT_LOG="debug"
@sstelfox
sstelfox / email_test.sh
Created March 31, 2014 01:57
Quick little script for testing whether or not a mail server is setup correctly.
#!/bin/bash
SMTP_SERVER='mail.example.tld'
EMAIL_FROM="$(whoami)@$(hostname)"
EMAIL_DESTINATION='[email protected]'
cat << EOM | nc -C ${SMTP_SERVER} 25
EHLO $(hostname)
MAIL FROM: ${EMAIL_FROM}
RCPT TO: ${EMAIL_DESTINATION}
@sstelfox
sstelfox / key_fingerprints.rb
Created April 18, 2014 20:32
Calculate various key fingerprints
require 'openssl'
# The key for the sample:
private_key = OpenSSL::PKey::RSA.new(1024)
# This method is for comparing an RSA key too an SSH server when it's using
# MD5. You can pass either a public or private key here.
def ssh_md5_fingerprint(key)
OpenSSL::Digest::MD5.hexdigest(
[7].pack("N") + 'ssh-rsa' + key.public_key.e.to_s(0) + key.public_key.n.to_s(0)
class Worker
attr_reader :id
def initialize(id)
@id = id
puts "Spawned new worker with id: #{id}"
end
def dead?
return true if @killed
@sstelfox
sstelfox / tail_recursive_change_maker.rb
Created April 25, 2014 14:14
Small un-optimized attempt at calculating how many unique ways there are too make a particular amount of money with the provided increments. This uses change * 100 to work exclusively with integers.
require 'singleton'
CHANGE_VALUES = [1, 5, 10, 25, 50, 100].reverse
TARGET_VALUE = 100
class ReportTiming
include Singleton
def initialize
reported
@sstelfox
sstelfox / exception_test.rb
Last active August 29, 2015 14:01
Just exploring how ensure behaves when an exception is raised within a rescue block, and how retry affects it all.
#!/usr/bin/env ruby
@crashes = 0
def exception_test(state)
puts "Main block: #{state}"
# Modify our 'state'
state += 1
@sstelfox
sstelfox / ip_inclusion.rb
Last active August 29, 2015 14:01
Sample using native ruby to only update information about hosts that were within the scope of the scan.
#!/usr/bin/env ruby
require 'ipaddr'
# Hosts that we're already aware of by IP
known_hosts = %w{ 127.0.0.1 192.168.122.5 192.168.122.20 192.168.122.48
192.168.122.134 192.168.122.200 192.168.122.210 192.168.122.230 }
# A new task has completed with the following target (only covers
# 192.168.122.0-192.168.122.127)