Skip to content

Instantly share code, notes, and snippets.

@olavmrk
olavmrk / ssh_env_key.py
Created August 27, 2015 11:38
SSH with key from environment variable
#!/usr/bin/env python
from __future__ import print_function
from __future__ import unicode_literals
import os
import tempfile
import subprocess
import sys
if not 'SSH_KEY' in os.environ:
@olavmrk
olavmrk / removeparent.sh
Last active August 29, 2015 13:57
Remove all parents from commit
# Remove parent of commit 9c747fd659803ab7406b55fe38f752a03b9157d3
git filter-branch --parent-filter 'test $GIT_COMMIT = "9c747fd659803ab7406b55fe38f752a03b9157d3" || cat' HEAD
@olavmrk
olavmrk / check_openssl_wheezy.py
Last active August 29, 2015 13:58
Simple tool to check for processes using deleted versions of openssl, and trying to identify services needing a restart
#!/usr/bin/env python2
import os
import re
import sys
vulnerable = frozenset([
'/usr/lib/i386-linux-gnu/i686/cmov/libssl.so.1.0.0',
'/usr/lib/x86_64-linux-gnu/libssl.so.1.0.0',
])
#include <asm/types.h>
#include <linux/netlink.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
int main() {
int res;
@olavmrk
olavmrk / statictest.py
Created June 29, 2014 18:04
Testing storing references to @staticmethod in class
#!/usr/bin/env python
class Hello(object):
@staticmethod
def _hello_impl_1():
print 'Hello world!'
_hello_impl = None
@staticmethod
def hello():
if Hello._hello_impl == None:
Hello._hello_impl = Hello._hello_impl_1
@olavmrk
olavmrk / sizeof-ulog_packet_msg_t.c
Created June 29, 2014 18:46
Check padding of ulog_packet_msg_t
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#define IFNAMSIZ 16
#define ULOG_PREFIX_LEN 32
#define ULOG_MAC_LEN 80
typedef struct ulog_packet_msg {
#!/usr/bin/env python
import platform
import socket
import struct
import sys
_ULOG_NL_EVENT = 111
class _NetlinkHeader:
SIZE = 16
@olavmrk
olavmrk / term-colors.sh
Created July 8, 2014 08:11
Show terminal colors
#!/bin/bash
for ((C=0;C<=7;C++)) do echo -e "\e[0;$((30+C))mcolor$C\e[0m \e[1;$((30+C))mcolor$((C+8))\e[0m"; done
@olavmrk
olavmrk / securerandom.php
Created July 16, 2014 09:44
Generate secure random integers in a uniform distribution
<?php
function getRandomBits($bits) {
assert('is_int($bits)');
/* First load some random bytes. */
$numBytes = ($bits - 1) / 8 + 1;
$bytes = openssl_random_pseudo_bytes($numBytes);
/* Convert it to an integer. */
@olavmrk
olavmrk / clockdbg.py
Last active August 29, 2015 14:10
Clock debugging script.
#!/usr/bin/env python
import ctypes
import ntplib # wget https://ntplib.googlecode.com/hg/ntplib.py
import sys
import time
# struct timespec {
# time_t tv_sec; /* seconds */
# long tv_nsec; /* nanoseconds */