Skip to content

Commit ee199f6

Browse files
committed
Merge pull request rapid7#1664 from scriptjunkie/msfguiKaliConnect
MSFGUI service autoconnect, DB fixes
2 parents 29752d6 + 1b6398d commit ee199f6

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

data/gui/msfgui.jar

697 Bytes
Binary file not shown.

external/source/gui/msfguijava/src/msfgui/DbConnectDialog.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN
295295
}
296296
/** Tries to connect to the database with given credentials */
297297
private boolean tryConnect() throws MsfException{
298+
Map status = (Map) rpcConn.execute("db.status");
299+
if(status.containsKey("db"))
300+
return true; // already connected
298301
HashMap opts = new HashMap();
299302
addNonempty("host", hostField, opts);
300303
addNonempty("port", portField, opts);

external/source/gui/msfguijava/src/msfgui/MainFrame.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private boolean confirmStop() {
171171
MsfguiApp.shuttingDown = true;
172172
if(choice == JOptionPane.YES_OPTION)
173173
rpcConn.execute("core.stop");
174-
else if(choice == JOptionPane.NO_OPTION)
174+
else if(choice == JOptionPane.NO_OPTION && rpcConn.username.length() > 0)
175175
rpcConn.execute("auth.logout");
176176
} catch (Exception ex) {
177177
}

external/source/gui/msfguijava/src/msfgui/OpenConnectionDialog.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import java.awt.event.ActionListener;
44
import java.awt.event.FocusEvent;
55
import java.awt.event.FocusListener;
6+
import java.io.BufferedReader;
67
import java.io.File;
8+
import java.io.FileReader;
9+
import java.io.IOException;
710
import java.security.NoSuchAlgorithmException;
811
import java.util.Map;
912
import javax.swing.JFileChooser;
@@ -120,6 +123,19 @@ else if (mex.getMessage().toLowerCase().contains("timed out"))
120123
} catch (NullPointerException nex) {//generated when attributes dont exist.
121124
} catch (Exception ex) { //for weird msg exceptions
122125
}
126+
//Try service token on default 3790
127+
BufferedReader fin = null;
128+
try{
129+
try{
130+
fin = new BufferedReader(new FileReader(MsfguiApp.getMsfRoot().getParent()+"/apps/pro/engine/tmp/servicekey.txt"));
131+
}catch(Exception iox2){
132+
fin = new BufferedReader(new FileReader("/opt/metasploit/apps/pro/engine/tmp/servicekey.txt"));
133+
}
134+
RpcConnection rpc = RpcConnection.getConn("", fin.readLine().toCharArray(), "localhost", 3790, true);
135+
if(javax.swing.JOptionPane.showConfirmDialog(null, "Connect to local rpcd?") == javax.swing.JOptionPane.YES_OPTION)
136+
return rpc;
137+
}catch(Exception iox){//file not found/unreadable/bad creds/etc. - ignore
138+
}
123139
//Darn. open the gui anyway
124140
OpenConnectionDialog diag = new OpenConnectionDialog(true, mainframe);
125141
diag.setVisible(true);

external/source/gui/msfguijava/src/msfgui/RpcConnection.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,15 @@ public void setup(String username, char[] password, String host, int port, boole
8484
String message = "";
8585
try {
8686
connect();
87-
Map results = (Map)exec("auth.login",new Object[]{username, this.password});
88-
rpcToken=results.get("token").toString();
89-
haveRpcd=results.get("result").equals("success");
87+
if(username == null || username.equals("")){
88+
rpcToken = this.password;
89+
execute("core.version"); //throws error if unsuccessful
90+
haveRpcd = true;
91+
}else{
92+
Map results = (Map)exec("auth.login",new Object[]{username, this.password});
93+
rpcToken=results.get("token").toString();
94+
haveRpcd=results.get("result").equals("success");
95+
}
9096
} catch (MsfException xre) {
9197
message = xre.getLocalizedMessage();
9298
} catch (IOException io){

0 commit comments

Comments
 (0)