├── .gitignore
├── package.json
├── LICENSE
├── README.md
├── API.md
├── public
├── admin.html
└── landing.html
└── app.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .env
2 | node_modules/
3 | .DS_Store
4 | switch_to_development.sh
5 | switch_to_production.sh
6 | package-lock.json
7 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "foreman",
3 | "version": "1.0.0",
4 | "description": "Keystore server for grandmaster",
5 | "main": "app.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Dylan Haifisch Laws",
10 | "license": "BSD-3-Clause",
11 | "dependencies": {
12 | "@pm2/io": "^4.3.2",
13 | "basic-auth": "^2.0.1",
14 | "body-parser": "^1.19.0",
15 | "dotenv": "^8.2.0",
16 | "express": "^4.17.1",
17 | "express-useragent": "^1.0.13",
18 | "mongodb": "^3.3.3",
19 | "nodejs-websocket": "^1.7.2",
20 | "shasum": "^1.0.2",
21 | "socket.io": "^2.3.0",
22 | "tsscmp": "^1.0.6",
23 | "uuid": "^3.3.3"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2019 Guardian Firewall
2 |
3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4 |
5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 |
7 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8 |
9 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 |
11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Foreman
2 | A NodeJS server that acts as an iOS firmware keybag database a.k.a. as a "keystore", serving [Grandmaster](https://github.com/GuardianFirewall/grandmaster) formatted keysets.
3 |
4 | [API Reference](API.md)
5 | -----------------------
6 |
7 | ## Installation
8 | Tested on a VPS running Ubuntu 18.04.
9 |
10 | ### Install NodeJS
11 | Start by updating apt, installing the prerequisites, and adding the sources to apt.
12 | ```
13 | sudo apt update
14 | sudo apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates gcc g++ make
15 | curl -sL https://deb.nodesource.com/setup_10.x | sudo bash
16 | ```
17 |
18 | Now, update apt again and install nodejs.
19 | ```
20 | sudo apt update
21 | sudo apt -y install nodejs
22 | ```
23 |
24 | #### PM2 Usage Notice
25 | Foreman leverages [pm2.io](https://pm2.io) for live runtime montioring and providing live metrics for specific endpoints. Foreman allows clients to act with autonomy, anonymously. As such, no PM2 metric will collect any identifier that may link back to a client making requests.
26 |
27 | ### Install mongodb
28 | Simply run the following.
29 | ```
30 | sudo apt install -y mongodb
31 | ```
32 |
33 | ### Install Nginx
34 | To install Nginx simply run the following.
35 | ```
36 | sudo apt update
37 | sudo apt install nginx
38 | ```
39 | and allow Nginx with ufw.
40 | ```
41 | ufw allow "Nginx Full"
42 | ```
43 |
44 | ### Install certbot
45 | To install certbot, using the following commands.
46 | ```
47 | sudo add-apt-repository ppa:certbot/certbot
48 | sudo apt update
49 | sudo apt-get install certbot
50 | ```
51 | Generate a certificate to use with Foreman by executing the following. Take note of where it stores your `privkey.pem` and `fullchain.pem` files.
52 | ```
53 | certbot certonly --standalone --keep-until-expiring --agree-tos -d your_hostname_com
54 | ```
55 |
56 | ### Configure Nginx
57 | Create a new file named `foreman-server` in `/etc/nginx/sites-available/` and fill it with the following configuration.
58 |
59 | Be sure to modify the `server_name`, `ssl_certificate`, and `ssl_certificate_key` specifiers.
60 | ```
61 | server {
62 | listen 80 default_server;
63 | server_name _;
64 | return 301 https://$host$request_uri;
65 | }
66 |
67 | server {
68 | listen 443 ssl;
69 | server_name your_hostname_com;
70 |
71 | ssl_certificate path_to_fullchain.pem;
72 | ssl_certificate_key path_to_privkey.pem;
73 |
74 | location / {
75 | proxy_pass https://localhost:4141;
76 | proxy_http_version 1.1;
77 | proxy_set_header Upgrade $http_upgrade;
78 | proxy_set_header Connection 'upgrade';
79 | proxy_set_header Host $host;
80 | proxy_cache_bypass $http_upgrade;
81 | }
82 | }
83 | ```
84 | To enable this config, make a symbolic this config in `/etc/nginx/sites-enabled/` and then run `systemctl restart nginx`.
85 |
86 | ### Install Foreman
87 | Move your `cd` to somewhere you'd like foreman to live in and then execute the following.
88 | ```
89 | git clone https://github.com/GuardianFirewall/foreman.git
90 | cd foreman
91 | npm i
92 | ```
93 |
94 | Foreman's prerequisites should now be installed. Create a `.env` file in the foreman directory and fill it in with the following replacing values as needed.
95 | ```
96 | FOREMAN_PORT=4141
97 | FOREMAN_SSL_KEY=path_to_privkey.pem
98 | FOREMAN_SSL_CERT=path_to_fullchain.pem
99 | FOREMAN_ADMIN_DIGEST=SHA512_PASSPHRASE_DIGEST
100 | ```
101 |
102 | `FOREMAN_DIGEST` is a SHA512 digest of the passphrase you'd like to give the root "foreman" account for the `/admin` interface.
103 |
104 | ## Running Foreman
105 | Execute `node app.js` to start the Foreman server.
--------------------------------------------------------------------------------
/API.md:
--------------------------------------------------------------------------------
1 | # Foreman API
2 |
3 | Unauthenticated Endpoints
4 | -------------------------
5 |
6 | ## GET `/api/queue`
7 | Get all keybags in the decryption queue.
8 | ```
9 | curl -i -H "Accept: application/json" https://foreman-public.sudosecuritygroup.com/api/queue
10 | ```
11 |
12 | ## GET `/api/find/all`
13 | Get all available keys in the Foreman keystore.
14 | ```
15 | curl -i -H "Accept: application/json" https://foreman-public.sudosecuritygroup.com/api/find/all
16 | ```
17 |
18 | ## GET `/api/find/build/:buildnumber`
19 | Get all keys for a specific iOS build number, ex. 17A860.
20 | ```
21 | curl -i -H "Accept: application/json" https://foreman-public.sudosecuritygroup.com/api/find/build/17A860
22 | ```
23 |
24 | ## GET `/api/find/device/:device`
25 | Get all keys for a specific device model, ex. iPod9,1
26 | ```
27 | curl -i -H "Accept: application/json" https://foreman-public.sudosecuritygroup.com/api/find/device/iPod9,1/
28 | ```
29 |
30 | ## GET `/api/find/combo/:device/:build`
31 | Get all keys for a specific device model, ex. iPod9,1 and build number ex. 17A860
32 | ```
33 | curl -i -H "Accept: application/json" https://foreman-public.sudosecuritygroup.com/api/find/combo/iPod9,1/17A860
34 | ```
35 |
36 | Authenticated Endpoints
37 | -----------------------
38 |
39 | ### `NoAuth` Mode Operation
40 | Adding `FOREMAN_FORCE_NOAUTH=true` to your `.env.` configuration will flag the following endpoints to accept any token, making them essentially unauthenticated. *A token and the User-Agent must be present in the request but the token can be set to anything*.
41 |
42 | ## POST `/api/submit/keys`
43 | Submit a grandmaster `gm.config` file to be archived in the keystore.
44 |
45 | Requires that the User-Agent be set to include `grandmaster` along with `x-api-key` being set to an authorized Foreman API token in the request header.
46 | ```
47 | curl -d '{"build":"17B111","device":"iPod9,1","download":"http://updates-http.cdn-apple.com/2019FallFCS/fullrestores/061-49700/BD7C17D0-0696-11EA-970C-D191B09E16A9/iPodtouch_7_13.2.3_17B111_Restore.ipsw","images":{"Firmware/all_flash/DeviceTree.n112ap.im4p":"","Firmware/all_flash/LLB.n112.RELEASE.im4p":"85784a219eb29bcb1cc862de00a590e7f539c51a7f3403d90c9bdc62490f6b5dab4318f4633269ce3fbbe855b33a4bc7","Firmware/all_flash/iBoot.n112.RELEASE.im4p":"052e13cf2bb7802ba9d1a27046b9f9cf325d957388cd1a4325d114a5b2524391b48111c6d9768ceb29bf0b28bd21ff5c","Firmware/dfu/iBEC.n112.RELEASE.im4p":"9f2f0a3df25594d781052202e09d1a47d4211e5b5864850ee76b0dac53f785148652c17000c5e57b9e2c57040adf2c8e","Firmware/dfu/iBSS.n112.RELEASE.im4p":"e096697bb5ce030cfbe004961dde7f50e384e198e50f1e13ca532016506d71ee176ea87384e3c9e04c9afa7231dbcb4d"},"iosver":"13.2.3","kbags":{"Firmware/all_flash/LLB.n112.RELEASE.im4p":["DEBD6EDC7308203646AE11D4A114E725CF9A1501492B67FDADE7CD7C8A21DA752F0B7D07D6C4F1E90EF8AB10B1EC0215","B15052EB57FA9C6C31E5F0BB67D2B2FE90FD5571DFB8C4F3558B4A6B26FAE4BA3E2333DE4F703F91C0D186F1CE1413B6"],"Firmware/all_flash/iBoot.n112.RELEASE.im4p":["B35F7F51964476895D6B2B5F0015D299CAE2E1A75D7AD664E948E77ACAD52BC785AFDA14307C440B49C0BDAD398B2331","B5BDA4BA78E0E8E99DD74494A613AF7B255E2AA6AF6C21711C8FB7AF8D3BAE95B135585C52EBA1A8A47C1FDFB9ACE8D4"],"Firmware/dfu/iBEC.n112.RELEASE.im4p":["AE4CE9EB184640E992CA576CCCCA8AC4FDB9AD30A1DC07B82175AEAD797F01399947056E6210B61AD1A1AF54084F0D07","9804C011D723156CDA3D5FC96A13015065B1D51203042AE77F2121E9AD7F256A2643DF87057450D90D938A79CF5C4905"],"Firmware/dfu/iBSS.n112.RELEASE.im4p":["FC2F689BBEA2DEA65014931DE81AA985B814A7B0188E50B2DD6A5E37C7E8523150A9E551E1D578D25C96D5FE859FDF74","73CE12C73B2971B412AF50CFFA11DA543AE885AA72336196A78287FA3901D844649F5B66301269A6CBF5596716AE5852"]}}' -H "Content-Type: application/json" -H "x-api-key: GENERATED_TOKEN" -A "grandmaster/0.0.1" -X POST https://foreman-public.sudosecuritygroup.com/api/submit/keys
48 | ```
49 |
50 | ## POST `/api/submit/keybags`
51 | Submit an unfinished grandmaster `gm.config` file to be added to the keybag decryption queue.
52 |
53 | Requires that the User-Agent be set to include `grandmaster` along with `x-api-key` being set to an authorized Foreman API token in the request header.
54 | ```
55 | curl -d '{"build":"17B111","device":"iPod9,1","download":"http://updates-http.cdn-apple.com/2019FallFCS/fullrestores/061-49700/BD7C17D0-0696-11EA-970C-D191B09E16A9/iPodtouch_7_13.2.3_17B111_Restore.ipsw","images":{"Firmware/all_flash/LLB.n112.RELEASE.im4p":"85784a219eb29bcb1cc862de00a590e7f539c51a7f3403d90c9bdc62490f6b5dab4318f4633269ce3fbbe855b33a4bc7","Firmware/all_flash/iBoot.n112.RELEASE.im4p":"052e13cf2bb7802ba9d1a27046b9f9cf325d957388cd1a4325d114a5b2524391b48111c6d9768ceb29bf0b28bd21ff5c","Firmware/dfu/iBEC.n112.RELEASE.im4p":"9f2f0a3df25594d781052202e09d1a47d4211e5b5864850ee76b0dac53f785148652c17000c5e57b9e2c57040adf2c8e","Firmware/dfu/iBSS.n112.RELEASE.im4p":"e096697bb5ce030cfbe004961dde7f50e384e198e50f1e13ca532016506d71ee176ea87384e3c9e04c9afa7231dbcb4d"},"iosver":"13.2.3","kbags":{"Firmware/all_flash/LLB.n112.RELEASE.im4p":[],"Firmware/all_flash/iBoot.n112.RELEASE.im4p":[],"Firmware/dfu/iBEC.n112.RELEASE.im4p":[],"Firmware/dfu/iBSS.n112.RELEASE.im4p":[]}}' -H "Content-Type: application/json" -H "x-api-key: GENERATED_TOKEN" -A "grandmaster/0.0.1" -X POST https://foreman-public.sudosecuritygroup.com/api/submit/keybags
56 | ```
--------------------------------------------------------------------------------
/public/admin.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |