Browse Source

Statistics/ViewLog added, MySQL protocol added

Lars 10 years ago
parent
commit
226b2200d0
36 changed files with 908 additions and 460 deletions
  1. 8 0
      AndroidManifest.xml
  2. 8 0
      bin/AndroidManifest.xml
  3. BIN
      bin/classes.dex
  4. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/R$id.class
  5. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/R$layout.class
  6. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/R$menu.class
  7. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/R$string.class
  8. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/R$style.class
  9. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/protocol/HTTP.class
  10. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/protocol/SMB.class
  11. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/ui/ListViewAdapter.class
  12. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$1.class
  13. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$2.class
  14. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$3.class
  15. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$4.class
  16. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$5.class
  17. BIN
      bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity.class
  18. BIN
      bin/hostage.apk
  19. BIN
      bin/resources.ap_
  20. 31 16
      gen/de/tudarmstadt/informatik/hostage/R.java
  21. 12 0
      res/layout/activity_main.xml
  22. 102 0
      res/layout/activity_viewlog.xml
  23. 1 0
      res/values/protocols.xml
  24. 4 0
      res/values/strings.xml
  25. 2 1
      src/de/tudarmstadt/informatik/hostage/handler/AbstractHandler.java
  26. 1 1
      src/de/tudarmstadt/informatik/hostage/io/ByteArrayReaderWriter.java
  27. 78 15
      src/de/tudarmstadt/informatik/hostage/logging/DatabaseHandler.java
  28. 17 4
      src/de/tudarmstadt/informatik/hostage/logging/SQLLogger.java
  29. 21 3
      src/de/tudarmstadt/informatik/hostage/logging/SQLRecord.java
  30. 28 29
      src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java
  31. 165 0
      src/de/tudarmstadt/informatik/hostage/protocol/MySQL.java
  32. 307 387
      src/de/tudarmstadt/informatik/hostage/protocol/SMB.java
  33. 2 4
      src/de/tudarmstadt/informatik/hostage/protocol/TELNET.java
  34. 9 0
      src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java
  35. 82 0
      src/de/tudarmstadt/informatik/hostage/ui/ViewLog.java
  36. 30 0
      src/de/tudarmstadt/informatik/hostage/ui/ViewLogTable.java

+ 8 - 0
AndroidManifest.xml

@@ -26,6 +26,14 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+        <activity
+            android:name="de.tudarmstadt.informatik.hostage.ui.ViewLog"
+            android:label="@string/app_name" >
+        </activity>
+       	<activity
+            android:name="de.tudarmstadt.informatik.hostage.ui.ViewLogTable"
+            android:label="@string/app_name" >
+        </activity>
 
         <service android:name="de.tudarmstadt.informatik.hostage.HoneyService" >
         </service>

+ 8 - 0
bin/AndroidManifest.xml

@@ -26,6 +26,14 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+        <activity
+            android:name="de.tudarmstadt.informatik.hostage.ui.ViewLog"
+            android:label="@string/app_name" >
+        </activity>
+       	<activity
+            android:name="de.tudarmstadt.informatik.hostage.ui.ViewLogTable"
+            android:label="@string/app_name" >
+        </activity>
 
         <service android:name="de.tudarmstadt.informatik.hostage.HoneyService" >
         </service>

BIN
bin/classes.dex


BIN
bin/classes/de/tudarmstadt/informatik/hostage/R$id.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/R$layout.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/R$menu.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/R$string.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/R$style.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/protocol/HTTP.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/protocol/SMB.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/ListViewAdapter.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$1.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$2.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$3.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$4.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$5.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity.class


BIN
bin/hostage.apk


BIN
bin/resources.ap_


+ 31 - 16
gen/de/tudarmstadt/informatik/hostage/R.java

