Beispiel #1
0
  def test_run_and_shutdown(self):
    """
    Create multiple xvfb and shut them down.
    """
    num = 10
    dimensions = '1024x768x24'
    xserver_offset = 200
    xvfbs = XvfbController(num, dimensions, xserver_offset=xserver_offset)
    xvfbs.start()

    for process in xvfbs.processes:
      assert process.poll() is None

    xvfbs.shutdown()

    time.sleep(1)

    for process in xvfbs.processes:
      assert process.poll()
Beispiel #2
0
  def browse_creatives(self, protocol):
    """
    The creatives are hosted on SSL servers and viewed by browsers. All requests and responses are
    captured for the analysis in the next step.

    :param protocol: `https` or `http`.
    """
    if not os.path.exists(self.certificate_file):
      raise Exception('No certificate found.')
    if not os.path.exists(self.privatekey_file):
      raise Exception('No private key found.')

    # Delete the existing scanlog.
    self.db_session.query(
      ScanLog
    ).filter(
      ScanLog.created_at == datetime.date.today(),
      ScanLog.protocol == protocol
    ).delete()

    query = self.db_session.query(
      Creative
    ).filter(
      Creative.created_at == datetime.date.today()
    )

    if self.max_scan > 0:
      query = query.limit(self.max_scan)

    creatives = query.all()
    servers, xvfbs, browsers = None, None, None

    try:
      # Open ports and bind them to servers.
      ports = adscan.net.find_open_ports(self.server_count)
      servers = ServerController(protocol, ports, self.certificate_file, self.privatekey_file)
      servers.start()

      # Start virtual X windows.
      xvfbs = XvfbController(self.browser_count, self.display_dimension, xserver_offset=self.xserver_offset)
      xvfbs.start()

      # Start browsers
      browsers = BrowserController(
        creatives, protocol, ports, self.browser_count, self.phantomjs, self.browserjs, self.cookie_dir,
        self.workspace.dirname, self.scanlog, adscan.transform.create_scan_snippet, debug=self.debug,
        xserver_offset=self.xserver_offset)
      browsers.start()
      browsers.wait()
    except KeyboardInterrupt:
      raise
    finally:
      if browsers:
        browsers.shutdown()
      if servers:
        servers.shutdown()
      if xvfbs:
        xvfbs.shutdown()

    self.db_session.commit()

    if self.save_netlog:
      dest_dir = '%s/%s/netlog' % (self.log_dir, protocol)
      self.workspace.move_netlog(dest_dir)
Beispiel #3
0
    def browse_creatives(self, protocol):
        """
    The creatives are hosted on SSL servers and viewed by browsers. All requests and responses are
    captured for the analysis in the next step.

    :param protocol: `https` or `http`.
    """
        if not os.path.exists(self.certificate_file):
            raise Exception('No certificate found.')
        if not os.path.exists(self.privatekey_file):
            raise Exception('No private key found.')

        # Delete the existing scanlog.
        self.db_session.query(ScanLog).filter(
            ScanLog.created_at == datetime.date.today(),
            ScanLog.protocol == protocol).delete()

        query = self.db_session.query(Creative).filter(
            Creative.created_at == datetime.date.today())

        if self.max_scan > 0:
            query = query.limit(self.max_scan)

        creatives = query.all()
        servers, xvfbs, browsers = None, None, None

        try:
            # Open ports and bind them to servers.
            ports = adscan.net.find_open_ports(self.server_count)
            servers = ServerController(protocol, ports, self.certificate_file,
                                       self.privatekey_file)
            servers.start()

            # Start virtual X windows.
            xvfbs = XvfbController(self.browser_count,
                                   self.display_dimension,
                                   xserver_offset=self.xserver_offset)
            xvfbs.start()

            # Start browsers
            browsers = BrowserController(creatives,
                                         protocol,
                                         ports,
                                         self.browser_count,
                                         self.phantomjs,
                                         self.browserjs,
                                         self.cookie_dir,
                                         self.workspace.dirname,
                                         self.scanlog,
                                         adscan.transform.create_scan_snippet,
                                         debug=self.debug,
                                         xserver_offset=self.xserver_offset)
            browsers.start()
            browsers.wait()
        except KeyboardInterrupt:
            raise
        finally:
            if browsers:
                browsers.shutdown()
            if servers:
                servers.shutdown()
            if xvfbs:
                xvfbs.shutdown()

        self.db_session.commit()

        if self.save_netlog:
            dest_dir = '%s/%s/netlog' % (self.log_dir, protocol)
            self.workspace.move_netlog(dest_dir)