Files
metasploit-gs/api/Msf/Util/DotNetDeserialization.html
T
jenkins-metasploit c3f5bd3de2 Reboot gh-pages
2026-05-08 17:08:43 +00:00

878 lines
39 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Module: Msf::Util::DotNetDeserialization
&mdash; Documentation by YARD 0.9.37
</title>
<link rel="stylesheet" href="../../css/style.css" type="text/css" />
<link rel="stylesheet" href="../../css/common.css" type="text/css" />
<script type="text/javascript">
pathId = "Msf::Util::DotNetDeserialization";
relpath = '../../';
</script>
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="../../class_list.html?1"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="../../_index.html">Index (D)</a> &raquo;
<span class='title'><span class='object_link'><a href="../../Msf.html" title="Msf (module)">Msf</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Util.html" title="Msf::Util (module)">Util</a></span></span>
&raquo;
<span class="title">DotNetDeserialization</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../../class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<div id="content"><h1>Module: Msf::Util::DotNetDeserialization
</h1>
<div class="box_info">
<dl>
<dt>Defined in:</dt>
<dd>lib/msf/util/dot_net_deserialization.rb<span class="defines">,<br />
lib/msf/util/dot_net_deserialization/enums.rb,<br /> lib/msf/util/dot_net_deserialization/types.rb,<br /> lib/msf/util/dot_net_deserialization/assemblies.rb,<br /> lib/msf/util/dot_net_deserialization/formatters.rb,<br /> lib/msf/util/dot_net_deserialization/gadget_chains.rb,<br /> lib/msf/util/dot_net_deserialization/types/general.rb,<br /> lib/msf/util/dot_net_deserialization/types/primitives.rb,<br /> lib/msf/util/dot_net_deserialization/types/record_values.rb,<br /> lib/msf/util/dot_net_deserialization/gadget_chains/data_set.rb,<br /> lib/msf/util/dot_net_deserialization/types/common_structures.rb,<br /> lib/msf/util/dot_net_deserialization/formatters/los_formatter.rb,<br /> lib/msf/util/dot_net_deserialization/formatters/soap_formatter.rb,<br /> lib/msf/util/dot_net_deserialization/formatters/binary_formatter.rb,<br /> lib/msf/util/dot_net_deserialization/formatters/json_net_formatter.rb,<br /> lib/msf/util/dot_net_deserialization/gadget_chains/claims_principal.rb,<br /> lib/msf/util/dot_net_deserialization/gadget_chains/windows_identity.rb,<br /> lib/msf/util/dot_net_deserialization/gadget_chains/data_set_type_spoof.rb,<br /> lib/msf/util/dot_net_deserialization/gadget_chains/object_data_provider.rb,<br /> lib/msf/util/dot_net_deserialization/gadget_chains/type_confuse_delegate.rb,<br /> lib/msf/util/dot_net_deserialization/gadget_chains/text_formatting_run_properties.rb</span>
</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>Much of this code is based on the YSoSerial.Net project see: <a href="https://github.com/pwntester/ysoserial.net">github.com/pwntester/ysoserial.net</a></p>
</div>
</div>
<div class="tags">
</div><h2>Defined Under Namespace</h2>
<p class="children">
<strong class="modules">Modules:</strong> <span class='object_link'><a href="DotNetDeserialization/Assemblies.html" title="Msf::Util::DotNetDeserialization::Assemblies (module)">Assemblies</a></span>, <span class='object_link'><a href="DotNetDeserialization/Enums.html" title="Msf::Util::DotNetDeserialization::Enums (module)">Enums</a></span>, <span class='object_link'><a href="DotNetDeserialization/Formatters.html" title="Msf::Util::DotNetDeserialization::Formatters (module)">Formatters</a></span>, <span class='object_link'><a href="DotNetDeserialization/GadgetChains.html" title="Msf::Util::DotNetDeserialization::GadgetChains (module)">GadgetChains</a></span>, <span class='object_link'><a href="DotNetDeserialization/Types.html" title="Msf::Util::DotNetDeserialization::Types (module)">Types</a></span>
</p>
<h2>
Constant Summary
<small><a href="#" class="constants_summary_toggle">collapse</a></small>
</h2>
<dl class="constants">
<dt id="DEFAULT_FORMATTER-constant" class="">DEFAULT_FORMATTER =
</dt>
<dd><pre class="code"><span class='symbol'>:BinaryFormatter</span></pre></dd>
<dt id="DEFAULT_GADGET_CHAIN-constant" class="">DEFAULT_GADGET_CHAIN =
</dt>
<dd><pre class="code"><span class='symbol'>:TextFormattingRunProperties</span></pre></dd>
</dl>
<h2>
Class Method Summary
<small><a href="#" class="summary_toggle">collapse</a></small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#encode_7bit_int-class_method" title="encode_7bit_int (class method)">.<strong>encode_7bit_int</strong>(int) &#x21d2; Object </a>
</span>
<span class="summary_desc"><div class='inline'></div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#formatter_compatible_gadget_chains-class_method" title="formatter_compatible_gadget_chains (class method)">.<strong>formatter_compatible_gadget_chains</strong>(formatter) &#x21d2; Array&lt;Symbol&gt; </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Get a list of gadget chains that are compatible with the specified formatter.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#generate-class_method" title="generate (class method)">.<strong>generate</strong>(cmd, gadget_chain: DEFAULT_GADGET_CHAIN, formatter: DEFAULT_FORMATTER) &#x21d2; String </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Generates a .NET deserialization payload for the specified OS command using a selected gadget-chain and formatter combination.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#generate_formatted-class_method" title="generate_formatted (class method)">.<strong>generate_formatted</strong>(stream, formatter: DEFAULT_FORMATTER) &#x21d2; String </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Take the specified serialized blob and encapsulate it with the specified formatter.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#generate_gadget_chain-class_method" title="generate_gadget_chain (class method)">.<strong>generate_gadget_chain</strong>(cmd, gadget_chain: DEFAULT_GADGET_CHAIN) &#x21d2; Types::SerializedStream </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Generate a serialized data blob using the specified gadget chain to execute the OS command.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#get_ancestor-class_method" title="get_ancestor (class method)">.<strong>get_ancestor</strong>(obj, ancestor_type, required: true) &#x21d2; Object </a>
</span>
<span class="summary_desc"><div class='inline'></div></span>
</li>
</ul>
<div id="class_method_details" class="method_details_list">
<h2>Class Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="encode_7bit_int-class_method">
.<strong>encode_7bit_int</strong>(int) &#x21d2; <tt>Object</tt>
</h3><table class="source_code">
<tr>
<td>
<pre class="lines">
14
15
16
17
18
19
20
21
22
23
24
25
26
27</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/msf/util/dot_net_deserialization.rb', line 14</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_encode_7bit_int'>encode_7bit_int</span><span class='lparen'>(</span><span class='id identifier rubyid_int'>int</span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\x00</span><span class='tstring_end'>&quot;</span></span><span class='period'>.</span><span class='id identifier rubyid_b'>b</span> <span class='kw'>if</span> <span class='id identifier rubyid_int'>int</span> <span class='op'>==</span> <span class='int'>0</span>
<span class='comment'># see: https://github.com/microsoft/referencesource/blob/3b1eaf5203992df69de44c783a3eda37d3d4cd10/mscorlib/system/io/binaryreader.cs#L582
</span> <span class='id identifier rubyid_encoded_int'>encoded_int</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
<span class='kw'>while</span> <span class='id identifier rubyid_int'>int</span> <span class='op'>&gt;</span> <span class='int'>0</span>
<span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_int'>int</span> <span class='op'>&amp;</span> <span class='int'>0x7f</span>
<span class='id identifier rubyid_int'>int</span> <span class='op'>&gt;&gt;=</span> <span class='int'>7</span>
<span class='id identifier rubyid_value'>value</span> <span class='op'>|=</span> <span class='int'>0x80</span> <span class='kw'>if</span> <span class='id identifier rubyid_int'>int</span> <span class='op'>&gt;</span> <span class='int'>0</span>
<span class='id identifier rubyid_encoded_int'>encoded_int</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_value'>value</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_encoded_int'>encoded_int</span><span class='period'>.</span><span class='id identifier rubyid_pack'>pack</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>C*</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="formatter_compatible_gadget_chains-class_method">
.<strong>formatter_compatible_gadget_chains</strong>(formatter) &#x21d2; <tt>Array&lt;Symbol&gt;</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Get a list of gadget chains that are compatible with the specified formatter.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>formatter</span>
<span class='type'>(<tt>Symbol</tt>)</span>
&mdash;
<div class='inline'>
<p>The formatter to get gadget chains for.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Array&lt;Symbol&gt;</tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
87
88
89
90
91
92
93
94
95
96
97
98
99
100</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/msf/util/dot_net_deserialization.rb', line 87</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_formatter_compatible_gadget_chains'>formatter_compatible_gadget_chains</span><span class='lparen'>(</span><span class='id identifier rubyid_formatter'>formatter</span><span class='rparen'>)</span>
<span class='kw'>case</span> <span class='id identifier rubyid_formatter'>formatter</span>
<span class='kw'>when</span> <span class='symbol'>:BinaryFormatter</span><span class='comma'>,</span> <span class='symbol'>:LosFormatter</span>
<span class='id identifier rubyid_chains'>chains</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains.html" title="Msf::Util::DotNetDeserialization::GadgetChains (module)">GadgetChains</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains.html#NAMES-constant" title="Msf::Util::DotNetDeserialization::GadgetChains::NAMES (constant)">NAMES</a></span></span><span class='period'>.</span><span class='id identifier rubyid_select'>select</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_name'>name</span><span class='op'>|</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains.html" title="Msf::Util::DotNetDeserialization::GadgetChains (module)">GadgetChains</a></span></span><span class='period'>.</span><span class='id identifier rubyid_const_get'>const_get</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span> <span class='op'>&lt;=</span> <span class='lparen'>(</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/Types.html" title="Msf::Util::DotNetDeserialization::Types (module)">Types</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/Types/SerializedStream.html" title="Msf::Util::DotNetDeserialization::Types::SerializedStream (class)">SerializedStream</a></span></span><span class='rparen'>)</span> <span class='rbrace'>}</span>
<span class='kw'>when</span> <span class='symbol'>:JsonNetFormatter</span>
<span class='id identifier rubyid_chains'>chains</span> <span class='op'>=</span> <span class='qsymbols_beg'>%i[</span><span class='words_sep'> </span><span class='tstring_content'>ObjectDataProvider</span><span class='words_sep'> </span><span class='tstring_end'>]</span></span>
<span class='kw'>when</span> <span class='symbol'>:SoapFormatter</span>
<span class='id identifier rubyid_chains'>chains</span> <span class='op'>=</span> <span class='qsymbols_beg'>%i[</span><span class='words_sep'> </span><span class='tstring_content'>ClaimsPrincipal</span><span class='words_sep'> </span><span class='tstring_content'>TextFormattingRunProperties</span><span class='words_sep'> </span><span class='tstring_content'>WindowsIdentity</span><span class='words_sep'> </span><span class='tstring_end'>]</span></span>
<span class='kw'>else</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>NotImplementedError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>The specified formatter is not implemented</span><span class='tstring_end'>&#39;</span></span>
<span class='kw'>end</span>
<span class='id identifier rubyid_chains'>chains</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="generate-class_method">
.<strong>generate</strong>(cmd, gadget_chain: DEFAULT_GADGET_CHAIN, formatter: DEFAULT_FORMATTER) &#x21d2; <tt>String</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Generates a .NET deserialization payload for the specified OS command using a selected gadget-chain and formatter combination.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>cmd</span>
<span class='type'>(<tt>String</tt>)</span>
&mdash;
<div class='inline'>
<p>The OS command to execute.</p>
</div>
</li>
<li>
<span class='name'>gadget_chain</span>
<span class='type'>(<tt>Symbol</tt>)</span>
<em class="default">(defaults to: <tt>DEFAULT_GADGET_CHAIN</tt>)</em>
&mdash;
<div class='inline'>
<p>The gadget chain to use for execution. This will be application specific.</p>
</div>
</li>
<li>
<span class='name'>formatter</span>
<span class='type'>(<tt>Symbol</tt>)</span>
<em class="default">(defaults to: <tt>DEFAULT_FORMATTER</tt>)</em>
&mdash;
<div class='inline'>
<p>An optional formatter to use to encapsulate the gadget chain.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String</tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
52
53
54
55</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/msf/util/dot_net_deserialization.rb', line 52</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_generate'>generate</span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='comma'>,</span> <span class='label'>gadget_chain:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_GADGET_CHAIN-constant" title="Msf::Util::DotNetDeserialization::DEFAULT_GADGET_CHAIN (constant)">DEFAULT_GADGET_CHAIN</a></span></span><span class='comma'>,</span> <span class='label'>formatter:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_FORMATTER-constant" title="Msf::Util::DotNetDeserialization::DEFAULT_FORMATTER (constant)">DEFAULT_FORMATTER</a></span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_stream'>stream</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_generate_gadget_chain'>generate_gadget_chain</span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='comma'>,</span> <span class='label'>gadget_chain:</span> <span class='id identifier rubyid_gadget_chain'>gadget_chain</span><span class='rparen'>)</span>
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_generate_formatted'>generate_formatted</span><span class='lparen'>(</span><span class='id identifier rubyid_stream'>stream</span><span class='comma'>,</span> <span class='label'>formatter:</span> <span class='id identifier rubyid_formatter'>formatter</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="generate_formatted-class_method">
.<strong>generate_formatted</strong>(stream, formatter: DEFAULT_FORMATTER) &#x21d2; <tt>String</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Take the specified serialized blob and encapsulate it with the specified formatter.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>stream</span>
<span class='type'>(<tt><span class='object_link'><a href="DotNetDeserialization/Types/SerializedStream.html" title="Msf::Util::DotNetDeserialization::Types::SerializedStream (class)">Msf::Util::DotNetDeserialization::Types::SerializedStream</a></span></tt>)</span>
&mdash;
<div class='inline'>
<p>The serialized stream representing the gadget chain to format into a string.</p>
</div>
</li>
<li>
<span class='name'>formatter</span>
<span class='type'>(<tt>Symbol</tt>)</span>
<em class="default">(defaults to: <tt>DEFAULT_FORMATTER</tt>)</em>
&mdash;
<div class='inline'>
<p>The formatter to use to encapsulate the serialized data blob.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String</tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/msf/util/dot_net_deserialization.rb', line 66</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_generate_formatted'>generate_formatted</span><span class='lparen'>(</span><span class='id identifier rubyid_stream'>stream</span><span class='comma'>,</span> <span class='label'>formatter:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_FORMATTER-constant" title="Msf::Util::DotNetDeserialization::DEFAULT_FORMATTER (constant)">DEFAULT_FORMATTER</a></span></span><span class='rparen'>)</span>
<span class='kw'>case</span> <span class='id identifier rubyid_formatter'>formatter</span>
<span class='kw'>when</span> <span class='symbol'>:BinaryFormatter</span>
<span class='id identifier rubyid_formatted'>formatted</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/Formatters.html" title="Msf::Util::DotNetDeserialization::Formatters (module)">Formatters</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/Formatters/BinaryFormatter.html" title="Msf::Util::DotNetDeserialization::Formatters::BinaryFormatter (module)">BinaryFormatter</a></span></span><span class='period'>.</span><span class='id identifier rubyid_generate'><span class='object_link'><a href="DotNetDeserialization/Formatters/BinaryFormatter.html#generate-class_method" title="Msf::Util::DotNetDeserialization::Formatters::BinaryFormatter.generate (method)">generate</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_stream'>stream</span><span class='rparen'>)</span>
<span class='kw'>when</span> <span class='symbol'>:JsonNetFormatter</span>
<span class='id identifier rubyid_formatted'>formatted</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/Formatters.html" title="Msf::Util::DotNetDeserialization::Formatters (module)">Formatters</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/Formatters/JsonNetFormatter.html" title="Msf::Util::DotNetDeserialization::Formatters::JsonNetFormatter (module)">JsonNetFormatter</a></span></span><span class='period'>.</span><span class='id identifier rubyid_generate'><span class='object_link'><a href="DotNetDeserialization/Formatters/JsonNetFormatter.html#generate-class_method" title="Msf::Util::DotNetDeserialization::Formatters::JsonNetFormatter.generate (method)">generate</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_stream'>stream</span><span class='rparen'>)</span>
<span class='kw'>when</span> <span class='symbol'>:LosFormatter</span>
<span class='id identifier rubyid_formatted'>formatted</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/Formatters.html" title="Msf::Util::DotNetDeserialization::Formatters (module)">Formatters</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/Formatters/LosFormatter.html" title="Msf::Util::DotNetDeserialization::Formatters::LosFormatter (module)">LosFormatter</a></span></span><span class='period'>.</span><span class='id identifier rubyid_generate'><span class='object_link'><a href="DotNetDeserialization/Formatters/LosFormatter.html#generate-class_method" title="Msf::Util::DotNetDeserialization::Formatters::LosFormatter.generate (method)">generate</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_stream'>stream</span><span class='rparen'>)</span>
<span class='kw'>when</span> <span class='symbol'>:SoapFormatter</span>
<span class='id identifier rubyid_formatted'>formatted</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/Formatters.html" title="Msf::Util::DotNetDeserialization::Formatters (module)">Formatters</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/Formatters/SoapFormatter.html" title="Msf::Util::DotNetDeserialization::Formatters::SoapFormatter (module)">SoapFormatter</a></span></span><span class='period'>.</span><span class='id identifier rubyid_generate'><span class='object_link'><a href="DotNetDeserialization/Formatters/SoapFormatter.html#generate-class_method" title="Msf::Util::DotNetDeserialization::Formatters::SoapFormatter.generate (method)">generate</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_stream'>stream</span><span class='rparen'>)</span>
<span class='kw'>else</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>NotImplementedError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>The specified formatter is not implemented</span><span class='tstring_end'>&#39;</span></span>
<span class='kw'>end</span>
<span class='id identifier rubyid_formatted'>formatted</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="generate_gadget_chain-class_method">
.<strong>generate_gadget_chain</strong>(cmd, gadget_chain: DEFAULT_GADGET_CHAIN) &#x21d2; <tt><span class='object_link'><a href="DotNetDeserialization/Types/SerializedStream.html" title="Msf::Util::DotNetDeserialization::Types::SerializedStream (class)">Types::SerializedStream</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Generate a serialized data blob using the specified gadget chain to execute the OS command. The chosen gadget chain must be compatible with the target application.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>cmd</span>
<span class='type'>(<tt>String</tt>)</span>
&mdash;
<div class='inline'>
<p>The operating system command to execute. It will automatically be prefixed with “cmd /c” by the gadget chain.</p>
</div>
</li>
<li>
<span class='name'>gadget_chain</span>
<span class='type'>(<tt>Symbol</tt>)</span>
<em class="default">(defaults to: <tt>DEFAULT_GADGET_CHAIN</tt>)</em>
&mdash;
<div class='inline'>
<p>The gadget chain to use for execution.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt><span class='object_link'><a href="DotNetDeserialization/Types/SerializedStream.html" title="Msf::Util::DotNetDeserialization::Types::SerializedStream (class)">Types::SerializedStream</a></span></tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/msf/util/dot_net_deserialization.rb', line 110</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_generate_gadget_chain'>generate_gadget_chain</span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='comma'>,</span> <span class='label'>gadget_chain:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_GADGET_CHAIN-constant" title="Msf::Util::DotNetDeserialization::DEFAULT_GADGET_CHAIN (constant)">DEFAULT_GADGET_CHAIN</a></span></span><span class='rparen'>)</span>
<span class='kw'>case</span> <span class='id identifier rubyid_gadget_chain'>gadget_chain</span>
<span class='kw'>when</span> <span class='symbol'>:ClaimsPrincipal</span>
<span class='id identifier rubyid_stream'>stream</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains.html" title="Msf::Util::DotNetDeserialization::GadgetChains (module)">GadgetChains</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/ClaimsPrincipal.html" title="Msf::Util::DotNetDeserialization::GadgetChains::ClaimsPrincipal (class)">ClaimsPrincipal</a></span></span><span class='period'>.</span><span class='id identifier rubyid_generate'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/ClaimsPrincipal.html#generate-class_method" title="Msf::Util::DotNetDeserialization::GadgetChains::ClaimsPrincipal.generate (method)">generate</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='rparen'>)</span>
<span class='kw'>when</span> <span class='symbol'>:DataSet</span>
<span class='id identifier rubyid_stream'>stream</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains.html" title="Msf::Util::DotNetDeserialization::GadgetChains (module)">GadgetChains</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/DataSet.html" title="Msf::Util::DotNetDeserialization::GadgetChains::DataSet (class)">DataSet</a></span></span><span class='period'>.</span><span class='id identifier rubyid_generate'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/DataSet.html#generate-class_method" title="Msf::Util::DotNetDeserialization::GadgetChains::DataSet.generate (method)">generate</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='rparen'>)</span>
<span class='kw'>when</span> <span class='symbol'>:DataSetTypeSpoof</span>
<span class='id identifier rubyid_stream'>stream</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains.html" title="Msf::Util::DotNetDeserialization::GadgetChains (module)">GadgetChains</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/DataSetTypeSpoof.html" title="Msf::Util::DotNetDeserialization::GadgetChains::DataSetTypeSpoof (class)">DataSetTypeSpoof</a></span></span><span class='period'>.</span><span class='id identifier rubyid_generate'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/DataSetTypeSpoof.html#generate-class_method" title="Msf::Util::DotNetDeserialization::GadgetChains::DataSetTypeSpoof.generate (method)">generate</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='rparen'>)</span>
<span class='kw'>when</span> <span class='symbol'>:ObjectDataProvider</span>
<span class='id identifier rubyid_stream'>stream</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains.html" title="Msf::Util::DotNetDeserialization::GadgetChains (module)">GadgetChains</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/ObjectDataProvider.html" title="Msf::Util::DotNetDeserialization::GadgetChains::ObjectDataProvider (class)">ObjectDataProvider</a></span></span><span class='period'>.</span><span class='id identifier rubyid_generate'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/ObjectDataProvider.html#generate-class_method" title="Msf::Util::DotNetDeserialization::GadgetChains::ObjectDataProvider.generate (method)">generate</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='rparen'>)</span>
<span class='kw'>when</span> <span class='symbol'>:TextFormattingRunProperties</span>
<span class='id identifier rubyid_stream'>stream</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains.html" title="Msf::Util::DotNetDeserialization::GadgetChains (module)">GadgetChains</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/TextFormattingRunProperties.html" title="Msf::Util::DotNetDeserialization::GadgetChains::TextFormattingRunProperties (class)">TextFormattingRunProperties</a></span></span><span class='period'>.</span><span class='id identifier rubyid_generate'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/TextFormattingRunProperties.html#generate-class_method" title="Msf::Util::DotNetDeserialization::GadgetChains::TextFormattingRunProperties.generate (method)">generate</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='rparen'>)</span>
<span class='kw'>when</span> <span class='symbol'>:TypeConfuseDelegate</span>
<span class='id identifier rubyid_stream'>stream</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains.html" title="Msf::Util::DotNetDeserialization::GadgetChains (module)">GadgetChains</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/TypeConfuseDelegate.html" title="Msf::Util::DotNetDeserialization::GadgetChains::TypeConfuseDelegate (class)">TypeConfuseDelegate</a></span></span><span class='period'>.</span><span class='id identifier rubyid_generate'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/TypeConfuseDelegate.html#generate-class_method" title="Msf::Util::DotNetDeserialization::GadgetChains::TypeConfuseDelegate.generate (method)">generate</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='rparen'>)</span>
<span class='kw'>when</span> <span class='symbol'>:WindowsIdentity</span>
<span class='id identifier rubyid_stream'>stream</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains.html" title="Msf::Util::DotNetDeserialization::GadgetChains (module)">GadgetChains</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/WindowsIdentity.html" title="Msf::Util::DotNetDeserialization::GadgetChains::WindowsIdentity (class)">WindowsIdentity</a></span></span><span class='period'>.</span><span class='id identifier rubyid_generate'><span class='object_link'><a href="DotNetDeserialization/GadgetChains/WindowsIdentity.html#generate-class_method" title="Msf::Util::DotNetDeserialization::GadgetChains::WindowsIdentity.generate (method)">generate</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_cmd'>cmd</span><span class='rparen'>)</span>
<span class='kw'>else</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>NotImplementedError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>The specified gadget chain is not implemented</span><span class='tstring_end'>&#39;</span></span>
<span class='kw'>end</span>
<span class='id identifier rubyid_stream'>stream</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="get_ancestor-class_method">
.<strong>get_ancestor</strong>(obj, ancestor_type, required: true) &#x21d2; <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
</div>
</div>
<div class="tags">
<p class="tag_title">Raises:</p>
<ul class="raise">
<li>
<span class='type'>(<tt>RuntimeError</tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
29
30
31
32
33
34
35
36
37</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/msf/util/dot_net_deserialization.rb', line 29</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_get_ancestor'>get_ancestor</span><span class='lparen'>(</span><span class='id identifier rubyid_obj'>obj</span><span class='comma'>,</span> <span class='id identifier rubyid_ancestor_type'>ancestor_type</span><span class='comma'>,</span> <span class='label'>required:</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='kw'>while</span> <span class='op'>!</span> <span class='lparen'>(</span><span class='id identifier rubyid_obj'>obj</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>||</span> <span class='id identifier rubyid_obj'>obj</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='id identifier rubyid_ancestor_type'>ancestor_type</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='id identifier rubyid_obj'>obj</span> <span class='op'>=</span> <span class='id identifier rubyid_obj'>obj</span><span class='period'>.</span><span class='id identifier rubyid_parent'>parent</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>RuntimeError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Failed to find ancestor </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_ancestor_type'>ancestor_type</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_obj'>obj</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_required'>required</span>
<span class='id identifier rubyid_obj'>obj</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Fri May 8 17:01:49 2026 by
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.37 (ruby-3.1.5).
</div>
</div>
</body>
</html>