|
@@ -9,13 +9,13 @@ import java.util.List;
|
|
import java.util.TimeZone;
|
|
import java.util.TimeZone;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
-import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
|
|
|
|
|
|
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
|
|
|
|
/**
|
|
/**
|
|
* SMB protocol
|
|
* SMB protocol
|
|
* @author Wulf Pfeiffer
|
|
* @author Wulf Pfeiffer
|
|
*/
|
|
*/
|
|
-public class SMB implements Protocol<ByteArray> {
|
|
|
|
|
|
+public class SMB implements Protocol {
|
|
/**
|
|
/**
|
|
* Represents the states of the protocol
|
|
* Represents the states of the protocol
|
|
*/
|
|
*/
|
|
@@ -40,78 +40,78 @@ public class SMB implements Protocol<ByteArray> {
|
|
return TALK_FIRST.CLIENT;
|
|
return TALK_FIRST.CLIENT;
|
|
}
|
|
}
|
|
|
|
|
|
- private SMBPacket packet = new SMBPacket();
|
|
|
|
|
|
+ private SMBPacket smbPacket = new SMBPacket();
|
|
|
|
|
|
|
|
|
|
- public List<ByteArray> processMessage(ByteArray message) {
|
|
|
|
- if(message != null)
|
|
|
|
- lastMessage = message.get();
|
|
|
|
- packet.newMsg(lastMessage);
|
|
|
|
- byte smbCommand = packet.getSmbCommand();
|
|
|
|
- List<ByteArray> response = new ArrayList<ByteArray>();
|
|
|
|
|
|
+ public List<Packet> processMessage(Packet packet) {
|
|
|
|
+ if(packet != null)
|
|
|
|
+ lastMessage = packet.getMessage();
|
|
|
|
+ smbPacket.newMsg(lastMessage);
|
|
|
|
+ byte smbCommand = smbPacket.getSmbCommand();
|
|
|
|
+ List<Packet> response = new ArrayList<Packet>();
|
|
|
|
|
|
switch (state) {
|
|
switch (state) {
|
|
case NONE:
|
|
case NONE:
|
|
if (smbCommand == 0x72) {
|
|
if (smbCommand == 0x72) {
|
|
state = STATE.CONNECTED;
|
|
state = STATE.CONNECTED;
|
|
- response.add(new ByteArray(packet.getNego()));
|
|
|
|
|
|
+ response.add(smbPacket.getNego());
|
|
} else {
|
|
} else {
|
|
state = STATE.DISCONNECTED;
|
|
state = STATE.DISCONNECTED;
|
|
- response.add(new ByteArray(packet.getTreeDisc()));
|
|
|
|
|
|
+ response.add(smbPacket.getTreeDisc());
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case CONNECTED:
|
|
case CONNECTED:
|
|
if (smbCommand == 0x73) {
|
|
if (smbCommand == 0x73) {
|
|
- response.add(new ByteArray(packet.getSessSetup()));
|
|
|
|
|
|
+ response.add(smbPacket.getSessSetup());
|
|
} else if (smbCommand == 0x75) {
|
|
} else if (smbCommand == 0x75) {
|
|
state = STATE.AUTHENTICATED;
|
|
state = STATE.AUTHENTICATED;
|
|
- response.add(new ByteArray(packet.getTreeCon()));
|
|
|
|
|
|
+ response.add(smbPacket.getTreeCon());
|
|
} else {
|
|
} else {
|
|
state = STATE.DISCONNECTED;
|
|
state = STATE.DISCONNECTED;
|
|
- response.add(new ByteArray(packet.getTreeDisc()));
|
|
|
|
|
|
+ response.add(smbPacket.getTreeDisc());
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case AUTHENTICATED:
|
|
case AUTHENTICATED:
|
|
if (smbCommand == (byte) 0xa2) {
|
|
if (smbCommand == (byte) 0xa2) {
|
|
state = STATE.LISTING;
|
|
state = STATE.LISTING;
|
|
- response.add(new ByteArray(packet.getNTCreate()));
|
|
|
|
|
|
+ response.add(smbPacket.getNTCreate());
|
|
} else if (smbCommand == 0x2b) {
|
|
} else if (smbCommand == 0x2b) {
|
|
- response.add(new ByteArray(packet.getEcho()));
|
|
|
|
|
|
+ response.add(smbPacket.getEcho());
|
|
} else if (smbCommand == 0x32) {
|
|
} else if (smbCommand == 0x32) {
|
|
- response.add(new ByteArray(packet.getTrans2()));
|
|
|
|
|
|
+ response.add(smbPacket.getTrans2());
|
|
} else if (smbCommand == 0x04) {
|
|
} else if (smbCommand == 0x04) {
|
|
- response.add(new ByteArray(packet.getClose()));
|
|
|
|
|
|
+ response.add(smbPacket.getClose());
|
|
} else if (smbCommand == 0x71) {
|
|
} else if (smbCommand == 0x71) {
|
|
state = STATE.CLOSED;
|
|
state = STATE.CLOSED;
|
|
- response.add(new ByteArray(packet.getTreeDisc()));
|
|
|
|
|
|
+ response.add(smbPacket.getTreeDisc());
|
|
} else {
|
|
} else {
|
|
state = STATE.DISCONNECTED;
|
|
state = STATE.DISCONNECTED;
|
|
- response.add(new ByteArray(packet.getTreeDisc()));
|
|
|
|
|
|
+ response.add(smbPacket.getTreeDisc());
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case LISTING:
|
|
case LISTING:
|
|
if (smbCommand == 0x25) {
|
|
if (smbCommand == 0x25) {
|
|
- response.add(new ByteArray(packet.getTrans()));
|
|
|
|
|
|
+ response.add(smbPacket.getTrans());
|
|
} else if (smbCommand == 0x04) {
|
|
} else if (smbCommand == 0x04) {
|
|
- response.add(new ByteArray(packet.getClose()));
|
|
|
|
|
|
+ response.add(smbPacket.getClose());
|
|
} else if (smbCommand == 0x71) {
|
|
} else if (smbCommand == 0x71) {
|
|
state = STATE.CLOSED;
|
|
state = STATE.CLOSED;
|
|
- response.add(new ByteArray(packet.getTreeDisc()));
|
|
|
|
|
|
+ response.add(smbPacket.getTreeDisc());
|
|
} else if (smbCommand == 0x72) {
|
|
} else if (smbCommand == 0x72) {
|
|
state = STATE.CONNECTED;
|
|
state = STATE.CONNECTED;
|
|
- response.add(new ByteArray(packet.getNego()));
|
|
|
|
|
|
+ response.add(smbPacket.getNego());
|
|
} else {
|
|
} else {
|
|
state = STATE.DISCONNECTED;
|
|
state = STATE.DISCONNECTED;
|
|
- response.add(new ByteArray(packet.getTreeDisc()));
|
|
|
|
|
|
+ response.add(smbPacket.getTreeDisc());
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case DISCONNECTED:
|
|
case DISCONNECTED:
|
|
state = STATE.CLOSED;
|
|
state = STATE.CLOSED;
|
|
- response.add(new ByteArray(packet.getTreeDisc()));
|
|
|
|
|
|
+ response.add(smbPacket.getTreeDisc());
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
state = STATE.CLOSED;
|
|
state = STATE.CLOSED;
|
|
- response.add(new ByteArray(packet.getTreeDisc()));
|
|
|
|
|
|
+ response.add(smbPacket.getTreeDisc());
|
|
}
|
|
}
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -127,8 +127,8 @@ public class SMB implements Protocol<ByteArray> {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public Class<ByteArray> getType() {
|
|
|
|
- return ByteArray.class;
|
|
|
|
|
|
+ public Class<byte[]> getType() {
|
|
|
|
+ return byte[].class;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -274,7 +274,7 @@ public class SMB implements Protocol<ByteArray> {
|
|
* Builds the negotiate packet
|
|
* Builds the negotiate packet
|
|
* @return negotiate packet
|
|
* @return negotiate packet
|
|
*/
|
|
*/
|
|
- private byte[] getNego() {
|
|
|
|
|
|
+ private Packet getNego() {
|
|
byte[] wordCount = {0x11};
|
|
byte[] wordCount = {0x11};
|
|
byte[] dialect = evaluateDialect();
|
|
byte[] dialect = evaluateDialect();
|
|
byte[] secMode = {0x03};
|
|
byte[] secMode = {0x03};
|
|
@@ -299,7 +299,7 @@ public class SMB implements Protocol<ByteArray> {
|
|
byte[] response = HelperUtils.concat(wordCount, dialect, secMode, maxMpxC, maxVcs, maxBufSize, maxRawBuf,
|
|
byte[] response = HelperUtils.concat(wordCount, dialect, secMode, maxMpxC, maxVcs, maxBufSize, maxRawBuf,
|
|
sessionKey, capabilities, sysTime, timeZone, keyLength, byteCount, guid, secBlob, oid,
|
|
sessionKey, capabilities, sysTime, timeZone, keyLength, byteCount, guid, secBlob, oid,
|
|
protectNeg, negToken, mechType, mechType2);
|
|
protectNeg, negToken, mechType, mechType2);
|
|
- return wrapNetbios(wrapHeader(response));
|
|
|
|
|
|
+ return new Packet(wrapNetbios(wrapHeader(response)));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -328,11 +328,12 @@ public class SMB implements Protocol<ByteArray> {
|
|
* Builds the session setup packet
|
|
* Builds the session setup packet
|
|
* @return session setup packet
|
|
* @return session setup packet
|
|
*/
|
|
*/
|
|
- private byte[] getSessSetup() {
|
|
|
|
- if(authenticateNext) return getSetupAuth();
|
|
|
|
- else {
|
|
|
|
|
|
+ private Packet getSessSetup() {
|
|
|
|
+ if(authenticateNext) {
|
|
|
|
+ return new Packet(getSetupAuth());
|
|
|
|
+ } else {
|
|
authenticateNext = true;
|
|
authenticateNext = true;
|
|
- return getSetupChal();
|
|
|
|
|
|
+ return new Packet(getSetupChal());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -439,7 +440,7 @@ public class SMB implements Protocol<ByteArray> {
|
|
* Builds the tree connect packet
|
|
* Builds the tree connect packet
|
|
* @return tree connect packet
|
|
* @return tree connect packet
|
|
*/
|
|
*/
|
|
- private byte[] getTreeCon() {
|
|
|
|
|
|
+ private Packet getTreeCon() {
|
|
String str = toString();
|
|
String str = toString();
|
|
byte[] wordCount = {0x00};
|
|
byte[] wordCount = {0x00};
|
|
byte[] andXCommand = {0x00, 0x00};
|
|
byte[] andXCommand = {0x00, 0x00};
|
|
@@ -469,14 +470,14 @@ public class SMB implements Protocol<ByteArray> {
|
|
response = HelperUtils.concat(wordCount, andXCommand);
|
|
response = HelperUtils.concat(wordCount, andXCommand);
|
|
}
|
|
}
|
|
|
|
|
|
- return wrapNetbios(wrapHeader(response));
|
|
|
|
|
|
+ return new Packet(wrapNetbios(wrapHeader(response)));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Builds the nt create packet
|
|
* Builds the nt create packet
|
|
* @return nt create packet
|
|
* @return nt create packet
|
|
*/
|
|
*/
|
|
- private byte[] getNTCreate() {
|
|
|
|
|
|
+ private Packet getNTCreate() {
|
|
byte[] wordCount = {0x22};
|
|
byte[] wordCount = {0x22};
|
|
byte[] andXCommand = {(byte) 0xff};
|
|
byte[] andXCommand = {(byte) 0xff};
|
|
byte[] reserved = {0x00};
|
|
byte[] reserved = {0x00};
|
|
@@ -499,14 +500,14 @@ public class SMB implements Protocol<ByteArray> {
|
|
byte[] response = HelperUtils.concat(wordCount, andXCommand, reserved, andXOffset, oplockLevel, fid,
|
|
byte[] response = HelperUtils.concat(wordCount, andXCommand, reserved, andXOffset, oplockLevel, fid,
|
|
createAction, created, lastAccess, lastWrite, change, fileAttributes, allocationSize,
|
|
createAction, created, lastAccess, lastWrite, change, fileAttributes, allocationSize,
|
|
endOfFile, fileType, ipcState, isDirectory, byteCount);
|
|
endOfFile, fileType, ipcState, isDirectory, byteCount);
|
|
- return wrapNetbios(wrapHeader(response));
|
|
|
|
|
|
+ return new Packet(wrapNetbios(wrapHeader(response)));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Builds the trans packet
|
|
* Builds the trans packet
|
|
* @return trans packet
|
|
* @return trans packet
|
|
*/
|
|
*/
|
|
- private byte[] getTrans() {
|
|
|
|
|
|
+ private Packet getTrans() {
|
|
byte[] transSub = getTransSub();
|
|
byte[] transSub = getTransSub();
|
|
byte[] response = null;
|
|
byte[] response = null;
|
|
if(transSub[0] == 0x00 && transSub[1] == 0x0b) { //bind_ack
|
|
if(transSub[0] == 0x00 && transSub[1] == 0x0b) { //bind_ack
|
|
@@ -584,7 +585,7 @@ public class SMB implements Protocol<ByteArray> {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- return wrapNetbios(wrapHeader(response));
|
|
|
|
|
|
+ return new Packet(wrapNetbios(wrapHeader(response)));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -637,7 +638,7 @@ public class SMB implements Protocol<ByteArray> {
|
|
* Builds the close packet
|
|
* Builds the close packet
|
|
* @return close packet
|
|
* @return close packet
|
|
*/
|
|
*/
|
|
- private byte[] getClose() {
|
|
|
|
|
|
+ private Packet getClose() {
|
|
byte[] wordCount = {0x00};
|
|
byte[] wordCount = {0x00};
|
|
byte[] byteCount = {0x00, 0x00};
|
|
byte[] byteCount = {0x00, 0x00};
|
|
|
|
|
|
@@ -645,14 +646,14 @@ public class SMB implements Protocol<ByteArray> {
|
|
|
|
|
|
byte[] response = HelperUtils.concat(wordCount, byteCount);
|
|
byte[] response = HelperUtils.concat(wordCount, byteCount);
|
|
|
|
|
|
- return wrapNetbios(wrapHeader(response));
|
|
|
|
|
|
+ return new Packet(wrapNetbios(wrapHeader(response)));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Builds the tree disconnect packet
|
|
* Builds the tree disconnect packet
|
|
* @return tree disconnect packet
|
|
* @return tree disconnect packet
|
|
*/
|
|
*/
|
|
- private byte[] getTreeDisc() {
|
|
|
|
|
|
+ private Packet getTreeDisc() {
|
|
byte[] wordCount = {0x00};
|
|
byte[] wordCount = {0x00};
|
|
byte[] byteCount = {0x00, 0x00};
|
|
byte[] byteCount = {0x00, 0x00};
|
|
|
|
|
|
@@ -660,21 +661,21 @@ public class SMB implements Protocol<ByteArray> {
|
|
|
|
|
|
byte[] response = HelperUtils.concat(wordCount, byteCount);
|
|
byte[] response = HelperUtils.concat(wordCount, byteCount);
|
|
|
|
|
|
- return wrapNetbios(wrapHeader(response));
|
|
|
|
|
|
+ return new Packet(wrapNetbios(wrapHeader(response)));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Builds the echo packet
|
|
* Builds the echo packet
|
|
* @return echo packet
|
|
* @return echo packet
|
|
*/
|
|
*/
|
|
- private byte[] getEcho() {
|
|
|
|
|
|
+ private Packet getEcho() {
|
|
byte[] wordCount = {0x01};
|
|
byte[] wordCount = {0x01};
|
|
byte[] echoSeq = {0x01, 0x00};
|
|
byte[] echoSeq = {0x01, 0x00};
|
|
byte[] byteCount = {0x10, 0x00};
|
|
byte[] byteCount = {0x10, 0x00};
|
|
byte[] echoData = {(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0,
|
|
byte[] echoData = {(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0,
|
|
(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0};
|
|
(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0};
|
|
byte[] response = HelperUtils.concat(wordCount, echoSeq, byteCount, echoData);
|
|
byte[] response = HelperUtils.concat(wordCount, echoSeq, byteCount, echoData);
|
|
- return wrapNetbios(wrapHeader(response));
|
|
|
|
|
|
+ return new Packet(wrapNetbios(wrapHeader(response)));
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -682,13 +683,13 @@ public class SMB implements Protocol<ByteArray> {
|
|
* Builds the trans2 packet
|
|
* Builds the trans2 packet
|
|
* @return trans2 packet
|
|
* @return trans2 packet
|
|
*/
|
|
*/
|
|
- private byte[] getTrans2() {
|
|
|
|
|
|
+ private Packet getTrans2() {
|
|
byte[] response = null;
|
|
byte[] response = null;
|
|
byte[] wordCount = {0x00};
|
|
byte[] wordCount = {0x00};
|
|
byte[] andXCommand = {0x00, 0x00};
|
|
byte[] andXCommand = {0x00, 0x00};
|
|
ntStat = new byte[] {0x22, 0x00, 0x00, (byte) 0xc0};
|
|
ntStat = new byte[] {0x22, 0x00, 0x00, (byte) 0xc0};
|
|
response = HelperUtils.concat(wordCount, andXCommand);
|
|
response = HelperUtils.concat(wordCount, andXCommand);
|
|
- return wrapNetbios(wrapHeader(response));
|
|
|
|
|
|
+ return new Packet(wrapNetbios(wrapHeader(response)));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|