Skip to content

Instantly share code, notes, and snippets.

View jsanders's full-sized avatar

James Sanders jsanders

View GitHub Profile
@jsanders
jsanders / blob.rb
Last active December 21, 2015 02:19
WIP Blob library for working with arbitrary unstructured binary data, and SHA1 implementation demonstrating its use.
# Public: Represent and manipulate arbitrary data.
class Blob
# Public: Create Blob from an array of bytes.
#
# bytes - The Array of numbers in the range [0, 255]
#
# Examples
# Blob.new([ 97, 98, 99, 100 ]).to_str
# # => "abcd"
# Blob.from_str([ 97, 98, 99, 100 ]).to_hex
@jsanders
jsanders / LICENSE
Last active January 26, 2025 06:55
32-bit x86 SHA1 implementation.
MIT License
Copyright (c) 2017 Martin Buberl
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:
@jsanders
jsanders / stripe-ctf-1.0.md
Last active May 26, 2017 16:22
Work-through of the Stripe CTF 1.0 focused more on system-level than web-level security.

Stripe CTF 1.0

Level 1

Ok, start by ssh-ing to [email protected] with password w5kjAsSKEjCT. Our goal is to read the file .password from the level02 user's home directory: /home/level02. Let's look for low-hanging fruit - maybe we can just read the file directly:

@jsanders
jsanders / level06_exploit.py
Last active December 22, 2015 16:48
Exploit in python for level 6 of Stripe's first CTF.
from os import pipe, write, close
from subprocess import Popen, PIPE
import select
import string
import sys
PIPE_MAX = 1<<16 # 64k
WELCOME_LEN = len("Welcome to the password checker!\n")
def args(guess):
@jsanders
jsanders / shellcode.asm
Last active December 26, 2015 04:56
Generally useful, well-documented, and small shellcode generator. Based on work I did for level05 of Stripe's original CTF, but much nicer.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; A nice, small 32-bit x86 execve shellcode template. ;
; execve("//bin/sh", [ "//bin/sh", NULL ], [ NULL ]). ;
; Shellcode itself is 25 bytes. ;
; Provide definitions of PayloadSize and JumpAddress ;
; to generate a self-contained buffer of the desired ;
; size and with the desired address to jump to. ;
; Build with "nasm -f bin -o shellcode shellcode.asm" ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@jsanders
jsanders / invmod.rb
Created September 27, 2013 20:57
Modular inverse function, with obligatory EGCD implementation.
# Extended Euclidean GCD algorithm
# Outputs k, u, and v such that ua + vb = k where k is the gcd of a and b
def egcd(a, b)
u_a, v_a, u_b, v_b = [ 1, 0, 0, 1 ]
while a != 0
q = b / a
a, b = [ b - q*a, a ]
u_a, v_a, u_b, v_b = [ u_b - q*u_a, v_b - q*v_a, u_a, v_a ]
# Each time, `u_a*a' + v_a*b' = a` and `u_b*a' + v_b*b' = b`
end
@jsanders
jsanders / redis.rs
Last active December 24, 2015 10:29
Start of redis client implementation in rust
use std::rt::io::{Reader, Writer};
use std::rt::io::net::ip::{Ipv4Addr,SocketAddr};
use std::rt::io::net::tcp::TcpStream;
use std::str;
trait ToUintSafe {
fn to_uint_safe(&self) -> Option<uint>;
}
impl ToUintSafe for int {
@jsanders
jsanders / flip.rs
Last active December 24, 2015 10:38
Seeing if I can make a rust implementation of `flip` that is reminiscent of Haskell's (http://hackage.haskell.org/package/base-4.6.0.1/docs/Prelude.html#v:flip)
fn flip<T>(f: ~fn(a: T, b: T)) -> ~fn(a: T, b: T) {
|a, b| { f(b, a) }
}
fn hello_world(hello: &str, world: &str) {
println!("{:s}, {:s}!", hello, world)
}
#[test]
fn test_flip() {
@jsanders
jsanders / glut_hello_world.cpp
Last active December 25, 2015 03:09
GLUT hello world implementations in c++ (for reference) and rust (as an attempt). The rust version seems close to working, but it hangs after the window comes up...
// Compile with `g++ -framework GLUT glut_hello_world.cpp`
#include <GLUT/glut.h>
void display(void) { }
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
@jsanders
jsanders / explain_analyze.rb
Created December 18, 2013 22:56
Run EXPLAIN ANALYZE on all select queries and log the results. Definitely don't use this if performance matters...
if Rails.env.development?
require 'active_record/connection_adapters/postgresql_adapter'
class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
def __explain_analyze(sql, command, *args)
meth = "#{command}_without_explain_analyze".to_sym
if /\A\s*SELECT/i.match(sql)
newsql = "EXPLAIN ANALYZE #{sql}"
plan = send(meth, newsql, *args).map { |row| row['QUERY PLAN'] }.join("\n")
Rails.logger.debug("\e[1m\e[31mQUERY PLAN FOR: #{sql.strip};\n#{plan}\e[0m")