Пример #1
0
def test_single_file_bomb():
    output = DummyOutput()
    target_size = 1000
    gz.options['type'] = 'single_file'
    gz.options['target_size'] = target_size
    gz.run(output)
    assert output.count() == 1
    assert len(gzip.decompress(output[0])) == target_size
Пример #2
0
def test_size_difference():
    output1 = DummyOutput()
    output2 = DummyOutput()
    billion_laughs.options['memory_impact'] = 10.0
    billion_laughs.run(output1)
    billion_laughs.options['memory_impact'] = 10000.0
    billion_laughs.run(output2)
    assert len(output1) == 1
    assert len(output2) == 1
    assert len(output1[0]) < len(output2[0])
Пример #3
0
def test_run_small_collision_count():
    output = DummyOutput()
    n_collisions = 10
    hash_table_size = 2**32
    target = '42'
    java.options['n_collisions'] = n_collisions
    java.options['target_type'] = 'image'
    java.options['target'] = target
    java.options['hash_table_size'] = hash_table_size
    java.run(CharGenerator(), output)
    assert output.count() == n_collisions
    for i in output:
        assert java_common.java_hash(i, hash_table_size) == int(target)
Пример #4
0
def test_preimage():
    output = DummyOutput()
    n_collisions = 10
    hash_table_size = 2**32
    preimage_target = 'hello world'
    java.options['n_collisions'] = n_collisions
    java.options['target_type'] = 'preimage'
    java.options['target'] = preimage_target
    java.options['hash_table_size'] = hash_table_size
    java.run(CharGenerator(), output)
    target = java_common.java_hash(preimage_target, hash_table_size)
    assert output.count() == n_collisions
    for i in output:
        assert java_common.java_hash(i, hash_table_size) == target
Пример #5
0
def test_run_small_collision_count():
    output = DummyOutput()
    n_collisions = 20
    hash_table_size = 2**32
    target = '42'
    php5_fast.options['n_collisions'] = n_collisions
    php5_fast.options['n_substrings'] = 10
    php5_fast.options['target_type'] = 'image'
    php5_fast.options['target'] = target
    php5_fast.options['hash_table_size'] = hash_table_size
    php5_fast.run(CharGenerator(), output)
    assert output.count() == n_collisions
    for i in output:
        assert php5_common.php_hash(i, hash_table_size) == int(target)
Пример #6
0
def test_preimage():
    output = DummyOutput()
    n_collisions = 10
    hash_table_size = 2**32
    preimage_target = 'hello world'
    php5_fast.options['n_collisions'] = n_collisions
    php5_fast.options['n_substrings'] = 10
    php5_fast.options['target_type'] = 'preimage'
    php5_fast.options['target'] = preimage_target
    php5_fast.options['hash_table_size'] = hash_table_size
    php5_fast.run(CharGenerator(), output)
    target = php5_common.php_hash(preimage_target, hash_table_size)
    assert output.count() == n_collisions
    for i in output:
        assert php5_common.php_hash(i, hash_table_size) == target
Пример #7
0
def test_run_small_collision_output():
    output = DummyOutput()
    n_collisions = 2
    length = 7
    substring_length = 3
    target = '42'
    python2_32.options['n_collisions'] = n_collisions
    python2_32.options['length'] = length
    python2_32.options['substring_length'] = substring_length
    python2_32.options['target'] = target
    python2_32.options['target_type'] = 'image'
    python2_32.run(CharGenerator(), output)
    assert output.count() == n_collisions
    for i in output:
        assert python2_32.hash(i) == int(target)
Пример #8
0
def test_preimage():
    output = DummyOutput()
    n_collisions = 2
    length = 8
    substring_length = 4
    target = 'hello'
    python2_32.options['n_collisions'] = n_collisions
    python2_32.options['length'] = length
    python2_32.options['substring_length'] = substring_length
    python2_32.options['target'] = target
    python2_32.options['target_type'] = 'preimage'
    python2_32.run(CharGenerator(), output)
    assert output.count() == n_collisions
    for i in output:
        assert python2_32.hash(i) == python2_32.hash(target)
Пример #9
0
def test_more_collisions():
    output = DummyOutput()
    n_collisions = 20
    hash_table_size = 10
    target = '5'
    length = 10
    adler32.options['n_collisions'] = n_collisions
    adler32.options['length'] = length
    adler32.options['target_type'] = 'image'
    adler32.options['target'] = target
    adler32.options['hash_table_size'] = hash_table_size
    adler32.run(output)
    assert output.count() == n_collisions
    for i in output:
        assert adler32_hash(i, hash_table_size) == int(target)
        assert len(i) == length
