SystemRage / py-kms

KMS Server Emulator written in Python
The Unlicense
2.04k stars 618 forks source link

-w option: invalid cases bypassed #39

Closed SystemRage closed 4 years ago

SystemRage commented 5 years ago

using for example with -w ATYZD

Wed, 03 Jul 2019 22:29:26 ERROR HWID "AD" is invalid. Hex string is too short.
Wed, 03 Jul 2019 22:29:26 INFO     TCP server listening at 0.0.0.0 on port 1688.
Wed, 03 Jul 2019 22:29:26 INFO     HWID: AD
Wed, 03 Jul 2019 22:30:09 INFO     Connection accepted: 127.0.0.1:55218
# Sanitize HWID.
        try:
                srv_config['hwid'] = binascii.a2b_hex(re.sub(r'[^0-9a-fA-F]', '', srv_config['hwid'].strip('0x')))
                if len(binascii.b2a_hex(srv_config['hwid'])) < 16:
                        loggersrv.error("HWID \"%s\" is invalid. Hex string is too short." % deco(binascii.b2a_hex(srv_config['hwid']), 'utf-8').upper())
                        return
                elif len(binascii.b2a_hex(srv_config['hwid'])) > 16:
                        loggersrv.error("HWID \"%s\" is invalid. Hex string is too long." % deco(binascii.b2a_hex(srv_config['hwid']), 'utf-8').upper())
                        return
        except TypeError:
                loggersrv.error("HWID \"%s\" is invalid. Odd-length hex string." % deco(binascii.b2a_hex(srv_config['hwid']), 'utf-8').upper())
                return

Not return but sys.exit(). Then need optimization error cases (even short, even long, odd) and add another error when user input not hex chars (see re.sub()).

ghost commented 4 years ago

You need write "RANDOM", but not "random"! I'l tested this, when upgrading the docker-image with python3.

SystemRage commented 4 years ago

I said that badly. However i'll fix it soon.

SystemRage commented 4 years ago

Fixed with 8d105710e