Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
29f748b
Directory restructuring
gavin-black Oct 30, 2013
618d86b
Update README
gavin-black Oct 30, 2013
712718d
Updated certificate script
gavin-black Oct 30, 2013
ae9f6b5
Readme is now markdown
gavin-black Oct 30, 2013
61f0d3d
Updated to have customer.csr
gavin-black Oct 30, 2013
909b72c
Update README.md
gavin-black Oct 30, 2013
5c00c31
Readme images
gavin-black Oct 30, 2013
c2f2065
Merge branch 'master' of github.com:project-imas/mdm-server
gavin-black Oct 30, 2013
4839b28
Update README.md
gavin-black Oct 30, 2013
91f49a8
Update README.md
gavin-black Nov 13, 2013
d7ffe91
Client reporting api
gavin-black Dec 20, 2013
12434fa
Update README.md
gavin-black Dec 20, 2013
c8eae99
update necessary support files
gavin-black Jan 17, 2014
003ee35
Added simple daemon script to 'fix' http/https error
gavin-black Jan 17, 2014
fbc325e
Updated with Scott's changes to allow multiple devices
gavin-black Jan 17, 2014
f145384
Update README.md
gavin-black Jan 17, 2014
1c28953
Update README.md
Jan 27, 2014
5543812
Added Softhinker vendor signing code
gavin-black Jan 30, 2014
dc58ee2
Merge branch 'master' of github.com:project-imas/mdm-server
gavin-black Jan 30, 2014
d834788
Update README.md
gavin-black Jan 30, 2014
3f4fdb4
Update LICENSE
gavin-black Jan 30, 2014
9558ec7
Restructured directories for scripts
gavin-black Jan 30, 2014
f4ef37a
More restructuring
gavin-black Jan 30, 2014
2bcf697
Update README.md
gavin-black Jan 30, 2014
d181884
Merge branch 'master' of github.com:project-imas/mdm-server
gavin-black Jan 30, 2014
2c80b97
Added script for vendor signing using the Java code
gavin-black Feb 12, 2014
9f49775
Fixed permissions on make_certs
gavin-black Feb 12, 2014
b450549
Update README.md
gavin-black Feb 12, 2014
60862af
Update README.md
gavin-black Feb 12, 2014
856b1e3
Updated to address alias issues
gavin-black Feb 12, 2014
b9a36f1
Update README.md
gavin-black Feb 12, 2014
3d520b2
Update README.md
Feb 14, 2014
541195b
Update README.md
gavin-black Mar 11, 2014
eea0726
Added bootstrap-based front end and updated server accordingly.
thrasr Apr 10, 2014
823f205
Removed old code, added comments, and general cleanup.
thrasr Apr 10, 2014
c927cdf
Fixed bash color errors.
thrasr Apr 10, 2014
aaffaae
Cleaned up device list storing and queue post request
thrasr Apr 14, 2014
f8902e7
Fixes crash on HTTP bug and adds dependency for PyOpenSSL
thrasr Apr 15, 2014
c5eb4eb
Updates readme to include PyOpenSLL dependency
thrasr Apr 15, 2014
4356c7a
Reenables code commented out for debugging
thrasr Apr 15, 2014
44f1dfb
Reenables polling functionality and temporarily fixes iOS 7 infinite …
thrasr Apr 21, 2014
d6469f1
Minor changes to comments
thrasr Apr 24, 2014
65474e1
Fixed comparison in loop
Apr 28, 2014
6f9dea5
Merge pull request #1 from TactMayers/master
thrasr Apr 28, 2014
b3b50bb
Minor fixes and comments
thrasr Apr 28, 2014
19efadf
Removes duplicate device hack and debug printing
thrasr Apr 28, 2014
5029d3b
Comment marking ClearPassword multi-device change
thrasr Apr 28, 2014
3266108
Initial changes for new device class. Not functional yet
thrasr Apr 28, 2014
03dcaa9
Enables additional functionality for device class. Adds pickle for b…
thrasr Apr 29, 2014
34aeb32
Device class should be fully functional. Server does NOT use device …
thrasr May 1, 2014
053816b
Updates server to use device class completely
thrasr May 1, 2014
290f4c6
Adds basic accordion functionality to be built upon
thrasr May 8, 2014
4805fd7
Update README.md
stevesoto May 9, 2014
ae8cb54
Merge pull request #1 from stevesoto/patch-1
gavin-black May 12, 2014
4a0a7d9
Adds commands to device and enables checkbox functionality. Reenable…
thrasr May 12, 2014
b505c29
Updates frontend and fixes multi-device command list error
thrasr May 19, 2014
5ba205d
Removes depricated creds.py file
thrasr May 19, 2014
9d43e46
Adds comments and cleans up some debug print statements
thrasr May 19, 2014
385cde3
Changes error message to better reflect situation
thrasr May 19, 2014
a6600ec
Fixes error where commands and pickle were being loaded twice on serv…
thrasr May 19, 2014
bc3b108
Merge branch 'master' into rewrite
thrasr May 19, 2014
3a540d7
Removes unnecessary library includes
thrasr May 19, 2014
1aa287c
Updates revision history to reflect major changes
thrasr May 19, 2014
ac123b6
Merge pull request #3 from thrasr/master
gavin-black May 20, 2014
8fd7366
Removes depricated daemon script
thrasr May 20, 2014
36aaf67
Updates script to correctly move files in prep for vendor signing
thrasr May 20, 2014
699f2ad
Updates device display to look better on tablets and smaller desktop/…
thrasr May 20, 2014
69b5937
Cleans up javascript and removes debugging output
thrasr May 20, 2014
dfe4a78
Switches from CDN to local copy of mustache.min.js to improve load times
thrasr May 20, 2014
4c62cc0
Updates readme to reflect the addition/deletion of key files
thrasr May 20, 2014
6bc8dfd
Adds device status color feature. Device will show green/yellow/red a…
thrasr May 22, 2014
73cbdc7
Minor formatting updates
thrasr May 22, 2014
f8fbb77
Updates devices to only return 5 most recent commands
thrasr May 22, 2014
a7d6579
Minor updates to server.py. Removes outdated code and comments
thrasr May 22, 2014
92c82a3
Minor updates to comments and removal of old code
thrasr May 22, 2014
1ee5486
Moves jquery.min.js to js folder and updates location in index.html
thrasr May 22, 2014
44557f9
Cleans up static folder
thrasr May 22, 2014
b501021
Moves mustache template to its own file and updates index.html accord…
thrasr May 22, 2014
8933f63
Updates readme to show up to date instructions
thrasr May 27, 2014
10868cf
Updates readme to use a more accurate screenshot
thrasr May 27, 2014
0fbb6e8
Fixes small error with readme screenshots.
thrasr May 27, 2014
9e4314f
Removes old server screenshot
thrasr May 27, 2014
c88491e
Updates make_certs.sh to move indentity.crt
thrasr May 29, 2014
f3a98fe
Updates setup script to change server.cnf
thrasr Jun 2, 2014
589710e
Folds both READMEs into one with updated info
thrasr Jun 3, 2014
072a6b9
Adds timeout capability and fixes multi-device bug
thrasr Jun 3, 2014
b6223a4
Adds individual command indicators to frontend
thrasr Jun 3, 2014
a8cec85
Fixes a few minor bugs
thrasr Jun 3, 2014
4e620a2
Solves issue with certain commands and nonJSON serializable data
thrasr Jun 5, 2014
455cec4
Updates to include license information
thrasr Jun 9, 2014
55c0eda
Adds ability to customize device info
thrasr Jun 16, 2014
131b14c
Updates README with new command successful image
thrasr Jun 16, 2014
49efc26
Merge pull request #4 from thrasr/master
gavin-black Jun 17, 2014
db12e1c
Minor readme updates and comments in code
thrasr Jun 23, 2014
f266380
Adds .gitignore file
thrasr Jun 24, 2014
90ecc19
Minor README.md updates
thrasr Jun 26, 2014
4579655
Applies workaround for commands being stored with incorrect UUIDs
thrasr Jun 30, 2014
e74544e
Minor README updates
thrasr Jul 1, 2014
d65b57c
Minor formatting update to README
thrasr Jul 14, 2014
85b267c
Cleans up index.html file
thrasr Jul 31, 2014
445f865
Moves js to external files
thrasr Jul 31, 2014
a185e4f
Merge pull request #11 from thrasr/master
thrasr Aug 4, 2014
f7d2468
Updates README.md
thrasr Aug 4, 2014
b6eb44b
Minor fix to README
thrasr Aug 4, 2014
54f32c7
Merge pull request #12 from thrasr/master
thrasr Aug 4, 2014
b4a9585
Fixes InstallProfile problems
thrasr Aug 5, 2014
0a5380d
Merge https://github.com/project-imas/mdm-server
thrasr Aug 5, 2014
2c591ff
Create vendor_signing.bat
Aug 13, 2014
5d0e268
Delete vendor_signing.bat
Aug 13, 2014
1099b5c
Added batch files for Windows Devices
Aug 13, 2014
5f42235
added support for windows
Aug 13, 2014
bf65b91
Merge pull request #14 from anandbaskaran/master
thrasr Aug 14, 2014
3906d41
Updates README w/ temp fix to APNSWrapper SSLv3
thrasr Nov 4, 2014
e61223f
Update make_certs.bat
MaximilianoRios Dec 2, 2014
fb9d949
Merge pull request #18 from MaximilianoRios/master
thrasr Dec 4, 2014
f4d286d
Updates readme with new cert instructions
thrasr Jan 15, 2015
1ae6dd6
Updates make_certs scripts
thrasr Jan 15, 2015
6f49c9e
Updated readme for windows script
thrasr Jan 15, 2015
88ae62c
Switched from softhinker to grinich vendor sign code
thrasr Jan 15, 2015
2321fc9
Minor readme updates
thrasr Jan 15, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Python related files
server/*.pyc

# Logs/storage with possible sensitive information
server/xactn.log
server/devicelist.pickle

# Certs with sensitive information
server/CA.crt
server/Enroll.mobileconfig
server/Identity.p12
server/PushCert.pem
server/Server.*
server/identity.crt

# Custom payloads
server/Manifest.plist
server/MyApp.*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor"]
path = vendor
url = git://github.com/grinich/mdmvendorsign
4 changes: 0 additions & 4 deletions Documentation/README

This file was deleted.

Binary file removed Presentations/InsideAppleMDM_BlackHatUSA_2011.pdf
Binary file not shown.
Binary file removed Presentations/InsideAppleMDM_ShmooCon_2012.pdf
Binary file not shown.
3 changes: 0 additions & 3 deletions Presentations/README

This file was deleted.

2 changes: 0 additions & 2 deletions README

This file was deleted.

248 changes: 248 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
# Overview[![analytics](http://www.google-analytics.com/collect?v=1&t=pageview&_s=1&dl=https%3A%2F%2Fgithub.com%2Fproject-imas%2Fmdm-server&_u=MAC~&cid=1757014354.1393964045&tid=UA-38868530-1)]()

Instructions and code for setting up a simple iOS Mobile Device Management (MDM) server. MDM allows for OS level control of multiple devices from a centralized location. A remote administrator can install/remove apps, install/revoke certificates, lock the device, change password requirements, etc.

# Prerequisites

* Publicly accessible Linux/Unix server
* Apple Enterprise Account
* Apple Developer Account
* Python 2.7 (See Server Setup for libraries)
* openssl command-line
* Java SDK (java/javac)
* Apple's iPhone Configuration Utility
* [OS X Version](http://support.apple.com/kb/dl1465)
* [Windows Version](http://support.apple.com/kb/DL1466)

# Setup

1. Create MDM Vendor CSR
* Open Keychain Access.
* Go to the menu bar: Keychain Access -> Certificate Assistant -> Request a Certificate From a Certificate Authority.
* Use the same email as the developer account that will be used. Enter in a common name as well.
* Select *Saved to disk*.

2. Upload CSR to Apple
* Go to [Apple's Certificates, Identifiers & Profiles page](https://developer.apple.com/account/ios/certificate/certificateCreate.action).
* Select MDM CSR under Production. If this option is disabled, you will need to contact apple to enable it. You can either email apple at devprograms@apple.com or go through the [online contact menu](http://developer.apple.com/contact/). In your message, indicate that you are looking to create an MDM Vendor Certificate and need the MDM CSR option enabled on the certificate creation page. Apple should respond within one business day according to their contact page.
* When you have the MDM CSR option available, select it and hit continue. Hit continue again through Apple's description of how to create a CSR file (we already have one).
* Upload the .certSigningRequest file we created in step 1 and then hit generate. A .cer file should be downloaded. Name it something like mdmvendor.cer.

3. Export MDM private key
* Open your mdmvendor.cer file in Keychain Access.
* Select Certificates from the left side.
* You should find your certificate listed as *MDM Vendor: Common Name*.
* There should be an arrow on that line that opens up show the MDM private key.
* Right-click the private key, select *Export...*, and save as private.p12
* Remember where you save this file, we will use it in step 5.

4. Create Push Certificate CSR
* In Keychain Access, again select from the menu bar: Keychain Access -> Certificate Assistant -> Request a Certificate From a Certificate Authority.
* Enter your email (can be a different email) and a common name.
* Select *Saved to disk* and name it something like push.csr.

5. Extract MDM private key and MDM Vendor Certificate
* Extract private key using the following command:

openssl pkcs12 -in private.p12 -nocerts -out key.pem

* Strip the password from the private key using the following command:

openssl rsa -in key.pem out private.key

* Extract certificate using the following command:

openssl pkcs12 -in private.p12 -clcerts -nokeys -out cert.pem

* Convert certificate to DES using the following command:

openssl x509 -in cert.pem -inform PEM -out mdm.cer -outform DES

* These files will be used in the next step.

6. Use the mdmvendorsign tool to create applepush.csr
* We're going to use the python code located in /vendor/. If /vendor/ is currently empty, you probably forgot to init and update submodules

git submodule init
git submodule update

* Copy private.key, push.csr, and mdm.cer into /vendor/

* Run the following command while in that directory:

python mdm_vendorpython mdm_vendor_sign.py –key private.key –csr push.csr –mdm mdm.cer –out applepush.csr

* This should generate applepush.csr.

7. Get Push Certificate from Apple
* Go to [Apple's Push Certificates Portal](https://identity.apple.com/pushcert/) and click the Create a Certificate button.
* Upload applepush.csr to create a new entry in the table.
* Download the resulting push certificate.
* Open the push certificate in Keychain Access.

8. Prepare Push Certificate
* Find the push certificate in Keychain Access. It should look like *APSP:hexstuffhere*.
* Right-click the certificate and select *Get Info*.
* Copy down the User ID which should look like com.apple.mgmt.External.hexstuffhere... We will use it later on in step 9.
* Right-click the certificate and select *Export...* and save it as mdm.p12
* Run the following command to convert it to a pem file:

openssl pkcs12 -in mdm.p12 -out PushCert.pem -nodes

* Move the resulting PushCert.pem file to /server/

9. Generate additional certs
* Go to the scripts directory and run make_certs.sh.
* This will generate a number of necessary certs to move forward.
* Certs will be automatically moved to their proper location in /server.
* We'll use identity.p12 in step 10 to create an Enroll.mobileconfig file

10. Create Enroll.mobileconfig
* Open the iPhone Configuration Utilities program, select *Configuration Profiles*, and then click the *New* button.
* In the General category: Pick a name to identify the cert. For Identifier, use the com.apple.mgmt.External.hexstuffhere that you copied down earlier.
* In the Credentials category, click configure and find your scripts/identity.p12 file generated in step 9. For password, we either use the PEM password or the export password - if the profile does not install, try the other option. Please leave feedback with which worked.
* For Mobile Device Management:
* Server URL: https://YOUR_HOSTNAME_OR_IP:8080/server
* Check In URL: https://YOUR_HOSTNAME_OR_IP:8080/checkin
* Topic: com.apple.mgmt... string (same as General->Identifier)
* Identity: identity.p12
* Sign messages: Checked
* Check out when removed: Unchecked
* Query device for: Check all that you want
* Add / Remove: Check all that you want
* Security: Check all that you want
* Use Development APNS server: Uncheck
* When done, click Export. Choose None for security and then Export....
* Save the file as **Enroll**. You will now have an Enroll.mobileconfig file - move it to the /server directory.

11. Cleanup
* Any additional files that are not in /server/ generated during this process are not necessary for running the server. Some of them may have/be private keys or other unique information, so it is probably a good idea to protect or destroy those files.
* Most certs will be located in the /scripts/ folder. There may be some generated from Keychain Access that were saved by the user and may be saved elsewhere.
* Please secure these files and prevent others from being able to access them.

NOTE: UPDATING CERTIFICATE INSTRUCTIONS - WORK IN PROGRESS


# Server Setup

The server code is based on and heavily takes from [Intrepidus Group's blackhat presentation](https://intrepidusgroup.com/). Copy over the **mdm-server/server** directory you put the enrollment profile and certificates in to your server.

You must have the following installed on the server:
* Openssl
* Recommend downloading and compiling yourself
* Some Debian-based distros disable features needed by M2Crypto
* Source available at [http://www.openssl.org/source/](http://www.openssl.org/source/)
* Python 2.7, with the following libraries
* [web.py](http://webpy.org/)
* [M2Crypto](https://pypi.python.org/pypi/M2Crypto)
* [PyOpenSSL](https://pypi.python.org/pypi/pyOpenSSL)
* [APNSWrapper](https://pypi.python.org/pypi/APNSWrapper)
* APNSWrapper appears to be inactive
* On 22 October 2014, [Apple removed support for SSLv3](https://developer.apple.com/news/?id=10222014a), which APNSWrapper uses, due to the poodle vulnerability
* As a temporary solution, users need to edit line 131 of connections.py of the source code of APNSWrapper
* Change "SSLv3" to "TLSv1", so that the line reads:
```python
ssl_version = self.ssl_module.PROTOCOL_TLSv1,
```
* After making the change, users should install the library using:

```bash
python setup.py install
```

* More information will follow as we find a better solution

Network Settings
* Outbound access to gateway.push.apple.com:2195
* Inbound access to port 8080
* iOS device must also have outbound access to gateway.push.apple.com:5223

If everything is setup appropriately, simply navigate to the **/server** directory and run <code>python server.py</code>.

