|
@@ -1,5 +1,8 @@
|
|
|
package de.tudarmstadt.informatik.hostage.protocol;
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.net.Socket;
|
|
|
import java.security.SecureRandom;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
@@ -8,6 +11,11 @@ import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.TimeZone;
|
|
|
|
|
|
+import android.content.Context;
|
|
|
+import android.os.AsyncTask;
|
|
|
+
|
|
|
+import de.tudarmstadt.informatik.hostage.HoneyService;
|
|
|
+import de.tudarmstadt.informatik.hostage.R;
|
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
|
|
|
@@ -19,6 +27,53 @@ import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
|
* @author Wulf Pfeiffer
|
|
|
*/
|
|
|
public class HTTP implements Protocol {
|
|
|
+
|
|
|
+ public HTTP() {
|
|
|
+ htmlDocumentContent = HelperUtils.getRandomString(32, false);
|
|
|
+ Context context = HoneyService.getContext();
|
|
|
+ String sharedPreferencePath = context.getString(R.string.shared_preference_path);
|
|
|
+ boolean useQotd = context.getSharedPreferences(sharedPreferencePath,
|
|
|
+ HoneyService.MODE_PRIVATE).getBoolean("useQotd", true);
|
|
|
+ if (useQotd) {
|
|
|
+ new QotdTask().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();
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPostExecute(String result) {
|
|
|
+ if (result != null)
|
|
|
+ HTTP.setHtmlDocumentContent(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Get the current time in html header format.
|
|
@@ -65,8 +120,7 @@ public class HTTP implements Protocol {
|
|
|
|
|
|
private String httpVersion = "HTTP/1.1";
|
|
|
|
|
|
- private static String htmlDocumentContent = HelperUtils.getRandomString(32,
|
|
|
- false);
|
|
|
+ private static String htmlDocumentContent;
|
|
|
|
|
|
// request codes
|
|
|
private static final String OPTIONS = "OPTIONS";
|