Beispiel #1
0
    def test_is_running(self, call_mock):
        """
    Exercises multiple use cases for the is_running function.
    """

        # mock response with a linux and bsd resolver
        running_commands = ['irssi', 'moc', 'tor', 'ps', '  firefox  ']

        for ps_cmd in (system.IS_RUNNING_PS_LINUX, system.IS_RUNNING_PS_BSD):
            call_mock.side_effect = mock_call(ps_cmd, running_commands)

            self.assertTrue(system.is_running('irssi'))
            self.assertTrue(system.is_running('moc'))
            self.assertTrue(system.is_running('tor'))
            self.assertTrue(system.is_running(['funky-tor', 'tor']))
            self.assertTrue(system.is_running('ps'))
            self.assertTrue(system.is_running('firefox'))
            self.assertFalse(system.is_running('something_else'))
            self.assertFalse(system.is_running(['funky-tor', 'funkier-tor']))

        # mock both calls failing

        call_mock.return_value = None
        call_mock.side_effect = None
        self.assertFalse(system.is_running('irssi'))
        self.assertEqual(None, system.is_running('irssi'))
Beispiel #2
0
  def test_is_running(self, call_mock):
    """
    Exercises multiple use cases for the is_running function.
    """

    # mock response with a linux and bsd resolver
    running_commands = [str_type('irssi'), str_type('moc'), str_type('tor'),
                        str_type('ps'), str_type('  firefox  ')]

    for ps_cmd in (system.IS_RUNNING_PS_LINUX, system.IS_RUNNING_PS_BSD):
      call_mock.side_effect = mock_call(ps_cmd, running_commands)

      self.assertTrue(system.is_running('irssi'))
      self.assertTrue(system.is_running('moc'))
      self.assertTrue(system.is_running('tor'))
      self.assertTrue(system.is_running('ps'))
      self.assertTrue(system.is_running('firefox'))
      self.assertEqual(False, system.is_running('something_else'))

    # mock both calls failing

    call_mock.return_value = None
    call_mock.side_effect = None
    self.assertFalse(system.is_running('irssi'))
    self.assertEqual(None, system.is_running('irssi'))
Beispiel #3
0
def start(tortpdir):
   """
   Start TorTP
   """
   if system.is_running("tor"):
      try:
         stem.socket.ControlPort(port = 9051)
      except stem.SocketError as exc:
         notify("TorTP", "[!] Unable to connect to port 9051 (%s)" % exc)
         sys.exit(1)
      if os.path.exists("%s/resolv.conf" % tortpdir) and os.path.exists("%s/dnsmasq.conf" % tortpdir) and os.path.exists("%s/iptables.txt" % tortpdir):
         notify("TorTP", "[!] TorTP is already running")
         sys.exit(2)
      else:
         check_sys_dependencies()
         iptables_clean()
         iptables_up(tortpdir, get_toruser())
         enable_tordns()
         enable_torproxy()
         resolvconf(tortpdir)
         dnsmasq(tortpdir)
         devnull = open(os.devnull,"w")
         subprocess.call(['/etc/init.d/dnsmasq', 'restart'], stdout=devnull)
         devnull.close()
         notify("TorTP", "[+] Tor Transparent Proxy enabled")
   else:
      notify("TorTP", "[!] Tor is not running")
      sys.exit(3)
Beispiel #4
0
def get_exit():
   """
   Get list of exit node from stem
   """
   if system.is_running("tor"):
      try:
         with Controller.from_port(port = 9051) as controller:
            controller.authenticate()
            exit = {'count': [], 'fingerprint': [], 'nickname': [], 'ipaddress': []}
            count = -1
            for circ in controller.get_circuits():
               if circ.status != CircStatus.BUILT:
                  continue
               exit_fp, exit_nickname = circ.path[-1]
               exit_desc = controller.get_network_status(exit_fp, None)
               exit_address = exit_desc.address if exit_desc else 'unknown'
               count += 1
               exit['count'].append(count)
               exit['fingerprint'].append(exit_fp)
               exit['nickname'].append(exit_nickname)
               exit['ipaddress'].append(exit_address)
         return exit
      except stem.SocketError as exc:
         notify("TorTP", "[!] Unable to connect to port 9051 (%s)" % exc)
         sys.exit(1)
   else:
      notify("TorTP", "[!] Tor is not running")
Beispiel #5
0
def start(tortpdir):
   """
   Start TorTP
   """
   if system.is_running("tor"):
      try:
         stem.socket.ControlPort(port = 9051)
      except stem.SocketError as exc:
         notify("TorTP", "[!] Unable to connect to port 9051 (%s)" % exc)
         sys.exit(1)
      if os.path.exists("%s/resolv.conf" % tortpdir) and os.path.exists("%s/dnsmasq.conf" % tortpdir) and os.path.exists("%s/iptables.txt" % tortpdir):
         notify("TorTP", "[!] TorTP is already running")
         sys.exit(2)
      else:
         check_sys_dependencies()
         iptables_clean()
         iptables_up(tortpdir, get_toruser())
         enable_tordns()
         enable_torproxy()
         resolvconf(tortpdir)
         dnsmasq(tortpdir)
         devnull = open(os.devnull,"w")
         subprocess.call(['/etc/init.d/dnsmasq', 'restart'], stdout=devnull)
         devnull.close()
         notify("TorTP", "[+] Tor Transparent Proxy enabled")
   else:
      notify("TorTP", "[!] Tor is not running")
      sys.exit(3)
