Browse Source

-HTTP: added qotds from servers or random String if no
internet-connection is available

-minor changes

Wulf Pfeiffer 10 years ago
parent
commit
25dab82959

BIN
assets/p


BIN
native/p


BIN
native/p.o


+ 50 - 1
src/de/tudarmstadt/informatik/hostage/HoneyService.java

@@ -1,5 +1,9 @@
 package de.tudarmstadt.informatik.hostage;
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.Socket;
+import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -14,6 +18,7 @@ import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
 import android.net.ConnectivityManager;
 import android.net.Uri;
+import android.os.AsyncTask;
 import android.os.Binder;
 import android.os.IBinder;
 import android.preference.PreferenceManager;
@@ -36,6 +41,7 @@ import de.tudarmstadt.informatik.hostage.ui.MainActivity;
  * Creates Notifications to inform the user what it happening.
  * @author Mihai Plasoianu 
  * @author Lars Pandikow
+ * @author Wulf Pfeiffer
  */
 public class HoneyService extends Service {
 
@@ -78,7 +84,8 @@ public class HoneyService extends Service {
 			listeners.add(new HoneyListener(this, protocol));
 		}
 		registerNetReceiver();
-		getLocationData();
+//		getLocationData(); //TODO dafuq geht hier nicht?
+		generateQotd();
 	}
 	
     @Override
@@ -350,4 +357,46 @@ public class HoneyService extends Service {
 		}
 	}
 
+	/**
+	 * Generate the qotd
+	 */
+	public void generateQotd() {
+		QotdTask task = new QotdTask();
+		task.execute(new String[]{});
+	}
+	
+	/**
+	 * Task for accuiring a qotd from one of four possible servers
+	 * @author Wulf Pfeiffer
+	 */
+	private class QotdTask extends AsyncTask<String, Void, String>{	
+		 @Override
+		 protected String doInBackground(String... unused) {
+			 String[] sources = new String[]{"djxmmx.net", "ota.iambic.com", "alpha.mike-r.com", "electricbiscuit.org"};
+			 SecureRandom rndm = new SecureRandom();
+			 StringBuffer sb = new StringBuffer();
+			 try {
+				 Socket client = new Socket(sources[rndm.nextInt(4)], 17);
+				 BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));		
+				 while(!in.ready());
+				 while(in.ready()) {
+					 sb.append(in.readLine());
+				 }
+				 in.close();
+				 client.close();
+			 } catch (Exception e) {
+				 e.printStackTrace();
+			 }
+			 System.out.println(sb.length());
+			 return sb.toString();
+		 }
+			 
+		 @Override
+		 protected void onPostExecute(String result){
+			 if (result != null)
+				 HelperUtils.setQotd(result);
+			 else
+				 HelperUtils.setQotd(null);	
+		 }
+	};
 }

+ 41 - 0
src/de/tudarmstadt/informatik/hostage/commons/HelperUtils.java

@@ -1,11 +1,18 @@
 package de.tudarmstadt.informatik.hostage.commons;
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import java.net.InetAddress;
+import java.net.Socket;
 import java.net.UnknownHostException;
 import java.security.KeyStore;
+import java.security.SecureRandom;
 
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.scheme.PlainSocketFactory;
@@ -19,17 +26,23 @@ import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
+import org.json.JSONObject;
 
+import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.net.MySSLSocketFactory;
+import de.tudarmstadt.informatik.hostage.ui.MainActivity;
 import android.content.Context;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
+import android.os.AsyncTask;
 import android.os.Environment;
 import android.preference.PreferenceManager;
 import android.text.TextUtils;
+import android.widget.TextView;
 
 /**
  * Helper class with some static methods for general usage.
@@ -268,4 +281,32 @@ public final class HelperUtils {
 	    }
 	    return bytes;
 	}
+	
+	private static String qotd;
+	
+	/**
+	 * qotd getter.
+	 * @return qotd
+	 */
+	public static String getQotd() {
+		return qotd;
+	}
+	
+	/**
+	 * qotd setter.
+	 * If qotd is null (this means something went wrong with getting a qotd from server),
+	 * a random string is generated instead.
+	 * @param newQotd
+	 */
+	public static void setQotd(String newQotd) {
+		qotd = newQotd;
+		if(newQotd == null) {
+			SecureRandom rndm = new SecureRandom();
+			char[] c = new char[rndm.nextInt(100)];
+			for(int i = 0; i < c.length; i++) {
+				c[i] = (char) (rndm.nextInt(95)+32);
+			}
+			qotd = new String(c);
+		}
+	}
 }

+ 5 - 21
src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java

