Skip to content

Commit

Permalink
PNG_CTF
Browse files Browse the repository at this point in the history
Wind010 committed Mar 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent cb852c5 commit 3dc46c9
Showing 15 changed files with 371 additions and 20 deletions.
Binary file added PNG_CTF/assets/deny.mp3
Binary file not shown.
Binary file added PNG_CTF/assets/error.mp3
Binary file not shown.
Binary file added PNG_CTF/assets/wub.mp3
Binary file not shown.
86 changes: 86 additions & 0 deletions PNG_CTF/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
body {
background-color: #212121;
margin: 10px;
overflow: hidden;
}

#box {
position: relative;
margin: 0 auto;
border: 1px solid #ccc;
padding: 0px;
border-radius: 4px;
width: 250px;
height: 42px;
}

#form {
height: 40px;
background-color: #fff;
overflow: hidden
}

#user_in {
font-size: 14px;
color: #54e325;
border-width: 0;
background: transparent;
line-height: 15px
}

#box input[type="text"],
#box input[type="number"] {
width: 90%;
padding: 12px 0 5px 0;
color: #6ff347;
outline: none;
}

#submit-button {
position: absolute;
top: 1px;
right: 1px;
bottom: 1px;

height: 40px;
width: 80px;
color: #fff;
text-align: center;
border-width: 0;
background-color: #36ba01;
cursor: pointer;
text-transform: uppercase;
border-radius: 3px;
outline: 0;
}

#submit-button:hover {
background: #00ff2b
}


.container {
display: flex;
justify-content: center;
/* Center horizontally */
align-items: center;
/* Center vertically */
height: 100vh;
/* Adjust as needed */
}

img {
max-width: 100%;
max-height: 100%;
position:absolute;
z-index: 2;
}

canvas {
width: 100%;
height: 100%;
position: absolute;
top: 80px;
left: 0px;
z-index: 1;
}
44 changes: 44 additions & 0 deletions PNG_CTF/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!--
Inspired by John Johnson's CTF
Engineered the reverse engineered the javascript code.
-->
<html>

<head>
<link rel="stylesheet" href="css/main.css">
<script src="https://code.jquery.com/jquery-3.7.1.slim.min.js"
integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8=" crossorigin="anonymous">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/101/three.min.js"
integrity="sha512-MzluaiqTHieej9sKOtlT5D5uog5n278iCAX/sr8Ms271OkiKptg1RZgRXRjhQ+v4yO3LcffdeeQfiUfMpduqeA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script src="https://cdn.jsdelivr.net/npm/@tsparticles/[email protected]/tsparticles.confetti.bundle.min.js"></script>

<script src="js/flag.js"></script>
<!--<script src="js/flag_small.js"></script>-->
<script src="js/particles.js"></script>
<script src="js/effects.js"></script>
<script src="js/ctf.js"></script>

<body>

<center>
<div id="box">
<form id="ctf_form" action="#i_pass_butter"
onsubmit="assemble_png(document.getElementById('user_in').value)">
<input id="user_in" type="text">
<!-- <input id="user_in" type="number" maxlength="16"> -->
<button id='submit-button' type='submit' title="Submit the Key"><span>🗝️</span></button>

</form>
</div>

<div class="container">
<img id="image" src="" />
</div>
</center>

</body>

</html>
42 changes: 42 additions & 0 deletions PNG_CTF/js/ctf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var bytes = [];

// TODO: API
if (resp) {
bytes = Array.from(resp.split(" "), x => Number(x));
}
else {
$.get("bytes", function (resp) {
bytes = Array.from(resp.split(" "), x => Number(x));
});
}


