[seedsofcontempt] r111 committed - improved the target visual...

1 view
Skip to first unread message

codesite...@google.com

unread,
Sep 29, 2009, 2:05:48 AM9/29/09
to seedsof...@googlegroups.com
Revision: 111
Author: pierce403
Date: Mon Sep 28 23:04:48 2009
Log: improved the target visual
made a nifty remote network visual
http://code.google.com/p/seedsofcontempt/source/detail?r=111

Modified:
/trunk/build.properties
/trunk/src/soc/contempt/data/SeedConnection.java
/trunk/src/soc/contempt/dialogs/ProvisionDialog.java
/trunk/src/soc/contempt/dialogs/StartSeedDialog.java
/trunk/src/soc/contempt/visuals/AssetsVisual.java
/trunk/src/soc/contempt/visuals/RemoteNetworkVisual.java
/trunk/src/soc/contempt/visuals/TargetsVisual.java
/trunk/src/soc/seed/DataSeedInterface.java
/trunk/src/soc/seed/data/SQLiteDataSeed.java
/trunk/src/soc/seed/seeds/NmapSeed.java
/trunk/src/soc/seed/seeds/TeamSeed.java

=======================================
--- /trunk/build.properties Thu Sep 24 15:10:40 2009
+++ /trunk/build.properties Mon Sep 28 23:04:48 2009
@@ -4,14 +4,10 @@
introContent.xml,\
intro.xhtml,\
icons/,\
- thirdparty/prefuse.jar,\
thirdparty/sqlitejdbc-v054-pure.jar,\
- thirdparty/core.jar,\
contempt.product,\
seedsofcontempt.product,\
contempt.jar,\
- bin/SeedServer.jar,\
- bin/TeamSeed.jar,\
plugin_customization.ini
jars.compile.order = thirdparty/prefuse.jar,\
thirdparty/derby.jar,\
=======================================
--- /trunk/src/soc/contempt/data/SeedConnection.java Thu Sep 24 15:10:40
2009
+++ /trunk/src/soc/contempt/data/SeedConnection.java Mon Sep 28 23:04:48
2009
@@ -188,9 +188,7 @@

