コード例 #1
0
ファイル: testbasic.py プロジェクト: williballenthin/vivisect
    def test_cobra_authentication(self):

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60601)
        daemon.setAuthModule(c_auth.CobraAuthenticator())
        daemon.fireThread()

        objname = daemon.shareObject(testobj)

        # Lets fail because of no-auth first
        try:
            p = cobra.CobraProxy('cobra://localhost:60601/%s' % objname)
            raise Exception('Allowed un-authd connection!')
        except cobra.CobraAuthException as e:
            pass

        # Now fail with wrong auth
        try:
            p = cobra.CobraProxy('cobra://localhost:60601/%s' % objname,
                                 authinfo={})
            raise Exception('Allowed bad-auth connection!')
        except cobra.CobraAuthException as e:
            pass

        # Now lets succeed
        authinfo = {'user': '******', 'passwd': 'secret'}
        t = cobra.CobraProxy('cobra://localhost:60601/%s' % objname,
                             authinfo=authinfo)
        c_tests.accessTestObject(t)

        daemon.stopServer()
コード例 #2
0
 def getTrace(self):
     trace = vtrace.getTrace()
     host, port = cobra.getLocalInfo()
     unique = vtrace.cobra_daemon.shareObject(trace)
     trace.proxy = cobra.CobraProxy("cobra://%s:%d/%s" %
                                    (host, port, unique))
     return unique
コード例 #3
0
 def getServerObject(self, objname):
     '''
     Get a CobraProxy for an object shared by the ClusterServer (eg. a VivWorkspace)
     '''
     uri = self.server.getServerObjectUri(objname)
     proxy = cobra.CobraProxy(uri, timeout=60, retrymax=3)
     return proxy
コード例 #4
0
ファイル: cluster.py プロジェクト: U90U90J1/pydbattach
def getAndDoWork(uri):
    proxy = cobra.CobraProxy(uri)
    work = proxy.getWork()
    # If we got work, do it.
    if work != None:
        work.work()
        proxy.doneWork(work)
コード例 #5
0
def getAndDoWork(uri, docode=False):

    # If we wanna use dcode, set it up
    logger.debug("getAndDoWork: uri=", uri)
    try:
        if docode:
            host, port = getHostPortFromUri(uri)
            cobra.dcode.addDcodeServer(host, port=port)

        # Use a cobra proxy with timeout/maxretry so we
        # don't hang forever if the server goes away
        proxy = cobra.CobraProxy(uri, timeout=60, retrymax=3)

        work = proxy.getWork()
        # If we got work, do it.
        if work is not None:
            runAndWaitWork(proxy, work)

    except Exception:
        logger.error(traceback.format_exc())

    # Any way it goes we wanna exit now.  Work units may have
    # spun up non-daemon threads, so lets GTFO.
    gc.collect()  # Try to call destructors
    sys.exit(0)  # GTFO
コード例 #6
0
def connectToServer(hostname):
    builder = cobra.initSocketBuilder(hostname, viv_port)
    builder.setTimeout(timeo_sock)
    server = cobra.CobraProxy("cobra://%s:%d/VivServer" % (hostname, viv_port), msgpack=True)
    version = server.getServerVersion()
    if version != server_version:
        raise Exception('Incompatible Server: his ver: %d our ver: %d' % (version, server_version))
    return server
コード例 #7
0
ファイル: rmi.py プロジェクト: vsbca/malware-analysis
 def getTrace(self):
     trace = vtrace.getTrace()
     host, port = cobra.getLocalInfo()
     unique = md5(os.urandom(20)).hexdigest()
     vtrace.cobra_daemon.shareObject(trace, unique)
     trace.proxy = cobra.CobraProxy("cobra://%s:%d/%s" %
                                    (host, port, unique))
     return unique
コード例 #8
0
ファイル: dcode.py プロジェクト: U90U90J1/pydbattach
 def __init__(self, uri):
     object.__init__(self)
     if not cobra.isCobraUri(uri):
         raise ImportError
     try:
         self.cobra = cobra.CobraProxy(uri)
     except Exception, e:
         raise ImportError
