Ejemplo n.º 1
0
 def test_usage(self):
     p = ThreadPool()
     # default size is 0, synchronous mode
     assert p.size() == 0
     
     # A task performing processing on items from an iterator
     t = IteratorThreadTask(iter(list(range(10))), "power", lambda i: i*i)
     reader = p.add_task(t)
     
     # read all items - they where procesed by worker 1
     items = reader.read()
     assert len(items) == 10 and items[0] == 0 and items[-1] == 81
     
     
     # chaining 
     t = IteratorThreadTask(iter(list(range(10))), "power", lambda i: i*i)
     reader = p.add_task(t)
     
     # chain both by linking their readers
     tmult = ChannelThreadTask(reader, "mult", lambda i: i*2)
     result_reader = p.add_task(tmult)
     
     # read all
     items = result_reader.read()
     assert len(items) == 10 and items[0] == 0 and items[-1] == 162
Ejemplo n.º 2
0
def solve(data, leak, ctext):
   
    guesses = []

    # Based on the access order of Pi ^ Ki pairs in the first round, see aes.c
    pairs = [   (0,4), (4,8), (8,12), (12,5),
                (5,9), (9,13), (13,1), (1,10), 
                (10,14), (14,2), (2,6), (6,15), 
                (15,3), (3,7), (7,11) ]
             
    workerPool = ThreadPool(8)
    workerPool.map(makeGuesses, pairs)
    for result in workerPool.get_results():
        guesses.extend(result)
    
    guesses = statisticalFilter(guesses)
    guesses.sort(key=lambda x : x.cost, reverse=False)

    pairs = np.zeros((16,16), dtype=np.uint8)
    for guess in guesses:
        pairs[guess.i1,guess.i2] = guess.relate
        pairs[guess.i2,guess.i1] = guess.relate

    
    # 00112233445566778899aabbccddeeff
    # 4355a46b19d348dc2f57c046f8ef63d4 (sha256sum(echo "1")[:16])
    keyBase = np.zeros((16), dtype=np.uint8)
    keyBase[0:6] = leak

    keyBase[14] = (keyBase[2]  ^ pairs[2,14]) & mask
    keyBase[10] = (keyBase[14] ^ pairs[10,14]) & mask
    #keyBase[1]  = (keyBase[10] ^ pairs[1,10]) & mask

    keyBase[7]  = (keyBase[3]  ^ pairs[3,7]) & mask
    keyBase[15] = (keyBase[3]  ^ pairs[3,15]) & mask
    keyBase[6]  = (keyBase[15] ^ pairs[6,15]) & mask

    #keyBase[0]  = (keyBase[4]  ^ pairs[4,0]) & mask
    keyBase[8]  = (keyBase[4]  ^ pairs[4,8]) & mask

    keyBase[9]  = (keyBase[5]  ^ pairs[9,5]) & mask
    keyBase[12] = (keyBase[5]  ^ pairs[5,12]) & mask
    keyBase[13] = (keyBase[9]  ^ pairs[9,13]) & mask

    print("Base Pair: %s" % "".join(list(map(lambda x : "%02x" % x, keyBase))))
    sys.stdout.flush()
    
    # 4355a46b19d348dc2f57c046f8ef63d4 (sha256sum(echo "1")[:16])
    for k11 in range(0x0,0x100):
        key = np.array(keyBase, copy=True)
        key[11] = k11
        workerPool.add_task(run, ctext, key)
        
    workerPool.get_results()
Ejemplo n.º 3
0
    def test_base(self):
        p = ThreadPool()

        # default pools have no workers - and threading was removed entirely ...
        assert p.size() == 0

        # SINGLE TASK SERIAL SYNC MODE
        ##############################
        # put a few unrelated tasks that we forget about - check ref counts and cleanup
        t1, t2 = FixtureThreadTask(iter(list()), "nothing1",
                                   None), FixtureThreadTask(
                                       iter(list()), "nothing2", None)
        urc1 = p.add_task(t1)
        urc2 = p.add_task(t2)
        assert p.num_tasks() == 2

        # test pool reader
        assert urc1.pool_ref()() is p
        assert urc1.task_ref()() is t1
        assert urc1.pool() == p
        assert urc1.task() == t1

        ## SINGLE TASK #################
        self._assert_single_task(p, False)
        if py2:
            assert p.num_tasks() == 2
        del (urc1)
        if py2:
            assert p.num_tasks() == 1

        p.remove_task(t2)
        if py2:
            assert p.num_tasks() == 0
        assert sys.getrefcount(t2) == 2

        t3 = FixtureChannelThreadTask(urc2, "channel", None)
        urc3 = p.add_task(t3)
        if py2:
            assert p.num_tasks() == 1
        del (urc3)
        if py2:
            assert p.num_tasks() == 0
        assert sys.getrefcount(t3) == 2

        # DEPENDENT TASKS SYNC MODE
        ###########################
        self._assert_async_dependent_tasks(p)
