Update to version 4.

Add first-run detection that farms out database initialization to msfconsole.
Autostart RPC if no other option is selected.
Check for RPC death in startup.
More lenient socket timeouts.



git-svn-id: file:///home/svn/framework3/trunk@13301 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Weeks 2011-07-23 00:05:38 +00:00
parent 8079bfa9b2
commit 9ebbe84a4a
4 changed files with 74 additions and 8 deletions

Binary file not shown.

View File

@ -38,11 +38,39 @@ public class MsfguiApp extends SingleFrameApplication {
public static JFileChooser fileChooser; public static JFileChooser fileChooser;
protected static Pattern backslash = Pattern.compile("\\\\"); protected static Pattern backslash = Pattern.compile("\\\\");
public static String workspace = "default"; public static String workspace = "default";
public static final String confFilename = System.getProperty("user.home")+File.separatorChar+".msf3"+File.separatorChar+"msfgui"; public static final String confFilename = System.getProperty("user.home")+File.separatorChar+".msf4"+File.separatorChar+"msfgui";
public static MainFrame mainFrame; public static MainFrame mainFrame;
public static boolean shuttingDown = false; public static boolean shuttingDown = false;
static{ //get saved properties file static{
//First start detection
if(!(new java.io.File(confFilename)).exists()){
try{
//Prepare exit rc
String rcname = MsfguiApp.getTempFilename("exit", ".rc");
FileWriter exitOut = new FileWriter(rcname);
exitOut.write("exit\n");
exitOut.close();
Process p;
//Run msfconsole once to init database.
if(System.getProperty("os.name").toLowerCase().contains("windows")){
ProcessBuilder ps = new ProcessBuilder(new String[]{"console.exe","-c",
System.getenv("BASE")+"tools\\console.xml","-t","Metasploit"});
ps.environment().put("MSFCONSOLE_OPTS", "-e production -y \""+
System.getenv("BASE")+"config\\database.yml\" -r "+rcname);
ps.directory(new File(System.getenv("BASE")));
p = ps.start();
}else{
p = startMsfProc(new String[]{"msfconsole","-r",rcname});
}
//Tell user and wait
JOptionPane.showMessageDialog(null, "Please wait for msf4 first-run initialization");
p.waitFor();
}catch(Exception iox){
JOptionPane.showMessageDialog(null, "First-run initialization failed: "+iox.getMessage());
}
}
//get saved properties file
Map props; Map props;
try{ try{
props = (Map)RpcConnection.parseVal(DocumentBuilderFactory.newInstance().newDocumentBuilder() props = (Map)RpcConnection.parseVal(DocumentBuilderFactory.newInstance().newDocumentBuilder()
@ -326,7 +354,6 @@ public class MsfguiApp extends SingleFrameApplication {
try{ try{
DatagramSocket socket = new DatagramSocket(); DatagramSocket socket = new DatagramSocket();
socket.connect(InetAddress.getByName("1.2.3.4"),1234); socket.connect(InetAddress.getByName("1.2.3.4"),1234);
socket.getLocalAddress();
String answer = socket.getLocalAddress().getHostAddress(); String answer = socket.getLocalAddress().getHostAddress();
socket.close(); socket.close();
return answer; return answer;

View File

@ -1,4 +1,8 @@
package msfgui; package msfgui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File; import java.io.File;
import java.util.Map; import java.util.Map;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
@ -9,8 +13,10 @@ import javax.swing.JTextField;
* @author scriptjunkie * @author scriptjunkie
*/ */
public class OpenConnectionDialog extends javax.swing.JDialog { public class OpenConnectionDialog extends javax.swing.JDialog {
MainFrame mainframe; private MainFrame mainframe;
RpcConnection rpcConn; private RpcConnection rpcConn;
private int timeout = 4;
private javax.swing.Timer countdown;
/** Creates new form UserPassDialog */ /** Creates new form UserPassDialog */
public OpenConnectionDialog(boolean modal, MainFrame mainframe) { public OpenConnectionDialog(boolean modal, MainFrame mainframe) {
@ -22,6 +28,30 @@ public class OpenConnectionDialog extends javax.swing.JDialog {
= org.jdesktop.application.Application.getInstance(msfgui.MsfguiApp.class) = org.jdesktop.application.Application.getInstance(msfgui.MsfguiApp.class)
.getContext().getResourceMap(ModulePopup.class); .getContext().getResourceMap(ModulePopup.class);
this.setIconImage(resourceMap.getImageIcon("main.icon").getImage()); this.setIconImage(resourceMap.getImageIcon("main.icon").getImage());
startNewButton.requestFocusInWindow();
startNewButton.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent fe) {
}
public void focusLost(FocusEvent fe) {
timeout = 0;
startNewButton.setText("Start new msfrpcd");
}
});
countdown = new javax.swing.Timer(1000,new ActionListener(){
public void actionPerformed(ActionEvent ae) {
if(timeout == 0){
countdown.stop();
return;
}
timeout = timeout - 1;
startNewButton.setText("Start new msfrpcd ("+timeout+")");
if(timeout == 0)
startNewButtonActionPerformed(ae);
}
});
countdown.start();
startNewButton.setText("Start new msfrpcd ("+timeout+")");
Map root = MsfguiApp.getPropertiesNode(); Map root = MsfguiApp.getPropertiesNode();
fillDefault(root.get("username"),usernameField); fillDefault(root.get("username"),usernameField);
fillDefault(root.get("host"),hostField); fillDefault(root.get("host"),hostField);

View File

@ -129,7 +129,7 @@ public class RpcConnection {
} else { } else {
connection = new Socket(host, port); connection = new Socket(host, port);
} }
connection.setSoTimeout(5000); //Five second timeout connection.setSoTimeout(10000); //Ten second timeout
sout = connection.getOutputStream(); sout = connection.getOutputStream();
sin = connection.getInputStream(); sin = connection.getInputStream();
} }
@ -396,8 +396,9 @@ public class RpcConnection {
defaultPass = password.toString(); defaultPass = password.toString();
} }
// Don't fork cause we'll check if it dies
java.util.List args = new java.util.ArrayList(java.util.Arrays.asList(new String[]{ java.util.List args = new java.util.ArrayList(java.util.Arrays.asList(new String[]{
"msfrpcd","-P",defaultPass,"-t","Basic","-U",defaultUser,"-a","127.0.0.1"})); "msfrpcd","-f","-P",defaultPass,"-t","Basic","-U",defaultUser,"-a","127.0.0.1"}));
if(!defaultSsl) if(!defaultSsl)
args.add("-S"); args.add("-S");
if(disableDb) if(disableDb)
@ -415,7 +416,15 @@ public class RpcConnection {
//Connect to started daemon //Connect to started daemon
setMessage("Started msfrpcd. Connecting to new msfrpcd..."); setMessage("Started msfrpcd. Connecting to new msfrpcd...");
boolean connected = false; boolean connected = false;
for (int tries = 0; tries < 1000; tries++) { //it usually takes a minute to get started 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 { try {
myRpcConn = new RpcConnection(defaultUser, defaultPass.toCharArray(), "127.0.0.1", defaultPort, defaultSsl); myRpcConn = new RpcConnection(defaultUser, defaultPass.toCharArray(), "127.0.0.1", defaultPort, defaultSsl);
connected = true; connected = true;