Advertisement
Guest User

vuln

a guest
Sep 24th, 2017
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.29 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. local printHelp = function()
  4.     print("Usage: mpc <modem> <device> <command> [parm]")
  5.     print("     modem = modem side")
  6.     print("     device = 'client'/'server'")  
  7.     print("     Client Commands:")  
  8.     print("       - spoof_id <sPort> <uPort>")  
  9.     print("       - get_port <sPort> <uID>")  
  10.     print("       - get_server_port <uPort>")  
  11.     print("       - get_name <sPort> <uPort> <uID>")  
  12.     print("       - set_name <sPort> <uPort> <uID> <name>")  
  13.     print("       - kick <sPort> <uPort> <uID>")  
  14.     print("       - logout <sPort> <uPort> <uID>")  
  15.     print("       - public_write <sPort> <uPort> <uID> <text>")  
  16.     print("       - private_write <sPort> <uPort> <uID> <text>")  
  17.     print("       - user_list <sPort> <uPort> <uID> <uName>")
  18.     print("     Server Commands:")
  19.     print("       - get_port <sName>")
  20.     print("       - get_all")
  21.     print("       - dos <sPort>")
  22.     print("       - user_overflow <sPort>")
  23.     print("       - get_all_uid <sPort>")
  24. end
  25.  
  26. local modem
  27. if #tArgs >= 2 then
  28.     modem = tArgs[1]
  29. else
  30.     if #tArgs == 2 then
  31.         error("Modem not found")
  32.     else
  33.         printHelp()
  34.     end
  35. end
  36.  
  37. if peripheral.getType(modem) ~= "modem" then
  38.     error("Modem not found")
  39. else
  40.     peripheral.call(modem, "closeAll")
  41. end
  42.  
  43. local command_list = {
  44.     server = {
  45.         caget_port = 1,
  46.         get_port = function(sName)
  47.             rednet.open(modem)
  48.             local hname = rednet.lookup("chat", sName)
  49.             if hname then
  50.                 return hname
  51.             else
  52.                 term.setTextColor(colors.red)
  53.                 return "Host not found"
  54.             end
  55.         end,
  56.         caget_all = 0,
  57.         get_all = function()
  58.             rednet.open(modem)
  59.             local hname = { rednet.lookup("chat") }
  60.             if hname then
  61.                 table.sort(hname)
  62.                 return table.unpack(hname)
  63.             else
  64.                 term.setTextColor(colors.red)
  65.                 return "No hosts found"
  66.             end
  67.         end,
  68.         cados = 1,
  69.         dos = function(sPort)
  70.             -- Maybe in some time
  71.         end,
  72.         causer_overflow = 1,
  73.         user_overflow = function(sPort)
  74.             -- Maybe in some time
  75.         end,
  76.         caget_all_uid = 1,
  77.         get_all_uid = function(sPort)
  78.             sPort = tonumber(sPort)
  79.            
  80.             local tUser = { }
  81.             local modem = peripheral.wrap(modem)
  82.  
  83.             modem.open(sPort)
  84.            
  85.             local timer = os.startTimer(15)
  86.             while true do
  87.                 local event, data, port, reply, message = os.pullEvent()
  88.                
  89.                 if event == "modem_message"
  90.                 and port == sPort
  91.                 and type(message) == "table"
  92.                 and type(message.message) == "table"
  93.                 and type(message.message.nUserID) == "number"
  94.                 then
  95.                     local doSave = true
  96.                     for _, id in pairs(tUser) do
  97.                         if id == message.message.nUserID then
  98.                             doSave = false
  99.                             break
  100.                         end
  101.                     end
  102.                    
  103.                     if doSave then
  104.                         table.insert(tUser, message.message.nUserID)
  105.                     end
  106.                 elseif event == "timer" and data == timer then
  107.                     break
  108.                 end
  109.             end
  110.            
  111.             if #tUser > 0 then
  112.                 return table.unpack( tUser )
  113.             else
  114.                 term.setTextColor(colors.red)
  115.                 return "No users found"
  116.             end
  117.         end
  118.     },
  119.     client = {
  120.         caspoof_id = 2,
  121.         spoof_user_id = function(sPort, uPort)
  122.             uPort = tonumber(uPort)
  123.             sPort = tonumber(sPort)
  124.            
  125.             local modem = peripheral.wrap(modem)
  126.             modem.open(uPort)
  127.  
  128.             local timer = os.startTimer(15)
  129.             while true do
  130.                 local event, data, port, reply, message = os.pullEvent()
  131.                
  132.                 if event == "modem_message"
  133.                 and port == uPort
  134.                 and reply == sPort
  135.                 and type(message) == "table"
  136.                 and type(message.message) == "table"
  137.                 and type(message.message.nUserID) == "number"
  138.                 then
  139.                     return message.message.nUserID
  140.                 elseif event == "timer" and data == timer then
  141.                     term.setTextColor(colors.red)
  142.                     return "User not found"
  143.                 end
  144.             end
  145.         end,
  146.         caget_port = 2,
  147.         get_port = function(sPort, uID)
  148.             sPort = tonumber(sPort)
  149.             uID = tonumber(uID)
  150.            
  151.             local modem = peripheral.wrap(modem)
  152.             modem.open(sPort)
  153.  
  154.             local timer = os.startTimer(15)
  155.             while true do
  156.                 local event, data, port, reply, message = os.pullEvent()
  157.                
  158.                 if event == "modem_message"
  159.                 and port == sPort
  160.                 and type(message) == "table"
  161.                 and type(message.message) == "table"
  162.                 and type(message.message.nUserID) == "number"
  163.                 and message.message.nUserID == uID
  164.                 then
  165.                     return reply
  166.                 elseif event == "timer" and data == timer then
  167.                     term.setTextColor(colors.red)
  168.                     return "Unable to get port"
  169.                 end
  170.             end
  171.         end,
  172.         caget_server_port = 1,
  173.         get_server_port = function(uPort)
  174.            
  175.         end,
  176.         caget_name = 3,
  177.         get_name = function(sPort, uPort, uID)
  178.             sPort = tonumber(sPort)
  179.             uPort = tonumber(uPort)
  180.             uID = tonumber(uID)
  181.            
  182.             local modem = peripheral.wrap(modem)
  183.             modem.open(uPort)
  184.             modem.open(sPort)
  185.            
  186.             modem.transmit(sPort, uPort,
  187.             {
  188.                 nRecipient = sPort,
  189.                 message = {
  190.                     sType = "chat",
  191.                     sText = "",
  192.                     nUserID = uID
  193.                 },
  194.                 nMessageID = math.random(1, 2147483647),
  195.                 sProtocol = "chat"
  196.             })
  197.            
  198.             local timer = os.startTimer(1)
  199.             while true do
  200.                 local event, data, port, reply, message = os.pullEvent()
  201.                
  202.                 if event == "modem_message"
  203.                 and port == uPort
  204.                 and type(message) == "table"
  205.                 and type(message.message) == "table"
  206.                 and type(message.message.sText) == "string"
  207.                 then
  208.                     return string.match(message.message.sText, "^<(.+)>")
  209.                 elseif event == "timer" and data == timer then
  210.                     term.setTextColor(colors.red)
  211.                     return "User not found"
  212.                 end
  213.             end
  214.         end,
  215.         caset_name = 4,
  216.         set_name = function(sPort, uPort, uID, uName)
  217.             sPort = tonumber(sPort)
  218.             uPort = tonumber(uPort)
  219.             uID = tonumber(uID)
  220.            
  221.             local modem = peripheral.wrap(modem)
  222.             modem.open(sPort)
  223.             modem.open(uPort)
  224.            
  225.             modem.transmit(sPort, uPort,
  226.             {
  227.                 nRecipient = sPort,
  228.                 message = {
  229.                     sType = "chat",
  230.                     sText = "/nick "..uName,
  231.                     nUserID = uID
  232.                 },
  233.                 nMessageID = math.random(1, 2147483647),
  234.                 sProtocol = "chat"
  235.             })
  236.            
  237.             os.startTimer(1)
  238.             while true do
  239.                 local event, data, port, reply, message = os.pullEvent()
  240.                
  241.                 if event == "modem_message"
  242.                 and port == uPort
  243.                 and type(message) == "table"
  244.                 and type(message.message) == "table"
  245.                 and type(message.message.sText) == "string"
  246.                 and string.match(message.message.sText, "^*.+is now known as.+$")
  247.                 then
  248.                     return "Successfully changed name to '"..uName.."'"
  249.                 elseif event == "timer" and data == timer then
  250.                     term.setTextColor(colors.red)
  251.                     return "Unable to change name"
  252.                 end
  253.             end
  254.         end,
  255.         cakick = 3,
  256.         kick = function(sPort, uPort, uID)
  257.             sPort = tonumber(sPort)
  258.             uPort = tonumber(uPort)
  259.             uID = tonumber(uID)
  260.            
  261.             local modem = peripheral.wrap(modem)
  262.             modem.open(sPort)
  263.            
  264.             modem.transmit(uPort, sPort,
  265.             {
  266.                 nRecipient = uPort,
  267.                 message = {
  268.                     sType = "kick",
  269.                     nUserID = uID
  270.                 },
  271.                 nMessageID = math.random(1, 2147483647),
  272.                 sProtocol = "chat"
  273.             })
  274.            
  275.             return "Kick was send"
  276.         end,
  277.         calogout = 3,
  278.         logout = function(sPort, uPort, uID)
  279.             sPort = tonumber(sPort)
  280.             uPort = tonumber(uPort)
  281.             uID = tonumber(uID)
  282.            
  283.             local modem = peripheral.wrap(modem)
  284.             modem.open(uPort)
  285.            
  286.             modem.transmit(sPort, uPort,
  287.             {
  288.                 nRecipient = sPort,
  289.                 message = {
  290.                     sType = "logout",
  291.                     nUserID = uID
  292.                 },
  293.                 nMessageID = math.random(1, 2147483647),
  294.                 sProtocol = "chat"
  295.             })
  296.            
  297.             return "Logout was send"
  298.         end,
  299.         capublic_write = 4,
  300.         public_write = function(sPort, uPort, uID, text)
  301.             sPort = tonumber(sPort)
  302.             uPort = tonumber(uPort)
  303.             uID = tonumber(uID)
  304.            
  305.             local modem = peripheral.wrap(modem)
  306.             modem.open(uPort)
  307.             modem.open(sPort)
  308.            
  309.             modem.transmit(sPort, uPort,
  310.             {
  311.                 nRecipient = sPort,
  312.                 message = {
  313.                     sType = "chat",
  314.                     sText = text,
  315.                     nUserID = uID
  316.                 },
  317.                 nMessageID = math.random(1, 2147483647),
  318.                 sProtocol = "chat"
  319.             })
  320.            
  321.             os.startTimer(1)
  322.             while true do
  323.                 local event, data, port, reply, message = os.pullEvent()
  324.                
  325.                 if event == "modem_message"
  326.                 and port == uPort
  327.                 and type(message) == "table"
  328.                 and type(message.message) == "table"
  329.                 and type(message.message.sText) == "string"
  330.                 and string.match(message.message.sText, ".+> "..text)
  331.                 then
  332.                     return "Successfully send message"
  333.                 elseif event == "timer" and data == timer then
  334.                     term.setTextColor(colors.red)
  335.                     return "Unable to send message"
  336.                 end
  337.             end
  338.         end,
  339.         caprivate_write = 4,
  340.         private_write = function(sPort, uPort, uID, text)
  341.             sPort = tonumber(sPort)
  342.             uPort = tonumber(uPort)
  343.             uID = tonumber(uID)
  344.            
  345.             local modem = peripheral.wrap(modem)
  346.             modem.open(sPort)
  347.            
  348.             modem.transmit(uPort, sPort,
  349.             {
  350.                 nRecipient = uPort,
  351.                 message = {
  352.                     sType = "text",
  353.                     sText = text,
  354.                     nUserID = uID
  355.                 },
  356.                 nMessageID = math.random(1, 2147483647),
  357.                 sProtocol = "chat"
  358.             })
  359.            
  360.             return "Message was send"
  361.         end,
  362.         causer_list = 4,
  363.         user_list = function(sPort, uPort, uID, uName)
  364.             sPort = tonumber(sPort)
  365.             uPort = tonumber(uPort)
  366.             uID = tonumber(uID)
  367.            
  368.             local modem = peripheral.wrap(modem)
  369.             modem.open(uPort)
  370.             modem.open(sPort)
  371.            
  372.             modem.transmit(sPort, uPort,
  373.             {
  374.                 nRecipient = sPort,
  375.                 message = {
  376.                     sType = "chat",
  377.                     sText = "/users",
  378.                     nUserID = uID
  379.                 },
  380.                 nMessageID = math.random(1, 2147483647),
  381.                 sProtocol = "chat"
  382.             })
  383.            
  384.             os.startTimer(1)
  385.             while true do
  386.                 local event, data, port, reply, message = os.pullEvent()
  387.                
  388.                 if event == "modem_message"
  389.                 and port == uPort
  390.                 and type(message) == "table"
  391.                 and type(message.message) == "table"
  392.                 and type(message.message.sText) == "string"
  393.                 and string.match(message.message.sText, "^\* .*"..uName..".*$")
  394.                 then
  395.                     return string.match(message.message.sText, "^\* (.*"..uName..".*)$")
  396.                 elseif event == "timer" and data == timer then
  397.                     term.setTextColor(colors.red)
  398.                     return "Unable to receive user list"
  399.                 end
  400.             end
  401.         end,
  402.     }
  403. }
  404.  
  405. if #tArgs == 2 and tArgs[2] == "load-lib" then
  406.     return command_list
  407. end
  408.  
  409. if #tArgs < 3 then
  410.     return printHelp()
  411. end
  412.  
  413. local device = tArgs[2]
  414. local command = tArgs[3]
  415.  
  416. local param = { }
  417. for i = 4, #tArgs do
  418.     table.insert(param, tArgs[i])
  419. end
  420.  
  421. if command_list[device]
  422. and command_list[device][command]
  423. and #tArgs - 3 == command_list[device]["ca"..command]
  424. then
  425.     term.setTextColor(colors.lime)
  426.     print( command_list[device][command](table.unpack( param )) )
  427. else
  428.     return printHelp()
  429. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement