Skip to content

Instantly share code, notes, and snippets.

View awnumar's full-sized avatar
🐘
I may be slow to respond.

Awn awnumar

🐘
I may be slow to respond.
View GitHub Profile
@awnumar
awnumar / mainwp-pe-exploit.py
Last active May 16, 2017 18:29
MainWP-Child Privilege Escalation POC Exploit
#!/usr/bin/python2
import requests
def fix_host(host):
if ((not host.startswith("http://")) and (not host.startswith("https://"))):
host = "http://" + host
if (host.endswith("/")):
host = host[:-1]
return host
@awnumar
awnumar / latency.markdown
Created October 8, 2016 21:00 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@awnumar
awnumar / recover_source_code.md
Created March 12, 2017 10:20 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@awnumar
awnumar / chunky.go
Last active August 14, 2019 13:04
Read data (1024) bytes at a time
data := "xxx[...]xxx"
var chunk []byte
for i := 0; i < len(data); i += 1024 {
if i+1024 > len(data) {
// Remaining data <= 1024.
chunk = data[len(data)-(len(data)%1024):]
} else {
// Split into chunks of 1024 bytes and pad.
chunk = data[i:i+1024]
@awnumar
awnumar / ptr2bytes.go
Created April 29, 2017 21:54
Go function to convert a pointer to a slice.
package ptr2bytes
func GetBytesFromPtr(ptr uintptr, len int, cap int) []byte {
var sl = struct {
addr uintptr
len int
cap int
}{ptr, len, cap}
return *(*[]byte)(unsafe.Pointer(&sl))
}
@awnumar
awnumar / encoding_int64.go
Created July 1, 2017 20:32
A small script outlining binary encoding int64 and uint64. (https://play.golang.org/p/t_xT3PcpcK)
package main
import (
"fmt"
"encoding/binary"
)
func main() {
//
// Largest signed int64 in smallest byte slice.
@awnumar
awnumar / int2bin.c
Created December 13, 2017 23:34
Code snippet to encode a uint32 as binary, in C.
// Encode the length into raw binary.
uint32_t rel_len = length;
unsigned char len_bytes[4];
len_bytes[0] = (rel_len >> 24) & 0xFF;
len_bytes[1] = (rel_len >> 16) & 0xFF;
len_bytes[2] = (rel_len >> 8) & 0xFF;
len_bytes[3] = rel_len & 0xFF;
@awnumar
awnumar / python-pattern-matching.py
Created April 2, 2018 14:03
Patern-matching strings in python.
#!/usr/bin/python2
import hashlib
from jinja2.sandbox import SandboxedEnvironment
# We're using only the hashlib functions for demonstratin purposes
# but any algorithm can be implemented and added to the program.
# Define algorithms we support.
@awnumar
awnumar / error.rs
Last active November 7, 2018 18:15
Rust error handling example taken from https://github.com/benashford/rs-es/blob/master/src/error.rs
/*
* Copyright 2015-2016 Ben Ashford
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
#ifndef PROGRAM
#define PROGRAM enquire.c
#define VERSION "5.1a"
#define PURPOSE Everything you wanted to know about your machine and C compiler
#define BUT didnt know who to ask
#define FOR Any OS, any C compiler
#define AUTHOR Steven Pemberton, CWI, Amsterdam; "Steven.Pemberton@cwi.nl"
#define COPYRIGHT(c) 1993-9 Steven Pemberton, CWI. All rights reserved.
#define NOTE Improvements gratefully received. Please mention the version.
#define COMPILE On Unix compile with: "sh enquire.c"; see below for details