SMB.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. package de.tudarmstadt.informatik.hostage.protocol;
  2. import java.nio.ByteBuffer;
  3. import java.util.ArrayList;
  4. import java.util.Calendar;
  5. import java.util.List;
  6. import java.util.Random;
  7. import java.util.TimeZone;
  8. import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
  9. public final class SMB implements Protocol<ByteArray> {
  10. private static enum STATE {
  11. NONE, CONNECTED, AUTHENTICATED, LISTING, DISCONNECTED, CLOSED
  12. }
  13. private STATE state = STATE.NONE;
  14. @Override
  15. public int getPort() {
  16. return 445;
  17. }
  18. @Override
  19. public TALK_FIRST whoTalksFirst() {
  20. return TALK_FIRST.CLIENT;
  21. }
  22. private SmbPacket packet = new SmbPacket();
  23. @Override
  24. public List<ByteArray> processMessage(ByteArray message) {
  25. byte[] primitiveByteArray = message.get();
  26. packet.newMsg(primitiveByteArray);
  27. byte smbCommand = packet.getSmbCommand();
  28. List<ByteArray> response = new ArrayList<ByteArray>();
  29. switch (state) {
  30. case NONE:
  31. if (smbCommand == 0x72) {
  32. state = STATE.CONNECTED;
  33. response.add(new ByteArray(packet.getNego()));
  34. } else {
  35. state = STATE.DISCONNECTED;
  36. response.add(new ByteArray(packet.getTreeDisc()));
  37. }
  38. break;
  39. case CONNECTED:
  40. if (smbCommand == 0x73) {
  41. response.add(new ByteArray(packet.getSessSetup()));
  42. } else if (smbCommand == 0x75) {
  43. state = STATE.AUTHENTICATED;
  44. response.add(new ByteArray(packet.getTreeCon()));
  45. } else {
  46. state = STATE.DISCONNECTED;
  47. response.add(new ByteArray(packet.getTreeDisc()));
  48. }
  49. break;
  50. case AUTHENTICATED:
  51. if (smbCommand == (byte) 0xa2) {
  52. state = STATE.LISTING;
  53. response.add(new ByteArray(packet.getNTCreate()));
  54. } else if (smbCommand == 0x2b) {
  55. response.add(new ByteArray(packet.getEcho()));
  56. } else if (smbCommand == 0x32) {
  57. response.add(new ByteArray(packet.getTrans2()));
  58. } else if (smbCommand == 0x04) {
  59. response.add(new ByteArray(packet.getClose()));
  60. } else if (smbCommand == 0x71) {
  61. state = STATE.CLOSED;
  62. response.add(new ByteArray(packet.getTreeDisc()));
  63. } else {
  64. state = STATE.DISCONNECTED;
  65. response.add(new ByteArray(packet.getTreeDisc()));
  66. }
  67. break;
  68. case LISTING:
  69. if (smbCommand == 0x25) {
  70. response.add(new ByteArray(packet.getTrans()));
  71. } else if (smbCommand == 0x04) {
  72. response.add(new ByteArray(packet.getClose()));
  73. } else if (smbCommand == 0x71) {
  74. state = STATE.CLOSED;
  75. response.add(new ByteArray(packet.getTreeDisc()));
  76. } else if (smbCommand == 0x72) {
  77. state = STATE.CONNECTED;
  78. response.add(new ByteArray(packet.getNego()));
  79. } else {
  80. state = STATE.DISCONNECTED;
  81. response.add(new ByteArray(packet.getTreeDisc()));
  82. }
  83. break;
  84. case DISCONNECTED:
  85. state = STATE.CLOSED;
  86. response.add(new ByteArray(packet.getTreeDisc()));
  87. break;
  88. default:
  89. state = STATE.CLOSED;
  90. response.add(new ByteArray(packet.getTreeDisc()));
  91. }
  92. return response;
  93. }
  94. @Override
  95. public boolean isClosed() {
  96. return (state == STATE.CLOSED);
  97. }
  98. @Override
  99. public boolean isSecure() {
  100. return false;
  101. }
  102. @Override
  103. public Class<ByteArray> getType() {
  104. return ByteArray.class;
  105. }
  106. @Override
  107. public String toString() {
  108. return "SMB";
  109. }
  110. public byte[] concat(byte[]... bytes) {
  111. int newSize = 0;
  112. for (byte[] b : bytes)
  113. newSize += b.length;
  114. byte[] dst = new byte[newSize];
  115. int currentPos = 0;
  116. int newPos;
  117. for (byte[] b : bytes) {
  118. newPos = b.length;
  119. System.arraycopy(b, 0, dst, currentPos, newPos);
  120. currentPos += newPos;
  121. }
  122. return dst;
  123. }
  124. public byte[] getTimeInBytes() {
  125. long time = System.currentTimeMillis();
  126. Calendar calend = Calendar.getInstance();
  127. calend.setTimeZone(TimeZone.getTimeZone("UTC"));
  128. calend.set(1601, 0, 01, 00, 00, 00);
  129. time -= calend.getTimeInMillis();
  130. time *= 10000;
  131. byte[] b = new byte[8];
  132. byte[] b2 = ByteBuffer.allocate(8).putLong(time).array();
  133. for (int i = 0, j = 7; i < 8 && j > -1; i++, j--) {
  134. b[i] = (byte) (b2[j] & 0xff);
  135. }
  136. return b;
  137. }
  138. public byte[] randomBytes(int size) {
  139. byte[] bytes = new byte[size];
  140. Random rdm = new Random();
  141. rdm.nextBytes(bytes);
  142. return bytes;
  143. }
  144. public String byteToStr(byte[] bytes) {
  145. return charToString(byteToChar(bytes));
  146. }
  147. public String charToString(char[] chars) {
  148. char[] newChars = new char[chars.length];
  149. for (int i = 0, j = 0; i < chars.length && j < newChars.length; i++) {
  150. if (isLetter(chars[i])) {
  151. newChars[j] = chars[i];
  152. j++;
  153. }
  154. }
  155. return new String(newChars);
  156. }
  157. public byte[] charToByte(char[] chars) {
  158. byte[] bytes = new byte[chars.length];
  159. for (int i = 0; i < chars.length; i++)
  160. bytes[i] = (byte) chars[i];
  161. return bytes;
  162. }
  163. public char[] byteToChar(byte[] bytes) {
  164. char[] chars = new char[bytes.length];
  165. for (int i = 0; i < bytes.length; i++)
  166. chars[i] = (char) bytes[i];
  167. return chars;
  168. }
  169. private boolean isLetter(char c) {
  170. return (c >= 32 && c <= 127);
  171. }
  172. private class SmbPacket {
  173. private byte[] msg = null;
  174. private final byte[] serverGUID = randomBytes(16);
  175. private boolean authenticateNext = false;
  176. private byte[] serverComp = new byte[4];
  177. private byte[] smbCommand = new byte[1];
  178. private byte[] ntStat = new byte[4];
  179. private byte[] smbFlags = new byte[1];
  180. private byte[] smbFlags2 = new byte[2];
  181. private byte[] processIDHigh = new byte[2];
  182. private byte[] signature = new byte[8];
  183. private byte[] reserved = new byte[2];
  184. private byte[] treeID = new byte[2];
  185. private byte[] processID = new byte[2];
  186. private byte[] userID = new byte[2];
  187. private byte[] multiplexID = new byte[2];
  188. public SmbPacket() {
  189. }
  190. public void newMsg(byte[] msg) {
  191. this.msg = msg;
  192. serverComp = new byte[]{msg[4], msg[5], msg[6], msg[7]};
  193. smbCommand = new byte[]{msg[8]};
  194. ntStat = new byte[]{msg[9], msg[10], msg[11], msg[12]};
  195. smbFlags = new byte[]{(byte) (msg[13] | 0x80)}; // | 0x80 for mark response bit
  196. smbFlags2 = new byte[]{msg[14], msg[15]};
  197. processIDHigh = new byte[]{msg[16], msg[17]};
  198. signature = new byte[]{msg[18], msg[19], msg[20], msg[21], msg[22], msg[23], msg[24], msg[25]};
  199. reserved = new byte[]{msg[26], msg[27]};
  200. treeID = new byte[]{msg[28], msg[29]};
  201. processID = new byte[]{msg[30], msg[31]};
  202. userID = new byte[]{msg[32], msg[33]};
  203. multiplexID = new byte[]{msg[34], msg[35]};
  204. }
  205. private byte[] getNetbios(byte[] response) {
  206. byte[] netbios = {0x00};
  207. byte[] buf = ByteBuffer.allocate(4).putInt(response.length).array(); // allocate(4) because int is 4 bytes long
  208. byte[] netbiosLength = {buf[1], buf[2], buf[3]}; // only bytes 1-3 needed, byte 0 is not needed
  209. return concat(netbios, netbiosLength);
  210. }
  211. private byte[] getHeader() {
  212. byte[] header = new byte[0];
  213. return concat(header, serverComp, smbCommand, ntStat, smbFlags, smbFlags2, processIDHigh, signature,
  214. reserved, treeID, processID, userID, multiplexID);
  215. }
  216. public byte[] getNego() {
  217. byte[] wordCount = {0x11};
  218. byte[] dialect = evaluateDialect();
  219. byte[] secMode = {0x03};
  220. byte[] maxMpxC = {0x32, 0x00};
  221. byte[] maxVcs = {0x01, 0x00};
  222. byte[] maxBufSize = {0x04, 0x11, 0x00, 0x00};
  223. byte[] maxRawBuf = {0x00, 0x00, 0x01, 0x00};
  224. byte[] sessionKey = {0x00, 0x00, 0x00, 0x00};
  225. byte[] capabilities = {(byte) 0xfc, (byte) 0xe3, 0x01, (byte) 0x80};
  226. byte[] sysTime = getTimeInBytes();
  227. byte[] timeZone = {(byte) 0x88, (byte) 0xff}; //FIXME correct time zone
  228. byte[] keyLength = {0x00};
  229. byte[] byteCount = {0x3a, 0x00};
  230. byte[] guid = serverGUID;
  231. byte[] secBlob = {0x60, 0x28, 0x06, 0x06};
  232. byte[] oid = {0x2b, 0x06, 0x01, 0x05, 0x05, 0x02};
  233. byte[] protectNeg = {(byte) 0xa0, 0x1e};
  234. byte[] negToken = {0x30, 0x1c, (byte) 0xa0, 0x1a, 0x30, 0x18};
  235. byte[] mechType = {0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, (byte) 0x82, 0x37, 0x02, 0x02, 0x1e};
  236. byte[] mechType2 = {0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, (byte) 0x82, 0x37, 0x02, 0x02, 0x0a};
  237. byte[] response = concat(getHeader(), wordCount, dialect, secMode, maxMpxC, maxVcs, maxBufSize, maxRawBuf,
  238. sessionKey, capabilities, sysTime, timeZone, keyLength, byteCount, guid, secBlob, oid,
  239. protectNeg, negToken, mechType, mechType2);
  240. return concat(getNetbios(response), response);
  241. }
  242. private byte[] evaluateDialect() {
  243. byte[] dialectMsg = new byte[msg.length-39];
  244. System.arraycopy(msg, 39, dialectMsg, 0, msg.length - 39);
  245. short dialectNumber = 0;
  246. for(int i = 0, start = 0; i < dialectMsg.length; i++) {
  247. if(dialectMsg[i] == 0x00) {
  248. byte[] dialect = new byte[i-start];
  249. System.arraycopy(dialectMsg, start, dialect, 0, i-start);
  250. if(byteToStr(dialect).contains("NT LM 0.12")) {
  251. return new byte[]{(byte)dialectNumber, (byte)(dialectNumber >> 8)};
  252. }
  253. start = i+1;
  254. dialectNumber++;
  255. }
  256. }
  257. return new byte[]{0x00, 0x00};
  258. }
  259. public byte[] getSessSetup() {
  260. if(authenticateNext) return getSetupAuth();
  261. else {
  262. authenticateNext = true;
  263. return getSetupChal();
  264. }
  265. }
  266. private byte[] getSetupChal() {
  267. byte[] wordCount = {0x04};
  268. byte[] andXCommand = {(byte) 0xff};
  269. byte[] reserved = {0x00};
  270. byte[] andXOffset = {0x60, 0x01};
  271. byte[] action = {0x00, 0x00};
  272. byte[] secBlobLength = {(byte) 0xc7, 0x00};
  273. byte[] byteCount = {0x35, 0x01};
  274. byte[] secBlob = {(byte) 0xa1, (byte) 0x81, (byte) 0xc4};
  275. byte[] negToken = {0x30, (byte) 0x81, (byte) 0xc1, (byte) 0xa0, 0x03, 0x0a, 0x01};
  276. byte[] negResult = {0x01};
  277. byte[] negToken2 = {(byte) 0xa1, 0x0c, 0x06, 0x0a};
  278. byte[] supportedMech = {0x2b, 0x06, 0x01, 0x04, 0x01, (byte) 0x82, 0x37, 0x02, 0x02, 0x0a};
  279. byte[] negToken3 = {(byte) 0xa2, (byte) 0x81, (byte) 0xab, 0x04, (byte) 0x81, (byte) 0xa8};
  280. byte[] respToken = {0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00,
  281. 0x38, 0x00, 0x00, 0x00, 0x15, (byte) 0x82, (byte) 0x8a, 0x62};
  282. byte[] challenge = randomBytes(8);
  283. byte[] respToken2 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x60, 0x00, 0x48, 0x00, 0x00, 0x00,
  284. 0x06, 0x01, (byte) 0xb0, 0x1d, 0x00, 0x00, 0x00, 0x0f, 0x42, 0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00,
  285. 0x4e, 0x00, 0x45, 0x00, 0x53, 0x00, 0x53, 0x00, 0x02, 0x00, 0x10, 0x00, 0x42, 0x00, 0x55, 0x00,
  286. 0x53, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x45, 0x00, 0x53, 0x00, 0x53, 0x00, 0x01, 0x00, 0x10, 0x00,
  287. 0x42, 0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x45, 0x00, 0x53, 0x00, 0x53, 0x00,
  288. 0x04, 0x00, 0x10, 0x00, 0x42, 0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x45, 0x00,
  289. 0x53, 0x00, 0x53, 0x00, 0x03, 0x00, 0x10, 0x00, 0x42, 0x00, 0x55, 0x00, 0x53, 0x00, 0x49, 0x00,
  290. 0x4e, 0x00, 0x45, 0x00, 0x53, 0x00, 0x53, 0x00, 0x07, 0x00, 0x08, 0x00};
  291. byte[] timeStamp = getTimeInBytes();
  292. byte[] respToken3 = {0x00, 0x00, 0x00, 0x00};
  293. byte[] nativOS = {0x57, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x64, 0x00,
  294. 0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00,
  295. 0x6f, 0x00, 0x66, 0x00, 0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x6e, 0x00,
  296. 0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x37, 0x00, 0x36, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00}; //Windows 7 Professional 7600
  297. byte[] nativLanMngr = {0x57, 0x00, 0x69, 0x00, 0x6e, 0x00,
  298. 0x64, 0x00, 0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x50, 0x00,
  299. 0x72, 0x00, 0x6f, 0x00, 0x66, 0x00, 0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00,
  300. 0x6e, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x36, 0x00, 0x2e, 0x00, 0x31, 0x00, 0x00, 0x00}; //Windows 7 Professional 6.1
  301. ntStat = new byte[]{0x16, 0x00, 0x00, (byte) 0xc0};
  302. userID = new byte[]{0x00, 0x08};
  303. byte[] response = concat(getHeader(), wordCount, andXCommand, reserved, andXOffset, action, secBlobLength,
  304. byteCount, secBlob, negToken, negResult, negToken2, supportedMech, negToken3,
  305. respToken, challenge, respToken2, timeStamp, respToken3, nativOS, nativLanMngr);
  306. return concat(getNetbios(response), response);
  307. }
  308. private byte[] getSetupAuth() {
  309. byte[] wordCount = {0x04};
  310. byte[] andXCommand = {(byte) 0xff};
  311. byte[] reserved = {0x00};
  312. byte[] andXOffset = {(byte) 0xa2, 0x00};
  313. byte[] action = {0x01, 0x00};
  314. byte[] secBlobLength = {0x09, 0x00};
  315. byte[] byteCount = {(byte) 0x77, 0x00};
  316. byte[] secBlob = {(byte) 0xa1, 0x07, 0x30, 0x05, (byte) 0xa0, 0x03, 0x0a, 0x01, 0x00};
  317. byte[] nativOS = {0x57, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x64, 0x00,
  318. 0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00,
  319. 0x6f, 0x00, 0x66, 0x00, 0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x6e, 0x00,
  320. 0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x37, 0x00, 0x36, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00}; //Windows 7 Professional 7600
  321. byte[] nativLanMngr = {0x57, 0x00, 0x69, 0x00, 0x6e, 0x00,
  322. 0x64, 0x00, 0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x50, 0x00,
  323. 0x72, 0x00, 0x6f, 0x00, 0x66, 0x00, 0x65, 0x00, 0x73, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00,
  324. 0x6e, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x36, 0x00, 0x2e, 0x00, 0x31, 0x00, 0x00, 0x00}; //Windows 7 Professional 6.1
  325. byte[] response = concat(getHeader(), wordCount, andXCommand, reserved, andXOffset, action, secBlobLength,
  326. byteCount, secBlob, nativOS, nativLanMngr);
  327. return concat(getNetbios(response), response);
  328. }
  329. public byte[] getTreeCon() {
  330. String str = toString();
  331. byte[] wordCount = {0x00};
  332. byte[] andXCommand = {0x00, 0x00};
  333. byte[] response = null;
  334. if(str.contains("IPC$") || str.contains("DOCS")) {
  335. wordCount = new byte[] {0x07};
  336. andXCommand = new byte[] {(byte) 0xff};
  337. byte[] reserved = {0x00};
  338. byte[] andXOffset = {0x38, 0x00};
  339. byte[] optionalSupport = {0x01, 0x00};
  340. byte[] maxShareAccess = {(byte) 0xff, (byte) 0xff, 0x1f, 0x00};
  341. byte[] guestMaxShareAccess = {(byte) 0xff, (byte) 0xff, 0x1f, 0x00};
  342. byte[] byteCount = {0x07, 0x00};
  343. byte[] service = {0x49, 0x50, 0x43, 0x00};
  344. byte[] extraParameters = {0x00, 0x00, 0x00};
  345. treeID = new byte[]{0x00, 0x08};
  346. response = concat(getHeader(), wordCount, andXCommand, reserved, andXOffset, optionalSupport, maxShareAccess,
  347. guestMaxShareAccess, byteCount, service, extraParameters);
  348. } else if(str.contains("C$") || str.contains("ADMIN$")) {
  349. ntStat = new byte[] {0x22, 0x00, 0x00, (byte) 0xc0};
  350. response = concat(getHeader(), wordCount, andXCommand);
  351. } else {
  352. ntStat = new byte[] {(byte) 0xcc, 0x00, 0x00, (byte) 0xc0};
  353. response = concat(getHeader(), wordCount, andXCommand);
  354. }
  355. return concat(getNetbios(response), response);
  356. }
  357. public byte[] getNTCreate() {
  358. byte[] wordCount = {0x22};
  359. byte[] andXCommand = {(byte) 0xff};
  360. byte[] reserved = {0x00};
  361. byte[] andXOffset = {0x67, 0x00};
  362. byte[] oplockLevel = {0x00};
  363. byte[] fid = {(byte) 0x00, 0x40};
  364. byte[] createAction = {0x01, 0x00, 0x00, 0x00};
  365. byte[] created = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  366. byte[] lastAccess = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  367. byte[] lastWrite = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  368. byte[] change = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  369. byte[] fileAttributes = {(byte) 0x80, 0x00, 0x00, 0x00};
  370. byte[] allocationSize = {0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  371. byte[] endOfFile = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  372. byte[] fileType = {0x02, 0x00};
  373. byte[] ipcState = {(byte) 0xff, 0x05};
  374. byte[] isDirectory = {0x00};
  375. byte[] byteCount = {0x00, 0x00};
  376. byte[] response = concat(getHeader(), wordCount, andXCommand, reserved, andXOffset, oplockLevel, fid,
  377. createAction, created, lastAccess, lastWrite, change, fileAttributes, allocationSize,
  378. endOfFile, fileType, ipcState, isDirectory, byteCount);
  379. return concat(getNetbios(response), response);
  380. }
  381. public byte[] getTrans() {
  382. byte[] transSub = getTransSub();
  383. byte[] response = null;
  384. if(transSub[0] == 0x00 && transSub[1] == 0x0b) {
  385. byte[] wordCount = {0x0a};
  386. byte[] totalParamCount = {0x00,0x00};
  387. byte[] totalDataCount = {0x44,0x00};
  388. byte[] reserved = {0x00, 0x00};
  389. byte[] paramCount = {0x00, 0x00};
  390. byte[] paramOffset = {0x38, 0x00};
  391. byte[] paramDisplace = {0x00, 0x00};
  392. byte[] dataCount = {0x44, 0x00};
  393. byte[] dataOffset = {0x38, 0x00};
  394. byte[] dataDisplace = {0x00, 0x00};
  395. byte[] setupCount = {0x00};
  396. byte[] reserved2 = {0x00};
  397. byte[] byteCount = {0x45, 0x00};
  398. byte[] padding = {0x00};
  399. byte[] dcerpc = {0x05, 0x00,
  400. 0x0c, 0x03, 0x10, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, (byte) 0xb8, 0x10,
  401. (byte) 0xb8, 0x10, 0x4a, 0x41, 0x00, 0x00, 0x0d, 0x00, 0x5c, 0x50, 0x49, 0x50, 0x45, 0x5c, 0x73, 0x72,
  402. 0x76, 0x73, 0x76, 0x63, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x5d,
  403. (byte) 0x88, (byte) 0x8a, (byte) 0xeb, 0x1c, (byte) 0xc9, 0x11, (byte) 0x9f, (byte) 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60, 0x02, 0x00,
  404. 0x00, 0x00};
  405. response = concat(getHeader(), wordCount, totalParamCount, totalDataCount, reserved, paramCount, paramOffset,
  406. paramDisplace, dataCount, dataOffset, dataDisplace, setupCount, reserved2, byteCount, padding, dcerpc);
  407. } else if(transSub[0] == 0x00 && transSub[1] == 0x00) {
  408. byte[] wordCount = {0x0a};
  409. byte[] totalParamCount = {0x00, 0x00};
  410. byte[] totalDataCount = {0x54, 0x01};
  411. byte[] reserved = {0x00, 0x00};
  412. byte[] paramCount = {0x00, 0x00};
  413. byte[] paramOffset = {0x38, 0x00};
  414. byte[] paramDisplace = {0x00, 0x00};
  415. byte[] dataCount = {0x54, 0x01};
  416. byte[] dataOffset = {0x38, 0x00};
  417. byte[] dataDisplace = {0x00, 0x00};
  418. byte[] setupCount = {0x00};
  419. byte[] reserved2 = {0x00};
  420. byte[] byteCount = {0x55, 0x01};
  421. byte[] padding = {0x00};
  422. byte[] dcerpc = {0x05, 0x00,
  423. 0x02, 0x03, 0x10, 0x00, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3c, 0x01,
  424. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  425. byte[] serverService = {0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  426. 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00,
  427. 0x02, 0x00, 0x00, 0x00, 0x00, (byte) 0x80, 0x0c, 0x00, 0x02, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00,
  428. 0x00, (byte) 0x80, 0x14, 0x00, 0x02, 0x00, 0x18, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00,
  429. 0x02, 0x00, 0x20, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, (byte) 0x80, 0x24, 0x00, 0x02, 0x00, 0x07, 0x00,
  430. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x41, 0x00, 0x44, 0x00, 0x4d, 0x00,
  431. 0x49, 0x00, 0x4e, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
  432. 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x52, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x6f, 0x00, 0x74, 0x00,
  433. 0x65, 0x00, 0x20, 0x00, 0x41, 0x00, 0x64, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x00, 0x00,
  434. 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x43, 0x00,
  435. 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00,
  436. 0x00, 0x00, 0x44, 0x00, 0x65, 0x00, 0x66, 0x00, 0x61, 0x00, 0x75, 0x00, 0x6c, 0x00, 0x74, 0x00,
  437. 0x20, 0x00, 0x73, 0x00, 0x68, 0x00, 0x61, 0x00, 0x72, 0x00, 0x65, 0x00, 0x00, 0x00, 0x05, 0x00,
  438. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x64, 0x00, 0x6f, 0x00, 0x63, 0x00,
  439. 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
  440. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00,
  441. 0x00, 0x00, 0x49, 0x00, 0x50, 0x00, 0x43, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00,
  442. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x52, 0x00, 0x65, 0x00, 0x6d, 0x00,
  443. 0x6f, 0x00, 0x74, 0x00, 0x65, 0x00, 0x20, 0x00, 0x49, 0x00, 0x50, 0x00, 0x43, 0x00, 0x00, 0x00};
  444. byte[] totalEntries = {0x00, 0x00, 0x04, 0x00, 0x00, 0x00};
  445. byte[] referentID = {0x28, 0x00, 0x02, 0x00};
  446. byte[] resumeHandle = {0x00, 0x00, 0x00, 0x00};
  447. byte[] windowsError = {0x00, 0x00, 0x00, 0x00};
  448. response = concat(getHeader(), wordCount, totalParamCount, totalDataCount, reserved, paramCount, paramOffset,
  449. paramDisplace, dataCount, dataOffset, dataDisplace, setupCount, reserved2, byteCount, padding, dcerpc,
  450. serverService, totalEntries, referentID, resumeHandle, windowsError);
  451. }
  452. return concat(getNetbios(response), response);
  453. }
  454. public byte[] getClose() {
  455. byte[] wordCount = {0x00};
  456. byte[] byteCount = {0x00, 0x00};
  457. smbCommand = new byte[]{0x04};
  458. byte[] response = concat(getHeader(), wordCount, byteCount);
  459. return concat(getNetbios(response), response);
  460. }
  461. public byte[] getTreeDisc() {
  462. byte[] wordCount = {0x00};
  463. byte[] byteCount = {0x00, 0x00};
  464. smbCommand[0] = 0x71;
  465. byte[] response = concat(getHeader(), wordCount, byteCount);
  466. return concat(getNetbios(response), response);
  467. }
  468. public byte[] getEcho() {
  469. byte[] wordCount = {0x01};
  470. byte[] echoSeq = {0x01, 0x00};
  471. byte[] byteCount = {0x10, 0x00};
  472. byte[] echoData = {(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0,
  473. (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0};
  474. byte[] response = concat(getHeader(), wordCount, echoSeq, byteCount, echoData);
  475. return concat(getNetbios(response), response);
  476. }
  477. public byte[] getTrans2() {
  478. byte[] response = null;
  479. byte[] wordCount = {0x00};
  480. byte[] andXCommand = {0x00, 0x00};
  481. ntStat = new byte[] {0x22, 0x00, 0x00, (byte) 0xc0};
  482. response = concat(getHeader(), wordCount, andXCommand);
  483. return concat(getNetbios(response), response);
  484. }
  485. private byte[] getTransSub() {
  486. byte[] transSub = new byte[2];
  487. if(smbCommand[0] == 0x32) transSub = new byte[]{msg[66], msg[65]};
  488. else if(smbCommand[0] == 0x25) transSub = new byte[]{0x00, msg[90]};
  489. else transSub = new byte[]{0x00, 0x00};
  490. return transSub;
  491. }
  492. public String toString() {
  493. return byteToStr(msg);
  494. }
  495. public byte getSmbCommand() {
  496. return smbCommand[0];
  497. }
  498. }
  499. }