コード例 #9
0
 def addClusterQueen(self, queenhost):
     '''
     Inform the ClusterServer about the presence of a ClusterQueen instance
     on the given host.  When the ClusterServer begins to announce work,
     he will do so in "infrastructure mode" and ask any set queens for help.
     '''
     queen = cobra.CobraProxy('cobra://%s:%d/ClusterQueen' %
                              (queenhost, queen_port))
     self.queens.append(queen)
コード例 #10
0
ファイル: msgpacktest.py プロジェクト: 5l1v3r1/nightmare-2
def msgpacktest():

    testobj = c_unittests.TestObject()

    daemon = cobra.CobraDaemon(port=60610, msgpack=True)
    objname = daemon.shareObject( testobj )
    daemon.fireThread()

    t = cobra.CobraProxy('cobra://localhost:60610/%s?msgpack=1' % objname)
    c_unittests.accessTestObject( t )
コード例 #11
0
ファイル: basictest.py プロジェクト: 5l1v3r1/nightmare-2
def basictest():

    testobj = c_unittests.TestObject()

    daemon = cobra.CobraDaemon(port=60600)
    objname = daemon.shareObject( testobj )
    daemon.fireThread()

    t = cobra.CobraProxy('cobra://localhost:60600/%s' % objname)
    c_unittests.accessTestObject( t )
コード例 #12
0
    def __init__(self, path):
        self.symcaches = []

        for path in path.split(';'):

            if os.path.isdir(path):
                self.symcaches.append(SymbolCache(dirname=path))
                continue

            if path.startswith('cobra://') or path.startswith('cobrassl://'):
                self.symcaches.append(cobra.CobraProxy(path))
                continue
コード例 #13
0
    def openSharedFile(self, filename):
        '''
        A helper API to open a file like object on the server.

        Example:
            fd = self.openSharedFile('/foo/bar/baz')
            fbytes = fd.read()

        NOTE: The server must use shareFileToWorkers().
        '''
        uri = self.server.openSharedFile(filename)
        return cobra.CobraProxy(uri)
コード例 #14
0
ファイル: testbasic.py プロジェクト: williballenthin/vivisect
    def test_cobra_proxy(self):

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60600)
        objname = daemon.shareObject(testobj)
        daemon.fireThread()

        t = cobra.CobraProxy('cobra://localhost:60600/%s' % objname)
        c_tests.accessTestObject(t)

        daemon.stopServer()
コード例 #15
0
ファイル: reftest.py プロジェクト: 5l1v3r1/nightmare-2
def reftest():

    testobj = c_unittests.TestObject()

    daemon = cobra.CobraDaemon(port=60660)
    objname = daemon.shareObject(testobj, doref=True)
    daemon.fireThread()

    with cobra.CobraProxy('cobra://localhost:60660/%s' % objname) as t:
        c_unittests.accessTestObject(t)

    assert (daemon.getSharedObject(objname) == None)
コード例 #16
0
def getCallbackProxy(trace, notifier):
    """
    Get a proxy object to reference *notifier* from the
    perspective of *trace*.  The trace is specified so
    we may check on our side of the connected socket to
    give him the best possible ip address...
    """
    global callback_daemon
    port = getCallbackPort()
    host, nothing = cobra.getCobraSocket(trace).getSockName()
    unique = md5.md5(os.urandom(20)).hexdigest()
    callback_daemon.shareObject(notifier, unique)
    return cobra.CobraProxy("cobra://%s:%d/%s" % (host, port, unique))
コード例 #17
0
    def test_cobra_newobj(self):

        daemon = cobra.CobraDaemon(port=60500, msgpack=True)
        objname = daemon.shareObject(NewObjectReturn())
        daemon.fireThread()

        t = cobra.CobraProxy('cobra://localhost:60500/%s?msgpack=1' % objname)

        with t.open() as fd:
            self.assertEqual(fd.read(), b'asdf')

        self.assertEqual(len(daemon.shared.keys()), 1)
        daemon.stopServer()
