فهرست منبع

Modbus Request Packet Processing and Request Analysis in Thesis Report Added

shreyas.srinivasa 10 سال پیش
والد
کامیت
198d23c565

+ 4 - 3
assets/payload/redirect-ports.sh

@@ -5,13 +5,14 @@
 
 #             ECHO  FTP   HTTP  HTTPS SMB (NETBIOS UDP & TCP) SSH   TELNET MODBUS
 protocol=(    "tcp" "tcp" "tcp" "tcp" "udp" "udp"  "tcp" "tcp" "tcp" "tcp" "tcp")
-origin=(       7     21    80    443   137   138    139   22    23    445   28639)
-destination=( 28144 28169 28217 28580 28274 28275 28276 28159 28160 28582) # simply offset by 1024 + 27113
+origin=(       7     21    80    443   137   138    139   22    23    445   502)
+destination=( 28144 28169 28217 28580 28274 28275 28276 28159 28160 28582 28639) # simply offset by 1024 + 27113
 length=${#protocol[@]} # count protocol elements
 
 # for (( i=0; i<$length; i++ ))
 #for i in `seq 0 9` # fix for android's annoyingly limited bash
-for i in 0 1 2 3 4 5 6 7 8 9 # another fix for devices missing the seq command
+
+for i in 0 1 2 3 4 5 6 7 8 9 10 # another fix for devices missing the seq command
 
 do
 	# echo ${protocol[$i]} ${origin[$i]} ${destination[$i]} # debug

+ 47 - 7
src/de/tudarmstadt/informatik/hostage/protocol/MODBUS.java

@@ -1,12 +1,14 @@
 package de.tudarmstadt.informatik.hostage.protocol;
 
+import android.util.Log;
+
 import java.util.ArrayList;
 import java.util.List;
 
 import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
 /**
- * Created by root on 25.05.15.
+ * Created by Shreyas Srinivasa on 25.05.15.
  */
 public class MODBUS implements Protocol {
 
@@ -23,11 +25,6 @@ public class MODBUS implements Protocol {
         return false;
     }
 
-    public List<Packet> processMessage(Packet requestPacket) {
-        List<Packet> responsePackets = new ArrayList<Packet>();
-        responsePackets.add(requestPacket);
-        return responsePackets;
-    }
 
     @Override
     public String toString() {
@@ -35,10 +32,53 @@ public class MODBUS implements Protocol {
     }
 
     public TALK_FIRST whoTalksFirst() {
-        return null;
+        return TALK_FIRST.CLIENT;
+    }
+
+    //Request Codes (keeping the most essential ones)
+
+    public static final int READ_COILS = 1;
+    public static final int READ_INPUT_DISCRETES = 2;
+    public static final int READ_INPUT_REGISTERS = 4;
+    public static final int WRITE_COIL = 5;
+    public static final int WRITE_SINGLE_REGISTER = 6;
+    public static final int WRITE_MULTIPLE_COILS = 15;
+    public static final int WRITE_MULTIPLE_REGISTERS = 16;
+    public static final int MODBUS_SERVICE = 17;
+
+
+    //Reply codes
+
+
+    //Device Information
+
+    private String DeviceInfo = getDeviceInfo();
+
+    private String getDeviceInfo() {
+
+        DeviceInfo = "Siemens SIMATIC S7-200";
+        return DeviceInfo;
     }
 
 
+    @Override
+    public List<Packet> processMessage(Packet requestPacket) {
+        List<Packet> responsePackets = new ArrayList<Packet>();
+        byte[] request = null;
+        if (requestPacket != null) {
+            request = requestPacket.getBytes();
+            for (byte b : request) {
+                System.out.println(b);
+
+
+            }
 
 
+        }
+
+
+        return responsePackets;
+    }
+
 }
+

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

@@ -41,11 +41,11 @@ public interface Protocol {
 	/**
 	 * Determines the next response.
 	 * 
-	 * @param message
+	 * @param requestPacket
 	 *            Last message received from the client.
 	 * @return Message to be sent to the client.
 	 */
-	List<Packet> processMessage(Packet message);
+	List<Packet> processMessage(Packet requestPacket);
 
 	/**
 	 * Returns the name of the protocol.

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

@@ -9,12 +9,7 @@ import android.preference.PreferenceManager;
 
 import org.alfresco.jlan.app.XMLServerConfiguration;
 import org.alfresco.jlan.netbios.server.NetBIOSNameServer;
-import org.alfresco.jlan.server.SessionListener;
-import org.alfresco.jlan.server.SrvSession;
 import org.alfresco.jlan.server.config.InvalidConfigurationException;
-import org.alfresco.jlan.server.filesys.FileListener;
-import org.alfresco.jlan.server.filesys.NetworkFile;
-import org.alfresco.jlan.smb.server.CIFSConfigSection;
 import org.alfresco.jlan.smb.server.SMBServer;
 
 import java.io.IOException;
@@ -186,7 +181,7 @@ public class SMB implements Protocol {
     }
 
     @Override
-    public List<Packet> processMessage(Packet message) {
+    public List<Packet> processMessage(Packet requestPacket) {
         return null;
     }
 

+ 2 - 1
src/de/tudarmstadt/informatik/hostage/wrapper/Packet.java

@@ -59,7 +59,8 @@ public class Packet {
 		if (protocol.equals("FTP") 
 				|| protocol.equals("HTTP") 
 				|| protocol.equals("HTTPS")
-				|| protocol.equals("SIP")) {
+				|| protocol.equals("SIP")
+				|| protocol.equals("MODBUS")) {
 			return new String(payload);
 		} else {
 			return HelperUtils.bytesToHexString(payload);

BIN
thesis_report/Progress_Report.odt