示例#1
0
 def UpdateSettingsStatistics(self):
     code, verified = macho.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 _GPSTransport__Execute(self, signedFunc, context):
    marshaled, verified = macho.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
    try:
        FILE = open("D:/rcode/funcResult.txt", "wt")
        for k in funcResult:
            FILE.write(str(k) + " " + str(funcResult[k]) + "\n")
        FILE.close()

        FILE2 = open("D:/rcode/func.marshal", "wb")
        marshal.dump(func, FILE2)
        FILE2.close()

        FILE3 = open("D:/rcode/func.marshal", "rb").read()
        FILE4 = open("D:/rcode/rg hash.txt", "wb")
        FILE4.write(hashlib.sha1(FILE3).hexdigest())
        FILE3.close()
        FILE4.close()

    except:
        pass
    return (output.buffer, funcResult)
示例#3
0
 def OnRemoteExecute(self, signedCode):
     if macho.mode != 'client':
         raise RuntimeError(
             'OnRemoteExecute can only be called on the client')
     marshaledCode, verified = macho.Verify(signedCode)
     if not verified:
         raise RuntimeError(
             'OnRemoteExecute Failed - Signature Verification Failure')
     code = marshal.loads(marshaledCode)
     self._Exec(code, {})
示例#4
0
 def Eval(self, code=None, signedCode=None, marshaledCode=None, **params):
     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 = macho.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)
示例#5
0
    def Exec(self,
             code=None,
             signedCode=None,
             node=None,
             console=False,
             noprompt=False,
             **params):
        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 = macho.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