Advertisement
Guest User

proxy.js (2B2T Version)

a guest
Feb 27th, 2019
2,830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Username = "Email here, must include quotes"
  2. const Password = "Password here, must include quotes"
  3. const PlayerName = "MC Username here, must include quotes"
  4.  
  5. /*
  6.  
  7. 2B2T NodeJS proxy server
  8.  
  9. Developed by BadPuns
  10. Built upon rom1504's 'minecraft-protocol'
  11.  
  12. Below is the code to set up a minecraft server on localhost:25566 that will forward traffic onto a destination server.
  13. This performs a MITM-like role, where one can log the packets being sent between the client and the server.
  14.  
  15. I added my own functionality to the proxy to modify packets en-route to the destination (client or server),
  16. filter out all packets of a certain type, and several other packet-based tasks within Minecraft.  This is a stripped down version of my
  17. original proxy, which includes a lot of teleportation, item storage exploits, and chat features.  This program includes:
  18. - Packet manager (.filter)
  19. - Chat formatter (.say [message], use % for color/format numbers)
  20. - Client-sided creative mode (.forcecreative)
  21. - Gamestate manager (.state [arg] [arg (optional)]) https://wiki.vg/Protocol#Change_Game_State
  22.  
  23. Before attempting to use this client, you must have NodeJS installed on your system.  You can do so at https://nodejs.org/en/
  24.  
  25. Once node is installed, you will need to install the dependancies for this proxy.  Here are the packages you'll need to install:
  26. - Minecraft protocol
  27. - readline
  28. - util
  29. - keypress
  30.  
  31. You can read more about each package on https://www.npmjs.com/
  32.  
  33. Detailed installation instructions below:
  34.  
  35. 1. Create a new folder on your desktop
  36. 2. Open command prompt and cd into that folder.  If you don't know how to do this you shouldn't own a computer.
  37. 3. Once in the correct folder/directory, you'll need to install the packages for this project.  Simply type the following into the prompt window
  38.  - "npm install [package]" (without quotes)
  39.  
  40.  Perform this command for each of the required packages listed above, replacing "[package]" with the name of the required package.
  41.  
  42. 4.  Next you'll want to create a text file.  Name it "proxy.js"
  43. 5.  Copy all the code from this file into that file, and save it.  Make sure it's actually saved as a .js file, and not "proxy.js.txt"
  44. 6.  You're almost done.  Next you're going to want to create the launcher for the proxy.  Create a new text file, and simply name it "start.txt"
  45. 7.  You're going to want to copy the following text and paste it into the file.
  46.  
  47. node proxy.js --dump-all -x keep_alive -x update_time -x block_break_animation -x advancements -x animation -x spawn_entity_living -x playerlist_header -x scoreboard_display_objective -x scoreboard_objective -x entity_update_attributes -x sound_effect -x map_chunk -x teams -x entity_equipment -x scoreboard_score -x world_particles -x entity_velocity -x rel_entity_move -x entity_look -x entity_move_look -x entity_teleport -x player_info -x entity_metadata -x entity_status -x entity_head_rotation 2b2t.org 1.12.2
  48. pause press [enter]
  49.  
  50. each entry with a -x in front of it shows a packet to exclude from the logger, because it's either spammy or useless.  Modify this as you please.
  51.  
  52. 8. Save the file with the text above as "start.bat", making sure it's not "start.bat.txt"
  53. 9. Run the .bat file, and it should open up a terminal.  If you don't get an error, your proxy should be up and running.
  54. 10. To connect to the proxy, add "localhost:25566" to your server list.  The connection will likely be slower than you're used to.
  55. 11. If you haven't input your login information into the variables above, you will get an error.  Make sure it's entered correctly if you're getting
  56. an invalid login error.
  57.  
  58. [FIXING THE CHUNK BAN]
  59. 1. Connect to the server.
  60. 2. As soon as possible, type ".filter add client map_chunk"
  61.  
  62. This adds the map_chunk packet to the blacklist for packets sent to the client, meaning terrain cannot be loaded.
  63. To undo this, type ".filter clear"
  64.  
  65. NOTE: If you have priority queue, this could be a lot harder for you, as you load into the game immediately.  I added an ability to send chat packets
  66. from normally impossible areas (like within a chest inventory.)  Simply go over to the console window, make sure it's selected, and spam the
  67. "c" key.  This could let you send the chat packet before you actually load the terrain.  Alternatively, if this does not work, you can
  68. change the "chatForced" value below to "/kill"
  69.  
  70. 3. If you successfully manage to join the server, chunks won't be rendered correctly.  It's an odd mess, and you can't move.  Your best bet is to
  71. /kill.  It sucks, but it's a lot better than being banned.
  72.  
  73. */
  74.  
  75. const mc = require('minecraft-protocol')
  76. const readline = require('readline')
  77. const util = require('util')
  78. var keypress = require('keypress');
  79. const now = new Date();
  80. var prefix = "."
  81.  
  82. var chatForced = ".filter add client map_chunk"
  83. var AccountEntity;
  84. var teleID = 0
  85. var pearlIntercept = false
  86. var targetClient;
  87. var clientPosition;
  88. var targetPosition = {
  89.   x: 0,
  90.   y: 0,
  91.   z: 0
  92. }
  93. var onlineServer = true
  94. var loggingPackets = true
  95. var offlineUser = "Pablo" //Only used for offline servers
  96.  
  97. var clientPackets = [
  98.       "spawn_entity_experience_orb",
  99.       "spawn_entity_weather",
  100.       "spawn_entity_living",
  101.       "spawn_entity_painting",
  102.       "named_entity_spawn",
  103.       "animation",
  104.       "statistics",
  105.       "advancements",
  106.       "block_break_animation",
  107.       "tile_entity_data",
  108.       "block_action",
  109.       "block_change",
  110.       "boss_bar",
  111.       "difficulty",
  112.       "tab_complete",
  113.       "chat",
  114.       "multi_block_change",
  115.       "transaction",
  116.       "close_window",
  117.       "open_window",
  118.       "window_items",
  119.       "craft_progress_bar",
  120.       "set_slot",
  121.       "set_cooldown",
  122.       "custom_payload",
  123.       "named_sound_effect",
  124.       "kick_disconnect",
  125.       "entity_status",
  126.       "explosion",
  127.       "unload_chunk",
  128.       "game_state_change",
  129.       "keep_alive",
  130.       "map_chunk",
  131.       "world_event",
  132.       "world_particles",
  133.       "login",
  134.       "map",
  135.       "rel_entity_move",
  136.       "entity_move_look",
  137.       "entity_look",
  138.       "entity",
  139.       "vehicle_move",
  140.       "open_sign_entity",
  141.       "craft_recipe_response",
  142.       "abilities",
  143.       "combat_event",
  144.       "player_info",
  145.       "position",
  146.       "bed",
  147.       "unlock_recipes",
  148.       "entity_destroy",
  149.       "remove_entity_effect",
  150.       "resource_pack_send",
  151.       "respawn",
  152.       "entity_head_rotation",
  153.       "world_border",
  154.       "camera",
  155.       "held_item_slot",
  156.       "scoreboard_display_objective",
  157.       "entity_metadata",
  158.       "attach_entity",
  159.       "entity_velocity",
  160.       "entity_equipment",
  161.       "experience",
  162.       "update_health",
  163.       "scoreboard_objective",
  164.       "set_passengers",
  165.       "teams",
  166.       "scoreboard_score",
  167.       "spawn_position",
  168.       "update_time",
  169.       "title",
  170.       "sound_effect",
  171.       "playerlist_header",
  172.       "collect",
  173.       "entity_teleport",
  174.       "entity_update_attributes",
  175.       "entity_effect",
  176.       "select_advancement_tab",
  177.       "spawn_entity",
  178.       "packet"
  179. ]
  180. var serverPackets = [
  181.         "teleport_confirm",
  182.         "tab_complete",
  183.         "chat",
  184.         "client_command",
  185.         "settings",
  186.         "transaction",
  187.         "enchant_item",
  188.         "window_click",
  189.         "close_window",
  190.         "custom_payload",
  191.         "use_entity",
  192.         "keep_alive",
  193.         "position",
  194.         "position_look",
  195.         "look",
  196.         "flying",
  197.         "vehicle_move",
  198.         "steer_boat",
  199.         "craft_recipe_request",
  200.         "abilities",
  201.         "block_dig",
  202.         "entity_action",
  203.         "steer_vehicle",
  204.         "crafting_book_data",
  205.         "resource_pack_receive",
  206.         "held_item_slot",
  207.         "set_creative_slot",
  208.         "update_sign",
  209.         "arm_animation",
  210.         "spectate",
  211.         "block_place",
  212.         "use_item",
  213.         "advancement_tab",
  214.         "packet"
  215. ]
  216. var clientFiltered = []
  217. var serverFiltered = []
  218.  
  219. const states = mc.states
  220. function printHelpAndExit (exitCode) {
  221.   console.log('usage: node proxy.js [<options>...] <target_srv> <version>')
  222.   console.log('options:')
  223.   console.log('  --dump name')
  224.   console.log('    print to stdout messages with the specified name.')
  225.   console.log('  --dump-all')
  226.   console.log('    print to stdout all messages, except those specified with -x.')
  227.   console.log('  -x name')
  228.   console.log('    do not print messages with this name.')
  229.   console.log('  name')
  230.   console.log('    a packet name as defined in protocol.json')
  231.   console.log('examples:')
  232.   console.log('  node proxy.js --dump-all -x keep_alive -x update_time -x entity_velocity -x rel_entity_move -x entity_look -x entity_move_look -x entity_teleport -x entity_head_rotation -x position localhost 1.8')
  233.   console.log('    print all messages except for some of the most prolific.')
  234.   console.log('  node examples/proxy.js --dump open_window --dump close_window --dump set_slot --dump window_items --dump craft_progress_bar --dump transaction --dump close_window --dump window_click --dump set_creative_slot --dump enchant_item localhost 1.8')
  235.   console.log('    print messages relating to inventory management.')
  236.  
  237.   process.exit(exitCode)
  238. }
  239.  
  240. if (process.argv.length < 4) {
  241.   console.log('Too few arguments!')
  242.   printHelpAndExit(1)
  243. }
  244.  
  245. process.argv.forEach(function (val) {
  246.   if (val === '-h') {
  247.     printHelpAndExit(0)
  248.   }
  249. })
  250.  
  251. const args = process.argv.slice(2)
  252. let host
  253. let port = 25565
  254. let version
  255.  
  256. let printAllNames = false
  257. const printNameWhitelist = {}
  258. const printNameBlacklist = {};
  259. (function () {
  260.   let i = 0
  261.   for (i = 0; i < args.length; i++) {
  262.     const option = args[i]
  263.     if (!/^-/.test(option)) break
  264.     if (option === '--dump-all') {
  265.       printAllNames = true
  266.       continue
  267.     }
  268.     i++
  269.     const name = args[i]
  270.     if (option === '--dump') {
  271.       printNameWhitelist[name] = 'io'
  272.     } else if (option === '-x') {
  273.       printNameBlacklist[name] = 'io'
  274.     } else {
  275.       printHelpAndExit(1)
  276.     }
  277.   }
  278.   if (!(i + 2 <= args.length && args.length <= i + 4)) printHelpAndExit(1)
  279.   host = args[i++]
  280.   version = args[i++]
  281. })()
  282.  
  283. if (host.indexOf(':') !== -1) {
  284.   port = host.substring(host.indexOf(':') + 1)
  285.   host = host.substring(0, host.indexOf(':'))
  286. }
  287.  
  288. //DEFAULT VIRTUAL SERVER
  289.  
  290. motds = ["§cPacket logging and injection at it's finest", "§c\"No mom I swear I'm not hacking please don't tell the admins\"", "§cNo homo", "§cOh it crashed again", "§cSounds like lag to me", "§cDeveloped by BadPuns. Don't take credit fags."]
  291. motdToUse = Math.floor(Math.random() * (+motds.length - +0)) + +0
  292.  
  293. const srv = mc.createServer({
  294.   'online-mode': false,
  295.   motd: motds[motdToUse],
  296.   port: 25566,
  297.   keepAlive: false,
  298.   version: version
  299. })
  300.  
  301. srv.on('login', function (client) {
  302.  
  303.  
  304.   keypress(process.stdin);
  305.  
  306.   process.stdin.on('keypress', function (ch, key) {
  307.  
  308.     if(key && key.name == 'p'){
  309.       if(loggingPackets == true){
  310.         loggingPackets = false
  311.         console.log("\x1b[43m" + "Toggled packet logging to false.  Press P to enable." + "\x1b[0m")
  312.       } else {
  313.         loggingPackets = true
  314.         console.log("\x1b[43m" + "Toggled packet logging to true.  Press P to disable." + "\x1b[0m")
  315.       }
  316.     }
  317.  
  318.     if(key && key.name == 'c'){
  319.       targetClient.write('chat', {message: chatForced});
  320.     }
  321.   });
  322.  
  323.   process.stdin.setRawMode(true);
  324.   process.stdin.resume();
  325.  
  326. })
  327.  
  328. srv.on('login', function (client) {
  329.   const addr = client.socket.remoteAddress
  330.   console.log('Incoming connection', '(' + addr + ')')
  331.   let endedClient = false
  332.   let endedTargetClient = false
  333.  
  334.   var loginMsg = {
  335.     translate: 'chat.type.admin',
  336.     "with": ["§3§lProxy", "§7Connected to §c" + host + ":" + port + "\n§7Online server: §c" + onlineServer + "\n§7Account: §c" + PlayerName + "\n\n§7For a list of commands, type " + prefix + "help"]
  337.   };
  338.  
  339. setTimeout(function(){
  340.   client.write("chat", { message: JSON.stringify(loginMsg), position: 0 });
  341. }, 1000);
  342.  
  343.   client.on('end', function () {
  344.     endedClient = true
  345.     console.log('Connection closed by client', '(' + addr + ')')
  346.     if (!endedTargetClient) { targetClient.end('§cHey! This is a Christian minecraft server, we don\'t appreciate language!') }
  347.   })
  348.   client.on('error', function (err) {
  349.     endedClient = true
  350.     console.log('Connection error by client', '(' + addr + ')')
  351.     console.log(err.stack)
  352.     if (!endedTargetClient) { targetClient.end('§c*robot noises* Base coordinates successfully exported.') }
  353.   })
  354.   if(onlineServer == false){
  355.       targetClient = mc.createClient({
  356.       host: host,
  357.       port: port,
  358.       username: client.username,
  359.       keepAlive: false,
  360.       version: version
  361.     })
  362.   } else {
  363.       targetClient = mc.createClient({
  364.       host: host,
  365.       port: port,
  366.       username: Username,
  367.       password: Password,
  368.       keepAlive: false,
  369.       version: version
  370.     })
  371.   }
  372.   client.on('packet', function (data, meta) {
  373.     var sendPacket = true
  374.     if (targetClient.state === states.PLAY && meta.state === states.PLAY) {
  375.     //if (targetClient.state && meta.state) {
  376.       if (shouldDump(meta.name, 'o')) {
  377.         if(loggingPackets == true){
  378.           console.log('client->server:',
  379.             client.state + ' ' + meta.name + ' :',
  380.             JSON.stringify(data))
  381.         }
  382.       }
  383.       if(data.message){
  384.         var words = data.message.split(' ');
  385. //Catch all messages that start with "."
  386.         if(data.message.toLowerCase().startsWith(prefix)){
  387.           sendPacket = false
  388.         }
  389.  
  390. //Help Command
  391.         if(data.message.toLowerCase().startsWith(prefix + "help")){
  392.  
  393.           var help = {
  394.             translate: 'chat.type.admin',
  395.             "with": ["§3§lProxy", "§7Help command coming soon.   I'm lazy."]
  396.           };
  397.  
  398.           client.write("chat", { message: JSON.stringify(help), position: 0 });
  399.           sendPacket = false
  400.         }
  401.  
  402. //Packet filter command.  Usage: 0/filter 1[add/remove/clear/list] 2[from:client/server] 3[packetName]
  403.         if(data.message.toLowerCase().startsWith(prefix + "filter")){
  404.           if(words[1]){
  405.  
  406.  
  407.             if(words[1].toLowerCase() == "list"){//SUBCOMMAND FINISHED
  408.               var serverStr = serverFiltered.join("\n§c")
  409.               var clientStr = clientFiltered.join("\n§c")
  410.               if(!serverFiltered[0]){
  411.                 serverStr = "§cThere are no packets currently being filtered from the server."
  412.               }
  413.               if(!clientFiltered[0]){
  414.                 clientStr = "§cThere are no packets currently being filtered from the client."
  415.               }
  416.  
  417.               var c = {
  418.                   translate: 'chat.type.admin',
  419.                   "with": ["§3§lProxy", "§7Packets from the client currently filtered:\n§c" + clientStr]
  420.                 };
  421.               client.write("chat", { message: JSON.stringify(c), position: 0 });
  422.               sendPacket = false
  423.  
  424.               var s = {
  425.                   translate: 'chat.type.admin',
  426.                   "with": ["§3§lProxy", "§7Packets from the server currently filtered:\n§c" + serverStr]
  427.                 };
  428.               client.write("chat", { message: JSON.stringify(s), position: 0 });
  429.               sendPacket = false
  430.             }
  431.  
  432.  
  433.  
  434.             if(words[1].toLowerCase() == "clear"){//SUBCOMMAND FINISHED
  435.               if(words[2]){
  436.                 if(words[2].toLowerCase() == "client"){
  437.                   clientFiltered = []
  438.  
  439.                   var help = {
  440.                       translate: 'chat.type.admin',
  441.                       "with": ["§3§lProxy", "§7All filters on traffic coming from the §cclient §7have been removed."]
  442.                     };
  443.                   client.write("chat", { message: JSON.stringify(help), position: 0 });
  444.                   sendPacket = false
  445.                 }
  446.                 if(words[2].toLowerCase() == "server"){
  447.                   serverFiltered = []
  448.  
  449.                   var help = {
  450.                       translate: 'chat.type.admin',
  451.                       "with": ["§3§lProxy", "§7All filters on traffic coming from the §cserver §7have been removed."]
  452.                     };
  453.                   client.write("chat", { message: JSON.stringify(help), position: 0 });
  454.                   sendPacket = false
  455.                 }
  456.               } else {
  457.                 clientFiltered = []
  458.                 serverFiltered = []
  459.  
  460.                 var help = {
  461.                     translate: 'chat.type.admin',
  462.                     "with": ["§3§lProxy", "§7All filters on traffic coming from both the §cclient and server §7have been removed."]
  463.                   };
  464.                 client.write("chat", { message: JSON.stringify(help), position: 0 });
  465.                 sendPacket = false
  466.               }
  467.             }
  468.  
  469.  
  470.  
  471.             if(words[1].toLowerCase() == "add"){
  472.               if(words[2]){
  473.                 if(words[2].toLowerCase() == "server"){
  474.                   if(words[3]){
  475.                     function serverFinder(item){
  476.                         return words[3].toLowerCase() == item.toLowerCase()
  477.                     }
  478.                     var foundPacket = serverPackets.find(serverFinder)
  479.                     if(foundPacket != undefined){
  480.                       serverFiltered.push(words[3].toLowerCase())
  481.  
  482.                       var yes = {
  483.                           translate: 'chat.type.admin',
  484.                           "with": ["§3§lProxy", "§7Added packet §c'" + words[3] + "'§7 to the " + words[2] + " filter"]
  485.                         };
  486.                       client.write("chat", { message: JSON.stringify(yes), position: 0 });
  487.                       sendPacket = false
  488.                     } else {
  489.                       var err = {
  490.                           translate: 'chat.type.admin',
  491.                           "with": ["§3§lProxy", "§cError: Could not find packet '" + words[3] + "'"]
  492.                         };
  493.                       client.write("chat", { message: JSON.stringify(err), position: 0 });
  494.                       sendPacket = false
  495.                     }
  496.                   } else {
  497.                     var err = {
  498.                         translate: 'chat.type.admin',
  499.                         "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  500.                       };
  501.                     client.write("chat", { message: JSON.stringify(err), position: 0 });
  502.                     sendPacket = false
  503.                   }
  504.                 }
  505.  
  506.                 if(words[2].toLowerCase() == "client"){
  507.                   if(words[3]){
  508.                     function clientFinder(item){
  509.                         return words[3].toLowerCase() == item.toLowerCase()
  510.                     }
  511.                     var foundPacket = clientPackets.find(clientFinder)
  512.                     if(foundPacket != undefined){
  513.                       clientFiltered.push(words[3].toLowerCase())
  514.  
  515.                       var yes = {
  516.                           translate: 'chat.type.admin',
  517.                           "with": ["§3§lProxy", "§7Added packet §c'" + words[3] + "'§7 to the " + words[2] + " filter"]
  518.                         };
  519.                       client.write("chat", { message: JSON.stringify(yes), position: 0 });
  520.                       sendPacket = false
  521.                     } else {
  522.                       var err = {
  523.                           translate: 'chat.type.admin',
  524.                           "with": ["§3§lProxy", "§cError: Could not find packet '" + words[3] + "'"]
  525.                         };
  526.                       client.write("chat", { message: JSON.stringify(err), position: 0 });
  527.                       sendPacket = false
  528.                     }
  529.                   } else {
  530.                     var err = {
  531.                         translate: 'chat.type.admin',
  532.                         "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  533.                       };
  534.                     client.write("chat", { message: JSON.stringify(err), position: 0 });
  535.                     sendPacket = false
  536.                   }
  537.                 }
  538.  
  539.               } else {
  540.                 var err = {
  541.                     translate: 'chat.type.admin',
  542.                     "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  543.                   };
  544.                 client.write("chat", { message: JSON.stringify(err), position: 0 });
  545.                 sendPacket = false
  546.               }
  547.             }
  548.  
  549.  
  550.             if(words[1].toLowerCase() == "remove"){
  551.               if(words[2]){
  552.                 if(words[2].toLowerCase() == "server"){
  553.                   if(words[3]){
  554.                     function serverFinder(item){
  555.                         return words[3].toLowerCase() == item.toLowerCase()
  556.                     }
  557.                     var foundPacket = serverPackets.find(serverFinder)
  558.                     if(foundPacket != undefined){
  559.                       //FIX THIS RIGHT HERE
  560.                       var index = serverFiltered.indexOf(words[3]);
  561.                       if (index > -1) {
  562.                         serverFiltered.splice(index, 1);
  563.                       }
  564.                       //
  565.                       var yes = {
  566.                           translate: 'chat.type.admin',
  567.                           "with": ["§3§lProxy", "§7Removed packet §c'" + words[3] + "'§7 from the " + words[2] + " filter"]
  568.                         };
  569.                       client.write("chat", { message: JSON.stringify(yes), position: 0 });
  570.                       sendPacket = false
  571.                     } else {
  572.                       var err = {
  573.                           translate: 'chat.type.admin',
  574.                           "with": ["§3§lProxy", "§cError: Could not find packet '" + words[3] + "'"]
  575.                         };
  576.                       client.write("chat", { message: JSON.stringify(err), position: 0 });
  577.                       sendPacket = false
  578.                     }
  579.                   } else {
  580.                     var err = {
  581.                         translate: 'chat.type.admin',
  582.                         "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  583.                       };
  584.                     client.write("chat", { message: JSON.stringify(err), position: 0 });
  585.                     sendPacket = false
  586.                   }
  587.                 }
  588.  
  589.                 if(words[2].toLowerCase() == "client"){
  590.                   if(words[3]){
  591.                     function clientFinder(item){
  592.                         return words[3].toLowerCase() == item.toLowerCase()
  593.                     }
  594.                     var foundPacket = clientPackets.find(clientFinder)
  595.                     if(foundPacket != undefined){
  596.                       //FIX THIS RIGHT HERE
  597.                       var index = clientFiltered.indexOf(words[3]);
  598.                       if (index > -1) {
  599.                         clientFiltered.splice(index, 1);
  600.                       }
  601.                       //
  602.                       var yes = {
  603.                           translate: 'chat.type.admin',
  604.                           "with": ["§3§lProxy", "§7Removed packet §c'" + words[3] + "'§7 from the " + words[2] + " filter"]
  605.                         };
  606.                       client.write("chat", { message: JSON.stringify(yes), position: 0 });
  607.                       sendPacket = false
  608.                     } else {
  609.                       var err = {
  610.                           translate: 'chat.type.admin',
  611.                           "with": ["§3§lProxy", "§cError: Could not find packet '" + words[3] + "'"]
  612.                         };
  613.                       client.write("chat", { message: JSON.stringify(err), position: 0 });
  614.                       sendPacket = false
  615.                     }
  616.                   } else {
  617.                     var err = {
  618.                         translate: 'chat.type.admin',
  619.                         "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  620.                       };
  621.                     client.write("chat", { message: JSON.stringify(err), position: 0 });
  622.                     sendPacket = false
  623.                   }
  624.                 }
  625.  
  626.               } else {
  627.                 var err = {
  628.                     translate: 'chat.type.admin',
  629.                     "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  630.                   };
  631.                 client.write("chat", { message: JSON.stringify(err), position: 0 });
  632.                 sendPacket = false
  633.               }
  634.             }
  635.  
  636.  
  637.  
  638.           } else {
  639.               var err = {
  640.                   translate: 'chat.type.admin',
  641.                   "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + words[0] + " [add/remove/clear/list] [client/server] [packetName]"]
  642.                 };
  643.               client.write("chat", { message: JSON.stringify(err), position: 0 });
  644.               sendPacket = false
  645.           }
  646.         }
  647.  
  648. //Say command
  649.         if(data.message.toLowerCase().startsWith(prefix + "say")){
  650.           if(words[1] == undefined){
  651.           var help = {
  652.               translate: 'chat.type.admin',
  653.               "with": ["§3§lProxy", "§cError: Invalid syntax.\n§7§lUsage: " + prefix + "say [message]"]
  654.             };
  655.             client.write("chat", { message: JSON.stringify(help), position: 0 });
  656.             sendPacket = false
  657.           } else {
  658.             words.shift()
  659.             msgStr = words.join(' ')
  660.             var msg = msgStr.replace(/%/gi, '§')
  661.  
  662.             targetClient.write('chat', {message: msg});
  663.             sendPacket = false
  664.           }
  665.         }
  666.  
  667. //Client creative
  668.         if(data.message.toLowerCase().startsWith(prefix + "forcecreative")){
  669.           var help = {
  670.               translate: 'chat.type.admin',
  671.               "with": ["§3§lProxy", "§7Player gamemode set to §ccreatve §7§l(Client sided only)"]
  672.             };
  673.  
  674.             client.write("chat", { message: JSON.stringify(help), position: 0 });
  675.             client.write('game_state_change', {
  676.               reason: 3,
  677.               gameMode: 1
  678.             })
  679.             sendPacket = false
  680.         }
  681.  
  682. //Gamestate command
  683.         if(data.message.toLowerCase().startsWith(prefix + "state")){
  684.           if(words[1] == undefined){
  685.           var help = {
  686.               translate: 'chat.type.admin',
  687.               "with": ["§3§lProxy", "§cError: Invalid syntax\n§7Usage: " + prefix + "state [reason] [value (optional)]"]
  688.             };
  689.  
  690.             client.write("chat", { message: JSON.stringify(help), position: 0 });
  691.             sendPacket = false
  692.           } else {
  693.             if(words[2] == undefined){
  694.               var msg = {
  695.                   translate: 'chat.type.admin',
  696.                   "with": ["§3§lProxy", "§7Packet has been sent to client"]
  697.                 };
  698.  
  699.  
  700.               client.write("chat", { message: JSON.stringify(msg), position: 0 });
  701.               client.write('game_state_change', {
  702.                 reason: parseInt(words[1])
  703.               })
  704.               sendPacket = false
  705.             } else {
  706.               var msg = {
  707.                   translate: 'chat.type.admin',
  708.                   "with": ["§3§lProxy", "§7Packet has been sent to client"]
  709.                 };
  710.  
  711.  
  712.               client.write("chat", { message: JSON.stringify(msg), position: 0 });
  713.               client.write('game_state_change', {
  714.                 reason: parseInt(words[1]),
  715.                 gameMode: parseInt(words[2])
  716.               })
  717.               sendPacket = false
  718.             }
  719.         }
  720.       }
  721.  
  722.  
  723.     }
  724.  
  725.     if(data.channel){
  726.       if(data.channel == "MC|BSign"){ //Add toggleable option too
  727.         var f = {
  728.           translate: 'chat.type.admin',
  729.           "with": ["§3§lProxy", "§7Book detected with data:\n§c" + data.data]
  730.         };
  731.         //client.write("chat", { message: JSON.stringify(f), position: 0 });
  732.         console.log("\n\nBOOK DATA: " + typeof(data.data) + "\n" + data.data + "\n\n")
  733.       }
  734.     }
  735.  
  736. var loop; //maybe?
  737. for(loop = 0; loop < serverFiltered.length; loop++){
  738.   if(meta.name.toLowerCase() == serverFiltered[loop].toLowerCase()){
  739.     sendPacket = false
  740.     console.log("\x1b[33m" + "\x1b[36m" + 'FILTERED PACKET DETECTED: ' + serverFiltered[loop] + "\x1b[0m")
  741.   }
  742. } //
  743.  
  744.       if(sendPacket == true){
  745.         if (!endedTargetClient) { targetClient.write(meta.name, data) }
  746.       }
  747.     }
  748.   })
  749.   targetClient.on('packet', function (data, meta) {
  750.     var sendPacket = true
  751.     if (meta.state === states.PLAY && client.state === states.PLAY) {
  752.     //if (meta.state && client.state) {
  753.       if (shouldDump(meta.name, 'i')) {
  754.         if(loggingPackets == true){
  755.         console.log("\x1b[36m" + "\x1b[47m" + 'server->client:' + "\x1b[0m" + "\x1b[36m",
  756.           "\x1b[4m" + targetClient.state + '.' + meta.name + "\x1b[0m" + "\x1b[36m" + ':' +
  757.           JSON.stringify(data) + "\x1b[0m")
  758.         }
  759.       }
  760.  
  761.       var loop; //Maybe?
  762.       for(loop = 0; loop < clientFiltered.length; loop++){
  763.         if(meta.name.toLowerCase() == clientFiltered[loop].toLowerCase()){
  764.           sendPacket = false
  765.           console.log("\x1b[33m" + "\x1b[36m" + 'FILTERED PACKET DETECTED: ' + clientFiltered[loop] + "\x1b[0m")
  766.         }
  767.       } //
  768.       if(sendPacket == true){ //maybe?
  769.         if (!endedClient) {
  770.           client.write(meta.name, data)
  771.           if (meta.name === 'set_compression') {
  772.             client.compressionThreshold = data.threshold
  773.           } // Set compression
  774.         }
  775.       } //
  776.     }
  777.   })
  778.  
  779.   targetClient.on('login', function (packet) {
  780.     AccountEntity = packet.entityId
  781.     console.log("\x1b[43m" + "\n\n\nACCOUNT ENTITY ID: " + AccountEntity + "\n\n\n" + "\x1b[0m")
  782.   })
  783.  
  784.  
  785.   const bufferEqual = require('buffer-equal')
  786.   targetClient.on('raw', function (buffer, meta) {
  787.     if (client.state !== states.PLAY || meta.state !== states.PLAY) { return }
  788.     const packetData = targetClient.deserializer.parsePacketBuffer(buffer).data.params
  789.     const packetBuff = client.serializer.createPacketBuffer({ name: meta.name, params: packetData })
  790.     if (!bufferEqual(buffer, packetBuff)) {
  791.       console.log('server->client: Error in packet ' + meta.state + '.' + meta.name)
  792.       console.log('received buffer', buffer.toString('hex'))
  793.       console.log('produced buffer', packetBuff.toString('hex'))
  794.       console.log('received length', buffer.length)
  795.       console.log('produced length', packetBuff.length)
  796.     }
  797.     /* if (client.state === states.PLAY && brokenPackets.indexOf(packetId.value) !=== -1)
  798.      {
  799.      console.log(`client<-server: raw packet);
  800.      console.log(packetData);
  801.      if (!endedClient)
  802.      client.writeRaw(buffer);
  803.      } */
  804.   })
  805.   client.on('raw', function (buffer, meta) {
  806.     if (meta.state !== states.PLAY || targetClient.state !== states.PLAY) { return }
  807.     const packetData = client.deserializer.parsePacketBuffer(buffer).data.params
  808.     const packetBuff = targetClient.serializer.createPacketBuffer({ name: meta.name, params: packetData })
  809.     if (!bufferEqual(buffer, packetBuff)) {
  810.       console.log('client->server: Error in packet ' + meta.state + '.' + meta.name)
  811.       console.log('received buffer', buffer.toString('hex'))
  812.       console.log('produced buffer', packetBuff.toString('hex'))
  813.       console.log('received length', buffer.length)
  814.       console.log('produced length', packetBuff.length)
  815.     }
  816.   })
  817.   targetClient.on('end', function () {
  818.     endedTargetClient = true
  819.     console.log('Connection closed by server', '(' + addr + ')')
  820.     if (!endedClient) { client.end('§cYou have been banned from 2B2T for illegal modifications.') }
  821.   })
  822.   targetClient.on('error', function (err) {
  823.     endedTargetClient = true
  824.     console.log('Connection error by server', '(' + addr + ') ', err)
  825.     console.log(err.stack)
  826.     if (!endedClient) { client.end('§cNice job dumbass, you fucked something up.  Check the console.') }
  827.   })
  828.  
  829.  
  830.  
  831. })
  832.  
  833. function shouldDump (name, direction) {
  834.   if (matches(printNameBlacklist[name])) return false
  835.   if (printAllNames) return true
  836.   return matches(printNameWhitelist[name])
  837.  
  838.   function matches (result) {
  839.     return result !== undefined && result !== null && result.indexOf(direction) !== -1
  840.   }
  841. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement