<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sanskar Jaiswal on Medium]]></title>
        <description><![CDATA[Stories by Sanskar Jaiswal on Medium]]></description>
        <link>https://medium.com/@aryan9600?source=rss-eb263a7019fd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*teCArl0UUsNuDriPKMI7nQ.jpeg</url>
            <title>Stories by Sanskar Jaiswal on Medium</title>
            <link>https://medium.com/@aryan9600?source=rss-eb263a7019fd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:15:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aryan9600/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hosting CTF challenges on a Kubernetes cluster]]></title>
            <link>https://medium.com/techloop/hosting-ctf-challenges-on-a-kubernetes-cluster-f0f7441c3cd0?source=rss-eb263a7019fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0f7441c3cd0</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[ingress]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Sanskar Jaiswal]]></dc:creator>
            <pubDate>Tue, 30 Mar 2021 11:57:56 GMT</pubDate>
            <atom:updated>2021-03-31T07:02:02.763Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will be walking through how to host CTF challenges, reachable via HTTP(s) and TCP on a k8s cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*5eFQiN_bCN9Hd2JJU5ZXOQ.png" /></figure><p>Hosting CTF challenges is tricky, as you’re hosting something which is meant to be poked at and you need to be prepared if some Russian hacker finds a vulnerability and decides to exploit it :)</p><p>Using k8s makes sense to host CTF challenges as it <strong>is “self healing”</strong>. If a challenge Deployment goes down suddenly, the k8s master node will <strong>automatically spin up a replacement</strong> for it. This translates into <strong>minimal downtime.</strong> The challenges also need to be scalable and respond to traffic demand in an efficient way.</p><h3>Deploying the challenges on a k8s cluster using Minikube</h3><p>I’m gonna assume that you’ve already dockerized all your challenges, if you haven’t, you can refer to this article in our CTF series. Furthermore, kindly make sure you have <a href="https://minikube.sigs.k8s.io/docs/start/">Minikube</a> and <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/">kubectl</a> installed as well.</p><p>Once you’re ready with your dockerized challenges, it’s time to go ahead and push it to any container registry of your choice (we went ahead with Docker Hub).</p><pre>docker build -t chall:latest .<br>docker push chall</pre><p>Once your images are pushed to a container registry, we can start writing all the YAML files to configure our cluster to use these images.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f57ad0c3fd1aab555aa5894a2c37569d/href">https://medium.com/media/f57ad0c3fd1aab555aa5894a2c37569d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/493daf6a46adeba2b39a19f8c11d7b2b/href">https://medium.com/media/493daf6a46adeba2b39a19f8c11d7b2b/href</a></iframe><p>Once, we have these files ready, we can can go ahead and apply these files using the <em>kubectl</em> command.</p><pre>kubectl apply -f deployment.yaml<br>kubectl apply -f service.yaml</pre><p>Now let’s verify if everything worked like we wanted it to :-) Here’s one way to go about it:</p><ul><li>Run kubectl get deployments to get a list of all your deployments along with their status. Choose a Deployment you’d like to test.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*Z33D57t_dbWIweHufm71AA.png" /></figure><ul><li>Run kubectl get ep to see all the endpoints (<em>internal and external</em>) of your cluster. Grab an endpoint related to the Deployment you wanna test.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*0QN2MhQqnKUTjoXt68Iczg.png" /></figure><ul><li>Run kubectl get pods and grab the name of any pod belonging to the Deployment you wanna test.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*pdIqDwyEbtw-uxvNQpGFkw.png" /></figure><ul><li>Run kubectl exec -t -i {pod-name} -- /bin/bash to open up a shell inside the pod. You can then use <em>curl</em> to directly access the ClusterIP service, since we have the related endpoint.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*2bAUPrRqRjhvL89FtMjqMg.png" /></figure><ul><li>Verify if the output looks okay, if it doesn’t you probably have an issue with your Dockerfile or the YAML files we wrote above, so kindly double check.</li></ul><p>You can create a folder with all the deployment and service YAML files, and then just run kubectl apply -f {folder}/ to <strong>apply all the files at once</strong>.</p><h3>Setting up ingress-nginx for load balancing</h3><p>Now that we have our Deployments and ClusterIP Services up and running, we need a way for traffic to reach these from anywhere in the world.</p><p>One way to do this would be to use NodePorts instead of ClusterIPs and have a Compute Engine instance running a load balancing tool like <em>HAProxy</em> or <em>Traefik</em>. You can refer to <a href="https://medium.com/csictf/using-kubernetes-haproxy-to-host-scalable-ctf-challenges-a4720b6a9bbc">this nice article</a> if that’s how you want to go about it.</p><p>You can also use a LoadBalancer service as a part of your k8s cluster to load balance traffic between the nodes. We decided to use an Ingress resource, as it’s <strong>easy to setup and pretty convenient</strong>, especially for HTTP(s). Exposing ports for TCP connections requires a bit more effort tho :)</p><p>An <strong>Ingress resource needs a related Ingress controller</strong>. The controller is necessary to fulfil the Ingress resource (<em>using a LoadBalancer internally</em>). We decided to go ahead with the <a href="https://kubernetes.github.io/ingress-nginx/">NGINX Ingress controller</a>, as it has excellent documentation, community support and NGINX is one of the industry standards for load balancing.</p><p>Our web questions, i.e., questions that need HTTP connections, were being <strong>served at different paths </strong>of our main <em>server</em> (Load Balancer), and questions that needed TCP connections were served by simply exposing the port.</p><p>Enable the controller by running minikube addons enable ingress and then type out a YAML file as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edfd8012161b6eedb8aa139903b79067/href">https://medium.com/media/edfd8012161b6eedb8aa139903b79067/href</a></iframe><p>This YAML file takes care of setting up our Ingress service as well as the NGINX ingress Controller for all HTTP connections (for now). If you want all connections to be served over HTTPS, you can refer to <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#tls">this doc</a> for the same.<br>You can use this file the same way as above by simply running kubectl apply -f ingress-service.yaml</p><p>You need to verify if everything’s a-okay by talking to the cluster directly instead of having to <em>curl</em> from inside a pod to a private ClusterIP service endpoint.</p><ul><li>Run minikube ip to get the public IP address of your Minikube k8s cluster.</li><li>Run curl {ip-addr}:{port-number} and verify if the output is acceptable.</li></ul><h3>Exposing ports for TCP only connections</h3><p>Ingress resources are by default configured to use HTTP(s) connections. But some CTF challenges (such as jails) require TCP only connections. Let’s see how to host such challenges!</p><p>When we first install the Ingress resource on our Minikube k8s cluster, it creates a few <strong>ConfigMap resources in the </strong><strong>kube-system namespace</strong>, out of which one is the <strong>tcp-services ConfigMap</strong>, which stores all the information the Ingress controller needs about handling TCP connections and corresponding ports.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b02af0d86f3f3cfda0b7f7fc3b2e582/href">https://medium.com/media/6b02af0d86f3f3cfda0b7f7fc3b2e582/href</a></iframe><p>The above JSON file can be applied as a patch to the existing tcp-services ConfigMap, which contains instructions for the Ingress controller to open up the necessary ports and the related ClusterIP services, it needs to forward traffic to.</p><p>We also need to patch the definition of our Ingress controller Deployment running in the kube-system namespace, to basically specify port mapping.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a333527a167cbcf45e5252fb6a333fe/href">https://medium.com/media/9a333527a167cbcf45e5252fb6a333fe/href</a></iframe><p>You can apply these patches by running:</p><p>kubectl patch configmap --namespace kube-system tcp-services --patch &quot;$(cat patch.json)&quot;</p><p>kubectl patch deployment --namespace kube-system ingress-nginx-controller --patch &quot;$(cat ingress-nginx-controller-patch.yaml)&quot;</p><p>You can verify if everything is working by using a tool like <em>netcat </em>or <em>telnet</em> to access the necessary port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*h2EsaAowyfFibmaRSD6EJg.png" /></figure><h3>Deploying the k8s cluster on GKE</h3><p>Now that we have our cluster perfectly setup locally on Minikube, we can go ahead and deploy it on Google Kubernetes Engine (GKE). Creating a cluster is pretty straightforward on GKE, so I am just going to leave the official docs <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-zonal-cluster">here</a>, which <em>should</em> be all you need. If you’re confused about your node pool configuration, feel free to go through this article about <strong>our CTF stats and infra </strong>and make your decision accordingly.</p><p>Since now our cluster will be running on GKE and not on Minikube, we need to do things a bit differently. First off, we need to install <a href="https://helm.sh/">Helm</a> on our GKE cluster. Helm can be thought of as a <strong>package manager for Kubernetes</strong>. We’ll be using it to install the NGINX Ingress controller.</p><p>Connect to the cluster using the gcloud container clusters get-credentials <a href="https://cloud.google.com/sdk/gcloud/reference/container/clusters/get-credentials">command</a>. Then go ahead, and install Helm following the i<a href="https://helm.sh/docs/intro/install/#from-script">nstallation instructions</a>. Now we can install the NGINX Ingress controller using Helm, as shown <a href="https://kubernetes.github.io/ingress-nginx/deploy/#using-helm">here</a>.</p><p>We used Travis CI to deploy all the images to our GKE k8s cluster. We wrote a bash script which contained a bunch of commands, that Travis was instructed to run every time, we want to deploy a new image to the cluster nodes. I won’t be talking about setting up Travis CI and configuring it to work with GKE as it goes out of the scope of this article, but here’s another article about this which is excellent.</p><p>On GKE, we also need to patch a Service named ingress-nginx-controller which, again, got created when we installed the Ingress controller using Helm. As seen below, we are just specifying the selector and related port mappings. You can run it in the same way we ran the patches mentioned above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd6d1cefa432020d465fd54012cb91d0/href">https://medium.com/media/dd6d1cefa432020d465fd54012cb91d0/href</a></iframe><p>One <strong>subtle yet important</strong> difference that, we noticed that isn’t really mentioned anywhere (not that we could find at least) is that if you install the NGINX Ingress controller using Helm instead of Minikube, all the ConfigMaps (such as the tcp-services one) and the ingress-nginx-controller Deployment <strong>get created in the </strong><strong>default</strong> namespace <strong>instead of the </strong><strong>kube-system</strong> namespace. Hence, we adjusted the commands in our bash script to work accordingly. You can find the bash script here, if you’re interested :D</p><h3>It’s CTF challenges time!</h3><p>We can finally start playing our CTF challenges. Grab the public IP address of the Ingress service and send a request to any of your defined paths or try pinging any of the exposed ports, and everything <em>should </em>be working.</p><blockquote>Note: GCP assigns the Ingress service an ephemeral IP address, which means your IP address can potentially (and probably will) change. Fortunately, <a href="https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address#reserve_new_static">provisioning a static IP address</a> is very easy and free if it’s being used by a GCP Load Balancer.</blockquote><p>Thank you for reading this article! If you wish to go through the questions of our CTF or any config files, <a href="https://github.com/ieee-vit/ieee-ctf-questions">head over to the GitHub repo</a> and feel free to leave a ⭐️!</p><blockquote>If you enjoyed reading this article, do checkout the rest of the articles in our CTF series:</blockquote><ul><li><a href="https://link.medium.com/Ht4ZfDjd4eb">Interactive Globe using three.js</a></li><li><a href="https://link.medium.com/WJOp77bd4eb">Composing CTF Challenges</a></li><li><a href="https://aryan9600.medium.com/ctf-challenges-dockerizing-and-repository-structure-bd3aed9314de">CTF challenges: Dockerizing and Repository structure</a></li><li><a href="https://aryan9600.medium.com/hosting-ctf-challenges-on-a-kubernetes-cluster-f0f7441c3cd0">Hosting CTF challenges on a Kubernetes cluster</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0f7441c3cd0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/techloop/hosting-ctf-challenges-on-a-kubernetes-cluster-f0f7441c3cd0">Hosting CTF challenges on a Kubernetes cluster</a> was originally published in <a href="https://medium.com/techloop">Techloop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Infra overview and planning:  IEEECTF 2020]]></title>
            <link>https://medium.com/techloop/infra-overview-and-planning-ieeectf-2020-555589505848?source=rss-eb263a7019fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/555589505848</guid>
            <category><![CDATA[google-kubernetes-engine]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Sanskar Jaiswal]]></dc:creator>
            <pubDate>Tue, 30 Mar 2021 11:57:13 GMT</pubDate>
            <atom:updated>2021-03-31T06:14:07.777Z</atom:updated>
            <content:encoded><![CDATA[<h3>Infra overview and planning: IEEECTF 2020</h3><h3>About IEEECTF 2020</h3><p>We at <a href="https://ieeevit.org/">IEEE-VIT</a> conducted a 36 hour CTF from 31st October 2020 to 2nd November 2020, with a variety of different challenges aimed at beginners and enthusiasts. It was crucial to plan our infrastructure and tech stack carefully and extensively, because we wanted to ensure that the CTFers playing had a nice, flawless experience. It would be disastrous if they found a bug/vulnerability in our infra that they could exploit, and they’d probably spend more time on that, than on the actual CTF challenges ;).</p><p>We had around <em>1500 registrations</em> from all over the world so we knew our infrastructure needed to</p><ul><li><strong>be scalable</strong></li><li><strong>be highly available</strong></li><li><strong>have zero downtime</strong> (or at least try to xD)</li></ul><p>Also, the fact that we are a non profit student organisation means that <em>we are broke </em>and hence have to do all of the above while <strong>minimising the hole</strong> in our pocket :)</p><blockquote><strong>Before we start, here’s a big-ass flow chart giving a rough overview of the entire infra setup, for someone who wants a TL;DR</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b9vGBqJZx2FJXlpvBw4YaQ.png" /><figcaption>Yes I use Figma for stuff other than making memes as well :)</figcaption></figure><h3>Overview</h3><p>As apparent from the flow chart, the infra consisted of three components:<br>1) A <strong>k8s cluster</strong>, where the challenges are hosted.</p><p>2) A <strong>Vercel</strong> app running our <strong>React frontend</strong>.</p><p>3) An <strong>App Engine</strong> instance running our <strong>node.js</strong> backend, with <strong>Firebase</strong> for authentication and <strong>Firestore</strong> as our NoSQL DB.</p><p>Although, not shown in the above chart, we also had a CI/CD pipeline setup for which we used TravisCI.</p><h3>The Platform</h3><p>There are multiple CTF platform solutions (<a href="https://github.com/balidani/tinyctf-platform">picoCTF</a>, <a href="https://github.com/facebook/fbctf">FBCTF</a>, <a href="https://ctfd.io/">ctfd</a>, etc), already out there which have been battle tested and built for out-of-box usage. If you’re low on time and/or you don’t want feel like putting a lot of effort in, <strong>we highly recommend you to check these out</strong>.<br>But, we like making our lives more miserable and difficult, so we decided to make our <em>own CTF platform from scratch</em>.<br>We decided to go with React for our frontend, as we planned the UI to be around a big cool globe and <a href="https://www.npmjs.com/package/react-globe.gl"><strong>react-globe.gl</strong></a>, looked like the package that promised to be the solution to this. If you’d like to know on how we implemented an UI as slick as shown below, head on over to <a href="https://medium.com/@fkjainco/c7723c7575fb"><strong>this article</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ChPBVMUeOj9JMlFI.jpeg" /></figure><p>We used <em>Firebase auth,</em> as it is ridiculously easy to implement and makes things like <em>“Login with Google”</em> painless. We chose <em>Firestore</em> over <em>MongoDB</em>, mainly because we already had a Firebase project setup, so it was simple and they also have a pretty generous free tier which helped us in minimising costs.</p><p>Since we chose <a href="https://vercel.com/"><strong>Vercel</strong></a> and <a href="https://cloud.google.com/appengine/"><strong>App Engine</strong></a>, deployment was fairly easy and straightforward. <a href="https://vercel.com/docs/platform/deployments#preview">Vercel’s per commit preview feature</a> was also very helpful during the dev stage, as it let us test out any subtle bugs that arose while implementing the complex globe component. Both Vercel and App Engine are managed services, so we didn’t really need to bother ourselves with stuff like <a href="https://www.nginx.com/resources/glossary/load-balancing/">load balancing</a>, <a href="https://www.websecurity.digicert.com/security-topics/what-is-ssl-tls-https">setting up TLS/SSL</a>, etc and this also was a crucial factor in us choosing these two technologies.</p><p>We decided to add <strong>Cloudflare</strong> to our infra as well, because of the following reasons:</p><ol><li><strong>to avoid getting DDoS’d</strong></li><li><strong>to improve response time through caching</strong></li><li><strong>their pretty dashboard</strong> xD.</li></ol><p>We highly recommend using Cloudflare, as it is really helpful in providing analytics about your website, <em>without invading the privacy</em> of your users. Also, it’s always nice to have DDoS protection, especially when your target audience consists of folks experienced in exploiting vulnerabilities and attacking services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*MYsDlPA1hrEA8i95y5HyWw.png" /><figcaption>Geographic spread of our users during IEEECTF 2020</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*7FTkhl9U-AH5i6kejiGnIw.png" /><figcaption>Network Stats for IEEECTF 2020</figcaption></figure><p>All of these stats helped us in analysing not only our audience but also our infra setup, so that we can improve next time. One thing Cloudflare is really <strong>good at is caching requests</strong>, which is helpful as your server is getting hit less often now, thus decreasing the load on it and the response times are super fast. It also informs us of where most of our users were playing from, which lets us know how far our Publicity and Marketing team were able to get the word out. Unsurprisingly, most of our users were from <strong>India</strong>, but as you can see we had quite a few users from <strong>Europe </strong>and some from<strong> China, South-East Asia, Australia and USA.</strong></p><h3>The k8s Cluster for Challenges</h3><blockquote>This section covers the cost, analysis, etc of our k8s use. If you want to know how we actually set the cluster up with code snippets and all, consider checking out <a href="https://medium.com/p/f0f7441c3cd0/edit?source=your_stories_page-------------------------------------">this article</a>.</blockquote><p>We decided to go ahead with <a href="https://cloud.google.com/kubernetes-engine">Google Kuberentes Engine</a> (GKE) as we had $300 worth of Google Cloud Platform credits. You can avail them too by making a new account.</p><p>The cluster consisted of <strong>3 (E2 series)</strong>, each with <strong>2vCPU </strong>and<strong> 8 gigs of RAM, </strong>with <strong>automatic scaling</strong> to make sure that the cluster wasn’t being utilised and we weren’t <em>paying more than we needed to</em>. You can definitely try to fiddle with this configuration to suit your needs. We would highly suggest you to use the <a href="https://cloud.google.com/products/calculator">pricing calculator</a> that GCP provides, which lets you analyse just how much money you’d end up paying. Note that, the <strong>nodes itself are not that expensive</strong>, since at the end of the day they’re just preemptible Compute Engine instances. It’s the <strong>Load Balancer which is going to cost the big bucks</strong>. Here’s the estimate we calculated:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*VjemI9xBxUR8HKXa7u8XuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*BIQvcMAdKC0NvZFhStN9vw.png" /></figure><p>As you can see the Load Balancer costs <strong>almost 4x</strong> more than the physical cluster nodes themselves. Also note that the cost of the Load Balancer is <strong>directly proportional</strong> to the number of forwarding rules. So practically speaking, the more number of challenges you have, the more your Load Balancer cost will increase, since each challenge would require it’s own forwarding rule. If you can’t afford to spend a lot of money, then consider setting up a load balancer using Traefik or HAProxy on your own.</p><p>We had 10 challenges running on our cluster, each challenge had it’s own Deployment, where each challenge belonged to either the web or jail category. You’ll notice there are 11 Deployments in the below screenshot. The extra deployment was required to host a MySQL server for our <a href="https://github.com/IEEE-VIT/IEEE-CTF-Questions/tree/master/WEB/haunted-house">Haunted House question</a>, which involved SQL injection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNQmYDE_xReA9lti3qXLzw.png" /><figcaption>Deployments running on the cluster</figcaption></figure><p>All Deployments that needed to be accessed publicly had a related ClusterIP service, which were all ultimately linked to our Ingress service which was handling the routing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xbdGOPjH9Ndz8E1FemcbUw.png" /><figcaption>ClusterIP, Ingress and Load Balancer services for our cluster</figcaption></figure><p>All Deployments had a RollingUpdate strategy, to minimise downtime and makes sure all challenges are available for users to play at any moment of time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IekRkBWctNaQCUPjCCaopA.png" /><figcaption>GKE dashboard showing monitoring stats about all resource types.</figcaption></figure><p>One area where we could’ve done a better job was integrating <a href="https://prometheus.io/">Prometheus</a>. We we didn’t leave enough time to experiment with <strong>Prometheus</strong> and host it as a sidecar. It’s <strong>definitely worth</strong> setting up Prometheus on your cluster, helping you make very fine tuned decisions based on the metrics.</p><h3>CI/CD</h3><p>We decided to use TravisCI as our CI/CD provider, since provide student accounts with 1000 free builds/month, which was enough for our testing and prod purposes. We wrote a simple <a href="https://github.com/IEEE-VIT/IEEE-CTF-Questions/blob/master/deploy.sh">bash script</a>, to help with deploying all changes pushed to master to our GKE cluster automatically. <a href="http://Continuous Deployment to GKE with Travis CI | by Rajat ...medium.com › continuous-deployment-to-gke-with-tra...">Setting up TravisCI with GKE</a> is super simple, so we won’t be going into that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*6yrVxM7AjIlnWAlzT_8QMQ.png" /></figure><p>One thing to note that is your build time can vary a lot, depending on the changes, since all questions are dockerized. Our highest build time, was <strong>around 10 minutes</strong>, which was mainly due to a web question written using <em>Ruby on Rails</em> (thanks a lot <em>gem</em> <em>dependencies</em> ;_;).</p><h3>Conclusion</h3><p>Overall, this infra setup worked well for us. We could’ve definitely things better and more efficiently but the cluster had almost zero downtime, and we didn’t have any users (almost xD) complaining about not being able to play a challenge. This was the first time, that our team was using k8s in production and it gives us immense pleasure to say that it was done so successfully 🚀. Moreover, the platform too had zero downtime and we had users appreciating the super cool UI of it, which was a real big +1 for our frontend and UI/UX team ✨.</p><blockquote>Please also checkout the related repositories and consider leaving a 🌟 if you like it:</blockquote><ul><li>Frontend: <a href="https://github.com/IEEE-VIT/CTF-Frontend">https://github.com/IEEE-VIT/CTF-Frontend</a></li><li>Backend: <a href="https://github.com/IEEE-VIT/CTF-Backend">https://github.com/IEEE-VIT/CTF-Backend</a></li><li>Questions and k8s: <a href="https://github.com/IEEE-VIT/IEEE-CTF-Questions/tree/master/WEB/haunted-house">https://github.com/IEEE-VIT/IEEE-CTF-Questions</a></li></ul><blockquote>If you enjoyed reading this article, do checkout the rest of the articles in our CTF series:</blockquote><ul><li><a href="https://link.medium.com/Ht4ZfDjd4eb">Interactive Globe using three.js</a></li><li><a href="https://link.medium.com/WJOp77bd4eb">Composing CTF Challenges</a></li><li><a href="https://aryan9600.medium.com/ctf-challenges-dockerizing-and-repository-structure-bd3aed9314de">CTF challenges: Dockerizing and Repository structure</a></li><li><a href="https://aryan9600.medium.com/hosting-ctf-challenges-on-a-kubernetes-cluster-f0f7441c3cd0">Hosting CTF challenges on a Kubernetes cluster</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=555589505848" width="1" height="1" alt=""><hr><p><a href="https://medium.com/techloop/infra-overview-and-planning-ieeectf-2020-555589505848">Infra overview and planning:  IEEECTF 2020</a> was originally published in <a href="https://medium.com/techloop">Techloop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CTF challenges: Dockerizing and Repository structure]]></title>
            <link>https://medium.com/techloop/ctf-challenges-dockerizing-and-repository-structure-bd3aed9314de?source=rss-eb263a7019fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd3aed9314de</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Sanskar Jaiswal]]></dc:creator>
            <pubDate>Tue, 30 Mar 2021 11:55:12 GMT</pubDate>
            <atom:updated>2021-03-31T07:27:16.595Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article we’ll be exploring how we can dockerize common CTF challenges and and nice way to structure the repo containing all challenges.</p><h3>Structuring the challenges repo</h3><p>We had a team of CTFers, with different levels of experience working on questions with varying levels of difficulty and complexity. It was imperative for them to collaborate properly, testing out each other questions, giving their feedback, etc. Apart from dockerizing the challenges as explained above, we also had to consider CI/CD integration to deploy the dockerized challenges safely, quickly and in a consistent manner. All this meant, the GitHub repository containing our challenges needed to be structured in a well-defined and self explanatory way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pPQqv-8cL-nT-oMOC4r2fg.png" /><figcaption>IEEE-CTF-Questions repository structure</figcaption></figure><p>As seen in the above screenshot, the repo has folders for each category of questions. Each of these folders contain another folder which contain the files for the challenge. Apart from that, we have a k8s folder which contains all our .yaml files which defined our cluster configuration. Since we used TravisCI for CI/CD, we have a .travis.yml file and a deploy.sh script which Travis was instructed to execute for each job that it ran. I won’t be going into the details of our CI/CD setup, but if you’re interested take a look at <a href="https://medium.com/@drew.buckman/use-travis-ci-to-automate-the-deployment-of-a-python-gunicorn-app-to-kubernetes-2a42cb9d2e88">this article</a> which follows a very similar approach to the one we took.</p><p>Each question folder has a README.md which is a small write-up about the question so that everyone has a clear idea about the question, and helps the participants who weren’t able to get the flag for that question. It also has a Dockerfile which bundles up the challenge into a container making deployments easy. Continue reading to see how ;)</p><h3>Containerisation and Docker</h3><p>CTF challenges are usually not as simple as serving a simple Flask application, for example. You need to create owners and groups, edit permissions, etc. Furthermore, you need to make sure that it’s not vulnerable, or rather the only vulnerability it has, is the one the challenge necessitates it to have. You also need to make sure that all CTFers are playing the same exact challenge, so it’s important to isolate resources, and package it in a self sufficient environment.</p><p>Why do we need to worry about stuff like containers while hosting CTF challenges? To understand this, let’s try to imagine a scenario. You setup a challenge which involves RCE, and host it on a server. What happens if a CTFer succeeds in executing some malicious code on your server? That’s something we’d definitely like to avoid :)<br>This is the kind of problem that containers are the perfect solution to. Most container technology follow the <a href="https://docs.docker.com/engine/security/#:~:text=Docker%20containers%20are%2C%20by%20default,or%20another%20appropriate%20hardening%20system."><em>secure by default</em></a><em> </em>ideology, i.e. they are isolated from the main system they’re running on. From Docker’s website:</p><blockquote>A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.</blockquote><p>This means that we don’t need to worry about libraries, packages, system dependencies for each challenge. Containerising the challenge guarantees that the challenge will run on every machine.</p><p>We mainly had two kind of challenges that we needed to dockerize:</p><ul><li>Challenges reachable via TCP only connections using tools like nc or ssh</li><li>Challenges served as websites, i.e. reachable via HTTP(s).</li></ul><h3>Dockerizing TCP only challenges</h3><p>For IEEECTF 2020, we had a question which involved two <em>chroot</em> jails. <em>chroot </em>is used to emulate a directory in the filesystem as the root of the filesystem, which enables us to make jails in an easy manner. One jail needed to be accessed via nc and the other one was supposed to be accessed via ssh .</p><p>We used a tool called <a href="https://github.com/google/nsjail"><em>nsjail</em></a><em> </em>for the first jail. It’s a process isolation tool built for Linux by the good devs over at Google. While it’s extremely powerful and can satisfy plenty of use cases, we were only interested in it’s network services isolation ability. It would expose a port which would be listening for any TCP connections, allowing for Remote Code Execution (RCE).</p><blockquote>An alternative to <em>nsjail</em> is <a href="https://linux.die.net/man/8/xinetd"><em>xinetd</em></a>. It lets you define <em>multi-threaded</em> services which require forking a new server process for each new connection request. The new server then handles that connection. For such services, xinetd keeps listening for new requests so that it can spawn new servers.</blockquote><p>The first step is to prepare the <em>chroot</em> jail itself. It’s a fairly simple albeit slightly time consuming process, although that depends on how extensive your jail is.</p><ul><li>Create a directory for your jail, and further subdirectories for dependencies.</li></ul><pre>mkdir jailed<br>cd jailed<br>mkdir bin/ lib64/ lib/</pre><ul><li>Use ldd to list all dependencies of your desired binary. Copy the binary and the corresponding deps into the jail. We do this for the bash executable below.</li></ul><pre>ldd /bin/bash<br>cp /lib/x86_64-linux-gnu/libtinfo.so.5 lib/<br>cp /lib/x86_64-linux-gnu/libdl.so.2 lib/<br>cp /lib/x86_64-linux-gnu/libc.so.6 lib/<br>cp /lib64/ld-linux-x86-64.so.2 lib64/<br>cp /bin/bash bin/</pre><ul><li>You can repeat the above step for all the binaries (like ls , cat , etc.) you want present in your jail.</li></ul><p>Now that our jail is ready, we can go ahead with dockerizing it and then access it by exposing it via a <em>nsjail </em>server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e595700a0e64d236156607f596dbb752/href">https://medium.com/media/e595700a0e64d236156607f596dbb752/href</a></iframe><p>We can now, build an image, run the container and play around in the jail.</p><pre>docker build -t jail:latest .<br>docker run -p 9002:9002 --privileged -it jail:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*Ddda6Q2o_A5vXZuVotK06Q.png" /><figcaption>Accessing the jail exposed by the nsjail server</figcaption></figure><p>Now that we’ve our first jail up and running properly, lets move to the next one. Since this jail requires to be accessed via ssh instead of a tool like nc , we don’t need <em>nsjail.</em></p><p>Assuming that you’ve prepared this jail as instructed above, go ahead and type out a Dockerfile like below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92b0762cb5af3e8ff3227f27d0834e4e/href">https://medium.com/media/92b0762cb5af3e8ff3227f27d0834e4e/href</a></iframe><pre>docker build -t jailed:latest<br>docker run -P jailed:latest</pre><p>Run docker ps , and grab the exposed port of the container. Now it’s time to ssh into the jail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*LqPB13aHedYSi8dFNagmhw.png" /><figcaption>Accessing the jail through password protected ssh</figcaption></figure><h3>Dockerizing HTTP challenges</h3><p>Dockerizing these are mostly straightforward, but sometimes you need to run your web server under some <em>non-ordinary</em> conditions. For example, we had a question built using <em>node.js</em> which involved the player entering commands, which would be executed in a <a href="https://nodejs.org/api/vm.html"><em>V8 VM</em></a><em>. </em>We had to make sure that the player couldn’t run commands that could potentially affect the filesystem and harm the container running the challenge. We handled that by adding a <em>user, </em>a <em>user group </em>and using chmod to edit permissions</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02c5e418de2fae81d07aba33fdce9148/href">https://medium.com/media/02c5e418de2fae81d07aba33fdce9148/href</a></iframe><p>Some web challenges sometimes require two running servers simultaneously. We had a question based on Server Side Request Forgery (SSRF), which required a node.js server and a simple server capable of serving HTML (for which we used the inbuilt http module in Python3) . To achieve this, we can write a simple bash script, like given below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27cd81e38100361b93e45b231899ce9d/href">https://medium.com/media/27cd81e38100361b93e45b231899ce9d/href</a></iframe><p>Now we can just instruct Docker to run this script whenever we start up a container.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0eb469676144d0a1393e22fbacb8d65/href">https://medium.com/media/f0eb469676144d0a1393e22fbacb8d65/href</a></iframe><h3><strong>Conclusion</strong></h3><p>We successfully dockerized multiple CTF questions each with their own dependencies and use cases. Now that we’ve packaged each question into one unit, we can move forward to actually hosting these for people to play. If you’re interested in that, do read the next article in the series, where we walk through deploying these dockerized challenges on a Kuberenetes cluster!</p><p>Thank you for reading this article! If you wish to go through the questions of our CTF or any config files, head over to the <a href="https://github.com/ieee-vit/ieee-ctf-questions">GitHub repo</a> and feel free to leave a ⭐️!</p><blockquote>If you enjoyed reading this article, do checkout the rest of the articles in our CTF series:</blockquote><ul><li><a href="https://link.medium.com/Ht4ZfDjd4eb">Interactive Globe using three.js</a></li><li><a href="https://link.medium.com/WJOp77bd4eb">Composing CTF Challenges</a></li><li><a href="https://aryan9600.medium.com/ctf-challenges-dockerizing-and-repository-structure-bd3aed9314de">CTF challenges: Dockerizing and Repository structure</a></li><li><a href="https://aryan9600.medium.com/hosting-ctf-challenges-on-a-kubernetes-cluster-f0f7441c3cd0">Hosting CTF challenges on a Kubernetes cluster</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd3aed9314de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/techloop/ctf-challenges-dockerizing-and-repository-structure-bd3aed9314de">CTF challenges: Dockerizing and Repository structure</a> was originally published in <a href="https://medium.com/techloop">Techloop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a clean Login UI in Flutter]]></title>
            <link>https://medium.com/techloop/building-a-clean-login-ui-in-flutter-9c655df2982a?source=rss-eb263a7019fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c655df2982a</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[ui]]></category>
            <dc:creator><![CDATA[Sanskar Jaiswal]]></dc:creator>
            <pubDate>Sun, 29 Sep 2019 17:42:57 GMT</pubDate>
            <atom:updated>2020-03-09T07:54:13.381Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will be building a<strong> clean, minimalistic login page</strong> with hints of inspiration from Facebook’s login page.</p><p>I have been learning Flutter for a few months now, and what I absolutely love about Flutter is how fast you can make your apps come to life. Since a major part of Flutter is community support, I decided to start writing articles about my experiences with Flutter to help people. ❤️</p><p>I am gonna assume you have some knowledge of the basic widgets such as Rows, Columns, etc. If you are a complete newbie, I suggest you head over to the <a href="http://flutter.dev/docs">documentation page of Flutter</a>, which is more than enough to get you started. 🙌🏼</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*hygax7oDSmitcdFQDudc_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*dwuSVqyYCDqcp_wAm-UiwQ.png" /><figcaption>This is what our final UI is gonna look like. (couldn’t resist the name xD)</figcaption></figure><p>So let’s start by creating a new Flutter app. Remove all the boiler code. Right now, I just have one stateful widget named <strong>LoginPage</strong>.</p><p>We are going to be building our UI inside this widget.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc1266e30717034a4aabcbb86ee687e7/href">https://medium.com/media/fc1266e30717034a4aabcbb86ee687e7/href</a></iframe><p>Now, let’s add an enum. This enum is gonna store the state of our form type: Login or Register. We also declare some variables to store the value of the inputs we are about to enter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/209786337d740805e6fff0305a576a01/href">https://medium.com/media/209786337d740805e6fff0305a576a01/href</a></iframe><p>We then define some <a href="https://api.flutter.dev/flutter/widgets/TextEditingController-class.html">TextEditingControllers</a> for all the <a href="https://api.flutter.dev/flutter/material/TextFormField-class.html">TextFormFields</a> we are about to define, along with a <a href="https://api.flutter.dev/flutter/widgets/GlobalKey-class.html">GlobalKey</a> for our <a href="https://api.flutter.dev/flutter/widgets/Form-class.html">Form</a>. This key helps us track the state of the form. After that, we define some helper functions, to switch the form type from Login to Register or vice-versa.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/572e0288e0d92eba2b6cb230684b895c/href">https://medium.com/media/572e0288e0d92eba2b6cb230684b895c/href</a></iframe><p>With all this out of the way, let’s start painting our UI to life.</p><h3>We should always try to make a lean widget tree to avoid clutter and build costs.</h3><p>If you don’t understand me right now, don’t worry, you will, when we start coding this out. 💡</p><p>Add the following code to your build method in the _LoginPageState class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df0621d72bae8433bafae8b46218d944/href">https://medium.com/media/df0621d72bae8433bafae8b46218d944/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*GWdcpjFa66EBMoFE-lif6g.png" /><figcaption>The logo and the title</figcaption></figure><p>We use a <a href="https://api.flutter.dev/flutter/widgets/ListView-class.html">ListView</a> to handle smaller screen sizes so that it doesn’t overflow and instead gracefully scrolls up and down. We then add some padding and a <a href="https://api.flutter.dev/flutter/widgets/SizedBox-class.html">SizedBox</a> to provide some empty space. The <a href="https://api.flutter.dev/flutter/widgets/Image/Image.asset.html">Image.asset</a> method allows us to display a picture (make sure you add your image file to your project and pubsec.yaml). We then display the title of our app.</p><p>Now comes the most important part of our code. The FORM. Remember, the formKey we defined? We pass the same variable to key parameter of our Form widget. This helps us reset the form anytime we change from Login to Register or vice-versa. We then define a <a href="https://api.flutter.dev/flutter/widgets/Column-class.html">Column</a> as its child which has two lists of type widget as its children: usernameAndPassword and submitButtons. Let’s define these now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b68cb5bb669482c4f0adc7b50acfccbc/href">https://medium.com/media/b68cb5bb669482c4f0adc7b50acfccbc/href</a></iframe><p>Remember the enum we defined? We use that enum, to check the form type. If form type is of type Login, we render the Login page, which consists of two TextFormFields, else if form type is of type Register, we render the Register page which consists of three TextFormFields. The styling of all the fields is the same. We also use the validator property of the TextFormField to do some basic validation, like checking if the fields are empty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*nOf-UaZdleqDAdzOooEVCQ.png" /><figcaption>The Input Fields</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/634b47d4c5a2382755feaad3f060684f/href">https://medium.com/media/634b47d4c5a2382755feaad3f060684f/href</a></iframe><p>You can probably guess what’s happening here. We check the form type and render some widgets accordingly. But there is one new thing we are doing here. We also call our moveToLogin and moveToRegister methods when we tap the Login and Sign Up buttons respectively. These methods help us change the form type accordingly. For instance, when we are on the Register page and click on Login, the moveToLogin method is called and the formType is now changed to FormType.Login. Since the formType is now of Login type, we render the Login components, in both of our widget lists.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*dwuSVqyYCDqcp_wAm-UiwQ.png" /><figcaption>Buttons added</figcaption></figure><h3>This is the point I wanted to make initially. By defining all of our main widgets outside the build method, we only change the widgets that actually need to be changed when we call those helper methods, saving the app the trouble of rebuilding the entire widget tree since the entire build method is not being invoked anytime I change my form type. We should always rebuild only the widgets that actually need to be rebuilt and not the entire tree. This is always a performance booster. 🚀</h3><p>So, that’s it, we have successfully built a Login UI in Flutter, in just a few minutes. See, how fast and easy that was? This is just a small example of how powerful Flutter can be.⚡️</p><p>I loved writing this blog. Please 👏🏼 if you liked this. See you guys in the next one!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c655df2982a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/techloop/building-a-clean-login-ui-in-flutter-9c655df2982a">Building a clean Login UI in Flutter</a> was originally published in <a href="https://medium.com/techloop">Techloop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>