Ejemplo n.º 4
0
    def test_base(self):
        p = ThreadPool()

        # default pools have no workers - and threading was removed entirely ... 
        assert p.size() == 0

        # SINGLE TASK SERIAL SYNC MODE
        ##############################
        # put a few unrelated tasks that we forget about - check ref counts and cleanup
        t1, t2 = FixtureThreadTask(iter(list()), "nothing1", None), FixtureThreadTask(iter(list()), "nothing2", None)
        urc1 = p.add_task(t1)
        urc2 = p.add_task(t2)
        assert p.num_tasks() == 2

        # test pool reader
        assert urc1.pool_ref()() is p
        assert urc1.task_ref()() is t1
        assert urc1.pool() == p
        assert urc1.task() == t1

        ## SINGLE TASK #################
        self._assert_single_task(p, False)
        if py2:
            assert p.num_tasks() == 2
        del(urc1)
        if py2:
            assert p.num_tasks() == 1

        p.remove_task(t2)
        if py2:
            assert p.num_tasks() == 0
        assert sys.getrefcount(t2) == 2

        t3 = FixtureChannelThreadTask(urc2, "channel", None)
        urc3 = p.add_task(t3)
        if py2:
            assert p.num_tasks() == 1
        del(urc3)
        if py2:
            assert p.num_tasks() == 0
        assert sys.getrefcount(t3) == 2


        # DEPENDENT TASKS SYNC MODE
        ###########################
        self._assert_async_dependent_tasks(p)
Ejemplo n.º 5
0
def test_if_pool_exists():
    # setup
    output_q = Queue()
    pool = ThreadPool(5)
    input_values = set(range(50))

    # run
    for i in input_values:
        pool.add_task(simple_handler, output_q, i)

    # assert
    output_q.join()
    all_values = set()

    while not output_q.empty():
        all_values.add(output_q.get())

    tools.assert_equals(input_values, all_values)
Ejemplo n.º 6
0
    def test_usage(self):
        p = ThreadPool()
        # default size is 0, synchronous mode
        assert p.size() == 0

        # A task performing processing on items from an iterator
        t = IteratorThreadTask(iter(list(range(10))), "power", lambda i: i * i)
        reader = p.add_task(t)

        # read all items - they where procesed by worker 1
        items = reader.read()
        assert len(items) == 10 and items[0] == 0 and items[-1] == 81

        # chaining
        t = IteratorThreadTask(iter(list(range(10))), "power", lambda i: i * i)
        reader = p.add_task(t)

        # chain both by linking their readers
        tmult = ChannelThreadTask(reader, "mult", lambda i: i * 2)
        result_reader = p.add_task(tmult)

        # read all
        items = result_reader.read()
        assert len(items) == 10 and items[0] == 0 and items[-1] == 162
Ejemplo n.º 7
0
    sys.stderr.flush()
      
    with open("./chal.exe", "rb") as f:
        data = f.read()
    data = data.replace(b"\xde\xad\xbe\xef"*4, key)
    fileOut = "/src/patched.exe"
    with open(fileOut, "wb") as f:
        f.write(data)
    st = os.stat(fileOut)
    os.chmod(fileOut, st.st_mode | stat.S_IEXEC)

    workers = ThreadPool(workerCount)
    
    tasks = 1024
    roundingerror = count - int(count/tasks)*tasks
    workers.add_task(run, int(count/tasks) + roundingerror, 0)
    for ii in range(1,tasks):
        workers.add_task(run, int(count/tasks), ii)
   
    textName = "/tmp/test.txt"

    results = workers.get_results()
    with open(textName, "wb") as f:
        for r in results:
            f.write(r)
    
    print(textName)
    
    readmeFile = "/tmp/Readme.txt"
    flag = os.getenv("FLAG", "flag{place:holder}")
    
Ejemplo n.º 8
0
    maskPatch = np.array([3, 3, 3, 3, 3], dtype=np.uint8)
    expand = np.array([8, 6, 4, 2, 0], dtype=np.uint32)

    for s in range(0, 0x400):
        patch = np.array((s >> expand) & maskPatch, dtype=np.uint8)
        key[6:11] &= maskV
        key[6:11] |= patch
        cipher = AES.new(array("B", key).tostring(), AES.MODE_ECB)
        plain = cipher.decrypt(cipherText)
        if b"flag" in plain:
            try:
                sys.stdout.write("%s" % plain.decode('utf-8'))
            except:
                sys.stdout.write("False Match Ignored")
            sys.stdout.flush()
            found = True
        if found:
            return


if __name__ == "__main__":
    keyBase = np.array(bytearray(unhexlify(sys.argv[1])))
    ctext = unhexlify(sys.argv[2])
    workerPool = ThreadPool(4)
    for s in range(0, 0x100):
        maskPatch = np.array([3, 3, 3, 3], dtype=np.uint8)
        expand = np.array([0, 2, 4, 6], dtype=np.uint8)
        key = np.array(keyBase, copy=True)
        key[12:] ^= (s >> expand) & maskPatch
        workerPool.add_task(bruteForce, *(ctext, key))
Ejemplo n.º 9
0
            logger.info("Found file " + file_url)
            filename = file_url.split('/')[-2] # splits and gets the word before /download, which is the filename
            try:
                extension = get_extension(filename)
                if extension in archive_types:
                    proj_ext_counter[extension] += 1
            except ValueError: # file without extension
                pass
        else: # is a directory
            file_queue.append("http://sourceforge.net" + file_url)

pool = ThreadPool(16)
for project_name in project_names:
    proj_ext_counter = Counter()
    file_queue = deque(["http://sourceforge.net/projects/%s/files/" % project_name])
    while file_queue:
        url = file_queue.popleft()
        pool.add_task(visit_project_file, url)
        if not file_queue:
            pool.wait_completion()
    try:
        extension, count = proj_ext_counter.most_common(1)[0]
        ext_counter[extension] += 1
    except IndexError: # no known archive files in project
        pass

print ext_counter
logger.info("Result: %s" % ext_counter)
error_log.close()
http_log.close()