Address #5887 and #5888 for RPC DB and msfgui

git-svn-id: file:///home/svn/framework3/trunk@14167 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Weeks 2011-11-05 18:12:10 +00:00
parent e4d540e031
commit 4629c0867b
5 changed files with 210 additions and 365 deletions

Binary file not shown.

View File

@ -131,7 +131,7 @@
<EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="hostsTableKeyReleased"/> <EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="hostsTableKeyReleased"/>
</Events> </Events>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(new String [] {&#xa;&#x9;&#x9;&quot;Created&quot;, &quot;Address&quot;, &quot;Address6&quot;, &quot;MAC&quot;, &quot;Name&quot;, &quot;State&quot;, &quot;OS name&quot;, &quot;OS flavor&quot;, &quot;OS SP&quot;, &quot;OS lang&quot;, &quot;Updated&quot;, &quot;Purpose&quot;, &quot;Info&quot;&#xa;&#x9;})"/> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(rpcConn, new String [] {&quot;Created&quot;, &quot;Address&quot;, &quot;Address6&quot;, &quot;MAC&quot;, &quot;Name&quot;, &quot;State&quot;, &quot;OS name&quot;, &quot;OS flavor&quot;, &quot;OS SP&quot;, &quot;OS lang&quot;, &quot;Updated&quot;, &quot;Purpose&quot;, &quot;Info&quot;}&#xa; , &quot;hosts&quot;,new String[]{&quot;created_at&quot;, &quot;address&quot;, &quot;address6&quot;, &quot;mac&quot;, &quot;name&quot;, &quot;state&quot;, &quot;os_name&quot;, &quot;os_flavor&quot;, &quot;os_sp&quot;, &quot;os_lang&quot;, &quot;updated_at&quot;, &quot;purpose&quot;, &quot;info&quot;})"/>
</AuxValues> </AuxValues>
</Component> </Component>
</SubComponents> </SubComponents>
@ -161,7 +161,7 @@
<EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="clientsTableKeyReleased"/> <EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="clientsTableKeyReleased"/>
</Events> </Events>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(new String [] {&#xa; &quot;Host&quot;, &quot;UA String&quot;, &quot;UA Name&quot;, &quot;UA Ver&quot;, &quot;Created&quot;, &quot;Updated&quot;&#xa; })"/> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(rpcConn, new String [] {&quot;Host&quot;, &quot;UA String&quot;, &quot;UA Name&quot;, &quot;UA Ver&quot;, &quot;Created&quot;, &quot;Updated&quot;}&#xa; , &quot;clients&quot;, new String[]{&quot;host&quot;, &quot;ua_string&quot;, &quot;ua_name&quot;, &quot;ua_ver&quot;, &quot;created_at&quot;, &quot;updated_at&quot;})"/>
</AuxValues> </AuxValues>
</Component> </Component>
</SubComponents> </SubComponents>
@ -191,7 +191,7 @@
<EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="servicesTableKeyReleased"/> <EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="servicesTableKeyReleased"/>
</Events> </Events>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(new String [] {&#xa; &quot;Host&quot;, &quot;Created&quot;, &quot;Updated&quot;, &quot;Port&quot;, &quot;Proto&quot;, &quot;State&quot;, &quot;Name&quot;, &quot;Info&quot;&#xa; })"/> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(rpcConn, new String [] {&quot;Host&quot;, &quot;Created&quot;, &quot;Updated&quot;, &quot;Port&quot;, &quot;Proto&quot;, &quot;State&quot;, &quot;Name&quot;, &quot;Info&quot;}&#xa;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;, &quot;services&quot;, new String[]{&quot;host&quot;, &quot;created_at&quot;, &quot;updated_at&quot;, &quot;port&quot;, &quot;proto&quot;, &quot;state&quot;, &quot;name&quot;, &quot;info&quot;})"/>
</AuxValues> </AuxValues>
</Component> </Component>
</SubComponents> </SubComponents>
@ -221,7 +221,7 @@
<EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="vulnsTableKeyReleased"/> <EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="vulnsTableKeyReleased"/>
</Events> </Events>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(new String [] {&#xa; &quot;Port&quot;, &quot;Proto&quot;, &quot;Time&quot;, &quot;Host&quot;, &quot;Name&quot;, &quot;Refs&quot;&#xa; })"/> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(rpcConn, new String [] {&quot;Port&quot;, &quot;Proto&quot;, &quot;Time&quot;, &quot;Host&quot;, &quot;Name&quot;, &quot;Refs&quot;&#xa;&#x9;&#x9;&#x9;&#x9;}, &quot;vulns&quot;, new String[]{&quot;port&quot;, &quot;proto&quot;, &quot;time&quot;, &quot;host&quot;, &quot;name&quot;, &quot;refs&quot;})"/>
</AuxValues> </AuxValues>
</Component> </Component>
</SubComponents> </SubComponents>
@ -251,7 +251,7 @@
<EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="notesTableKeyReleased"/> <EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="notesTableKeyReleased"/>
</Events> </Events>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(new String [] {&#xa; &quot;Time&quot;, &quot;Host&quot;, &quot;Service&quot;, &quot;Type&quot;, &quot;Data&quot;&#xa; })"/> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(rpcConn, new String [] {&quot;Time&quot;, &quot;Host&quot;, &quot;Service&quot;, &quot;Type&quot;, &quot;Data&quot;&#xa;&#x9;&#x9;&#x9;}, &quot;notes&quot;, new String[]{&quot;time&quot;, &quot;host&quot;, &quot;service&quot;, &quot;type&quot;, &quot;data&quot;})"/>
</AuxValues> </AuxValues>
</Component> </Component>
</SubComponents> </SubComponents>
@ -281,7 +281,7 @@
<EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="lootsTableKeyReleased"/> <EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="lootsTableKeyReleased"/>
</Events> </Events>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(new String [] {&#xa; &quot;Host&quot;, &quot;Service&quot;, &quot;Ltype&quot;, &quot;Ctype&quot;, &quot;Data&quot;, &quot;Created&quot;, &quot;Updated&quot;, &quot;Name&quot;, &quot;Info&quot;&#xa; })"/> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(rpcConn,new String [] {&quot;Host&quot;, &quot;Service&quot;, &quot;Ltype&quot;, &quot;Ctype&quot;, &quot;Data&quot;, &quot;Created&quot;, &quot;Updated&quot;, &quot;Name&quot;, &quot;Info&quot;&#xa;}, &quot;loots&quot;, new String[]{&quot;host&quot;, &quot;service&quot;, &quot;ltype&quot;, &quot;ctype&quot;, &quot;data&quot;, &quot;created_at&quot;, &quot;updated_at&quot;, &quot;name&quot;, &quot;info&quot;})"/>
</AuxValues> </AuxValues>
</Component> </Component>
</SubComponents> </SubComponents>
@ -308,7 +308,7 @@
<Property name="name" type="java.lang.String" value="credsTable" noResource="true"/> <Property name="name" type="java.lang.String" value="credsTable" noResource="true"/>
</Properties> </Properties>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(new String [] {&#xa; &quot;Host&quot;, &quot;Time&quot;, &quot;Port&quot;, &quot;Proto&quot;, &quot;Sname&quot;, &quot;Type&quot;, &quot;User&quot;, &quot;Pass&quot;, &quot;Active&quot;&#xa; })"/> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MsfTable(rpcConn, new String [] {&quot;Host&quot;, &quot;Time&quot;, &quot;Port&quot;, &quot;Proto&quot;, &quot;Sname&quot;, &quot;Type&quot;, &quot;User&quot;, &quot;Pass&quot;, &quot;Active&quot;&#xa; }, &quot;creds&quot;, new String[]{&quot;host&quot;, &quot;time&quot;, &quot;port&quot;, &quot;proto&quot;, &quot;sname&quot;, &quot;type&quot;, &quot;user&quot;, &quot;pass&quot;, &quot;active&quot;})"/>
</AuxValues> </AuxValues>
</Component> </Component>
</SubComponents> </SubComponents>

View File

@ -5,7 +5,6 @@ package msfgui;
import java.awt.Component; import java.awt.Component;
import java.awt.HeadlessException; import java.awt.HeadlessException;
import javax.swing.JTable;
import org.jdesktop.application.*; import org.jdesktop.application.*;
import java.awt.event.*; import java.awt.event.*;
import java.io.*; import java.io.*;
@ -26,7 +25,6 @@ import javax.swing.JMenu;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.application.Task; import org.jdesktop.application.Task;
import org.jdesktop.swingworker.SwingWorker; import org.jdesktop.swingworker.SwingWorker;
@ -48,14 +46,8 @@ public class MainFrame extends FrameView {
public MainFrame(SingleFrameApplication app) { public MainFrame(SingleFrameApplication app) {
super(app); super(app);
MsfFrame.setLnF(); MsfFrame.setLnF();
connectRpc(); // Connect to RPC daemon
initComponents(); initComponents();
eventsPane = new javax.swing.JScrollPane();
eventsTable = new MsfTable(new String [] {
"Host", "Created", "Updated", "Name", "Critical", "Username", "Info"
});
eventsTable.setName("eventsTable"); // NOI18N
eventsPane.setViewportView(eventsTable);
tabbedPane.addTab("Events", eventsPane); // NOI18N
sessionsTableModel = null; sessionsTableModel = null;
sessionWindowMap = new HashMap(); sessionWindowMap = new HashMap();
@ -121,14 +113,22 @@ public class MainFrame extends FrameView {
//Set up GUI, RPC connection, and recent modules //Set up GUI, RPC connection, and recent modules
setupSessionsPollTimer(); setupSessionsPollTimer();
setupPopupMenus(); setupPopupMenus();
if(rpcConn != null)
getModules();
MsfguiApp.fileChooser = new JFileChooser(); MsfguiApp.fileChooser = new JFileChooser();
connectRpc();
getFrame().addWindowListener(new WindowAdapter() { getFrame().addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) { public void windowClosing(WindowEvent we) {
if(!MsfguiApp.shuttingDown && !confirmStop()) if(!MsfguiApp.shuttingDown && !confirmStop())
throw new RuntimeException("Closing aborted."); throw new RuntimeException("Closing aborted.");
} }
}); });
//Events pane
eventsPane = new javax.swing.JScrollPane();
eventsTable = new MsfTable(rpcConn, new String [] {"Host", "Created", "Updated", "Name", "Critical", "Username", "Info"
}, "events", new String[]{"host","created_at","updated_at","name","critical","username", "info"});
eventsTable.setName("eventsTable"); // NOI18N
eventsPane.setViewportView(eventsTable);// Create a scrollable text area
tabbedPane.addTab("Events", eventsPane); // NOI18N
//Setup icon //Setup icon
this.getFrame().setIconImage( resourceMap.getImageIcon("main.icon").getImage()); this.getFrame().setIconImage( resourceMap.getImageIcon("main.icon").getImage());
//Disable tabs by default //Disable tabs by default
@ -147,6 +147,15 @@ public class MainFrame extends FrameView {
} }
} }
MsfFrame.updateSizes(getFrame()); MsfFrame.updateSizes(getFrame());
// Setup table autoquery code
((MsfTable)eventsTable).addAutoAdjuster(eventsPane);
((MsfTable)hostsTable).addAutoAdjuster(hostsPane);
((MsfTable)clientsTable).addAutoAdjuster(clientsPane);
((MsfTable)servicesTable).addAutoAdjuster(servicesPane);
((MsfTable)vulnsTable).addAutoAdjuster(vulnsPane);
((MsfTable)notesTable).addAutoAdjuster(notesPane);
((MsfTable)lootsTable).addAutoAdjuster(lootsPane);
((MsfTable)credsTable).addAutoAdjuster(credsPane);
} }
/** Before exit, check whether the daemon should be stopped or just the session terminated */ /** Before exit, check whether the daemon should be stopped or just the session terminated */
private boolean confirmStop() { private boolean confirmStop() {
@ -490,33 +499,26 @@ nameloop: for (int i = 0; i < names.length; i++) {
sessionsPane = new javax.swing.JScrollPane(); sessionsPane = new javax.swing.JScrollPane();
sessionsTable = new javax.swing.JTable(); sessionsTable = new javax.swing.JTable();
hostsPane = new javax.swing.JScrollPane(); hostsPane = new javax.swing.JScrollPane();
hostsTable = new MsfTable(new String [] { hostsTable = new MsfTable(rpcConn, new String [] {"Created", "Address", "Address6", "MAC", "Name", "State", "OS name", "OS flavor", "OS SP", "OS lang", "Updated", "Purpose", "Info"}
"Created", "Address", "Address6", "MAC", "Name", "State", "OS name", "OS flavor", "OS SP", "OS lang", "Updated", "Purpose", "Info" , "hosts",new String[]{"created_at", "address", "address6", "mac", "name", "state", "os_name", "os_flavor", "os_sp", "os_lang", "updated_at", "purpose", "info"});
});
clientsPane = new javax.swing.JScrollPane(); clientsPane = new javax.swing.JScrollPane();
clientsTable = new MsfTable(new String [] { clientsTable = new MsfTable(rpcConn, new String [] {"Host", "UA String", "UA Name", "UA Ver", "Created", "Updated"}
"Host", "UA String", "UA Name", "UA Ver", "Created", "Updated" , "clients", new String[]{"host", "ua_string", "ua_name", "ua_ver", "created_at", "updated_at"});
});
servicesPane = new javax.swing.JScrollPane(); servicesPane = new javax.swing.JScrollPane();
servicesTable = new MsfTable(new String [] { servicesTable = new MsfTable(rpcConn, new String [] {"Host", "Created", "Updated", "Port", "Proto", "State", "Name", "Info"}
"Host", "Created", "Updated", "Port", "Proto", "State", "Name", "Info" , "services", new String[]{"host", "created_at", "updated_at", "port", "proto", "state", "name", "info"});
});
vulnsPane = new javax.swing.JScrollPane(); vulnsPane = new javax.swing.JScrollPane();
vulnsTable = new MsfTable(new String [] { vulnsTable = new MsfTable(rpcConn, new String [] {"Port", "Proto", "Time", "Host", "Name", "Refs"
"Port", "Proto", "Time", "Host", "Name", "Refs" }, "vulns", new String[]{"port", "proto", "time", "host", "name", "refs"});
});
notesPane = new javax.swing.JScrollPane(); notesPane = new javax.swing.JScrollPane();
notesTable = new MsfTable(new String [] { notesTable = new MsfTable(rpcConn, new String [] {"Time", "Host", "Service", "Type", "Data"
"Time", "Host", "Service", "Type", "Data" }, "notes", new String[]{"time", "host", "service", "type", "data"});
});
lootsPane = new javax.swing.JScrollPane(); lootsPane = new javax.swing.JScrollPane();
lootsTable = new MsfTable(new String [] { lootsTable = new MsfTable(rpcConn,new String [] {"Host", "Service", "Ltype", "Ctype", "Data", "Created", "Updated", "Name", "Info"
"Host", "Service", "Ltype", "Ctype", "Data", "Created", "Updated", "Name", "Info" }, "loots", new String[]{"host", "service", "ltype", "ctype", "data", "created_at", "updated_at", "name", "info"});
});
credsPane = new javax.swing.JScrollPane(); credsPane = new javax.swing.JScrollPane();
credsTable = new MsfTable(new String [] { credsTable = new MsfTable(rpcConn, new String [] {"Host", "Time", "Port", "Proto", "Sname", "Type", "User", "Pass", "Active"
"Host", "Time", "Port", "Proto", "Sname", "Type", "User", "Pass", "Active" }, "creds", new String[]{"host", "time", "port", "proto", "sname", "type", "user", "pass", "active"});
});
menuBar = new javax.swing.JMenuBar(); menuBar = new javax.swing.JMenuBar();
javax.swing.JMenu fileMenu = new javax.swing.JMenu(); javax.swing.JMenu fileMenu = new javax.swing.JMenu();
connectRpcMenuItem = new javax.swing.JMenuItem(); connectRpcMenuItem = new javax.swing.JMenuItem();
@ -1191,7 +1193,6 @@ nameloop: for (int i = 0; i < names.length; i++) {
helpMenu.add(onlineHelpMenu); helpMenu.add(onlineHelpMenu);
aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
aboutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
aboutMenuItem.setName("aboutMenuItem"); // NOI18N aboutMenuItem.setName("aboutMenuItem"); // NOI18N
helpMenu.add(aboutMenuItem); helpMenu.add(aboutMenuItem);
@ -1242,6 +1243,8 @@ nameloop: for (int i = 0; i < names.length; i++) {
private void connectRpcMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectRpcMenuItemActionPerformed private void connectRpcMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectRpcMenuItemActionPerformed
connectRpc(); connectRpc();
if(rpcConn != null)
getModules();
}//GEN-LAST:event_connectRpcMenuItemActionPerformed }//GEN-LAST:event_connectRpcMenuItemActionPerformed
private void clearHistoryItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearHistoryItemActionPerformed private void clearHistoryItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearHistoryItemActionPerformed
@ -1318,19 +1321,14 @@ nameloop: for (int i = 0; i < names.length; i++) {
} }
try { //Now load data out of current workspace try { //Now load data out of current workspace
MsfguiApp.workspace = ((Map) rpcConn.execute("db.current_workspace")).get("workspace").toString(); MsfguiApp.workspace = ((Map) rpcConn.execute("db.current_workspace")).get("workspace").toString();
if(DraggableTabbedPane.isVisible(eventsTable)) ((MsfTable)eventsTable).reAddQuery(all, 0);
reAdd(eventsTable,(List) ((Map)rpcConn.execute("db.events",MsfguiApp.workspace)).get("events"), ((MsfTable)lootsTable).reAddQuery(all, 0);
new String[]{"host","created_at","updated_at","name","critical","username","info"}); ((MsfTable)hostsTable).reAddQuery(all, 0);
if(all || DraggableTabbedPane.isVisible(lootsTable)) ((MsfTable)clientsTable).reAddQuery(all, 0);
reAdd(lootsTable,(List) ((Map)rpcConn.execute("db.loots",MsfguiApp.workspace)).get("loots"), ((MsfTable)servicesTable).reAddQuery(all, 0);
new String[]{"host","service","ltype","ctype","data","created_at","updated_at","name","info"}); ((MsfTable)vulnsTable).reAddQuery(all, 0);
reAddQuery(hostsTable,"hosts",new String[]{"created_at","address","address6","mac","name","state","os_name", ((MsfTable)notesTable).reAddQuery(all, 0);
"os_flavor","os_sp","os_lang","updated_at","purpose","info"}, all); ((MsfTable)credsTable).reAddQuery(all, 0);
reAddQuery(clientsTable,"clients",new String[]{"host","ua_string","ua_name","ua_ver","created_at","updated_at"}, all);
reAddQuery(servicesTable, "services", new String[]{"host","created_at","updated_at","port","proto","state","name","info"}, all);
reAddQuery(vulnsTable,"vulns",new String[]{"port","proto","time","host","name","refs"}, all);
reAddQuery(notesTable,"notes",new String[]{"time", "host", "service", "type", "data"}, all);
reAddQuery(credsTable,"creds",new String[]{"host", "time", "port", "proto", "sname", "type", "user", "pass", "active"}, all);
} catch (MsfException mex) { } catch (MsfException mex) {
if(!mex.getMessage().equals("database not loaded")) if(!mex.getMessage().equals("database not loaded"))
mex.printStackTrace(); mex.printStackTrace();
@ -1440,7 +1438,7 @@ nameloop: for (int i = 0; i < names.length; i++) {
reloadDb(false); reloadDb(false);
if(evt.getKeyCode() != KeyEvent.VK_DELETE) if(evt.getKeyCode() != KeyEvent.VK_DELETE)
return; return;
JTable tab = (JTable)evt.getSource(); MsfTable tab = (MsfTable)evt.getSource();
for(int row : tab.getSelectedRows()){ for(int row : tab.getSelectedRows()){
try { try {
HashMap map = new HashMap(); HashMap map = new HashMap();
@ -1451,7 +1449,7 @@ nameloop: for (int i = 0; i < names.length; i++) {
MsfguiApp.showMessage(getFrame(), mex); MsfguiApp.showMessage(getFrame(), mex);
} }
}//delete then readd }//delete then readd
reAddQuery(tab,name+"s",colNames, true); tab.reAddQuery(true, 0);
} }
private void hostsTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_hostsTableKeyReleased private void hostsTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_hostsTableKeyReleased
tableDelCheck(evt,"host",new String[]{"created_at","address","address6","mac","name","state","os_name", tableDelCheck(evt,"host",new String[]{"created_at","address","address6","mac","name","state","os_name",
@ -1471,7 +1469,7 @@ nameloop: for (int i = 0; i < names.length; i++) {
}//GEN-LAST:event_notesTableKeyReleased }//GEN-LAST:event_notesTableKeyReleased
private void lootsTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lootsTableKeyReleased private void lootsTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lootsTableKeyReleased
reAddQuery(lootsTable,"loots",new String[]{"host","service","ltype","ctype","data","created_at","updated_at","name","info"}, true); ((MsfTable)lootsTable).reAddQuery(true, 0);
}//GEN-LAST:event_lootsTableKeyReleased }//GEN-LAST:event_lootsTableKeyReleased
private void clientsTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_clientsTableKeyReleased private void clientsTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_clientsTableKeyReleased
@ -1623,8 +1621,6 @@ nameloop: for (int i = 0; i < names.length; i++) {
private void connectRpc() { private void connectRpc() {
//make new rpcConnection //make new rpcConnection
rpcConn = OpenConnectionDialog.getConnection(this); rpcConn = OpenConnectionDialog.getConnection(this);
if(rpcConn != null)
getModules();
} }
/** Attempts to start msfrpcd and connect to it.*/ /** Attempts to start msfrpcd and connect to it.*/
@ -1974,35 +1970,4 @@ nameloop: for (int i = 0; i < names.length; i++) {
private final Icon[] busyIcons = new Icon[15]; private final Icon[] busyIcons = new Icon[15];
private int busyIconIndex = 0; private int busyIconIndex = 0;
private JDialog aboutBox; private JDialog aboutBox;
/** Clear a table's contents, reenabling the tab, and replace with contents of data returned from a db call */
private void reAddQuery(JTable table, String call, String[] cols, boolean force) {
if(!force && !DraggableTabbedPane.isVisible(table))
return; //Don't re-add if not visible
try {
HashMap arg = new HashMap();
arg.put("workspace", MsfguiApp.workspace);
List data = (List) ((Map)rpcConn.execute("db."+call,arg)).get(call);
if(data == null)
return;
reAdd(table, data, cols);
} catch (MsfException mex) {
mex.printStackTrace();
if(mex.getMessage().equals("database not loaded"))
throw mex;
}
}
private void reAdd(JTable table, List data, String[] cols) throws MsfException {
DefaultTableModel mod = (DefaultTableModel) table.getModel();
while (mod.getRowCount() > 0)
mod.removeRow(0);
for (Object dataObj : data) {
Object[] row = new Object[cols.length];
for (int i = 0; i < cols.length; i++)
row[i] = ((Map) dataObj).get(cols[i]);
mod.addRow(row);
}
TableHelper.fitColumnWidths(mod, table);
DraggableTabbedPane.setTabComponentEnabled(table, true);
}
} }

View File

@ -1,12 +1,19 @@
package msfgui; package msfgui;
import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants; import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableModel;
/** /**
* Table customization defaults to non-editable, autosorted table with some preferences * Table customization defaults to non-editable, autosorted table with some preferences
@ -16,11 +23,17 @@ import javax.swing.ScrollPaneConstants;
* @author scriptjunkie * @author scriptjunkie
*/ */
public class MsfTable extends javax.swing.JTable { public class MsfTable extends javax.swing.JTable {
private final String[] dbNames;
private final String dbTable;
private final RpcConnection rpcConn;
/** /**
* Default constructor just takes column names * Default constructor just takes column names
* @param colnames The names of the columns in the table * @param colnames The names of the columns in the table
*/ */
public MsfTable(String[] colnames){ public MsfTable(final RpcConnection rpcConn, String[] colnames, String dbTable, String[] dbNames){
this.dbNames = dbNames;
this.dbTable = dbTable;
this.rpcConn = rpcConn;
setModel(new javax.swing.table.DefaultTableModel(new Object [][] {}, colnames) { setModel(new javax.swing.table.DefaultTableModel(new Object [][] {}, colnames) {
public Class getColumnClass(int columnIndex) { public Class getColumnClass(int columnIndex) {
try{ try{
@ -60,4 +73,54 @@ public class MsfTable extends javax.swing.JTable {
} }
} ); } );
} }
/** Automatically query more info on new data */
public void addAutoAdjuster(final JScrollPane pane){
//Add autoadjuster to get more DB info
pane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent evt) {
java.awt.Adjustable adj = evt.getAdjustable();
if(evt.getValueIsAdjusting() || adj.getValue() + adj.getVisibleAmount() != adj.getMaximum())
return;
Component source = ((Component)evt.getSource());
while(!(source instanceof JScrollPane))
source = source.getParent();
int rowCount = getRowCount();
if(rowCount == 0 || (getRowCount() % 100) != 0)
return;
reAddQuery(false, rowCount);
}
});
}
/** Clear a table's contents, reenabling the tab, and replace with contents of data returned from a db call */
public void reAddQuery(boolean force, int offset) {
if(!force && !DraggableTabbedPane.isVisible(this))
return; //Don't re-add if not visible
try {
HashMap arg = new HashMap(10);
arg.put("workspace", MsfguiApp.workspace);
arg.put("offset", offset);
List data = (List) ((Map)rpcConn.execute("db."+dbTable, arg)).get(dbTable);
if(data == null)
return;
DefaultTableModel mod = (DefaultTableModel) getModel();
while (mod.getRowCount() > offset)
mod.removeRow(mod.getRowCount() - 1);
for (Object dataObj : data) {
Object[] row = new Object[dbNames.length];
for (int i = 0; i < dbNames.length; i++){
row[i] = ((Map) dataObj).get(dbNames[i]);
if(dbNames[i].endsWith("_at"))
row[i] = new java.util.Date(Long.parseLong(row[i].toString()) * 1000);
}
mod.addRow(row);
}
TableHelper.fitColumnWidths(mod, this);
DraggableTabbedPane.setTabComponentEnabled(this, true);
} catch (MsfException mex) {
mex.printStackTrace();
if(mex.getMessage().equals("database not loaded"))
throw mex;
}
}
} }

View File

@ -9,7 +9,7 @@ private
def find_workspace(wspace = nil) def find_workspace(wspace = nil)
if(wspace and wspace != "") if(wspace and wspace != "")
return self.framework.db.find_workspace(wspace) return self.framework.db.find_workspace(wspace) || error(500, "Invalid workspace")
end end
self.framework.db.workspace self.framework.db.workspace
end end
@ -74,23 +74,29 @@ private
error(500, "Database Not Loaded") if not db error(500, "Database Not Loaded") if not db
end end
def init_db_opts_workspace(xopts)
db_check
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace])
return opts, opts[:workspace]
end
public public
def rpc_hosts(xopts) def rpc_hosts(xopts)
opts, wspace = init_db_opts_workspace(xopts)
db_check
opts = fix_options(xopts)
conditions = {} conditions = {}
conditions[:state] = [Msf::HostState::Alive, Msf::HostState::Unknown] if opts[:only_up] conditions[:state] = [Msf::HostState::Alive, Msf::HostState::Unknown] if opts[:only_up]
conditions[:address] = opts[:addresses] if opts[:addresses] conditions[:address] = opts[:addresses] if opts[:addresses]
wspace = find_workspace(opts[:workspace]) limit = opts.delete(:limit) || 100
offset = opts.delete(:offset) || 0
ret = {} ret = {}
ret[:hosts] = [] ret[:hosts] = []
wspace.hosts.all(:conditions => conditions, :order => :address).each do |h| wspace.hosts.all(:conditions => conditions, :order => :address,
:limit => limit, :offset => offset).each do |h|
host = {} host = {}
host[:created_at] = h.created_at.to_i host[:created_at] = h.created_at.to_i
host[:address] = h.address.to_s host[:address] = h.address.to_s
@ -111,48 +117,22 @@ public
end end
def rpc_services( xopts) def rpc_services( xopts)
opts, wspace = init_db_opts_workspace(xopts)
limit = opts.delete(:limit) || 100
offset = opts.delete(:offset) || 0
db_check
opts = fix_options(xopts)
wspace = find_workspace(opts[:workspace])
opts[:workspace] = wspace if opts[:workspace]
hosts = []
if opts[:addresses]
conditions = {} conditions = {}
conditions[:address] = opts[:addresses] if opts[:addresses] conditions[:state] = [ServiceState::Open] if opts[:only_up]
hosts = wspace.hosts.all(:conditions => conditions, :order => :address) conditions[:proto] = opts[:proto] if opts[:proto]
elsif opts[:host] || opts[:address] conditions["hosts.address"] = opts[:addresses] if opts[:addresses]
host = self.framework.db.get_host(opts) conditions[:port] = Rex::Socket.portspec_to_portlist(opts[:ports]) if opts[:ports]
hosts << host conditions[:name] = opts[:names].strip().split(",") if opts[:names]
end
ret = {} ret = {}
ret[:services] = [] ret[:services] = []
a = self.framework.db.get_host(opts) wspace.services.all(:include => :host, :conditions => conditions,
:limit => limit, :offset => offset).each do |s|
services = []
if opts[:host] || opts[:address] || opts[:addresses]
hosts.each do |host|
sret = nil
if(opts[:proto] && opts[:port])
sret = host.services.find_by_proto_and_port(opts[:proto], opts[:port])
else
sret = host.services
end
next if sret == nil
services << sret if sret.class == Msf::DBManager::Service
services |= sret if sret.class == Array
end
else
services = wspace.services
end
return ret if (not services)
services.each do |s|
service = {} service = {}
host = s.host host = s.host
service[:host] = host.address || host.address6 || "unknown" service[:host] = host.address || host.address6 || "unknown"
@ -168,79 +148,20 @@ public
ret ret
end end
def rpc_vulns(xopts) def rpc_vulns(xopts)
opts, wspace = init_db_opts_workspace(xopts)
limit = opts.delete(:limit) || 100
offset = opts.delete(:offset) || 0
db_check conditions = {}
conditions["hosts.address"] = opts[:addresses] if opts[:addresses]
opts = fix_options(xopts) conditions[:name] = opts[:names].strip().split(",") if opts[:names]
wspace = find_workspace(opts[:workspace]) conditions["services.port"] = Rex::Socket.portspec_to_portlist(opts[:ports]) if opts[:port]
opts[:workspace] = wspace if opts[:workspace] conditions["services.proto"] = opts[:proto] if opts[:proto]
ret = {} ret = {}
ret[:vulns] = [] ret[:vulns] = []
hosts = [] wspace.vulns.all(:include => :service, :conditions => conditions, :limit => limit, :offset => offset).each do |v|
services = []
vulns = []
# Get Matching Hosts
if opts[:addresses]
conditions = {}
conditions[:address] = opts[:addresses] if opts[:addresses]
hosts = wspace.hosts.all(:conditions => conditions, :order => :address)
elsif opts[:host] || opts[:address]
host = self.framework.db.get_host(opts)
hosts << host
end
#Get Matching Services
if opts[:host] || opts[:address] || opts[:addresses]
hosts.each do |host|
sret = nil
if(opts[:proto] && opts[:port])
sret = host.services.find_by_proto_and_port(opts[:proto], opts[:port])
else
sret = host.services
end
next if sret == nil
services << sret if sret.class == Msf::DBManager::Service
services |= sret if sret.class == Array
end
elsif opts[:port] && opts[:proto]
sret = wspace.services.find_by_proto_and_port(opts[:proto],opts[:port])
services << sret if sret.class == Msf::DBManager::Service
services |= sret if sret.class == Array
end
#get list of vulns
if services.count > 0
services.each do |s|
if opts[:name]
nret = s.vulns.find_by_name(opts[:name])
else
nret = s.vulns
end
next if nret == nil
vulns << nret if nret.class == Msf::DBManager::Vuln
vulns |= nret if nret.class == Array
end
elsif hosts.count > 0
hosts.each do |h|
if opts[:name]
nret = h.vulns.find_by_name(opts[:name])
else
nret = h.vulns
end
next if nret == nil
vulns << nret if nret.class == Msf::DBManager::Vuln
vulns |= nret if nret.class == Array
end
else
nret = wspace.vulns
vulns << nret if nret.class == Msf::DBManager::Vuln
vulns |= nret if nret.class == Array
end
vulns.each do |v|
vuln = {} vuln = {}
reflist = v.refs.map { |r| r.name } reflist = v.refs.map { |r| r.name }
if(v.service) if(v.service)
@ -330,12 +251,11 @@ public
end end
def rpc_get_host(xopts) def rpc_get_host(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
ret = {} ret = {}
ret[:host] = [] ret[:host] = []
opts = fix_options(xopts) opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
h = self.framework.db.get_host(opts) h = self.framework.db.get_host(opts)
if(h) if(h)
host = {} host = {}
@ -358,9 +278,7 @@ public
end end
def rpc_report_host(xopts) def rpc_report_host(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
res = self.framework.db.report_host(opts) res = self.framework.db.report_host(opts)
return { :result => 'success' } if(res) return { :result => 'success' } if(res)
@ -369,19 +287,14 @@ public
end end
def rpc_report_service(xopts) def rpc_report_service(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
res = self.framework.db.report_service(opts) res = self.framework.db.report_service(opts)
return { :result => 'success' } if(res) return { :result => 'success' } if(res)
{ :result => 'failed' } { :result => 'failed' }
end end
def rpc_get_service(xopts) def rpc_get_service(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
wspace = find_workspace(opts[:workspace])
opts[:workspace] = wspace if opts[:workspace]
ret = {} ret = {}
ret[:service] = [] ret[:service] = []
@ -425,10 +338,7 @@ public
end end
def rpc_get_note(xopts) def rpc_get_note(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
ret = {} ret = {}
ret[:note] = [] ret[:note] = []
@ -478,9 +388,7 @@ public
end end
def rpc_get_client(xopts) def rpc_get_client(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
ret = {} ret = {}
ret[:client] = [] ret[:client] = []
c = self.framework.db.get_client(opts) c = self.framework.db.get_client(opts)
@ -499,9 +407,7 @@ public
end end
def rpc_report_client(xopts) def rpc_report_client(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
res = self.framework.db.report_client(opts) res = self.framework.db.report_client(opts)
return { :result => 'success' } if(res) return { :result => 'success' } if(res)
{ :result => 'failed' } { :result => 'failed' }
@ -509,9 +415,7 @@ public
#DOC NOTE: :data and :ntype are REQUIRED #DOC NOTE: :data and :ntype are REQUIRED
def rpc_report_note(xopts) def rpc_report_note(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
if (opts[:host] or opts[:address]) and opts[:port] and opts[:proto] if (opts[:host] or opts[:address]) and opts[:port] and opts[:proto]
addr = opts[:host] || opts[:address] addr = opts[:host] || opts[:address]
wspace = opts[:workspace] || self.framework.db.workspace wspace = opts[:workspace] || self.framework.db.workspace
@ -526,76 +430,21 @@ public
end end
def rpc_notes(xopts) def rpc_notes(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts) limit = opts.delete(:limit) || 100
wspace = find_workspace(opts[:workspace]) if opts[:workspace] offset = opts.delete(:offset) || 0
opts[:workspace] = wspace
conditions = {}
conditions["hosts.address"] = opts[:addresses] if opts[:addresses]
conditions[:name] = opts[:names].strip().split(",") if opts[:names]
conditions[:ntype] = opts[:ntype] if opts[:ntype]
conditions["services.port"] = Rex::Socket.portspec_to_portlist(opts[:ports]) if opts[:port]
conditions["services.proto"] = opts[:proto] if opts[:proto]
ret = {} ret = {}
ret[:notes] = [] ret[:notes] = []
hosts = [] wspace.notes.all(:include => [:host, :service], :conditions => conditions,
services = [] :limit => limit, :offset => offset).each do |n|
notes = []
# Get Matching Hosts
if opts[:addresses]
conditions = {}
conditions[:address] = opts[:addresses] if opts[:addresses]
hosts = wspace.hosts.all(:conditions => conditions, :order => :address)
elsif opts[:host] || opts[:address]
host = self.framework.db.get_host(opts)
hosts << host
end
#Get Matching Services
if opts[:host] || opts[:address] || opts[:addresses]
hosts.each do |host|
sret = nil
if(opts[:proto] && opts[:port])
sret = host.services.find_by_proto_and_port(opts[:proto], opts[:port])
else
sret = host.services
end
next if sret == nil
services << sret if sret.class == Msf::DBManager::Service
services |= sret if sret.class == Array
end
elsif opts[:port] && opts[:proto]
sret = wspace.services.find_by_proto_and_port(opts[:proto],opts[:port])
services << sret if sret.class == Msf::DBManager::Service
services |= sret if sret.class == Array
end
#get list of notes
if services.count > 0
services.each do |s|
if opts[:ntype]
nret = s.notes.find_by_ntype(opts[:ntype])
else
nret = s.notes
end
next if nret == nil
notes << nret if nret.class == Msf::DBManager::Note
notes |= nret if nret.class == Array
end
elsif hosts.count > 0
hosts.each do |h|
if opts[:ntype]
nret = h.notes.find_by_ntype(opts[:ntype])
else
nret = h.notes
end
next if nret == nil
notes << nret if nret.class == Msf::DBManager::Note
notes |= nret if nret.class == Array
end
else
nret = wspace.notes
notes << nret if nret.class == Msf::DBManager::Note
notes |= nret if nret.class == Array
end
notes.each do |n|
note = {} note = {}
note[:time] = n.created_at.to_i note[:time] = n.created_at.to_i
note[:host] = "" note[:host] = ""
@ -610,18 +459,14 @@ public
end end
def rpc_report_auth_info(xopts) def rpc_report_auth_info(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
res = self.framework.db.report_auth_info(opts) res = self.framework.db.report_auth_info(opts)
return { :result => 'success' } if(res) return { :result => 'success' } if(res)
{ :result => 'failed' } { :result => 'failed' }
end end
def rpc_get_auth_info(xopts) def rpc_get_auth_info(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
ret = {} ret = {}
ret[:auth_info] = [] ret[:auth_info] = []
ai = self.framework.db.get_auth_info(opts) ai = self.framework.db.get_auth_info(opts)
@ -641,9 +486,7 @@ public
end end
def rpc_del_vuln(xopts) def rpc_del_vuln(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
wspace = find_workspace(opts[:workspace])
hosts = [] hosts = []
services = [] services = []
vulns = [] vulns = []
@ -710,9 +553,7 @@ public
end end
def rpc_del_note(xopts) def rpc_del_note(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
wspace = find_workspace(opts[:workspace])
hosts = [] hosts = []
services = [] services = []
notes = [] notes = []
@ -778,9 +619,7 @@ public
end end
def rpc_del_service(xopts) def rpc_del_service(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
wspace = find_workspace(opts[:workspace])
hosts = [] hosts = []
services = [] services = []
if opts[:host] or opts[:address] if opts[:host] or opts[:address]
@ -860,7 +699,6 @@ public
return { :result => 'success', :deleted => deleted } return { :result => 'success', :deleted => deleted }
end end
def rpc_report_vuln(xopts) def rpc_report_vuln(xopts)
db_check db_check
opts = fix_options(xopts) opts = fix_options(xopts)
@ -870,15 +708,15 @@ public
{ :result => 'failed' } { :result => 'failed' }
end end
def rpc_events(xopts)
opts, wspace = init_db_opts_workspace(xopts)
limit = opts.delete(:limit) || 100
offset = opts.delete(:offset) || 0
def rpc_events(wspace = nil)
db_check
wspace = find_workspace(wspace)
error(500, "Unknown Workspace") if(not wspace)
ret = {} ret = {}
ret[:events] = [] ret[:events] = []
self.framework.db.events(wspace).each do |e| wspace.events.all(:limit => limit, :offset => offset).each do |e|
event = {} event = {}
event[:host] = e.host.address || e.host.address6 if(e.host) event[:host] = e.host.address || e.host.address6 if(e.host)
event[:created_at] = e.created_at.to_i event[:created_at] = e.created_at.to_i
@ -893,9 +731,7 @@ public
end end
def rpc_report_event(xopts) def rpc_report_event(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
res = self.framework.db.report_event(opts) res = self.framework.db.report_event(opts)
{ :result => 'success' } if(res) { :result => 'success' } if(res)
end end
@ -903,8 +739,7 @@ public
#NOTE Path is required #NOTE Path is required
#NOTE To match a service need host, port, proto #NOTE To match a service need host, port, proto
def rpc_report_loot(xopts) def rpc_report_loot(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
if opts[:host] && opts[:port] && opts[:proto] if opts[:host] && opts[:port] && opts[:proto]
opts[:service] = self.framework.db.find_or_create_service(opts) opts[:service] = self.framework.db.find_or_create_service(opts)
end end
@ -913,14 +748,14 @@ public
{ :result => 'success' } if(res) { :result => 'success' } if(res)
end end
def rpc_loots(wspace=nil) def rpc_loots(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
wspace = find_workspace(wspace) limit = opts.delete(:limit) || 100
error(500, "Unknown Workspace") if(not wspace) offset = opts.delete(:offset) || 0
ret = {} ret = {}
ret[:loots] = [] ret[:loots] = []
self.framework.db.loots(wspace).each do |l| wspace.loots.all(:limit => limit, :offset => offset).each do |l|
loot = {} loot = {}
loot[:host] = l.host.address || l.host.address6 if(l.host) loot[:host] = l.host.address || l.host.address6 if(l.host)
loot[:service] = l.service.name || n.service.port if(n.service) loot[:service] = l.service.name || n.service.port if(n.service)
@ -938,8 +773,7 @@ public
# requires host, port, user, pass, ptype, and active # requires host, port, user, pass, ptype, and active
def rpc_report_cred(xopts) def rpc_report_cred(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
res = framework.db.find_or_create_cred(opts) res = framework.db.find_or_create_cred(opts)
return { :result => 'success' } if res return { :result => 'success' } if res
{ :result => 'failed' } { :result => 'failed' }
@ -947,15 +781,17 @@ public
#right now workspace is the only option supported #right now workspace is the only option supported
def rpc_creds(xopts) def rpc_creds(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts) limit = opts.delete(:limit) || 100
wspace = find_workspace(opts[:workspace]) offset = opts.delete(:offset) || 0
ret = {} ret = {}
ret[:creds] = [] ret[:creds] = []
self.framework.db.creds(wspace).each do |c| DBManager::Cred.find(:all, :include => {:service => :host}, :conditions => ["hosts.workspace_id = ?",
framework.db.workspace.id ], :limit => limit, :offset => offset).each do |c|
cred = {} cred = {}
cred[:host] = c.service.host.address || c.service.host.address6 if(c.service.host) cred[:host] = c.service.host.address || c.service.host.address6 if(c.service.host)
cred[:time] = c.updated_at cred[:updated_at] = c.updated_at.to_i
cred[:port] = c.service.port cred[:port] = c.service.port
cred[:proto] = c.service.proto cred[:proto] = c.service.proto
cred[:sname] = c.service.name cred[:sname] = c.service.name
@ -969,17 +805,13 @@ public
end end
def rpc_import_data(xopts) def rpc_import_data(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
self.framework.db.import(opts) self.framework.db.import(opts)
return { :result => 'success' } return { :result => 'success' }
end end
def rpc_get_vuln(xopts) def rpc_get_vuln(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts)
opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
ret = {} ret = {}
ret[:vuln] = [] ret[:vuln] = []
@ -1027,35 +859,20 @@ public
end end
def rpc_clients(xopts) def rpc_clients(xopts)
db_check opts, wspace = init_db_opts_workspace(xopts)
opts = fix_options(xopts) limit = opts.delete(:limit) || 100
wspace = find_workspace(opts[:workspace]) offset = opts.delete(:offset) || 0
hosts = []
clients = []
ret = {}
ret[:clients] = []
if opts[:host] or opts[:address] or opts[:addresses]
hosts = opts_to_hosts(opts)
else
hosts = wspace.hosts
end
hosts.each do |h|
cret = nil
if opts[:ua_name] or opts[:ua_ver]
conditions = {} conditions = {}
conditions[:ua_name] = opts[:ua_name] if opts[:ua_name] conditions[:ua_name] = opts[:ua_name] if opts[:ua_name]
conditions[:ua_ver] = opts[:ua_ver] if opts[:ua_ver] conditions[:ua_ver] = opts[:ua_ver] if opts[:ua_ver]
cret = h.clients.all(:conditions => conditions) conditions["hosts.address"] = opts[:addresses] if opts[:addresses]
else
cret = h.clients ret = {}
end ret[:clients] = []
next if cret == nil
clients << cret if cret.class == Msf::DBManager::Client wspace.clients.all(:include => :host, :conditions => conditions,
clients |= cret if cret.class == Array :limit => limit, :offset => offset).each do |c|
end
clients.each do |c|
client = {} client = {}
client[:host] = c.host.address.to_s if c.host client[:host] = c.host.address.to_s if c.host
client[:ua_string] = c.ua_string client[:ua_string] = c.ua_string