Skip to content

Instantly share code, notes, and snippets.

@bennydictor
bennydictor / gist:c4e005808bd17a834fe8
Created May 15, 2015 21:15
Factorial written is GNU Assembler
.text
.global _start
_start: # syscall is done by %rax(%rdi, %rsi, %rdx)
# read(fd, buf, count)
# we want read one char from stdin, so %rax = 1; %rdi = 1; %rsi = buffer; %rdx = 1
movq $buffer, %rsi # pointer to buffer
movq $0, %rdi # STDIN_FILENO
movq $1, %rdx # one char
rchar: movq $0, %rax # syscall read number (as defined in asm/unistd.h)
window.onload = function() { alert('XSS!'); }
=== gen.py ===
#!/usr/bin/python3
def glob_format(s):
g = globals().copy()
if 'n' in g:
g['n_inc'] = (g['n'] + 1) % 256
g['n_dec'] = (g['n'] - 1) % 256
g['n_c'] = chr(g['n'])
if 'c' in g:
@bennydictor
bennydictor / bf-vim.txt
Created March 18, 2017 08:00
Brainfuck on Vim macros
This is a Brainfuck interpreter written in vim macros
To use it, copy the fourth line to `a' register (4G"ayy),
and run the macro (@a).
{macro}
/^{letterh}
$h"cyl/^{program}
j0"cx/^{code:c}
j"myy@m
Your program here:
@bennydictor
bennydictor / proxy.c
Created April 12, 2017 09:55
Proxy for one website and it injects javascript (and probably doesn't work)
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <netdb.h>
#include <poll.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <cerrno>
#include <cstring> // for strerror
#include <cctype> // for tolower
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <unistd.h>
#define BUF_MAX (4 * 1024)
int read_char(void) {
static char buf[BUF_MAX];
static unsigned int size = 0;
static unsigned int ptr = 0;
if (ptr == size) {
size = read(0, buf, BUF_MAX);
ptr = 0;
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/sendfile.h>
#include <vector>
#include <set>
#include <limits.h>
using namespace std;
@bennydictor
bennydictor / receiver.c
Created April 24, 2018 09:29
Sending file descriptors over unix domain sockets
#include <err.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <unistd.h>
@bennydictor
bennydictor / solution.mk
Created December 7, 2018 15:01
Advent of Code 2018 Day 7 Part 1 in GNU Make
RULES := $(file < input)
RULES := $(subst Step,,$(RULES))
RULES := $(subst must be finished before step,,$(RULES))
RULES := $(subst can begin.,,$(RULES))
RULES := $(strip $(RULES))
TARGETS := $(sort $(RULES))
set_get = $(strip $(__set_$(1)))