function assemble_png(u_in) {
var LEN = 16;
var key = "0000000000000000";
var shifter;

if (u_in == "particles") {
run();
return;
}

if (u_in.length == LEN) {
key = u_in;
}

var result = [];
for (var i = 0; i < LEN; i++) {
shifter = key.charCodeAt(i) - 48;
for (var j = 0; j < (bytes.length / LEN); j++) {
result[(j * LEN) + i] = bytes[(((j + shifter) * LEN) % bytes.length) + i]
}
}
while (result[result.length - 1] == 0) {
result = result.slice(0, result.length - 1);
}
document.getElementById("image").src = "data:image/png;base64,"
+ btoa(String.fromCharCode.apply(null, new Uint8Array(result)));
return false;
}

57 changes: 57 additions & 0 deletions PNG_CTF/js/effects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function congratulations() {
const defaults = {
spread: 360,
ticks: 100,
gravity: 0,
decay: 0.94,
startVelocity: 30,
};

function shoot() {
confetti({
...defaults,
particleCount: 30,
scalar: 1.2,
shapes: ["circle", "square"],
colors: ["#a864fd", "#29cdff", "#78ff44", "#ff718d", "#fdff6a"],
});

confetti({
...defaults,
particleCount: 60,
scalar: 2,
shapes: ["emoji"],
shapeOptions: {
emoji: {
value: ["🐱‍💻", "🌈", "🖖", "💎", "👩‍💻", "⚡", "🚀"],
},
},
});
}

setTimeout(shoot, 0);
setTimeout(shoot, 100);
setTimeout(shoot, 200);
}


window.addEventListener('load', function () {
var img = document.getElementById('image');

img.onload = function () {
console.log('Image loaded successfully.');
congratulations();
assets = ["https://wind010.github.io/ctf_soundboard/assets/3.wav", "assets/wub.mp3"]
var audio = new Audio(assets[Math.floor(Math.random() * assets.length)]);
audio.play();
};

img.onerror = function () {
console.log('Error loading image.');
assets = ["assets/error.mp3", "assets/deny.mp3"]
var audio = new Audio(assets[Math.floor(Math.random() * assets.length)]);
audio.play();
};
})


1 change: 1 addition & 0 deletions PNG_CTF/js/flag.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions PNG_CTF/js/flag_small.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions PNG_CTF/js/particles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
function run() {
//threejs - demo - https://threejs.org/examples/?q=particles#webgl_points_billboards
//var container = document.createElement('div');
//document.body.appendChild(container);

var container = document.getElementsByTagName('body')[0]

var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 3000)
camera.position.z = 1000; // Pull this back to 2000 to see what is actually going on

var scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x41ac17, 0.0020); // color of fog - objects are all white
var geometry = new THREE.Geometry();

for (i = 0; i < 20000; i++) // Total objects within each particle object
{ //-1000 is for centering on screen, span would be -1000 to 1000
var vertex = new THREE.Vector3();
vertex.x = Math.random() * 2000 - 1000;
vertex.y = Math.random() * 2000 - 1000;
vertex.z = Math.random() * 2000 - 1000;
geometry.vertices.push(vertex);
}

for (i = 0; i < getRandomNumber(1, 10); i++) {
var material = new THREE.PointsMaterial({ size: getRandomNumber() });
var particles = new THREE.Points(geometry, material);
particles.rotation.x = getRandomNumber();
particles.rotation.y = getRandomNumber();
particles.rotation.z = getRandomNumber();
scene.add(particles);
}

////////////////////////////////////////////////////////////////

var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);

renderer.render(scene, camera);
render();

function render() {
camera.position.z = generateSmoothNumber() // Zoom in and out via sine wave logic.
requestAnimationFrame(render);
for (i = 0; i < scene.children.length; i++) {
var object = scene.children[i];
if (object instanceof THREE.Points) {
object.rotation.y += .0033;
}
}
renderer.render(scene, camera);
}
}

function getRandomNumber(min=1, max=10) {
// Generate a random decimal number between 0 and 1
var randomNumber = Math.random();

// Scale the random number to be between min and max
var scaledNumber = Math.floor(randomNumber * (max - min + 1)) + min;

return scaledNumber;
}


