Exemplo n.º 1
0
  def test_get_pid_by_name_ps_bsd(self):
    """
    Tests the get_pid_by_name function with the bsd variant of ps.
    """

    mocking.mock(system.is_bsd, mocking.return_true())
    mocking.mock(system.call, mock_call(system.GET_PID_BY_NAME_PS_BSD, GET_PID_BY_NAME_PS_BSD))
    self.assertEquals(1, system.get_pid_by_name("launchd"))
    self.assertEquals(11, system.get_pid_by_name("DirectoryService"))
    self.assertEquals(None, system.get_pid_by_name("blarg"))
Exemplo n.º 2
0
    def test_get_pid_by_name_ps_bsd(self):
        """
    Tests the get_pid_by_name function with the bsd variant of ps.
    """

        mocking.mock(system.is_bsd, mocking.return_true())
        mocking.mock(
            system.call,
            mock_call(system.GET_PID_BY_NAME_PS_BSD, GET_PID_BY_NAME_PS_BSD))
        self.assertEquals(1, system.get_pid_by_name("launchd"))
        self.assertEquals(11, system.get_pid_by_name("DirectoryService"))
        self.assertEquals(None, system.get_pid_by_name("blarg"))
Exemplo n.º 3
0
  def test_get_pid_by_name_ps_bsd(self, call_mock):
    """
    Tests the get_pid_by_name function with the bsd variant of ps.
    """

    call_mock.side_effect = mock_call(system.GET_PID_BY_NAME_PS_BSD, GET_PID_BY_NAME_PS_BSD)
    self.assertEquals(1, system.get_pid_by_name("launchd"))
    self.assertEquals(11, system.get_pid_by_name("DirectoryService"))
    self.assertEquals(None, system.get_pid_by_name("blarg"))

    call_mock.side_effect = mock_call(system.GET_PID_BY_NAME_PS_BSD, GET_PID_BY_NAME_PS_BSD_MULTIPLE)

    self.assertEquals([1, 41], system.get_pid_by_name("launchd", multiple = True))
Exemplo n.º 4
0
  def test_get_pid_by_name_lsof(self):
    """
    Tests the get_pid_by_name function with lsof responses.
    """

    responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
    responses["success"] = ["1111"]
    responses["multiple_results"] = ["123", "456", "789"]
    mocking.mock(system.call, mock_call(system.GET_PID_BY_NAME_LSOF, responses))

    for test_input in responses:
      expected_response = 1111 if test_input == "success" else None
      self.assertEquals(expected_response, system.get_pid_by_name(test_input))

    self.assertEquals([123, 456, 789], system.get_pid_by_name("multiple_results", multiple = True))
Exemplo n.º 5
0
  def test_get_pid_by_name_lsof(self, call_mock):
    """
    Tests the get_pid_by_name function with lsof responses.
    """

    responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
    responses["success"] = ["1111"]
    responses["multiple_results"] = ["123", "456", "789"]
    call_mock.side_effect = mock_call(system.GET_PID_BY_NAME_LSOF, responses)

    for test_input in responses:
      expected_response = 1111 if test_input == "success" else None
      self.assertEquals(expected_response, system.get_pid_by_name(test_input))

    self.assertEquals([123, 456, 789], system.get_pid_by_name("multiple_results", multiple = True))
Exemplo n.º 6
0
  def test_get_pid_by_name_ps_linux(self, call_mock):
    """
    Tests the get_pid_by_name function with the linux variant of ps.
    """

    responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
    responses["success"] = ["PID", " 1111"]
    responses["multiple_results"] = ["PID", " 123", " 456", " 789"]
    call_mock.side_effect = mock_call(system.GET_PID_BY_NAME_PS_LINUX, responses)

    for test_input in responses:
      expected_response = 1111 if test_input == "success" else None
      self.assertEquals(expected_response, system.get_pid_by_name(test_input))

    self.assertEquals([123, 456, 789], system.get_pid_by_name("multiple_results", multiple = True))
