From 34c95557176dffe5b7843ec9aeb8c9562e570395 Mon Sep 17 00:00:00 2001 From: Pedro Ribeiro Date: Tue, 18 Dec 2018 15:37:47 +0000 Subject: [PATCH] Fix byte_xori encoder The byte_xori encoder for mipsbe does not work correctly. At the end of the decoding, it should invoke cacheflush() with the correct parameters: int cacheflush(char *addr, int nbytes, int cache) I think this is because the encoder is based of the longxori encoder, which itself is pretty old (2008), and before kernel 2.6.11, cacheflush() did not need any parameters (from the cacheflush man page): BUGS Linux kernels older than version 2.6.11 ignore the addr and nbytes arguments, making this function fairly expensive. Therefore, the whole cache is always flushed. This commit fixes that by setting up the parameters correctly. As an unfortunate side effect this increases the shellcode by 16 bytes, but it is absolutely necessary for it to work properly. Note that this bug is not present when testing the encoder output on an emulator like qemu; emulators do not need to flush the caches to work properly. --- modules/encoders/mipsbe/byte_xori.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/encoders/mipsbe/byte_xori.rb b/modules/encoders/mipsbe/byte_xori.rb index ce56c69af2..9bf4a43f12 100644 --- a/modules/encoders/mipsbe/byte_xori.rb +++ b/modules/encoders/mipsbe/byte_xori.rb @@ -18,8 +18,9 @@ class MetasploitModule < Msf::Encoder::Xor }, 'Author' => [ - 'Julien Tinnes ', # original longxor encoder, which this one is based on - 'juan vazquez' # byte_xori encoder + 'Julien Tinnes ', # original longxor encoder, which this one is based on + 'juan vazquez', # byte_xori encoder + 'Pedro Ribeiro ', # fix for Linux >= 2.6.11 (set up cacheflush() args properly) ], 'Arch' => ARCH_MIPSBE, 'License' => MSF_LICENSE, @@ -44,6 +45,7 @@ class MetasploitModule < Msf::Encoder::Xor # 16-bits not (again, see also commented source) reg_14 = (number_of_passes+1)^0xFFFF + reg_5 = state.buf.length^0xFFFF decoder = Metasm::Shellcode.assemble(Metasm::MIPS.new(:big), <