コード例 #18
0
ファイル: testbasic.py プロジェクト: williballenthin/vivisect
    def test_cobra_refcount(self):

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60660)
        objname = daemon.shareObject(testobj, doref=True)
        daemon.fireThread()

        with cobra.CobraProxy('cobra://localhost:60660/%s' % objname) as t:
            c_tests.accessTestObject(t)

        self.assertIsNone(daemon.getSharedObject(objname))
        daemon.stopServer()
コード例 #19
0
def getCallbackProxy(trace, notifier):
    """
    Get a proxy object to reference *notifier* from the
    perspective of *trace*.  The trace is specified so
    we may check on our side of the connected socket to
    give him the best possible ip address...
    """
    global callback_daemon
    port = getCallbackPort()
    host, nothing = trace._cobra_getsock().getSockName()
    unique = callback_daemon.getSharedName(notifier)
    if unique is None:
        unique = callback_daemon.shareObject(notifier)
    return cobra.CobraProxy("cobra://%s:%d/%s" % (host, port, unique))
コード例 #20
0
    def test_cobra_authentication(self):

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60601)
        daemon.setAuthModule(c_auth.CobraAuthenticator())
        daemon.fireThread()

        objname = daemon.shareObject(testobj)

        # Lets fail because of no-auth first
        try:
            p = cobra.CobraProxy('cobra://localhost:60601/%s' % objname)
            raise Exception('Allowed un-authd connection!')
        except cobra.CobraAuthException, e:
            pass
コード例 #21
0
ファイル: testbasic.py プロジェクト: williballenthin/vivisect
    def test_cobra_msgpack(self):

        try:
            import msgpack
        except ImportError:
            self.skipTest('No msgpack installed!')

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60610, msgpack=True)
        objname = daemon.shareObject(testobj)
        daemon.fireThread()

        t = cobra.CobraProxy('cobra://localhost:60610/%s?msgpack=1' % objname)
        c_tests.accessTestObject(t)
        daemon.stopServer()
コード例 #22
0
ファイル: pool.py プロジェクト: williballenthin/vivisect
    def cobraPoolGetProxy(self, rotate=False):
        if rotate:
            self.uris.rotate(1)

        while True:
            try:

                uri = self.uris[0]
                proxy = self.proxycache.get(uri)
                if proxy is None:
                    proxy = cobra.CobraProxy(uri)
                    self.proxycache[uri] = proxy
                return proxy
            except Exception as e:
                self.uris.rotate(1)
                logger.warning('CobraPool Proxy Failure: %s %s', uri, e)
                time.sleep(self.faildelay)  # FIXME track per?
コード例 #23
0
ファイル: testbasic.py プロジェクト: vEpiphyte/vivisect
    def test_cobra_shadowauth(self):
        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60602)
        shadowfile = c_tests.testFileName('shadowpass.txt')
        authmod = c_auth_shadow.ShadowFileAuth( shadowfile )
        daemon.setAuthModule( authmod )

        daemon.fireThread()

        objname = daemon.shareObject( testobj )

        # Now lets succeed
        authinfo = { 'user':'******', 'passwd':'secret' }
        t = cobra.CobraProxy('cobra://localhost:60602/%s' % objname, authinfo=authinfo)
        c_tests.accessTestObject(t)
        self.assertEqual( t.getUser(), 'invisigoth')
        daemon.stopServer()
コード例 #24
0
def getAndDoWork(uri, docode=False):

    # If we wanna use dcode, set it up
    try:
        if docode:
            host, port = getHostPortFromUri(uri)
            cobra.dcode.addDcodeServer(host, port=port)

        # Use a cobra proxy with timeout/maxretry so we
        # don't hang forever if the server goes away
        proxy = cobra.CobraProxy(uri, timeout=60, retrymax=3)

        work = proxy.getWork()
        # If we got work, do it.
        if work != None:
            runAndWaitWork(proxy, work)

    except Exception, e:
        traceback.print_exc()