Exemplo n.º 7
0
def get_toruser():
    """
    Get tor username
    """
    pid = system.get_pid_by_name("tor")
    toruser = system.get_user(pid)
    return toruser
Exemplo n.º 8
0
def get_toruser():
    """
    Get tor username
    """
    pid = system.get_pid_by_name("tor")
    toruser = system.get_user(pid)
    return toruser
Exemplo n.º 9
0
    def test_get_pid_by_name_lsof(self, call_mock):
        """
    Tests the get_pid_by_name function with lsof responses.
    """

        responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
        responses['success'] = ['1111']
        responses['multiple_results'] = ['123', '456', '789']
        call_mock.side_effect = mock_call(system.GET_PID_BY_NAME_LSOF,
                                          responses)

        for test_input in responses:
            expected_response = 1111 if test_input == 'success' else None
            self.assertEquals(expected_response,
                              system.get_pid_by_name(test_input))

        self.assertEquals([123, 456, 789],
                          system.get_pid_by_name('multiple_results',
                                                 multiple=True))
Exemplo n.º 10
0
  def test_get_pid_by_name_ps_linux(self):
    """
    Tests the get_pid_by_name function with the linux variant of ps.
    """

    mocking.mock(system.is_bsd, mocking.return_false())
    responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
    responses["success"] = ["PID", " 1111"]
    responses["multiple_results"] = ["PID", " 123", " 456", " 789"]
    mocking.mock(system.call, mock_call(system.GET_PID_BY_NAME_PS_LINUX, responses))

    for test_input in responses:
      expected_response = 1111 if test_input == "success" else None
      self.assertEquals(expected_response, system.get_pid_by_name(test_input))
Exemplo n.º 11
0
    def test_get_pid_by_name_lsof(self):
        """
    Tests the get_pid_by_name function with lsof responses.
    """

        responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
        responses["success"] = ["1111"]
        responses["multiple_results"] = ["123", "456", "789"]
        mocking.mock(system.call,
                     mock_call(system.GET_PID_BY_NAME_LSOF, responses))

        for test_input in responses:
            expected_response = 1111 if test_input == "success" else None
            self.assertEquals(expected_response,
                              system.get_pid_by_name(test_input))
Exemplo n.º 12
0
    def test_get_pid_by_name_ps_linux(self):
        """
    Tests the get_pid_by_name function with the linux variant of ps.
    """

        mocking.mock(system.is_bsd, mocking.return_false())
        responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
        responses["success"] = ["PID", " 1111"]
        responses["multiple_results"] = ["PID", " 123", " 456", " 789"]
        mocking.mock(system.call,
                     mock_call(system.GET_PID_BY_NAME_PS_LINUX, responses))

        for test_input in responses:
            expected_response = 1111 if test_input == "success" else None
            self.assertEquals(expected_response,
                              system.get_pid_by_name(test_input))
Exemplo n.º 13
0
if not resolvers:
    print 'Stem doesn\'t support any connection resolvers on our platform.'
    sys.exit(1)

picked_resolver = resolvers[0]  # lets just opt for the first
#print 'Our platform supports connection resolution via: %s (picked %s)' % (', '.join(resolvers), picked_resolver)

seenips = set()

try:
    while True:
        #try to get tor pid
        tor_pids = []
        while len(tor_pids) != 1:
            tor_pids = get_pid_by_name('tor', multiple=True)
            time.sleep(5)
        tor = tor_pids[0]

        # constantly read tor ips and output them
        while tor in get_pid_by_name('tor', multiple=True):
            try:
                for conn in get_connections(picked_resolver,
                                            process_pid=tor_pids[0],
                                            process_name='tor'):
                    #print '  %s:%s => %s:%s' % (conn.local_address, conn.local_port, conn.remote_address, conn.remote_port)
                    if conn.remote_address == '127.0.0.1':
                        continue
                    elif conn.remote_address not in seenips:
                        print conn.remote_address
                        seenips.add(conn.remote_address)