Beispiel #6
0
def get_exit():
   """
   Get list of exit node from stem
   """
   if system.is_running("tor"):
      try:
         with Controller.from_port(port = 9051) as controller:
            controller.authenticate()
            exit = {'count': [], 'fingerprint': [], 'nickname': [], 'ipaddress': []}
            count = -1
            for circ in controller.get_circuits():
               if circ.status != CircStatus.BUILT:
                  continue
               exit_fp, exit_nickname = circ.path[-1]
               exit_desc = controller.get_network_status(exit_fp, None)
               exit_address = exit_desc.address if exit_desc else 'unknown'
               count += 1
               exit['count'].append(count)
               exit['fingerprint'].append(exit_fp)
               exit['nickname'].append(exit_nickname)
               exit['ipaddress'].append(exit_address)
         return exit
      except stem.SocketError as exc:
         notify("TorTP", "[!] Unable to connect to port 9051 (%s)" % exc)
         sys.exit(1)
   else:
      notify("TorTP", "[!] Tor is not running")
Beispiel #7
0
def check_tortp(myip, exit):
   """
   Check if my IP is a Tor exit node
   """
   if system.is_running("tor"):
      try:
         if myip not in exit['ipaddress']:
            notify("TorTP", "[-] Sorry. TorTP is not working: %s" % myip)
            sys.exit(1)
      except stem.SocketError as exc:
         notify("TorTP", "[!] Unable to connect to port 9051 (%s)" % exc)
         sys.exit(1)

      notify("TorTP", "[+] Congratulations. TorTP is working: %s" % myip)
      return myip
   else:
      notify("TorTP", "[!] Tor is not running")
      sys.exit(3)
Beispiel #8
0
def check_tortp(myip, exit):
   """
   Check if my IP is a Tor exit node
   """
   if system.is_running("tor"):
      try:
         if myip not in exit['ipaddress']:
            notify("TorTP", "[-] Sorry. TorTP is not working: %s" % myip)
            sys.exit(1)
      except stem.SocketError as exc:
         notify("TorTP", "[!] Unable to connect to port 9051 (%s)" % exc)
         sys.exit(1)

      notify("TorTP", "[+] Congratulations. TorTP is working: %s" % myip)
      return myip
   else:
      notify("TorTP", "[!] Tor is not running")
      sys.exit(3)
Beispiel #9
0
    def test_is_running(self):
        """
    Exercises multiple use cases for the is_running function.
    """

        # mock response with a linux and bsd resolver
        running_commands = ["irssi", "moc", "tor", "ps", "  firefox  "]

        for ps_cmd in (system.IS_RUNNING_PS_LINUX, system.IS_RUNNING_PS_BSD):
            mocking.mock(system.call, mock_call(ps_cmd, running_commands))

            self.assertTrue(system.is_running("irssi"))
            self.assertTrue(system.is_running("moc"))
            self.assertTrue(system.is_running("tor"))
            self.assertTrue(system.is_running("ps"))
            self.assertTrue(system.is_running("firefox"))
            self.assertEqual(False, system.is_running("something_else"))

        # mock both calls failing
        mocking.mock(system.call, mocking.return_none())
        self.assertFalse(system.is_running("irssi"))
        self.assertEquals(None, system.is_running("irssi"))
Beispiel #10
0
  def test_is_running(self):
    """
    Exercises multiple use cases for the is_running function.
    """

    # mock response with a linux and bsd resolver
    running_commands = ["irssi", "moc", "tor", "ps", "  firefox  "]

    for ps_cmd in (system.IS_RUNNING_PS_LINUX, system.IS_RUNNING_PS_BSD):
      mocking.mock(system.call, mock_call(ps_cmd, running_commands))

      self.assertTrue(system.is_running("irssi"))
      self.assertTrue(system.is_running("moc"))
      self.assertTrue(system.is_running("tor"))
      self.assertTrue(system.is_running("ps"))
      self.assertTrue(system.is_running("firefox"))
      self.assertEqual(False, system.is_running("something_else"))

    # mock both calls failing
    mocking.mock(system.call, mocking.return_none())
    self.assertFalse(system.is_running("irssi"))
    self.assertEquals(None, system.is_running("irssi"))
Beispiel #11
0
  def test_is_running(self, call_mock):
    """
    Exercises multiple use cases for the is_running function.
    """

    # mock response with a linux and bsd resolver
    running_commands = [u"irssi", u"moc", u"tor", u"ps", u"  firefox  "]

    for ps_cmd in (system.IS_RUNNING_PS_LINUX, system.IS_RUNNING_PS_BSD):
      call_mock.side_effect = mock_call(ps_cmd, running_commands)

      self.assertTrue(system.is_running("irssi"))
      self.assertTrue(system.is_running("moc"))
      self.assertTrue(system.is_running("tor"))
      self.assertTrue(system.is_running("ps"))
      self.assertTrue(system.is_running("firefox"))
      self.assertEqual(False, system.is_running("something_else"))

    # mock both calls failing

    call_mock.return_value = None
    call_mock.side_effect = None
    self.assertFalse(system.is_running("irssi"))
    self.assertEquals(None, system.is_running("irssi"))