public boolean connect()
{
- System.out.println("attempting to connect from the back 1");
if(connected==true)return true;
- System.out.println("attempting to connect from the back 2");

SslRMIClientSocketFactory csf=new SslRMIClientSocketFactory();

@@ -199,7 +197,6 @@
rmiRegistry=LocateRegistry.getRegistry(hostname,41414,csf);
managerSeed=(ManagerSeedInterface)rmiRegistry.lookup("ManagerSeed");
dataSeed=(DataSeedInterface)rmiRegistry.lookup("DataSeed");
- //managerSeed.addNotifier(notifier);
}
catch(Exception e)
{
=======================================
--- /trunk/src/soc/contempt/dialogs/ProvisionDialog.java Thu Sep 24
15:10:40 2009
+++ /trunk/src/soc/contempt/dialogs/ProvisionDialog.java Mon Sep 28
23:04:48 2009
@@ -2,6 +2,7 @@

import java.io.File;
import java.io.FileOutputStream;
+import java.io.InputStream;
import java.net.UnknownHostException;
import java.security.KeyStore;
import java.security.PrivateKey;
@@ -12,6 +13,8 @@
import java.sql.Statement;
import java.util.Date;

+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
@@ -24,10 +27,15 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

+import soc.contempt.Activator;
import soc.contempt.data.SeedConnector;
import sun.security.x509.CertAndKeyGen;
import sun.security.x509.X500Name;

+// responsible for:
+// generating keys for the server and the user
+// placing the default seeds in their proper location
+
public class ProvisionDialog extends Dialog
{
public String username=null;
@@ -136,6 +144,74 @@
return;
}

+ // Place the default seeds in their proper location
+ try
+ {
+ // place SeedServer.jar
+ File serverFile=new
File(SeedConnector.contemptPath+File.separator+"SeedServer.jar");
+ if(!serverFile.exists())
+ {
+ InputStream
inputStream=FileLocator.openStream(Activator.getDefault().getBundle(),new
Path("bin/SeedServer.jar"),false);
+
+ int len;
+ byte[] buf=new byte[1024];
+ FileOutputStream fos=new FileOutputStream(serverFile);
+ // write the file from the plugin to the contempt dir
+ while(-1!=(len=inputStream.read(buf)))fos.write(buf,0,len);
+ }
+
+ // place TeamSeed.jar and NmapSeed.jar in .contempt/seeds
+ File contemptSeedsDir=new
File(SeedConnector.contemptPath+File.separator+"seeds");
+ if(!contemptSeedsDir.exists())
+ {
+ int len;
+ byte[] buf=new byte[1024];
+ InputStream inputStream=null;
+ FileOutputStream fos=null;
+
+ contemptSeedsDir.mkdir();
+
+ File teamSeedFile=new
File(SeedConnector.contemptPath+File.separator+"seeds"+File.separator+"TeamSeed.jar");
+
inputStream=FileLocator.openStream(Activator.getDefault().getBundle(),new
Path("bin/TeamSeed.jar"),false);
+ fos=new FileOutputStream(teamSeedFile);
+ while(-1!=(len=inputStream.read(buf)))fos.write(buf,0,len);
+
+ File nmapSeedFile=new
File(SeedConnector.contemptPath+File.separator+"seeds"+File.separator+"NmapSeed.jar");
+
inputStream=FileLocator.openStream(Activator.getDefault().getBundle(),new
Path("bin/NmapSeed.jar"),false);
+ fos=new FileOutputStream(nmapSeedFile);
+ while(-1!=(len=inputStream.read(buf)))fos.write(buf,0,len);
+ }
+
+ // place TeamSeed.jar and NmapSeed.jar in .seed/seeds
+ File seedsDir=new
File(SeedConnector.contemptPath+File.separator+"seeds");
+ if(!seedsDir.exists())
+ {
+ int len;
+ byte[] buf=new byte[1024];
+ InputStream inputStream=null;
+ FileOutputStream fos=null;
+
+ seedsDir.mkdir();
+
+ File teamSeedFile=new
File(seedsDir.getPath()+File.separator+"TeamSeed.jar");
+
inputStream=FileLocator.openStream(Activator.getDefault().getBundle(),new
Path("bin/TeamSeed.jar"),false);
+ fos=new FileOutputStream(teamSeedFile);
+ while(-1!=(len=inputStream.read(buf)))fos.write(buf,0,len);
+
+ File nmapSeedFile=new
File(seedsDir.getPath()+File.separator+"NmapSeed.jar");
+
inputStream=FileLocator.openStream(Activator.getDefault().getBundle(),new
Path("bin/NmapSeed.jar"),false);
+ fos=new FileOutputStream(nmapSeedFile);
+ while(-1!=(len=inputStream.read(buf)))fos.write(buf,0,len);
+ }
+
+ }
+ catch(Exception e)
+ {
+ System.out.println("there was a problem writing the default seeds");
+ e.printStackTrace();
+ }
+
+
aborted=false;
super.okPressed();
}
=======================================
--- /trunk/src/soc/contempt/dialogs/StartSeedDialog.java Thu Sep 24
15:10:40 2009
+++ /trunk/src/soc/contempt/dialogs/StartSeedDialog.java Mon Sep 28
23:04:48 2009
@@ -54,50 +54,6 @@
public StartSeedDialog(Shell parent)
{
super(parent);
-
- // make sure seed files have been placed
- try
- {
- // place SeedServer.jar
- File serverFile=new
File(SeedConnector.contemptPath+File.separator+"SeedServer.jar");
- if(!serverFile.exists())
- {
- InputStream
inputStream=FileLocator.openStream(Activator.getDefault().getBundle(),new
Path("bin/SeedServer.jar"),false);
-
- int len;
- byte[] buf=new byte[1024];
- FileOutputStream fos=new FileOutputStream(serverFile);
- // write the file from the plugin to the contempt dir
- while(-1!=(len=inputStream.read(buf)))fos.write(buf,0,len);
- }
-
- // place TeamSeed.jar and NmapSeed.jar
- File seedDir=new
File(SeedConnector.contemptPath+File.separator+"seeds");
- if(!seedDir.exists())
- {
- int len;
- byte[] buf=new byte[1024];
- InputStream inputStream=null;
- FileOutputStream fos=null;
-
- seedDir.mkdir();
-
- File teamSeedFile=new
File(SeedConnector.contemptPath+File.separator+"seeds"+File.separator+"TeamSeed.jar");
-
inputStream=FileLocator.openStream(Activator.getDefault().getBundle(),new
Path("bin/SeedServer.jar"),false);
- fos=new FileOutputStream(teamSeedFile);
- while(-1!=(len=inputStream.read(buf)))fos.write(buf,0,len);
-
- File nmapSeedFile=new
File(SeedConnector.contemptPath+File.separator+"seeds"+File.separator+"NmapSeed.jar");
-
inputStream=FileLocator.openStream(Activator.getDefault().getBundle(),new
Path("bin/SeedServer.jar"),false);
- fos=new FileOutputStream(nmapSeedFile);
- while(-1!=(len=inputStream.read(buf)))fos.write(buf,0,len);
- }
-
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
}

protected void okPressed()
=======================================
--- /trunk/src/soc/contempt/visuals/AssetsVisual.java Thu Sep 24 15:10:40
2009
+++ /trunk/src/soc/contempt/visuals/AssetsVisual.java Mon Sep 28 23:04:48
2009
@@ -149,12 +149,12 @@
try
{
final Object[] row=(Object[])o;
- final String[] rowStrings=new String[row.length+1]; // add an element
for ID
+ final String[] rowStrings=new String[row.length];

rowStrings[0]=""; // XXX just add "" for now, later maybe add row number
for(int x=0;x<row.length;++x)
{
- rowStrings[x+1]=row[x].toString();
+ rowStrings[x]=row[x].toString();
}

// add new table item (must be in display thread to do so)
=======================================
--- /trunk/src/soc/contempt/visuals/RemoteNetworkVisual.java Thu Sep 24
15:10:40 2009
+++ /trunk/src/soc/contempt/visuals/RemoteNetworkVisual.java Mon Sep 28
23:04:48 2009
@@ -8,6 +8,8 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
@@ -32,8 +34,11 @@
private Tree tree=null;
private Display display=null;

- // tableMap remembers the row id for each target
- private ArrayList<String> targetList=new ArrayList<String>();
+ // store a lookup table for the items
+ private HashMap<String,TreeItem> hostMap=new HashMap<String,TreeItem>();
+ private HashMap<String,TreeItem> aMap=new HashMap<String,TreeItem>();
+ private HashMap<String,TreeItem> bMap=new HashMap<String,TreeItem>();
+ private HashMap<String,TreeItem> cMap=new HashMap<String,TreeItem>();

public RemoteNetworkVisual()
{
@@ -52,8 +57,7 @@

}

- public void init(IEditorSite site, IEditorInput input)
- throws PartInitException
+ public void init(IEditorSite site, IEditorInput input)throws
PartInitException
{
System.out.println("new database editor init()ed");
// TODO Auto-generated method stub
@@ -63,7 +67,7 @@
System.out.println("get the database name!");
tableName=input.getName();
seedConnection=((VisualInput)input).seedConnection;
- setPartName("targets");
+ setPartName("remote networks");
}

public boolean isDirty()
@@ -84,33 +88,21 @@
display=Display.getCurrent();

// create the table
- tree = new Tree(parent,SWT.VIRTUAL | SWT.BORDER);
+ parent.setLayout(new GridLayout(1,false));
+ tree = new Tree(parent,SWT.BORDER);
+ tree.setLayoutData(new GridData(GridData.FILL_BOTH));
+ //tree.setItemCount(256);

try
{
- Object[][] targets=seedConnection.dataSeed.selectAll("HOST");
-
- for(Object[] target:targets)
- {
- TreeItem targetItem=new TreeItem(tree,SWT.NONE);
- targetItem.setText((String)target[1]);
-
- if(target[0] instanceof Integer)
- {
- int targetID=((Integer)target[0]).intValue();
- targetList.ensureCapacity(targetID);
- targetList.add(targetID,target[1].toString());
- }
- else return;
-
- Object[][]
targetNotes=seedConnection.dataSeed.select("TAGS","ASSET_ID",target[0]);
-
- if(targetNotes!=null) // make sure select is not null
- for(Object[] note:targetNotes)
- {
- TreeItem noteItem=new TreeItem(targetItem,SWT.NONE);
- noteItem.setText((String)note[2]);
- }
+ for(Object[] host:seedConnection.dataSeed.selectAll("HOST"))
+ {
+ addHost(host);
+ }
+
+ for(Object[] service:seedConnection.dataSeed.selectAll("SERVICE"))
+ {
+ addService(service);
}
}
catch(Exception e)
@@ -134,99 +126,75 @@
{
}
});
-
- // add a context menu for the tree
- Menu menu=new Menu(parent);
- MenuItem addTarget=new MenuItem(menu,SWT.PUSH);
- addTarget.setText("add target");
- addTarget.addSelectionListener(new SelectionListener()
- {
- public void widgetDefaultSelected(SelectionEvent e)
- {
- }
-
- public void widgetSelected(SelectionEvent e)
- {
- StringDialog dialog=new StringDialog(null,"add target","target");
- dialog.open();
- if(dialog.aborted)return;
- if(dialog.getString().equals(""))return;
-
- DataSeedInterface dataSeed=seedConnection.dataSeed;
- try
- {
- dataSeed.insertRow("TARGETS",new Object[]{dialog.getString()});
- }
- catch (RemoteException e1)
- {
- e1.printStackTrace();
- }
- }
- });
- MenuItem addNote=new MenuItem(menu,SWT.PUSH);
- addNote.setText("add note");
- addNote.addSelectionListener(new SelectionListener()
- {
- public void widgetDefaultSelected(SelectionEvent e)
- {
- }
-
- public void widgetSelected(SelectionEvent e)
- {
- StringDialog dialog=new StringDialog(null,"add note","note");
- dialog.open();
- if(dialog.aborted)return;
- if(dialog.getString().equals(""))return;
-
- DataSeedInterface dataSeed=seedConnection.dataSeed;
-
- TreeItem targetItem=tree.getSelection()[0];
- if(targetItem==null)
- {
- System.out.println("could not find which item this is");
- return;
- }
-
- int targetID=targetList.indexOf(targetItem.getText());
-
- try
- {
- dataSeed.insertRow("TAGS",new
Object[]{"note",dialog.getString(),"TARGETS",targetID+""});
- }
- catch (RemoteException e1)
- {
- e1.printStackTrace();
- }
- }
- });
- tree.setMenu(menu);
-
+
// add the notifiers
-
seedConnection.notifier.subscribe("data.newRow.TARGETS",this,"addTarget");
- seedConnection.notifier.subscribe("data.newRow.TAGS",this,"addNote");
+ seedConnection.notifier.subscribe("data.newRow.HOST",this,"addHost");
+
//seedConnection.notifier.subscribe("data.newRow.SERVICE",this,"addService");
}