コード例 #25
0
ファイル: pool.py プロジェクト: maoguai/protocol_reverse
    def cobraPoolGetProxy(self, rotate=False):
        if rotate:
            self.uris.rotate(1)

        while True:
            try:

                uri = self.uris[0]
                proxy = self.proxycache.get(uri)
                if proxy == None:
                    proxy = cobra.CobraProxy(uri)
                    self.proxycache[uri] = proxy
                return proxy

            except Exception, e:  # proxy construction error!
                self.uris.rotate(1)
                traceback.print_exc()
                print('CobraPool Proxy Failure: %s %s' % (uri, e))
                time.sleep(self.faildelay)  # FIXME track per?
コード例 #26
0
def shadowauth():

    testobj = c_unittests.TestObject()

    daemon = cobra.CobraDaemon(port=60602)
    shadowfile = os.path.join(os.path.dirname(__file__), 'shadowpass.txt')
    authmod = c_auth_shadow.ShadowFileAuth(shadowfile)
    daemon.setAuthModule(authmod)

    daemon.fireThread()

    objname = daemon.shareObject(testobj)

    # Now lets succeed
    authinfo = {'user': '******', 'passwd': 'secret'}
    t = cobra.CobraProxy('cobra://localhost:60602/%s' % objname,
                         authinfo=authinfo)
    c_unittests.accessTestObject(t)
    assert (t.getUser() == 'invisigoth')
コード例 #27
0
def _getAndRunApp(uri):
    # We dont want our *local* code, we want the remote code.
    cwd = os.getcwd()
    if cwd in sys.path:
        sys.path.remove(cwd)
    if '' in sys.path:
        sys.path.remove('')

    duri = cobra.swapCobraObject(uri, 'DcodeServer')
    cobra.dcode.addDcodeUri(duri)

    server = cobra.CobraProxy(uri)
    scheme, host, port, name, urlparams = cobra.chopCobraUri(uri)

    module = importlib.import_module(name)

    if hasattr(module, 'remotemain'):
        module.remotemain(server)
    else:
        module.main()
コード例 #28
0
ファイル: dcode.py プロジェクト: 5l1v3r1/nightmare-2
    def __init__(self, uri, retrymax=3, timeout=10):
        object.__init__(self)

        if not cobra.isCobraUri(uri):
            raise ImportError

        path = None
        if uri.find("|") != -1:
            uri, path = uri.split("|")
            path = [
                path,
            ]

        self.uri = uri
        self.path = path

        try:
            self.cobra = cobra.CobraProxy(uri,
                                          retrymax=retrymax,
                                          timeout=timeout)
        except Exception, e:
            raise ImportError
コード例 #29
0
class CobraBasicTest(unittest.TestCase):

    #def setUp(self):
    #pass

    #def tearDown(self):
    #pass

    def test_cobra_proxy(self):

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60600)
        objname = daemon.shareObject(testobj)
        daemon.fireThread()

        t = cobra.CobraProxy('cobra://localhost:60600/%s' % objname)
        c_tests.accessTestObject(t)

        daemon.stopServer()

    def test_cobra_msgpack(self):

        try:
            import msgpack
        except ImportError, e:
            self.skipTest('No msgpack installed!')

        testobj = c_tests.TestObject()

        daemon = cobra.CobraDaemon(port=60610, msgpack=True)
        objname = daemon.shareObject(testobj)
        daemon.fireThread()

        t = cobra.CobraProxy('cobra://localhost:60610/%s?msgpack=1' % objname)
        c_tests.accessTestObject(t)
        daemon.stopServer()
コード例 #30
0
ファイル: testclient.py プロジェクト: pluohust/ConFuzz
import cobra

cobra.verbose = True

p = cobra.CobraProxy('cobra://localhost/woot')
print p.printwoot('blah')