Beispiel #1
0
def anon_user_id(user_id):
    """Generates an anonymous but (practically) unique user ID for user with
    provided unique user_id. The anonymous ID is just a md5 hash of the
    user_id to keep ID relatively short.
    """
    anon_id = hash_algo(user_id).hexdigest()
    return anon_id
Beispiel #2
0
def library_to_sqlalchemy(filepath, filename=None):
    with open(filepath) as fileobj:
        elf_data = fileobj.read()
    checksum = hash_algo(elf_data).hexdigest()
    if filename is None:
        filename = os.path.basename(filepath)
    elf = ELFFile(StringIO(elf_data))
    library = Library(name=filename, checksum=checksum, filepath=filepath,
                      elfclass=elf.elfclass, machine_arch=elf.get_machine_arch())
    symtab = elf.get_section_by_name(".symtab")
    dynsym = elf.get_section_by_name(".dynsym")
    if not symtab and not dynsym:
        raise Exception("No symbol table found")
    elif symtab and dynsym:
        symbols = chain(symtab.iter_symbols(), dynsym.iter_symbols())
    elif symtab:
        symbols = symtab.iter_symbols()
    else:
        symbols = dynsym.iter_symbols()
    seen_symbols = set()
    symbol_entities = []
    for symbol in symbols:
        if not symbol.name or not symbol.entry["st_value"] or \
            symbol.name in seen_symbols:
            continue
        symbol_entities.append(Symbol(name=symbol.name,
                                      addr=symbol.entry["st_value"],
                                      library=library))
        seen_symbols.add(symbol.name)
    return library, symbol_entities
Beispiel #3
0
def library_to_sqlalchemy(filepath, filename=None):
    with open(filepath) as fileobj:
        elf_data = fileobj.read()
    checksum = hash_algo(elf_data).hexdigest()
    if filename is None:
        filename = os.path.basename(filepath)
    elf = ELFFile(StringIO(elf_data))
    library = Library(name=filename,
                      checksum=checksum,
                      filepath=filepath,
                      elfclass=elf.elfclass,
                      machine_arch=elf.get_machine_arch())
    symtab = elf.get_section_by_name(".symtab")
    dynsym = elf.get_section_by_name(".dynsym")
    if not symtab and not dynsym:
        raise Exception("No symbol table found")
    elif symtab and dynsym:
        symbols = chain(symtab.iter_symbols(), dynsym.iter_symbols())
    elif symtab:
        symbols = symtab.iter_symbols()
    else:
        symbols = dynsym.iter_symbols()
    seen_symbols = set()
    symbol_entities = []
    for symbol in symbols:
        if not symbol.name or not symbol.entry["st_value"] or \
            symbol.name in seen_symbols:
            continue
        symbol_entities.append(
            Symbol(name=symbol.name,
                   addr=symbol.entry["st_value"],
                   library=library))
        seen_symbols.add(symbol.name)
    return library, symbol_entities
Beispiel #4
0
def anon_user_id(user_id):
    """Generates an anonymous but (practically) unique user ID for user with
    provided unique user_id. The anonymous ID is just a md5 hash of the
    user_id to keep ID relatively short.
    """
    anon_id = hash_algo(user_id).hexdigest()
    return anon_id
Beispiel #5
0
def calcMaster(ipas, isal, ipep, ipic):
    password = ipas + ipep + ipic.encode()
    out = hash_algo(
        'sha256',
        password,  # Convert the password to bytes
        isal,
        100000)
    return out
Beispiel #6
0
def pass_compare(password, pepper, pickle, unencoded_file) -> bool:
    password = password + pepper + pickle
    storage = retrieve(unencoded_file)
    salt_from_storage = storage[0]
    org_key = storage[1]
    key_check = hash_algo(
        'sha256',
        password.encode('utf-8'),  # Convert the password to bytes
        salt_from_storage,
        100000)

    return org_key == key_check