- public void addTarget(Object o) // called when a new target is added to
the db
+ public void addHost(Object o) // called when a new target is added to the
db
{
try
{
final Object[] row=(Object[])o;
- final String targetName=(String)row[0];
-
- //int targetID=((Integer)target[0]).intValue();
- //targetList.ensureCapacity(targetID);
- //targetList.add(targetID,targetName); <-- this is the proper way
- targetList.add(targetName);
- // TODO This is so bad, no verification is made to check that
- // the target name actually links up with this ID
-
- // add new table item (must be in display thread to do so)
- display.asyncExec(new Runnable()
+ final String host=row[2].toString();
+ final String a=row[3].toString();
+ final String b=row[4].toString();
+ final String c=row[5].toString();
+
+ // make sure this isn't a 1918 address
+ if(a.equals("10"))return;
+ if(a.equals("192")&&b.equals("168"))return;
+ if(a.equals("172")) // damn /12 subnet
+ {
+ Integer bInt=new Integer(b);
+ if(bInt>=16 && bInt<32)return;
+ }
+
+ display.syncExec(new Runnable()
{
public void run()
{
- TreeItem newItem=new TreeItem(tree,SWT.NONE);
- newItem.setText(targetName);
+ TreeItem hostItem=null;
+ TreeItem aItem=null;
+ TreeItem bItem=null;
+ TreeItem cItem=null;
+
+ System.out.println("making host");
+
+ if(aMap.containsKey(a))aItem=aMap.get(a);
+ else
+ {
+ System.out.println("making a");
+ aItem=new TreeItem(tree,SWT.NONE);//,new Integer(a).intValue());
+ aItem.setText(a+".0.0.0/8");
+ //aItem.setItemCount(256);
+ aMap.put(a, aItem);
+ }
+
+ if(bMap.containsKey(b))bItem=bMap.get(b);
+ else
+ {
+ System.out.println("making b");
+ bItem=new TreeItem(aItem,SWT.NONE);//,new Integer(b).intValue());
+ bItem.setText(a+"."+b+".0.0/16");
+ //bItem.setItemCount(256);
+ bMap.put(b, bItem);
+ }
+
+ if(cMap.containsKey(c))cItem=cMap.get(c);
+ else
+ {
+ System.out.println("making c");
+ cItem=new TreeItem(bItem,SWT.NONE);//,new Integer(c).intValue());
+ cItem.setText(a+"."+b+"."+c+".0/24");
+ //cItem.setItemCount(256);
+ cMap.put(c, cItem);
+ }
+
+ hostItem=new TreeItem(cItem,SWT.NONE);//,new
Integer(host.split("\\.")[3]).intValue());
+ hostItem.setText(host);
+ hostMap.put(host, hostItem);
}
});
}
@@ -236,43 +204,34 @@
}
}

