예제 #1
0
import string
import random
import hashlib
from exercises.registry import register_generator

def password_generator(length=6):
    '''
    Create a random string of lowercase letters.
    '''
    return 'the_password_is_' + ''.join(random.SystemRandom().choice(string.ascii_lowercase) for _ in range(length))

class HashExercise(object):
    '''
    SHA256 encoding class for the hands-on exercise of lesson 6 of crypto-class.
    '''
    def __init__(self, arg_dict=None):
        self.metadata = {}
        self.metadata['password'] = password_generator()
        self.encode()

    def encode(self):
        self.metadata['message'] = self.message = hashlib.sha256(self.metadata['password'].encode('utf8')).hexdigest()

register_generator('6.0', HashExercise)
예제 #2
0
from exercises.registry import register_generator


class OnionExercise(object):
    '''
    Hands-on exercise for creating an onion address
    '''
    def __init__(self, args_dict=None):
        if 'user' not in args_dict:
            print 'User is required for OnionExercise initialization'
            exit(1)

        user = args_dict['user']

        if not user.is_authenticated():
            self.message = '*****@*****.**'
            self.metadata = {}
            return

        # user is authenticated
        self.metadata = {'user_email': user.email}
        self.message = user.email


register_generator('20.0', OnionExercise)
예제 #3
0
from django.conf import settings
from exercises.registry import register_generator

from .models import HttpsPassword
import random


class HttpsExercise(object):
    '''
    Hands-on exercise for HTTPS traffic decryption
    '''
    def __init__(self, args_dict=None):
        exercise_packet = random.choice(HttpsPassword.objects.all())
        self.metadata = {'password': exercise_packet.password}
        self.message = '<a href="%s">Download file</a>' % (
            settings.MEDIA_URL + exercise_packet.filename)


register_generator('18.0', HttpsExercise)
예제 #4
0
            self.metadata = {}
            quote = random.choice(SubstitutionQuote.objects.all()).quote
            random_lst = list(string.ascii_uppercase)
            random.shuffle(random_lst)
            self.metadata['permutation'] = ''.join(random_lst)
            self.metadata['password'] = password_generator()
            self.metadata['cleartext'] = quote.upper() + '\nPassword '.upper() + self.metadata['password']
            self.encode('e')

    def encode(self, mode):
        out = ''
        inp = self.metadata['cleartext'] if mode == 'e' else self.message
        for pos, ch in enumerate(inp):
            if ch not in string.uppercase:
                out += ch
            else:
                if mode == 'e':
                    offset = ord(ch) - ord('A')
                    out += self.metadata['permutation'][offset]
                else:
                    offset = self.metadata['permutation'].find(ch)
                    out += string.ascii_uppercase[offset]
        if mode == 'e':
            self.metadata['message'] = self.message = out
        else:
            self.cleartext = out

register_generator('1.1', Base64Exercise)
register_generator('1.2', Rot13Exercise)
register_generator('1.3', SubstitutionExercise)
예제 #5
0
            random_lst = list(string.ascii_uppercase)
            random.shuffle(random_lst)
            self.metadata['permutation'] = ''.join(random_lst)
            self.metadata['password'] = password_generator()
            self.metadata['cleartext'] = quote.upper() + '\nPassword '.upper(
            ) + self.metadata['password']
            self.encode('e')

    def encode(self, mode):
        out = ''
        inp = self.metadata['cleartext'] if mode == 'e' else self.message
        for pos, ch in enumerate(inp):
            if ch not in string.uppercase:
                out += ch
            else:
                if mode == 'e':
                    offset = ord(ch) - ord('A')
                    out += self.metadata['permutation'][offset]
                else:
                    offset = self.metadata['permutation'].find(ch)
                    out += string.ascii_uppercase[offset]
        if mode == 'e':
            self.metadata['message'] = self.message = out
        else:
            self.cleartext = out


register_generator('1.1', Base64Exercise)
register_generator('1.2', Rot13Exercise)
register_generator('1.3', SubstitutionExercise)
예제 #6
0
import random
from .models import RSAValues
from exercises.registry import register_generator

class RSAWienerExercise(object):
    def __init__(self, args_dict=None):
        if len(args_dict) == 1:
            args_dict = {}
        try:
            if 'metadata' in args_dict:
                self.metadata = args_dict['metadata']
                self.message = self.metadata['message']
            else:
                self.metadata = { }
                rsa_value = random.choice(RSAValues.objects.all())

                message = 'n:\n' + rsa_value.n + '\n\ne:\n' + rsa_value.e
                self.metadata['message'] = self.message = message
                self.metadata['private-key'] = rsa_value.d
        except Exception, e:
            print e.message
            exit(1)

register_generator('14.0', RSAWienerExercise)
예제 #7
0
from exercises.registry import register_generator

class OnionExercise(object):
    '''
    Hands-on exercise for creating an onion address
    '''
    def __init__(self, args_dict=None):
        if 'user' not in args_dict:
            print 'User is required for OnionExercise initialization'
            exit(1)

        user = args_dict['user']

        if not user.is_authenticated():
            self.message = '*****@*****.**'
            self.metadata = { }
            return

        # user is authenticated
        self.metadata = {
            'user_email': user.email
        }
        self.message = user.email

register_generator('20.0', OnionExercise)
예제 #8
0
from exercises.registry import register_generator

class PGPExercise(object):
    '''
    Hands-on exercise for PGP signing a file
    '''
    def __init__(self, args_dict=None):
        if 'user' not in args_dict:
            print 'User is required for PGP exercise initialization'
            exit(1)

        user = args_dict['user']

        if not user.is_authenticated():
            self.message = '*****@*****.**'
            self.metadata = { }
            return

        # user is authenticated
        self.metadata = {
            'user_email': user.email
        }
        self.message = user.email

register_generator('20.1', PGPExercise)
예제 #9
0
import random
from .models import RSAValues
from exercises.registry import register_generator


class RSAWienerExercise(object):
    def __init__(self, args_dict=None):
        if len(args_dict) == 1:
            args_dict = {}
        try:
            if 'metadata' in args_dict:
                self.metadata = args_dict['metadata']
                self.message = self.metadata['message']
            else:
                self.metadata = {}
                rsa_value = random.choice(RSAValues.objects.all())

                message = 'n:\n' + rsa_value.n + '\n\ne:\n' + rsa_value.e
                self.metadata['message'] = self.message = message
                self.metadata['private-key'] = rsa_value.d
        except Exception, e:
            print e.message
            exit(1)


register_generator('14.0', RSAWienerExercise)
예제 #10
0
from django.conf import settings
from exercises.registry import register_generator

from .models import HttpsPassword
import random

class HttpsExercise(object):
    '''
    Hands-on exercise for HTTPS traffic decryption
    '''
    def __init__(self, args_dict=None):
        exercise_packet = random.choice(HttpsPassword.objects.all())
        self.metadata = {
            'password': exercise_packet.password
        }
        self.message = '<a href="%s">Download file</a>' % (settings.MEDIA_URL + exercise_packet.filename)

register_generator('18.0', HttpsExercise)