Browse Source

-Improvied SIP
-Minor fixes

Wulf Pfeiffer 10 years ago
parent
commit
a36267f18c

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

@@ -70,7 +70,6 @@ public class HTTP implements Protocol {
 				.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")) {

+ 17 - 16
src/de/tudarmstadt/informatik/hostage/protocol/SIP.java

@@ -7,7 +7,7 @@ import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
 /**
  * SIP protocol. Implementation of RFC document 3261 It can handle the
- * following requests: INVITE, BYE. For all other requests
+ * following requests: INVITE, ACK, BYE. For all other requests
  * '400 Bad Request' will be replied.
  * @author Wulf Pfeiffer
  */
@@ -23,7 +23,6 @@ public class SIP implements Protocol {
 	private static final String INVITE = "INVITE";
 	private static final String ACK= "ACK";
 	private static final String BYE = "BYE";
-	private static final String STATUS_CODE_180 = "180 Ringing";
 	private static final String STATUS_CODE_200 = "200 OK";
 	private static final String STATUS_CODE_400 = "400 Bad Request";
 	private static final String STATUS_CODE_505 = "505 Version Not Supported";
@@ -57,16 +56,15 @@ public class SIP implements Protocol {
 		extractLines(lines);
 		
 		if(!lines[0].contains(VERSION)) {
-			responsePackets.add(new Packet(STATUS_CODE_505));
+			responsePackets.add(getVersionNotSupportedResponse());
 			return responsePackets;
 		} else if(lines[0].contains(INVITE)) {
-			responsePackets.add(getRingResponse());
 			responsePackets.add(getOkResponseWithSDP());
 		} else if(lines[0].contains(BYE)) {
 			responsePackets.add(getOkResponse());
 			state = STATE.CLOSED;
 		} else if(lines[0].contains(ACK)) {
-			//nothing here
+			//nothing to do here
 		} else {
 			responsePackets.add(getBadRequestResponse());
 		}
@@ -85,6 +83,8 @@ public class SIP implements Protocol {
 	}
 	
 	private void extractLines(String[] lines) {
+		header = "";
+		sdpPayload = "";
 		StringBuffer sbHeader = new StringBuffer();
 		StringBuffer sbSdp = new StringBuffer();
 		boolean recordHeader = false;
@@ -92,14 +92,15 @@ public class SIP implements Protocol {
 		for (String line : lines) {
 			if (line.startsWith("Via:")) {
 				recordHeader = true;
-			} else if (line.startsWith("Max-Forwards:")) {
+			} else if (line.startsWith("Max-Forwards")) {
 				recordHeader = false;
+				header = sbHeader.toString();
 			} else if(line.startsWith("v=")) {
 				recordSdp = true;
 			} else if(line.startsWith("a=")) {
 				sbSdp.append(line + "\r\n");
-				header = sbHeader.toString();
 				sdpPayload = sbSdp.toString();
+				break;
 			}
 			if(recordHeader) {
 				sbHeader.append(line + "\r\n");
@@ -109,15 +110,6 @@ public class SIP implements Protocol {
 		}
 	}
 	
-	private Packet getRingResponse() {
-		StringBuffer sb = new StringBuffer();
-		sb.append(VERSION + " " + STATUS_CODE_180 + "\r\n");
-		sb.append(header);
-		sb.append("Content-Length: 0\r\n");
-		
-		return new Packet(sb.toString());
-	}
-	
 	private Packet getOkResponseWithSDP() {
 		StringBuffer sb = new StringBuffer();
 		sb.append(VERSION + " " + STATUS_CODE_200 + "\r\n");
@@ -147,5 +139,14 @@ public class SIP implements Protocol {
 		
 		return new Packet(sb.toString());
 	}
+	
+	private Packet getVersionNotSupportedResponse() {
+		StringBuffer sb = new StringBuffer();
+		sb.append(VERSION + " " + STATUS_CODE_505 + "\r\n");
+		sb.append(header);
+		sb.append("Content-Length:   0\r\n");
+		
+		return new Packet(sb.toString());
+	}
 
 }

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

@@ -101,7 +101,6 @@ public class SMB implements Protocol {
 				.getContext()
 				.getSharedPreferences(sharedPreferencePath,
 						Context.MODE_PRIVATE).getString("os", "");
-		System.out.println(profile);
 		if (profile.equals("Windows 7")) {
 			return possibleSmbVersions[0];
 		} else if (profile.equals("Windows 8")) {

+ 0 - 3
src/de/tudarmstadt/informatik/hostage/protocol/SSH.java

@@ -584,13 +584,10 @@ public class SSH implements Protocol {
 	private Packet terminalReply(byte[] request) {
 		TypesReader tr = new TypesReader(request, 6);
 		String messsage = "";
-		System.out.println(HelperUtils.bytesToHexString(request));
 		try {
 			tr.readUINT32();
 			messsage = tr.readString();
-			System.out.println(messsage);
 			if (messsage.contains("\r")) {
-				System.out.println("hi");
 				if (command.toString().contains("exit")) {
 					state = STATE.CLOSED; // ugly style
 					return disconnectReply(2);