On the device navigate to: **https://YOUR_HOST:8080/**
Once there you need to, in order:
1. Tap *here* to install the CA Cert (for Server/Identity)
2. Tap *here* to enroll in MDM (the device should appear after this step)
3. Select Command (DeviceLock is a good one to test) and check your device. Click Submit to send the command.
4. If everything works, the device should lock and you're good to go! As of right now some of the commands aren't fully implemented. Feel free to experiment with different commands!

---
![Device Enrollment Steps](images/deviceEnroll.jpg)
---

You can now run those commands from any web browser, a successfull command will often looks something like the following:

---
![Command Success](images/commandSuccess.png)
---

Click the "Response" button to see the plist response from apple. Click the pencil to edit the device name, device owner, and device location.


When stopping the server, the standard control-c doesn't usually work. Instead use control-z to suspend the process and then use a kill command to end the process.

^z
[1]+ Stopped python server.py
user:~/mdm-server/server$ kill %1
[1]+ Terminated python server.py
user:~/mdm-server/server$

The server uses the pickle library to save devices. When the device class is updated, the pickle format may be invalidated, causing the server to error. In order to fix this, remove the devicelist.pickle file (make a backup just in case!) and re-enroll all devices.

# Client Reporting

The MDM server also has REST endpoints for reporting issues and geolocation data from the enrolled clients. This functionality may be used at a later point in time by a security app. The API can be imported into any project as follows:

