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-b9f4589650daunstable
parent
8079bfa9b2
commit
9ebbe84a4a
Binary file not shown.
|
@ -38,11 +38,39 @@ public class MsfguiApp extends SingleFrameApplication {
|
|||
public static JFileChooser fileChooser;
|
||||
protected static Pattern backslash = Pattern.compile("\\\\");
|
||||
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 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;
|
||||
try{
|
||||
props = (Map)RpcConnection.parseVal(DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
|
@ -326,7 +354,6 @@ public class MsfguiApp extends SingleFrameApplication {
|
|||
try{
|
||||
DatagramSocket socket = new DatagramSocket();
|
||||
socket.connect(InetAddress.getByName("1.2.3.4"),1234);
|
||||
socket.getLocalAddress();
|
||||
String answer = socket.getLocalAddress().getHostAddress();
|
||||
socket.close();
|
||||
return answer;
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
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.util.Map;
|
||||
import javax.swing.JFileChooser;
|
||||
|
@ -9,8 +13,10 @@ import javax.swing.JTextField;
|
|||
* @author scriptjunkie
|
||||
*/
|
||||
public class OpenConnectionDialog extends javax.swing.JDialog {
|
||||
MainFrame mainframe;
|
||||
RpcConnection rpcConn;
|
||||
private MainFrame mainframe;
|
||||
private RpcConnection rpcConn;
|
||||
private int timeout = 4;
|
||||
private javax.swing.Timer countdown;
|
||||
|
||||
/** Creates new form UserPassDialog */
|
||||
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)
|
||||
.getContext().getResourceMap(ModulePopup.class);
|
||||
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();
|
||||
fillDefault(root.get("username"),usernameField);
|
||||
fillDefault(root.get("host"),hostField);
|
||||
|
|
|
@ -129,7 +129,7 @@ public class RpcConnection {
|
|||
} else {
|
||||
connection = new Socket(host, port);
|
||||
}
|
||||
connection.setSoTimeout(5000); //Five second timeout
|
||||
connection.setSoTimeout(10000); //Ten second timeout
|
||||
sout = connection.getOutputStream();
|
||||
sin = connection.getInputStream();
|
||||
}
|
||||
|
@ -396,8 +396,9 @@ public class RpcConnection {
|
|||
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[]{
|
||||
"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)
|
||||
args.add("-S");
|
||||
if(disableDb)
|
||||
|
@ -415,7 +416,15 @@ public class RpcConnection {
|
|||
//Connect to started daemon
|
||||
setMessage("Started msfrpcd. Connecting to new msfrpcd...");
|
||||
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 {
|
||||
myRpcConn = new RpcConnection(defaultUser, defaultPass.toCharArray(), "127.0.0.1", defaultPort, defaultSsl);
|
||||
connected = true;
|
||||
|
|
Loading…
Reference in New Issue