Merge pull request #1664 from scriptjunkie/msfguiKaliConnect

MSFGUI service autoconnect, DB fixes
unstable
Josh 2013-03-25 21:58:28 -07:00
commit ee199f64cb
5 changed files with 29 additions and 4 deletions

Binary file not shown.

View File

@ -295,6 +295,9 @@ public class DbConnectDialog extends OptionsDialog {
}
/** Tries to connect to the database with given credentials */
private boolean tryConnect() throws MsfException{
Map status = (Map) rpcConn.execute("db.status");
if(status.containsKey("db"))
return true; // already connected
HashMap opts = new HashMap();
addNonempty("host", hostField, opts);
addNonempty("port", portField, opts);

View File

@ -171,7 +171,7 @@ public class MainFrame extends FrameView {
MsfguiApp.shuttingDown = true;
if(choice == JOptionPane.YES_OPTION)
rpcConn.execute("core.stop");
else if(choice == JOptionPane.NO_OPTION)
else if(choice == JOptionPane.NO_OPTION && rpcConn.username.length() > 0)
rpcConn.execute("auth.logout");
} catch (Exception ex) {
}

View File

@ -3,7 +3,10 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import javax.swing.JFileChooser;
@ -120,6 +123,19 @@ public class OpenConnectionDialog extends javax.swing.JDialog {
} catch (NullPointerException nex) {//generated when attributes dont exist.
} catch (Exception ex) { //for weird msg exceptions
}
//Try service token on default 3790
BufferedReader fin = null;
try{
try{
fin = new BufferedReader(new FileReader(MsfguiApp.getMsfRoot().getParent()+"/apps/pro/engine/tmp/servicekey.txt"));
}catch(Exception iox2){
fin = new BufferedReader(new FileReader("/opt/metasploit/apps/pro/engine/tmp/servicekey.txt"));
}
RpcConnection rpc = RpcConnection.getConn("", fin.readLine().toCharArray(), "localhost", 3790, true);
if(javax.swing.JOptionPane.showConfirmDialog(null, "Connect to local rpcd?") == javax.swing.JOptionPane.YES_OPTION)
return rpc;
}catch(Exception iox){//file not found/unreadable/bad creds/etc. - ignore
}
//Darn. open the gui anyway
OpenConnectionDialog diag = new OpenConnectionDialog(true, mainframe);
diag.setVisible(true);

View File

@ -84,9 +84,15 @@ public abstract class RpcConnection {
String message = "";
try {
connect();
Map results = (Map)exec("auth.login",new Object[]{username, this.password});
rpcToken=results.get("token").toString();
haveRpcd=results.get("result").equals("success");
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){