cleverness (mostly) confirmed. exploiting bugs in cmd.exe for fun and pretty printing ftw i guess?

This commit is contained in:
brent s 2017-11-17 15:09:03 -05:00
parent 7598e2bf6f
commit b2109646f3
1 changed files with 24 additions and 36 deletions

View File

@ -18,36 +18,22 @@ except ImportError:
class color(object): class color(object):
# Windows doesn't support ANSI color escapes like sh does. # Windows doesn't support ANSI color escapes like sh does.
if sys.platform == 'win32': if sys.platform == 'win32':
# "You should be using subprocess!" yeah yeah yeah, I know, shut up. # Gorram it, Windows.
# I already have OS imported and this is a quick hack. # https://bugs.python.org/issue29059
BLACK = os.system('color 0') # https://bugs.python.org/issue30075
BLUE = os.system('color 1') # https://github.com/Microsoft/WSL/issues/1173
GREEN = os.system('color 2') import subprocess
DARKCYAN = os.system('color 3') # "Aqua" text subprocess.call('', shell=True)
RED = os.system('color 4') PURPLE = '\033[95m'
PURPLE = os.system('color 5') CYAN = '\033[96m'
YELLOW = os.system('color 6') DARKCYAN = '\033[36m'
END = os.system('color 7') # "White" text BLUE = '\033[94m'
GRAY = os.system('color 8') GREEN = '\033[92m'
CYAN = os.system('color 9') # "Light Blue" text YELLOW = '\033[93m'
LTGREEN = os.system('color A') # "Light Green" text RED = '\033[91m'
LTAQUA = os.system('color B') # "Light Aqua" text BOLD = '\033[1m'
LTRED = os.system('color C') # "Light Red" text UNDERLINE = '\033[4m'
LTPURPLE = os.system('color D') # "Light Purple" text END = '\033[0m'
LTYELLOW = os.system('color E') # "Light Yellow" text
BOLD = os.system('color F') # "Bright White" text
UNDERLINE = None
else:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'


class Hasher(object): class Hasher(object):
def __init__(self, args): def __init__(self, args):
@ -200,10 +186,8 @@ def parseArgs():
if sys.platform == 'darwin': if sys.platform == 'darwin':
_cfgpath = 'PLIST:~/Library/Preferences/net.sourceforge.mumble.Mumble.plist' _cfgpath = 'PLIST:~/Library/Preferences/net.sourceforge.mumble.Mumble.plist'
# ALL versions of windows, even Win10, on x86. Even 64-bit. I know. # ALL versions of windows, even Win10, on x86. Even 64-bit. I know.
elif sys.platform == 'win32': # And Cygwin, which currently doesn't even suppport registry reading (see blobGetter()).
_cfgpath = r'REG:HKEY_CURRENT_USER\Software\Mumble\Mumble\net\certificate' elif sys.platform in ('win32', 'cygwin'):
# Some people are sensible.
if sys.platform == 'cygwin':
_cfgpath = r'REG:HKEY_CURRENT_USER\Software\Mumble\Mumble\net\certificate' _cfgpath = r'REG:HKEY_CURRENT_USER\Software\Mumble\Mumble\net\certificate'
elif (sys.platform == 'linux') or (re.match('.*bsd.*', sys.platform)): # duh elif (sys.platform == 'linux') or (re.match('.*bsd.*', sys.platform)): # duh
_cfgpath = 'INI:~/.config/Mumble/Mumble.conf' _cfgpath = 'INI:~/.config/Mumble/Mumble.conf'
@ -240,6 +224,9 @@ def parseArgs():
'{0}INI{1}'.format(color.BOLD, color.END), '{0}INI{1}'.format(color.BOLD, color.END),
'{0}REG{1}'.format(color.BOLD, color.END), '{0}REG{1}'.format(color.BOLD, color.END),
'{0}{1}{2}'.format(color.BOLD, _defcrt, color.END))) '{0}{1}{2}'.format(color.BOLD, _defcrt, color.END)))
# this ^ currently prints "0m" at the end of the help message,
# all the way on the left on Windows.
# Why? Who knows; Microsoft is a mystery even to themselves.
return(args) return(args)


def main(): def main():
@ -247,8 +234,9 @@ def main():
cert = Hasher(args) cert = Hasher(args)
cert.importCert() cert.importCert()
h = cert.hashCert() h = cert.hashCert()
print('\n\t\033[1mYour certificate\'s public hash is: \033[94m{0}\033[0m'.format(h)) print(('\n\t{0}Your certificate\'s public hash is: ' +
print('\n\t\033[1mPlease provide this to the Mumble server administrator that has requested it.\033[0m\n') '{1}{2}{3}\n\n\t{0}Please provide this to the Mumble server administrator ' +
'that has requested it.{3}').format(color.BOLD, color.BLUE, h, color.END))


if __name__ == '__main__': if __name__ == '__main__':
main() main()