Skip to content

Commit 5a5fea7

Browse files
adding more challenges
1 parent 265c8cf commit 5a5fea7

File tree

160 files changed

+42431
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+42431
-0
lines changed

dockerfiles/jailbreak/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Stage: UI
2+
FROM node:12.18-alpine as ui
3+
4+
# Create app directory
5+
WORKDIR /app
6+
7+
# Bundle app source
8+
COPY . /app/
9+
10+
# Disable Source Map
11+
ENV GENERATE_SOURCEMAP=false
12+
13+
# Install packages
14+
RUN npm install
15+
RUN npm run build
16+
17+
18+
# Stage: Core
19+
FROM nginx:1.19-alpine
20+
COPY nginx.conf /etc/nginx/conf.d/default.conf
21+
# Copy ui
22+
COPY --from=ui /app/build/ /usr/share/nginx/html
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import json
2+
import boto3
3+
import os
4+
5+
PRISONERS = {
6+
1: "Next time I see you, remind me not to talk to you.",
7+
2: "I never forget a face, but in your case I'll be glad to make an exception.",
8+
3: os.environ['Flag']
9+
}
10+
11+
12+
def get_user(access_key, prisoner=None):
13+
client = boto3.client('cognito-idp')
14+
try:
15+
response = client.get_user(AccessToken=access_key)
16+
except:
17+
return wrap_response(299, {
18+
'text': 'The server has accepted your request but thinks you can Try Harder!'
19+
})
20+
for name in response['UserAttributes']:
21+
if 'iswarden' in name['Name'].lower():
22+
if name['Value'] == '0':
23+
return wrap_response(403, {
24+
'text': 'Only the warden is allowed!'
25+
})
26+
elif name['Value'] == '1':
27+
if prisoner is not None:
28+
prisoner = dict((k.lower(), v) for k, v in json.loads(prisoner).items())
29+
if "prisoner" in prisoner and prisoner["prisoner"].isdigit():
30+
prisoner = int(prisoner["prisoner"])
31+
if 1 <= prisoner <= len(PRISONERS):
32+
return wrap_response(200,
33+
{'text': PRISONERS[prisoner]})
34+
return wrap_response(400, {
35+
'text': "Prisoner was not found"
36+
})
37+
return wrap_response(451, {
38+
'text': "Unavailable For Legal Reasons, Stop messing around!"
39+
})
40+
return wrap_response(200, {
41+
"text": "Hello Warden"
42+
})
43+
return wrap_response(401, {
44+
'text': 'Authentication Failed'
45+
})
46+
47+
48+
def wrap_response(code, res=None):
49+
return {
50+
'statusCode': code,
51+
'body': json.dumps(res) if res is not None else None,
52+
'headers': {
53+
"Content-Type": "application/json",
54+
"Access-Control-Allow-Origin": "*",
55+
"Access-Control-Allow-Methods": "OPTIONS, POST",
56+
"Access-Control-Allow-Headers": "Access-Control-Allow-Origin, "
57+
"Access-Control-Allow-Methods, Content-Type, authorization"
58+
}
59+
}
60+
61+
62+
def lambda_handler(event, _):
63+
if event["httpMethod"] == "OPTIONS":
64+
return wrap_response(200)
65+
try:
66+
if event["httpMethod"] == "POST":
67+
headers = {k.lower(): v for k, v in event["headers"].items()}
68+
if "body" in event:
69+
return get_user(headers["authorization"], event["body"])
70+
else:
71+
return get_user(event["authorization"])
72+
except:
73+
return wrap_response(500, {
74+
'text': 'Not Authorized!'
75+
})
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import os
2+
import hmac
3+
import json
4+
import boto3
5+
import base64
6+
import hashlib
7+
8+
# Global Variables
9+
APP_CLIENT_ID = os.environ['APP_CLIENT_ID']
10+
APP_CLIENT_SECRET = os.environ['APP_CLIENT_SECRET']
11+
12+
13+
def get_secret_hash(username):
14+
digest = hmac.new(
15+
str(APP_CLIENT_SECRET).encode('utf-8'),
16+
msg=str(username + APP_CLIENT_ID).encode('utf-8'),
17+
digestmod=hashlib.sha256
18+
).digest()
19+
return base64.b64encode(digest).decode()
20+
21+
22+
def wrap_response(status_code, res=None):
23+
return {
24+
'statusCode': status_code,
25+
'body': json.dumps(res) if res is not None else None,
26+
'headers': {
27+
"Content-Type": "application/json",
28+
"Access-Control-Allow-Origin": "*",
29+
"Access-Control-Allow-Methods": "OPTIONS, POST",
30+
"Access-Control-Allow-Headers": "Access-Control-Allow-Origin, Access-Control-Allow-Methods, Content-Type"
31+
}
32+
}
33+
34+
35+
def authenticate_user(username, password):
36+
credentials = {
37+
'USERNAME': username.lower(),
38+
'SECRET_HASH': get_secret_hash(username.lower()),
39+
'PASSWORD': password
40+
}
41+
try:
42+
client = boto3.client('cognito-idp', region_name=os.environ['AWS_REGION'])
43+
response = client.initiate_auth(AuthFlow='USER_PASSWORD_AUTH',
44+
AuthParameters=credentials, ClientId=APP_CLIENT_ID)
45+
except Exception as e:
46+
if "attempts exceeded" in str(e).split("operation: ")[1]:
47+
return wrap_response(299, {
48+
'text': 'Violence is not the solution!',
49+
'isSuccees': False
50+
})
51+
return wrap_response(401, {
52+
'text': str(e).split("operation: ")[1],
53+
'isSuccees': False
54+
})
55+
if response and 'AccessToken' in response['AuthenticationResult'] and 'IdToken' in response['AuthenticationResult']:
56+
return wrap_response(200, {
57+
'isSuccees': True,
58+
'AccessToken': response['AuthenticationResult']['AccessToken'],
59+
'IdToken': response['AuthenticationResult']['IdToken']
60+
})
61+
return wrap_response(401, {
62+
'text': 'Authentication Failed',
63+
'isSuccees': False
64+
})
65+
66+
67+
def lambda_handler(event, _):
68+
if event["httpMethod"] == "OPTIONS":
69+
return wrap_response(200)
70+
try:
71+
if event["httpMethod"] == "POST":
72+
auth_data = dict((k.lower(), v) for k, v in json.loads(event["body"]).items())
73+
if "username" not in auth_data or "password" not in auth_data:
74+
return wrap_response(500, {
75+
'text': 'Please fill username and password.',
76+
'isSuccees': False
77+
})
78+
return authenticate_user(auth_data["username"], auth_data["password"])
79+
except:
80+
return wrap_response(500, {
81+
'text': 'Please fill username and password.',
82+
'isSuccees': False
83+
})
84+
return wrap_response(2)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import boto3
3+
4+
5+
def lambda_handler(event, context):
6+
client = client = boto3.client('cognito-idp')
7+
try:
8+
client.admin_get_user(
9+
UserPoolId=os.environ['UserPoolId'],
10+
Username='marx'
11+
)
12+
except:
13+
client.admin_create_user(
14+
UserPoolId=os.environ['UserPoolId'],
15+
Username='marx',
16+
UserAttributes=[
17+
{
18+
'Name': 'custom:isWarden',
19+
'Value': '0'
20+
},
21+
]
22+
)
23+
client.admin_set_user_password(
24+
UserPoolId=os.environ['UserPoolId'],
25+
Username='marx',
26+
Password='Jailbreak',
27+
Permanent=True
28+
)
29+
return event

