scraw

catsguard l2jfrozen

Mar 1st, 2021
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.83 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2jFrozenInterlude
  3. Index: gameserver/head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java
  4. ===================================================================
  5. --- gameserver/head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java (revision 986)
  6. +++ gameserver/head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java (working copy)
  7. @@ -1500,6 +1500,9 @@
  8. /** The _is stored. */
  9. private boolean _isStored = false;
  10.  
  11. +
  12. + private String _hwid;
  13. +
  14. /**
  15. * Skill casting information (used to queue when several skills are cast in a short time) *.
  16. */
  17. @@ -1644,6 +1647,24 @@
  18. return _accountName;
  19. }
  20.  
  21. + /**
  22. + * Gets the hwid
  23. + *
  24. + * @return the hwid
  25. + */
  26. + public String getHWid()
  27. + {
  28. + if (getClient() == null)
  29. + return _hwid;
  30. + _hwid = getClient().getHWid();
  31. + return _hwid;
  32. + }
  33. +
  34. + public String getLastHwId()
  35. + {
  36. + return this._hwid;
  37. + }
  38. +
  39. /**
  40. * Gets the account chars.
  41. *
  42. Index: gameserver/head-src/com/l2jfrozen/protection/LameHandler.java
  43. ===================================================================
  44. --- gameserver/head-src/com/l2jfrozen/protection/LameHandler.java (revision 0)
  45. +++ gameserver/head-src/com/l2jfrozen/protection/LameHandler.java (revision 0)
  46. @@ -0,0 +1,15 @@
  47. +package com.l2jfrozen.protection;
  48. +
  49. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  50. +
  51. +public class LameHandler
  52. +{
  53. + public void runCommand(L2PcInstance admin, String[] params)
  54. + {
  55. + }
  56. +
  57. + public String[] getCommandList()
  58. + {
  59. + return null;
  60. + }
  61. +}
  62. \ No newline at end of file
  63. Index: gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/GameGuardReply.java
  64. ===================================================================
  65. --- gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/GameGuardReply.java (revision 986)
  66. +++ gameserver/head-src/com/l2jfrozen/gameserver/network/clientpackets/GameGuardReply.java (working copy)
  67. @@ -14,50 +14,44 @@
  68. */
  69. package com.l2jfrozen.gameserver.network.clientpackets;
  70.  
  71. -import java.util.logging.Logger;
  72. -
  73. -import com.l2jfrozen.Config;
  74. -import com.l2jfrozen.crypt.nProtect;
  75. +import com.l2jfrozen.gameserver.network.L2GameClient;
  76. +import com.l2jfrozen.protection.CatsGuard;
  77. +import java.nio.ByteBuffer;
  78.  
  79. -/**
  80. - * @author zabbix Lets drink to code!
  81. - * Unknown Packet: ca 0000: 45 00 01 00 1e 37 a2 f5 00 00 00 00 00 00 00 00
  82. - * E....7..........
  83. - */
  84. public class GameGuardReply extends L2GameClientPacket
  85. {
  86. - private int[] _reply = new int[4];
  87. - private static final Logger _log = Logger.getLogger(GameGuardReply.class.getName());
  88. + private static final String _C__CA_GAMEGUARDREPLY = "[C] CA GameGuardReply";
  89. + private int[] _reply;
  90.  
  91. - @Override
  92. - protected void readImpl()
  93. - {
  94. - _reply[0] = readD();
  95. - _reply[1] = readD();
  96. - _reply[2] = readD();
  97. - _reply[3] = readD();
  98. - }
  99. + public GameGuardReply()
  100. + {
  101. + this._reply = new int[4];
  102. + }
  103.  
  104. - @Override
  105. - protected void runImpl()
  106. - {
  107. - //TODO: clean nProtect System
  108. - if (!nProtect.getInstance().checkGameGuardRepy(getClient(), _reply))
  109. - return;
  110. -
  111. - //L2jFrozen cannot be reached with GameGuard: L2Net notification --> Close Client connection
  112. - if(Config.GAMEGUARD_L2NET_CHECK){
  113. - getClient().closeNow();
  114. - _log.warning("Player with account name "+getClient().accountName +" kicked to use L2Net ");
  115. - return;
  116. - }
  117. -
  118. - getClient().setGameGuardOk(true);
  119. - }
  120. + protected void readImpl()
  121. + {
  122. + if ((CatsGuard.getInstance().isEnabled()) && (((L2GameClient)getClient()).getHWid() == null))
  123. + {
  124. + this._reply[0] = readD();
  125. + this._reply[1] = readD();
  126. + this._reply[2] = readD();
  127. + this._reply[3] = readD();
  128. + }
  129. + else
  130. + {
  131. + byte[] b = new byte[this._buf.remaining()];
  132. + readB(b);
  133. + }
  134. + }
  135.  
  136. - @Override
  137. - public String getType()
  138. - {
  139. - return "[C] CA GameGuardReply";
  140. - }
  141. + protected void runImpl()
  142. + {
  143. + if (CatsGuard.getInstance().isEnabled())
  144. + CatsGuard.getInstance().initSession((L2GameClient)getClient(), this._reply);
  145. + }
  146. +
  147. + public String getType()
  148. + {
  149. + return "[C] CA GameGuardReply";
  150. + }
  151. }
  152. \ No newline at end of file
  153. Index: gameserver/head-src/com/l2jfrozen/gameserver/network/GameCrypt.java
  154. ===================================================================
  155. --- gameserver/head-src/com/l2jfrozen/gameserver/network/GameCrypt.java (revision 986)
  156. +++ gameserver/head-src/com/l2jfrozen/gameserver/network/GameCrypt.java (working copy)
  157. @@ -1,87 +1,94 @@
  158. -/*
  159. - * This program is free software: you can redistribute it and/or modify it under
  160. - * the terms of the GNU General Public License as published by the Free Software
  161. - * Foundation, either version 3 of the License, or (at your option) any later
  162. - * version. This program is distributed in the hope that it will be useful, but
  163. - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  164. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  165. - * details. You should have received a copy of the GNU General Public License
  166. - * along with this program. If not, see <http://www.gnu.org/licenses/>.
  167. - */
  168. package com.l2jfrozen.gameserver.network;
  169.  
  170. -/**
  171. - * @author L2JFrozen
  172. - */
  173. public class GameCrypt
  174. {
  175. - private final byte[] _inKey = new byte[16];
  176. - private final byte[] _outKey = new byte[16];
  177. - private boolean _isEnabled;
  178. + private final byte[] _inKey = new byte[16];
  179. + private final byte[] _outKey = new byte[16];
  180. + private boolean _isEnabled;
  181. + private com.lameguard.crypt.GameCrypt _lameCrypt;
  182. + public static boolean _ISLAME;
  183. +
  184. + public GameCrypt()
  185. + {
  186. + if (_ISLAME)
  187. + this._lameCrypt = new com.lameguard.crypt.GameCrypt();
  188. + }
  189.  
  190. - public static void decrypt(final byte[] raw, final int offset, final int size, final GameCrypt gcrypt)
  191. - {
  192. - if(!gcrypt._isEnabled)
  193. - return;
  194. + public void setKey(byte[] key)
  195. + {
  196. + System.arraycopy(key, 0, this._inKey, 0, 16);
  197. + System.arraycopy(key, 0, this._outKey, 0, 16);
  198. + }
  199.  
  200. - int temp = 0;
  201. + public void decrypt(byte[] raw, int offset, int size)
  202. + {
  203. + if (_ISLAME)
  204. + {
  205. + this._lameCrypt.decrypt(raw, offset, size);
  206. + return;
  207. + }
  208.  
  209. - for(int i = 0; i < size; i++)
  210. - {
  211. - final int temp2 = raw[offset + i] & 0xFF;
  212. + if (!this._isEnabled) {
  213. + return;
  214. + }
  215. + int temp = 0;
  216.  
  217. - raw[offset + i] = (byte) (temp2 ^ gcrypt._inKey[i & 15] ^ temp);
  218. - temp = temp2;
  219. - }
  220. + for (int i = 0; i < size; i++)
  221. + {
  222. + int temp2 = raw[(offset + i)] & 0xFF;
  223.  
  224. - int old = gcrypt._inKey[8] & 0xff;
  225. - old |= gcrypt._inKey[9] << 8 & 0xff00;
  226. - old |= gcrypt._inKey[10] << 0x10 & 0xff0000;
  227. - old |= gcrypt._inKey[11] << 0x18 & 0xff000000;
  228. + raw[(offset + i)] = ((byte)(temp2 ^ this._inKey[(i & 0xF)] ^ temp));
  229. + temp = temp2;
  230. + }
  231.  
  232. - old += size;
  233. + int old = this._inKey[8] & 0xFF;
  234. + old |= this._inKey[9] << 8 & 0xFF00;
  235. + old |= this._inKey[10] << 16 & 0xFF0000;
  236. + old |= this._inKey[11] << 24 & 0xFF000000;
  237.  
  238. - gcrypt._inKey[8] = (byte) (old & 0xff);
  239. - gcrypt._inKey[9] = (byte) (old >> 0x08 & 0xff);
  240. - gcrypt._inKey[10] = (byte) (old >> 0x10 & 0xff);
  241. - gcrypt._inKey[11] = (byte) (old >> 0x18 & 0xff);
  242. - }
  243. + old += size;
  244.  
  245. - public static void encrypt(final byte[] raw, final int offset, final int size, final GameCrypt gcrypt)
  246. - {
  247. - if(!gcrypt._isEnabled)
  248. - {
  249. - gcrypt._isEnabled = true;
  250. - return;
  251. - }
  252. + this._inKey[8] = ((byte)(old & 0xFF));
  253. + this._inKey[9] = ((byte)(old >> 8 & 0xFF));
  254. + this._inKey[10] = ((byte)(old >> 16 & 0xFF));
  255. + this._inKey[11] = ((byte)(old >> 24 & 0xFF));
  256. + }
  257.  
  258. - int temp = 0;
  259. + public void encrypt(byte[] raw, int offset, int size)
  260. + {
  261. + if (_ISLAME)
  262. + {
  263. + this._lameCrypt.encrypt(raw, offset, size);
  264. + return;
  265. + }
  266.  
  267. - for(int i = 0; i < size; i++)
  268. - {
  269. - final int temp2 = raw[offset + i] & 0xFF;
  270. + if (!this._isEnabled)
  271. + {
  272. + this._isEnabled = true;
  273. + return;
  274. + }
  275.  
  276. - temp = temp2 ^ gcrypt._outKey[i & 15] ^ temp;
  277. - raw[offset + i] = (byte) temp;
  278. - }
  279. + int temp = 0;
  280.  
  281. - int old = gcrypt._outKey[8] & 0xff;
  282. + for (int i = 0; i < size; i++)
  283. + {
  284. + int temp2 = raw[(offset + i)] & 0xFF;
  285.  
  286. - old |= gcrypt._outKey[9] << 8 & 0xff00;
  287. - old |= gcrypt._outKey[10] << 0x10 & 0xff0000;
  288. - old |= gcrypt._outKey[11] << 0x18 & 0xff000000;
  289. + temp = temp2 ^ this._outKey[(i & 0xF)] ^ temp;
  290. + raw[(offset + i)] = ((byte)temp);
  291. + }
  292.  
  293. - old += size;
  294. + int old = this._outKey[8] & 0xFF;
  295.  
  296. - gcrypt._outKey[8] = (byte) (old & 0xff);
  297. - gcrypt._outKey[9] = (byte) (old >> 0x08 & 0xff);
  298. - gcrypt._outKey[10] = (byte) (old >> 0x10 & 0xff);
  299. - gcrypt._outKey[11] = (byte) (old >> 0x18 & 0xff);
  300. - }
  301. + old |= this._outKey[9] << 8 & 0xFF00;
  302. + old |= this._outKey[10] << 16 & 0xFF0000;
  303. + old |= this._outKey[11] << 24 & 0xFF000000;
  304.  
  305. - public static void setKey(final byte[] key, final GameCrypt gcrypt)
  306. - {
  307. - System.arraycopy(key, 0, gcrypt._inKey, 0, 16);
  308. - System.arraycopy(key, 0, gcrypt._outKey, 0, 16);
  309. - }
  310. -}
  311. + old += size;
  312. +
  313. + this._outKey[8] = ((byte)(old & 0xFF));
  314. + this._outKey[9] = ((byte)(old >> 8 & 0xFF));
  315. + this._outKey[10] = ((byte)(old >> 16 & 0xFF));
  316. + this._outKey[11] = ((byte)(old >> 24 & 0xFF));
  317. + }
  318. +}
  319. \ No newline at end of file
  320. Index: gameserver/head-src/com/l2jfrozen/protection/CRC16.java
  321. ===================================================================
  322. --- gameserver/head-src/com/l2jfrozen/protection/CRC16.java (revision 0)
  323. +++ gameserver/head-src/com/l2jfrozen/protection/CRC16.java (revision 0)
  324. @@ -0,0 +1,15 @@
  325. +package com.l2jfrozen.protection;
  326. +
  327. +public class CRC16
  328. +{
  329. + private static int[] table = { 0, 49345, 49537, 320, 49921, 960, 640, 49729, 50689, 1728, 1920, 51009, 1280, 50625, 50305, 1088, 52225, 3264, 3456, 52545, 3840, 53185, 52865, 3648, 2560, 51905, 52097, 2880, 51457, 2496, 2176, 51265, 55297, 6336, 6528, 55617, 6912, 56257, 55937, 6720, 7680, 57025, 57217, 8000, 56577, 7616, 7296, 56385, 5120, 54465, 54657, 5440, 55041, 6080, 5760, 54849, 53761, 4800, 4992, 54081, 4352, 53697, 53377, 4160, 61441, 12480, 12672, 61761, 13056, 62401, 62081, 12864, 13824, 63169, 63361, 14144, 62721, 13760, 13440, 62529, 15360, 64705, 64897, 15680, 65281, 16320, 16000, 65089, 64001, 15040, 15232, 64321, 14592, 63937, 63617, 14400, 10240, 59585, 59777, 10560, 60161, 11200, 10880, 59969, 60929, 11968, 12160, 61249, 11520, 60865, 60545, 11328, 58369, 9408, 9600, 58689, 9984, 59329, 59009, 9792, 8704, 58049, 58241, 9024, 57601, 8640, 8320, 57409, 40961, 24768, 24960, 41281, 25344, 41921, 41601, 25152, 26112, 42689, 42881, 26432, 42241, 26048, 25728, 42049, 27648, 44225, 44417, 27968, 44801, 28608, 28288, 44609, 43521, 27328, 27520, 43841, 26880, 43457, 43137, 26688, 30720, 47297, 47489, 31040, 47873, 31680, 31360, 47681, 48641, 32448, 32640, 48961, 32000, 48577, 48257, 31808, 46081, 29888, 30080, 46401, 30464, 47041, 46721, 30272, 29184, 45761, 45953, 29504, 45313, 29120, 28800, 45121, 20480, 37057, 37249, 20800, 37633, 21440, 21120, 37441, 38401, 22208, 22400, 38721, 21760, 38337, 38017, 21568, 39937, 23744, 23936, 40257, 24320, 40897, 40577, 24128, 23040, 39617, 39809, 23360, 39169, 22976, 22656, 38977, 34817, 18624, 18816, 35137, 19200, 35777, 35457, 19008, 19968, 36545, 36737, 20288, 36097, 19904, 19584, 35905, 17408, 33985, 34177, 17728, 34561, 18368, 18048, 34369, 33281, 17088, 17280, 33601, 16640, 33217, 32897, 16448 };
  330. +
  331. + public static int calc(byte[] bytes) {
  332. + int crc = 0;
  333. + for (byte b : bytes)
  334. + {
  335. + crc = crc >> 8 & 0xFF ^ table[((crc ^ b) & 0xFF)];
  336. + }
  337. + return crc;
  338. + }
  339. +}
  340. \ No newline at end of file
  341. Index: gameserver/head-src/com/l2jfrozen/gameserver/network/L2GameClient.java
  342. ===================================================================
  343. --- gameserver/head-src/com/l2jfrozen/gameserver/network/L2GameClient.java (revision 986)
  344. +++ gameserver/head-src/com/l2jfrozen/gameserver/network/L2GameClient.java (working copy)
  345. @@ -66,6 +66,8 @@
  346. import com.l2jfrozen.util.CloseUtil;
  347. import com.l2jfrozen.util.database.L2DatabaseFactory;
  348.  
  349. +import com.l2jfrozen.protection.CatsGuard;
  350. +
  351. /**
  352. * @author L2JFrozen dev
  353. */
  354. @@ -109,7 +111,10 @@
  355. private ClientStats _stats;
  356.  
  357. // Crypt
  358. - public GameCrypt crypt;
  359. + public GameCrypt _crypt;
  360. +
  361. + private String _hwid = null;
  362. + public IExReader _reader;
  363.  
  364. // Flood protection
  365. public long packetsNextSendTick = 0;
  366. @@ -132,7 +137,7 @@
  367. super(con);
  368. state = GameClientState.CONNECTED;
  369. _connectionstartTime = System.currentTimeMillis();
  370. - crypt = new GameCrypt();
  371. + _crypt = new GameCrypt();
  372. _stats = new ClientStats();
  373. _packetQueue = new ArrayBlockingQueue<ReceivablePacket<L2GameClient>>(com.l2jfrozen.netcore.Config.getInstance().CLIENT_PACKET_QUEUE_SIZE);
  374.  
  375. @@ -150,7 +155,7 @@
  376. public byte[] enableCrypt()
  377. {
  378. byte[] key = BlowFishKeygen.getRandomKey();
  379. - GameCrypt.setKey(key, crypt);
  380. + _crypt.setKey(key);
  381. return key;
  382. }
  383.  
  384. @@ -182,30 +187,31 @@
  385. public boolean decrypt(ByteBuffer buf, int size)
  386. {
  387. _closenow = false;
  388. - GameCrypt.decrypt(buf.array(), buf.position(), size, crypt);
  389. - return true;
  390. + _crypt.decrypt(buf.array(), buf.position(), size);
  391. + return true;
  392. }
  393.  
  394. @Override
  395. public boolean encrypt(final ByteBuffer buf, final int size)
  396. {
  397. - GameCrypt.encrypt(buf.array(), buf.position(), size, crypt);
  398. - buf.position(buf.position() + size);
  399. - return true;
  400. + _crypt.encrypt(buf.array(), buf.position(), size);
  401. + buf.position(buf.position() + size);
  402. + return true;
  403. }
  404.  
  405. public L2PcInstance getActiveChar()
  406. {
  407. return activeChar;
  408. }
  409. -
  410. +
  411. public void setActiveChar(L2PcInstance pActiveChar)
  412. {
  413. - activeChar = pActiveChar;
  414. - if(activeChar != null)
  415. - {
  416. - L2World.getInstance().storeObject(getActiveChar());
  417. - }
  418. + activeChar = pActiveChar;
  419. + if ((_reader != null) && (activeChar != null))
  420. + {
  421. + _reader.checkChar(activeChar);
  422. + L2World.getInstance().storeObject(getActiveChar());
  423. + }
  424. }
  425.  
  426. public ReentrantLock getActiveCharLock()
  427. @@ -226,6 +232,8 @@
  428. public void setAccountName(String pAccountName)
  429. {
  430. accountName = pAccountName;
  431. + if (_reader == null)
  432. + CatsGuard.getInstance().initSession(this);
  433. }
  434.  
  435. public String getAccountName()
  436. @@ -741,6 +749,8 @@
  437. if(Config.ENABLE_ALL_EXCEPTIONS)
  438. e.printStackTrace();
  439. }
  440. + if (this._reader != null)
  441. + CatsGuard.getInstance().doneSession(this);
  442. }
  443.  
  444. /**
  445. @@ -1212,7 +1222,23 @@
  446. }
  447. }
  448.  
  449. - /**
  450. + public void setHWID(String hwid)
  451. + {
  452. + this._hwid = hwid;
  453. + }
  454. +
  455. + public String getHWid()
  456. + {
  457. + return this._hwid;
  458. + }
  459. +
  460. + public static abstract interface IExReader
  461. + {
  462. + public abstract int read(ByteBuffer paramByteBuffer);
  463. + public abstract void checkChar(L2PcInstance paramL2PcInstance);
  464. + }
  465. +
  466. + /**
  467. * @return the _forcedToClose
  468. */
  469. public boolean is_forcedToClose()
  470. Index: gameserver/head-src/com/l2jfrozen/gameserver/network/BlowFishKeygen.java
  471. ===================================================================
  472. --- gameserver/head-src/com/l2jfrozen/gameserver/network/BlowFishKeygen.java (revision 986)
  473. +++ gameserver/head-src/com/l2jfrozen/gameserver/network/BlowFishKeygen.java (working copy)
  474. @@ -19,52 +19,36 @@
  475.  
  476. import com.l2jfrozen.util.random.Rnd;
  477.  
  478. -/**
  479. - * Blowfish keygen for GameServer client connections
  480. - *
  481. - * @author KenM
  482. - */
  483. public class BlowFishKeygen
  484. {
  485. - private static final int CRYPT_KEYS_SIZE = 20;
  486. - private static final byte[][] CRYPT_KEYS = new byte[CRYPT_KEYS_SIZE][16];
  487. + private static final int CRYPT_KEYS_SIZE = 20;
  488. + private static final byte[][] CRYPT_KEYS = new byte[20][16];
  489. + public static boolean _ISLAME;
  490.  
  491. - static
  492. - {
  493. - // init the GS encryption keys on class load
  494. + public static byte[] getRandomKey()
  495. + {
  496. + if (_ISLAME)
  497. + return com.lameguard.crypt.BlowFishKeygen.getRandomKey();
  498. + return CRYPT_KEYS[Rnd.get(20)];
  499. + }
  500.  
  501. - for(int i = 0; i < CRYPT_KEYS_SIZE; i++)
  502. - {
  503. - // randomize the 8 first bytes
  504. - for(int j = 0; j < CRYPT_KEYS[i].length; j++)
  505. - {
  506. - CRYPT_KEYS[i][j] = (byte) Rnd.get(255);
  507. - }
  508. + static
  509. + {
  510. + for (int i = 0; i < 20; i++)
  511. + {
  512. + for (int j = 0; j < CRYPT_KEYS[i].length; j++)
  513. + {
  514. + CRYPT_KEYS[i][j] = ((byte)Rnd.get(255));
  515. + }
  516.  
  517. - // the last 8 bytes are static
  518. - CRYPT_KEYS[i][8] = (byte) 0xc8;
  519. - CRYPT_KEYS[i][9] = (byte) 0x27;
  520. - CRYPT_KEYS[i][10] = (byte) 0x93;
  521. - CRYPT_KEYS[i][11] = (byte) 0x01;
  522. - CRYPT_KEYS[i][12] = (byte) 0xa1;
  523. - CRYPT_KEYS[i][13] = (byte) 0x6c;
  524. - CRYPT_KEYS[i][14] = (byte) 0x31;
  525. - CRYPT_KEYS[i][15] = (byte) 0x97;
  526. - }
  527. - }
  528. -
  529. - // block instantiation
  530. - private BlowFishKeygen()
  531. - {}
  532. -
  533. - /**
  534. - * Returns a key from this keygen pool, the logical ownership is retained by this keygen.<BR>
  535. - * Thus when getting a key with interests other then read-only a copy must be performed.<BR>
  536. - *
  537. - * @return A key from this keygen pool.
  538. - */
  539. - public static byte[] getRandomKey()
  540. - {
  541. - return CRYPT_KEYS[Rnd.get(CRYPT_KEYS_SIZE)];
  542. - }
  543. -}
  544. + CRYPT_KEYS[i][8] = -56;
  545. + CRYPT_KEYS[i][9] = 39;
  546. + CRYPT_KEYS[i][10] = -109;
  547. + CRYPT_KEYS[i][11] = 1;
  548. + CRYPT_KEYS[i][12] = -95;
  549. + CRYPT_KEYS[i][13] = 108;
  550. + CRYPT_KEYS[i][14] = 49;
  551. + CRYPT_KEYS[i][15] = -105;
  552. + }
  553. + }
  554. +}
  555. \ No newline at end of file
  556. Index: gameserver/head-src/com/l2jfrozen/protection/RC4.java
  557. ===================================================================
  558. --- gameserver/head-src/com/l2jfrozen/protection/RC4.java (revision 0)
  559. +++ gameserver/head-src/com/l2jfrozen/protection/RC4.java (revision 0)
  560. @@ -0,0 +1,96 @@
  561. +package com.l2jfrozen.protection;
  562. +
  563. +public class RC4
  564. +{
  565. + private byte[] state = new byte[256];
  566. + private int x;
  567. + private int y;
  568. + private byte[] _key;
  569. + private boolean _block = false;
  570. +
  571. + public RC4(String key, boolean block)
  572. + throws NullPointerException
  573. + {
  574. + this(key.getBytes(), block);
  575. + }
  576. +
  577. + public RC4(byte[] key, boolean block)
  578. + throws NullPointerException
  579. + {
  580. + this._key = key;
  581. + this._block = block;
  582. + setKey();
  583. + }
  584. +
  585. + private void setKey()
  586. + {
  587. + for (int i = 0; i < 256; i++)
  588. + {
  589. + this.state[i] = ((byte)i);
  590. + }
  591. +
  592. + this.x = 0;
  593. + this.y = 0;
  594. +
  595. + int index1 = 0;
  596. + int index2 = 0;
  597. +
  598. + if ((this._key == null) || (this._key.length == 0))
  599. + {
  600. + throw new NullPointerException();
  601. + }
  602. + for (int i = 0; i < 256; i++)
  603. + {
  604. + index2 = (this._key[index1] & 0xFF) + (this.state[i] & 0xFF) + index2 & 0xFF;
  605. +
  606. + byte tmp = this.state[i];
  607. + this.state[i] = this.state[index2];
  608. + this.state[index2] = tmp;
  609. +
  610. + index1 = (index1 + 1) % this._key.length;
  611. + }
  612. + }
  613. +
  614. + public byte[] rc4(String data)
  615. + {
  616. + if ((data == null) || (data.length() == 0))
  617. + {
  618. + return null;
  619. + }
  620. + return rc4(data.getBytes());
  621. + }
  622. +
  623. + public byte[] rc4(byte[] buf)
  624. + {
  625. + if (buf == null)
  626. + {
  627. + return null;
  628. + }
  629. +
  630. + byte[] result = new byte[buf.length];
  631. +
  632. + for (int i = 0; i < buf.length; i++)
  633. + {
  634. + this.x = (this.x + 1 & 0xFF);
  635. + this.y = ((this.state[this.x] & 0xFF) + this.y & 0xFF);
  636. +
  637. + byte tmp = this.state[this.x];
  638. + this.state[this.x] = this.state[this.y];
  639. + this.state[this.y] = tmp;
  640. +
  641. + int xorIndex = (this.state[this.x] & 0xFF) + (this.state[this.y] & 0xFF) & 0xFF;
  642. + result[i] = ((byte)((buf[i] ^ this.state[xorIndex]) & 0xFF));
  643. + }
  644. + if (this._block)
  645. + {
  646. + this.x = 0;
  647. + this.y = 0;
  648. + }
  649. + else if ((this.x > 5000) || (this.y > 5000))
  650. + {
  651. + this.x = 0; this.y = 0;
  652. + }
  653. +
  654. + return result;
  655. + }
  656. +}
  657. \ No newline at end of file
  658. Index: gameserver/head-src/com/l2jfrozen/gameserver/GameServer.java
  659. ===================================================================
  660. --- gameserver/head-src/com/l2jfrozen/gameserver/GameServer.java (revision 986)
  661. +++ gameserver/head-src/com/l2jfrozen/gameserver/GameServer.java (working copy)
  662. @@ -146,10 +146,12 @@
  663. import com.l2jfrozen.netcore.SelectorConfig;
  664. import com.l2jfrozen.netcore.SelectorThread;
  665. import com.l2jfrozen.status.Status;
  666. +import com.l2jfrozen.protection.CatsGuard;
  667. import com.l2jfrozen.util.IPv4Filter;
  668. import com.l2jfrozen.util.Memory;
  669. import com.l2jfrozen.util.Util;
  670. import com.l2jfrozen.util.database.L2DatabaseFactory;
  671. +import com.lameguard.LameGuard;
  672.  
  673. public class GameServer
  674. {
  675. @@ -161,7 +163,7 @@
  676.  
  677. public static final Calendar dateTimeServerStarted = Calendar.getInstance();
  678.  
  679. - public static void main(String[] args) throws Exception
  680. + public static void main(String[] args) throws Throwable
  681. {
  682. ServerType.serverMode = ServerType.MODE_GAMESERVER;
  683.  
  684. @@ -221,10 +223,26 @@
  685. CrestCache.getInstance();
  686. L2ScriptEngineManager.getInstance();
  687.  
  688. - nProtect.getInstance();
  689. - if (nProtect.isEnabled())
  690. - _log.info("nProtect System Enabled");
  691. -
  692. + CatsGuard.getInstance();
  693. + if (!CatsGuard.getInstance().isEnabled()) {
  694. + try
  695. + {
  696. + Class clazz = Class.forName("com.lameguard.LameGuard");
  697. + if (clazz != null)
  698. + {
  699. + File f = new File("./lameguard/lameguard.properties");
  700. + if (f.exists())
  701. + {
  702. + Util.printSection("LameGuard");
  703. +
  704. + LameGuard.main(new String[] { "ru.catssoftware.protection.LameStub" });
  705. + }
  706. + }
  707. + }
  708. + catch (Exception ignored)
  709. + {
  710. + }
  711. + }
  712. Util.printSection("World");
  713. L2World.getInstance();
  714. MapRegionTable.getInstance();
  715. Index: gameserver/head-src/com/l2jfrozen/protection/CatsGuard.java
  716. ===================================================================
  717. --- gameserver/head-src/com/l2jfrozen/protection/CatsGuard.java (revision 0)
  718. +++ gameserver/head-src/com/l2jfrozen/protection/CatsGuard.java (revision 0)
  719. @@ -0,0 +1,298 @@
  720. +package com.l2jfrozen.protection;
  721. +
  722. +import com.l2jfrozen.L2Properties;
  723. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  724. +import com.l2jfrozen.gameserver.model.entity.Announcements;
  725. +import com.l2jfrozen.gameserver.network.L2GameClient;
  726. +import com.l2jfrozen.gameserver.network.L2GameClient.IExReader;
  727. +import com.l2jfrozen.gameserver.network.serverpackets.GameGuardQuery;
  728. +import com.l2jfrozen.gameserver.network.serverpackets.LeaveWorld;
  729. +import com.l2jfrozen.gameserver.thread.LoginServerThread;
  730. +import com.l2jfrozen.util.Util;
  731. +import com.l2jfrozen.util.database.L2DatabaseFactory;
  732. +import java.nio.ByteBuffer;
  733. +import java.sql.Connection;
  734. +import java.sql.PreparedStatement;
  735. +import java.sql.ResultSet;
  736. +import java.sql.SQLException;
  737. +import java.util.List;
  738. +import java.util.Map;
  739. +import java.util.logging.Logger;
  740. +import javolution.util.FastList;
  741. +import javolution.util.FastMap;
  742. +
  743. +public class CatsGuard
  744. +{
  745. + private static Logger _log = Logger.getLogger("CatsGuard");
  746. + private static CatsGuard _instance;
  747. + private Map<String, Integer> _connections;
  748. + private List<String> _premium = new FastList();
  749. + private List<String> _bannedhwid;
  750. + private static boolean ENABLED = true;
  751. + private static int _SERVER_KEY = 7958915;
  752. + private int MAX_SESSIONS;
  753. + private int MAX_PREMIUM_SESSIONS;
  754. + private String LOG_OPTION;
  755. + private boolean ANNOUNCE_HACK;
  756. + private String ON_HACK_ATTEMP;
  757. + private boolean ALLOW_GM_FROM_BANNED_HWID;
  758. + private boolean LOG_SESSIONS;
  759. +
  760. + public static CatsGuard getInstance()
  761. + {
  762. + if (_instance == null)
  763. + _instance = new CatsGuard();
  764. + return _instance;
  765. + }
  766. +
  767. + private CatsGuard()
  768. + {
  769. + Util.printSection("CatsGuard");
  770. + try
  771. + {
  772. + if (_SERVER_KEY == 0)
  773. + return;
  774. + L2Properties p = new L2Properties("./config/protected/catsguard.properties");
  775. + ENABLED = (Boolean.parseBoolean(p.getProperty("Enabled", "true"))) && (ENABLED);
  776. + if (!ENABLED)
  777. + {
  778. + _log.info("CatsGuard: disabled");
  779. + return;
  780. + } else {
  781. + _log.info("CatsGuard: enabled!");
  782. + }
  783. + this.LOG_OPTION = p.getProperty("LogOption", "NOSPS HACK");
  784. + this.MAX_SESSIONS = Integer.parseInt(p.getProperty("MaxSessionsFromHWID", "-1"));
  785. + this.MAX_PREMIUM_SESSIONS = Integer.parseInt(p.getProperty("MaxSessionsForPremium", "-1"));
  786. + this.ANNOUNCE_HACK = Boolean.parseBoolean(p.getProperty("AnnounceHackAttempt", "true"));
  787. + this.ON_HACK_ATTEMP = p.getProperty("OnHackAttempt", "kick");
  788. + this.ALLOW_GM_FROM_BANNED_HWID = Boolean.parseBoolean(p.getProperty("AllowGMFromBannedHWID", "false"));
  789. + this._connections = new FastMap().setShared(true);
  790. + this.LOG_SESSIONS = Boolean.parseBoolean(p.getProperty("LogSessions", "false"));
  791. + this._bannedhwid = new FastList();
  792. + Connection con = L2DatabaseFactory.getInstance().getConnection(false);
  793. + PreparedStatement stm = con.prepareStatement("select * from banned_hwid");
  794. + try
  795. + {
  796. + ResultSet rs = stm.executeQuery();
  797. + while (rs.next())
  798. + this._bannedhwid.add(rs.getString(1));
  799. + rs.close();
  800. + }
  801. + catch (Exception e)
  802. + {
  803. + if (e.getClass().getSimpleName().equals("MySQLSyntaxErrorException"))
  804. + {
  805. + stm.close();
  806. + stm = con.prepareStatement("create table `banned_hwid` (`hwid` varchar(64) not null primary key)");
  807. + stm.execute();
  808. + }
  809. + }
  810. + stm.close();
  811. + con.close();
  812. + _log.info("CatsGuard: Loaded " + this._bannedhwid.size() + " banned hwid(s)");
  813. + _log.info("CatsGuard: Ready");
  814. + }
  815. + catch (Exception e)
  816. + {
  817. + _log.warning("CatsGuard: Error while loading ./config/protected/catsguard.properties");
  818. + ENABLED = false;
  819. + }
  820. + }
  821. +
  822. + public boolean isEnabled()
  823. + {
  824. + return ENABLED;
  825. + }
  826. +
  827. + public void ban(L2PcInstance player)
  828. + {
  829. + ban(player.getHWid());
  830. + }
  831. +
  832. + public void ban(String hwid)
  833. + {
  834. + if (!ENABLED)
  835. + return;
  836. + synchronized (this._bannedhwid)
  837. + {
  838. + if (this._bannedhwid.contains(hwid))
  839. + return;
  840. + this._bannedhwid.add(hwid);
  841. + try
  842. + {
  843. + Connection con = L2DatabaseFactory.getInstance().getConnection(false);
  844. + PreparedStatement stm = con.prepareStatement("insert into banned_hwid values(?)");
  845. + stm.setString(1, hwid);
  846. + stm.execute();
  847. + stm.close();
  848. + con.close();
  849. + }
  850. + catch (SQLException e)
  851. + {
  852. + _log.warning("CatsGuard: Unable to store banned hwid");
  853. + }
  854. + }
  855. + }
  856. +
  857. + private void illegalAction(L2GameClient cl, String reason)
  858. + {
  859. + if ((cl.getActiveChar() != null) && (this.ANNOUNCE_HACK))
  860. + Announcements.getInstance().announceToAll("Player " + cl.getActiveChar().getName() + " used illegal software!");
  861. + if ((this.ON_HACK_ATTEMP.equals("hwidban")) && (cl.getHWid() != null))
  862. + ban(cl.getHWid());
  863. + else if ((this.ON_HACK_ATTEMP.equals("jail")) && (cl.getActiveChar() != null))
  864. + cl.getActiveChar().isInJail();
  865. + else if ((this.ON_HACK_ATTEMP.equals("ban")) && (cl.getActiveChar() != null))
  866. + LoginServerThread.getInstance().sendAccessLevel(cl.getAccountName(), -100);
  867. + _log.info("CatsGuard: Client " + cl + " use illegal software and will " + this.ON_HACK_ATTEMP + "ed. Reason: " + reason);
  868. + cl.close(new LeaveWorld());
  869. + }
  870. +
  871. + public void initSession(L2GameClient cl)
  872. + {
  873. + if (!ENABLED)
  874. + return;
  875. + cl.sendPacket(GameGuardQuery.STATIC_PACKET);
  876. + cl._reader = new CatsGuardReader(cl);
  877. + }
  878. +
  879. + public void doneSession(L2GameClient cl)
  880. + {
  881. + if (!ENABLED)
  882. + return;
  883. + if (cl.getHWid() != null)
  884. + {
  885. + this._premium.remove(cl.getHWid());
  886. + if (this._connections.containsKey(cl.getHWid()))
  887. + {
  888. + int nwnd = ((Integer)this._connections.get(cl.getHWid())).intValue();
  889. + if (nwnd == 0)
  890. + this._connections.remove(cl.getHWid());
  891. + else
  892. + this._connections.put(cl.getHWid(), Integer.valueOf(--nwnd));
  893. + }
  894. + }
  895. + cl._reader = null;
  896. + }
  897. +
  898. + public void initSession(L2GameClient cl, int[] data)
  899. + {
  900. + if (!ENABLED)
  901. + return;
  902. + if (data[0] != _SERVER_KEY)
  903. + {
  904. + if (this.LOG_OPTION.contains("NOPROTECT"))
  905. + _log.info("CatsGuard: Client " + cl + " try to log with no CatsGuard");
  906. + cl.close(new LeaveWorld());
  907. + return;
  908. + }
  909. + String hwid = String.format("%x", new Object[] { Integer.valueOf(data[3]) });
  910. + if (cl._reader == null)
  911. + {
  912. + if (this.LOG_OPTION.contains("HACK"))
  913. + _log.info("CatsGuard: Client " + cl + " has no pre-authed state");
  914. + cl.close(new LeaveWorld());
  915. + return;
  916. + }
  917. + if (this._bannedhwid.contains(hwid))
  918. + {
  919. + ((CatsGuardReader)cl._reader)._checkChar = true;
  920. + }
  921. + if (!this._connections.containsKey(hwid))
  922. + this._connections.put(hwid, Integer.valueOf(0));
  923. + int nwindow = ((Integer)this._connections.get(hwid)).intValue();
  924. + int max = this.MAX_SESSIONS;
  925. + if (this._premium.contains(hwid))
  926. + max = this.MAX_PREMIUM_SESSIONS;
  927. + if (max > 0) { nwindow++; if (nwindow > max)
  928. + {
  929. + if (this.LOG_OPTION.contains("SESSIONS"))
  930. + _log.info("CatsGuard: To many sessions from hwid " + hwid);
  931. + cl.close(new LeaveWorld());
  932. + return;
  933. + } }
  934. + if (!this._premium.contains(hwid))
  935. + this._premium.add(hwid);
  936. + this._connections.put(hwid, Integer.valueOf(nwindow));
  937. + cl.setHWID(hwid);
  938. + ((CatsGuardReader)cl._reader).setKey(data);
  939. + if (this.LOG_SESSIONS)
  940. + _log.info("Client " + cl.getAccountName() + " connected with hwid " + cl.getHWid());
  941. + }
  942. +
  943. + private class CatsGuardReader
  944. + implements L2GameClient.IExReader
  945. + {
  946. + private RC4 _crypt;
  947. + private L2GameClient _client;
  948. + private int _prevcode = 0;
  949. + private byte[] buffer = new byte[4];
  950. + private int _state;
  951. + private boolean _checkChar;
  952. +
  953. + private CatsGuardReader(L2GameClient cl)
  954. + {
  955. + this._state = 0;
  956. + this._client = cl;
  957. + }
  958. +
  959. + private void setKey(int[] data)
  960. + {
  961. + String key = "";
  962. + for (int i = 0; i < 10; i++)
  963. + key = key + String.format("%X%X", new Object[] { Integer.valueOf(data[1]), Integer.valueOf(CatsGuard._SERVER_KEY) });
  964. + this._crypt = new RC4(key, false);
  965. + this._state = 1;
  966. + }
  967. +
  968. + public int read(ByteBuffer buf)
  969. + {
  970. + int opcode = 0;
  971. + if (this._state == 0)
  972. + {
  973. + opcode = buf.get() & 0xFF;
  974. + if (opcode != 202)
  975. + {
  976. + CatsGuard.this.illegalAction(this._client, "Invalid opcode on pre-auth state");
  977. + return 0;
  978. + }
  979. +
  980. + }
  981. + else if (buf.remaining() < 4) {
  982. + CatsGuard.this.illegalAction(this._client, "Invalid block size on authed state");
  983. + }
  984. + else {
  985. + buf.get(this.buffer);
  986. + opcode = decryptPacket(this.buffer) & 0xFF;
  987. + }
  988. +
  989. + return opcode;
  990. + }
  991. +
  992. + private int decryptPacket(byte[] packet)
  993. + {
  994. + packet = this._crypt.rc4(packet);
  995. + int crc = CRC16.calc(new byte[] { (byte)(this._prevcode & 0xFF), packet[1] });
  996. + int read_crc = (packet[3] & 0xFF) << 8 & 0xFF00 | packet[2] & 0xFF;
  997. + if (crc != read_crc)
  998. + {
  999. + CatsGuard.this.illegalAction(this._client, "CRC error");
  1000. + return 0;
  1001. + }
  1002. + this._prevcode = (packet[1] & 0xFF);
  1003. + return this._prevcode;
  1004. + }
  1005. +
  1006. + public void checkChar(L2PcInstance cha)
  1007. + {
  1008. + if ((!this._checkChar) || (cha == null))
  1009. + return;
  1010. + if (CatsGuard.this.ALLOW_GM_FROM_BANNED_HWID)
  1011. + return;
  1012. + if (CatsGuard.this.LOG_OPTION.contains("BANNED"))
  1013. + CatsGuard._log.info("CatsGuard: Client " + cha.getClient() + " try to log with banned hwid");
  1014. + cha.closeNetConnection();
  1015. + }
  1016. + }
  1017. +}
  1018. \ No newline at end of file
  1019. Index: gameserver/config/protected/catsguard.properties
  1020. ===================================================================
  1021. --- gameserver/config/protected/catsguard.properties (revision 0)
  1022. +++ gameserver/config/protected/catsguard.properties (revision 0)
  1023. @@ -0,0 +1,30 @@
  1024. +# Enable Protection (need client patch)
  1025. +Enabled = True
  1026. +
  1027. +# Log
  1028. +# NOPROTECT - Login without client patch
  1029. +# HACK - Hacking attempt
  1030. +# SESSIONS - Enter players to world
  1031. +LogOption = NOPROTECT HACK SESSIONS
  1032. +
  1033. +# Maximum sessions from one HWID
  1034. +MaxSessionsFromHWID = 1
  1035. +
  1036. +#
  1037. +MaxSessionsForPremium=-1
  1038. +
  1039. +# Announce to all world hacker name
  1040. +AnnounceHackAttempt = false
  1041. +
  1042. +# then hack attempt
  1043. +# kick - kick player
  1044. +# jail - move player to jail
  1045. +# ban - ban player
  1046. +# hwidban - ban with hwid
  1047. +OnHackAttempt = kick
  1048. +
  1049. +# Allow GM from banned HWID pc
  1050. +AllowGMFromBannedHWID=false
  1051. +
  1052. +# Log players in enter world
  1053. +LogSessions= true
  1054. Index: gameserver/head-src/com/l2jfrozen/gameserver/network/serverpackets/GameGuardQuery.java
  1055. ===================================================================
  1056. --- gameserver/head-src/com/l2jfrozen/gameserver/network/serverpackets/GameGuardQuery.java (revision 986)
  1057. +++ gameserver/head-src/com/l2jfrozen/gameserver/network/serverpackets/GameGuardQuery.java (working copy)
  1058. @@ -18,39 +18,25 @@
  1059. */
  1060. package com.l2jfrozen.gameserver.network.serverpackets;
  1061.  
  1062. -import com.l2jfrozen.crypt.nProtect;
  1063. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  1064. +import com.l2jfrozen.gameserver.network.L2GameClient;
  1065.  
  1066. -/**
  1067. - * @author zabbix Lets drink to code!
  1068. - */
  1069. public class GameGuardQuery extends L2GameServerPacket
  1070. {
  1071. - private static final String _S__F9_GAMEGUARDQUERY = "[S] F9 GameGuardQuery";
  1072. + private static final String _S__F9_GAMEGUARDQUERY = "[S] F9 GameGuardQuery";
  1073. + public static final GameGuardQuery STATIC_PACKET = new GameGuardQuery();
  1074.  
  1075. - public GameGuardQuery()
  1076. - {
  1077. + public void runImpl(L2GameClient client, L2PcInstance activeChar)
  1078. + {
  1079. + }
  1080.  
  1081. - }
  1082. + public void writeImpl()
  1083. + {
  1084. + writeC(249);
  1085. + }
  1086.  
  1087. - @Override
  1088. - public void runImpl()
  1089. - {
  1090. - // Lets make user as gg-unauthorized
  1091. - // We will set him as ggOK after reply fromclient
  1092. - // or kick
  1093. - getClient().setGameGuardOk(false);
  1094. - }
  1095. -
  1096. - @Override
  1097. - public void writeImpl()
  1098. - {
  1099. - writeC(0xf9);
  1100. - nProtect.getInstance().sendGameGuardQuery(this);
  1101. - }
  1102. -
  1103. - @Override
  1104. - public String getType()
  1105. - {
  1106. - return _S__F9_GAMEGUARDQUERY;
  1107. - }
  1108. -}
  1109. + public String getType()
  1110. + {
  1111. + return "[S] F9 GameGuardQuery";
  1112. + }
  1113. +}
  1114. \ No newline at end of file
  1115. Index: gameserver/head-src/com/l2jfrozen/protection/LameStub.java
  1116. ===================================================================
  1117. --- gameserver/head-src/com/l2jfrozen/protection/LameStub.java (revision 0)
  1118. +++ gameserver/head-src/com/l2jfrozen/protection/LameStub.java (revision 0)
  1119. @@ -0,0 +1,12 @@
  1120. +package com.l2jfrozen.protection;
  1121. +
  1122. +public class LameStub
  1123. +{
  1124. + public static boolean ISLAME = false;
  1125. +
  1126. + public static void main(String[] args) {
  1127. + com.l2jfrozen.gameserver.network.BlowFishKeygen._ISLAME = true;
  1128. + com.l2jfrozen.gameserver.network.GameCrypt._ISLAME = true;
  1129. + ISLAME = true;
  1130. + }
  1131. +}
  1132. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment