Skip to content

Instantly share code, notes, and snippets.

@asterite3
asterite3 / unbuffered.go
Created December 20, 2020 10:29
Unbuffered with CleanContext with a second struct
package broadcaster
import (
"context"
"io"
"sync"
"sync/atomic"
)
// Unbuffered accumulates multiple io.WriteCloser by stream.
@asterite3
asterite3 / print-a-lot-and-exit.go
Created December 19, 2020 20:01
A program that prints a lot and exits after 63 seconds
package main
import (
"io"
"time"
"os"
)
const a = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"
SecRuleEngine On
SecAction \
"id:1,\
phase:1,\
pass,\
nolog,\
t:none,\
setvar:'tx.anomaly_score_pl1=0'"
@asterite3
asterite3 / test.conf
Created February 6, 2020 10:11
Minimal test config to demonstrate PCRE data leaks in ModSecurity2
SecRuleEngine On
# Default HTTP policy: allowed_request_content_type (rule 900220)
SecRule &TX:allowed_request_content_type "@eq 0" \
"id:901162,\
phase:1,\
pass,\
nolog,\
setvar:'tx.allowed_request_content_type=application/x-www-form-urlencoded|multipart/form-data|text/xml|application/xml|application/soap+xml|application/x-amf|application/json|application/octet-stream|application/csp-report|application/xss-auditor-report|text/plain'"
#include <stdio.h>
#include <stdlib.h>
#include "api.h"
const char * url = "/remote.php/dav/files/";
void logMessage(void *obj, int level, char *str) { printf("%s\n", str); }
apr_status_t readbody(request_rec *r, char *buf, unsigned int length, unsigned int *readcnt, int *is_eos) {
@asterite3
asterite3 / solve_line.py
Created June 11, 2019 16:30
Z3-based solution of ctf.moscow task "line"
from z3 import *
from cypher import L3LFSR
KEY_LEN = 128
KNOWN = 'CTF.Moscow{eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9'
#KNOWN = 'CTF.Moscow{e'
KNOWN = 'CTF.Moscow{eyJ0eX'
KNOWN_INT = int.from_bytes(bytes(KNOWN, 'ascii'), 'big')
KNOWN_BITS = list(map(int, bin(KNOWN_INT)[2:]))
KNOWN_LEN = len(KNOWN)
@asterite3
asterite3 / cipher.py
Created June 11, 2019 11:42
L3LFSR keystream generator for cipher from ctf.moscow task "line"
class L3LFSR:
def __init__(self, key):
self.r1 = key[:67]
self.r2 = key[67:67+59]
self.r3 = key[-2:]
self.b1 = [67, 5, 2, 1]
self.b2 = [59, 6, 5, 4, 3, 1]
self.b3 = [2, 1]
def _clock_r(self, reg, branches):
@asterite3
asterite3 / pgproxy.go
Last active June 1, 2019 11:18
PostgreSQL wire protocol proxy/MitM written in Go based on pgx (https://github.com/jackc/pgx). Does not support SSLRequest (connect with sslmode=disable).
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net"
"sync"
@asterite3
asterite3 / gist:4b9159b8bfcdf9ad8def88168d28b60e
Created March 6, 2019 16:43
Bash one-liner to run nginx on command line as regular user to serve files from current directory (a replacement for python -m SimpleHTTPServer)
T=`mktemp` P=`mktemp` && bash -e -c "exec 3<$T && exec 4>$P && rm $P && echo -e 'daemon off;worker_processes auto;pid /dev/null;error_log /dev/stderr;events {} http { access_log /dev/stdout; include /etc/nginx/mime.types; server { listen 127.0.0.1:8000; location / { autoindex on; autoindex_exact_size off; root .;} }}' > $T && rm $T && exec nginx -p . -c /dev/fd/3"
@asterite3
asterite3 / nginx.sh
Last active October 12, 2023 20:39
Serve current directory with nginx. As a regular (non-root) user (a replacement for python -m SimpleHTTPServer)
#!/bin/bash
# Usage:
# ./nginx.sh
# ./nginx.sh 8888
# ./nginx.sh 0.0.0.0 8080
set -e
HOST="127.0.0.1"