@@ -8,6 +8,8 @@ import java.util.List;
 import java.util.Locale;
 import java.util.TimeZone;
 
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+
 /**
  * HTTP protocol
  * @author Wulf Pfeiffer
@@ -101,26 +103,6 @@ public class HTTP implements Protocol<String> {
 	    return dateFormat.format(calendar.getTime());
 	}
 	
-	private String getQuote() {
-//		String[] sources = new String[]{"djxmmx.net", "ota.iambic.com", "alpha.mike-r.com", "electricbiscuit.org"};
-//		SecureRandom rndm = new SecureRandom();
-//		StringBuffer sb = new StringBuffer();
-//		try {
-//			Socket client = new Socket(sources[rndm.nextInt(4)], 17);
-//			BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));		
-//			while(!in.ready());
-//			while(in.ready()) {
-//				sb.append(in.readLine());
-//			}
-//			in.close();
-//			client.close();
-//		} catch (Exception e) {
-//			e.printStackTrace();
-//		}
-//		return sb.toString();
-		return "";
-	}
-	
 	private String[][][] possibleVersions = {
 			{{"Apache/2.0."},{"28","32","35","36","39","40","42","43","44","45","46","47","48","49","50","51","52","53","54","55","58","59","61","63","64","65"}},
 			{{"Apache/2.2."},{"0","2","3","4","6","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"}},
@@ -130,6 +112,7 @@ public class HTTP implements Protocol<String> {
 	private SecureRandom rndm = new SecureRandom();
 	private int majorVersion = rndm.nextInt(3);
 	private final String serverVersion = possibleVersions[majorVersion][0][0] + possibleVersions[majorVersion][1][rndm.nextInt(possibleVersions[majorVersion][1].length)];
+	private final String qotd = HelperUtils.getQotd();
 	//html header pre and suffix
 	private final String headerPrefix =				
 			"Date: " + getServerTime() + "\r\n" +
@@ -148,7 +131,8 @@ public class HTTP implements Protocol<String> {
 			"<html lang=\"en\">\n" +
 			"<head>\n" +
 			"<meta charset=\"UTF-8\">\n" +
-			"<title>" + getQuote() + "</title>\n" +
+			"<title>" + qotd + "</title>\n" +
+			"<body>" + qotd + "</body>\n" +
 			"</head>\n" +
 			"</html>";
 	//html error pre and suffix

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

@@ -100,7 +100,7 @@ public class MySQL implements Protocol<ByteArray>{
 	private byte[] greeting() {
 		SecureRandom rndm = new SecureRandom();
 		byte[] protocol = {0x0a};
-		String version = "5." + (rndm.nextInt(1)+5) + "." + (rndm.nextInt(13)+1);	//Randomize Version: 5.(5-6).(2-14)
+		String version = "5." + (rndm.nextInt(1)+5) + "." + (rndm.nextInt(13)+1);	//Randomize Version: 5.(5-6).(2-14) //TODO
 		byte[] versionFin = {0x00};
 		byte[] thread = {0x2a, 0x00, 0x00, 0x00};
 		byte[] salt = {0x44, 0x64, 0x49, 0x7e, 0x60, 0x48, 0x25, 0x7e, 0x00};

+ 3 - 2
src/de/tudarmstadt/informatik/hostage/protocol/SMB.java

@@ -179,8 +179,9 @@ public class SMB implements Protocol<ByteArray> {
 													{"Windows 8 Enterprise 9200", "Windows 8 Enterprise 9200"},
 													{"Windows Server 2012 Standard 6.2", "Windows Server 2012 Standard 6.2"},
 //													{"Unix", "Samba"}
+													//TODO
 		};
-		private byte[] serverName 				= fillWithZero("lalalalalala".getBytes());
+		private byte[] serverName 				= fillWithZero("lalalalalala".getBytes()); //TODO
 		private final String[] serverVersion	= possibleVersions[rndm.nextInt(possibleVersions.length)];
 		private byte[] message					= null; 
 		private final byte[] serverGUID			= randomBytes(16);
@@ -416,7 +417,7 @@ public class SMB implements Protocol<ByteArray> {
 			byte[] wordCount	= {0x00};
 			byte[] andXCommand	= {0x00, 0x00};
 			byte[] response 	= null;
-			
+			//TODO
 			if(str.contains("IPC$") || str.contains("DOCS")) {
 				wordCount			= new byte[] {0x07};
 				andXCommand			= new byte[] {(byte) 0xff};

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

@@ -30,7 +30,7 @@ public class TELNET implements Protocol<ByteArray> {
 	/** last command sent by the client */
 	private byte[] command;
 	/** name of the server */
-	private String server = "raspberrypi";
+	private String server = "raspberrypi"; //TODO
 	/** command line prefix */
 	private byte[] sessionToken = null;
 
@@ -62,7 +62,7 @@ public class TELNET implements Protocol<ByteArray> {
 		case OPEN:
 			if(request != null) {
 				response.add(new ByteArray(getOptionResponse(request)));
-				response.add(new ByteArray("Debian GNU/Linux 7.0\r\n"));
+				response.add(new ByteArray("Debian GNU/Linux 7.0\r\n")); //TODO
 				response.add(new ByteArray(server + " login: "));
 				state = STATE.LOGIN;
 			}
@@ -98,7 +98,7 @@ public class TELNET implements Protocol<ByteArray> {
 		case AUTHENTICATE:
 			if(request == null) break;
 			else if(checkForByte(request, (byte) 0x0d)) {
-				response.add(new ByteArray("\r\nLinux" + server + " 3.6.11+\r\n"));
+				response.add(new ByteArray("\r\nLinux" + server + " 3.6.11+\r\n")); //TODO
 				response.add(new ByteArray(sessionToken));
 				state = STATE.LOGGED_IN;
 			} else if (checkForByte(request, (byte) 0x7f)) {
@@ -208,7 +208,7 @@ public class TELNET implements Protocol<ByteArray> {
 	/** options requested by the server */
 	private final byte[] optionRequest = {(byte) 0xff, (byte) 0xfb, 0x03,	//will suppress go ahead
 										(byte) 0xff, (byte) 0xfb, 0x01};	//will echo
-	//session token prefix, mid and suffix
+	//session token prefix, mid and suffix //TODO
 	private final byte[] sessionPrefix = {0x1b, 0x5d, 0x30, 0x3b};
 	private final byte[] sessionMiddle = {0x40, 0x72, 0x61, 0x73, 
 			0x70, 0x62, 0x65, 0x72, 0x72, 0x79, 0x70, 0x69, 0x3a, 0x20, 0x7e, 0x07, 0x1b, 0x5b, 0x30, 0x31,