dockerfiles/jailbreak/nginx.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
5+
location / {
6+
root /usr/share/nginx/html;
7+
index index.html index.htm;
8+
try_files $uri /index.html;
9+
}
10+
11+
error_page 500 502 503 504 /50x.html;
12+
location = /50x.html {
13+
root /usr/share/nginx/html;
14+
}
15+
}
16+

dockerfiles/jailbreak/package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "untitled3",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@testing-library/jest-dom": "^4.2.4",
7+
"@testing-library/react": "^9.3.2",
8+
"@testing-library/user-event": "^7.1.2",
9+
"axios": "^0.19.2",
10+
"bootstrap": "^4.5.0",
11+
"jwt-decode": "^2.2.0",
12+
"material-ui": "^0.20.2",
13+
"react": "^16.13.1",
14+
"react-bootstrap": "^1.0.1",
15+
"react-dom": "^16.13.1",
16+
"react-router": "^5.2.0",
17+
"react-router-dom": "^5.2.0",
18+
"react-scripts": "3.4.1",
19+
"react-tap-event-plugin": "^3.0.3",
20+
"react-router": "latest"
21+
},
22+
"scripts": {
23+
"start": "react-scripts start",
24+
"build": "react-scripts build",
25+
"test": "react-scripts test",
26+
"eject": "react-scripts eject"
27+
},
28+
"eslintConfig": {
29+
"extends": "react-app"
30+
},
31+
"browserslist": {
32+
"production": [
33+
">0.2%",
34+
"not dead",
35+
"not op_mini all"
36+
],
37+
"development": [
38+
"last 1 chrome version",
39+
"last 1 firefox version",
40+
"last 1 safari version"
41+
]
42+
}
43+
}
264 KB
Binary file not shown.
425 KB
Loading
787 KB
Loading
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta
9+
name="description"
10+
content="Web site created using create-react-app"
11+
/>
12+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13+
<!--
14+
manifest.json provides metadata used when your web app is installed on a
15+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16+
-->
17+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18+
<!--
19+
Notice the use of %PUBLIC_URL% in the tags above.
20+
It will be replaced with the URL of the `public` folder during the build.
21+
Only files inside the `public` folder can be referenced from the HTML.
22+
23+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24+
work correctly both with client-side routing and a non-root public URL.
25+
Learn how to configure a non-root public URL by running `npm run build`.
26+
-->
27+
<title>Welcome to the Jail!</title>
28+
</head>
29+
<body>
30+
<noscript>You need to enable JavaScript to run this app.</noscript>
31+
<div id="root"></div>
32+
<!--
33+
This HTML file is a template.
34+
If you open it directly in the browser, you will see an empty page.
35+
36+
You can add webfonts, meta tags, or analytics to this file.
37+
The build step will place the bundled scripts into the <body> tag.
38+
39+
To begin the development, run `npm start` or `yarn start`.
40+
To create a production bundle, use `npm run build` or `yarn build`.
41+
-->
42+
</body>
43+
</html>
6.74 KB
Loading
6.74 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
19+
}
20+
],
21+
"start_url": ".",
22+
"display": "standalone",
23+
"theme_color": "#000000",
24+
"background_color": "#ffffff"
25+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:

dockerfiles/jailbreak/src/App.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.App {
2+
text-align: center;
3+
}

0 commit comments

Comments
 (0)