Skip to content

Instantly share code, notes, and snippets.

View Freaky's full-sized avatar

Thomas Hurst Freaky

View GitHub Profile
@Freaky
Freaky / patch-src_gifread_gifread.c
Last active October 30, 2023 23:47
Workaround for OptiPNG 0.7.7's CVE-2023-43907
--- src/gifread/gifread.c.orig 2023-10-30 19:44:00.082877489 +0000
+++ src/gifread/gifread.c 2023-10-30 22:42:08.789142913 +0000
@@ -363,6 +363,11 @@
lastbit = (2 + count) * 8;
}
+ if (code_size && (size_t)(curbit + code_size - 1) / 8 >= sizeof(buffer)) {
+ GIFError("Malformed GIF (CVE-2023-43907)");
+ return -1;
+ }
@Freaky
Freaky / fixed_length_secure_compare.rb
Created August 25, 2023 03:37
A faster pure Ruby constant-time secure compare
def fixed_length_secure_compare(a, b)
raise ArgumentError, 'length mismatch' unless a.bytesize == b.bytesize
res = 0
if a.bytesize >= 4 && a.bytesize % 4 == 0
ai = a.unpack "L*"
bi = b.unpack "L*"
ai.each { |int| res |= int ^ bi.shift }
else
ab = a.bytes
@Freaky
Freaky / zenbleed_workaround
Last active August 12, 2023 18:59
FreeBSD Zenbleed mitigation rc script
#!/bin/sh
#
# PROVIDE: zenbleed_workaround
# REQUIRE: root mountcritlocal microcode_update
# BEFORE: SERVERS
# KEYWORD: nojail resume
# Source: https://gist.github.com/Freaky/2560975d3c94246b86f464b8be75c967
#
# Copyright (c) 2023 Thomas Hurst <tom@hur.st>
@Freaky
Freaky / nzbsplit.rb
Created March 13, 2020 04:51
Split an NZB into multiple smaller NZBs
#!/usr/bin/env ruby
def usage() abort("#{$0} [base nzb] [number of new nzbs]") end
file = ARGV.shift
nzb = File.read(file)
num = Integer(ARGV.shift) rescue usage
header, nzb = nzb.split(/(?=<file)/, 2)
files = nzb.scan(/<file.*?<\/file>/m)
#!/usr/bin/env ruby
times = ARGF
.each_line
.map { |line| /^.*\+([0-9]{10})\.([0-9]{6})[0-9]* (.{1,77})/.match(line) }
.select(&:itself)
.map { |md| [Integer(md[1] + md[2]), md[3]] }
.each_cons(2)
.map { |a, b| [b[0] - a[0], a[1]]}
.sort_by(&:first)
@Freaky
Freaky / Dockerfile
Last active April 7, 2019 15:51
tarssh Dockerfile
FROM rust:1.33-stretch as build
WORKDIR /usr/src/tarssh
# Make a blank project with our deps for Docker to cache.
# We skip rusty-sandbox because it does nothing useful on Linux.
COPY Cargo.toml Cargo.lock .
RUN mkdir -p src \
&& echo 'fn main() { }' >src/main.rs \
&& cargo build --release --no-default-features --features drop_privs
@Freaky
Freaky / tarssh.rs
Last active March 26, 2019 18:31
Rust ssh tarpit
use std::env;
use std::net::SocketAddr;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Duration, Instant};
use exitcode;
use env_logger;
use log::{error, info, warn};
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define LO ((uint64_t)0x0101010101010101L)
#define HI ((uint64_t)0x8080808080808080L)
#define LOOP_SIZE (2 * sizeof(uint64_t))
@Freaky
Freaky / readline-prefixed-junk.rb
Created January 2, 2019 15:55
Print crap before readline
#!/usr/bin/env ruby
require 'readline'
run = true
puts
worker = Thread.new do
i = 0
while run
STDOUT.print("\e[s\r\e[A\e[KMoo moo baa #{i += 1}\n\e[u");
@Freaky
Freaky / vm_superhub.rb
Created December 28, 2018 19:56
Munin plugin for Virgin Media Superhub
#!/usr/local/bin/ruby
Host = '192.168.100.1'
require 'net/http'
require 'timeout'
def get(page)
Timeout.timeout(5) { Net::HTTP.get(Host, page) }
rescue => e
STDERR.puts "GET http://#{Host}/#{page} failure: #{e.class}: #{e.message}"