- public void addNote(Object o) // called when a new tag is added to the db
+ public void addService(Object o)
{
try
{
- Object[] row=(Object[])o;
- System.out.println(row.length);
-
- final String tagName=row[1].toString();
- int targetID=new Integer(row[3].toString()).intValue();
- final String targetName=targetList.get(targetID);
-
- // add new table item (must be in display thread to do so)
- display.asyncExec(new Runnable()
+ final Object[] row=(Object[])o;
+ final String host=row[2].toString();
+ final String port=row[3].toString();
+ final String proto=row[4].toString();
+
+ display.syncExec(new Runnable()
{
public void run()
{
- // first we have to find the target that the note is attached to
- TreeItem[] items=tree.getItems();
- TreeItem targetItem=null;
-
- for(TreeItem item:items)
- {
- if(targetName.equals(item.getText()))
- {
- System.out.println("found targetItem: "+item.getText());
- targetItem=item;
- continue;
- }
- else
- {
- System.out.println(item.getText()+" is not "+targetName);
- }
- }
- if(targetItem==null)return; // make sure we have found a targetitem
-
- TreeItem newItem=new TreeItem(targetItem,SWT.NONE);
- newItem.setText(tagName);
+
+ if(!hostMap.containsKey(host))
+ {
+ String a=host.split("\\.")[0];
+ String b=host.split("\\.")[1];
+ String c=host.split("\\.")[2];
+
+ addHost(new Object[]{"","",host,a,b,c});
+ }
+
+ TreeItem hostItem=hostMap.get(host);
+ if(hostItem==null)return;
+
+ TreeItem serviceItem=new TreeItem(hostItem,SWT.NONE);
+ serviceItem.setText(port+" "+proto);
}
});
}
@@ -280,9 +239,7 @@
{
e.printStackTrace();
}
-
- }
-
+ }

