Exemplo n.º 1
0
def generate_machine_id_bytes() -> bytes:
    random_hex_string = choices(
        population=hexdigits.lower(),
        k=32,
    )

    return b''.join((x.encode() for x in random_hex_string))
Exemplo n.º 2
0
def index(argv: typing.List[str], args: argparse.Namespace):
    """
    Queue an SQS message to the indexer lambda for each key in object storage beginning with `bundles/{prefix}`.
    If `prefix` is omitted, send a message for each key in object storage beginning with `bundles/`
    """
    replica = Replica[args.replica]
    handle = Config.get_blobstore_handle(replica)
    index_queue_url = get_queue_url("dss-index-operation-" +
                                    os.environ['DSS_DEPLOYMENT_STAGE'])

    if "on-change" == args.send_notifications:
        send_notifications = None
    else:
        send_notifications = ("true" == args.send_notifications)

    def _forward_keys(pfx):
        with SQSMessenger(index_queue_url) as sqsm:
            for key in handle.list(replica.bucket, pfx):
                msg = dict(replica=replica.name, key=key)
                if send_notifications is not None:
                    msg['send_notifications'] = send_notifications
                sqsm.send(json.dumps(msg))

    with ThreadPoolExecutor(max_workers=10) as e:
        futures = [
            e.submit(_forward_keys, f"bundles/{args.prefix}{c}")
            for c in set(hexdigits.lower())
        ]
        for f in as_completed(futures):
            f.result()
Exemplo n.º 3
0
def is_valid_passport_strict(passport: Dict[str, str]) -> bool:
    rules = {
        "byr":
        lambda x: 1920 <= int(x) <= 2002,
        "iyr":
        lambda x: 2010 <= int(x) <= 2020,
        "eyr":
        lambda x: 2020 <= int(x) <= 2030,
        "hgt":
        lambda x: {
            "cm": lambda cm: 150 <= cm <= 193,
            "in": lambda inch: 59 <= inch <= 76,
        }[x[-2:]](int(x[:-2])),
        "hcl":
        lambda x: len(x) == 7 and x[0] == "#" and all(
            digit in hexdigits.lower() for digit in x[1:]),
        "ecl":
        lambda x: x in ("amb", "blu", "brn", "gry", "grn", "hzl", "oth"),
        "pid":
        lambda x: len(x) == 9 and all(digit in decdigits for digit in x),
    }
    try:
        return all(rule(passport[field]) for field, rule in rules.items())
    except KeyError:
        return False
Exemplo n.º 4
0
def record(argv: typing.List[str], args: argparse.Namespace):
    """
    Record events for `keys` into flashflood prefix `prefix`
    If `keys` is omitted, record an event for each bundle in `replica` via lambda forwarding.
    """
    replica = Replica[args.replica]
    job_id = args.job_id or f"{uuid4()}"
    cmd_template = (f"events record --job-id {job_id} "
                    f"--prefix {args.prefix} "
                    f"--replica {replica.name} "
                    f"--keys {{keys}}")

    if args.keys is None:
        start_time = datetime.now()

        def forward_keys(bundle_fqids):
            with SQSMessenger(command_queue_url) as sqsm:
                for fqid in bundle_fqids:
                    sqsm.send(cmd_template.format(keys=f"bundles/{fqid}"))

        handle = Config.get_blobstore_handle(replica)
        with ThreadPoolExecutor(max_workers=4) as e:
            for c in set(hexdigits.lower()):
                bundle_fqids = Living(handle.list_v2(replica.bucket, f"bundles/{c}"))
                e.submit(forward_keys, bundle_fqids)
        monitor_logs(logs, job_id, start_time)
    else:
        for key in args.keys:
            msg = json.dumps(dict(action="record event", job_id=job_id, replica=replica.name, key=key))
            record_event_for_bundle(Replica[args.replica], key, (args.prefix,), use_version_for_timestamp=True)
            print(msg)
Exemplo n.º 5
0
	def uniqid(self, prefix = '', more_entropy = False):
		from time import time
		m = time()
		from math import floor
		myuniqid = '%8x%05x' % (floor(m), (m - floor(m))*1000000)
		from string import hexdigits
		if more_entropy:
			valid_chars = list(set(hexdigits.lower()))
			entropy_string = ''
			for i in range(0,10,1):
				from random import choice
				entropy_string += choice(valid_chars)
			myuniqid = myuniqid + entropy_string
		myuniqid = prefix + myuniqid
		return myuniqid
Exemplo n.º 6
0
 def run(self, src, end, base):
     s = self.state
     logger.info("Made it to strtoul sim.")
     logger.info("Params:\nsrc=%s\nend=%s\nbase=%s\n", src, end, base)
     try:
         all_bytes = [s.memory.load(src + i, 1) for i in range(8)]
         total = claripy.BVV(0, 8 * 4)
         for i, b in enumerate(reversed(all_bytes)):
             logger.info("On byte: %s", b)
             f = partial(self.if_builder, b)
             out = reduce(f, hexdigits.lower(), claripy.BVV(0, 8 * 4))
             total += (16 * i) + out
     except Exception as e:
         logger.error(e)
         exit(0)
     return total
Exemplo n.º 7
0
def random_ip(v):

    if v == 4:
        octets = []
        for x in xrange(4):
            octets.append(unicode(randint(0, 255)))
        return u'.'.join(octets)

    elif v == 6:
        octets = []
        for x in xrange(8):
            octet = []
            for x in xrange(4):
                octet.append(unicode(choice(hexdigits.lower())))
            octets.append(u''.join(octet))
        return u':'.join(octets)

    else:
        return