Пример #10
0
def test_more_collisions():
    output = DummyOutput()
    n_collisions = 3
    length = 5
    hash_table_size = 100
    target = '42'
    sum.options['n_collisions'] = n_collisions
    sum.options['length'] = length
    sum.options['hash_table_size'] = hash_table_size
    sum.options['target_type'] = 'image'
    sum.options['target'] = target
    sum.run(output)
    assert output.count() == n_collisions
    for i in output:
        assert sum_hash(i, hash_table_size) == int(target)
        assert len(i) == length
Пример #11
0
def test_run():
    output = DummyOutput()
    n_collisions = 1
    hash_table_size = 0xffffffff
    target = '42'
    length = 10
    crc32.options['n_collisions'] = n_collisions
    crc32.options['length'] = length
    crc32.options['target_type'] = 'image'
    crc32.options['target'] = target
    crc32.options['hash_table_size'] = hash_table_size
    crc32.run(output)
    assert output.count() == n_collisions
    for i in output:
        assert crc32_hash(i, hash_table_size) == int(target)
        assert len(i) == length
Пример #12
0
def test_time_multiplier_bomb():
    output = DummyOutput()
    target_payload_memory = 1000
    pdf.options['target_payload_memory'] = target_payload_memory
    pdf.options['time_multiplier'] = 2
    pdf.run(output)
    assert len(output) == 1
Пример #13
0
def test_larger_width():
    output = DummyOutput()
    n_collisions = 1
    length = 5
    hash_table_size = 100
    target = '42'
    xor8.options['n_collisions'] = n_collisions
    xor8.options['length'] = length
    xor8.options['hash_table_size'] = hash_table_size
    xor8.options['target_type'] = 'image'
    xor8.options['target'] = target
    xor8.run(output)
    assert output.count() == n_collisions
    for i in output:
        assert xor8_hash(i, hash_table_size) == int(target)
        assert len(i) == length
Пример #14
0
def test_short_length():
    output = DummyOutput()
    n_collisions = 10
    hash_table_size = 100
    target = '42'
    length = 5
    bsd.options['n_collisions'] = n_collisions
    bsd.options['length'] = length
    bsd.options['target_type'] = 'image'
    bsd.options['target'] = target
    bsd.options['hash_table_size'] = hash_table_size
    bsd.run(output)
    assert output.count() == n_collisions
    for i in output:
        assert bsd_hash(i, hash_table_size) == int(target)
        assert len(i) == length
Пример #15
0
def test_run():
    output = DummyOutput()
    n_collisions = 1
    hash_table_size = 2**32
    target = '42'
    length = 10
    java_z3.options['n_collisions'] = n_collisions
    java_z3.options['length'] = length
    java_z3.options['target_type'] = 'image'
    java_z3.options['target'] = target
    java_z3.options['hash_table_size'] = hash_table_size
    java_z3.run(output)
    assert output.count() == n_collisions
    for i in output:
        assert java_common.java_hash(i, hash_table_size) == int(target)
        assert len(i) == length
Пример #16
0
def test_run_larger_hash_table_size():
    output = DummyOutput()
    n_collisions = 10
    hash_table_size = 1024
    target = '42'
    length = 10
    lrc.options['n_collisions'] = n_collisions
    lrc.options['length'] = length
    lrc.options['target_type'] = 'image'
    lrc.options['target'] = target
    lrc.options['hash_table_size'] = hash_table_size
    lrc.run(output)
    assert output.count() == n_collisions
    for i in output:
        assert z3lrc_hash(i, hash_table_size) == int(target)
        assert len(i) == length
Пример #17
0
def test_multi_layer_bomb():
    output = DummyOutput()
    tar_gz.options['type'] = 'layer'
    tar_gz.options['target_size'] = 1000000
    tar_gz.options['n_layers'] = 5
    tar_gz.run(output)
    assert len(output) == 1
Пример #18
0
def test_no_zero_intial_key():
    output = DummyOutput()
    n_collisions = 1
    hash_table_size = 0x3FFFFFFFFFFFFFFF
    target = '42'
    initial_key = 11312
    chicken_scheme.options['n_collisions'] = n_collisions
    chicken_scheme.options['n_substrings'] = 1
    chicken_scheme.options['initial_key'] = initial_key
    chicken_scheme.options['target_type'] = 'image'
    chicken_scheme.options['target'] = target
    chicken_scheme.options['hash_table_size'] = hash_table_size
    chicken_scheme.run(output)
    assert output.count() == n_collisions
    for i in output:
        assert chicken_scheme_hash(i, hash_table_size,
                                   initial_key) == int(target)
