Shadow19

Decoy Packet Editor (DPE)

Aug 17th, 2016
1,189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 30.14 KB | None | 0 0
  1. =begin
  2.     ==IMPORTANT (Update July 20th 2017)==
  3.     PLEASE WATCH THIS VIDEO IF YOU'RE SETTING UP
  4.     https://youtu.be/1JshIC6_6w4
  5.  
  6.     DO NOT USE THE STEPS BELOW IF YOU'RE USING HTTPS XAT, OTHERWISE GO AHEAD.
  7.     =====================================
  8.  
  9.     MAJOR NOTE: FIREFOX 51+ WILL NOT WORK WITH THIS ANYMORE!
  10.    
  11.     A packet editor focused on sending, receiving, reading or modifying packets
  12.     between you and Xat.
  13.  
  14.     Copyright (c) 2016 Daniel. S. (Majora) [ [email protected] ]
  15.  
  16.     Permission is hereby granted, free of charge, to any person
  17.     obtaining a copy of this software and associated documentation
  18.     files (the "Software"), to deal in the Software without
  19.     restriction, including without limitation the rights to use,
  20.     copy, modify, merge, publish, distribute, sublicense, and/or
  21.     sell copies of the Software, and to permit persons to whom
  22.     the Software is furnished to do so, subject to the following conditions:
  23.  
  24.     The above copyright notice and this permission notice shall be
  25.     included in all copies or substantial portions of the Software.
  26.  
  27.     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  28.     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  29.     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  30.     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  31.     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  32.     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  33.     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  34.     OTHER DEALINGS IN THE SOFTWARE.
  35.  
  36. =end
  37. #= Important Note =#
  38. =begin
  39.  
  40.     Before you run the program, you should set your PAC file
  41.     for your browser to be "https://shadow19.xyz/proxy",
  42.     if you do not know how to install a PAC file
  43.     goto http://findproxyforurl.com/deploying-pac/
  44.     and read under the "Browser Deployment"
  45.     section.
  46.    
  47.     Download the custom crossdomain.xml
  48.     http://pastebin.com/raw/1e7fDinF
  49.     or make you're own.
  50.     make sure the name of the file is "crossdomain.xml"
  51.     and is in the same folder as the program.
  52.    
  53.     Then you should go and install ruby on
  54.     your system, so you can run the program.
  55.    
  56.     Windows: http://rubyinstaller.org/downloads/
  57.     Mac, Unix, Linux: https://www.ruby-lang.org/en/documentation/installation/#package-management-systems
  58.    
  59.     PS: I'm not going to help anyone, so don't ask please, thank you.
  60.     If you don't understand this, then it is over your head.
  61.    
  62.     PS PS: If you want to use a custom swf for the chat,
  63.     use "https://shadow19.xyz/proxy?custom"
  64.     for your PAC options instead, then
  65.     paste your swf to the directory of
  66.     the program, make sure its name is
  67.     like "chatXXXd.swf", "chatXXX.swf" or just "chat.swf".
  68. =end
  69. #= End =#
  70. ["socket","eat","json","cgi","zlib"].each do |lib|
  71.     begin
  72.         require lib
  73.     rescue LoadError
  74.         system("gem install #{lib}")
  75.         Gem.clear_paths
  76.         retry
  77.     end
  78. end
  79.  
  80. #= Options =#
  81. $cache_iprules = true #Set to false temporarily if you get weird glitches on xat (likes friends list not being functional)
  82. $cache_static = true
  83. $logging = true
  84. $inchat_logging = false
  85. $super_chat = [true, "PRIVATE"]
  86. #= End =#
  87.  
  88. #= Catching the useless verbose =#
  89. class HTTPClient::SSLConfig
  90.     def warn(*a)
  91.         ""
  92.     end
  93. end
  94. class WebAgent::Cookie
  95.     def warn(*a)
  96.         ""
  97.     end
  98. end
  99. class NilClass
  100.     def split(*a)
  101.         ""
  102.     end
  103.     def length(*a)
  104.         0
  105.     end
  106. end
  107. #= End =#
  108. class String
  109.     def getAttr(attribute)
  110.         return self[/#{attribute}=\"(.*?)\"/,1]
  111.     end
  112.     def setAttr(attribute, value)
  113.         return self.gsub!(/#{attribute}=\"[^\"]*?\"/,"#{attribute}=\"#{value}\"")
  114.     end
  115.     def tag?(tagname)
  116.         return self[/<(.*?)[\s+|\/>]/,1] == tagname
  117.     end
  118.     def tag
  119.         return self[/<(.*?)[\s+|\/>]/,1]
  120.     end
  121. end
  122. def deepCopy(obj)
  123.     return Marshal.load(Marshal.dump(obj))
  124. end
  125. def csum(str)
  126.     str = str.to_s
  127.     return Zlib::crc32(str)
  128. end
  129. def windows?
  130.     return (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
  131. end
  132. def mac?
  133.     return (/darwin/ =~ RUBY_PLATFORM) != nil
  134. end
  135. def unix?
  136.     return !windows?
  137. end
  138. def linux?
  139.     return unix? if !mac?
  140. end
  141. def loadFilters(decoy=false)
  142.     Dir.mkdir("filters") unless File.directory?("filters")
  143.     path = File.expand_path(File.dirname(__FILE__))
  144.     if !decoy
  145.         Thread.main["filters"] = {}
  146.         Dir["#{path}/filters/*.rb"].each do |filter|
  147.             Thread.main["filters"][filter[filter.rindex("/")+1..-1]] = File.binread(filter)
  148.         end
  149.     elsif decoy.class == Thread
  150.         decoy["filters"] = {}
  151.         Dir["#{path}/filters/*.rb"].each do |filter|
  152.             decoy["filters"][filter[filter.rindex("/")+1..-1]] = File.binread(filter)
  153.         end
  154.     end
  155. end
  156. def filter(data, direction, decoy)
  157.     if direction == ">"
  158.         if data.getAttr("t")
  159.             command = data.getAttr("t").strip.split(" ")
  160.             command[0].delete!("^[a-zA-Z0-9\/]")
  161.             if decoy["done"]
  162.                 if command[0][0..1] == "//"
  163.                     command[0] = command[0][2..-1]
  164.                     if command[0] == "decoy" && command[1] == "die"
  165.                         exit()
  166.                     end
  167.                     if command[0] == "decoy" && command[1] == "unload" && command[2] != "all"
  168.                         decoy["filters"] = {}
  169.                         decoy["parent"]["filters"] = {} if decoy["parent"]
  170.                         decoy["child"]["filters"] = {} if decoy["child"]
  171.                         decoy["<"].print(
  172.                             packet(
  173.                                 {
  174.                                     "m"=>{
  175.                                         "t"=>"Filters have been unloaded.",
  176.                                         "u"=>"0"
  177.                                     }
  178.                                 }
  179.                             )
  180.                         )
  181.                         return false
  182.                     end
  183.                     if command[0] == "decoy" && command[1] == "unload" && command[2] == "all"
  184.                         Thread.main["filters"] = {}
  185.                         Thread.main["connected"].keys.each do |dec|
  186.                             dec = Thread.main["connected"][dec]
  187.                             if dec
  188.                                 dec[3]["filters"] = {}
  189.                                 dec[2]["filters"] = {}
  190.                             end
  191.                         end
  192.                         decoy["<"].print(
  193.                             packet(
  194.                                 {
  195.                                     "m"=>{
  196.                                         "t"=>"All filters have been unloaded.",
  197.                                         "u"=>"0"
  198.                                     }
  199.                                 }
  200.                             )
  201.                         )
  202.                         return false
  203.                     end
  204.                     if command[0] == "decoy" && command[1] == "reload" && command[2] != "all"
  205.                         loadFilters(decoy)
  206.                         loadFilters(decoy["parent"]) if decoy["parent"]
  207.                         loadFilters(decoy["child"]) if decoy["child"]
  208.                         decoy["<"].print(
  209.                             packet(
  210.                                 {
  211.                                     "m"=>{
  212.                                         "t"=>"Filters have been reloaded.",
  213.                                         "u"=>"0"
  214.                                     }
  215.                                 }
  216.                             )
  217.                         )
  218.                         return false
  219.                     end
  220.                     if command[0] == "decoy" && command[1] == "reload" && command[2] == "all"
  221.                         loadFilters(false)
  222.                         Thread.main["connected"].keys.each do |dec|
  223.                             dec = Thread.main["connected"][dec]
  224.                             if dec
  225.                                 loadFilters(dec[3])
  226.                                 loadFilters(dec[2])
  227.                             end
  228.                         end
  229.                         decoy["<"].print(
  230.                             packet(
  231.                                 {
  232.                                     "m"=>{
  233.                                         "t"=>"All filters have been reloaded.",
  234.                                         "u"=>"0"
  235.                                     }
  236.                                 }
  237.                             )
  238.                         )
  239.                         return false
  240.                     end
  241.                 end
  242.             end
  243.         end
  244.     end
  245.     backup_data = deepCopy(data)
  246.     decoy["filters"].keys.each do |file|
  247.         begin
  248.             eval(decoy["filters"][file])
  249.         rescue Exception
  250.             puts "Error occured in #{file}"
  251.             data = backup_data
  252.         end
  253.     end
  254.     return data
  255. end
  256. def packet(*object)
  257.     return object.collect{|object|"<#{object.keys[0].to_s.gsub(/\W/,"")} #{object[object.keys[0]].keys.collect{|attribute|"#{attribute.to_s.gsub(/\W/,"")}=\"#{object[object.keys[0]][attribute].to_s.gsub("\"","&quot;").gsub(">","\xCB\x83").gsub("<","&lt;")}\""}.join(" ")} />\x00"}.join
  258. end
  259. def getId(username)
  260.     if Thread.main["cache"]
  261.         return Thread.main["cache"]["grid#{username}"] if Thread.main["cache"]["grid#{username}"]
  262.     end
  263.     error = false
  264.     data = eat("http://xat.me/web_gear/chat/profile.php?name=#{username.delete("^[a-zA-Z0-9]")}") rescue error = true
  265.     return data != "" && !error ? (Thread.main["cache"]["grid#{username}"]=data) : (Thread.main["cache"]["grid#{username}"]=username)
  266. end
  267. def getUsername(id)
  268.     if Thread.main["cache"]
  269.         return Thread.main["cache"]["grun#{id}"] if Thread.main["cache"]["grun#{id}"]
  270.     end
  271.     error = false
  272.     data = eat("http://xat.me/web_gear/chat/profile.php?id=#{id.delete("^[0-9]")}") rescue error = true
  273.     return data != "" && !error ? (Thread.main["cache"]["grun#{id}"]=data) : (Thread.main["cache"]["grun#{id}"]=id)
  274. end
  275. def getRoomId(chatname)
  276.     if Thread.main["cache"]
  277.         return Thread.main["cache"]["gri#{chatname}"] if Thread.main["cache"]["gri#{chatname}"]
  278.     end
  279.     error = false
  280.     data = eat("http://xat.com/web_gear/chat/roomid.php?d=#{chatname.delete("^[a-zA-Z0-9_]")}") rescue error = true
  281.     return data != "-10-110" && !error ? (Thread.main["cache"]["gri#{chatname}"]=data) : (Thread.main["cache"]["gri#{chatname}"]=chatname) if Thread.main["cache"]
  282.     return data != "-10-110" && !error ? data : chatname
  283. end
  284. def getRoomName(id)
  285.     return Thread.main["cache"]["grn#{id}"] if Thread.main["cache"]["grn#{id}"] if Thread.main["cache"]
  286.     error = false
  287.     data = eat("http://xat.com/x?id=#{id.delete("^[0-9]")}")[/\<meta property=\"og:url\" content=\"(.*?)\" \/>/,1][/\/\/xat.com\/(.*)/,1] rescue error = true
  288.    return data != "" && !error ? (Thread.main["cache"]["grn#{id}"]=data) : (Thread.main["cache"]["grn#{id}"]=id) if Thread.main["cache"]
  289.     return data != "" && !error ? data : id
  290. end
  291. def iprules(startup)
  292.     if File.file?("ip2.txt") and File.file?("ip2.txt.expire") and $cache_iprules
  293.         if File.mtime("ip2.txt").to_i >= File.read("ip2.txt.expire").to_i
  294.             Thread.main["iprules_original"] = JSON.parse(eat("http://xat.com/web_gear/chat/ip2.php"))
  295.             Thread.main["iprules"] = deepCopy(Thread.main["iprules_original"])
  296.             Thread.main["iprules"]["E1"] = Thread.main["iprules"]["E0"] = [1,["127.0.0.1:456:1"]]
  297.             File.write("ip2.txt",JSON.pretty_generate(Thread.main["iprules_original"]))
  298.             File.write("ip2.txt.expire",(Time.now.to_i+300))
  299.         elsif startup
  300.             Thread.main["iprules_original"] = JSON.parse(File.read("ip2.txt"))
  301.             Thread.main["iprules"] = deepCopy(Thread.main["iprules_original"])
  302.             Thread.main["iprules"]["E1"] = Thread.main["iprules"]["E0"] = [1,["127.0.0.1:456:1"]]
  303.         end
  304.     end
  305.     if startup
  306.         if !File.file?("ip2.txt") or !File.file?("ip2.txt.expire") or !$cache_iprules
  307.             Thread.main["iprules_original"] = JSON.parse(eat("http://xat.com/web_gear/chat/ip2.php"))
  308.             Thread.main["iprules"] = deepCopy(Thread.main["iprules_original"])
  309.             Thread.main["iprules"]["E1"] = Thread.main["iprules"]["E0"] = [1,["127.0.0.1:456:1"]]
  310.             File.write("ip2.txt",JSON.pretty_generate(Thread.main["iprules_original"])) if $cache_iprules
  311.             File.write("ip2.txt.expire",(Time.now.to_i+300)) if $cache_iprules
  312.         end
  313.     end
  314.     Thread.main["attempt"] = 0
  315.     Thread.main["prevrpool"] = -1
  316. end
  317. def xhttp(d, e=1800, t="text/html")
  318.     return %{HTTP/1.1 200 OK\r\nDate: #{Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S GMT")}\r\nContent-Type: #{t}\r\nContent-Length: #{d.length}\r\nConnection: keep-alive\r\nCache-Control: max-age=#{e}\r\nServer: cloudflare-nginx\r\n\r\n}.lstrip + d
  319. end
  320. def connected?()
  321.     return (!!`ping #{windows? ? "-n" : "-c"} 1 8.8.8.8`[/ttl/i]) rescue false
  322. end
  323. def connect(host, port, timeout=false)
  324.     addr = Socket.getaddrinfo(host, nil)
  325.     sock = Socket.new(Socket.const_get(addr[0][0]),Socket::SOCK_STREAM,0)
  326.     if timeout
  327.         secs = timeout.to_i
  328.         usecs = ((timeout-secs)*1000000).to_i
  329.         timeout = [secs,usecs].pack("l_2")
  330.         sock.setsockopt(Socket::SOL_SOCKET,Socket::SO_RCVTIMEO,timeout)
  331.         sock.setsockopt(Socket::SOL_SOCKET,Socket::SO_SNDTIMEO,timeout)
  332.     end
  333.     sock.connect(Socket.pack_sockaddr_in(port, addr[0][3]))
  334.     return sock
  335. end
  336. #= Ported from network.as =#
  337. def xdom(room) #roomid
  338.     return rand(0..3) if Thread.main["iprules"]["xFlag"] & 8 == 8
  339.     return 0 if room.to_i == 8
  340.     return room.to_i < 8 ? 3 : (room.to_i & 96) >> 5
  341. end
  342. def xport(room) #roomid
  343.     return 10007 + rand(0..31) if Thread.main["iprules"]["xFlag"] & 8 == 8
  344.     return 10000 if room.to_i == 8
  345.     return room.to_i < 8 ? 9999 + room.to_i : 10007 + room.to_i % 32
  346. end
  347. def xroom(roomname) #roomname, returns roomid
  348.     return eat("http://xat.com/web_gear/chat/roomid.php?d=#{roomname.downcase.gsub(/[^\w_]/,"")}")
  349. end
  350. def pickip(room) #roomid, returns ip, port, timeout
  351.     Thread.main["attempt"] = Thread.main["attempt"] % 4
  352.     Thread.main["attempt"] += 1
  353.     a = b = c = d = f = g = h = nil
  354.     h = Thread.main["iprules_original"]["order"][Thread.main["attempt"]][0]
  355.     i = Thread.main["iprules_original"][h]
  356.     j = Thread.main["iprules_original"]["order"][Thread.main["attempt"]][1]
  357.     if i[0] & 1 == 1
  358.         a = 0
  359.         if Thread.main["prevrpool"] == -1
  360.             a = rand(1..(i.length-1))
  361.         else
  362.             a = ((a % (i.length - 1)) + 1)
  363.         end
  364.         b = rand(0..(i[a].length-1))
  365.         c = i[a][b].split(":")
  366.         c[1] = 10000 if !c[1]
  367.         c[2] = 39 if !c[2]
  368.         d = c[1].to_i + rand(0..c[2].to_i-1)
  369.         Thread.main["prevrpool"] = a
  370.         a = b = c[1] = c[2] = f = g = h = i = nil
  371.         return [c[0],d,j]
  372.     end
  373.     e = xdom(room)
  374.     f = xport(room)
  375.     g = i[1][rand((4 * e)..3)]
  376.     a = b = c = d = h = i = nil
  377.     return [g,f,j]
  378. end
  379. #= End =#
  380.  
  381. #= Globals =#
  382. Thread.main["cdp"] = File.binread("crossdomain.xml")
  383. Thread.main["connected"] = {}
  384. Thread.main["logging"] = $logging
  385. Thread.main["icl"] = $inchat_logging
  386. Thread.main["cache"] = {} if $cache_static
  387. Thread.main["filters"] = {}
  388. Thread.main["active_chat"] = ($super_chat.class == Array ? $super_chat[0] : $super_chat) ? "" : false
  389. Thread.main["super_chat_mode"] = $super_chat.class == Array ? ($super_chat[1].strip.downcase == "private" ? 1 : $super_chat[1].strip.downcase == "main" ? 2 : $super_chat[1].strip.downcase == "both" ? 3 : 0) : 3
  390. #= End =#
  391.  
  392. #Initialize
  393. if windows?
  394.     system("title Decoy Packet Editor")
  395.     system("cls")
  396. elsif mac?
  397.     system("echo -n -e \"\033]0;Decoy Packet Editor\007\"")
  398.     system("clear")
  399. elsif unix? or linux?
  400.     system("PS1=$; unset PROMPT_COMMAND")
  401.     system("echo -ne \"\033]0;Decoy Packet Editor\007\"")
  402.     system("clear")
  403. end
  404. iprules(true)
  405. loadFilters(false)
  406. begin
  407.     Thread.main["middle"] = TCPServer.new("127.0.0.1",456)
  408. rescue Exception
  409.     puts "Error occured in creating the local server,"
  410.     puts "please make sure decoy is not running already"
  411.     puts "or check if the port \"456\" is being used"
  412.     puts "by another program, or if your network"
  413.     puts "is working properly."
  414.     sleep(3)
  415.     exit()
  416. end
  417. puts "Decoy Packet Editor is now ready!"
  418.  
  419. Thread.new do
  420.     loop do
  421.         Thread.start(Thread.main["middle"].accept) do |client| #parent
  422.             Thread.current["<"] = client
  423.             Thread.current["done"] = false
  424.             Thread.current["afix"] = nil
  425.             Thread.current["ping"] = Time.now.to_i
  426.             loadFilters(Thread.current)
  427.             while data = Thread.current["<"].recv(16384)
  428.                 if !data or data == ""
  429.                     print(Thread.current["roomname"] ? "Disconnected from #{Thread.current["roomname"]}.\n" : "")
  430.                     Thread.current["afix"] = nil
  431.                     Thread.current["<"].close rescue break
  432.                     Thread.current[">"].close rescue break
  433.                     break
  434.                 end
  435.                 if data[0] != "<" or data[-3..-1] != "/>\x00"
  436.                     Thread.current["afix"] = nil
  437.                     Thread.current["<"].close rescue break
  438.                     Thread.current[">"].close rescue break
  439.                     break
  440.                 end
  441.                 #Sorting the packets individually
  442.                 data.split(/(?<=\x00)/).each do |data|
  443.                     #Send crafted crossdomain policy.
  444.                     if data.tag?("policy-file-request")
  445.                         puts "[<] #{data}".inspect[1..-2] if Thread.main["logging"]
  446.                         Thread.current["<"].print "#{Thread.main["cdp"]}\x00"
  447.                     #Check for y initialization packet
  448.                     elsif data.tag?("y") and data.getAttr("r")
  449.                         #Check if connection is hanging after y initialization
  450.                         Thread.current["_y"] = Thread.new(Thread.current){|y| sleep(1.5); y["<"].close; y[">"].close}
  451.                         #Identifying what chat the thread is on.
  452.                         Thread.current["uid"] = data.getAttr("u")
  453.                         Thread.current["room"] = data.getAttr("r")
  454.                         Thread.main["active_chat"] = data.getAttr("r") if Thread.main["active_chat"]
  455.                         Thread.current["roomname"] = getRoomName(data.getAttr("r"))
  456.                         puts "[#{Thread.current["roomname"]}][>] #{data}".inspect[1..-2] if Thread.main["logging"]
  457.                         #Kill old duplicate connections/threads
  458.                         if Thread.main["connected"][data.getAttr("r")]
  459.                             Thread.main["connected"][data.getAttr("r")][0].close rescue puts("INPUT SOCKET FAILED TO CLOSE")
  460.                             Thread.main["connected"][data.getAttr("r")][1].close rescue puts("OUTPUT SOCKET FAILED TO CLOSE")
  461.                             Thread.main["connected"][data.getAttr("r")][2].kill rescue puts("OLD INPUT DUPLICATE THREAD FAILED TO DIE")
  462.                             Thread.main["connected"][data.getAttr("r")][3].kill rescue puts("OLD OUTPUT DUPLICATE THREAD FAILED TO DIE")
  463.                             Thread.main["connected"].delete(data.getAttr("r"))
  464.                         end
  465.                         info = pickip(data.getAttr("r"))
  466.                         #Choose IP like client does it
  467.                         Thread.current[">"] = connect(info[0], xport(data.getAttr("r")), info[2])
  468.                         Thread.current[">"].print data
  469.                         Thread.current["child"] = Thread.new do
  470.                             loadFilters(Thread.current)
  471.                             Thread.current["BUFFER"] = ""
  472.                             Thread.current[">"] = Thread.current["parent"][">"]
  473.                             Thread.current["<"] = Thread.current["parent"]["<"]
  474.                             Thread.current["uid"] = Thread.current["parent"]["uid"]
  475.                             Thread.current["room"] = Thread.current["parent"]["room"]
  476.                             Thread.current["roomname"] = Thread.current["parent"]["roomname"]
  477.                             begin
  478.                                 while data = Thread.current[">"].recv(16384) and !Thread.current[">"].closed?
  479.                                     #Connection isn't hanging, so we kill the hang check
  480.                                     Thread.current["parent"]["_y"].kill
  481.                                     if !data or data == ""
  482.                                         Thread.current["parent"]["afix"] = nil
  483.                                         Thread.current[">"].close rescue break
  484.                                         break
  485.                                     end
  486.                                     #Buffer partitioned data
  487.                                     if data[-3..-1] != "/>\x00"
  488.                                         Thread.current["BUFFER"] += data
  489.                                         next
  490.                                     elsif Thread.current["BUFFER"] != ""
  491.                                         Thread.current["BUFFER"] += data
  492.                                         data = Thread.current["BUFFER"]
  493.                                         Thread.current["BUFFER"] = ""
  494.                                     end
  495.                                     #Check for valid xml
  496.                                     if data[0] != "<" or data[-3..-1] != "/>\x00"
  497.                                         Thread.current["parent"]["afix"] = nil
  498.                                         Thread.current[">"].close rescue break
  499.                                         break
  500.                                     end
  501.                                     #Sorting the packets individually
  502.                                     data.split(/(?<=\x00)/).each do |data|
  503.                                         if data.tag?("done")
  504.                                             Thread.current["done"] = Thread.current["parent"]["done"] = true
  505.                                             Thread.current["<"].print(
  506.                                                 packet(
  507.                                                     {
  508.                                                         "m"=>{
  509.                                                             "t"=>"Decoy Packet Editor is running!",
  510.                                                             "u"=>"0"
  511.                                                         }
  512.                                                     }
  513.                                                 )
  514.                                             )
  515.                                         end
  516.                                         # Super Chat
  517.                                         if Thread.main["active_chat"] and Thread.current["done"] and ["m","p"].index(data.tag) and data.getAttr("t")
  518.                                             if (Thread.main["super_chat_mode"] == 1 and data.tag?("p")) or (Thread.main["super_chat_mode"] == 2 and data.tag?("m")) or (Thread.main["super_chat_mode"] == 3 and ["m","p"].index(data.tag))
  519.                                                 if !["/"].index(data.getAttr("t")[0]) and Thread.current["room"] != Thread.main["active_chat"]
  520.                                                     begin
  521.                                                         Thread.main["connected"][Thread.main["active_chat"]][0].print(
  522.                                                             packet(
  523.                                                                 {
  524.                                                                     "m"=>{
  525.                                                                         "t"=>"[#{Thread.current["roomname"]}]#{["z","p"].index(data.tag) ? "[Private]" : ""}[#{getUsername(data.getAttr("u")[/(.+)[_]/,1]||data.getAttr("u"))}] #{data.getAttr("t")}",
  526.                                                                         "u"=>Thread.current["uid"],
  527.                                                                         "i"=>"0"
  528.                                                                     }
  529.                                                                 }
  530.                                                             )
  531.                                                         )
  532.                                                     rescue Exception
  533.                                                     end
  534.                                                 end
  535.                                             end
  536.                                         end
  537.                                         # ~ Super Chat End
  538.                                         if Thread.current["done"] and Thread.main["icl"]
  539.                                             begin
  540.                                                 Thread.current["<"].print(
  541.                                                     packet(
  542.                                                         {
  543.                                                             "z"=>{
  544.                                                                 "t"=>"[<] #{data.gsub("#"," _# ").gsub("\""," &quot; ").inspect[1..-6]}",
  545.                                                                 "u"=>Thread.current["uid"],
  546.                                                                 "d"=>Thread.current["uid"],
  547.                                                                 "s"=>"2"
  548.                                                             }
  549.                                                         }
  550.                                                     )
  551.                                                 )
  552.                                             rescue Exception
  553.                                             end
  554.                                         end
  555.                                         data = filter(data,"<",Thread.current)
  556.                                         next if data == false
  557.                                         puts "[#{Thread.current["roomname"]}][<] #{data}".inspect[1..-2] if Thread.main["logging"] #Input
  558.                                         Thread.current["<"].print data#From middle
  559.                                     end
  560.                                 end
  561.                             rescue
  562.                                 Thread.current["<"].close rescue puts("INPUT SOCKET FAILED TO CLOSE")
  563.                                 Thread.current[">"].close rescue puts("OUTPUT SOCKET FAILED TO CLOSE")
  564.                                 Thread.current["parent"].kill rescue puts("OLD OUTPUT DUPLICATE THREAD FAILED TO DIE")
  565.                                 Thread.current.kill rescue puts("OLD INPUT DUPLICATE THREAD FAILED TO DIE")
  566.                             end
  567.                         end#Child
  568.                         Thread.current["child"]["parent"] = Thread.current
  569.                         Thread.main["connected"][data.getAttr("r")] = [Thread.current["<"],Thread.current[">"],Thread.current["child"],Thread.current]
  570.                     else#Master tag check
  571.                         # Super Chat Check
  572.                         if ["f","z","m","p","c"].index(data.tag) and Thread.main["active_chat"]
  573.                             if data.getAttr("t")
  574.                                 if !data.getAttr("t")["/KD"] and !data.getAttr("t")["/KEEPALIVE"] and !data.getAttr("t")["/away"] and !data.getAttr("t")["/a"]
  575.                                     Thread.main["active_chat"] = Thread.current["room"]
  576.                                 end
  577.                             else
  578.                                 Thread.main["active_chat"] = Thread.current["room"]
  579.                             end
  580.                         end
  581.                         # ~ Super Chat Check End
  582.                         next if Thread.current["afix"] == data and !data.tag?("f")
  583.                         Thread.current["afix"] = data
  584.                         if Thread.current["done"] and Thread.main["icl"]
  585.                             begin
  586.                                 Thread.current["<"].print(
  587.                                     packet(
  588.                                         {
  589.                                             "z"=>{
  590.                                                 "t"=>"[>] #{data.gsub("#"," _# ").gsub("\""," &quot; ").inspect[1..-6]}",
  591.                                                 "u"=>Thread.current["uid"],
  592.                                                 "d"=>Thread.current["uid"],
  593.                                                 "s"=>"2"
  594.                                             }
  595.                                         }
  596.                                     )
  597.                                 )
  598.                             rescue Exception
  599.                             end
  600.                         end
  601.                         data = filter(data,">",Thread.current)
  602.                         next if data == false
  603.                         puts "[#{Thread.current["roomname"]}][>] #{data}".inspect[1..-2] if Thread.main["logging"] #Output
  604.                         Thread.current[">"].print data #To middle
  605.                     end
  606.                 end#Sorting packets
  607.             end#Socket data collection
  608.         end#Accepting Thread
  609.     end#Loop
  610. end#Thread
  611.  
  612. #local-only webserver to serve crafted GET responses
  613. #Note: Can also do other requests if you want to.
  614. Thread.main["proxy"]  = TCPServer.open("localhost",1000)
  615.  
  616. loop do
  617.   client = Thread.main["proxy"].accept
  618.   data = client.recv(4096)
  619.   #Scan for valid GET
  620.   get = data[/GET\s*(.*?)\s*HTTP\/1.(0\r\n|1\r\n|0\n|1\n)/,1]
  621.   if get
  622.     if get[/ip2.php$/]
  623.         iprules(false)
  624.         client.puts xhttp(JSON.generate(Thread.main["iprules"]),1800,"text/html")
  625.     elsif get[/chat.*swf\?.*$/]
  626.         swfn = Dir["cha*.swf"][0]
  627.         if swfn
  628.             swf = File.binread(swfn)
  629.             client.puts(xhttp(swf,180,"application/x-shockwave-flash"))
  630.         else
  631.             swf = eat(get.gsub(/chat([0-9]{3}).swf/,"chat\\1d.swf"))
  632.             File.binwrite("chat.swf",swf)
  633.             client.puts(xhttp(swf,180,"application/x-shockwave-flash"))
  634.         end
  635.     end
  636.   end
  637.   client.close
  638. end
Advertisement
Add Comment
Please, Sign In to add comment