* Click on the top level Project item and add files ("option-command-a")
* Navigate to client-reporting/
* Highlight the client-reporting subdirectory
* Click the Add button

The library provides the following functions:

+(void) setHostAddress: (NSString*) host; // Set where the MDM server lives
+(void) setPause : (BOOL) toggle; // Toggle whether to add a thread execution pause to allow requests to finish
+(void) reportJailbreak; // Report that the device has been jailbroken
+(void) reportDebugger; // Report that the application has a debugger attached
+(void) reportLocation : (CLLocationCoordinate2D*) coords; // Report the lat/lon location of the device

"setHostAddress" and "setPause" are meant to be set once only, and effect all "report" calls. An example usage may look like:

// Code in application init
[client_reporting setHostAddress:@"192.168.0.0"];
[client_reporting setPause:YES];

// Later code during execution
[client_reporting reportDebugger]

This client API can be coupled with the [iMAS security-check controls](git@github.com:project-imas/security-check.git) to provide accurate reporting of jailbreak and debugger detection.


Apologies for the long and complex setup, we hope to eventually make things easier and simpler. Please post questions to github if you get stuck and we'll do our best to help. Enjoy!



# LICENSE AND ATTRIBUTION

Copyright 2013-2014 The MITRE Corporation, All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


This project also uses code from various sources under various licenses.

[The original code from the Intrepidus Group's python server is under the BSD License found here.](server/LICENSE)

[The python vendor signing code is located here and is under the MIT license.](https://github.com/grinich/mdmvendorsign)

[The Softhinker certificate signing code is under the Apache License found here.](vendor-signing/LICENSE)

[The website's Bootstrap code is under the MIT License found here.](server/static/dist/LICENSE)

The certificate setup instructions were based on [this blog post](http://www.blueboxmoon.com/wordpress/?p=877). Our thanks to Daniel.

Finally we use some free [glyphicons](http://glyphicons.com/) that are included with bootstrap.
Loading