Skip to content

Instantly share code, notes, and snippets.

View defuse's full-sized avatar
🔬

Taylor Hornby defuse

🔬
View GitHub Profile
@defuse
defuse / attack.php
Created March 14, 2015 21:52
Padding Oracle Attack
<?php
/*
* Padding oracle attack against https://github.com/keboola/php-encryption
* By: Taylor Hornby.
* Date: March 14, 2014.
*/
/* Download the two files and place in the same folder. */
require_once('EncryptorInterface.php');
@defuse
defuse / infoleak.php
Created March 1, 2015 21:31
PHP Exception Leaks Encryption Key
<?php
// Broken crypto code from https://github.com/slimphp/Slim/blob/develop/Slim/Crypt.php
function validateKeyLength($key, $module)
{
$keySize = strlen($key);
$keySizeMin = 1;
$keySizeMax = mcrypt_enc_get_key_size($module);
$validKeySizes = mcrypt_enc_get_supported_key_sizes($module);
if ($validKeySizes) {
if (!in_array($keySize, $validKeySizes)) {
@defuse
defuse / backdoored.php
Created February 28, 2015 08:27
Backdoored Crypto Code
<?php
/*
* Backdooring the constant-time comparison algorithm.
* Taylor Hornby. Feburary 28, 2015.
*
* THIS CODE IS INTENTIONALLY BACKDOORED. DO NOT USE IT!
*/
/* ========================================================================= */
@defuse
defuse / invoice.txt
Created May 14, 2014 00:19
ASCII Invoice
George Carlin INVOICE
carlin@example.org
To: Invoice #6
Stephen Hawking Date: May 13, 2014
hawking@example.org
+-----------------------------------------------------------------+
| Quantity | Description | Unit Price | Total |
@defuse
defuse / constant.c
Last active August 29, 2015 14:00
Constant Time Array Lookup?
// WARNING! This code is untested and experimental. DO NOT USE IT.
// NOTE: If I knew of a way to do the "shift and OR" thing reliably with unsigned ints, the code could be simplified a lot.
// Will always be compiled with -std=c99
// Returns UINT32_MAX if a == b, 0 otherwise.
uint32_t invariant_time_integer_compare(uint32_t a, uint32_t b)
{
/* z will be zero if and only if a == b. */
@defuse
defuse / file_permissions.txt
Created April 11, 2014 04:06
File Permissions
# This is well-known behavior, it's just interesting.
$ mkdir a
$ echo "hello!" > a/file.txt
$ cat a/file.txt
hello!
$ chmod 000 a/file.txt
# Now I don't expect to be able to change a/file.txt...
$ echo "GOODBYE" > a/file.txt
bash: a/file.txt: Permission denied
# Okay, good, I can't modify the file directly.
@defuse
defuse / stats.txt
Created April 2, 2014 15:43
Statistical Test
WARNING: This takes about 10-20 hours to run, depending on your system.
1%...
2%...
3%...
4%...
5%...
6%...
7%...
8%...
9%...
@defuse
defuse / algorithm.txt
Last active August 29, 2015 13:57
Random Characters to Random Bits
Goal:
You're given a sequence of random alphanumeric characters (0-9a-zA-Z, 62
possible characters), for example from a password generator. Convert it into
a sequence of random *bits*.
The output should have the property:
The alphanumeric character RNG can be distinguished from random if and
only if the alphanumeric character RNG, with the conversion algorithm
attached, can be distinguished from random.
@defuse
defuse / paypal_process.rb
Created March 15, 2014 18:51
Paypal Download.csv processor
# WARNING! There is no warranty. This script might not work!
FILE = "Download.csv"
rows = []
File.open( FILE ) do |f|
rows = f.readlines()
end
rows = rows[1..-1]
@defuse
defuse / multitarget.rb
Created March 13, 2014 19:08
Multi-target guessing probability.
# This script answers the following question:
# Alice chooses N random numbers between 1 and K.
# Bob chooses G random numbers between 1 and K.
# What is the probability that at least one number is chosen by both of them?
# Computes (K-N choose G) / (K choose G) in O(N)-ish time.
k = 1_000_000_000
n = 10_000
g = 100_000