Skip to content

Commit d2207fc

Browse files
committed
Merge branch 'feature/add-auth-to-ws-20241111' into development
2 parents 6e1ba05 + f80dabc commit d2207fc

File tree

6 files changed

+292
-26
lines changed

6 files changed

+292
-26
lines changed

src/includes/main-menu.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,11 @@
716716
Documentation
717717
</a>
718718
</li>
719+
<li>
720+
<a href="./webservices/rest/ws-login.php">
721+
Login
722+
</a>
723+
</li>
719724
<li>
720725
<a href="./webservices/rest/ws-test-connectivity.php">
721726
Test Connectivity
@@ -749,6 +754,11 @@
749754
Documentation
750755
</a>
751756
</li>
757+
<li>
758+
<a href="./webservices/soap/ws-login.php">
759+
Login
760+
</a>
761+
</li>
752762
<li>
753763
<a href="">Test Pages</a>
754764
<ul>

src/set-up-database.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ function format($pMessage, $pLevel) {
229229
("CHook", "JollyRoger", "Gator-hater", false, "Captain", "Hook", "' . bin2hex(random_bytes(16)) . '", "' . bin2hex(random_bytes(32)) . '"),
230230
("james", "i<3devs", "Occupation: Researcher", false, "James", "Jardine", "' . bin2hex(random_bytes(16)) . '", "' . bin2hex(random_bytes(32)) . '"),
231231
("ed", "pentest", "Commandline KungFu anyone?", false, "Ed", "Skoudis", "' . bin2hex(random_bytes(16)) . '", "' . bin2hex(random_bytes(32)) . '"),
232+
("joe", "holly", "Off by one error", false, "Joe", "Holly", "' . bin2hex(random_bytes(16)) . '", "' . bin2hex(random_bytes(32)) . '"),
232233
("peter", "initech123", "I dont like my job", false, "Peter", "Gibbons", "' . bin2hex(random_bytes(16)) . '", "' . bin2hex(random_bytes(32)) . '"),
233234
("milton", "stapler", "Wheres my stapler?", false, "Milton", "Waddams", "' . bin2hex(random_bytes(16)) . '", "' . bin2hex(random_bytes(32)) . '"),
234235
("bill", "tpsreports", "Did you get the memo?", true, "Bill", "Lumbergh", "' . bin2hex(random_bytes(16)) . '", "' . bin2hex(random_bytes(32)) . '"),

src/webservices/soap/docs/soap-services.html

Lines changed: 106 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,22 @@
2929
a:hover {
3030
text-decoration: underline;
3131
}
32-
.note {
32+
.note, .auth-note {
3333
background-color: #e7f3fe;
3434
border-left: 6px solid #2196F3;
3535
margin: 1rem 0;
3636
padding: 1rem;
3737
}
38+
code {
39+
background-color: #f4f4f4;
40+
padding: 0.2rem 0.4rem;
41+
font-size: 0.9rem;
42+
}
43+
pre {
44+
background-color: #f4f4f4;
45+
padding: 1rem;
46+
overflow-x: auto;
47+
}
3848
</style>
3949
</head>
4050
<body>
@@ -52,17 +62,105 @@ <h2>Available SOAP Services</h2>
5262
<li><a href="ws-echo.html">WS Echo Service</a> - A simple echo service to test message transmission.</li>
5363
<li><a href="ws-test-connectivity.html">WS Test Connectivity Service</a> - Verifies connectivity with the API.</li>
5464
<li><a href="ws-user-account.html">WS User Account Service</a> - Manages user accounts (CRUD operations).</li>
65+
<li><a href="ws-login.html">WS Login Service</a> - Authenticates clients and returns a JWT for further requests.</li>
66+
</ul>
67+
68+
<h2>Understanding Security Levels and Authentication</h2>
69+
<p>This system has multiple security levels that affect access to the web services:</p>
70+
<ul>
71+
<li><strong>Security Level 0</strong> - No authentication required. You can send requests without any additional headers or tokens.</li>
72+
<li><strong>Security Level 1 or Higher</strong> - Authentication with a JWT token is required for all services except <code>ws-login</code>. You must obtain a JWT token by logging in through the <code>ws-login</code> endpoint using your <code>client_id</code> and <code>client_secret</code>.</li>
73+
</ul>
74+
75+
<div class="auth-note">
76+
<strong>Important:</strong> At security level 1 or higher, you must include a JWT token in the <code>Authorization</code> header for each request. Without a valid token, you will receive a <code>401 Unauthorized</code> error.
77+
</div>
78+
79+
<h2>Step-by-Step Guide to Using JWT Authentication</h2>
80+
<ol>
81+
<li>
82+
<strong>Log In to Obtain a JWT Token:</strong>
83+
Send a POST request to the <a href="ws-login.html">WS Login Service</a> using your <code>client_id</code> and <code>client_secret</code> to authenticate. If successful, the response will include a JWT token.
84+
<p><strong>Example (curl):</strong></p>
85+
<pre><code>curl -X POST http://mutillidae.localhost/webservices/soap/ws-login.php \
86+
-H "Content-Type: text/xml" \
87+
--data "&lt;soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' \
88+
xmlns:urn='urn:ws-login'&gt;
89+
&lt;soapenv:Header/&gt;
90+
&lt;soapenv:Body&gt;
91+
&lt;urn:login&gt;
92+
&lt;client_id&gt;your-client-id&lt;/client_id&gt;
93+
&lt;client_secret&gt;your-client-secret&lt;/client_secret&gt;
94+
&lt;audience&gt;target-audience-url&lt;/audience&gt;
95+
&lt;/urn:login&gt;
96+
&lt;/soapenv:Body&gt;
97+
&lt;/soapenv:Envelope&gt;"</code></pre>
98+
<p>The response will include a token in the format:</p>
99+
<pre><code>{
100+
"access_token": "your-jwt-token-here",
101+
"token_type": "bearer",
102+
"expires_in": 3600,
103+
"timestamp": "2024-11-17T19:30:00Z"
104+
}</code></pre>
105+
</li>
106+
107+
<li>
108+
<strong>Save the Token:</strong> Copy the JWT token from the response and store it securely. You will need to include it in the Authorization header of each authenticated request.
109+
</li>
110+
111+
<li>
112+
<strong>Include the Token in Requests:</strong> When calling any authenticated endpoint, include the token in the Authorization header using the format <code>Bearer &lt;your-token&gt;</code>.
113+
</li>
114+
115+
<h3>Examples of Making Authenticated Requests</h3>
116+
<h4>Using curl</h4>
117+
<p>Below is an example of an authenticated request using <code>curl</code>:</p>
118+
<pre><code>curl -X POST http://mutillidae.localhost/webservices/soap/ws-user-account.php \
119+
-H "Content-Type: text/xml" \
120+
-H "Authorization: Bearer &lt;your-token&gt;" \
121+
--data "&lt;soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' \
122+
xmlns:urn='urn:ws-user-account'&gt;
123+
&lt;soapenv:Header/&gt;
124+
&lt;soapenv:Body&gt;
125+
&lt;urn:getUser&gt;
126+
&lt;username&gt;john&lt;/username&gt;
127+
&lt;/urn:getUser&gt;
128+
&lt;/soapenv:Body&gt;
129+
&lt;/soapenv:Envelope&gt;"</code></pre>
130+
131+
<h4>Using Burp Suite</h4>
132+
<p>To send an authenticated request in Burp Suite:</p>
133+
<ol>
134+
<li>Open <strong>Burp Suite</strong> and navigate to the <strong>Repeater</strong> tab.</li>
135+
<li>Enter the URL in the Request line, such as:
136+
<pre><code>POST /webservices/soap/ws-user-account.php HTTP/1.1
137+
Host: mutillidae.localhost
138+
Content-Type: text/xml
139+
Authorization: Bearer your-jwt-token-here</code></pre>
140+
</li>
141+
<li>In the <strong>Headers</strong> section, ensure the Authorization header is included:
142+
<pre><code>Authorization: Bearer your-jwt-token-here</code></pre>
143+
</li>
144+
<li>Click <strong>Send</strong> to submit the request. If the token is valid, you will receive a successful response from the server.</li>
145+
</ol>
146+
</ol>
147+
148+
<h2>How to Use the Services</h2>
149+
<p>Each service page provides:</p>
150+
<ul>
151+
<li>An overview of the service functionality.</li>
152+
<li>Examples of requests using Burp Repeater and <code>curl</code>.</li>
153+
<li>Details about the expected response from the service.</li>
154+
<li>Troubleshooting tips in case of issues.</li>
55155
</ul>
56156

57-
<h2>How to Use This Documentation</h2>
58-
<p>Each service documentation page provides:</p>
157+
<h2>Troubleshooting Common Issues</h2>
59158
<ul>
60-
<li>A description of the service and its purpose.</li>
61-
<li>Supported SOAP methods with example requests and responses.</li>
62-
<li>Step-by-step guides for interacting with the service using Burp Repeater and <code>curl</code>.</li>
63-
<li>Troubleshooting tips for common issues.</li>
159+
<li><strong>401 Unauthorized:</strong> Make sure your request includes a valid JWT token in the <code>Authorization</code> header. If you haven't obtained a token yet, refer to the "Log In to Obtain a JWT Token" section.</li>
160+
<li><strong>400 Bad Request:</strong> Verify that your request follows the correct SOAP structure and all required parameters are included. Missing or incorrectly formatted parameters can cause this error.</li>
161+
<li><strong>500 Internal Server Error:</strong> This usually indicates a server-side issue. Check the SOAP response for detailed error messages and ensure the server is functioning correctly.</li>
64162
</ul>
65163

66-
<p>If you encounter any issues or have questions, feel free to reach out to your instructor or refer to the troubleshooting sections in the individual documentation pages.</p>
164+
<p>If you encounter other issues, please consult the documentation or contact support for assistance.</p>
67165
</body>
68166
</html>
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
2+
3+
<!DOCTYPE html>
4+
<html lang="en">
5+
<head>
6+
<meta charset="UTF-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>SOAP WS Login Service Documentation</title>
9+
<style>
10+
body {
11+
font-family: Arial, sans-serif;
12+
background-color: #f5f5f5;
13+
padding: 2rem;
14+
}
15+
h1, h2 {
16+
color: #2c3e50;
17+
}
18+
pre {
19+
background-color: #ecf0f1;
20+
padding: 1rem;
21+
border-radius: 5px;
22+
overflow-x: auto;
23+
}
24+
code {
25+
font-family: Consolas, "Courier New", monospace;
26+
}
27+
ul {
28+
line-height: 1.8;
29+
}
30+
.note {
31+
background-color: #e7f3fe;
32+
border-left: 6px solid #2196F3;
33+
margin: 1rem 0;
34+
padding: 1rem;
35+
}
36+
</style>
37+
</head>
38+
<body>
39+
<h1>SOAP WS Login Service Documentation</h1>
40+
<p>The <strong>SOAP WS Login Service</strong> allows clients to authenticate using their <code>client_id</code> and <code>client_secret</code>, receiving a JSON Web Token (JWT) for further interaction with secured services.</p>
41+
42+
<h2>Endpoint</h2>
43+
<pre><code>POST /webservices/soap/ws-login.php</code></pre>
44+
45+
<h2>Request Parameters</h2>
46+
<ul>
47+
<li><b>client_id</b> (string, required): A 32-character unique identifier for the client.</li>
48+
<li><b>client_secret</b> (string, required): A 64-character secret associated with the client ID.</li>
49+
<li><b>audience</b> (string, required): The intended audience for the token, typically the endpoint you want to access.</li>
50+
</ul>
51+
52+
<h2>Example Request Using Burp Repeater</h2>
53+
<p>Here’s how to send a SOAP request to the login service using Burp Repeater:</p>
54+
<pre><code>POST /webservices/soap/ws-login.php HTTP/1.1
55+
Host: mutillidae.localhost
56+
Content-Type: text/xml; charset=utf-8
57+
SOAPAction: "urn:ws-login#login"
58+
Content-Length: [length]
59+
Connection: close
60+
61+
&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
62+
xmlns:urn=&quot;urn:ws-login&quot;&gt;
63+
&lt;soapenv:Header/&gt;
64+
&lt;soapenv:Body&gt;
65+
&lt;urn:login&gt;
66+
&lt;client_id&gt;fb975a0e0248994221b3a6e87ba92fe9&lt;/client_id&gt;
67+
&lt;client_secret&gt;f1d10934f1525ebfdf0b08a2413a3a3f683eaae3913489c786e496e403ab7bff&lt;/client_secret&gt;
68+
&lt;audience&gt;http://mutillidae.localhost/webservices/soap/ws-user-account.php&lt;/audience&gt;
69+
&lt;/urn:login&gt;
70+
&lt;/soapenv:Body&gt;
71+
&lt;/soapenv:Envelope&gt;</code></pre>
72+
73+
<p><strong>Instructions:</strong></p>
74+
<ol>
75+
<li>Open Burp Suite and navigate to the Repeater tab.</li>
76+
<li>Copy the above request and paste it into the Repeater window.</li>
77+
<li>Update the <code>Content-Length</code> header to match the byte size of the body.</li>
78+
<li>Click <strong>Send</strong> to see the response.</li>
79+
</ol>
80+
81+
<h2>Example Request Using <code>curl</code></h2>
82+
<p>If you prefer using the command line, here’s how to send the same request with <code>curl</code>:</p>
83+
<pre><code>
84+
curl -X POST "http://mutillidae.localhost/webservices/soap/ws-login.php" \
85+
-H "Content-Type: text/xml; charset=utf-8" \
86+
-H "SOAPAction: "urn:ws-login#login"" \
87+
--data '&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
88+
&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:urn=&quot;urn:ws-login&quot;&gt;
89+
&lt;soapenv:Header/&gt;
90+
&lt;soapenv:Body&gt;
91+
&lt;urn:login&gt;
92+
&lt;client_id&gt;fb975a0e0248994221b3a6e87ba92fe9&lt;/client_id&gt;
93+
&lt;client_secret&gt;f1d10934f1525ebfdf0b08a2413a3a3f683eaae3913489c786e496e403ab7bff&lt;/client_secret&gt;
94+
&lt;audience&gt;http://mutillidae.localhost/webservices/soap/ws-user-account.php&lt;/audience&gt;
95+
&lt;/urn:login&gt;
96+
&lt;/soapenv:Body&gt;
97+
&lt;/soapenv:Envelope&gt;'</code></pre>
98+
99+
<p><strong>Instructions:</strong></p>
100+
<ol>
101+
<li>Open a terminal or command prompt.</li>
102+
<li>Copy and paste the above <code>curl</code> command.</li>
103+
<li>Replace <code>fb975a0e0248994221b3a6e87ba92fe9</code> and <code>f1d10934f1525ebfdf0b08a2413a3a3f683eaae3913489c786e496e403ab7bff</code> with valid values.</li>
104+
<li>Press <strong>Enter</strong> to send the request and view the response.</li>
105+
</ol>
106+
107+
<h2>Expected Response</h2>
108+
<p>Upon successful authentication, the server will respond with a JWT token:</p>
109+
<pre><code>&lt;?xml version=&quot;1.0&quot;?&gt;
110+
&lt;response&gt;
111+
&lt;access_token&gt;your-jwt-token&lt;/access_token&gt;
112+
&lt;token_type&gt;bearer&lt;/token_type&gt;
113+
&lt;expires_in&gt;3600&lt;/expires_in&gt;
114+
&lt;timestamp&gt;2024-11-18T12:00:00Z&lt;/timestamp&gt;
115+
&lt;/response&gt;</code></pre>
116+
117+
<h2>Using the JWT Token in Subsequent Requests</h2>
118+
<p>After obtaining the token, include it in the <code>Authorization</code> header for future SOAP or REST requests. For example:</p>
119+
120+
<h3>Example Using curl</h3>
121+
<p>To call an authenticated endpoint, such as <code>ws-user-account</code>:</p>
122+
<pre><code>
123+
curl -X POST "http://mutillidae.localhost/webservices/soap/ws-user-account.php" \
124+
-H "Content-Type: text/xml; charset=utf-8" \
125+
-H "SOAPAction: "urn:ws-user-account#getUser"" \
126+
-H "Authorization: Bearer your-jwt-token" \
127+
--data '&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
128+
&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:urn=&quot;urn:ws-user-account&quot;&gt;
129+
&lt;soapenv:Header/&gt;
130+
&lt;soapenv:Body&gt;
131+
&lt;urn:getUser&gt;
132+
&lt;username&gt;some-user&lt;/username&gt;
133+
&lt;/urn:getUser&gt;
134+
&lt;/soapenv:Body&gt;
135+
&lt;/soapenv:Envelope&gt;'</code></pre>
136+
137+
<h3>Example Using Burp Repeater</h3>
138+
<p>To include the token in Burp Suite:</p>
139+
<ol>
140+
<li>Paste the token in the <code>Authorization</code> header of your request:</li>
141+
<pre><code>Authorization: Bearer your-jwt-token</code></pre>
142+
<li>Send the request to a secured endpoint.</li>
143+
</ol>
144+
145+
<div class="note">
146+
<strong>Troubleshooting Tips:</strong>
147+
<ul>
148+
<li>Ensure the <code>SOAPAction</code> header matches the registered action for the service.</li>
149+
<li>Check for proper XML formatting and valid <code>client_id</code> and <code>client_secret</code> values.</li>
150+
<li>If authentication fails, verify the <code>audience</code> matches a valid endpoint.</li>
151+
</ul>
152+
</div>
153+
</body>
154+
</html>

src/webservices/soap/docs/ws-user-account.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ <h4>Burp Repeater Request:</h4>
181181
&lt;soapenv:Header/&gt;
182182
&lt;soapenv:Body&gt;
183183
&lt;urn:deleteUser&gt;
184-
&lt;username&gt;Joe&lt;/username&gt;
185-
&lt;password&gt;Holly&lt;/password&gt;
184+
&lt;username&gt;joe&lt;/username&gt;
185+
&lt;password&gt;holly&lt;/password&gt;
186186
&lt;/urn:deleteUser&gt;
187187
&lt;/soapenv:Body&gt;
188188
&lt;/soapenv:Envelope&gt;
@@ -197,8 +197,8 @@ <h4>curl Command:</h4>
197197
&lt;soapenv:Header/&gt;
198198
&lt;soapenv:Body&gt;
199199
&lt;urn:deleteUser&gt;
200-
&lt;username&gt;Joe&lt;/username&gt;
201-
&lt;password&gt;Holly&lt;/password&gt;
200+
&lt;username&gt;joe&lt;/username&gt;
201+
&lt;password&gt;holly&lt;/password&gt;
202202
&lt;/urn:deleteUser&gt;
203203
&lt;/soapenv:Body&gt;
204204
&lt;/soapenv:Envelope&gt;"

0 commit comments

Comments
 (0)