CVE-2019-1000010 (published 2019-02-04T21:29Z)

phpIPAM version 1.3.2 and earlier contains a Cross Site Scripting (XSS) vulnerability in subnet-scan-telnet.php that can result in executing code in victims browser. This attack appears to be exploitable via victim visits link crafted by an attacker. This vulnerability appears to have been fixed in 1.4.

Severity: MEDIUM
CVSS v2 base score: 4.3 (AV:N/AC:M/Au:N/C:N/I:P/A:N)
CVSS v3 base score: 6.1, MEDIUM (CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-79
cwe_name: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
description: The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
extended_description: 
            Cross-site scripting (XSS) vulnerabilities occur when:
            
               Untrusted data enters a web application, typically from a web request.
               The web application dynamically generates a web page that contains this untrusted data.
               During page generation, the application does not prevent the data from containing content that is executable by a web browser, such as JavaScript, HTML tags, HTML attributes, mouse events, Flash, ActiveX, etc.
               A victim visits the generated web page through a web browser, which contains malicious script that was injected using the untrusted data.
               Since the script comes from a web page that was sent by the web server, the victim's web browser executes the malicious script in the context of the web server's domain.
               This effectively violates the intention of the web browser's same-origin policy, which states that scripts in one domain should not be able to access resources or run code in a different domain.
            
            There are three main kinds of XSS:
            
               
                  Type 1: Reflected XSS (or Non-Persistent) - 
         			The server reads data directly from the HTTP request and reflects it back in the HTTP response. Reflected XSS exploits occur when an attacker causes a victim to supply dangerous content to a vulnerable web application, which is then reflected back to the victim and executed by the web browser. The most common mechanism for delivering malicious content is to include it as a parameter in a URL that is posted publicly or e-mailed directly to the victim. URLs constructed in this manner constitute the core of many phishing schemes, whereby an attacker convinces a victim to visit a URL that refers to a vulnerable site. After the site reflects the attacker's content back to the victim, the content is executed by the victim's browser.
               
                  Type 2: Stored XSS (or Persistent) - 
               The application stores dangerous data in a database, message forum, visitor log, or other trusted data store. At a later time, the dangerous data is subsequently read back into the application and included in dynamic content. From an attacker's perspective, the optimal place to inject malicious content is in an area that is displayed to either many users or particularly interesting users. Interesting users typically have elevated privileges in the application or interact with sensitive data that is valuable to the attacker. If one of these users executes malicious content, the attacker may be able to perform privileged operations on behalf of the user or gain access to sensitive data belonging to the user. For example, the attacker might inject XSS into a log message, which might not be handled properly when an administrator views the logs.
            
               
                  Type 0: DOM-Based XSS - 
               In DOM-based XSS, the client performs the injection of XSS into the page; in the other types, the server performs the injection. DOM-based XSS generally involves server-controlled, trusted script that is sent to the client, such as Javascript that performs sanity checks on a form before the user submits it. If the server-supplied script processes user-supplied data and then injects it back into the web page (such as with dynamic HTML), then DOM-based XSS is possible.
            
            
            Once the malicious script is injected, the attacker can perform a variety of malicious activities. The attacker could transfer private information, such as cookies that may include session information, from the victim's machine to the attacker. The attacker could send malicious requests to a web site on behalf of the victim, which could be especially dangerous to the site if the victim has administrator privileges to manage that site. Phishing attacks could be used to emulate trusted web sites and trick the victim into entering a password, allowing the attacker to compromise the victim's account on that web site. Finally, the script could exploit a vulnerability in the web browser itself possibly taking over the victim's machine, sometimes referred to as "drive-by hacking."
            In many cases, the attack can be launched without the victim even being aware of it. Even with careful users, attackers frequently use a variety of methods to encode the malicious portion of the attack, such as URL encoding or Unicode, so the request looks less suspicious.
         
         

Fix information:
repo_url: https://github.com/phpipam/phpipam
commit_details: repo_url: https://github.com/phpipam/phpipam
author: Gary Allan
author_date: 2018-12-08 13:35:39+00:00
msg: Bugfix: XSS in subnet-scan-telnet.php, CSRF in subnet-scan-execute.php. Fixes #2327
repository: repo_url: https://github.com/phpipam/phpipam
repo_name: phpipam/phpipam
description: phpipam development repository
repo_language: PHP
owner: phpipam
file_changes: filename: subnet-scan-execute-scan-icmp.php
change_type: ModificationType.MODIFY
diff: @@ -4,11 +4,8 @@
  * Discover new hosts with ping
  *******************************/
 
-# verify that user is logged in
-$User->check_user_session();
-
-# create csrf token
-$csrf = $User->Crypto->csrf_cookie ("create", "scan");
+# Check we have been included and not called directly
+if (!isset($subnet_scan_execute_included)) { $Result->show("danger", _("Invalid request"), true); }
 
 # validate subnetId and type
 if(!is_numeric($_POST['subnetId']))                        { $Result->show("danger", "Invalid subnet Id", true); die(); }

programming_language: PHP
filename: subnet-scan-execute-scan-telnet.php
change_type: ModificationType.MODIFY
diff: @@ -4,17 +4,17 @@
  * Discover new hosts with telnet scan
  *******************************/
 
-# verify that user is logged in
-$User->check_user_session();
+# Check we have been included and not called directly
+if (!isset($subnet_scan_execute_included)) { $Result->show("danger", _("Invalid request"), true); }
 
 # get ports
-if(strlen($_POST['port'])==0) 	  { $Result->show("danger", _('Please enter ports to scan').'!', true); }
+if(empty($_POST['port'])) 	  { $Result->show("danger", _('Please enter ports to scan').'!', true); }
 
 //verify ports
 $pcheck = explode(";", str_replace(",",";",$_POST['port']));
 foreach($pcheck as $p) {
 	if(!is_numeric($p)) {
-		$Result->show("danger", _("Invalid port")." ($p)", true);
+		$Result->show("danger", _("Invalid port").' ('.escape_input($p).')', true);
 	}
 }
 $_POST['port'] = str_replace(";",",",$_POST['port']);

programming_language: PHP
filename: subnet-scan-execute-snmp-arp.php
change_type: ModificationType.MODIFY
diff: @@ -4,11 +4,8 @@
  * Discover new hosts with snmp
  *******************************/
 
-# verify that user is logged in
-$User->check_user_session();
-
-# create csrf token
-$csrf = $User->Crypto->csrf_cookie ("create", "scan");
+# Check we have been included and not called directly
+if (!isset($subnet_scan_execute_included)) { $Result->show("danger", _("Invalid request"), true); }
 
 //title
 print "<h5>"._('Scan results').":</h5><hr>";

programming_language: PHP
filename: subnet-scan-execute-snmp-mac.php
change_type: ModificationType.MODIFY
diff: @@ -4,11 +4,8 @@
  * Discover new hosts with snmp
  *******************************/
 
-# verify that user is logged in
-$User->check_user_session();
-
-# create csrf token
-$csrf = $User->Crypto->csrf_cookie ("create", "scan");
+# Check we have been included and not called directly
+if (!isset($subnet_scan_execute_included)) { $Result->show("danger", _("Invalid request"), true); }
 
 //title
 print "<h5>"._('Scan results').":</h5><hr>";

programming_language: PHP
filename: subnet-scan-execute-update-icmp.php
change_type: ModificationType.MODIFY
diff: @@ -4,6 +4,9 @@
  * Update alive status of all hosts in subnet
  ***************************/
 
+# Check we have been included and not called directly
+if (!isset($subnet_scan_execute_included)) { $Result->show("danger", _("Invalid request"), true); }
+
 # validate subnetId and type
 if(!is_numeric($_POST['subnetId']))                        { $Result->show("danger", "Invalid subnet Id", true); die(); }
 

programming_language: PHP
filename: subnet-scan-execute-update-snmp-arp.php
change_type: ModificationType.MODIFY
diff: @@ -4,8 +4,8 @@
  * Discover new hosts with snmp
  *******************************/
 
-# verify that user is logged in
-$User->check_user_session();
+# Check we have been included and not called directly
+if (!isset($subnet_scan_execute_included)) { $Result->show("danger", _("Invalid request"), true); }
 
 # scan disabled
 if ($User->settings->enableSNMP!="1")           { $Result->show("danger", "SNMP module disbled", true); }

programming_language: PHP
filename: subnet-scan-execute.php
change_type: ModificationType.MODIFY
diff: @@ -24,6 +24,9 @@ $User->check_user_session();
 # check maintaneance mode
 $User->check_maintaneance_mode ();
 
+# validate csrf cookie
+$User->Crypto->csrf_cookie ("validate", "scan", $_POST['csrf_cookie']) === false ? $Result->show("danger", _("Invalid CSRF cookie"), true) : "";
+
 # subnet Id must be a integer
 if(!is_numeric($_POST['subnetId']))	{ $Result->show("danger", _("Invalid ID"), true); }
 
@@ -43,29 +46,21 @@ if ($_POST['type']!="update-icmp" && $subnet->isFull==1)                { $Resul
 # verify php path
 if(!file_exists($Scan->php_exec))	{ $Result->show("danger", _("Invalid php path"), true, true); }
 
-# scan
-switch ($_POST['type']) {
+$type = $_POST['type'];
+
+switch ($type) {
+#scan
     case "scan-icmp":
-        include("subnet-scan-execute-scan-icmp.php");
-        break;
     case "scan-telnet":
-        include("subnet-scan-execute-scan-telnet.php");
-        break;
     case "snmp-arp":
-        include("subnet-scan-execute-snmp-arp.php");
-        break;
     case "snmp-mac":
-        include("subnet-scan-execute-snmp-mac.php");
-        break;
     case "snmp-route-all":
-        include("subnet-scan-execute-snmp-route-all.php");
-        break;
 # discovery
     case "update-icmp":
-        include("subnet-scan-execute-update-icmp.php");
-        break;
     case "update-snmp-arp":
-        include("subnet-scan-execute-update-snmp-arp.php");
+        $csrf = $_POST['csrf_cookie'];
+        $subnet_scan_execute_included = true;
+        require("subnet-scan-execute-$type.php");
         break;
     default:
         $Result->show("danger", _("Invalid scan type"), true);

programming_language: PHP
filename: subnet-scan-result.php
change_type: ModificationType.MODIFY
diff: @@ -29,7 +29,7 @@ switch ($type) {
     case "snmp-mac":
     case "snmp-route-all":
         $subnet_scan_result_included = true;
-        include("subnet-scan-result-$type.php");
+        require("subnet-scan-result-$type.php");
         break;
     default:
         $Result->show("danger", _("Invalid scan type"), true);

programming_language: PHP
filename: subnet-scan.php
change_type: ModificationType.MODIFY
diff: @@ -17,6 +17,8 @@ $Result 	= new Result ();
 # verify that user is logged in
 $User->check_user_session();
 
+# create csrf token
+$csrf = $User->Crypto->csrf_cookie ("create", "scan");
 
 # ID must be numeric
 if(!is_numeric($_POST['subnetId']))										{ $Result->show("danger", _("Invalid ID"), true, true); }
@@ -104,7 +106,7 @@ $subnet->description = strlen($subnet->description)>0 ? "(".$subnet->description
 <div class="pFooter">
 	<div class="btn-group">
 		<button class="btn btn-sm btn-default hidePopups"><?php print _('Cancel'); ?></button>
-		<button class="btn btn-sm btn-default btn-success" id="subnetScanSubmit" data-subnetId='<?php print $_POST['subnetId']; ?>'><i class="fa fa-gears"></i> <?php print _('Scan subnet'); ?></button>
+		<button class="btn btn-sm btn-default btn-success" id="subnetScanSubmit" data-subnetId='<?php print $_POST['subnetId']; ?>' data-csrf-cookie='<?php print $csrf; ?>'><i class="fa fa-gears"></i> <?php print _('Scan subnet'); ?></button>
 	</div>
 
 	<div class="subnetTruncateResult"></div>

programming_language: PHP
filename: version.php
change_type: ModificationType.MODIFY
diff: @@ -4,7 +4,7 @@ define("VERSION", "1.4");									//decimal release version e.g 1.32
 /* set latest version */
 define("VERSION_VISIBLE", "1.4");							//visible version in footer e.g 1.3.2
 /* set latest revision */
-define("REVISION", "030");									//increment on static content changes (js/css) or point releases to avoid caching issues
+define("REVISION", "031");									//increment on static content changes (js/css) or point releases to avoid caching issues
 /* set last possible upgrade */
 define("LAST_POSSIBLE", "1.1");								//minimum required version to be able to upgrade
 

programming_language: PHP
filename: magic.js
change_type: ModificationType.MODIFY
diff: @@ -732,12 +732,13 @@ $(document).on('click','#subnetScanSubmit', function() {
 	showSpinner();
 	$('#subnetScanResult').slideUp('fast');
 	var subnetId = $(this).attr('data-subnetId');
+	var csrf     = $(this).attr('data-csrf-cookie');
 	var type 	 = $('select[name=type]').find(":selected").val();
 	if($('input[name=debug]').is(':checked'))	{ var debug = 1; }
 	else										{ var debug = 0; }
 	var port     = $('input[name=telnetports]').val();
 	$('#alert-scan').slideUp('fast');
-	$.post('app/subnets/scan/subnet-scan-execute.php', {subnetId:subnetId, type:type, debug:debug, port:port}, function(data) {
+	$.post('app/subnets/scan/subnet-scan-execute.php', {subnetId:subnetId, type:type, debug:debug, port:port, csrf_cookie:csrf}, function(data) {
         $('#subnetScanResult').html(data).slideDown('fast');
 		hideSpinner();
     }).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });	return false;

programming_language: JavaScript
filename: CHANGELOG
change_type: ModificationType.MODIFY
diff: @@ -53,6 +53,7 @@
     + XSS in print-user.php, CSRF in user-edit.php (#2326);
     + Possible SQL injection in nat/item-add-submit.php (#2344);
     + Fixed possible file inclusion in editing authenticaiton methods;
+    + XSS in subnet-scan-telnet.php, CSRF in subnet-scan-execute.php (#2327);
 
 == 1.3.2
 

programming_language: Markdown