Path: blob/master/spec/lib/rex/parser/acunetix_document_spec.rb
36035 views
require 'spec_helper'1require 'rex/parser/acunetix_document'23RSpec.describe Rex::Parser::AcunetixDocument do45if ENV['REMOTE_DB']6before {skip("Not supported for remote DB")}7end89include_context 'Msf::UIDriver'10include_context 'Msf::DBManager'1112def web_vuln_xml13%{14<Request>GET /search.php?q=test HTTP/1.1\r\nHost: 192.168.200.142\r\n\r\n</Request>15<Response>HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<html><body>Results</body></html></Response>16}17end1819def other_vuln_xml20%{<Request><![CDATA[Not available in the free trial]]></Request>}21end2223def xml_block(interpolated_vuln)24%{<?xml version="1.0"?>25<ScanGroup ExportedOn="26/04/2023, 00:33:40">26<Scan>27<Name><![CDATA[scan_name]]></Name>28<ShortName><![CDATA[scan_short_name]]></ShortName>29<StartURL><![CDATA[http://192.168.200.142]]></StartURL>30<StartTime><![CDATA[26/04/2023, 00:27:04]]></StartTime>31<FinishTime><![CDATA[26/04/2023, 00:32:06]]></FinishTime>32<ScanTime><![CDATA[4 minutes, 57 seconds]]></ScanTime>33<Aborted><![CDATA[True]]></Aborted>34<Responsive><![CDATA[]]></Responsive>35<Banner><![CDATA[]]></Banner>36<Os><![CDATA[]]></Os>37<WebServer><![CDATA[]]></WebServer>38<Technologies>39<![CDATA[]]>40</Technologies>41<Crawler StartUrl="http://192.168.200.142">42<Cookies>4344</Cookies>45<SiteFiles>46<SiteFile id="1">47<Name><![CDATA[http://192.168.200.142/]]></Name>48<URL><![CDATA[/]]></URL>49<FullURL><![CDATA[http://192.168.200.142/]]></FullURL>5051</SiteFile>52</SiteFiles>53</Crawler>54<ReportItems>55<ReportItem id="1" color="red">56<Name><![CDATA[PHP-CGI remote code execution]]></Name>57<ModuleName><![CDATA[Scripting (PHP_CGI_RCE_Force_Redirect.script)]]></ModuleName>58<Details><![CDATA[Not available in the free trial]]></Details>59<Affects><![CDATA[/]]></Affects>60<Parameter><![CDATA[]]></Parameter>61<AOP_SourceFile><![CDATA[]]></AOP_SourceFile>62<AOP_SourceLine></AOP_SourceLine>63<AOP_Additional><![CDATA[]]></AOP_Additional>64<IsFalsePositive><![CDATA[]]></IsFalsePositive>65<Severity><![CDATA[high]]></Severity>66<Type><![CDATA[denialofservice]]></Type>67<Impact><![CDATA[A remote unauthenticated attacker could obtain sensitive information, cause a denial of service condition or may be able to execute arbitrary code with the privileges of the web server.]]></Impact>68<Description><![CDATA[PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. When PHP is used in a CGI-based setup (such as Apache's mod_cgid), the php-cgi receives a processed query string parameter as command line arguments which allows command-line switches, such as -s, -d or -c to be passed to the php-cgi binary, which can be exploited to disclose source code and obtain arbitrary code execution. <br/><br/>69An example of the -s command, allowing an attacker to view the source code of index.php is below:70<pre>71http://localhost/index.php?-s72</pre>73]]></Description>74<DetailedInformation><![CDATA[]]></DetailedInformation>75<Recommendation><![CDATA[An alternative is to configure your web server to not let these types of requests with query strings starting with a "-" and not containing a "=" through. Adding a rule like this should not break any sites. For Apache using mod_rewrite it would look like this: <br/><br/>76<code><pre>77RewriteCond %{QUERY_STRING} ^(%2d|-)[^=]+$ [NC]78RewriteRule ^(.*) $1? [L]79</pre></code>]]></Recommendation>80<TechnicalDetails>81#{interpolated_vuln}82</TechnicalDetails>83<CWEList>8485<CWE id="20"><![CDATA[CWE-20]]></CWE>8687</CWEList>88<CVEList>8990<CVE id="1823" year="2012"><![CDATA[CVE-2012-1823]]></CVE>9192<CVE id="2311" year="2012"><![CDATA[CVE-2012-2311]]></CVE>9394</CVEList>95<CVSS>96<Descriptor><![CDATA[AV:N/AC:L/Au:N/C:P/I:P/A:P/E:F/RL:OF/RC:C]]></Descriptor>97<Score><![CDATA[7.5]]></Score>98<AV><![CDATA[Network_Accessible]]></AV>99<AC><![CDATA[Low]]></AC>100<Au><![CDATA[None]]></Au>101<C><![CDATA[Partial]]></C>102<I><![CDATA[Partial]]></I>103<A><![CDATA[Partial]]></A>104<E><![CDATA[]]></E>105<RL><![CDATA[]]></RL>106<RC><![CDATA[]]></RC>107</CVSS>108109<References>110111<Reference>112<Database><![CDATA[Eindbazen PHP-CGI advisory (CVE-2012-1823)]]></Database>113<URL><![CDATA[http://eindbazen.net/2012/05/php-cgi-advisory-cve-2012-1823/]]></URL>114</Reference>115116<Reference>117<Database><![CDATA[CVE-2012-1823-mitigation]]></Database>118<URL><![CDATA[http://eindbazen.net/wp-content/uploads/2012/05/CVE-2012-1823-mitigation.tar.gz]]></URL>119</Reference>120121<Reference>122<Database><![CDATA[PHP-CGI query string parameter vulnerability]]></Database>123<URL><![CDATA[http://www.kb.cert.org/vuls/id/520827]]></URL>124</Reference>125126<Reference>127<Database><![CDATA[PHP 5.3.12 and PHP 5.4.2 Released!]]></Database>128<URL><![CDATA[http://www.php.net/archive/2012.php#id2012-05-03-1]]></URL>129</Reference>130131</References>132</ReportItem>133</ReportItems>134</Scan>135</ScanGroup>}136end137138let(:acunetix_web_vuln_report) do139xml_block(web_vuln_xml)140end141142let(:acunetix_other_vuln_report) do143xml_block(other_vuln_xml)144end145146let(:acunetix_args) {147{148# Only the workspace arg is necessary.149# Others such as `options`, `filename` and `blacklist` are not necessary here.150workspace: framework.db.workspace.name151}152}153154describe '#parse' do155subject do156doc = Rex::Parser::AcunetixDocument.new(acunetix_args, framework.db)157::Nokogiri::XML::SAX::Parser.new(doc)158end159160context 'when importing a file containing a web vulnerability' do161it 'should import a web vulnerability' do162# Calling .parse here populates out `framework.db.workspace.web_vulns` and `vulns`. It does not return any value.163subject.parse(acunetix_web_vuln_report)164165# After the fix, web vulnerabilities with request/response data should still be reported as web_vuln166expect(framework.db.workspace.web_vulns.length).to be >= 1167expect(framework.db.workspace.web_vulns.first.name).to eq('PHP-CGI remote code execution')168end169end170171context 'when importing a file containing a normal vulnerability' do172it 'should import a normal vulnerability' do173subject.parse(acunetix_other_vuln_report)174175expect(framework.db.workspace.vulns.length).to be >= 1176expect(framework.db.workspace.vulns.first.name).to eq('PHP-CGI remote code execution')177end178end179end180end181182183