Пример #19
0
def test_mu_too_small():
    output = DummyOutput()
    order = 200
    simplex.options['order'] = order
    simplex.options['mu'] = 2.0
    simplex.options['pivot_type'] = 'largest_coefficient'
    with pytest.raises(ValueError):
        simplex.run(output)
Пример #20
0
def test_more_inputs():
    output = DummyOutput()
    n_inputs = 100
    bubblesort.options['n_inputs'] = n_inputs
    bubblesort.run(IntGenerator(), output)
    assert len(output) == n_inputs
    for i in range(len(output) - 1):
        assert output[i] == output[i + 1] + 1
Пример #21
0
def test_git_bombs():
    depths = range(10, 51, 10)

    for d in depths:
        output = DummyOutput()
        git_bombs.options['depth'] = d
        git_bombs.run(output)
        assert len(output) == 1
Пример #22
0
def test_preimage():
    output = DummyOutput()
    n_collisions = 10
    hash_table_size = 0xffff
    target = 'hello'
    length = len(target)
    bsd.options['n_collisions'] = n_collisions
    bsd.options['length'] = length
    bsd.options['target_type'] = 'preimage'
    bsd.options['target'] = target
    bsd.options['hash_table_size'] = hash_table_size
    bsd.run(output)
    assert output.count() == n_collisions
    for i in output:
        assert bsd_hash(i,
                        hash_table_size) == bsd_hash(target, hash_table_size)
        assert len(i) == length
Пример #23
0
def test_preimage():
    output = DummyOutput()
    n_collisions = 10
    hash_table_size = 100
    target = 'hello'
    length = len(target)
    adler32.options['n_collisions'] = n_collisions
    adler32.options['length'] = length
    adler32.options['target_type'] = 'preimage'
    adler32.options['target'] = target
    adler32.options['hash_table_size'] = hash_table_size
    adler32.run(output)
    assert output.count() == n_collisions
    for i in output:
        assert adler32_hash(i, hash_table_size) == adler32_hash(
            target, hash_table_size)
        assert len(i) == length
Пример #24
0
def test_min_more_inputs():
    output = DummyOutput()
    n_inputs = 100
    red_black_tree.options['n_inputs'] = n_inputs
    red_black_tree.run(IntGenerator(), output)
    assert len(output) == n_inputs
    for i in range(len(output) - 1):
        assert output[i] == output[i + 1] + 1
Пример #25
0
def test_run():
    output = DummyOutput()
    string_length = 120
    line_breaking.options['string_length'] = string_length
    line_breaking.run(CharGenerator(), output)
    assert len(output) == 1
    assert len(output[0]) == string_length - 1
    assert output[0] == ('a ' * ((string_length - 1) // 2)) + 'a'
Пример #26
0
def test_run():
    output = DummyOutput()
    n_inputs = 10
    b_tree.options['n_inputs'] = n_inputs
    b_tree.run(IntGenerator(), output)
    assert len(output) == n_inputs
    for i in range(len(output) - 1):
        assert output[i] == output[i + 1] + 1
Пример #27
0
def test_run():
    output = DummyOutput()
    expected = 'abccdddeeeee'
    n_inputs = len(expected)
    huffman.options['n_inputs'] = n_inputs
    huffman.run(CharGenerator(), output)
    assert len(output) == 1
    assert output[0] == expected
Пример #28
0
def test_run_hoare():
    output = DummyOutput()
    n_inputs = 11
    quicksort.options['n_inputs'] = n_inputs
    quicksort.options['type'] = 'hoare'
    quicksort.run(IntGenerator(), output)
    assert len(output) == n_inputs
    for i, j in enumerate(output):
        assert j == i + 1 + (255 - n_inputs)
Пример #29
0
def test_min():
    output = DummyOutput()
    n_inputs = 10
    heap.options['n_inputs'] = n_inputs
    heap.options['type'] = 'min'
    heap.run(IntGenerator(), output)
    assert len(output) == n_inputs
    for i in range(len(output) - 1):
        assert output[i] == output[i + 1] + 1
Пример #30
0
def test_preimage():
    output = DummyOutput()
    n_collisions = 10
    hash_table_size = 0x3FFFFFFFFFFFFFFF
    target = 'hello'
    initial_key = 0
    chicken_scheme.options['n_collisions'] = n_collisions
    chicken_scheme.options['n_substrings'] = 1
    chicken_scheme.options['initial_key'] = initial_key
    chicken_scheme.options['target_type'] = 'preimage'
    chicken_scheme.options['target'] = target
    chicken_scheme.options['hash_table_size'] = hash_table_size
    chicken_scheme.run(output)
    assert output.count() == n_collisions
    for i in output:
        assert (chicken_scheme_hash(i, hash_table_size,
                                    initial_key) == chicken_scheme_hash(
                                        target, hash_table_size, initial_key))