public void setFocus()
{
=======================================
--- /trunk/src/soc/contempt/visuals/TargetsVisual.java Thu Sep 24 15:10:40
2009
+++ /trunk/src/soc/contempt/visuals/TargetsVisual.java Mon Sep 28 23:04:48
2009
@@ -1,27 +1,23 @@
package soc.contempt.visuals;

-import java.rmi.RemoteException;
-import java.util.ArrayList;
-import java.util.HashMap;
-
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.swt.widgets.ExpandBar;
+import org.eclipse.swt.widgets.ExpandItem;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;

import soc.contempt.data.SeedConnection;
-import soc.contempt.dialogs.StringDialog;
-import soc.seed.DataSeedInterface;

public class TargetsVisual extends EditorPart
{
@@ -29,12 +25,9 @@
//private Text entry;
String tableName;
private SeedConnection seedConnection=null;
- private Tree tree=null;
+ private ExpandBar expandBar=null;
private Display display=null;

- // tableMap remembers the row id for each target
- private ArrayList<String> targetList=new ArrayList<String>();
-
public TargetsVisual()
{
// TODO Auto-generated constructor stub
@@ -63,7 +56,7 @@
System.out.println("get the database name!");
tableName=input.getName();
seedConnection=((VisualInput)input).seedConnection;
- setPartName("targets");
+ setPartName(seedConnection.serverName+" targets");
}

public boolean isDirty()
@@ -84,7 +77,7 @@
display=Display.getCurrent();

// create the table
- tree = new Tree(parent,SWT.VIRTUAL | SWT.BORDER);
+ expandBar = new ExpandBar(parent,SWT.V_SCROLL);

try
{
@@ -92,25 +85,7 @@

for(Object[] target:targets)
{
- TreeItem targetItem=new TreeItem(tree,SWT.NONE);
- targetItem.setText((String)target[1]);
-
- if(target[0] instanceof Integer)
- {
- int targetID=((Integer)target[0]).intValue();
- targetList.ensureCapacity(targetID+20);
- targetList.add(targetID,target[1].toString());
- }
- else return;
-
- Object[][]
targetNotes=seedConnection.dataSeed.select("TAGS","ASSET_ID",target[0]);
-
- if(targetNotes!=null) // make sure select is not null
- for(Object[] note:targetNotes)
- {
- TreeItem noteItem=new TreeItem(targetItem,SWT.NONE);
- noteItem.setText((String)note[1]);
- }
+ addTarget(target);
}
}
catch(Exception e)
@@ -118,175 +93,116 @@
e.printStackTrace();
}

- // set the tree to expand when double clicked on (or enter)
- tree.addSelectionListener(new SelectionListener()
- {
- public void widgetDefaultSelected(SelectionEvent e)
- {
- if(e.item instanceof TreeItem)
- {
- TreeItem item=(TreeItem)e.item;
- item.setExpanded(!item.getExpanded());
- }
- }
-
- public void widgetSelected(SelectionEvent e)
- {
- }
- });
-
- // add a context menu for the tree
- Menu menu=new Menu(parent);
- MenuItem addTarget=new MenuItem(menu,SWT.PUSH);
- addTarget.setText("add target");
- addTarget.addSelectionListener(new SelectionListener()
- {
- public void widgetDefaultSelected(SelectionEvent e)
- {
- }
-
- public void widgetSelected(SelectionEvent e)
- {
- StringDialog dialog=new StringDialog(null,"add target","target");
- dialog.open();
- if(dialog.aborted)return;
- if(dialog.getString().equals(""))return;
-
- DataSeedInterface dataSeed=seedConnection.dataSeed;
- try
- {
- dataSeed.insertRow("TARGET",new Object[]{dialog.getString()});
- }
- catch (RemoteException e1)
- {
- e1.printStackTrace();
- }
- }
- });
- MenuItem addNote=new MenuItem(menu,SWT.PUSH);
- addNote.setText("add note");
- addNote.addSelectionListener(new SelectionListener()
- {
- public void widgetDefaultSelected(SelectionEvent e)
- {
- }
-
- public void widgetSelected(SelectionEvent e)
- {
- StringDialog dialog=new StringDialog(null,"add note","note");
- dialog.open();
- if(dialog.aborted)return;
- if(dialog.getString().equals(""))return;
-
- DataSeedInterface dataSeed=seedConnection.dataSeed;
-
- TreeItem targetItem=tree.getSelection()[0];
- if(targetItem==null)
- {
- System.out.println("could not find which item this is");
- return;
- }
-
- int targetID=targetList.indexOf(targetItem.getText());
-
- try
- {
- //dataSeed.insertRow("TAGS",new
Object[]{"note",dialog.getString(),"TARGETS",targetID+""});
- dataSeed.tagAsset(dialog.getString(),"TARGET",targetID);
- }
- catch (RemoteException e1)
- {
- e1.printStackTrace();
- }
+ // add the notifiers
+ seedConnection.notifier.subscribe("data.newRow.TARGET",this,"addTarget");
+
seedConnection.notifier.subscribe("data.updatedField.TARGET",this,"targetUpdated");
+ }
+
+ public void addTarget(Object o) // called when a new target is added to
the db
+ {
+ Object[] target=null;
+ if(o instanceof Object[])target=(Object[])o;
+ else return;
+
+ final String targetID=target[0].toString();
+ //final String targetTime=target[1].toString();
+ final String targetName=target[2].toString();
+ final String targetStatus=target[3].toString();
+ final String targetNotes=target[4].toString();
+
+ // run this in the UI thread
+ display.syncExec(new Runnable()
+ {
+ public void run()
+ {
+ final ExpandItem expandItem=new ExpandItem(expandBar,SWT.NONE);
+ final Text text=new Text(expandBar,SWT.MULTI|SWT.WRAP|SWT.BORDER);
+ expandItem.setText(targetName+" ("+targetStatus+")
["+targetID+"]");
+ text.setText(targetNotes);
+ text.setLayoutData(new GridData(GridData.FILL_BOTH));
+ expandItem.setHeight(text.computeSize(SWT.DEFAULT, SWT.DEFAULT).y+3);
+ expandItem.setControl(text);
+ expandItem.setExpanded(true);
+
+ // keep resizing text area while typing
+ text.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ expandItem.setHeight(text.computeSize(SWT.DEFAULT, SWT.DEFAULT).y+3);
+ }
+ });
+
+ // once edited, make sure everyone gets an update of the notes
+ text.addFocusListener(new FocusListener()
+ {
+ public void focusGained(FocusEvent e){}
+ public void focusLost(FocusEvent e)
+ {
+ String notes=text.getText();
+ try
+ {
+ seedConnection.dataSeed.updateField("TARGET",new
Integer(targetID),"NOTES",(Object)notes);
+ }
+ catch(Exception e2)
+ {
+ return;
+ }
+ }
+ });
}
});
- tree.setMenu(menu);
-
- // add the notifiers
- seedConnection.notifier.subscribe("data.newRow.TARGET",this,"addTarget");
- seedConnection.notifier.subscribe("data.newRow.TAG",this,"addNote");
- }
-
- public void addTarget(Object o) // called when a new target is added to
the db
- {
- try
- {
- final Object[] row=(Object[])o;
- final String targetName=(String)row[0];
-
- //int targetID=((Integer)row[0]).intValue();
- //targetList.ensureCapacity(targetID);
- //targetList.add(targetID,targetName);// <-- this is the proper way
- targetList.add(targetName);
- // TODO This is so bad, no verification is made to check that
- // the target name actually links up with this ID
-
- // add new table item (must be in display thread to do so)
- display.asyncExec(new Runnable()
- {
- public void run()
- {
- TreeItem newItem=new TreeItem(tree,SWT.NONE);
- newItem.setText(targetName);
- }
- });
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
}

- public void addNote(Object o) // called when a new tag is added to the db
- {
+ // this will be in the form of <id, fieldname, value>
+ public void targetUpdated(Object o)
+ {
try
{
- Object[] row=(Object[])o;
- System.out.println(row.length);
-
- final String tagName=row[1].toString();
- int targetID=new Integer(row[3].toString()).intValue();
- final String targetName=targetList.get(targetID);
-
- // add new table item (must be in display thread to do so)
+ Object[] update=(Object[])o;
+ if(update.length!=3)return;
+
+ final String id=update[0].toString();
+ final String fieldName=update[1].toString();
+ final String value=update[2].toString();
+
display.asyncExec(new Runnable()
{
public void run()
{
- // first we have to find the target that the note is attached to
- TreeItem[] items=tree.getItems();
- TreeItem targetItem=null;
-
- for(TreeItem item:items)
- {
- if(targetName.equals(item.getText()))
- {
- System.out.println("found targetItem: "+item.getText());
- targetItem=item;
- continue;
- }
- else
- {
- System.out.println(item.getText()+" is not "+targetName);
- }
- }
- if(targetItem==null)return; // make sure we have found a targetitem
-
- TreeItem newItem=new TreeItem(targetItem,SWT.NONE);
- newItem.setText(tagName);
+ for(ExpandItem item:expandBar.getItems())
+ {
+ String itemText=item.getText();
+ String
targetID=itemText.substring(itemText.lastIndexOf("[")+1,itemText.lastIndexOf("]"));
+
+ if(targetID.equals(id))
+ {
+ if(fieldName.equals("STATUS"))
+ {
+ String targetName=itemText.substring(0,itemText.lastIndexOf("
("));
+ item.setText(targetName+" ("+value+") ["+id+"]");
+ return;
+ }
+ if(fieldName.equals("NOTES"))
+ {
+ Text text=(Text)item.getControl();
+ text.setText(value);
+ return;
+ }
+ }
+ else System.out.println(targetID+" is not "+id);
+ }
+ System.out.println("dag, the compare didn't work");
}
});
}
catch(Exception e)
{
e.printStackTrace();
- }
-
- }
-
+ }
+ }

public void setFocus()
{
}
-
-}
+}
=======================================
--- /trunk/src/soc/seed/DataSeedInterface.java Thu Sep 24 15:10:40 2009
+++ /trunk/src/soc/seed/DataSeedInterface.java Mon Sep 28 23:04:48 2009
@@ -18,6 +18,7 @@

import java.rmi.Remote;
import java.rmi.RemoteException;
+import java.util.ArrayList;

public interface DataSeedInterface extends Remote
{
@@ -25,9 +26,14 @@
public String[] getFields(String tableName) throws RemoteException;
public boolean createTable(String tableName,String[] rows) throws
RemoteException;
public boolean insertRow(String tableName, Object[] row) throws
RemoteException;
- public Object[][] select(String tableName, String fieldName, Object
value) throws RemoteException;
+ public boolean updateRow(String tableName, Integer id, ArrayList<Object>
values) throws RemoteException;
+ public boolean updateField(String tableName, Integer id, String
fieldName, Object value) throws RemoteException;
+ public Object[][] select(String tableName, Object[] query) throws
RemoteException;
public Object[][] selectAll(String tableName) throws RemoteException;

+ public boolean deleteTable(String tableName) throws RemoteException;
+ public boolean deleteRow(String tableName, Integer rowID) throws
RemoteException;
+
public String tagAsset(String value, String aTable, Integer aID) throws
RemoteException;
public String relateAssets(String value, String aTable, Integer aID,
String bTable, Integer bID) throws RemoteException;

=======================================
--- /trunk/src/soc/seed/data/SQLiteDataSeed.java Thu Sep 24 15:10:40 2009
+++ /trunk/src/soc/seed/data/SQLiteDataSeed.java Mon Sep 28 23:04:48 2009
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.rmi.RemoteException;

+import java.security.SecureRandom;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
@@ -40,6 +41,7 @@
{
private static final long serialVersionUID = 4397150604244071321L;
public Connection conn=null; // the jdbc connector
+ public SecureRandom rng=null;

public SQLiteDataSeed() throws RemoteException
{
@@ -53,20 +55,23 @@
{
e.printStackTrace();
}
-
+
+ rng=new SecureRandom();
+ rng.setSeed(System.currentTimeMillis());
+
createTable("TAGS",new String[]
{
- "VALUE varchar(400) not null",
- "ASSET_TABLE varchar(400) not null",
+ "VALUE text not null",
+ "ASSET_TABLE text not null",
"ASSET_ID integer not null"
});

createTable("RELATIONS",new String[]
{
- "VALUE varchar(400) not null",
- "ASSET1_TABLE varchar(400) not null",
+ "VALUE text not null",
+ "ASSET1_TABLE text not null",
"ASSET1_ID integer not null",
- "ASSET2_TABLE varchar(400) not null",
+ "ASSET2_TABLE text not null",
"ASSET2_ID integer not null"
});
}
@@ -107,33 +112,30 @@
{
DatabaseMetaData meta;
ResultSet columns=null;
- ArrayList<String> rowNames=new ArrayList<String>();
+ ArrayList<String> columnNames=new ArrayList<String>();

// query the database for the rows and columns
try
{
meta=conn.getMetaData();
columns=meta.getColumns(null, null, tableName, null);
- System.out.println("looking in table "+tableName+": ");
-
- while(columns.next())
- {
- System.out.println("field: "+columns.getString(4));
- rowNames.add(columns.getString(4));
- }
+
+ // compile a list that contains names for each column
+ while(columns.next())columnNames.add(columns.getString(4));
+
}
catch(Exception e)
{
e.printStackTrace();
}
- return (String[]) rowNames.toArray(new String[]{});
+ return (String[]) columnNames.toArray(new String[]{});
}

// new table
public boolean createTable(String tableName,String[] rows)
{
// make sure rowNames.count is the same as rowClasses.count
- String command="CREATE TABLE "+tableName+" ( ID integer primary key
autoincrement, ";
+ String command="CREATE TABLE "+tableName+" ( ID integer primary key,
TIMESTAMP text, ";
for(int x=0;x<rows.length;++x)
{
command=command+rows[x];
@@ -152,7 +154,6 @@
System.out.println("SQLiteDataSeed: table '"+tableName+"' already
exists");
//e.printStackTrace();
}
-

System.out.println("looks like the table creation worked..");
return true;
@@ -166,22 +167,27 @@
// this might not work well because of index
// we might need to getFields()
String[] fields=getFields(tableName);
- if(fields.length-1!=row.length) // -1 to ignore the ID field
+ if(fields.length-2!=row.length) // -1 to ignore the ID/TIMESTAMP field
{
System.out.println("can't insert row, the counts don't match ("+
fields.length+", "+row.length+")");
return false;
}

- String command="INSERT INTO "+tableName+"(";
- for(int x=1;x<fields.length;++x) // start at 1 to ignore ID field (auto
incremented)
+ String command="INSERT INTO "+tableName+"(ID, TIMESTAMP,";
+ for(int x=2;x<fields.length;++x) // start at 2 to ignore ID/TIMESTAMP
field (auto incremented)
{
command+=fields[x];
if((x+1)==fields.length)command+=")"; // finish off the statement...
else command+=","; // ...or prepare for a new object
}

- command+=" values(";
+ int randID=rng.nextInt();
+ if(randID<1)randID*=-1; // make sure randID is a positive int
+ String randIDString=""+randID;
+ String timeString=""+System.currentTimeMillis();
+
+ command+=" values("+randID+","+timeString+",";
for(int x=0;x<row.length;++x)
{
command+="?";
@@ -201,7 +207,14 @@

ps.executeUpdate(); // this does not actually return row number

- ManagerSeed.notifyClients(new
SeedNotification("data.newRow."+tableName,row));
+ // add the ID and timestamp into the array
+ Object[] fullRow=new Object[row.length+2];
+ fullRow[0]=randIDString;
+ fullRow[1]=timeString;
+ for(int x=0;x<row.length;++x)fullRow[x+2]=row[x];
+
+ //notify everyone about the new row
+ ManagerSeed.notifyClients(new
SeedNotification("data.newRow."+tableName,fullRow));
}
catch(Exception e)
{
@@ -211,21 +224,44 @@
return true;
}

- // update row
- //public boolean updateRow(String tableName, int id, ArrayList row)
- //{
-
- //}
+ //update row
+ public boolean updateRow(String tableName, Integer id, ArrayList<Object>
row)
+ {
+ System.out.println("update row not implemented!");
+ return false;
+ }

// update field
- //public boolean updateField(String tableName, String fieldName, Object
value)
- //{
-
- //}
-
- // update
- public Object[][] select(String tableName, String fieldName, Object value)
- {
+ public boolean updateField(String tableName, Integer id,String fieldName,
Object value)
+ {
+ if(fieldName.equals("ID"))return false;
+
+ PreparedStatement ps=null;
+ try
+ {
+ ps=conn.prepareStatement("UPDATE "+tableName+" SET "+fieldName+"=?
where ID=?");
+ ps.setObject(1, value);
+ ps.setInt(2, id.intValue());
+
+ int rows=ps.executeUpdate();
+
+ ManagerSeed.notifyClients(new
SeedNotification("data.updatedField."+tableName,new
Object[]{id,fieldName,value}));
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ return false;
+ }
+
+ return true;
+ }
+
+ // update TODO GENERALIZE THIS
+ //public Object[][] select(String tableName, String fieldName, Object
value)
+ public Object[][] select(String tableName, Object[] query)
+ {
+ if(query.length%2!=0)return null; // make sure length is a multiple of 2
+
ResultSet rows=null;
Statement statement=null;
ArrayList<Object[]> rowList=new ArrayList<Object[]>();
@@ -234,13 +270,21 @@
try
{
statement = conn.createStatement();
+
+ // TODO there is a better more sqly way to do this
rows=statement.executeQuery("select * from "+tableName);

- while(rows.next())
+ // label the loop for double breakout
+ loop: while(rows.next())
{
// make sure this row matches the query
- if(!rows.getObject(fieldName).equals(value))continue;
-
+ for(int x=0;x<query.length;x+=2)
+ {
+ // double breakout continue attack!
+ if(!rows.getObject(query[x].toString()).equals(query[x+1]))continue
loop;
+ }
+
+ // this row matches, add it to the list
Object[] currentRow=new Object[numFields];
for(int x=0;x<numFields;++x)
{
@@ -248,7 +292,6 @@
}
rowList.add(currentRow);
}
-
}
catch (SQLException e)
{
@@ -288,6 +331,18 @@
}
return (Object[][]) rowList.toArray(new Object[][]{});
}
+
+ public boolean deleteTable(String tableName)
+ {
+ System.out.println("delete table not implemented!");
+ return false;
+ }
+
+ public boolean deleteRow(String tableName, Integer rowID)
+ {
+ System.out.println("delete row not implemented!");
+ return false;
+ }

public String tagAsset(String value, String aTable, Integer aID)
{
=======================================
--- /trunk/src/soc/seed/seeds/NmapSeed.java Thu Sep 24 15:10:40 2009
+++ /trunk/src/soc/seed/seeds/NmapSeed.java Mon Sep 28 23:04:48 2009
@@ -23,20 +23,23 @@

data.createTable("HOST",new String[]
{
- "HOST varchar(40) not null",
- "PARENT_ID int",
+ "HOST text unique not null",
+ "A integer",
+ "B integer",
+ "C integer",
+
"GATEWAY boolean",
- "NETWORK varchar(40)"
+ "NETWORK text"
});

// make sure that the SERVICE table exists
data.createTable("SERVICE",new String[]
{
- "HOST varchar(40) not null",
- "PORT varchar(10) not null",
- "PROTOCOL varchar(10)",
- "APPLICATION varchar(10)",
- "VERSION varchar(10)"
+ "HOST text not null",
+ "PORT text not null",
+ "PROTOCOL text",
+ "APPLICATION text",
+ "VERSION text"
});
}

@@ -75,15 +78,30 @@

String[] servicePort=lineArray[3].split("/");
String port=null;
- String proto=null;
if(servicePort.length==2)
{
port=servicePort[0];
- proto=servicePort[1];
}
else System.out.println("strange nmap output..");

- data.insertRow("SERVICE",new
Object[]{lineArray[5],port,proto,"",""});
+ // split the IP address
+ String host=lineArray[5];
+ String[] hostArray=host.split("\\.");
+ if(hostArray.length!=4)
+ {
+ System.out.println("strange looking IP address");
+ return;
+ }
+
+ // add the new host
+ data.insertRow("HOST",new
Object[]{host,hostArray[0],hostArray[1],hostArray[2],false,""});
+
+ // make sure we haven't added this host/port pair
+ Object[][] result=data.select("SERVICE",new
Object[]{"HOST",host,"PORT",port});
+ if(result==null || result.length>0)continue;
+
+ // add the discovered service if it is new
+ data.insertRow("SERVICE",new
Object[]{host,port,portToProtocol(port),"",""});
}
}
catch(Exception e)
@@ -94,5 +112,16 @@
}
}
}.start();
- }
-}
+ }
+
+ private String portToProtocol(String port)
+ {
+ if(port.equals("21"))return "ftp";
+ if(port.equals("22"))return "ssh";
+ if(port.equals("23"))return "telnet";
+ if(port.equals("80"))return "http";
+ if(port.equals("443"))return "https";
+
+ return "";
+ }
+}
=======================================
--- /trunk/src/soc/seed/seeds/TeamSeed.java Thu Sep 24 15:10:40 2009
+++ /trunk/src/soc/seed/seeds/TeamSeed.java Mon Sep 28 23:04:48 2009
@@ -19,7 +19,9 @@
// make sure the tables are in place
SeedServer.dataSeed.createTable("TARGET",new String[]
{
- "TARGET varchar(400) not null"
+ "TARGET varchar(32) not null",
+ "STATUS varchar(32)",
+ "NOTES varchar(1024)"
});

}
@@ -36,17 +38,26 @@
return null;
}

- @Exposed(description="start monitoring dns queries", arguments={"target"})
+ @Exposed(description="add a target", arguments={"target"})
public String addTarget(String target) throws RemoteException
{
- SeedServer.dataSeed.insertRow("TARGET",new Object[]{target});
+ SeedServer.dataSeed.insertRow("TARGET",new Object[]{target,"new",""});
return null;
}

- @Exposed(description="start monitoring dns queries",
arguments={"target","note"})
- public String attachNote(Integer targetID, String note) throws
RemoteException
- {
- SeedServer.dataSeed.tagAsset(note,"TARGET",targetID);
+ @Exposed(description="set status", arguments={"target","status"})
+ public String setStatus(Integer targetID, String status) throws
RemoteException
+ {
+ if(status==null)return null;
+ SeedServer.dataSeed.updateField("TARGET",targetID,"STATUS",status);
+ return null;
+ }
+
+ @Exposed(description="set note", arguments={"target","note"})
+ public String setNote(Integer targetID, String note) throws
RemoteException
+ {
+ if(note==null)return null;
+ SeedServer.dataSeed.updateField("TARGET",targetID,"NOTES",note);
return null;
}
}

Reply all
Reply to author
Forward
0 new messages