Browse Source

- Fixed some protocol issues
- extended HTTP

qam 10 years ago
parent
commit
7d38dbc31a

BIN
bin/classes.dex


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


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


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


BIN
bin/hostage.apk


BIN
bin/resources.ap_


+ 149 - 149
gen/de/tudarmstadt/informatik/hostage/R.java

@@ -1,149 +1,149 @@
-/* AUTO-GENERATED FILE.  DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found.  It
- * should not be modified by hand.
- */
-
-package de.tudarmstadt.informatik.hostage;
-
-public final class R {
-    public static final class anim {
-        public static final int in_left_to_right=0x7f040000;
-        public static final int in_right_to_left=0x7f040001;
-        public static final int out_left_to_right=0x7f040002;
-        public static final int out_right_to_left=0x7f040003;
-    }
-    public static final class array {
-        public static final int protocols=0x7f070002;
-        public static final int upload_entries=0x7f070000;
-        public static final int upload_values=0x7f070001;
-    }
-    public static final class attr {
-    }
-    public static final class dimen {
-        /**  Default screen margins, per the Android Design guidelines. 
-
-         Customize dimensions originally defined in res/values/dimens.xml (such as
-         screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
-    
-         */
-        public static final int activity_horizontal_margin=0x7f060000;
-        public static final int activity_vertical_margin=0x7f060001;
-    }
-    public static final class drawable {
-        public static final int ic_launcher=0x7f020000;
-        public static final int light_green=0x7f020001;
-        public static final int light_green_large=0x7f020002;
-        public static final int light_grey=0x7f020003;
-        public static final int light_grey_large=0x7f020004;
-        public static final int light_red=0x7f020005;
-        public static final int light_red_large=0x7f020006;
-        public static final int light_yellow=0x7f020007;
-        public static final int light_yellow_large=0x7f020008;
-    }
-    public static final class id {
-        public static final int TextViewServices=0x7f0b000f;
-        public static final int action_settings=0x7f0b001d;
-        public static final int buttonDeleteLog=0x7f0b0019;
-        public static final int buttonShowLog=0x7f0b0005;
-        public static final int buttonUploadLog=0x7f0b0018;
-        public static final int checkBoxParanoid=0x7f0b0003;
-        public static final int imageViewLight=0x7f0b0002;
-        public static final int layoutContainer=0x7f0b0012;
-        public static final int listViewProtocols=0x7f0b0010;
-        public static final int textFirstAttack=0x7f0b0013;
-        public static final int textFirstAttackValue=0x7f0b0014;
-        public static final int textLastAttack=0x7f0b0015;
-        public static final int textLastAttackValue=0x7f0b0016;
-        public static final int textLogFile=0x7f0b0017;
-        public static final int textStatistics=0x7f0b0011;
-        public static final int textViewBSSID=0x7f0b0009;
-        public static final int textViewBSSIDValue=0x7f0b000a;
-        public static final int textViewConnections=0x7f0b001b;
-        public static final int textViewConnectionsValue=0x7f0b001c;
-        public static final int textViewDetails=0x7f0b0006;
-        public static final int textViewExternalIP=0x7f0b000d;
-        public static final int textViewExternalIPValue=0x7f0b000e;
-        public static final int textViewInternalIP=0x7f0b000b;
-        public static final int textViewInternalIPValue=0x7f0b000c;
-        public static final int textViewProtocol=0x7f0b001a;
-        public static final int textViewSSID=0x7f0b0007;
-        public static final int textViewSSIDValue=0x7f0b0008;
-        public static final int textViewStatus=0x7f0b0001;
-        public static final int toggleButtonOnOff=0x7f0b0004;
-        public static final int viewAnimator=0x7f0b0000;
-    }
-    public static final class layout {
-        public static final int activity_main=0x7f030000;
-        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=0x7f0a0000;
-    }
-    public static final class string {
-        public static final int action_settings=0x7f080001;
-        public static final int app_name=0x7f080000;
-        public static final int bssid=0x7f080008;
-        public static final int capital_off=0x7f080003;
-        public static final int capital_on=0x7f080002;
-        public static final int connections=0x7f08000c;
-        public static final int details=0x7f080006;
-        public static final int external_ip=0x7f08000a;
-        public static final int firstAttack=0x7f08000f;
-        public static final int internal_ip=0x7f080009;
-        public static final int lastAttack=0x7f080010;
-        public static final int logFile=0x7f08000e;
-        public static final int paranoid=0x7f080005;
-        public static final int pref_alarm=0x7f080012;
-        public static final int pref_alarm_default=0x7f080013;
-        public static final int pref_external_storage_summ=0x7f080016;
-        public static final int pref_external_storage_title=0x7f080015;
-        public static final int pref_notification=0x7f080017;
-        public static final int pref_storage=0x7f080014;
-        public static final int pref_tracing=0x7f08001a;
-        public static final int pref_upload=0x7f08001b;
-        public static final int pref_upload_connection=0x7f08001d;
-        public static final int pref_upload_connection_summ=0x7f08001e;
-        public static final int pref_upload_summ=0x7f08001c;
-        public static final int pref_vibration=0x7f080018;
-        public static final int pref_vibration_summ=0x7f080019;
-        public static final int services=0x7f08000b;
-        public static final int settings=0x7f080011;
-        public static final int ssid=0x7f080007;
-        public static final int statistics=0x7f08000d;
-        public static final int status=0x7f080004;
-    }
-    public static final class style {
-        /** 
-        Base application theme, dependent on API level. This theme is replaced
-        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-    
-
-            Theme customizations available in newer API levels can go in
-            res/values-vXX/styles.xml, while customizations related to
-            backward-compatibility can go here.
-        
-
-        Base application theme for API 11+. This theme completely replaces
-        AppBaseTheme from res/values/styles.xml on API 11+ devices.
-    
- API 11 theme customizations can go here. 
-
-        Base application theme for API 14+. This theme completely replaces
-        AppBaseTheme from BOTH res/values/styles.xml and
-        res/values-v11/styles.xml on API 14+ devices.
-    
- API 14 theme customizations can go here. 
-         */
-        public static final int AppBaseTheme=0x7f090000;
-        /**  Application theme. 
- All customizations that are NOT specific to a particular API-level can go here. 
-         */
-        public static final int AppTheme=0x7f090001;
-    }
-    public static final class xml {
-        public static final int preferences=0x7f050000;
-    }
-}
+/* AUTO-GENERATED FILE.  DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found.  It
+ * should not be modified by hand.
+ */
+
+package de.tudarmstadt.informatik.hostage;
+
+public final class R {
+    public static final class anim {
+        public static final int in_left_to_right=0x7f040000;
+        public static final int in_right_to_left=0x7f040001;
+        public static final int out_left_to_right=0x7f040002;
+        public static final int out_right_to_left=0x7f040003;
+    }
+    public static final class array {
+        public static final int protocols=0x7f070002;
+        public static final int upload_entries=0x7f070000;
+        public static final int upload_values=0x7f070001;
+    }
+    public static final class attr {
+    }
+    public static final class dimen {
+        /**  Default screen margins, per the Android Design guidelines. 
+
+         Customize dimensions originally defined in res/values/dimens.xml (such as
+         screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
+    
+         */
+        public static final int activity_horizontal_margin=0x7f060000;
+        public static final int activity_vertical_margin=0x7f060001;
+    }
+    public static final class drawable {
+        public static final int ic_launcher=0x7f020000;
+        public static final int light_green=0x7f020001;
+        public static final int light_green_large=0x7f020002;
+        public static final int light_grey=0x7f020003;
+        public static final int light_grey_large=0x7f020004;
+        public static final int light_red=0x7f020005;
+        public static final int light_red_large=0x7f020006;
+        public static final int light_yellow=0x7f020007;
+        public static final int light_yellow_large=0x7f020008;
+    }
+    public static final class id {
+        public static final int TextViewServices=0x7f0b000f;
+        public static final int action_settings=0x7f0b001d;
+        public static final int buttonDeleteLog=0x7f0b0019;
+        public static final int buttonShowLog=0x7f0b0005;
+        public static final int buttonUploadLog=0x7f0b0018;
+        public static final int checkBoxParanoid=0x7f0b0003;
+        public static final int imageViewLight=0x7f0b0002;
+        public static final int layoutContainer=0x7f0b0012;
+        public static final int listViewProtocols=0x7f0b0010;
+        public static final int textFirstAttack=0x7f0b0013;
+        public static final int textFirstAttackValue=0x7f0b0014;
+        public static final int textLastAttack=0x7f0b0015;
+        public static final int textLastAttackValue=0x7f0b0016;
+        public static final int textLogFile=0x7f0b0017;
+        public static final int textStatistics=0x7f0b0011;
+        public static final int textViewBSSID=0x7f0b0009;
+        public static final int textViewBSSIDValue=0x7f0b000a;
+        public static final int textViewConnections=0x7f0b001b;
+        public static final int textViewConnectionsValue=0x7f0b001c;
+        public static final int textViewDetails=0x7f0b0006;
+        public static final int textViewExternalIP=0x7f0b000d;
+        public static final int textViewExternalIPValue=0x7f0b000e;
+        public static final int textViewInternalIP=0x7f0b000b;
+        public static final int textViewInternalIPValue=0x7f0b000c;
+        public static final int textViewProtocol=0x7f0b001a;
+        public static final int textViewSSID=0x7f0b0007;
+        public static final int textViewSSIDValue=0x7f0b0008;
+        public static final int textViewStatus=0x7f0b0001;
+        public static final int toggleButtonOnOff=0x7f0b0004;
+        public static final int viewAnimator=0x7f0b0000;
+    }
+    public static final class layout {
+        public static final int activity_main=0x7f030000;
+        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=0x7f0a0000;
+    }
+    public static final class string {
+        public static final int action_settings=0x7f080001;
+        public static final int app_name=0x7f080000;
+        public static final int bssid=0x7f080008;
+        public static final int capital_off=0x7f080003;
+        public static final int capital_on=0x7f080002;
+        public static final int connections=0x7f08000c;
+        public static final int details=0x7f080006;
+        public static final int external_ip=0x7f08000a;
+        public static final int firstAttack=0x7f08000f;
+        public static final int internal_ip=0x7f080009;
+        public static final int lastAttack=0x7f080010;
+        public static final int logFile=0x7f08000e;
+        public static final int paranoid=0x7f080005;
+        public static final int pref_alarm=0x7f080012;
+        public static final int pref_alarm_default=0x7f080013;
+        public static final int pref_external_storage_summ=0x7f080016;
+        public static final int pref_external_storage_title=0x7f080015;
+        public static final int pref_notification=0x7f080017;
+        public static final int pref_storage=0x7f080014;
+        public static final int pref_tracing=0x7f08001a;
+        public static final int pref_upload=0x7f08001b;
+        public static final int pref_upload_connection=0x7f08001d;
+        public static final int pref_upload_connection_summ=0x7f08001e;
+        public static final int pref_upload_summ=0x7f08001c;
+        public static final int pref_vibration=0x7f080018;
+        public static final int pref_vibration_summ=0x7f080019;
+        public static final int services=0x7f08000b;
+        public static final int settings=0x7f080011;
+        public static final int ssid=0x7f080007;
+        public static final int statistics=0x7f08000d;
+        public static final int status=0x7f080004;
+    }
+    public static final class style {
+        /** 
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    
+
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        
+
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    
+ API 11 theme customizations can go here. 
+
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    
+ API 14 theme customizations can go here. 
+         */
+        public static final int AppBaseTheme=0x7f090000;
+        /**  Application theme. 
+ All customizations that are NOT specific to a particular API-level can go here. 
+         */
+        public static final int AppTheme=0x7f090001;
+    }
+    public static final class xml {
+        public static final int preferences=0x7f050000;
+    }
+}