Exemplo n.º 8
0
 def build_character_set(self):
     '''Assemble the list of acceptable characters for password generation.
     '''
     if self.hexadecimal:
         # If hexadecimal output enabled, return early.
         # Use *only* hex in character set.
         # Do some manipulations here to remove lowercase `a-f`
         if self.upper:
             hexcase = hexdigits.upper()
         else:
             hexcase = hexdigits.lower()
         self.char_set += ''.join(list(set(hexcase)))
         return
     if self.alpha:
         self.char_set += ascii_lowercase
     if self.upper:
         self.char_set += ascii_uppercase
     if self.numerals:
         self.char_set += digits
     if self.special:
         self.char_set += punctuation
Exemplo n.º 9
0
    def run(self, dst, fmt, arg1):
        s = self.state
        fmt = s.mem[fmt].string.concrete
        logger.info("Made it to sprintf sim.\n->dst=%s\n->fmt=%s", dst, fmt)
        logger.debug("arg=%s", arg1)
        if fmt != "%lx":
            logger.error("Injected the wrong sprintf")
            return 0

        for in_idx, b in enumerate(map(arg1.get_byte, xrange(4))):
            out_idx = 2 * in_idx
            for i in range(7, 0, -4):
                nibble = b[i:i - 3]
                logger.debug("nibble: %s", nibble)
                f = partial(self.if_builder, nibble)
                out = reduce(f, hexdigits.lower(), claripy.BVV(0, 8))
                # logger.debug("result: %s",chr(seval(s,out)))
                logger.debug("stored at: %s", out_idx)
                s.memory.store(dst + out_idx, out)
                out_idx += 1
        return 8
Exemplo n.º 10
0
Arquivo: util.py Projeto: mmgen/mmgen
def is_hex_str_lc(s): return set(list(s))         <= set(list(hexdigits.lower()))
def is_hex_str_uc(s): return set(list(s))         <= set(list(hexdigits.upper()))
Exemplo n.º 11
0
def is_hex_str_lc(s):
    return set(list(s)) <= set(list(hexdigits.lower()))
Exemplo n.º 12
0
def make_id(length):
    string = "".join([random.choice(hexdigits.lower()) for _ in range(length)])
    return string
Exemplo n.º 13
0
def is_hexstring_lc(s):
	return _is_whatstring(s,hexdigits.lower())
Exemplo n.º 14
0
# limitations under the License.
##
"""
Docker Hub API v2 Digest
"""

from enum import Enum, auto, unique
from string import hexdigits as upperCaseHexDigits
from typing import Sequence

from attr import attrs

__all__ = ()

# Docker Hub produces lowercase hex digits
lowerCaseHexDigits = upperCaseHexDigits.lower()
hexDigits = "".join(frozenset(lowerCaseHexDigits + upperCaseHexDigits))

asHex = hex


class AutoName(str, Enum):
    @staticmethod
    def _generate_next_value_(name: str, start: int, count: int,
                              last_values: Sequence[str]) -> str:
        return name


@unique
class DigestAlgorithm(AutoName):
    """
Exemplo n.º 15
0
#!/usr/local/bin/python3
from string import hexdigits

PASSPORT_FILE = 'input.txt'

FIELDS = {
    'byr': lambda y: 1920 <= int(y) <= 2002,
    'iyr': lambda y: 2010 <= int(y) <= 2020,
    'eyr': lambda y: 2020 <= int(y) <= 2030,
    'hgt': lambda h: h[-2:] == 'cm' and 150 <= int(h[:-2]) <= 193 or h[-2:] == 'in' and 59 <= int(h[:-2]) <= 76,
    'hcl': lambda h: h.startswith('#') and all(c in hexdigits.lower() for c in h[1:]),
    'ecl': lambda e: e in 'amb blu brn gry grn hzl oth'.split(),
    'pid': lambda p: len(p) == 9 and all(c.isdigit() for c in p)
}


def parse_passport(raw_passport):
    fields = raw_passport.rstrip().replace('\n', ' ').split(' ')
    return dict([f.split(':') for f in fields])


def is_valid_field(passport, field):
    return field in passport and FIELDS[field](passport[field])


def is_valid_passport(passport):
    return all(is_valid_field(passport, f) for f in FIELDS)


if __name__ == '__main__':
    with open(PASSPORT_FILE) as f:
Exemplo n.º 16
0
def __height_validator(value):
    """ Validates a height value. Centimeter values must end in 'cm' and be in the range 150-193,
    inch values must end in 'in', and be in the range 58-76. Any other value is invalid. """

    if value.endswith('cm'):
        height = int(value[:-2])
        return height in range(150, 194)

    if value.endswith('in'):
        height = int(value[:-2])
        return height in range(59, 77)

    return False


__VALID_HEX_DIGITS_LOWER = set(hexdigits.lower())


def __validate_hair_color(value):
    """ Validates a hair color. It must be a hexadecimal value, starting with '#', and containing
    6 lowercase hexadecimal characters. """

    if not value.startswith('#'):
        return False

    color = value[1:]
    if len(color) != 6:
        return False

    for char in color:
        if not char in __VALID_HEX_DIGITS_LOWER:
Exemplo n.º 17
0
def force_range(iter, allowed=hexdigits.lower()):
    #This function yeilds constraints that ensure
    #	members of iter are in the range of allowed chrs
    for x in iter:
        yield claripy.Or(*[x == y for y in allowed])