-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from sdslabs/kissaki
Kissaki
- Loading branch information
Showing
77 changed files
with
1,253 additions
and
771 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ vendor/* | |
teams/* | ||
teamcreds.txt | ||
lib/harbor/certs/* | ||
sam/ | ||
work.txt | ||
sam.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
[submodule "katana-services"] | ||
path = katana-services | ||
url = [email protected]:sdslabs/katana-services.git | ||
[submodule "[email protected]:sdslabs/katana-services.git"] | ||
branch = main |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
challenge_template/knock/knock-challenge-checker/knock-challenge-checker.txt
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM ubuntu:20.04 | ||
|
||
RUN apt-get update | ||
RUN apt-get install -y python3 python3-pip curl | ||
|
||
WORKDIR /opt/kissaki/ | ||
COPY . . | ||
|
||
RUN pip3 install -r requirements.txt | ||
|
||
CMD ["/bin/bash", "-c", "python3 /opt/kissaki/app.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import requests | ||
import time | ||
from flask import Flask, jsonify | ||
import os | ||
from kubernetes import client, config | ||
import logging | ||
|
||
# app = Flask(__name__) | ||
|
||
# Set up logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
try: | ||
config.load_incluster_config() | ||
except config.config_exception.ConfigException: | ||
try: | ||
config.load_kube_config() | ||
except config.config_exception.ConfigException: | ||
raise | ||
|
||
v1 = client.CoreV1Api() | ||
service = v1.read_namespaced_service(name="kissaki-svc", namespace="katana") | ||
cluster_ip = service.spec.cluster_ip | ||
ports = service.spec.ports | ||
port = ports[0].port | ||
|
||
|
||
# @app.route("/") | ||
def hello(): | ||
return "Hello, world!" | ||
|
||
|
||
# @app.route("/test") | ||
def test_challenge_checker(): | ||
res = ( | ||
"making request to " | ||
+ "http://" | ||
+ str(cluster_ip) | ||
+ ":" | ||
+ str(port) | ||
+ "/register " | ||
) | ||
return res | ||
|
||
|
||
# @app.route("/register") | ||
def register_challenge_checker(): | ||
logging.info( | ||
"making request to " | ||
+ "http://" | ||
+ str(cluster_ip) | ||
+ ":" | ||
+ str(port) | ||
+ "/register " | ||
) | ||
|
||
# Register with kissaki | ||
checker_info = { | ||
"name": "knock-challenge-checker", | ||
"challenge": "knock", | ||
} # Example info | ||
|
||
response = requests.post( | ||
"http://" + str(cluster_ip) + ":" + str(port) + "/register", | ||
json=checker_info, | ||
) | ||
message = response.json().get("message") | ||
|
||
logging.info(f"Received message from kissaki: {message}") | ||
|
||
return "challenge_checker registered in kissaki" | ||
|
||
|
||
# @app.route("/check") | ||
def check_challenge(): | ||
for i in range(10): | ||
# TODO: Implement challenge checking logic | ||
challenge_status = {"status": "OK"} # Example status | ||
|
||
# Send status to kissaki service | ||
response = requests.post( | ||
"http://" + str(cluster_ip) + ":" + str(port) + "/status", | ||
json=challenge_status, | ||
) | ||
message = response.json().get("message") | ||
logging.info(f"Received message from kissaki: {message}") | ||
|
||
time.sleep(10) # Check every 10 seconds | ||
|
||
return jsonify(challenge_status) | ||
|
||
|
||
# if __name__ == "__main__": | ||
# app.run(host="0.0.0.0", port=8080) |
1 change: 1 addition & 0 deletions
1
challenges-sample/knock/challenge-checker/challenge-checker.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
challenge checker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
kubernetes | ||
flask | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
contains informations about schedules |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
flag getter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
flag setter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[challenge.author] | ||
name = "paradox" | ||
email = "[email protected]" | ||
|
||
[challenge.metadata] | ||
name = "knock" | ||
flag = "dice{1_d00r_y0u_d00r_w3_a11_d00r_f0r_1_d00r}" | ||
description = "Knock knock? Who's there? Another pastebin!!" | ||
type = "web" | ||
points = 100 | ||
|
||
[challenge.env] | ||
port_mappings = ["3000:3000"] |
15 changes: 15 additions & 0 deletions
15
challenges-sample/the-varsity/challenge-checker/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM ubuntu:20.04 | ||
|
||
RUN apt-get update | ||
RUN apt-get install -y python3 python3-pip curl | ||
|
||
WORKDIR /opt/kissaki/ | ||
COPY . . | ||
|
||
RUN pip3 install -r requirements.txt | ||
|
||
# this arg is not being passed need to fix that.------------------------ | ||
ARG chall_name | ||
ENV CHALL_NAME=$chall_name | ||
|
||
CMD ["/bin/bash", "-c", "python3 /opt/kissaki/app.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
import requests | ||
import time | ||
from flask import Flask, jsonify | ||
import os | ||
from kubernetes import client, config | ||
import logging | ||
|
||
import chall_checker # import the module containing the script | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
chall_name = os.environ.get("CHALL_NAME") | ||
chall_name = chall_name[:-3] | ||
chall_name = "the-varsity" # fix this later | ||
# kissaki | ||
svc_name = "kissaki-svc" | ||
namespace = "katana" | ||
team_count = 2 # ----------harcoded for now, need to fix this | ||
# Set up logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
try: | ||
config.load_incluster_config() | ||
except config.config_exception.ConfigException: | ||
try: | ||
config.load_kube_config() | ||
except config.config_exception.ConfigException: | ||
raise | ||
|
||
# v1 = client.CoreV1Api() | ||
# service = v1.read_namespaced_service(name=svc_name, namespace=namespace) | ||
# # cluster_ip = service.spec.cluster_ip | ||
# ports = service.spec.ports | ||
# port = ports[0].port | ||
|
||
v1 = client.CoreV1Api() | ||
|
||
|
||
def service_port(svc, ns): | ||
service = v1.read_namespaced_service(name=svc, namespace=ns) | ||
# cluster_ip = service.spec.cluster_ip | ||
ports = service.spec.ports | ||
port = ports[0].port | ||
return port | ||
|
||
|
||
@app.route("/") | ||
def hello(): | ||
logging.info(chall_name) | ||
return "Hello, world!" | ||
|
||
|
||
@app.route("/test") | ||
def test_challenge_checker(): | ||
res = ( | ||
"making request to " | ||
+ "http://" | ||
+ svc_name | ||
+ "." | ||
+ namespace | ||
+ ".svc.cluster.local:" | ||
+ str(service_port(svc_name, namespace)) | ||
+ "/register " | ||
) | ||
return res | ||
|
||
|
||
# @app.route("/register") | ||
# def register_challenge_checker(): | ||
# logging.info( | ||
# "making request to " | ||
# + "http://" | ||
# + str(cluster_ip) | ||
# + ":" | ||
# + str(port) | ||
# + "/register " | ||
# ) | ||
|
||
# # Register with kissaki | ||
# checker_info = { | ||
# "name": "knock-challenge-checker", | ||
# "challenge": "knock", | ||
# } # Example info | ||
|
||
# response = requests.post( | ||
# "http://" + str(cluster_ip) + ":" + str(port) + "/register", | ||
# json=checker_info, | ||
# ) | ||
# message = response.json().get("message") | ||
|
||
# logging.info(f"Received message from kissaki: {message}") | ||
|
||
# return "challenge_checker registered in kissaki" | ||
|
||
|
||
@app.route("/register") | ||
def register_challenge_checker(): | ||
logging.info( | ||
"making request to " | ||
+ "http://" | ||
+ svc_name | ||
+ "." | ||
+ namespace | ||
+ ".svc.cluster.local:" | ||
+ str(service_port(svc_name, namespace)) | ||
+ "/register " | ||
) | ||
|
||
# Register with kissaki | ||
# keys in checker_info are harcoded if changed here then some change may be needed in katana-services/Kissaki/src/app.py | ||
checker_info = {"ccName": chall_name + "-cc"} | ||
|
||
response = requests.post( | ||
"http://" | ||
+ svc_name | ||
+ "." | ||
+ namespace | ||
+ ".svc.cluster.local:" | ||
+ str(service_port(svc_name, namespace)) | ||
+ "/register", | ||
json=checker_info, | ||
) | ||
message = response.json().get("message") | ||
|
||
logging.info(f"Received message from kissaki: {message}") | ||
|
||
return "challenge_checker registered in kissaki" | ||
|
||
|
||
# {service_port(chall_svc, chall_ns)} | ||
@app.route("/check") | ||
def check_challenge(): | ||
i = 0 | ||
chall_svc = f"{chall_name}-svc-{i}" | ||
chall_ns = f"katana-team-{i}-ns" | ||
url = f"http://{chall_svc}.{chall_ns}.svc.cluster.local:80/" | ||
return url | ||
try: | ||
status = chall_checker.check_challenge(url) | ||
return status | ||
except Exception as e: | ||
logging.error(f"Error checking challenge: {str(e)}") | ||
return str(e) | ||
|
||
|
||
@app.route("/checker") | ||
def check_route(): | ||
results = {"challengeName": chall_name, "data": []} | ||
for i in range(team_count): | ||
team_name = f"katana-team-{i}" | ||
result = {"team-name": team_name} | ||
chall_svc = f"{chall_name}-svc-{i}" | ||
chall_ns = f"katana-team-{i}-ns" | ||
url = f"http://{chall_svc}.{chall_ns}.svc.cluster.local:80/" # update this later ---port should not be hardcoded---- | ||
try: | ||
status = chall_checker.check_challenge(url) | ||
result["status"] = status | ||
except Exception as e: | ||
logging.error(f"Error checking challenge: {str(e)}") | ||
result["error"] = str(e) | ||
results["data"].append(result) | ||
return jsonify(results) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(host="0.0.0.0", port=8080) |
Oops, something went wrong.