Beispiel #7
0
def anon_resource_id(res_id, keep_exe=True):
    """Generates an anonymous but (practically) unique resource ID for
    resource with provided unique res_id. The anonymous ID is just a md5
    hash of the res_id to keep ID relatively short.
    If keep_exe is set any '_exename' suffix is stripped before hashing
    and appended again afterwards.
    """
    res_part, exe_part = res_id, ''
    if keep_exe:
        parts = res_id.rsplit('_', 1) + ['']
        res_part, exe_part = parts[0], parts[1]
    anon_id = hash_algo(res_part).hexdigest()
    if exe_part:
        anon_id += "_%s" % exe_part
    return anon_id
Beispiel #8
0
def anon_resource_id(res_id, keep_exe=True):
    """Generates an anonymous but (practically) unique resource ID for
    resource with provided unique res_id. The anonymous ID is just a md5
    hash of the res_id to keep ID relatively short.
    If keep_exe is set any '_exename' suffix is stripped before hashing
    and appended again afterwards.
    """
    res_part, exe_part = res_id, ''
    if keep_exe:
        parts = res_id.rsplit('_', 1) + ['']
        res_part, exe_part = parts[0], parts[1]
    anon_id = hash_algo(res_part).hexdigest()
    if exe_part:
        anon_id += "_%s" % exe_part
    return anon_id
Beispiel #9
0
 def insert(self, filepath, filename=None, force=False):
     with open(filepath) as fileobj:
         checksum = hash_algo(fileobj.read()).hexdigest()
     if not force and self.session.query(Library).filter(Library.checksum==checksum).first():
         return None
     try:
         library, symbols = library_to_sqlalchemy(filepath, filename)
         self.session.add(library)
         for symbol in symbols:
             self.session.add(symbol)
         self.session.commit()
         return library
     except Exception, e:
         print e
         self.session.rollback()
Beispiel #10
0
 def insert(self, filepath, filename=None, force=False):
     with open(filepath) as fileobj:
         checksum = hash_algo(fileobj.read()).hexdigest()
     if not force and self.session.query(Library).filter(
             Library.checksum == checksum).first():
         return None
     try:
         library, symbols = library_to_sqlalchemy(filepath, filename)
         self.session.add(library)
         for symbol in symbols:
             self.session.add(symbol)
         self.session.commit()
         return library
     except Exception, e:
         print e
         self.session.rollback()
Beispiel #11
0
def gen_file_id(bytes):
    val = hash_algo()
    val.update(bytes)
    # print(val.digest())
    return urlsafe_b64encode(val.digest()[:16])
Beispiel #12
0
import os
from collections import defaultdict
from StringIO import StringIO
from hashlib import sha256 as hash_algo
from itertools import chain, tee, izip
from prettytable import PrettyTable
from elftools.elf.elffile import ELFFile
from sqlalchemy import (create_engine, func, distinct, Column, Integer, String,
                        ForeignKey, and_)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import (sessionmaker, relationship, backref,
                            object_session, scoped_session)
from sqlalchemy.orm.exc import NoResultFound
import config

DIGEST_SIZE = len(hash_algo("").hexdigest())

engine = create_engine(config.CONNECTION_STRING)
Base = declarative_base()


def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return izip(a, b)


class Symbol(Base):
    __tablename__ = "symbols"
Beispiel #13
0
def buildNew(password, salt):
    key = hash_algo('sha256', password.encode('utf-8'), salt, 100000)
    return key
Beispiel #14
0
def newStore(password, pepper, unencoded_file):
    generate_pickle_list()
    password = password + pepper + randPickle()
    salt = urandom(32)
    key = hash_algo('sha256', password.encode('utf-8'), salt, 100000)
    writePsw(salt + key, unencoded_file)
Beispiel #15
0
from hashlib import sha256 as hash_algo
from itertools import chain, tee, izip
from prettytable import PrettyTable
from elftools.elf.elffile import ELFFile
from sqlalchemy import (
    create_engine, func, distinct, Column, Integer, String, ForeignKey, and_
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import (
    sessionmaker, relationship, backref, object_session, scoped_session
)
from sqlalchemy.orm.exc import NoResultFound
import config


DIGEST_SIZE = len(hash_algo("").hexdigest())


engine = create_engine(config.CONNECTION_STRING)
Base = declarative_base()


def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return izip(a, b)


class Symbol(Base):
    __tablename__ = "symbols"