private void connectButtonActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_connectButtonActionPerformed
   try {
     success = tryConnect();
     if (!success) MsfguiApp.showMessage(myParent, "Failure connecting to database!");
   } catch (MsfException mex) {
     MsfguiApp.showMessage(myParent, mex);
   }
   setVisible(false);
 }
 private void okButtonActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_okButtonActionPerformed
   StringBuilder cmd = new StringBuilder("uploadexec ");
   if (optionsField.getText().length() > 0)
     cmd.append(" -o \"" + MsfguiApp.doubleBackslashes(optionsField.getText()) + "\"");
   if (pathField.getText().length() > 0)
     cmd.append(" -p \"" + MsfguiApp.doubleBackslashes(pathField.getText()) + "\"");
   cmd.append(" -e \"" + MsfguiApp.doubleBackslashes(fileField.getText()) + "\"");
   if (verboseBox.isSelected()) cmd.append(" -v");
   if (removeBox.isSelected()) cmd.append(" -r");
   command = cmd.toString();
   doClose();
 } // GEN-LAST:event_okButtonActionPerformed
 /** Loads database information from the database.yml file in the default install. */
 private void reloadDefaults() {
   try {
     Scanner s;
     try {
       s = new Scanner(new File(System.getenv("BASE") + "config/database.yml"));
     } catch (FileNotFoundException fnfox) {
       try {
         s = new Scanner(new File(MsfguiApp.getMsfRoot() + "/../config/database.yml"));
       } catch (FileNotFoundException fnfx) {
         s = new Scanner(new File("/opt/metasploit/apps/pro/ui/config/database.yml"));
       }
     }
     String token = s.next();
     while (!token.equals("production:")) token = s.next();
     while (s.hasNext()) {
       if (token.equals("adapter:")) props.put("dbdriver", stripQuotes(s.next()));
       else if (token.equals("database:")) props.put("dbdatabase", stripQuotes(s.next()));
       else if (token.equals("username:"******"dbusername", stripQuotes(s.next()));
       else if (token.equals("password:"******"dbpassword", stripQuotes(s.next()));
       else if (token.equals("host:")) props.put("dbhost", stripQuotes(s.next()));
       else if (token.equals("port:")) props.put("dbport", stripQuotes(s.next()));
       token = s.next();
     }
   } catch (FileNotFoundException fnfox) {
     fnfox.printStackTrace();
   }
   showDefaults();
 }
Example #4
0
 /** Setup sets up a connection and authenticates. */
 public void setup(String username, char[] password, String host, int port, boolean ssl)
     throws MsfException {
   boolean haveRpcd = false;
   this.username = username;
   this.password = new String(password);
   this.host = host;
   this.port = port;
   this.ssl = ssl;
   String message = "";
   try {
     connect();
     if (username == null || username.equals("")) {
       rpcToken = this.password;
       execute("core.version"); // throws error if unsuccessful
       haveRpcd = true;
     } else {
       Map results = (Map) exec("auth.login", new Object[] {username, this.password});
       rpcToken = results.get("token").toString();
       haveRpcd = results.get("result").equals("success");
     }
   } catch (MsfException xre) {
     message = xre.getLocalizedMessage();
   } catch (IOException io) {
     message = io.getLocalizedMessage();
   } catch (NullPointerException nex) {
   } catch (NoSuchAlgorithmException nsax) {
   } catch (KeyManagementException kmx) {
   }
   if (!haveRpcd) throw new MsfException("Error connecting. " + message);
   Map root = MsfguiApp.getPropertiesNode();
   root.put("username", username);
   root.put("password", this.password);
   root.put("host", host);
   root.put("port", port);
   root.put("ssl", ssl);
   root.put("disableDb", disableDb);
   MsfguiApp.savePreferences();
 }
 private void okButtonActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_okButtonActionPerformed
   StringBuilder cmd = new StringBuilder("netenum ");
   if (addressField.getText().length() > 0) cmd.append(" -r ").append(addressField.getText());
   if (pingBox.isSelected()) cmd.append(" -ps");
   if (reverseDnsBox.isSelected()) cmd.append(" -rl");
   if (forwardBox.isSelected()) cmd.append(" -fl");
   if (fileField.getText().length() > 0)
     cmd.append(" -hl ").append(MsfguiApp.escapeBackslashes(fileField.getText()));
   if (domainField.getText().length() > 0) cmd.append(" -d ").append(domainField.getText());
   if (mxNsBox.isSelected()) cmd.append(" -st");
   if (serviceBox.isSelected()) cmd.append(" -sr");
   command = cmd.toString();
   setVisible(false);
   dispose();
 } // GEN-LAST:event_okButtonActionPerformed
 /** Creates new form DbConnectDialog */
 public DbConnectDialog(Frame parent, RpcConnection rpcConn, boolean modal) {
   super(parent, "Database Connection Options", modal);
   initComponents();
   this.rpcConn = rpcConn;
   myParent = parent;
   success = false;
   props = MsfguiApp.getPropertiesNode();
   try {
     // If we don't have saved creds, look for them
     if (!props.containsKey("dbusername")) reloadDefaults();
     showDefaults();
   } catch (NullPointerException nex) {
   } catch (MsfException mex) { // No msf root?
     mex.printStackTrace();
   }
   Object driver = props.get("dbdriver");
   List l = ((javax.swing.SpinnerListModel) typeSpinner.getModel()).getList();
   for (Object o : l) if (o.equals(driver)) typeSpinner.setValue(driver);
 }
Example #7
0
  /** Attempts to start msfrpcd and connect to it. */
  public static Task startRpcConn(final MainFrame mainFrame) {
    if (mainFrame.rpcConn != null) {
      MsfguiApp.showMessage(
          mainFrame.getFrame(),
          "You are already connected!\n" + "Exit before making a new connection.");
      throw new RuntimeException("Already connected");
    }
    return new Task<RpcConnection, Void>(mainFrame.getApplication()) {
      private RpcConnection myRpcConn;

      @Override
      protected RpcConnection doInBackground() throws Exception {
        setTitle("Starting new msfrpcd");
        setMessage("Setting up and saving parameters.");
        if (defaultPass == null) {
          StringBuilder password = new StringBuilder();
          Random secrand = new SecureRandom();
          for (int i = 0; i < 10; i++) password.append((char) ('a' + secrand.nextInt(26)));
          defaultPass = password.toString();
        }

        // Don't fork cause we'll check if it dies
        String rpcType = "Basic";
        java.util.List args =
            new java.util.ArrayList(
                java.util.Arrays.asList(
                    new String[] {
                      "msfrpcd",
                      "-f",
                      "-P",
                      defaultPass,
                      "-U",
                      defaultUser,
                      "-a",
                      "0.0.0.0",
                      "-p",
                      Integer.toString(defaultPort)
                    }));
        if (!defaultSsl) args.add("-S");
        if (disableDb) args.add("-n");
        setMessage("Starting msfrpcd.");
        Process proc = null;
        try {
          proc = MsfguiApp.startMsfProc(args);
        } catch (MsfException ex) {
          setMessage("msfrpcd not found.");
          setProgress(1f);
          throw new MsfException("Could not find or start msfrpcd"); // darn
        }

        // Connect to started daemon
        setMessage("Started msfrpcd. Connecting to new msfrpcd...");
        boolean connected = false;
        int timeoutTries = 0;
        for (int tries = 0; tries < 10000; tries++) { // it usually takes a minute to get started

          try { // unfortunately this is the only direct way to check if process has terminated
            int exitval = proc.exitValue();
            setMessage("msfrpcd died with exit value " + exitval);
            throw new MsfException("msfrpcd died");
          } catch (IllegalThreadStateException itsy) {
          } // Nope. We're good.

          try {
            myRpcConn =
                RpcConnection.getConn(
                    defaultUser, defaultPass.toCharArray(), "127.0.0.1", defaultPort, defaultSsl);
            connected = true;
            break;
          } catch (MsfException mex) {
            if (mex.getMessage().toLowerCase().contains("authentication error")) {
              mex.printStackTrace();
              setMessage("Cannot connect to started msfrpcd.");
              proc.destroy();
              throw mex;
            } else if (mex.getMessage().toLowerCase().contains("connection reset")) {
              mex.printStackTrace();
              setMessage("Connection reset.");
              proc.destroy();
              throw mex;
            } else if (mex.getMessage().toLowerCase().contains("timed out")) {
              mex.printStackTrace();
              setMessage("Timeout.");
              timeoutTries++;
              if (timeoutTries > 5) { // this can happen legitimately
                proc.destroy();
                throw mex;
              }
            }
          }
          try {
            Thread.sleep(200); // Wait for msfrpcd to be ready
          } catch (InterruptedException iex) {
          }
        } // end try to connect loop
        if (!connected) {
          setMessage("Cannot connect to started msfrpcd.");
          throw new MsfException("Cannot connect to started msfrpcd.");
        }
        return myRpcConn;
      }

      @Override
      protected void succeeded(RpcConnection myRpcConn) {
        mainFrame.rpcConn = myRpcConn;
        mainFrame.handleNewRpcConnection();
      }
    };
  }