+ 83 - 15
src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java

@@ -2,10 +2,15 @@ package de.tudarmstadt.informatik.hostage.protocol;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.regex.Pattern;
 
 public final class HTTP implements Protocol<String> {
+	
+	private enum STATE {
+		NONE, CLOSED
+	}
 
+	private STATE state = STATE.NONE;
+	
 	@Override
 	public int getPort() {
 		return 80;
@@ -19,21 +24,42 @@ public final class HTTP implements Protocol<String> {
 	@Override
 	public List<String> processMessage(String message) {
 		List<String> response = new ArrayList<String>();
-		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");
+		request = message + request;
+		System.out.println(request);
+		
+		switch(state) {
+		case NONE:
+			if(!message.contains(version)){
+				response.add(buildPacket(versionUnsupported, ""));
+			} else if(message.contains(get)) {
+				response.add(buildPacket(ok, get));
+			} else if(message.contains(head)) {
+				response.add(buildPacket(ok, head));
+			} else if(message.contains(trace)){
+				response.add(buildPacket(ok, trace));
+			} else if(message.contains(options)){
+				response.add(buildPacket(methodNotAllowed, options));
+			} else if(message.contains(post)){
+				response.add(buildPacket(methodNotAllowed, post));
+			} else if(message.contains(put)){
+				response.add(buildPacket(methodNotAllowed, put));
+			} else if(message.contains(delete)){
+				response.add(buildPacket(methodNotAllowed, delete));
+			} else if(message.contains(connect)){
+				response.add(buildPacket(methodNotAllowed, connect));
+			} else {
+				response.add(buildPacket(badRequest, ""));
+			}
+			state = STATE.CLOSED;
+		default:
+			state = STATE.CLOSED;
 		}
 		return response;
 	}
 
 	@Override
 	public boolean isClosed() {
-		return false;
+		return state == STATE.CLOSED;
 	}
 
 	@Override
@@ -50,19 +76,49 @@ public final class HTTP implements Protocol<String> {
 	public String toString() {
 		return "HTTP";
 	}
+	
+	private String buildPacket(String code, String type) {
+		String doc = "";
+		if(type.equals(get)) doc = htmlDoc;
+		else if(type.equals(head)) doc = "";
+		else if(type.equals(trace)) doc = request;
+		else doc = errorHtmlPrefix + code + errorHtmlSuffix;
+		
+		return version + code + headerPrefix + doc.length() + headerSuffix + doc;
+	}
 
-	private String header =	"HTTP/1.1 200 OK\r\n" +
+	private String request = "";
+	private String version = "HTTP/1.1";
+	
+	private String options 	= "OPTIONS";
+	private String get 		= "GET";
+	private String head 	= "HEAD";
+	private String post		= "POST";
+	private String put		= "PUT";
+	private String delete	= "DELETE";
+	private String trace	= "TRACE";
+	private String connect	= "CONNECT";
+	
+	private String ok 					= " 200 OK\r\n";
+	private String badRequest 			= " 400 Bad Request\r\n";
+	private String methodNotAllowed 	= " 405 Method Not Allowed\r\n";
+	private String versionUnsupported 	= " 505 HTTP Version not supported\r\n";
+	
+	
+	private String headerPrefix =				
 			"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" +	
+			"Content-Length: ";
+	private String headerSuffix =
+			"\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 html = "<!doctype html>\n" +
+	private String htmlDoc = 
+			"<!doctype html>\n" +
 			"<html lang=\"en\">\n" +
 			"<head>\n" +
 			"<meta charset=\"UTF-8\">\n" +
@@ -73,5 +129,17 @@ public final class HTTP implements Protocol<String> {
 			"<p>Congratulations.</p>\n" +
 			"</body>\n" +
 			"</html>";
-
+	
+	private String errorHtmlPrefix =
+			"<!doctype html>\n" +
+			"<html lang=\"en\">\n" +
+			"<head>\n" +
+			"<meta charset=\"UTF-8\">\n" +
+			"<title>";
+	private String errorHtmlSuffix =
+			"</title>\n" +
+			"</head>\n" +
+			"<body>\n" +
+			"</body>\n" +
+			"</html>";
 }

+ 2 - 7
src/de/tudarmstadt/informatik/hostage/protocol/MySQL.java

@@ -9,7 +9,7 @@ import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
 
 public class MySQL implements Protocol<ByteArray>{
 	private enum STATE {
-		NONE, CONNECTED, LOGIN_INFO, AUTHENTICATE, LOGGED_IN, CLOSED
+		NONE, CONNECTED, LOGIN_INFO, CLOSED
 	}
 	
 	private STATE state = STATE.NONE;
@@ -34,18 +34,13 @@ public class MySQL implements Protocol<ByteArray>{
 			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()));
+				response.add(new ByteArray(responseOK()));
 			} else {
 				response.add(new ByteArray(responseError()));
 			}
 			break;
-		case AUTHENTICATE:
-			break;
-		case LOGGED_IN:
-			break;
 		default:
 			state = STATE.CLOSED;
 			break;

+ 1 - 0
src/de/tudarmstadt/informatik/hostage/protocol/SMB.java

@@ -35,6 +35,7 @@ public final class SMB implements Protocol<ByteArray> {
 		packet.newMsg(primitiveByteArray);
 		byte smbCommand = packet.getSmbCommand();
 		List<ByteArray> response = new ArrayList<ByteArray>();
+
 		switch (state) {
 		case NONE:
 			if (smbCommand == 0x72) {

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

@@ -41,14 +41,21 @@ public final class TELNET implements Protocol<ByteArray> {
 			state = STATE.LOGIN;
 			break;
 		case LOGIN:
+			if(message.get()[0] == (byte) 0xff && message.get()[1] == (byte) 0xf4) {
+				state = STATE.CLOSED;
+				break;
+			}
 			usr = new byte[message.size()-2];
 			System.arraycopy(message.get(), 0, usr, 0, message.size() - 2);
 			response.add(new ByteArray("Password: ".getBytes()));
 			state = STATE.AUTHENTICATE;
 			break;
 		case AUTHENTICATE:
-			response.add(new ByteArray(
-					"Last Login: \r\nLinux raspberrypi 3.6.11+\r\n".getBytes()));
+			if(message.get()[0] == 0xff && message.get()[1] == 0xf4) {
+				state = STATE.CLOSED;
+				break;
+			}
+			response.add(new ByteArray("Last Login: \r\nLinux raspberrypi 3.6.11+\r\n".getBytes()));
 			response.add(new ByteArray(concatenate(a, usr, b, usr, c)));
 			state = STATE.LOGGED_IN;
 			break;