|
@@ -1,8 +1,5 @@
|
|
|
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;
|
|
@@ -12,8 +9,6 @@ import java.util.Locale;
|
|
|
import java.util.TimeZone;
|
|
|
|
|
|
import android.content.Context;
|
|
|
-import android.os.AsyncTask;
|
|
|
-
|
|
|
import de.tudarmstadt.informatik.hostage.Hostage;
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
@@ -27,60 +22,13 @@ import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
|
* @author Wulf Pfeiffer
|
|
|
*/
|
|
|
public class HTTP implements Protocol {
|
|
|
-
|
|
|
- public HTTP() {
|
|
|
- htmlDocumentContent = HelperUtils.getRandomString(32, false);
|
|
|
- Context context = Hostage.getContext();
|
|
|
- String sharedPreferencePath = context.getString(R.string.shared_preference_path);
|
|
|
- boolean useQotd = context.getSharedPreferences(sharedPreferencePath,
|
|
|
- Hostage.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.
|
|
|
*
|
|
|
* @return the formatted server time.
|
|
|
*/
|
|
|
- private static String getServerTime() {
|
|
|
+ private String getServerTime() {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat(
|
|
|
"EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
|
|
@@ -92,7 +40,7 @@ public class HTTP implements Protocol {
|
|
|
private String request = "";
|
|
|
|
|
|
// version stuff
|
|
|
- private static String[][][] possibleHttpVersions = {
|
|
|
+ private String[][][] possibleHttpVersions = {
|
|
|
{
|
|
|
{ "Apache/2.0." },
|
|
|
{ "28", "32", "35", "36", "39", "40", "42", "43", "44",
|
|
@@ -106,21 +54,41 @@ public class HTTP implements Protocol {
|
|
|
"21", "22", "23", "24", "25" } },
|
|
|
{ { "Apache/2.3." },
|
|
|
{ "4", "5", "6", "8", "10", "11", "12", "14", "15", "16" } },
|
|
|
- { { "Apache/2.4." }, { "1", "2", "3", "4", "6" } } };
|
|
|
+ { { "Apache/2.4." }, { "1", "2", "3", "4", "6" } },
|
|
|
+ { { "Microsoft-IIS/" }, { "5.1", "7.0", "8.0" } } };
|
|
|
|
|
|
- private static String serverVersion = initServerVersion();
|
|
|
+ private String serverVersion = initServerVersion();
|
|
|
|
|
|
- private static String initServerVersion() {
|
|
|
+ private String initServerVersion() {
|
|
|
SecureRandom rndm = new SecureRandom();
|
|
|
int majorVersion = rndm.nextInt(possibleHttpVersions.length);
|
|
|
- return possibleHttpVersions[majorVersion][0][0]
|
|
|
- + possibleHttpVersions[majorVersion][1][rndm
|
|
|
- .nextInt(possibleHttpVersions[majorVersion][1].length)];
|
|
|
+
|
|
|
+ String version;
|
|
|
+ String sharedPreferencePath = Hostage.getContext().getString(
|
|
|
+ R.string.shared_preference_path);
|
|
|
+ String profile = Hostage
|
|
|
+ .getContext()
|
|
|
+ .getSharedPreferences(sharedPreferencePath,
|
|
|
+ Context.MODE_PRIVATE).getString("os", "");
|
|
|
+ System.out.println(profile);
|
|
|
+ if (profile.equals("Windows 7") || profile.equals("Windows Server 2008")) {
|
|
|
+ version = "Microsoft-IIS/7.5";
|
|
|
+ } else if (profile.equals("Windows Server 2012") || profile.equals("Windows 8")) {
|
|
|
+ version = "Microsoft-IIS/8.0";
|
|
|
+ } else if (profile.equals("Windows XP")) {
|
|
|
+ version = "Microsoft-IIS/5.1";
|
|
|
+ } else {
|
|
|
+ version = possibleHttpVersions[majorVersion][0][0]
|
|
|
+ + possibleHttpVersions[majorVersion][1][rndm
|
|
|
+ .nextInt(possibleHttpVersions[majorVersion][1].length)];
|
|
|
+ }
|
|
|
+
|
|
|
+ return version;
|
|
|
}
|
|
|
|
|
|
private String httpVersion = "HTTP/1.1";
|
|
|
|
|
|
- private static String htmlDocumentContent;
|
|
|
+ private static String htmlDocumentContent = HelperUtils.getRandomString(32, false);
|
|
|
|
|
|
// request codes
|
|
|
private static final String OPTIONS = "OPTIONS";
|