|
@@ -4,6 +4,9 @@ import java.security.SecureRandom;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import android.content.SharedPreferences;
|
|
|
+import android.preference.PreferenceManager;
|
|
|
+
|
|
|
import de.tudarmstadt.informatik.hostage.Hostage;
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
@@ -98,6 +101,15 @@ public class SMB implements Protocol {
|
|
|
.getRandomString(16, true).getBytes());
|
|
|
private static String workgroup;
|
|
|
private SMBPacket smbPacket = new SMBPacket(serverVersion, new String(serverName), workgroup);
|
|
|
+ private int maxEchoPackets = initMaxPackets();
|
|
|
+ private int receivedEchoPackets = 0;
|
|
|
+
|
|
|
+ private int initMaxPackets() {
|
|
|
+ int maxPackets;
|
|
|
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Hostage.getContext());
|
|
|
+ maxPackets = prefs.getInt("timeout", 30) / 5;
|
|
|
+ return maxPackets;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public int getPort() {
|
|
@@ -123,6 +135,19 @@ public class SMB implements Protocol {
|
|
|
byte[] response;
|
|
|
List<Packet> responsePackets = new ArrayList<Packet>();
|
|
|
|
|
|
+ if (smbCommand == SMB_COM_ECHO) {
|
|
|
+ receivedEchoPackets++;
|
|
|
+ } else {
|
|
|
+ receivedEchoPackets = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (receivedEchoPackets == maxEchoPackets) {
|
|
|
+ state = STATE.CLOSED;
|
|
|
+ response = smbPacket.getTreeDisc();
|
|
|
+ responsePackets.add(new Packet(response, toString()));
|
|
|
+ return responsePackets;
|
|
|
+ }
|
|
|
+
|
|
|
switch (state) {
|
|
|
case NONE:
|
|
|
if (smbCommand == SMB_COM_NEGOTIATE) {
|