13 lines
53 KiB
HTML
13 lines
53 KiB
HTML
|
|
<!DOCTYPE html><html lang="en-US"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=Edge"><link rel="shortcut icon" href="/assets/images/favicon.png" type="image/x-icon"><link rel="stylesheet" href="/assets/css/just-the-docs-default.css"> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-4622520-7"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-4622520-7', { 'anonymize_ip': true }); </script> <script type="text/javascript" src="/assets/js/vendor/lunr.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/mermaid@10.8.0/dist/mermaid.min.js"></script> <script type="text/javascript" src="/assets/js/just-the-docs.js"></script><meta name="viewport" content="width=device-width, initial-scale=1"><title>Fail_with | Metasploit Documentation Penetration Testing Software, Pen Testing Security</title><meta name="generator" content="Jekyll v4.3.4" /><meta property="og:title" content="Fail_with" /><meta property="og:locale" content="en_US" /><meta name="description" content="View Metasploit Framework Documentation" /><meta property="og:description" content="View Metasploit Framework Documentation" /><link rel="canonical" href="https://rapid7.github.io/metasploit-framework/docs/development/developing-modules/libraries/handling-module-failures-with-fail_with.html" /><meta property="og:url" content="https://rapid7.github.io/metasploit-framework/docs/development/developing-modules/libraries/handling-module-failures-with-fail_with.html" /><meta property="og:site_name" content="Metasploit Documentation Penetration Testing Software, Pen Testing Security" /><meta property="og:type" content="website" /><meta name="twitter:card" content="summary" /><meta property="twitter:title" content="Fail_with" /> <script type="application/ld+json"> {"@context":"https://schema.org","@type":"WebPage","description":"View Metasploit Framework Documentation","headline":"Fail_with","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"https://rapid7.github.io/metasploit-framework/assets/images/favicon.png"}},"url":"https://rapid7.github.io/metasploit-framework/docs/development/developing-modules/libraries/handling-module-failures-with-fail_with.html"}</script><body> <svg xmlns="http://www.w3.org/2000/svg" style="display: none;"> <symbol id="svg-link" viewBox="0 0 24 24"><title>Link</title><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path> </svg> </symbol> <symbol id="svg-search" viewBox="0 0 24 24"><title>Search</title><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"> <circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line> </svg> </symbol> <symbol id="svg-menu" viewBox="0 0 24 24"><title>Menu</title><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-menu"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line> </svg> </symbol> <symbol id="svg-arrow-right" viewBox="0 0 24 24"><title>Expand</title><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"><polyline points="9 18 15 12 9 6"></polyline> </svg> </symbol> <symbol id="svg-doc" viewBox="0 0 24 24"><title>Document</title><svg xmlns="http://www.w3.org/2000/s
|
|||
|
|
<span class="n">fail_with</span> <span class="no">Failure</span><span class="o">::</span><span class="no">NotVulnerable</span><span class="p">,</span> <span class="s1">'Target is not vulnerable'</span>
|
|||
|
|
<span class="k">end</span>
|
|||
|
|
</code></pre></div></div><p><code class="language-plaintext highlighter-rouge">modules/exploits/multi/http/struts2_namespace_ognl.rb</code> fails using the <code class="language-plaintext highlighter-rouge">Failure::PayloadFailed</code> if the target’s response does not include a string indicating that the payload successfully executed. Alternatively, if the target responds with an HTTP error, the module invokes <code class="language-plaintext highlighter-rouge">fail_with</code> using the <code class="language-plaintext highlighter-rouge">Failure::UnexpectedReply</code> parameter:</p><div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="k">if</span> <span class="n">r</span> <span class="o">&&</span> <span class="n">r</span><span class="p">.</span><span class="nf">headers</span> <span class="o">&&</span> <span class="n">r</span><span class="p">.</span><span class="nf">headers</span><span class="p">[</span><span class="s1">'Location'</span><span class="p">].</span><span class="nf">split</span><span class="p">(</span><span class="s1">'/'</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">success_string</span>
|
|||
|
|
<span class="n">print_good</span><span class="p">(</span><span class="s2">"Payload successfully dropped and executed."</span><span class="p">)</span>
|
|||
|
|
<span class="k">elsif</span> <span class="n">r</span> <span class="o">&&</span> <span class="n">r</span><span class="p">.</span><span class="nf">headers</span><span class="p">[</span><span class="s1">'Location'</span><span class="p">]</span>
|
|||
|
|
<span class="n">vprint_error</span><span class="p">(</span><span class="s2">"RESPONSE: "</span> <span class="o">+</span> <span class="n">r</span><span class="p">.</span><span class="nf">headers</span><span class="p">[</span><span class="s1">'Location'</span><span class="p">])</span>
|
|||
|
|
<span class="n">fail_with</span><span class="p">(</span><span class="no">Failure</span><span class="o">::</span><span class="no">PayloadFailed</span><span class="p">,</span> <span class="s2">"Target did not successfully execute the request"</span><span class="p">)</span>
|
|||
|
|
<span class="k">elsif</span> <span class="n">r</span> <span class="o">&&</span> <span class="n">r</span><span class="p">.</span><span class="nf">code</span> <span class="o">==</span> <span class="mi">400</span>
|
|||
|
|
<span class="n">fail_with</span><span class="p">(</span><span class="no">Failure</span><span class="o">::</span><span class="no">UnexpectedReply</span><span class="p">,</span> <span class="s2">"Target reported an unspecified error while executing the payload"</span><span class="p">)</span>
|
|||
|
|
<span class="k">end</span>
|
|||
|
|
</code></pre></div></div><h2 id="comprehensive-list-of-fail_with-parameters"> <a href="#comprehensive-list-of-fail_with-parameters" class="anchor-heading" aria-labelledby="comprehensive-list-of-fail_with-parameters"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Comprehensive list of <code class="language-plaintext highlighter-rouge">fail_with</code> parameters</h2><p>The following are currently used <code class="language-plaintext highlighter-rouge">fail_with</code> parameters and a brief description of common uses.</p><div class="table-wrapper"><table><thead><tr><th><code class="language-plaintext highlighter-rouge">fail_with</code> parameter<th>Reason for failure<tbody><tr><td>Failure::BadConfig<td>The user-provided parameters are invalid and must be corrected.<tr><td>Failure::Disconnected<td>The target closed the connection forcibly.<tr><td>Failure::NoAccess<td>An attempt to authenticate failed, likely due to invalid credentials.<tr><td>Failure::None<td>The outcome for the module has already been met, for example a privilege escalation is already in an elevated context)<tr><td>Failure::NoTarget<td>The specified TARGET or PAYLOAD variables are misconfigured or the target environment is unsupported.<tr><td>Failure::NotFound<td>A preexisting file or resource on target is missing.<tr><td>Failure::NotVulnerable<td>The target returned a response indicative of being patched or otherwise mitigated.<tr><td>Failure::PayloadFailed<td>A return code from payload execution indicates the payload did not execute or terminated unexpectedly.<tr><td>Failure::TimeoutExpired<td>The target did not respond to the connection request in a timely manner. Check RHOSTS and RPORT, then consider increasing WFSDelay.<tr><td>Failure::UnexpectedReply<td>The target responded in an entirely unexpected way, and may not be running the vulnerable service at all.<tr><td>Failure::Unknown<td>An entirely unexpected exception occurred, and the target may not be running the expected services at all.<tr><td>Failure::Unreachable<td>The host or service is not reachable, often indicated by a refused connection or ICMP “unreachable” message.</table></div><hr><footer><p><a href="#top" id="back-to-top">Back to top</a></p><p class="text-small text-grey-dk-000 mb-0"> <a href="https://github.com/rapid7/metasploit-framework/tree/master/docs/metasploit-framework.wiki/Handling-Module-Failures-with-fail_with.md" id="edit-this-page">Edit this page on GitHub</a></p></footer></div></div><div class="search-overlay"></div></div><script type="text/javascript" src="/assets/js/toggle_mode.js"></script> <script> var config = { theme: 'default', logLevel: 'fatal', securityLevel: 'strict', startOnLoad: true, arrowMarkerAbsolute: false, er: { diagramPadding: 20, layoutDirection: 'TB', minEntityWidth: 100, minEntityHeight: 75, entityPadding: 15, stroke: 'gray', fill: 'honeydew', fontSize: 12, useMaxWidth: true, }, flowchart:{ diagramPadding: 8, htmlLabels: true, curve: 'basis', }, sequence: { diagramMarginX: 50, diagramMarginY: 10, actorMargin: 50, width: 150, height: 65, boxMargin: 10, boxTextMargin: 5, noteMargin: 10, messageMargin: 35, messageAlign: 'center', mirrorActors: true, bottomMarginAdj: 1, useMaxWidth: true, rightAngles: false, showSequenceNumbers: false, }, gantt: { titleTopMargin: 25, barHeight: 20, barGap: 4, topPadding: 50, leftPadding: 75, fontSize: 11, gridLineStartPadding: 35, fontFamily: '\'Open Sans\', sans-serif', numberSectionStyles: 4, axisFormat: '%Y-%m-%d', topAxis: false, }, }; mermaid.initialize(config); window.mermaid.init(undefined, document.querySelectorAll('.language-mermaid')); </script>
|