@@ -41,30 +41,41 @@ public final class R {
         public static final int light_yellow_large=0x7f020008;
     }
     public static final class id {
-        public static final int TextViewServices=0x7f0a000e;
-        public static final int action_settings=0x7f0a0013;
+        public static final int TextViewServices=0x7f0a000f;
+        public static final int action_settings=0x7f0a001d;
+        public static final int buttonDeleteLog=0x7f0a0019;
+        public static final int buttonShowLog=0x7f0a0005;
+        public static final int buttonUploadLog=0x7f0a0018;
         public static final int checkBoxParanoid=0x7f0a0003;
         public static final int imageViewLight=0x7f0a0002;
-        public static final int listViewProtocols=0x7f0a000f;
-        public static final int textViewBSSID=0x7f0a0008;
-        public static final int textViewBSSIDValue=0x7f0a0009;
-        public static final int textViewConnections=0x7f0a0011;
-        public static final int textViewConnectionsValue=0x7f0a0012;
-        public static final int textViewDetails=0x7f0a0005;
-        public static final int textViewExternalIP=0x7f0a000c;
-        public static final int textViewExternalIPValue=0x7f0a000d;
-        public static final int textViewInternalIP=0x7f0a000a;
-        public static final int textViewInternalIPValue=0x7f0a000b;
-        public static final int textViewProtocol=0x7f0a0010;
-        public static final int textViewSSID=0x7f0a0006;
-        public static final int textViewSSIDValue=0x7f0a0007;
+        public static final int layoutContainer=0x7f0a0012;
+        public static final int listViewProtocols=0x7f0a0010;
+        public static final int textFirstAttack=0x7f0a0013;
+        public static final int textFirstAttackValue=0x7f0a0014;
+        public static final int textLastAttack=0x7f0a0015;
+        public static final int textLastAttackValue=0x7f0a0016;
+        public static final int textLogFile=0x7f0a0017;
+        public static final int textStatistics=0x7f0a0011;
+        public static final int textViewBSSID=0x7f0a0009;
+        public static final int textViewBSSIDValue=0x7f0a000a;
+        public static final int textViewConnections=0x7f0a001b;
+        public static final int textViewConnectionsValue=0x7f0a001c;
+        public static final int textViewDetails=0x7f0a0006;
+        public static final int textViewExternalIP=0x7f0a000d;
+        public static final int textViewExternalIPValue=0x7f0a000e;
+        public static final int textViewInternalIP=0x7f0a000b;
+        public static final int textViewInternalIPValue=0x7f0a000c;
+        public static final int textViewProtocol=0x7f0a001a;
+        public static final int textViewSSID=0x7f0a0007;
+        public static final int textViewSSIDValue=0x7f0a0008;
         public static final int textViewStatus=0x7f0a0001;
         public static final int toggleButtonOnOff=0x7f0a0004;
         public static final int viewAnimator=0x7f0a0000;
     }
     public static final class layout {
         public static final int activity_main=0x7f030000;
-        public static final int list_view_protocols_row=0x7f030001;
+        public static final int activity_viewlog=0x7f030001;
+        public static final int list_view_protocols_row=0x7f030002;
     }
     public static final class menu {
         public static final int main=0x7f090000;
@@ -78,10 +89,14 @@ public final class R {
         public static final int connections=0x7f07000c;
         public static final int details=0x7f070006;
         public static final int external_ip=0x7f07000a;
+        public static final int firstAttack=0x7f07000f;
         public static final int internal_ip=0x7f070009;
+        public static final int lastAttack=0x7f070010;
+        public static final int logFile=0x7f07000e;
         public static final int paranoid=0x7f070005;
         public static final int services=0x7f07000b;
         public static final int ssid=0x7f070007;
+        public static final int statistics=0x7f07000d;
         public static final int status=0x7f070004;
     }
     public static final class style {

+ 12 - 0
res/layout/activity_main.xml

@@ -51,6 +51,18 @@
                 android:onClick="buttonOnOffClick"
                 android:textOff="@string/capital_off"
                 android:textOn="@string/capital_on" />
+
+            <Button
+                android:id="@+id/buttonShowLog"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_alignParentLeft="true"
+                android:layout_alignParentTop="true"
+                android:onClick="showLog"
+                android:text="Show Log" />
+
+
+
         </RelativeLayout>
 
         <LinearLayout

+ 102 - 0
res/layout/activity_viewlog.xml

@@ -0,0 +1,102 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin" >
+
+    <TextView
+        android:id="@+id/textStatistics"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/statistics"
+        android:textAppearance="?android:attr/textAppearanceLarge" />
+
+    <LinearLayout
+        android:id="@+id/layoutContainer"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical"
+        android:paddingLeft="@dimen/activity_horizontal_margin" >
+    </LinearLayout>
+
+        <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal" >
+        
+    <TextView
+        android:id="@+id/textFirstAttack"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/firstAttack"
+        android:textAppearance="?android:attr/textAppearanceMedium" />
+    
+	<TextView
+        android:id="@+id/textFirstAttackValue"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text=""
+        android:textAppearance="?android:attr/textAppearanceMedium" />
+	
+	</LinearLayout>
+	
+        
+	<LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal" >
+	
+    <TextView
+        android:id="@+id/textLastAttack"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/lastAttack"
+        android:textAppearance="?android:attr/textAppearanceMedium" />
+    
+   	<TextView
+        android:id="@+id/textLastAttackValue"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text=""
+        android:textAppearance="?android:attr/textAppearanceMedium" />
+   	
+   	</LinearLayout> 
+
+    <TextView
+        android:id="@+id/textLogFile"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/logFile"
+        android:textAppearance="?android:attr/textAppearanceLarge" />
+
+    <Button
+        android:id="@+id/buttonShowLog"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:onClick="showLog"
+        android:text="Show Log" />
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal" >
+
+        <Button
+            android:id="@+id/buttonUploadLog"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Upload Log" />
+
+        <Button
+            android:id="@+id/buttonDeleteLog"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:onClick="deleteLog"
+            android:text="Delete Log" />
+    </LinearLayout>
+
+</LinearLayout>

+ 1 - 0
res/values/protocols.xml

@@ -7,6 +7,7 @@
         <item>SMB</item>
         <item>SSH</item>
         <item>TELNET</item>
+        <item>MySQL</item>
     </string-array>
 
 </resources>

+ 4 - 0
res/values/strings.xml

@@ -14,5 +14,9 @@
     <string name="external_ip">External IP:</string>
     <string name="services">Services</string>
     <string name="connections">Active connections:</string>
+    <string name="statistics">Statistics</string>
+	<string name="logFile">Log File</string>
+	<string name="firstAttack">First Attack:</string>
+	<string name="lastAttack">Last Attack:</string>
 
 </resources>

+ 2 - 1
src/de/tudarmstadt/informatik/hostage/handler/AbstractHandler.java

@@ -31,7 +31,7 @@ public abstract class AbstractHandler implements Runnable {
 		this.protocol = protocol;
 		this.client = client;
 		this.thread = new Thread(this);
-		attack_id = 0; 	//TODO Attack ID zuordnen
+		attack_id = log.getAttackCount();
 		setSoTimeout(client);
 		thread.start();
 	}
@@ -78,6 +78,7 @@ public abstract class AbstractHandler implements Runnable {
 	protected SQLRecord createRecord(String type, String packet) {
 		SQLRecord record = new SQLRecord();
 		record.setAttack_id(attack_id);
+		record.setProtocol(protocol.toString());
 		record.setType(type);
 		record.setTimestamp(String.valueOf(System.currentTimeMillis()));
 		record.setLocalIP(client.getLocalAddress().getHostAddress());

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/io/ByteArrayReaderWriter.java

@@ -33,7 +33,7 @@ public class ByteArrayReaderWriter implements ReaderWriter<ByteArray> {
 	public void write(List<ByteArray> message) throws IOException {
 		for (ByteArray m : message) {
 			out.write(m.get());
+			out.flush();
 		}
 	}
-
 }

+ 78 - 15
src/de/tudarmstadt/informatik/hostage/logging/DatabaseHandler.java

@@ -24,6 +24,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
 	// Contacts Table Columns names
 	private static final String KEY_ID = "id";
 	private static final String KEY_ATTACK_ID = "attack_id";
+	private static final String KEY_PROTOCOL = "protocol";
 	private static final String KEY_TYPE = "type";
 	private static final String KEY_TIME = "timestamp";
 	private static final String KEY_LOCAL_IP = "localIP";
@@ -40,7 +41,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
 	@Override
 	public void onCreate(SQLiteDatabase db) {
 		String CREATE_RECORD_TABLE = "CREATE TABLE " + TABLE_RECORDS + "(" + KEY_ID
-				+ " INTEGER PRIMARY KEY," + KEY_ATTACK_ID + " INTEGER,"
+				+ " INTEGER PRIMARY KEY," + KEY_ATTACK_ID + " INTEGER," + KEY_PROTOCOL + " TEXT,"
 				+ KEY_TYPE + " TEXT," + KEY_TIME + " TEXT," + KEY_LOCAL_IP
 				+ " Text," + KEY_LOCAL_PORT + " INTEGER," + KEY_REMOTE_IP
 				+ " TEXT," + KEY_REMOTE_PORT + " INTEGER," + KEY_PACKET
@@ -64,6 +65,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
 
 		ContentValues values = new ContentValues();
 		values.put(KEY_ATTACK_ID, record.getAttack_id()); // Log Attack ID
+		values.put(KEY_PROTOCOL, record.getProtocol());
 		values.put(KEY_TYPE, record.getType()); // Log Type
 		values.put(KEY_TIME, record.getTimestamp()); // Log Timestamp
 		values.put(KEY_LOCAL_IP, record.getLocalIP()); // Log Local IP
@@ -82,7 +84,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
 		SQLiteDatabase db = this.getReadableDatabase();
 
 		Cursor cursor = db.query(TABLE_RECORDS, new String[] { KEY_ID,
-				KEY_ATTACK_ID, KEY_TYPE, KEY_TIME, KEY_LOCAL_IP,
+				KEY_ATTACK_ID, KEY_PROTOCOL, KEY_TYPE, KEY_TIME, KEY_LOCAL_IP,
 				KEY_LOCAL_PORT, KEY_REMOTE_IP, KEY_REMOTE_PORT, KEY_PACKET },
 				KEY_ID + "=?", new String[] { String.valueOf(id) }, null, null,
 				null, null);
@@ -90,10 +92,13 @@ public class DatabaseHandler extends SQLiteOpenHelper {
 			cursor.moveToFirst();
 
 		SQLRecord record = new SQLRecord(Integer.parseInt(cursor.getString(0)),
-				Integer.parseInt(cursor.getString(1)), cursor.getString(2),
-				cursor.getString(3), cursor.getString(4),
-				Integer.parseInt(cursor.getString(5)), cursor.getString(6),
-				Integer.parseInt(cursor.getString(7)), cursor.getString(8));
+				Integer.parseInt(cursor.getString(1)), cursor.getString(2), cursor.getString(3),
+				cursor.getString(4), cursor.getString(5),
+				Integer.parseInt(cursor.getString(6)), cursor.getString(7),
+				Integer.parseInt(cursor.getString(8)), cursor.getString(9));
+		
+        cursor.close();
+		db.close();
 		// return contact
 		return record;
 	}
@@ -113,19 +118,21 @@ public class DatabaseHandler extends SQLiteOpenHelper {
 				SQLRecord record = new SQLRecord();
 				record.setID(Integer.parseInt(cursor.getString(0)));
 				record.setAttack_id(Integer.parseInt(cursor.getString(1)));
-				record.setType(cursor.getString(2));
-				record.setTimestamp(cursor.getString(3));
-				record.setLocalIP(cursor.getString(4));
-				record.setLocalPort(Integer.parseInt(cursor.getString(5)));
-				record.setRemoteIP(cursor.getString(6));
-				record.setRemotePort(Integer.parseInt(cursor.getString(7)));
-				record.setPacket(cursor.getString(8));
+				record.setProtocol(cursor.getString(2));
+				record.setType(cursor.getString(3));
+				record.setTimestamp(cursor.getString(4));
+				record.setLocalIP(cursor.getString(5));
+				record.setLocalPort(Integer.parseInt(cursor.getString(6)));
+				record.setRemoteIP(cursor.getString(7));
+				record.setRemotePort(Integer.parseInt(cursor.getString(8)));
+				record.setPacket(cursor.getString(9));
 				
 				// Adding record to list
 				contactList.add(record);
 			} while (cursor.moveToNext());
 		}
-
+        cursor.close();
+		db.close();
 		// return record list
 		return contactList;
 	}
@@ -135,9 +142,65 @@ public class DatabaseHandler extends SQLiteOpenHelper {
         String countQuery = "SELECT  * FROM " + TABLE_RECORDS;
         SQLiteDatabase db = this.getReadableDatabase();
         Cursor cursor = db.rawQuery(countQuery, null);
+       int result = cursor.getCount();
+       cursor.close();
+ 
+        // return count
+        db.close();
+        return result;
+    }
+    
+	// Getting record Count
+    public int getAttackCount() {
+        String countQuery = "SELECT  * FROM " + TABLE_RECORDS + " GROUP BY " + KEY_ATTACK_ID;
+        SQLiteDatabase db = this.getReadableDatabase();
+        Cursor cursor = db.rawQuery(countQuery, null);
+        int result = cursor.getCount();
         cursor.close();
  
         // return count
-        return cursor.getCount();
+        db.close();
+        return result;
+    }
+    
+	// Getting record Count
+    public int getAttackPerProtokolCount(String protocol) {
+        String countQuery = "SELECT  * FROM " + TABLE_RECORDS + " WHERE " + KEY_PROTOCOL + " = " + "'" + protocol + "'" +  " GROUP BY " + KEY_ATTACK_ID;
+        SQLiteDatabase db = this.getReadableDatabase();
+        Cursor cursor = db.rawQuery(countQuery, null);
+        int result = cursor.getCount();
+        cursor.close();
+ 
+        // return count
+        db.close();
+        return result;
+    }
+    
+    
+    public SQLRecord getFirstEntry(){
+    	//TODO Fixen oder löschen
+    	SQLiteDatabase db = this.getReadableDatabase();
+    	Cursor cursor = db.query(TABLE_RECORDS, new String[] { KEY_ID,
+				KEY_ATTACK_ID, KEY_PROTOCOL, KEY_TYPE, KEY_TIME, KEY_LOCAL_IP,
+				KEY_LOCAL_PORT, KEY_REMOTE_IP, KEY_REMOTE_PORT, KEY_PACKET },
+				KEY_ID + "=?", new String[] { "min(" + KEY_ID + ")" }, null,
+                null, null, null);
+		
+    	if (cursor != null)
+			cursor.moveToFirst();
+ 
+		SQLRecord record = new SQLRecord(Integer.parseInt(cursor.getString(0)),
+				Integer.parseInt(cursor.getString(1)), cursor.getString(2), cursor.getString(3),
+				cursor.getString(4), cursor.getString(5),
+				Integer.parseInt(cursor.getString(6)), cursor.getString(7),
+				Integer.parseInt(cursor.getString(8)), cursor.getString(9));    
+		return record;
+    }
+    
+    //Delete all Data from Database
+    public void clearData(){
+    	SQLiteDatabase db = this.getReadableDatabase();
+        db.delete(TABLE_RECORDS, null, null);
+        db.close();
     }
 }

+ 17 - 4
src/de/tudarmstadt/informatik/hostage/logging/SQLLogger.java

@@ -7,16 +7,16 @@ import android.content.Context;
 
 public class SQLLogger{
 	Context context;
-	DatabaseHandler db;
+	DatabaseHandler dbh;
 	private FileOutputStream log = null;
 	
 	public SQLLogger(Context context){
 		this.context = context;
-		db = new DatabaseHandler(context);		
+		dbh = new DatabaseHandler(context);		
 	}
 
 	public void addRecord(SQLRecord record) {
-		db.addRecord(record);
+		dbh.addRecord(record);
 	}
 	
 	public void exportDatabase(){
@@ -26,7 +26,7 @@ public class SQLLogger{
 			e.printStackTrace();
 		}		
 		
-		ArrayList<SQLRecord> records = db.getAllRecords();
+		ArrayList<SQLRecord> records = dbh.getAllRecords();
 		for(SQLRecord record : records){
 			writeLine(record);
 		}
@@ -45,5 +45,18 @@ public class SQLLogger{
 	public void exportDatabaseJson(){
 		//TODO JSON implementieren, beachten dass nur jeder Angriff nicht jeder Record geloggt wird
 	}
+	
+	public int getAttackCount(){
+		return dbh.getAttackCount();
+	}
+	
+	public int getAttackPerProtokollCount(String protocol){
+		return dbh.getAttackPerProtokolCount(protocol);
+	}
+	
+	public void clearLog(){
+		dbh.clearData();
+	}
+
 
 }

+ 21 - 3
src/de/tudarmstadt/informatik/hostage/logging/SQLRecord.java

@@ -6,6 +6,7 @@ public class SQLRecord {
 	// private variables
 	private int id;
 	private int attack_id;
+	private String protocol;
 	private String type;
 	private String timestamp;
 	private String localIP;
@@ -20,11 +21,12 @@ public class SQLRecord {
 	}
 
 	// constructor
-	public SQLRecord(int id, int attack_id, String type, String timestamp,
+	public SQLRecord(int id, int attack_id, String protocol,  String type, String timestamp,
 			String localIP, int localPort, String remoteIP, int remotePort,
 			String packet) {
 		this.id = id;
 		this.attack_id = attack_id;
+		this.setProtocol(protocol);
 		this.type = type;
 		this.timestamp = timestamp;
 		this.localIP = localIP;
@@ -35,9 +37,10 @@ public class SQLRecord {
 	}
 
 	// constructor
-	public SQLRecord(int attack_id, String type, String timestamp, String localIP,
+	public SQLRecord(int attack_id, String protocol, String type, String timestamp, String localIP,
 			int localPort, String remoteIP, int remotePort, String packet) {
 		this.attack_id = attack_id;
+		this.setProtocol(protocol);
 		this.type = type;
 		this.timestamp = timestamp;
 		this.localIP = localIP;
@@ -77,6 +80,20 @@ public class SQLRecord {
 		this.attack_id = attack_id;
 	}
 
+	/**
+	 * @return the protocol
+	 */
+	public String getProtocol() {
+		return protocol;
+	}
+
+	/**
+	 * @param protocol the protocol to set
+	 */
+	public void setProtocol(String protocol) {
+		this.protocol = protocol;
+	}
+
 	/**
 	 * @return the type
 	 */
@@ -182,8 +199,9 @@ public class SQLRecord {
 		this.packet = packet;
 	}
 
+	@Override
 	public String toString() {
-		return String.format("%d %s [%d,%s:%d,%s:%d,%s]", id, type, timestamp,
+		return String.format("%d %s [%s,%s:%d,%s:%d,%s]", attack_id, type, timestamp,
 				localIP, localPort, remoteIP, remotePort, packet);
 	}
 

+ 28 - 29
src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java

@@ -19,11 +19,13 @@ public final class HTTP implements Protocol<String> {
 	@Override
 	public List<String> processMessage(String message) {
 		List<String> response = new ArrayList<String>();
-		if (Pattern.matches("^HEAD\\s?", message)) {
-			response.add(buildHeader());
-		} else if (Pattern.matches("^GET\\s?", message)) {
-			response.add((buildHeader() + buildPage()));
-		} else {
+		if(!message.contains("HTTP/1.1")){
+			response.add("HTTP/1.1 505 HTTP Version not supported");
+		} else if(message.contains("GET")) {
+			response.add(header+html);
+		} else if(message.contains("HEAD")) {
+			response.add(header);
+		} else {		
 			response.add("HTTP/1.1 501 Not Implemented");
 		}
 		return response;
@@ -49,30 +51,27 @@ public final class HTTP implements Protocol<String> {
 		return "HTTP";
 	}
 
-	private String buildHeader() {
-		StringBuilder builder = new StringBuilder();
-		builder.append("HTTP/1.1 200 OK\r\n");
-		builder.append("Server: Apache/2.4.6 (Unix) PHP/5.5.2\r\n");
-		builder.append("Content-Length: 148\r\n");
-		builder.append("Content-Language: en\r\n");
-		builder.append("Connection: close\r\n");
-		builder.append("Content-Type: text/html\r\n");
-		builder.append("\r\n");
-		return builder.toString();
-	}
+	private String header =	"HTTP/1.1 200 OK\r\n" +
+			"Date: Mon, 01 Jul 2013 18:27:55 GMT\r\n" +
+			"Server: Apache/2.2.22 (Debian)\r\n" +
+			"X-Powered-By: PHP/5.4.4.-14\r\n" +
+			"Vary: Accept-Encoding\r\n" +
+			"Content-Length: 173\r\n" +	
+			"Keep-Alive: timeout=5, max=100\r\n" +
+			"Connection: Keep-Alive\r\n" +
+			"Content-Type: text/html\r\n" +
+			"\r\n";
 
-	private String buildPage() {
-		StringBuilder builder = new StringBuilder();
-		builder.append("<html>");
-		builder.append("<head>");
-		builder.append("<title>hostage</title>");
-		builder.append("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />");
-		builder.append("</head>");
-		builder.append("<body>");
-		builder.append("<p>Hello there!</p>");
-		builder.append("</body>");
-		builder.append("</html>");
-		return builder.toString();
-	}
+	private String html = "<!doctype html>\n" +
+			"<html lang=\"en\">\n" +
+			"<head>\n" +
+			"<meta charset=\"UTF-8\">\n" +
+			"<title>Test successful</title>\n" +
+			"</head>\n" +
+			"<body>\n" +
+			"<h1>Test successful</h1>\n" +
+			"<p>Congratulations.</p>\n" +
+			"</body>\n" +
+			"</html>";
 
 }

+ 165 - 0
src/de/tudarmstadt/informatik/hostage/protocol/MySQL.java

@@ -0,0 +1,165 @@
+package de.tudarmstadt.informatik.hostage.protocol;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
+
+
+public class MySQL implements Protocol<ByteArray>{
+	private enum STATE {
+		NONE, CONNECTED, LOGIN_INFO, AUTHENTICATE, LOGGED_IN, CLOSED
+	}
+	
+	private STATE state = STATE.NONE;
+	
+	private byte[] request;
+	
+	@Override
+	public List<ByteArray> processMessage(ByteArray request) {
+		List<ByteArray> response = new ArrayList<ByteArray>();
+		if(request != null) {
+			this.request = request.get();
+		}
+				
+		switch(state) {
+		case NONE:
+			response.add(new ByteArray(greeting()));
+			state = STATE.CONNECTED;
+			break;
+		case CONNECTED:
+			response.add(new ByteArray(responseOK()));
+			state = STATE.LOGIN_INFO;
+			break;
+		case LOGIN_INFO:
+			if(this.request[4] == 0x01) {
+				response = null;
+				state = STATE.CLOSED;
+			} else if(this.request[4] == 0x03) {
+				response.add(new ByteArray(response()));
+			} else {
+				response.add(new ByteArray(responseError()));
+			}
+			break;
+		case AUTHENTICATE:
+			break;
+		case LOGGED_IN:
+			break;
+		default:
+			state = STATE.CLOSED;
+			break;
+		}
+		
+		return response;
+	}
+	
+	@Override
+	public TALK_FIRST whoTalksFirst() {
+		return TALK_FIRST.SERVER;
+	}
+
+	@Override
+	public String toString(){
+		return "MySQL";		
+	}
+	
+	@Override
+	public int getPort() {
+		return 3306;
+	}
+	
+	@Override
+	public boolean isClosed() {
+		return state == STATE.CLOSED;
+	}
+	
+	private byte[] wrapPckt(byte[] pckt) {
+		byte[] buff = ByteBuffer.allocate(4).putInt(pckt.length).array();
+		byte[] pcktLength = {buff[3], buff[2], buff[1]};
+		byte[] pcktNumber = new byte[1];
+		if(request != null) pcktNumber[0] = (byte) (request[3] + 1);
+		else pcktNumber[0] = 0x00;
+		
+		byte[] response = concat(pcktLength, pcktNumber, pckt);
+		return response;
+	}
+	
+	private byte[] greeting() {
+		byte[] protocol = {0x0a};
+		String version = "5.5.31-0+wheezy1";
+		byte[] versionFin = {0x00};
+		byte[] thread = {0x2a, 0x00, 0x00, 0x00};
+		byte[] salt = {0x44, 0x64, 0x49, 0x7e, 0x60, 0x48, 0x25, 0x7e, 0x00};
+		byte[] capabilities = {(byte) 0xff, (byte) 0xf7};
+		byte[] language = {0x08};
+		byte[] status = {0x02, 0x00};
+		byte[] unused = {0x0f, (byte) 0x80, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+		byte[] salt2 = {0x6c, 0x26, 0x71, 0x2c, 0x25, 0x72, 0x31, 0x3d, 0x7d, 0x21, 0x26, 0x3b, 0x00};
+		String payload = "mysql_native_password";
+		byte[] fin = {0x00};
+		
+		byte[] response = concat(protocol, version.getBytes(),versionFin, thread, salt, capabilities, language, status, unused, salt2, payload.getBytes(), fin);
+		
+		return wrapPckt(response);
+	}
+	
+	private byte[] responseOK() {
+		byte[] affectedRows = {0x00, 0x00, 0x00};
+		byte[] status = {0x02, 0x00};
+		byte[] warnings = {0x00, 0x00};
+		
+		byte[] response = concat(affectedRows, status, warnings);
+		return wrapPckt(response);
+	}
+	
+	private byte[] response() {
+		// 4 packets to respond
+		byte[] pckt0 = {0x01, 0x00, 0x00, 0x01, 0x01};
+		byte[] pckt1 = {0x27, 0x00, 0x00, 0x02, 0x03, 0x64, 0x65, 0x66, 0x00, 
+				0x00, 0x00, 0x11, 0x40, 0x40, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x6d, 0x6d,
+				0x65, 0x6e, 0x74, 0x00, 0x0c, 0x21, 0x00, 0x18, 0x00, 0x00, 0x00, (byte) 0xfd, 0x00, 0x00, 0x1f, 0x00, 0x00};
+		byte[] pckt2 = {0x05, 0x00, 0x00, 0x03, (byte) 0xfe, 0x00, 0x00, 0x02, 0x00};
+		byte[] pckt3 = {0x09, 0x00, 0x00, 0x04, 0x08, 0x28, 0x44, 0x65, 0x62, 0x69, 0x61, 0x6e, 0x29};
+		byte[] pckt4 = {0x05, 0x00, 0x00, 0x05, (byte) 0xfe, 0x00, 0x00, 0x02, 0x00};
+			
+		byte[] response = concat(pckt0, pckt1, pckt2, pckt3, pckt4);
+		return response;	//no wrapPckt() needed, because packets already have length and number
+	}
+	
+	private byte[] responseError() {
+		byte[] fill1 = {(byte) 0xff};
+		byte[] code = {0x17, 0x04};
+		byte[] fill2 = {0x23};
+		String state = "08S01";
+		String msg = "Unknown command";
+		
+		byte[] response = concat(fill1, code, fill2, state.getBytes(), msg.getBytes());		
+		return wrapPckt(response);
+	}
+	
+	private byte[] concat(byte[]...bytes) {
+		int newSize = 0;	
+		for(byte[] b: bytes) newSize += b.length;		//get total new size
+		byte[] dst = new byte[newSize];				//create new array with new size
+		
+		int currentPos = 0;				
+		int newPos;	
+		for(byte[] b:bytes) {									//for each elem b out of bytes
+			newPos = b.length;									//get b.length and new position
+			System.arraycopy(b, 0, dst, currentPos, newPos);	//copy b in dst from currentPos to newPos
+			currentPos += newPos;								//increase currentPos to newPos + currentPos
+		}
+		return dst;
+	}
+
+	@Override
+	public boolean isSecure() {
+		return false;
+	}
+
+	@Override
+	public Class<ByteArray> getType() {
+		return ByteArray.class;
+	}
+}

+ 307 - 387
src/de/tudarmstadt/informatik/hostage/protocol/SMB.java

@@ -26,11 +26,13 @@ public final class SMB implements Protocol<ByteArray> {
 	public TALK_FIRST whoTalksFirst() {
 		return TALK_FIRST.CLIENT;
 	}
+	
+	private SmbPacket packet = new SmbPacket();
 
 	@Override
 	public List<ByteArray> processMessage(ByteArray message) {
 		byte[] primitiveByteArray = message.get();
-		SmbPacket packet = new SmbPacket(primitiveByteArray);
+		packet.newMsg(primitiveByteArray);
 		byte smbCommand = packet.getSmbCommand();
 		List<ByteArray> response = new ArrayList<ByteArray>();
 		switch (state) {
@@ -160,6 +162,10 @@ public final class SMB implements Protocol<ByteArray> {
 		return bytes;
 	}
 
+	public String byteToStr(byte[] bytes) {
+		return charToString(byteToChar(bytes));
+	}
+	
 	public String charToString(char[] chars) {
 		char[] newChars = new char[chars.length];
 		for (int i = 0, j = 0; i < chars.length && j < newChars.length; i++) {
@@ -190,459 +196,373 @@ public final class SMB implements Protocol<ByteArray> {
 	}
 
 	private class SmbPacket {
-		private byte[] msg = null;
-		private final byte[] serverGUID = randomBytes(16);
-		private boolean authenticateNext = false;
-
-		private byte[] serverComp = new byte[4];
-		private byte[] smbCommand = new byte[1];
-		private byte[] ntStat = new byte[4];
-		private byte[] smbFlags = new byte[1];
-		private byte[] smbFlags2 = new byte[2];
-		private byte[] processIDHigh = new byte[2];
-		private byte[] signature = new byte[8];
-		private byte[] reserved = new byte[2];
-		private byte[] treeID = new byte[2];
-		private byte[] processID = new byte[2];
-		private byte[] userID = new byte[2];
-		private byte[] multiplexID = new byte[2];
-
-		public SmbPacket(byte[] message) {
-			this.msg = message;
-			serverComp = new byte[] { message[4], message[5], message[6],
-					message[7] };
-			smbCommand = new byte[] { message[8] };
-			ntStat = new byte[] { message[9], message[10], message[11],
-					message[12] };
-			smbFlags = new byte[] { (byte) (message[13] | 0x80) }; // | 0x80 for
-																	// mark
-																	// response
-																	// bit
-			smbFlags2 = new byte[] { message[14], message[15] };
-			processIDHigh = new byte[] { message[16], message[17] };
-			signature = new byte[] { message[18], message[19], message[20],
-					message[21], message[22], message[23], message[24],
-					message[25] };
-			reserved = new byte[] { message[26], message[27] };
-			treeID = new byte[] { message[28], message[29] };
-			processID = new byte[] { message[30], message[31] };
-			userID = new byte[] { message[32], message[33] };
-			multiplexID = new byte[] { message[34], message[35] };
+		private byte[] msg					= null; 
+		private final byte[] serverGUID		= randomBytes(16);
+		private boolean authenticateNext	= false;
+		
+		private byte[] serverComp 		= new byte[4];
+		private byte[] smbCommand		= new byte[1];
+		private byte[] ntStat 			= new byte[4];
+		private byte[] smbFlags			= new byte[1];	
+		private byte[] smbFlags2		= new byte[2];
+		private byte[] processIDHigh	= new byte[2];
+		private byte[] signature	 	= new byte[8];
+		private byte[] reserved			= new byte[2];
+		private byte[] treeID			= new byte[2];
+		private byte[] processID		= new byte[2];
+		private byte[] userID			= new byte[2];
+		private byte[] multiplexID		= new byte[2];
+					
+		public SmbPacket() {
 		}
-
+		
+		public void newMsg(byte[] msg) {
+			this.msg = msg;
+			serverComp 		= new byte[]{msg[4], msg[5], msg[6], msg[7]};
+			smbCommand		= new byte[]{msg[8]};
+			ntStat 			= new byte[]{msg[9], msg[10], msg[11], msg[12]};
+			smbFlags		= new byte[]{(byte) (msg[13] | 0x80)};		// | 0x80 for mark response bit
+			smbFlags2		= new byte[]{msg[14], msg[15]};
+			processIDHigh	= new byte[]{msg[16], msg[17]};
+			signature	 	= new byte[]{msg[18], msg[19], msg[20], msg[21], msg[22], msg[23], msg[24], msg[25]};
+			reserved		= new byte[]{msg[26], msg[27]};
+			treeID			= new byte[]{msg[28], msg[29]};
+			processID		= new byte[]{msg[30], msg[31]};
+			userID			= new byte[]{msg[32], msg[33]};
+			multiplexID		= new byte[]{msg[34], msg[35]};
+		}
+		
 		private byte[] getNetbios(byte[] response) {
-			byte[] netbios = { 0x00 };
-			byte[] buf = ByteBuffer.allocate(4).putInt(response.length).array(); // allocate(4)
-																					// because
-																					// int
-																					// is
-																					// 4
-																					// bytes
-																					// long
-			byte[] netbiosLength = { buf[1], buf[2], buf[3] }; // only bytes 1-3
-																// needed, byte
-																// 0 is not
-																// needed
+			byte[] netbios = {0x00};
+			byte[] buf = ByteBuffer.allocate(4).putInt(response.length).array();	// allocate(4) because int is 4 bytes long
+			byte[] netbiosLength = {buf[1], buf[2], buf[3]};			// only bytes 1-3 needed, byte 0 is not needed
 			return concat(netbios, netbiosLength);
 		}
-
+		
 		private byte[] getHeader() {
 			byte[] header = new byte[0];
-			return concat(header, serverComp, smbCommand, ntStat, smbFlags,
-					smbFlags2, processIDHigh, signature, reserved, treeID,
-					processID, userID, multiplexID);
+			return concat(header, serverComp, smbCommand, ntStat, smbFlags, smbFlags2, processIDHigh, signature,
+									reserved, treeID, processID, userID, multiplexID);
 		}
-
+		
 		public byte[] getNego() {
-			byte[] wordCount = { 0x11 };
-			byte[] dialect = evaluateDialect();
-			byte[] secMode = { 0x03 };
-			byte[] maxMpxC = { 0x32, 0x00 };
-			byte[] maxVcs = { 0x01, 0x00 };
-			byte[] maxBufSize = { 0x04, 0x11, 0x00, 0x00 };
-			byte[] maxRawBuf = { 0x00, 0x00, 0x01, 0x00 };
-			byte[] sessionKey = { 0x00, 0x00, 0x00, 0x00 };
-			byte[] capabilities = { (byte) 0xfc, (byte) 0xe3, 0x01, (byte) 0x80 };
-			byte[] sysTime = getTimeInBytes();
-			byte[] timeZone = { (byte) 0x88, (byte) 0xff }; // FIXME correct
-															// time zone
-			byte[] keyLength = { 0x00 };
-			byte[] byteCount = { 0x3a, 0x00 };
-			byte[] guid = serverGUID;
-			byte[] secBlob = { 0x60, 0x28, 0x06, 0x06 };
-			byte[] oid = { 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02 };
-			byte[] protectNeg = { (byte) 0xa0, 0x1e };
-			byte[] negToken = { 0x30, 0x1c, (byte) 0xa0, 0x1a, 0x30, 0x18 };
-			byte[] mechType = { 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01,
-					(byte) 0x82, 0x37, 0x02, 0x02, 0x1e };
-			byte[] mechType2 = { 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01,
-					(byte) 0x82, 0x37, 0x02, 0x02, 0x0a };
-
-			byte[] response = concat(getHeader(), wordCount, dialect, secMode,
-					maxMpxC, maxVcs, maxBufSize, maxRawBuf, sessionKey,
-					capabilities, sysTime, timeZone, keyLength, byteCount,
-					guid, secBlob, oid, protectNeg, negToken, mechType,
-					mechType2);
+			byte[] wordCount	= {0x11};
+			byte[] dialect		= evaluateDialect();		
+			byte[] secMode		= {0x03};
+			byte[] maxMpxC 		= {0x32, 0x00};
+			byte[] maxVcs		= {0x01, 0x00};
+			byte[] maxBufSize	= {0x04, 0x11, 0x00, 0x00};
+			byte[] maxRawBuf	= {0x00, 0x00, 0x01, 0x00};
+			byte[] sessionKey	= {0x00, 0x00, 0x00, 0x00};
+			byte[] capabilities	= {(byte) 0xfc, (byte) 0xe3, 0x01, (byte) 0x80};
+			byte[] sysTime		= getTimeInBytes();
+			byte[] timeZone		= {(byte) 0x88, (byte) 0xff};		//FIXME correct time zone
+			byte[] keyLength	= {0x00};
+			byte[] byteCount	= {0x3a, 0x00};			
+			byte[] guid			= serverGUID;
+			byte[] secBlob		= {0x60, 0x28, 0x06, 0x06};
+			byte[] oid			= {0x2b, 0x06, 0x01, 0x05, 0x05, 0x02};
+			byte[] protectNeg	= {(byte) 0xa0, 0x1e};
+			byte[] negToken		= {0x30, 0x1c, (byte) 0xa0, 0x1a, 0x30, 0x18};
+			byte[] mechType		= {0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, (byte) 0x82, 0x37, 0x02, 0x02, 0x1e};
+			byte[] mechType2	= {0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, (byte) 0x82, 0x37, 0x02, 0x02, 0x0a};
+			
+			byte[] response = concat(getHeader(), wordCount, dialect, secMode, maxMpxC, maxVcs, maxBufSize, maxRawBuf,
+							sessionKey, capabilities, sysTime, timeZone, keyLength, byteCount, guid, secBlob, oid,
+							protectNeg, negToken, mechType, mechType2);
 			return concat(getNetbios(response), response);
 		}
-
+		
 		private byte[] evaluateDialect() {
-			byte[] dialectMsg = java.util.Arrays.copyOfRange(msg, 39,
-					msg.length);
+			byte[] dialectMsg = new byte[msg.length-39];
+			System.arraycopy(msg, 39, dialectMsg, 0, msg.length - 39);
 			short dialectNumber = 0;
-			for (int i = 0, start = 0; i < dialectMsg.length; i++) {
-				if (dialectMsg[i] == 0x00) {
-					if (new String(java.util.Arrays.copyOfRange(dialectMsg,
-							start, i)).contains("NT LM 0.12")) {
-						return new byte[] { (byte) dialectNumber,
-								(byte) (dialectNumber >> 8) };
+			for(int i = 0, start = 0; i < dialectMsg.length; i++) {
+				if(dialectMsg[i] == 0x00) {
+					byte[] dialect = new byte[i-start];
+					System.arraycopy(dialectMsg, start, dialect, 0, i-start);
+					if(byteToStr(dialect).contains("NT LM 0.12")) {
+						return new byte[]{(byte)dialectNumber, (byte)(dialectNumber >> 8)};
 					}
-					start = i + 1;
+					start = i+1;
 					dialectNumber++;
 				}
 			}
-			return new byte[] { 0x00, 0x00 };
+			return new byte[]{0x00, 0x00};
 		}
-
+		
 		public byte[] getSessSetup() {
-			if (authenticateNext)
-				return getSetupAuth();
+			if(authenticateNext) return getSetupAuth();
 			else {
 				authenticateNext = true;
 				return getSetupChal();
 			}
 		}
-
+		
 		private byte[] getSetupChal() {
-			byte[] wordCount = { 0x04 };
-			byte[] andXCommand = { (byte) 0xff };
-			byte[] reserved = { 0x00 };
-			byte[] andXOffset = { 0x60, 0x01 };
-			byte[] action = { 0x00, 0x00 };
-			byte[] secBlobLength = { (byte) 0xc7, 0x00 };
-			byte[] byteCount = { 0x35, 0x01 };
-			byte[] secBlob = { (byte) 0xa1, (byte) 0x81, (byte) 0xc4 };
-			byte[] negToken = { 0x30, (byte) 0x81, (byte) 0xc1, (byte) 0xa0,
-					0x03, 0x0a, 0x01 };
-			byte[] negResult = { 0x01 };
-			byte[] negToken2 = { (byte) 0xa1, 0x0c, 0x06, 0x0a };
-			byte[] supportedMech = { 0x2b, 0x06, 0x01, 0x04, 0x01, (byte) 0x82,
-					0x37, 0x02, 0x02, 0x0a };
-			byte[] negToken3 = { (byte) 0xa2, (byte) 0x81, (byte) 0xab, 0x04,
-					(byte) 0x81, (byte) 0xa8 };
-			byte[] respToken = { 0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50,
-					0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x38,
-					0x00, 0x00, 0x00, 0x15, (byte) 0x82, (byte) 0x8a, 0x62 };
-			byte[] challenge = randomBytes(8);
-			byte[] respToken2 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-					0x00, 0x60, 0x00, 0x60, 0x00, 0x48, 0x00, 0x00, 0x00, 0x06,
-					0x01, (byte) 0xb0, 0x1d, 0x00, 0x00, 0x00, 0x0f, 0x42,
-					0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x45,
-					0x00, 0x53, 0x00, 0x53, 0x00, 0x02, 0x00, 0x10, 0x00, 0x42,
-					0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x45,
-					0x00, 0x53, 0x00, 0x53, 0x00, 0x01, 0x00, 0x10, 0x00, 0x42,
-					0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x45,
-					0x00, 0x53, 0x00, 0x53, 0x00, 0x04, 0x00, 0x10, 0x00, 0x42,
-					0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x45,
-					0x00, 0x53, 0x00, 0x53, 0x00, 0x03, 0x00, 0x10, 0x00, 0x42,
-					0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x45,
-					0x00, 0x53, 0x00, 0x53, 0x00, 0x07, 0x00, 0x08, 0x00 };
-			byte[] timeStamp = getTimeInBytes();
-			byte[] respToken3 = { 0x00, 0x00, 0x00, 0x00 };
-			byte[] nativOS = { 0x57, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x64, 0x00,
-					0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37, 0x00,
-					0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x66, 0x00,
-					0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00,
-					0x6e, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x37, 0x00,
-					0x36, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00 }; // Windows
-																		// 7
-																		// Professional
-																		// 7600
-			byte[] nativLanMngr = { 0x57, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x64,
-					0x00, 0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37,
-					0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x66,
-					0x00, 0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f,
-					0x00, 0x6e, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x36,
-					0x00, 0x2e, 0x00, 0x31, 0x00, 0x00, 0x00 }; // Windows 7
-																// Professional
-																// 6.1
-
-			ntStat = new byte[] { 0x16, 0x00, 0x00, (byte) 0xc0 };
-			userID = new byte[] { 0x00, 0x08 };
-
-			byte[] response = concat(getHeader(), wordCount, andXCommand,
-					reserved, andXOffset, action, secBlobLength, byteCount,
-					secBlob, negToken, negResult, negToken2, supportedMech,
-					negToken3, respToken, challenge, respToken2, timeStamp,
-					respToken3, nativOS, nativLanMngr);
+			byte[] wordCount		= {0x04};
+			byte[] andXCommand		= {(byte) 0xff};
+			byte[] reserved			= {0x00};
+			byte[] andXOffset		= {0x60, 0x01};
+			byte[] action			= {0x00, 0x00};
+			byte[] secBlobLength	= {(byte) 0xc7, 0x00};
+			byte[] byteCount		= {0x35, 0x01};
+			byte[] secBlob			= {(byte) 0xa1, (byte) 0x81, (byte) 0xc4};
+			byte[] negToken			= {0x30, (byte) 0x81, (byte) 0xc1, (byte) 0xa0, 0x03, 0x0a, 0x01};
+			byte[] negResult		= {0x01};
+			byte[] negToken2		= {(byte) 0xa1, 0x0c, 0x06, 0x0a};
+			byte[] supportedMech	= {0x2b, 0x06, 0x01, 0x04, 0x01, (byte) 0x82, 0x37, 0x02, 0x02, 0x0a};
+			byte[] negToken3		= {(byte) 0xa2, (byte) 0x81, (byte) 0xab, 0x04, (byte) 0x81, (byte) 0xa8};
+			byte[] respToken		= {0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 
+										0x38, 0x00, 0x00, 0x00, 0x15, (byte) 0x82, (byte) 0x8a, 0x62};
+			byte[] challenge		= randomBytes(8);
+			byte[] respToken2		= {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x60, 0x00, 0x48, 0x00, 0x00, 0x00, 
+										0x06, 0x01, (byte) 0xb0, 0x1d, 0x00, 0x00, 0x00, 0x0f, 0x42, 0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00, 
+										0x4e, 0x00, 0x45, 0x00, 0x53, 0x00, 0x53, 0x00, 0x02, 0x00, 0x10, 0x00, 0x42, 0x00, 0x55, 0x00, 
+										0x53, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x45, 0x00, 0x53, 0x00, 0x53, 0x00, 0x01, 0x00, 0x10, 0x00, 
+										0x42, 0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x45, 0x00, 0x53, 0x00, 0x53, 0x00, 
+										0x04, 0x00, 0x10, 0x00, 0x42, 0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x45, 0x00, 
+										0x53, 0x00, 0x53, 0x00, 0x03, 0x00, 0x10, 0x00, 0x42, 0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00, 
+										0x4e, 0x00, 0x45, 0x00, 0x53, 0x00, 0x53, 0x00, 0x07, 0x00, 0x08, 0x00};
+			byte[] timeStamp		= getTimeInBytes();
+			byte[] respToken3		= {0x00, 0x00, 0x00, 0x00};
+			byte[] nativOS			= {0x57, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x64, 0x00, 
+										0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 
+										0x6f, 0x00, 0x66, 0x00, 0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x6e, 0x00, 
+										0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x37, 0x00, 0x36, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00};			//Windows 7 Professional 7600
+			byte[] nativLanMngr		= {0x57, 0x00, 0x69, 0x00, 0x6e, 0x00, 			
+										0x64, 0x00, 0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x50, 0x00, 
+										0x72, 0x00, 0x6f, 0x00, 0x66, 0x00, 0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00, 
+										0x6e, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x36, 0x00, 0x2e, 0x00, 0x31, 0x00, 0x00, 0x00};			//Windows 7 Professional 6.1
+			
+			ntStat 					= new byte[]{0x16, 0x00, 0x00, (byte) 0xc0};
+			userID					= new byte[]{0x00, 0x08};
+			
+			byte[] response = concat(getHeader(), wordCount, andXCommand, reserved, andXOffset, action, secBlobLength,
+												byteCount, secBlob, negToken, negResult, negToken2, supportedMech, negToken3, 
+												respToken, challenge, respToken2, timeStamp, respToken3, nativOS, nativLanMngr);
 			return concat(getNetbios(response), response);
 		}
-
+		
 		private byte[] getSetupAuth() {
-			byte[] wordCount = { 0x04 };
-			byte[] andXCommand = { (byte) 0xff };
-			byte[] reserved = { 0x00 };
-			byte[] andXOffset = { (byte) 0xa2, 0x00 };
-			byte[] action = { 0x01, 0x00 };
-			byte[] secBlobLength = { 0x09, 0x00 };
-			byte[] byteCount = { (byte) 0x77, 0x00 };
-			byte[] secBlob = { (byte) 0xa1, 0x07, 0x30, 0x05, (byte) 0xa0,
-					0x03, 0x0a, 0x01, 0x00 };
-			byte[] nativOS = { 0x57, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x64, 0x00,
-					0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37, 0x00,
-					0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x66, 0x00,
-					0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00,
-					0x6e, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x37, 0x00,
-					0x36, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00 }; // Windows
-																		// 7
-																		// Professional
-																		// 7600
-			byte[] nativLanMngr = { 0x57, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x64,
-					0x00, 0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37,
-					0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x66,
-					0x00, 0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f,
-					0x00, 0x6e, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x36,
-					0x00, 0x2e, 0x00, 0x31, 0x00, 0x00, 0x00 }; // Windows 7
-																// Professional
-																// 6.1
-
-			byte[] response = concat(getHeader(), wordCount, andXCommand,
-					reserved, andXOffset, action, secBlobLength, byteCount,
-					secBlob, nativOS, nativLanMngr);
+			byte[] wordCount		= {0x04};
+			byte[] andXCommand		= {(byte) 0xff};
+			byte[] reserved			= {0x00};
+			byte[] andXOffset		= {(byte) 0xa2, 0x00};
+			byte[] action			= {0x01, 0x00};
+			byte[] secBlobLength	= {0x09, 0x00};
+			byte[] byteCount		= {(byte) 0x77, 0x00};
+			byte[] secBlob			= {(byte) 0xa1, 0x07, 0x30, 0x05, (byte) 0xa0, 0x03, 0x0a, 0x01, 0x00};
+			byte[] nativOS			= {0x57, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x64, 0x00, 
+										0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 
+										0x6f, 0x00, 0x66, 0x00, 0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x6e, 0x00, 
+										0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x37, 0x00, 0x36, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00};			//Windows 7 Professional 7600
+			byte[] nativLanMngr		= {0x57, 0x00, 0x69, 0x00, 0x6e, 0x00, 			
+										0x64, 0x00, 0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x50, 0x00, 
+										0x72, 0x00, 0x6f, 0x00, 0x66, 0x00, 0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00, 
+										0x6e, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x36, 0x00, 0x2e, 0x00, 0x31, 0x00, 0x00, 0x00};			//Windows 7 Professional 6.1
+
+			
+			byte[] response = concat(getHeader(), wordCount, andXCommand, reserved, andXOffset, action, secBlobLength,
+					byteCount, secBlob, nativOS, nativLanMngr);
 			return concat(getNetbios(response), response);
 		}
 
 		public byte[] getTreeCon() {
-			String str = toString();
-			byte[] wordCount = { 0x00 };
-			byte[] andXCommand = { 0x00, 0x00 };
-			byte[] response = null;
-
-			if (str.contains("IPC$") || str.contains("DOCS")) {
-				wordCount = new byte[] { 0x07 };
-				andXCommand = new byte[] { (byte) 0xff };
-				byte[] reserved = { 0x00 };
-				byte[] andXOffset = { 0x38, 0x00 };
-				byte[] optionalSupport = { 0x01, 0x00 };
-				byte[] maxShareAccess = { (byte) 0xff, (byte) 0xff, 0x1f, 0x00 };
-				byte[] guestMaxShareAccess = { (byte) 0xff, (byte) 0xff, 0x1f,
-						0x00 };
-				byte[] byteCount = { 0x07, 0x00 };
-				byte[] service = { 0x49, 0x50, 0x43, 0x00 };
-				byte[] extraParameters = { 0x00, 0x00, 0x00 };
-
-				treeID = new byte[] { 0x00, 0x08 };
-
-				response = concat(getHeader(), wordCount, andXCommand,
-						reserved, andXOffset, optionalSupport, maxShareAccess,
-						guestMaxShareAccess, byteCount, service,
-						extraParameters);
-			} else if (str.contains("C$") || str.contains("ADMIN$")) {
-				ntStat = new byte[] { 0x22, 0x00, 0x00, (byte) 0xc0 };
+			String str 			= toString();
+			byte[] wordCount	= {0x00};
+			byte[] andXCommand	= {0x00, 0x00};
+			byte[] response 	= null;
+			
+			if(str.contains("IPC$") || str.contains("DOCS")) {
+				wordCount			= new byte[] {0x07};
+				andXCommand			= new byte[] {(byte) 0xff};
+				byte[] reserved				= {0x00};
+				byte[] andXOffset			= {0x38, 0x00};
+				byte[] optionalSupport		= {0x01, 0x00};
+				byte[] maxShareAccess		= {(byte) 0xff, (byte) 0xff, 0x1f, 0x00};
+				byte[] guestMaxShareAccess	= {(byte) 0xff, (byte) 0xff, 0x1f, 0x00};
+				byte[] byteCount			= {0x07, 0x00};
+				byte[] service				= {0x49, 0x50, 0x43, 0x00};
+				byte[] extraParameters		= {0x00, 0x00, 0x00};
+			
+				treeID						= new byte[]{0x00, 0x08};
+							
+				response = concat(getHeader(), wordCount, andXCommand, reserved, andXOffset, optionalSupport, maxShareAccess,
+												guestMaxShareAccess, byteCount, service, extraParameters);
+			} else if(str.contains("C$") || str.contains("ADMIN$")) {
+				ntStat = new byte[] {0x22, 0x00, 0x00, (byte) 0xc0};
 				response = concat(getHeader(), wordCount, andXCommand);
 			} else {
-				ntStat = new byte[] { (byte) 0xcc, 0x00, 0x00, (byte) 0xc0 };
+				ntStat = new byte[] {(byte) 0xcc, 0x00, 0x00, (byte) 0xc0};
 				response = concat(getHeader(), wordCount, andXCommand);
 			}
-
+			
 			return concat(getNetbios(response), response);
 		}
-
+		
 		public byte[] getNTCreate() {
-			byte[] wordCount = { 0x22 };
-			byte[] andXCommand = { (byte) 0xff };
-			byte[] reserved = { 0x00 };
-			byte[] andXOffset = { 0x67, 0x00 };
-			byte[] oplockLevel = { 0x00 };
-			byte[] fid = { (byte) 0x00, 0x40 };
-			byte[] createAction = { 0x01, 0x00, 0x00, 0x00 };
-			byte[] created = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-			byte[] lastAccess = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-					0x00 };
-			byte[] lastWrite = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-			byte[] change = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-			byte[] fileAttributes = { (byte) 0x80, 0x00, 0x00, 0x00 };
-			byte[] allocationSize = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
-					0x00 };
-			byte[] endOfFile = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-			byte[] fileType = { 0x02, 0x00 };
-			byte[] ipcState = { (byte) 0xff, 0x05 };
-			byte[] isDirectory = { 0x00 };
-			byte[] byteCount = { 0x00, 0x00 };
-
-			byte[] response = concat(getHeader(), wordCount, andXCommand,
-					reserved, andXOffset, oplockLevel, fid, createAction,
-					created, lastAccess, lastWrite, change, fileAttributes,
-					allocationSize, endOfFile, fileType, ipcState, isDirectory,
-					byteCount);
+			byte[] wordCount		= {0x22};
+			byte[] andXCommand		= {(byte) 0xff};
+			byte[] reserved			= {0x00};
+			byte[] andXOffset		= {0x67, 0x00};
+			byte[] oplockLevel		= {0x00};
+			byte[] fid				= {(byte) 0x00, 0x40};
+			byte[] createAction		= {0x01, 0x00, 0x00, 0x00};
+			byte[] created			= {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+			byte[] lastAccess		= {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+			byte[] lastWrite		= {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+			byte[] change			= {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+			byte[] fileAttributes	= {(byte) 0x80, 0x00, 0x00, 0x00};
+			byte[] allocationSize	= {0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+			byte[] endOfFile		= {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+			byte[] fileType			= {0x02, 0x00};
+			byte[] ipcState			= {(byte) 0xff, 0x05};
+			byte[] isDirectory		= {0x00};
+			byte[] byteCount		= {0x00, 0x00};
+			
+			byte[] response = concat(getHeader(), wordCount, andXCommand, reserved, andXOffset, oplockLevel, fid,
+												createAction, created, lastAccess, lastWrite, change, fileAttributes, allocationSize,
+												endOfFile, fileType, ipcState, isDirectory, byteCount);
 			return concat(getNetbios(response), response);
 		}
-
+		
 		public byte[] getTrans() {
-			byte[] transSub = getTransSub();
+			byte[] transSub	= getTransSub();
 			byte[] response = null;
-			if (transSub[0] == 0x00 && transSub[1] == 0x0b) {
-				byte[] wordCount = { 0x0a };
-				byte[] totalParamCount = { 0x00, 0x00 };
-				byte[] totalDataCount = { 0x44, 0x00 };
-				byte[] reserved = { 0x00, 0x00 };
-				byte[] paramCount = { 0x00, 0x00 };
-				byte[] paramOffset = { 0x38, 0x00 };
-				byte[] paramDisplace = { 0x00, 0x00 };
-				byte[] dataCount = { 0x44, 0x00 };
-				byte[] dataOffset = { 0x38, 0x00 };
-				byte[] dataDisplace = { 0x00, 0x00 };
-				byte[] setupCount = { 0x00 };
-				byte[] reserved2 = { 0x00 };
-				byte[] byteCount = { 0x45, 0x00 };
-				byte[] padding = { 0x00 };
-
-				byte[] dcerpc = { 0x05, 0x00, 0x0c, 0x03, 0x10, 0x00, 0x00,
-						0x00, 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
-						(byte) 0xb8, 0x10, (byte) 0xb8, 0x10, 0x4a, 0x41, 0x00,
-						0x00, 0x0d, 0x00, 0x5c, 0x50, 0x49, 0x50, 0x45, 0x5c,
-						0x73, 0x72, 0x76, 0x73, 0x76, 0x63, 0x00, 0x00, 0x01,
-						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x5d,
-						(byte) 0x88, (byte) 0x8a, (byte) 0xeb, 0x1c,
-						(byte) 0xc9, 0x11, (byte) 0x9f, (byte) 0xe8, 0x08,
-						0x00, 0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00 };
-
-				response = concat(getHeader(), wordCount, totalParamCount,
-						totalDataCount, reserved, paramCount, paramOffset,
-						paramDisplace, dataCount, dataOffset, dataDisplace,
-						setupCount, reserved2, byteCount, padding, dcerpc);
-
-			} else if (transSub[0] == 0x00 && transSub[1] == 0x00) {
-				byte[] wordCount = { 0x0a };
-				byte[] totalParamCount = { 0x00, 0x00 };
-				byte[] totalDataCount = { 0x54, 0x01 };
-				byte[] reserved = { 0x00, 0x00 };
-				byte[] paramCount = { 0x00, 0x00 };
-				byte[] paramOffset = { 0x38, 0x00 };
-				byte[] paramDisplace = { 0x00, 0x00 };
-				byte[] dataCount = { 0x54, 0x01 };
-				byte[] dataOffset = { 0x38, 0x00 };
-				byte[] dataDisplace = { 0x00, 0x00 };
-				byte[] setupCount = { 0x00 };
-				byte[] reserved2 = { 0x00 };
-				byte[] byteCount = { 0x55, 0x01 };
-				byte[] padding = { 0x00 };
-
-				byte[] dcerpc = { 0x05, 0x00, 0x02, 0x03, 0x10, 0x00, 0x00,
-						0x00, 0x54, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
-						0x3c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-				byte[] serverService = { 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
-						0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00,
-						0x00, 0x04, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00,
-						0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, (byte) 0x80,
-						0x0c, 0x00, 0x02, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00,
-						0x00, 0x00, (byte) 0x80, 0x14, 0x00, 0x02, 0x00, 0x18,
-						0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00,
-						0x02, 0x00, 0x20, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00,
-						(byte) 0x80, 0x24, 0x00, 0x02, 0x00, 0x07, 0x00, 0x00,
-						0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
-						0x41, 0x00, 0x44, 0x00, 0x4d, 0x00, 0x49, 0x00, 0x4e,
-						0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00,
-						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00,
-						0x00, 0x52, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x6f, 0x00,
-						0x74, 0x00, 0x65, 0x00, 0x20, 0x00, 0x41, 0x00, 0x64,
-						0x00, 0x6d, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x00, 0x00,
-						0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-						0x00, 0x03, 0x00, 0x00, 0x00, 0x43, 0x00, 0x24, 0x00,
-						0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
-						0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x44, 0x00,
-						0x65, 0x00, 0x66, 0x00, 0x61, 0x00, 0x75, 0x00, 0x6c,
-						0x00, 0x74, 0x00, 0x20, 0x00, 0x73, 0x00, 0x68, 0x00,
-						0x61, 0x00, 0x72, 0x00, 0x65, 0x00, 0x00, 0x00, 0x05,
-						0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00,
-						0x00, 0x00, 0x64, 0x00, 0x6f, 0x00, 0x63, 0x00, 0x73,
-						0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
-						0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
-						0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
-						0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x49, 0x00, 0x50,
-						0x00, 0x43, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
-						0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b,
-						0x00, 0x00, 0x00, 0x52, 0x00, 0x65, 0x00, 0x6d, 0x00,
-						0x6f, 0x00, 0x74, 0x00, 0x65, 0x00, 0x20, 0x00, 0x49,
-						0x00, 0x50, 0x00, 0x43, 0x00, 0x00, 0x00 };
-				byte[] totalEntries = { 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 };
-				byte[] referentID = { 0x28, 0x00, 0x02, 0x00 };
-				byte[] resumeHandle = { 0x00, 0x00, 0x00, 0x00 };
-				byte[] windowsError = { 0x00, 0x00, 0x00, 0x00 };
-
-				response = concat(getHeader(), wordCount, totalParamCount,
-						totalDataCount, reserved, paramCount, paramOffset,
-						paramDisplace, dataCount, dataOffset, dataDisplace,
-						setupCount, reserved2, byteCount, padding, dcerpc,
-						serverService, totalEntries, referentID, resumeHandle,
-						windowsError);
-
+			if(transSub[0] == 0x00 && transSub[1] == 0x0b) {
+				byte[] wordCount		= {0x0a};
+				byte[] totalParamCount	= {0x00,0x00};
+				byte[] totalDataCount	= {0x44,0x00};
+				byte[] reserved			= {0x00, 0x00};
+				byte[] paramCount		= {0x00, 0x00};
+				byte[] paramOffset		= {0x38, 0x00};
+				byte[] paramDisplace	= {0x00, 0x00};
+				byte[] dataCount		= {0x44, 0x00};
+				byte[] dataOffset		= {0x38, 0x00};
+				byte[] dataDisplace		= {0x00, 0x00};
+				byte[] setupCount		= {0x00};
+				byte[] reserved2		= {0x00};
+				byte[] byteCount		= {0x45, 0x00};
+				byte[] padding			= {0x00};
+				
+				byte[] dcerpc			= {0x05, 0x00, 
+											0x0c, 0x03, 0x10, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, (byte) 0xb8, 0x10, 
+											(byte) 0xb8, 0x10, 0x4a, 0x41, 0x00, 0x00, 0x0d, 0x00, 0x5c, 0x50, 0x49, 0x50, 0x45, 0x5c, 0x73, 0x72, 
+											0x76, 0x73, 0x76, 0x63, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x5d, 
+											(byte) 0x88, (byte) 0x8a, (byte) 0xeb, 0x1c, (byte) 0xc9, 0x11, (byte) 0x9f, (byte) 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 
+											0x00, 0x00}; 
+				
+				response = concat(getHeader(), wordCount, totalParamCount, totalDataCount, reserved, paramCount, paramOffset,
+													paramDisplace, dataCount, dataOffset, dataDisplace, setupCount, reserved2, byteCount, padding, dcerpc);
+				
+			} else if(transSub[0] == 0x00 && transSub[1] == 0x00) {
+				byte[] wordCount		= {0x0a};
+				byte[] totalParamCount	= {0x00, 0x00};
+				byte[] totalDataCount	= {0x54, 0x01};
+				byte[] reserved			= {0x00, 0x00};
+				byte[] paramCount		= {0x00, 0x00};
+				byte[] paramOffset		= {0x38, 0x00};
+				byte[] paramDisplace	= {0x00, 0x00};
+				byte[] dataCount		= {0x54, 0x01};
+				byte[] dataOffset		= {0x38, 0x00};
+				byte[] dataDisplace		= {0x00, 0x00};
+				byte[] setupCount		= {0x00};
+				byte[] reserved2		= {0x00};
+				byte[] byteCount		= {0x55, 0x01};
+				byte[] padding			= {0x00};
+				
+				byte[] dcerpc			= {0x05, 0x00, 
+											0x02, 0x03, 0x10, 0x00, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3c, 0x01, 
+											0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+				byte[] serverService	= {0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 
+											0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 
+											0x02, 0x00, 0x00, 0x00, 0x00, (byte) 0x80, 0x0c, 0x00, 0x02, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 
+											0x00, (byte) 0x80, 0x14, 0x00, 0x02, 0x00, 0x18, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 
+											0x02, 0x00, 0x20, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, (byte) 0x80, 0x24, 0x00, 0x02, 0x00, 0x07, 0x00, 
+											0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x41, 0x00, 0x44, 0x00, 0x4d, 0x00, 
+											0x49, 0x00, 0x4e, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 
+											0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x52, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x6f, 0x00, 0x74, 0x00, 
+											0x65, 0x00, 0x20, 0x00, 0x41, 0x00, 0x64, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x00, 0x00, 
+											0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x43, 0x00, 
+											0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 
+											0x00, 0x00, 0x44, 0x00, 0x65, 0x00, 0x66, 0x00, 0x61, 0x00, 0x75, 0x00, 0x6c, 0x00, 0x74, 0x00, 
+											0x20, 0x00, 0x73, 0x00, 0x68, 0x00, 0x61, 0x00, 0x72, 0x00, 0x65, 0x00, 0x00, 0x00, 0x05, 0x00, 
+											0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x64, 0x00, 0x6f, 0x00, 0x63, 0x00, 
+											0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 
+											0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 
+											0x00, 0x00, 0x49, 0x00, 0x50, 0x00, 0x43, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 
+											0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x52, 0x00, 0x65, 0x00, 0x6d, 0x00, 
+											0x6f, 0x00, 0x74, 0x00, 0x65, 0x00, 0x20, 0x00, 0x49, 0x00, 0x50, 0x00, 0x43, 0x00, 0x00, 0x00};
+				byte[] totalEntries		= {0x00, 0x00, 0x04, 0x00, 0x00, 0x00};
+				byte[] referentID		= {0x28, 0x00, 0x02, 0x00};
+				byte[] resumeHandle		= {0x00, 0x00, 0x00, 0x00};
+				byte[] windowsError		= {0x00, 0x00, 0x00, 0x00};
+
+				response = concat(getHeader(), wordCount, totalParamCount, totalDataCount, reserved, paramCount, paramOffset,
+													paramDisplace, dataCount, dataOffset, dataDisplace, setupCount, reserved2, byteCount, padding, dcerpc,
+													serverService, totalEntries, referentID, resumeHandle, windowsError);
+				
+				
 			}
-
-			return concat(getNetbios(response), response);
+			
+			return concat(getNetbios(response), response);		
 		}
-
+		
 		public byte[] getClose() {
-			byte[] wordCount = { 0x00 };
-			byte[] byteCount = { 0x00, 0x00 };
-
-			smbCommand = new byte[] { 0x04 };
-
+			byte[] wordCount	= {0x00};
+			byte[] byteCount	= {0x00, 0x00};
+			
+			smbCommand			= new byte[]{0x04};
+			
 			byte[] response = concat(getHeader(), wordCount, byteCount);
-
+			
 			return concat(getNetbios(response), response);
 		}
-
+		
 		public byte[] getTreeDisc() {
-			byte[] wordCount = { 0x00 };
-			byte[] byteCount = { 0x00, 0x00 };
-
+			byte[] wordCount	= {0x00};
+			byte[] byteCount	= {0x00, 0x00};
+			
 			smbCommand[0] = 0x71;
-
+			
 			byte[] response = concat(getHeader(), wordCount, byteCount);
-
+			
 			return concat(getNetbios(response), response);
 		}
-
+		
 		public byte[] getEcho() {
-			byte[] wordCount = { 0x01 };
-			byte[] echoSeq = { 0x01, 0x00 };
-			byte[] byteCount = { 0x10, 0x00 };
-			byte[] echoData = { (byte) 0xf0, (byte) 0xf0, (byte) 0xf0,
-					(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0,
-					(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0,
-					(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0,
-					(byte) 0xf0 };
-			byte[] response = concat(getHeader(), wordCount, echoSeq,
-					byteCount, echoData);
+			byte[] wordCount	= {0x01};
+			byte[] echoSeq		= {0x01, 0x00};
+			byte[] byteCount	= {0x10, 0x00};
+			byte[] echoData		= {(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0,
+									(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0}; 
+			byte[] response = concat(getHeader(),  wordCount, echoSeq, byteCount, echoData);
 			return concat(getNetbios(response), response);
 
 		}
-
+		
 		public byte[] getTrans2() {
-			byte[] response = null;
-			byte[] wordCount = { 0x00 };
-			byte[] andXCommand = { 0x00, 0x00 };
-			ntStat = new byte[] { 0x22, 0x00, 0x00, (byte) 0xc0 };
+			byte[] response = null;		
+			byte[] wordCount	= {0x00};
+			byte[] andXCommand	= {0x00, 0x00};
+			ntStat = new byte[] {0x22, 0x00, 0x00, (byte) 0xc0};
 			response = concat(getHeader(), wordCount, andXCommand);
 			return concat(getNetbios(response), response);
 		}
-
+				
 		private byte[] getTransSub() {
 			byte[] transSub = new byte[2];
-			if (smbCommand[0] == 0x32)
-				transSub = new byte[] { msg[66], msg[65] };
-			else if (smbCommand[0] == 0x25)
-				transSub = new byte[] { 0x00, msg[90] };
-			else
-				transSub = new byte[] { 0x00, 0x00 };
+			if(smbCommand[0] == 0x32) transSub = new byte[]{msg[66], msg[65]};
+			else if(smbCommand[0] == 0x25) transSub = new byte[]{0x00, msg[90]};
+			else transSub = new byte[]{0x00, 0x00};
 			return transSub;
 		}
-
+		
 		public String toString() {
-			return new String(msg);
+			return byteToStr(msg);
 		}
-
+		
 		public byte getSmbCommand() {
 			return smbCommand[0];
 		}

+ 2 - 4
src/de/tudarmstadt/informatik/hostage/protocol/TELNET.java

@@ -41,8 +41,7 @@ public final class TELNET implements Protocol<ByteArray> {
 			state = STATE.LOGIN;
 			break;
 		case LOGIN:
-			usr = java.util.Arrays.copyOfRange(message.get(), 0,
-					message.size() - 2);
+			System.arraycopy(message.get(), 0, usr, 0, message.size() - 2);
 			response.add(new ByteArray("Password: ".getBytes()));
 			state = STATE.AUTHENTICATE;
 			break;
@@ -53,8 +52,7 @@ public final class TELNET implements Protocol<ByteArray> {
 			state = STATE.LOGGED_IN;
 			break;
 		case LOGGED_IN:
-			cmd = java.util.Arrays.copyOfRange(message.get(), 0,
-					message.size() - 2);
+			System.arraycopy(message.get(), 0, cmd, 0, message.size() - 2);
 			if (new String(cmd).contains("exit")) {
 				response.add(new ByteArray("logout\r\n".getBytes()));
 				state = STATE.CLOSED;

+ 9 - 0
src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java

@@ -30,6 +30,7 @@ import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.TextView;
+import android.widget.Toast;
 import android.widget.ToggleButton;
 import android.widget.ViewAnimator;
 import de.tudarmstadt.informatik.hostage.HoneyListener;
@@ -37,6 +38,7 @@ import de.tudarmstadt.informatik.hostage.HoneyService;
 import de.tudarmstadt.informatik.hostage.HoneyService.LocalBinder;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
 
 public class MainActivity extends Activity {
 
@@ -432,5 +434,12 @@ public class MainActivity extends Activity {
 			return true;
 		}
 	};
+	
+	
+	//TODO NACH TEST ENTFERNEN
+	public void showLog(View view){
+		startActivity(new Intent(this, ViewLog.class));
+	}
+
 
 }

+ 82 - 0
src/de/tudarmstadt/informatik/hostage/ui/ViewLog.java

@@ -0,0 +1,82 @@
+package de.tudarmstadt.informatik.hostage.ui;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+
+import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class ViewLog extends Activity {
+
+	HashMap<String, TextView> statisticCounter;
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_viewlog);
+
+		initStatistic();
+	}
+
+	@Override
+	public boolean onCreateOptionsMenu(Menu menu) {
+		getMenuInflater().inflate(R.menu.main, menu);
+		return true;
+	}
+	
+	public void showLog(View view){
+		startActivity(new Intent(this, ViewLogTable.class));
+	}
+	
+	public void deleteLog(View view){
+		DatabaseHandler dbh = new DatabaseHandler(getBaseContext());		
+		dbh.clearData();
+	}
+
+	private void initStatistic() {
+		LinearLayout container = (LinearLayout) findViewById(R.id.layoutContainer);
+		statisticCounter = new HashMap<String, TextView>();
+		DatabaseHandler dbh = new DatabaseHandler(getBaseContext());
+
+		ArrayList<String> protocols = new ArrayList<String>();
+		protocols.add("Total");
+		protocols.addAll(Arrays.asList(getResources().getStringArray(
+				R.array.protocols)));
+
+		for (String protocol : protocols) {
+			LinearLayout containerRow = new LinearLayout(this);
+			TextView text = new TextView(this);
+			text.setText("-" + protocol + ": ");
+			text.setTextAppearance(this, android.R.style.TextAppearance_Medium);
+			containerRow.addView(text);
+			text = new TextView(this);
+			text.setTextAppearance(this, android.R.style.TextAppearance_Medium);
+			containerRow.addView(text);
+			if(protocol.equals("Total")){
+				text.setText("" + dbh.getAttackCount());
+			}else{
+				text.setText("" + dbh.getAttackPerProtokolCount(protocol));
+			}
+			statisticCounter.put(protocol, text);
+			container.addView(containerRow);
+		}
+		
+        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
+        Date resultdate = new Date(Long.parseLong(dbh.getRecord(1).getTimestamp()));
+        TextView text = (TextView) findViewById(R.id.textFirstAttackValue);
+        text.setText(sdf.format(resultdate));
+        text = (TextView) findViewById(R.id.textLastAttackValue);
+        resultdate = new Date(Long.parseLong(dbh.getRecord( dbh.getRecordCount()).getTimestamp()));
+        text.setText(sdf.format(resultdate));
+	}
+}

+ 30 - 0
src/de/tudarmstadt/informatik/hostage/ui/ViewLogTable.java

@@ -0,0 +1,30 @@
+package de.tudarmstadt.informatik.hostage.ui;
+
+import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
+import de.tudarmstadt.informatik.hostage.logging.SQLRecord;
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+public class ViewLogTable extends Activity{
+	
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		DatabaseHandler db = new DatabaseHandler(getBaseContext());
+		String log = "";
+		for(SQLRecord record: db.getAllRecords())
+		{
+			log = log + record.toString() + "\n";
+		}
+		
+		ScrollView scroll = new ScrollView(this);
+		TextView text = new TextView(getApplicationContext());
+		text.setText(log);
+		scroll.addView(text);
+		setContentView(scroll);
+
+	}
+
+}