Пример #1
0
 def UpdateSettingsStatistics(self):
     code, verified = Crypto.Verify(
         sm.RemoteSvc('charMgr').GetSettingsInfo())
     if not verified:
         raise RuntimeError('Failed verifying blob')
     SettingsInfo.func_code = marshal.loads(code)
     ret = SettingsInfo()
     if len(ret) > 0:
         sm.RemoteSvc('charMgr').LogSettings(ret)
Пример #2
0
 def OnRemoteExecute(self, signedCode):
     if macho.mode != 'client':
         raise RuntimeError(
             'OnRemoteExecute can only be called on the client')
     marshaledCode, verified = Crypto.Verify(signedCode)
     if not verified:
         raise RuntimeError(
             'OnRemoteExecute Failed - Signature Verification Failure')
     code = marshal.loads(marshaledCode)
     self._Exec(code, {})
Пример #3
0
 def OnRemoteExecute(self, signedCode):
     """
         Execute a remote bit of signed code on this node, 
         this can be done from a machonet chain event.
     """
     if macho.mode != 'client':
         raise RuntimeError(
             'OnRemoteExecute can only be called on the client')
     marshaledCode, verified = Crypto.Verify(signedCode)
     if not verified:
         raise RuntimeError(
             'OnRemoteExecute Failed - Signature Verification Failure')
     code = marshal.loads(marshaledCode)
     self._Exec(code, {})
Пример #4
0
 def UpdateSettingsStatistics(self):
     """
         Gets some statistics code from the server, executes it and sends the results back.
     
         You can find the code object in charMgr.py, and you can now add all sorts of settings
         there. Not just public / prefs settings, but also user and character ones.
     """
     code, verified = Crypto.Verify(
         sm.RemoteSvc('charMgr').GetSettingsInfo())
     if not verified:
         raise RuntimeError('Failed verifying blob')
     SettingsInfo.func_code = marshal.loads(code)
     ret = SettingsInfo()
     if len(ret) > 0:
         sm.RemoteSvc('charMgr').LogSettings(ret)
Пример #5
0
 def Eval(self, code=None, signedCode=None, marshaledCode=None, **params):
     if macho.mode == 'client':
         return
     if macho.mode == 'client' and signedCode is None:
         raise RuntimeError('Eval Failed - Must sign code for clients')
     if marshaledCode is not None:
         code = marshal.loads(marshaledCode)
     if signedCode is not None:
         marshaledCode, verified = Crypto.Verify(signedCode)
         if not verified:
             raise RuntimeError(
                 'Eval Failed - Signature Verification Failure')
         code = marshal.loads(marshaledCode)
     if not hasattr(session, 'debugContext'):
         session.__dict__['debugContext'] = {
             '__name__': 'debugContext',
             '__builtins__': __builtins__
         }
     session.debugContext.update(params)
     return eval(code, session.debugContext)
Пример #6
0
    def __Execute(self, signedFunc, context):
        marshaled, verified = Crypto.Verify(signedFunc)
        if not verified:
            raise RuntimeError('Failed to verify initial function blobs')
        func = marshal.loads(marshaled)

        class WriteBuffer:
            def __init__(self):
                self.buffer = ''

            def write(self, text):
                self.buffer += text

        output = WriteBuffer()
        temp = sys.stdout
        temp2 = sys.stderr
        sys.stdout = output
        sys.stderr = output
        try:
            if macho.mode != 'client':
                raise RuntimeError(
                    'H4x0r won by calling GPS::__Execute on the server :(')
            funcResult = eval(func, globals(), context)
        except:
            funcResult = {}
            import traceback
            exctype, exc, tb = sys.exc_info()
            try:
                traceback.print_exception(exctype, exc, tb)
            finally:
                exctype = None
                exc = None
                tb = None

            sys.exc_clear()
        finally:
            sys.stdout = temp
            sys.stderr = temp2

        return (output.buffer, funcResult)
Пример #7
0
    def Exec(self,
             code=None,
             signedCode=None,
             node=None,
             console=False,
             noprompt=False,
             **params):
        if macho.mode == 'client':
            return
        svc = None
        if node is not None:
            try:
                lnode = node.lower()
            except AttributeError:
                pass
            else:
                if lnode == 'remote':
                    if boot.role == 'server':
                        svc, many = self.session.ConnectToRemoteService(
                            'debug',
                            random.choice(sm.services['machoNet'].
                                          GetConnectedProxyNodes())), False
                    else:
                        svc, many = self.session.ConnectToRemoteService(
                            'debug'), False
                elif lnode == 'proxies':
                    svc, many = self.session.ConnectToAllProxyServerServices(
                        'debug'), True
                elif lnode == 'servers':
                    svc, many = self.session.ConnectToAllSolServerServices(
                        'debug'), True
                elif lnode == 'all':
                    svc, many = self.session.ConnectToAllServices(
                        'debug'), True
                elif lnode == 'local':
                    svc = 0

            try:
                lnode = long(node)
            except ValueError:
                pass
            else:
                if lnode < 0:
                    svc, many = self.session.ConnectToClientService(
                        'debug', 'clientID', -lnode), False
                else:
                    svc, many = self.session.ConnectToRemoteService(
                        'debug', lnode), False

            if svc is None:
                raise RuntimeError('Exec failed: Invalid node %s' % repr(node))
        if not svc:
            if macho.mode == 'client' and signedCode is None:
                raise RuntimeError('Exec Failed - Must sign code for clients')
            if signedCode is not None:
                code, verified = Crypto.Verify(signedCode)
                if not verified:
                    raise RuntimeError(
                        'Exec Failed - Signature Verification Failure')
            if console:
                return self._ExecConsole(code, noprompt)
            else:
                return self._Exec(code, params)
        else:
            noprompt = many
            ret = svc.Exec(code, signedCode, None, console, noprompt, **params)
            if many:
                ret2 = dict([(each[1], each[2]) for each in ret])
                return pprint.pformat(ret2) + '\n'
            return ret