Skip to content

Commit 79994aa

Browse files
authored
Merge pull request #78 from commjoen/fix-vulns
Check teamname before proxy & make hmackey configurable per deployment
2 parents 891f36d + e5373c4 commit 79994aa

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

helm/wrongsecrets-ctf-party/templates/wrongsecrets-balancer/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ spec:
6060
value: {{ .Values.wrongsecrets.tag}}
6161
- name: WRONGSECRETS_DESKTOP_TAG
6262
value: 1.5.7RC1
63+
- name: REACT_APP_CREATE_TEAM_HMAC_KEY
64+
value: hardcodedkey
6365
- name: SECRETS_MANAGER_SECRET_ID_1
6466
value: {{ .Values.balancer.env.SECRETS_MANAGER_SECRET_ID_1 }}
6567
- name: SECRETS_MANAGER_SECRET_ID_2

wrongsecrets-balancer/src/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ app.get('/balancer/dynamics', (req, res) => {
6666
heroku_wrongsecret_ctf_url: process.env['REACT_APP_HEROKU_WRONGSECRETS_URL'],
6767
ctfd_url: process.env['REACT_APP_CTFD_URL'],
6868
s3_bucket_url: process.env['REACT_APP_S3_BUCKET_URL'],
69+
hmac_key: process.env['REACT_APP_CREATE_TEAM_HMAC_KEY'],
6970
enable_password: usePassword,
7071
});
7172
});

wrongsecrets-balancer/src/proxy/proxy.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ async function updateLastConnectTimestamp(req, res, next) {
105105
*/
106106
function proxyTrafficToJuiceShop(req, res) {
107107
const teamname = req.teamname;
108-
//TODO: FIX THE PORT!
108+
const regex = new RegExp('^[a-z0-9]([-a-z0-9])+[a-z0-9]$', 'i');
109+
if (!regex.test(teamname)) {
110+
logger.info(`Got malformed teamname: ${teamname}s`);
111+
return res.redirect('/balancer/');
112+
}
109113
const currentReferrerForDesktop = '/?desktop';
110114
logger.debug(
111115
`Proxying request ${req.method.toLocaleUpperCase()} ${
@@ -126,7 +130,6 @@ function proxyTrafficToJuiceShop(req, res) {
126130
req.path === '/files/socket.io/' ||
127131
req.path === '/files/socket.io/socket.io.js.map'
128132
) {
129-
// logger.info('we have a desktop entry for team ' + teamname);
130133
target = {
131134
target: `http://${teamname}-virtualdesktop.${teamname}.svc:8080`,
132135
ws: true,
@@ -139,7 +142,6 @@ function proxyTrafficToJuiceShop(req, res) {
139142
}
140143
logger.info(`we got ${teamname} requesting ${target.target}`);
141144

142-
//TODO: FIX THAT THIS WILL WORK IN THE FUTURE!
143145
if (req.path === '/guaclite') {
144146
let server = res.socket.server;
145147
logger.info('putting ws through for /quaclite');
@@ -158,6 +160,11 @@ function proxyTrafficToJuiceShop(req, res) {
158160
});
159161
server.on('connect', function (req, socket, head) {
160162
const connectTeamname = extractTeamName(req);
163+
const regex = new RegExp('^[a-z0-9]([-a-z0-9])+[a-z0-9]$', 'i');
164+
if (!regex.test(connectTeamname)) {
165+
logger.info(`Got malformed teamname: ${teamname}s`);
166+
return res.redirect('/balancer/');
167+
}
161168
logger.info(`proxying upgrade request for: ${req.url} with team ${connectTeamname}`);
162169
proxy.ws(req, socket, head, {
163170
target: `ws://${connectTeamname}-virtualdesktop.${connectTeamname}.svc:8080`,

wrongsecrets-balancer/src/teams/teams.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const Joi = require('@hapi/joi');
77
const expressJoiValidation = require('express-joi-validation');
88
const promClient = require('prom-client');
99
const accessPassword = process.env.REACT_APP_ACCESS_PASSWORD;
10+
const hmac_key = process.env.REACT_APP_CREATE_TEAM_HMAC_KEY || 'hardcodedkey';
1011

1112
const validator = expressJoiValidation.createValidator();
1213
const k8sEnv = process.env.K8S_ENV || 'k8s';
13-
1414
const router = express.Router();
1515

1616
const {
@@ -96,7 +96,7 @@ async function validateHMAC(req, res, next) {
9696
const { team } = req.params;
9797
const { hmacvalue } = req.body;
9898
const validationValue = crypto
99-
.createHmac('sha256', 'hardcodedkey')
99+
.createHmac('sha256', hmac_key)
100100
.update(`${team}`, 'utf-8')
101101
.digest('hex');
102102
if (validationValue === hmacvalue) {

wrongsecrets-balancer/ui/src/pages/JoinPage.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const JoinPage = injectIntl(({ intl }) => {
5858
}
5959
if (dynamics.enable_password) {
6060
const hmacvalue = cryptoJS
61-
.HmacSHA256(`${teamname}`, 'hardcodedkey')
61+
.HmacSHA256(`${teamname}`, dynamics.hmac_key)
6262
.toString(cryptoJS.enc.Hex);
6363
const { data } = await axios.post(`/balancer/teams/${teamname}/join`, {
6464
passcode,
@@ -68,7 +68,7 @@ export const JoinPage = injectIntl(({ intl }) => {
6868
navigate(`/teams/${teamname}/joined/`, { state: { passcode: data.passcode } });
6969
} else {
7070
const hmacvalue = cryptoJS
71-
.HmacSHA256(`${teamname}`, 'hardcodedkey')
71+
.HmacSHA256(`${teamname}`, dynamics.hmac_key)
7272
.toString(cryptoJS.enc.Hex);
7373
const { data } = await axios.post(`/balancer/teams/${teamname}/join`, {
7474
passcode,
@@ -99,6 +99,7 @@ export const JoinPage = injectIntl(({ intl }) => {
9999
heroku_wrongsecret_ctf_url: process.env['REACT_APP_HEROKU_WRONGSECRETS_URL'],
100100
ctfd_url: process.env['REACT_APP_CTFD_URL'],
101101
s3_bucket_url: process.env['REACT_APP_S3_BUCKET_URL'],
102+
hmac_key: process.env['REACT_APP_CREATE_TEAM_HMAC_KEY'],
102103
enable_password: false,
103104
};
104105

0 commit comments

Comments
 (0)