function generateSmoothNumber(min= 100, max=2500) {
// Get the current timestamp in milliseconds
const timestamp = new Date().getTime();

// Calculate a value between 0 and 1 based on sine function
const value = Math.sin(timestamp / 10000); // Adjust the divisor to control the smoothness

// Map the value from the range [-1, 1] to the range [min, max]
const smoothNumber = value * (max - min) / 2 + (max + min) / 2;

return smoothNumber;
}


window.addEventListener('load', function () {
//run();
});

window.addEventListener('resize', onWindowResize, false);
function onWindowResize() {
if (typeof camera === 'undefined') {
return;
}
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();

renderer.setSize(window.innerWidth, window.innerHeight);

}
4 changes: 4 additions & 0 deletions PNG_CTF/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Some future PTO

TODO:
* API to provide generated bytes.
7 changes: 4 additions & 3 deletions SSH_Server/Dockerfile
Original file line number Diff line number Diff line change
@@ -6,8 +6,9 @@ ENV CTF=$CTF

# Install SSH server and any other dependencies.
# If behind corporate firewall, may need --no-check-certificate
RUN apk update && apk upgrade \
&& apk add openssh cmatrix \
RUN apk update --no-check-certificate && apk upgrade --no-check-certificate \
&& apk add openssh --no-check-certificate \
&& apk add cmatrix --no-check-certificate \
&& rm -rf /var/cache/apk/*


@@ -20,7 +21,7 @@ RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/


# Generate ssh host key.
RUN ssh-keygen -A
RUN ssh-keygen -A

# Add your script or exe to the container
ADD $CTF /usr/local/bin/$CTF
22 changes: 5 additions & 17 deletions SSH_Server/ctf.sh
Original file line number Diff line number Diff line change
@@ -16,23 +16,11 @@ CYAN='\033[0;36m'
timeout 3s cmatrix


# Substring to check for
substring=""

while true; do
# Prompt user for input
echo -e -n "${GREEN}Query?: ${NC}"
echo -e "${GREEN}Congratulations! A little further... ${NC}"
echo -e "${CYAN}NB2HI4DTHIXS6Z3JON2C4Z3JORUHKYTVONSXEY3PNZ2GK3TUFZRW63JPK5UW4ZBQGEYC6MZWGI2WKNRYHE2GKNBSGQ2TEZBZGI2TKNBZGFSTSOBUGFSGCZBSF5ZGC5ZPGQYTKZRQME4DENRVHA4TMNZUG5SWCZLBGEYTMMBXMRRGCOBXGJRWMYLBGY2TEODGF5QXGY3JNFPWY33SMRPW643DMFZC45DYOQ======${NC}\n\n"

read -r user_input
#read -r -p "Query: " user_input

# Check if the entered string contains the substring
if [[ "$user_input" == *"$substring"* ]]; then
echo "OMG..."
echo -e "${CYAN}Nice!${NC}\n\n"

# Don't use exit/break since this will kill the script and leave user in ssh terminal.
pkill -u $(whoami) sshd
else
echo -e "${RED}Boo!${NC}\n"
fi

pkill -u $(whoami) sshd
done
25 changes: 25 additions & 0 deletions tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Docker project generated files to ignore
# if you want to ignore files created by your editor/tools,
# please consider a global .gitignore https://help.github.com/articles/ignoring-files
.vagrant*
bin
docker/docker
.*.swp
a.out
*.orig
build_src
.flymake*
.idea
.DS_Store
docs/_build
docs/_static
docs/_templates
.gopath/
.dotcloud
*.test
bundles/
.hg/
.git/
vendor/pkg/
pyenv
Vagrantfile
8 changes: 8 additions & 0 deletions tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Use the Alpine Linux base image
FROM alpine:latest

# Install sshpass
RUN apk --no-cache add openssh-client sshpass --no-check-certificate

# CMD to keep the container running
CMD ["tail", "-f", "/dev/null"]

0 comments on commit 3dc46c9

Please sign in to comment.