Skip to content

Instantly share code, notes, and snippets.

@inaz2
inaz2 / xortools.py
Created March 31, 2014 07:25
utilities for XOR/ROT substritution cipher
$ python
Python 2.7.3 (default, Feb 27 2014, 20:00:17)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from xortools import *
>>> plaintext = 'This program cannot be run in DOS mode.'
>>> ciphertext = xorencode(plaintext, 'AX')
>>> ciphertext
'\x150(+a(37&* 5a; 6/75x#=a*46a1/x\x05\x17\x12x,7%=o'
>>> find_xorkey(ciphertext, 'program', keylen=2)
@inaz2
inaz2 / inlineasm.c
Last active August 29, 2015 13:58
GCCインラインアセンブラでスタックを見る
$ gcc -masm=intel inlineasm.c
$ ./a.out
saved_ebp = 0
saved_eip = b7e444d3
argc = 1
argv = bffff864
envp = bffff86c
$ objdump -d a.out | sed -n '/<main>:/,/^$/p'
@inaz2
inaz2 / test_malloc.c
Last active August 29, 2015 13:58
malloc and buffer over-read vulnerability
$ uname -a
Linux vm-ubuntu64 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$ gcc test_malloc.c
$ ./a.out
[+] allocate chunks: a = malloc(32), b = malloc(256), c = malloc(32)
a = 0x832010, b = 0x832040, c = 0x832150
*a = 41414141, *b = 42424242, *c = 45524548
[+] free the mid chunk: free(b)
@inaz2
inaz2 / yt2m4a.py
Last active August 29, 2015 13:58
wgetとavconvでYouTube URLをM4A (AAC) ファイルに変換
$ python yt2m4a.py "http://www.youtube.com/watch?v=4YMD6xELI_k"
--2014-04-11 02:25:26-- http://r2---sn-ogueyn7z.googlevideo.com/videoplayback?sparams=id%2Cip%2Cipbits%2Citag%2Cpcm2fr%2Cratebypass%2Csource%2Cupn%2Cexpire&ipbits=0&mt=1397150542&expire=1397173854&upn=15FckWnBsJw&fexp=927905%2C936905%2C901065%2C916623%2C945513%2C937417%2C913434%2C936916%2C934022%2C936921%2C936923&signature=A2B6A3A92CCB9F6F09EDEC21266137C2A09975DF.A94CC65958FD475F79CE18DDF05188C29591C7A0&key=yt5&ip=123.224.99.3&pcm2fr=yes&itag=22&source=youtube&sver=3&mv=u&ratebypass=yes&ms=au&id=o-ADTX4MBPHtBDylBsjOsDle1msEAsW4PTJ7EyQH0qyPo1
Resolving r2---sn-ogueyn7z.googlevideo.com (r2---sn-ogueyn7z.googlevideo.com)... 74.125.171.39
Connecting to r2---sn-ogueyn7z.googlevideo.com (r2---sn-ogueyn7z.googlevideo.com)|74.125.171.39|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://r13---sn-ogueyn7z.googlevideo.com/videoplayback?sparams=id%2Cip%2Cipbits%2Citag%2Cpcm2fr%2Cratebypass%2Csource%2Cupn%2Cexpire&ipbits=0&
@inaz2
inaz2 / decom.py
Last active March 15, 2020 14:56
filter script from x86 instructions to C-like expressions
import sys
import re
lines = []
locs = []
def add_loc(s):
def _add_loc(m):
locs.append(m.group(1))
return s % m.group(1)
@inaz2
inaz2 / rot.py
Created June 9, 2014 06:10
perform rot0 -- rot25
$ echo -n 'hello world' | python rot.py
hello world
ifmmp xpsme
jgnnq yqtnf
khoor zruog
lipps asvph
mjqqt btwqi
nkrru cuxrj
olssv dvysk
pmttw ewztl
@inaz2
inaz2 / ngram.py
Last active August 29, 2015 14:02
calculate n-gram statistics
$ wget http://printkjv.ifbweb.com/AV_txt.zip
2014-06-09 15:30:46 (535 KB/s) - `AV_txt.zip' saved [1262589/1262589]
$ unzip AV_txt.zip
Archive: AV_txt.zip
inflating: AV1611Bible.txt
$ python ngram.py < AV1611Bible.txt
1 gram result:
414963 'e'
@inaz2
inaz2 / auto_and_decltype.cpp
Created July 3, 2014 11:24
C++11: auto and decltype
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <functional>
using namespace std;
template <typename T>
auto cube(T x) -> decltype(x)
{
@inaz2
inaz2 / asm.sh
Created July 8, 2014 08:46
convert between asm and opcodes
function asm() {
echo "$*" | as -msyntax=intel -mnaked-reg -aln -o /dev/null
}
function disas() {
echo "$*" | perl -ne 's/([0-9A-Fa-f]{2})/print pack("H2",$1)/eg' >/tmp/disasm && objdump -M intel -D -b binary -m i386 /tmp/disasm | tail -n+8
}
@inaz2
inaz2 / gist:8cc80f55d5f1a212ec15
Created July 9, 2014 01:41
seq, factor, awkで素数列挙
$ seq 100 | factor | awk 'NF==2{print $2}'
2
3
5
7
11
13
17
19
23