Full text
Containerization of a Pentesting platform Master Thesis submitted to the Faculty of the Escola T`ecnica d’Enginyeria de Telecomunicaci´o de Barcelona Universitat Polit`ecnica de Catalunya by Erika Salome Morales Mu˜noz In partial fulfillment of the requirements for the master in Master’s degree in Cybersecurity Director: Ren´e Serral-Graci`a, Computer architecture department Barcelona, February 2024
Contents List of Figures 4 Listings 5 List of Tables 6 1 Introduction 8 1.1 Context ..................................... 8 1.2 Problemstatement ............................... 8 1.3 Stateoftheart ................................. 9 1.4 Justification................................... 10 1.4.1 Limitations of current solutions . . . . . . . . . . . . . . . . . . . . 10 1.4.2 Chosen research direction . . . . . . . . . . . . . . . . . . . . . . . 10 1.5 Scope ...................................... 11 1.5.1 Objectives................................ 11 1.5.2 Requirements .............................. 11 1.5.3 Obstacles and risks . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.6 Technologiesused................................ 13 1.6.1 Penetration Testing Toolkit . . . . . . . . . . . . . . . . . . . . . . 13 1.6.2 CI/CD[19] ............................... 13 1.6.3 CloudComputing............................ 14 1.6.4 Docker.................................. 14 1.6.5 Kubernetes ............................... 14 2 Planning 15 2.1 Methodology .................................. 15 2.2 Descriptionoftasks............................... 15 2.2.1 Project Management . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.2.2 Project Development . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.2.3 ProjectValidation ........................... 17 2.2.4 Thesis documentation and preparation . . . . . . . . . . . . . . . . 17 2.3 Resources .................................... 18 2.3.1 Humanresources ............................ 18 2.3.2 Material resources . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.4 EstimatesandGantt .............................. 18 2.5 Budget...................................... 20 2.5.1 Identification of costs . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.5.2 Management control . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3 Design 24 3.1 Functional Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.1.1 Former Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.1.2 Improved Architecture . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.2 AWS Infrastructure Architecture . . . . . . . . . . . . . . . . . . . . . . . 28 2
4 Implementation 29 4.1 Legacy code improvements . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.1.1 Attacks Instantiation . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.1.2 Attacks Dockerization . . . . . . . . . . . . . . . . . . . . . . . . . 31 4.1.3 SetupAutomation ........................... 33 4.2 Infrastructure as Code in AWS . . . . . . . . . . . . . . . . . . . . . . . . 36 4.2.1 Terraform Structure . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.2.2 Terraform Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . 42 5 Results 46 5.1 AWSInfrastructure............................... 46 5.1.1 Preparationsteps............................ 46 5.1.2 Terraform Workflow Outcomes . . . . . . . . . . . . . . . . . . . . 47 5.2 Deployment of applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 5.2.1 HuntDown services . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 5.2.2 Testbed ................................. 60 5.3 PentestingAnalysis............................... 63 5.3.1 Information Gathering . . . . . . . . . . . . . . . . . . . . . . . . . 63 5.3.2 Exploitation............................... 65 5.4 Assessing the outcomes obtained with Attacks Instantiation . . . . . . . . 68 6 Future Development and Conclusions 71 6.1 FutureDevelopment .............................. 71 6.2 Conclusions ................................... 72 References 73 3
List of Figures 1 Initial Gantt [Own Compilation] . . . . . . . . . . . . . . . . . . . . . . . . 20 2 Final Gantt [Own Compilation] . . . . . . . . . . . . . . . . . . . . . . . . 23 3 HuntDown Login page [Own Compilation] . . . . . . . . . . . . . . . . . . 24 4 HuntDown Dashboard [Own Compilation] . . . . . . . . . . . . . . . . . . 24 5 HuntDown Attack List [Own Compilation] . . . . . . . . . . . . . . . . . . 25 6 HuntDown Nmap attack [Own Compilation] . . . . . . . . . . . . . . . . . 25 7 HuntDown Attack Results [Own Compilation] . . . . . . . . . . . . . . . . 25 8 Initial Architecture [Own Compilation] . . . . . . . . . . . . . . . . . . . . 26 9 Improved Architecture [Own Compilation] . . . . . . . . . . . . . . . . . . 27 10 Deployment Architecture in AWS [Own Compilation, based on [24]] . . . . 28 11 Attacks .gitlab-ci.yml file [Own Compilation] . . . . . . . . . . . . . . . . . 32 12 HuntDown Deployment [Own Compilation] . . . . . . . . . . . . . . . . . . 34 13 GitLab CI: release-images-job [Own Compilation] . . . . . . . . . . . . . . 35 14 HuntDown images in AWS ECR [Own Compilation] . . . . . . . . . . . . . 36 15 Terraform Workflow with GitLab pipeline [Own Compilation] . . . . . . . 42 16 Terraform GitLab CI Pipeline [Own Compilation] . . . . . . . . . . . . . . 43 17 GitLab CI: Terraform Init results [Own Compilation] . . . . . . . . . . . . 43 18 GitLab CI: validate stage results [Own Compilation] . . . . . . . . . . . . . 44 19 GitLab CI: validate stage error results [Own Compilation] . . . . . . . . . 44 20 GitLab CI: plan stage results [Own Compilation] . . . . . . . . . . . . . . 44 21 GitLab CI: apply stage results [Own Compilation] . . . . . . . . . . . . . . 45 22 GitLab CI: destroy stage results (beginning) [Own Compilation] . . . . . . 45 23 GitLab CI: destroy stage results (end) [Own Compilation] . . . . . . . . . 45 24 AWS Academy Lab [Own Compilation] . . . . . . . . . . . . . . . . . . . . 46 25 AWS Console: Dashboard [Own Compilation] . . . . . . . . . . . . . . . . 46 26 AWS Console: KMS Key list [Own Compilation] . . . . . . . . . . . . . . . 47 27 AWS Console: Key pair list [Own Compilation] . . . . . . . . . . . . . . . 47 28 AWS Console: HD VPC Details [Own Compilation] . . . . . . . . . . . . . 47 29 AWS Console: IGW Details [Own Compilation] . . . . . . . . . . . . . . . 48 30 AWS Console: NAT GW List [Own Compilation] . . . . . . . . . . . . . . 48 31 AWS Console: Public Subnet A Details [Own Compilation] . . . . . . . . . 48 32 AWS Console: Private Subnet A Details [Own Compilation] . . . . . . . . 49 33 AWS Console: EKS cluster Details [Own Compilation] . . . . . . . . . . . 49 34 AWS Console: Node group Details [Own Compilation] . . . . . . . . . . . . 50 35 AWS Console: Node details from Node group [Own Compilation] . . . . . . 50 36 AWS Console: Cloud 9 Interface [Own Compilation] . . . . . . . . . . . . . 51 37 AWS Console: EC2 instances List [Own Compilation] . . . . . . . . . . . . 51 38 AWS Console: Details of hd-for-attacks instance [Own Compilation] . . . 52 39 AWS Console: Security Group of hd-services instance [Own Compilation] 52 40 HuntDown Deployment [Own Compilation] . . . . . . . . . . . . . . . . . . 53 41 Add first user to database [Own Compilation] . . . . . . . . . . . . . . . . 54 42 HuntDown Deployment Pod Details [Own Compilation] . . . . . . . . . . . 58 43 EKS Deployment Pod Events [Own Compilation] . . . . . . . . . . . . . . 59 44 Load Balancer Details [Own Compilation] . . . . . . . . . . . . . . . . . . 60 4
45 HuntDown Application Accessed from Browser [Own Compilation] . . . . . 60 46 DVWA config.inc.php [Own Compilation] . . . . . . . . . . . . . . . . . . . 61 47 /etc/php/8.2/apache2/php.ini [Own Compilation] . . . . . . . . . . . . . . 61 48 /etc/apache2/ports.conf [Own Compilation] . . . . . . . . . . . . . . . . . 62 49 /etc/apache2/sites-available/000-default.conf [Own Compilation] . . . . . . 62 50 DVWA Login Page [Own Compilation] . . . . . . . . . . . . . . . . . . . . 62 51 Nikto Attack [Own Compilation] . . . . . . . . . . . . . . . . . . . . . . . 63 52 Nikto Progress in Result History [Own Compilation] . . . . . . . . . . . . . 63 53 Nikto Attack Results [Own Compilation] . . . . . . . . . . . . . . . . . . . 64 54 Nikto Attack Results Downloaded [Own Compilation] . . . . . . . . . . . . 64 55 Path /DVWA/config - config.inc.php.bak [Own Compilation] . . . . . . . . 64 56 Path /DVWA/Database - sqli.db [Own Compilation] . . . . . . . . . . . . 65 57 SQLMap Attack Form [Own Compilation] . . . . . . . . . . . . . . . . . . 65 58 SQLMap Attack Form - Cookie option enabled [Own Compilation] . . . . . 65 59 SQLMap Attack Results Part I [Own Compilation] . . . . . . . . . . . . . 66 60 SQLMap Attack Results Part II [Own Compilation] . . . . . . . . . . . . . 66 61 SQLMap Attack All [Own Compilation] . . . . . . . . . . . . . . . . . . . 66 62 SQLMap Attack All Results [Own Compilation] . . . . . . . . . . . . . . . 67 63 Hydra Attack Form Part I [Own Compilation] . . . . . . . . . . . . . . . . 67 64 Hydra Attack Form Part II [Own Compilation] . . . . . . . . . . . . . . . . 67 65 Hydra Attack Results Part I [Own Compilation] . . . . . . . . . . . . . . . 68 66 Hydra Attack Results Part II [Own Compilation] . . . . . . . . . . . . . . 68 67 Attack deployment Chart [Own Compilation] . . . . . . . . . . . . . . . . 69 Listings 1 HydraAttackDockerfile ............................ 31 2 Code part from compose.yaml . . . . . . . . . . . . . . . . . . . . . . . . . 31 3 Code part from variables.tf . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4 Code part from provider.tf . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 5 Code part from provider.tf . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 6 vpc.tf ...................................... 37 7 Code part from subnets.tf - Public Subnet . . . . . . . . . . . . . . . . . . 38 8 Code part from subnets.tf - Private Subnet . . . . . . . . . . . . . . . . . . 38 9 Code part from internet-gateway.tf . . . . . . . . . . . . . . . . . . . . . . 39 10 Code part from routing-tables.tf . . . . . . . . . . . . . . . . . . . . . . . . 39 11 Setup hd-services workstation script . . . . . . . . . . . . . . . . . . . . . . 53 12 Code to Add/Update Attack schemas . . . . . . . . . . . . . . . . . . . . . 54 13 Setup hd-attacks workstation script . . . . . . . . . . . . . . . . . . . . . . 55 14 namespace.yaml................................. 56 15 environment-config.yaml . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 16 deployment.yaml ................................ 57 17 service.yaml................................... 59 5
List of Tables 1 Nessus vs. OpenVAS [Own Compilation, based on [5]] . . . . . . . . . . . . 9 2 Task summary [Own Compilation] . . . . . . . . . . . . . . . . . . . . . . . 19 3 Salary of the staff [Own Compilation] . . . . . . . . . . . . . . . . . . . . . 20 4 Personnel cost per activity [Own Compilation] . . . . . . . . . . . . . . . . 21 5 Material cost [Own Compilation] . . . . . . . . . . . . . . . . . . . . . . . 21 6 Total Incidentals [Own Compilation] . . . . . . . . . . . . . . . . . . . . . 22 7 Final Budget [Own Compilation] . . . . . . . . . . . . . . . . . . . . . . . 22 8 Vagrant vs. Docker [Own Compilation, based on [25] [26]] . . . . . . . . . . 29 9 Docker images of the attacks automated for HD [Own Compilation] . . . . 32 10 Comparison of attacks Deployment performance (in seconds) . . . . . . . . 69 6
Abstract In today’s technology-driven landscape, organizations increasingly store vast amounts of sensitive personal and confidential data, making them vulnerable targets for cybercriminals seeking to exploit system security weaknesses. Simply complying with security standards and regulations is not enough, as we cannot guarantee absolute immunity from vulnerabilities in our systems. The growing demand for cybersecurity talent underscores the need for effective vulnerability scanning tools, which are often complex and require expert knowledge, limiting their accessibility. To address these challenges, HuntDown (HD) has emerged as an ethical hacking tool that provides an accessible solution for security auditing. Nonetheless, HuntDown still requires improvements to match the efficiency of existing vulnerability scanners. This thesis project aims to help refine the HuntDown application deployment process and streamline attack instantiation methods. This research focuses on key aspects such as automation, cloud deployment, and containerization methods to improve HuntDown’s performance. To validate the effectiveness of these enhancements, a simple pentest is performed against a vulnerable web application that serves as a benchmark for evaluating HuntDown’s performance. The methodologies employed, technologies used, and practical validation performed in this thesis highlight its success and relevance in the dynamic landscape of cybersecurity and penetration testing. The insights gained from this research pave the way for future innovation and advancement in the field, driving progress toward a more secure digital environment. 7
1 Introduction 1.1 Context This Master’s thesis, titled Containerization of a Pentesting platform, is a part of the HuntDown project, which is being supervised by Ren´e Serral-Graci`a. The thesis is a component of the Master’s degree in Cybersecurity program at the Barcelona School of Telecommunications Engineering, Universitat Polit`ecnica de Catalunya. HuntDown is an emerging ally in the field of penetration testing, offering a dynamic web application that enables users to conduct security audits. The platform presently enables users to configure powerful Linux-based pentesting tools such as Nmap, Hydra, and Nikto. These tools are deployed in a secure and isolated manner, and they form the foundation of our commitment to improving your penetration testing experience. 1.2 Problem statement In today’s technology-driven era, no organization can claim absolute immunity against cybercrime. Therefore, companies must prioritize cybersecurity measures. According to Forbes [1], 65% of organizations plan to boost their cybersecurity budget by 2023. Unfortunately, some businesses still underestimate the severity of cyber threats. Surprisingly, 67% of businesses believe that their senior leadership team does not take cyber threats seriously. Cybersecurity is a broad field that involves various activities and roles aimed at safeguarding computer systems, networks, and data from security threats. Ethical Hacking [2], or penetration testing, is an integral component of cybersecurity. Penetration testing involves identifying and assessing vulnerabilities in systems to enhance their overall security. Vulnerability assessment is a resource-intensive process that requires a significant amount of time, effort, and resources from penetration testers and security analysts. As a result, developers created a unique cybersecurity tool called a Vulnerability Scanner that automates different test cases by integrating various penetration tools. This tool can be used to produce an automated vulnerability assessment. Developers who create Vulnerability scanners play a crucial role in the cybersecurity ecosystem by contributing to the development of software, in which ethical hackers and security professionals use to assess and strengthen systems’ security. These tools simulate real-world cyberattacks, helping organizations identify and address potential weaknesses before hackers can exploit them. Nowadays, we could note that certain Vulnerability scanners rely too heavily on automation and may not offer enough customization options. This can make it difficult for users to use them without having specific expertise on the field. In the upcoming section, we will take a closer look at these tools and explore the reasons behind developing a new solution. 8
1.3 State of the art In cybersecurity, vulnerability scanners are widely used to identify security weaknesses in systems or networks. This project focuses on two popular vulnerability scanning tools: Nessus [3] and OpenVAS [4]. To better understand the strengths and characteristics of Nessus and OpenVAS, we provide a detailed comparison in the table below. Features Nessus OpenVAS License Commercial Open-source Development By Tenable, a single commercial entity By Greenbone and a collaborative community Vulnerability Detection Powerful because detects an extensive range of vulnerabilities Comprehensive but may find slightly fewer vulnerabilities Complexity It is user-friendly but targets an expert public Requires a certain level of expertise Customization Create policies and templates Customize scans’ configurations, target hosts, and scan parameters OS Support Supports Windows, macOS, and Linux platforms Primarily Linux-based, with limited support for Windows Table 1: Nessus vs. OpenVAS [Own Compilation, based on [5]] Both Nessus and OpenVAS share the goal of scanning systems or software for vulnerabilities, utilizing advanced templates tailored to specific targets. Nessus is a commercial tool that is considered more powerful and can detect a higher number of vulnerabilities. OpenVAS, on the other hand, is an open-source project that branched off from the original Nessus, resulting in two distinct projects developed by separate entities. Customization of Nessus and OpenVAS is subjective and depends on the user’s background, available resources, and the complexity of customization requirements. Although designed to be accessible to a broad audience, users with a robust foundation in cybersecurity concepts may find customization tasks easier. Regarding OS support, both tools need to be installed on-site. Nessus provides versatility for users on different operating systems, while OpenVAS focuses mainly on some Linux operating systems. Both vulnerability scanning tools are highly competent and reliable. However, their suitability and usefulness depend on the organization’s specific requirements and the users’ proficiency. When selecting the appropriate vulnerability scanner for a particular environment, it is essential to consider these factors carefully. 9
•PM2. Planning: Describe the planning of the project. Dedication: 10 hours. Dependencies: PM1. •PM3. Budget: Estimate the budget of the project. Dedication: 5 hours. Dependencies: PM2. •PM4. Integration in a final document: Add a description of the above tasks in the report. Dedication: 10 hours. Dependencies: PM3. •PM5. Meetings: Each week we will have a meeting to plan the development, documentation and to prepare the defense. Dedication: 15 hours (45’ per week). Dependencies: none. 2.2.2 Project Development Now, we can see some tasks related to the development of this thesis. The entire task will take approximately 221 hours. Familiarization with the project To begin with the project, we need to understand the functionalities involved in the HuntDown platform and other related solutions. •FP1. Study of the state of the art: Learn about Nessus and OpenVAS. Dedication: 2 hours. Dependencies: none. •FP2. Understanding HuntDown: Learn about the architecture, the programming languages and tools used for the development of HuntDown. Dedication: 20 hours. Dependencies: none. •FP3. HuntDown installation: Setup the development workstation in order to run HuntDown. Dedication: 8 hours. Dependencies: FP2. •FP4. HuntDown Tests: Perform tests using HuntDown Web App to understand the interaction between all its services. Dedication: 20 hours. Dependencies: FP3. Tasks related to HuntDown development Within this portion, we outline key tasks vital to the continuous enhancement of the HuntDown application. •HD1. Attacks instantiation alternative: Improve the Attacks instantiation by bringing up a new solution. Dedication: 70 hours. Dependencies: none. •HD2. Attacks Containerization: Containerize pentesting tools. Dedication: 8 hours. Dependencies: HD1. •HD3. Automate HuntDown Installation: Create new scripts to ease HuntDown installation and dockerize HuntDown components. Dedication: 25 hours. Dependencies: FP3. 16
Tasks related to AWS Infrastructure Automation These tasks collectively contribute to the seamless automation of AWS infrastructure and the deployment of the HuntDown application. •IA1. Familiarize with AWS Academy: Understand the limitations we have with AWS Academy. Dedication: 2 hours. Dependencies: none. •IA2. Learn Terraform: Follow Terraform tutorials to get familiar with it. Dedication: 8 hours. Dependencies: none. •IA3. Learn Kubernetes: Follow Kubernetes tutorials to get familiar with it. Dedication: 8 hours. Dependencies: none. •IA4. IaC with Terraform: Create scripts to automate infrastructure deployment in AWS. Also, prepare the CI pipeline to execute Terraform Workflow. Dedication: 30 hours. Dependencies: IA1, IA2. •IA5. Automate Deployment of HuntDown application: Create scripts to deploy HuntDown in Kubernetes. Dedication: 15 hours. Dependencies: IA3, IA4. 2.2.3 Project Validation This section focuses on validating the project through essential deployment steps and penetration testing, ensuring reliability and effectiveness. •VA1. Deploy AWS Infrastructure: Provision the necessary infrastructure to deploy HuntDown. Dedication: 2 hours. Dependencies: IA4. •VA2. Deploy HuntDown application: Execute scripts to deploy HuntDown in Kubernetes and other components. Dedication: 4 hours. Dependencies: VA1, IA5. •VA3. Setup an insecure Web Application: Deploy an insecure Web App to a machine exposed to the Internet and get familiar with it. Dedication: 8 hours. Dependencies: none. •VA4. Web Application Penetration Testing: Attack the insecure Web App using HuntDown tools. Dedication: 20 hours. Dependencies: VA2, VA3. 2.2.4 Thesis documentation and preparation Here we can see the tasks related with the documentation and final thesis defense preparation. The entire task will take approximately 65 hours. •TH1 – Documentation: Finish documentation of the thesis. Dedication: 40 hours. Dependencies: none. •TH2 – Thesis defense preparation: Prepare the presentation of this thesis. Dedication: 25 hours. Dependencies: TH1. 17
2.3 Resources In this section, we identify the different resources that were necessary for the development of this thesis. 2.3.1 Human resources On one side, this thesis will be directed and managed by the product tutor [T], Ren´e Serral. On the other side, Erika Morales [EM] will be responsible of the development of this thesis. 2.3.2 Material resources Below are the necessary material resources to carry out the previous tasks. •R1 – Computer and a Debian Virtual Machine: The technical and nontechnical parts require a computer. And the validation part of this project requires a Debian machine. •R2 – GitLab: Mainly used to store the project code, it also serves as a Docker Registry and to save Terraform states. •R3 – VirtualBox: Our development workstation is an Ubuntu 22.04 Virtual Machine prepared with Docker, Go, Terraform and other software. •R4 – Visual Studio Code: Used to program, run and debug our code. •R5 – Notion: To document development steps and keep tracking of the progress of the project. •R6 – Overleaf, PowerPoint and draw.io: Used for the thesis documentation, presentation, and creation of diagrams. •R7 – Google Meet, Google Calendar and Gmail: We use this tools for communication purposes. •R8 – AWS Academy Learner Lab: We need an AWS account for provisioning infrastructure. 2.4 Estimates and Gantt This area provides a table that summarizes the previous described tasks, with their dependencies, their resources, and the total number of hours they compute. Additionally, Figure 1 shows the initial planning Gantt. 18
ID TASK DEPENDENCIES RESOURCES HOURS PM1 Context and Scope - EM, R1, R6, T 5 PM2 Planning PM1 EM, R1, R6, T 10 PM3 Budget PM2 EM, R1, R6, T 5 PM4 Integration in the final document PM3 EM, R1, R6 10 PM5 Meetings - EM, T, R1, R5, R7 15 FP1 Study of the state of the art - EM, T, R1, R6 2 FP2 Understanding HuntDown - EM, T, R1, R2, R5 20 FP3 HuntDown installation FP2 EM, T, R1, R2, R3, R5 8 FP4 HuntDown Tests FP3 EM, T, R1, R3 20 HD1 Attacks instantiation alternative - EM, R1, R2, R3, R4, R5 70 HD2 Attacks Containerization HD1 EM, R1, R2, R3, R4, R5 8 HD3 Automate HuntDown Installation FP3 EM, R1, R2, R3, R4, R5 25 IA1 Familiarize with AWS Academy - EM, R1, R5, R8 2 IA2 Learn Terraform - EM, R1, R3, R4 8 IA3 Learn Kubernetes - EM, R1, R3, R4 8 IA4 IaC with Terraform IA1, IA2 EM, R1, R2, R3, R4, R5, R8 30 IA5 Automate Deployment of HuntDown application IA3, IA4 EM, R1, R2, R3, R4, R5 15 VA1 Deploy AWS Infrastructure IA4 EM, R1, R2, R5, R8 2 VA2 Deploy HuntDown application VA1, IA5 EM, R1, R2, R5, R8 4 VA3 Setup an insecure Web Application - EM, R1, R5 8 VA4 Web Application Penetration Testing VA2, VA3 EM, R1, R5, R8 20 TH1 Documentation - EM, R2, R5, R6 40 TH2 Thesis defense preparation TH1 EM, T, R6 25 TOTAL 360 Table 2: Task summary [Own Compilation] 19
Figure 1: Initial Gantt [Own Compilation] 2.5 Budget At this segment, we will identify all the costs that will constitute our final budget. Then, we will see the measures for controlling the possible deviations during the project execution. 2.5.1 Identification of costs Next, we will describe and estimate the different costs presented in the budget. Human resources Let us compute the cost of each task based on the team’s salary. We have obtained the annual salary and salary per hour of the staff with talent.com. Then, if we add the cost of social security (SS), Table 3 shows the gross salary multiplied by 1.35. The staff is composed by two different persons: •[PD] Project Director: The director and supervisor of this project is Ren´e Serral. •[SE] Software Engineer: This role is assumed by Erika Morales. Role Annual Salary (€) Hourly wage (€) Hourly wage + S.S. (€) PM [21] 78000 40 54 SE [22] 50000 25,64 34,61 Table 3: Salary of the staff [Own Compilation] 20
Moreover, in Table 4 we can find the Duration column that contains the total hours of performing a task by the staff. ID Associated Roles Hours Task cost (€) PM1 SE, PM 5 443 PM2 SE 10 346 PM3 SE 5 173 PM4 SE 10 346 PM5 SE, PM 15 519,2 FP1 SE 2 69,2 FP2 SE 20 692,2 FP3 SE 8 276,9 FP4 SE 20 692,2 HD1 SE 70 2422,7 HD2 SE 8 276,9 HD3 SE 25 865,3 IA1 SE 2 69,2 IA2 SE 8 276,9 IA3 SE 8 276,9 IA4 SE 30 1038,3 IA5 SE 15 519,2 VA1 SE 2 69,2 VA2 SE 4 138,4 VA3 SE 8 276,9 VA4 SE 20 692,2 TH1 SE 40 1384,4 TH2 SE 25 865,3 TOTAL 12729,5 Table 4: Personnel cost per activity [Own Compilation] Material costs Regarding the hardware, we will use a Yoga Slim 9-14ITL05 Laptop which costs approximately 2.993,27 €. We estimate that this has an approximate lifetime of 5 years. Also, we know that the duration of this project is about 360 hours. And we suppose the laptop is used 18 hours per week resulting in 936 hours per year. Thus, we will use the formula below to calculate the amortization of this computer. Amortization = (Purchase import ∗T otal project hours)/(Total hours/year ∗lifetime) All the software that we use is open-source. Therefore, the resulting material costs is presented in the following table. Resource Cost Final cost (€) Yoga Slim 9-14ITL05 Laptop 2.993,27 230,25 Total 230,25 Table 5: Material cost [Own Compilation] 21
Contingency costs So far, we computed the total cost of this project. However, we keep in mind that we cannot anticipate all unexpected events. Hence, we will add to our budget a security margin, that is, a 15% of contingency to the total cost. Contingency = (12729,5 + 230,25) ∗0,15 = 1944 Incidentals In contrast with the previous section, we need to be prepared when an incident occurs. Since tasks are overestimated, potential risks are covered, we will just consider an incident with our laptop. Resource Cost Risk (%) Final cost (€) Yoga Slim 9-14ITL05 Laptop 2.993,27 7 209,53 Total 209,53 Table 6: Total Incidentals [Own Compilation] Final budget The table below shows the final budget of our project. Type of cost Cost (€) Human Resources 12729,5 Material Resources 230,25 Contingency 1944 Incidentals 209,53 Total 15113,3 Table 7: Final Budget [Own Compilation] 2.5.2 Management control After identifying the costs, we could present the final budget deviations from the initial planning. Tasks deviations were compensated by adding more hours and reducing time spent on some tasks. •PM4. Integration in a final document: This task was performed before the expected time. Deviation: -6 hours •FP4. HuntDown Tests: This task was shortened because we executed simple attacks to understand how HuntDown works. Deviation: -15 hours •HD1. Attacks instantiation alternative: Since we invested time in understanding how HuntDown worked, this task was shortened because we had more clear what to do. Deviation: -8 hours 22
•HD2. Attacks Containerization: This task was straightforward. Deviation: -3 hours •HD3. Automate HuntDown Installation: We experienced problems with automating the deployment in Kubernetes of the Instantiation Manager. It required specific data that needed to be set before starting the container. Deviation: +13 hours •IA5.Automate Deployment of HuntDown application: This task was easier to perform than expected. Deviation: -11 hours •VA1. Deploy AWS Infrastructure: Since it was our first time using GitLab CI/CD tools and required specific configuration. Deviation: +12 hours •VA2. Deploy HuntDown application: Since it was our first time creating a load balancer, we misconfigured it, which led to spending time troubleshooting. Deviation: +8 hours •VA4. Web Application Penetration Testing: Due to inconsistencies with time performance, we needed to spend more time making tests. Also, we computed the average duration time of our attacks. Deviation: +10 hours These results indicated no deviation in either time or budget. However, certain tasks experienced slow deployment, resulting in minimal differences in the subsequent Gantt chart. Figure 2: Final Gantt [Own Compilation] 23
3 Design In this area, we focus on explaining the former and newer architecture of HuntDown, along with its underlying infrastructure in AWS. 3.1 Functional Architecture HuntDown is an ongoing web application provided to perform penetration testing. For using the HuntDown UI, it is necessary to log in with valid credentials (Figure 3). Once logged in, the Dashboard (Figure 4) shows a summary of the results of the attacks that have been deployed, if any. Figure 3: HuntDown Login page [Own Compilation] Figure 4: HuntDown Dashboard [Own Compilation] To create an attack, the user clicks on the ”New Attack” button. This will display a list of the available attacks (Figure 5) to deploy. For instance, the user could launch a simple Nmap attack against 8.8.8.8, which is the primary Google DNS (Figure 6). 24
Figure 5: HuntDown Attack List [Own Compilation] Figure 6: HuntDown Nmap attack [Own Compilation] So far, a new attack has been configured but not deployed. Therefore, the user needs to manually start the attack from the ”Configured Attacks” page. Then, the progress can be tracked on the ”Result History” page. When the attack succeeds, the user can view the attack results (Figure 7). Depending on the attack, a results table will be retrieved, along with the standard output of the attack. The output can also be downloaded if needed. Figure 7: HuntDown Attack Results [Own Compilation] 25
As we could see, there is a service definition for the Hydra attack. The build statement specifies the folder containing the Dockerfile, while the image statement sets the URL pointing to our GitLab Container Registry 4. The table below shows all the attacks we automated and their Docker image URLs. Attack Docker Image URL Fierce registry.gitlab.com/huntdownupc/attacks/fierce:latest GoldenEye registry.gitlab.com/huntdownupc/attacks/goldeneye:latest Hydra registry.gitlab.com/huntdownupc/attacks/hydra:latest NetCAT registry.gitlab.com/huntdownupc/attacks/netcat:latest Nikto registry.gitlab.com/huntdownupc/attacks/nikto:latest Slowloris registry.gitlab.com/huntdownupc/attacks/slowloris:latest SQLMap registry.gitlab.com/huntdownupc/attacks/sqlmap:latest Traceroute registry.gitlab.com/huntdownupc/attacks/traceroute:latest WPScan registry.gitlab.com/huntdownupc/attacks/wpscan:latest Table 9: Docker images of the attacks automated for HD [Own Compilation] We have the option to either manually execute the Docker Compose file on our local machine or automate it using a GitLab CI pipeline (as shown in Figure 11). This pipeline is triggered automatically whenever a commit is pushed. To build and release the Docker images, the pipeline logs in to the Container Registry using a GitLab Deploy Token [34]. Figure 11: Attacks .gitlab-ci.yml file [Own Compilation] By encapsulating our attacks and their dependencies in Docker images, we can ensure that they are easily deployable and can run smoothly within the Docker environment. This makes it much easier for us to manage the attacks and execute them efficiently. 4The images of the attacks are stored in the Container Registry from the Attack Repository [33] 32
4.1.3 Setup Automation As described in subsection 3.2, to streamline the deployment of HuntDown in AWS, we utilize Kubernetes for container orchestration [35]. Containerizing the HuntDown application eliminates the need for manual library and program installations, ensuring enhanced portability and efficiency through Docker. This is made possible by HuntDown’s modular programming and existing scripts that were originally designed for on-premises installations. At first, the setup and configuration of HuntDown relied on a script named setup.sh. This script was crucial in installing necessary software like Golang, React, MongoDB, and Pulsar, compiling the different micro-services, establishing system services to execute the services, and preparing the working directory. The only remaining manual step was compiling and executing the Web Application with the npm CLI tool. Nevertheless, this process became a nuisance due to the package incompatibility with the Operating System where HuntDown was deployed and the manual steps involved. Additionally, the installation was automated but the removal was not. This led us to reconsider our strategy, and we opted to leverage Docker once again. Now, moving on to the specifics of the new automation with Docker 5, we can distinguish two parts: the automation of external services such as Pulsar and MongoDB, and the automation of HuntDown services, which include Instantiation Manager, Attack Manager, Database Manager, and Web Application. Third-party services automation In the HuntDown Repository [36], a directory named ”utils” stores a main Bash script named init-db-and-pulsar.sh and directories for each service. This primary script serves as the starting point for automating several setup tasks related to Docker, MongoDB, and Pulsar. MongoDB setup After setting up the workstation, the script installs and sets up the MongoDB systemd service. It also creates an administrative user for the database using the docker run mongo.sh script. Subsequently, the script starts the system, which will execute the following script for creating a MongoDB Docker container: #!/ bin /bash sudo docker start huntdown -db || sudo docker run --name huntdown-db -d - p 27017:27017 -v ~/ hd - mongo -db/data :/ data /db -v ~/hd - mongo -db/ mongo_init . sh :/ dockerentrypoint - initdb .d/ mongo_init .sh mongo 5The automation scripts can be found in Erika’s branch in the HuntDown Repository [36] 33
Pulsar setup Similarly, the script continues with the Pulsar systemd service installation, setup, and execution through a Docker container. The only difference in this service setup includes a health check, ensuring the Pulsar service is responsive. We use systemd services because that way the containers will be restarted on the machine reboot. In summary, the script automates the setup of Docker, MongoDB, and Pulsar, with a focus on Dockerized instances of these services. It encapsulates the necessary steps, configurations, and service management, providing an optimized approach for initializing and launching these components. Internal services automation We will now illustrate the process of creating the HuntDown docker images with the following diagram. Figure 12: HuntDown Deployment [Own Compilation] Every new commit to the HuntDown GitLab Repository triggers a CI pipeline named gitlab-ci.yml that will be responsible for performing the following steps. Pipeline initialization Firstly, it sets golang:1.20 as the default Docker image to be used for all jobs inside this pipeline. Also, it defines the different stages or jobs of this pipeline: dependencies, run, and release. Lastly, it includes a before script argument that updates and installs necessary software, this will be executed before every job in the pipeline. Downloading dependencies Next, the HuntDown workspace is created using the dependencies stage. To achieve this, we have predefined Go modules in the go-modules GitLab Repository [37]. These modules must be exported to our current directory to ensure the proper functioning of Go programs. This task is facilitated by a pre-existing zip file containing the modules, accessible via the go-modules GitLab Artifacts 6. Lastly, we create a go.work file 7defining that defines the routes to the various modules. 6A pipeline in the go-modules repository [37] is triggered to compress the modules into a zip file. 7A go.work file is used to specify a workspace with the module. For more information, visit: https://go.dev/doc/tutorial/workspaces 34
Compiling the HuntDown project Now, we proceed to compile the HuntDown micro-services programs to facilitate the subsequent creation of Docker images. This process involves two distinct steps. The initial step entails executing the dockerizing hd.sh, which undertakes the following tasks: •Initialize ENV variables that will be used during the pipeline execution, such as MONGO HOST and PULSAR HOST that define the Public IP of the machine that is running those services •Create the working directories for HuntDown /etc/huntdown,/var/huntdown and /usr/local/huntdown •Create configuration files and save them in the working directories •Compiles the Go modules and main applications by running different Makefiles The next step involves launching the preparing-dockerization.sh script, which organizes three separate folders containing configuration files, directories, and the respective Dockerfile for each service. Releasing services to AWS ECR The first step of the final job (Figure 13) is to log in to the AWS ECR registry server, where the HuntDown Docker images will be stored. Afterwards, the job will proceed with building, tagging, and pushing the HuntDown images to the ECR repositories (Figure 14). In addition, a Docker image for the UI will also be created. This will simplify the process of compiling and executing both the frontend and backend automatically. Figure 13: GitLab CI: release-images-job [Own Compilation] 35
Figure 14: HuntDown images in AWS ECR [Own Compilation] These improvements have been significant in making the deployment process smoother and adapting to the ongoing changes in our development workflow. 4.2 Infrastructure as Code in AWS In cloud computing, Infrastructure as Code (IaC) has become an important model that has revolutionized the way we manage our infrastructure. In the following subsection we will share our approach for building the infrastructure seen in the Figure 10 for Amazon Web Services (AWS). As an alternative to a pay-as-you-go AWS account, we are employing the AWS Academy student platform. Keep in mind that this platform may have specific limitations, and it might be necessary to modify certain scripts for deployment. 4.2.1 Terraform Structure I suggest now we explore how to implement IaC using Terraform by following a specific Terraform structure. We will walk through various code snippets to illustrate this. Variables Block To enhance readability and maintainability of our Terraform code, we make use of variables to store commonly used data across different Terraform files. We will refer to these values in the upcoming sections. 1variable "iam_role_arn" { 2description = "AWS Academy LabRole" 3type = string 4default = " arn :aws :iam ::998260163531: role / LabRole " 5} 6... Listing 3: Code part from variables.tf 36
Terraform Block The Terraform block serves as the starting point for every Terraform execution. Since we are using the AWS Cloud Provider, this block requires the provider source and version specification. 1terraform { 2required_providers { 3aws = { 4source = " hashicorp / aws" 5version = " 5.4.0 " 6} 7} 8backend "http " {} 9} Listing 4: Code part from provider.tf Provider Block For the provider segment, we specify the region available for use. AWS credentials are note required as we are leveraging automation. 1provider "aws" { 2region = "${var. aws_region }" 3} Listing 5: Code part from provider.tf Resource Block This section represents a resource we want to deploy in AWS. Each resource includes a type, name, and encapsulates configuration details. We shall see the different groups of resources used to provision the entire EKS cluster and related components. VPC The following Terraform code snippet shows how to create an AWS VPC with the CIDR block 10.0.0.0/16. Additionally, we set a name tag and enable required parameters for EKS. 1resource " aws_vpc " " main " { 2cidr_block = var . vpc_cidr 3instance_tenancy = "default" 4tags = { 5Name = "hd - vpc" 6} 7enable_dns_support = true # Required for EKS 8enable_dns_hostnames = true # Required for EKS 9assign_generated_ipv6_cidr_block = false # Required for EKS 10 } Listing 6: vpc.tf 37
IGW Next, a resource ”aws internet gateway” was required for allowing Internet connectivity to the public subnets and it is associated with the previously created VPC. Subnets To align with AWS recommendations, we need to have at least two subnets in different Availability Zones (AZ) for deploying an EKS cluster [38] and load balancers [39]. Therefore, we could find in the code snippet below four subnet resources (pairs of private and public subnets) for the AZs us-east-1a and us-east-1b. For each subnet, we have to indicate the VPC ID, the CIDR Block, the availability zone, and some tags such as its name and the EKS cluster name (to associate the subnets to it). Further specific information is provided for public and private subnets. For the public subnets, we use the map public ip on launch to assign a Public IP address to the instances that are launched within the subnet. And, we set the tag kubernetes.io/role/elb so every time we want to deploy external load balancers Kubernetes will identify these subnets. 1resource " aws_subnet " " myPublicSubnet1 " { 2vpc_id = aws_vpc . main .id 3cidr_block = var. public_subnet_cidr1 4availability_zone = "us -east -1a" 5map_public_ip_on_launch = true 6tags = { 7Name = "hd - public - subnet -a" 8" kubernetes .io / cluster /hd - eks " ="shared" 9" kubernetes . io /role /elb" = 1 10 } 11 } Listing 7: Code part from subnets.tf - Public Subnet Similarly, for private subnets, this tag kubernetes.io/role/internal-elb will identify the subnets as the ones to use in case we deploy internal load balancers. 1resource " aws_subnet " " myPrivateSubnet1 " { 2vpc_id = aws_vpc . main .id 3cidr_block = var.private_subnet_cidr1 4availability_zone = "us -east -1a" 5tags = { 6Name = "hd -private - subnet -a" 7" kubernetes .io / cluster /hd - eks " ="shared" 8" kubernetes . io /role / internal - elb " = 1 9} 10 } Listing 8: Code part from subnets.tf - Private Subnet 38
NAT Gateways 8 We are using NAT Gateways (NAT GWs) because the private subnets need internet access but should not be directly reachable from the Internet. Therefore, we first create two Elastic IP (EIP) addresses since a static Public IP address is needed for each NAT gateway. Then, we can create and associate one NAT GW to each public subnet, by indicating an EIP and the name tag. 1resource " aws_eip " " eip1 " { 2depends_on = [aws_internet_gateway.igw] 3... # Name tag definition 4} 5 6resource " aws_nat_gateway " "nat -gw1 " { 7allocation_id = aws_eip . eip1 .id 8subnet_id = aws_subnet . myPublicSubnet1 .id 9... # Name tag definition 10 } Listing 9: Code part from internet-gateway.tf Routing Tables 9 We need to create Routing Tables (RT) to enable communication to the Internet for the public and private subnets. As shown in the code below, for each routing table, we indicate the name tag, the VPC ID, and the route to the Internet (0.0.0.0/0). However, we distinguish between public and private RTs depending on the gateway id specified: •One public RT where we specified our IGW ID •Two private RTs where we have specified the NAT gateways created before Additionally, we create four associations between an RT and its respective subnet. 1# Sample of the Public RT and its association with a public subnet 2resource " aws_route_table " " publicRT " { 3vpc_id = aws_vpc . main .id 4route { 5cidr_block = " 0.0.0.0/0 " 6gateway_id = aws_internet_gateway .igw .id 7} 8... # Name tag definition 9} 10 11 resource " aws_route_table_association " " publicRTassociation1 " { 12 subnet_id = aws_subnet . myPublicSubnet1 .id 13 route_table_id = aws_route_table . publicRT .id 14 } Listing 10: Code part from routing-tables.tf 8NAT Gateways Terraform file available here. 9RTs Terraform file available here. 39
EKS Cluster 10 Before creating the EKS cluster to deploy our HuntDown application with Kubernetes, we took a security consideration [40]. As configuration files containing sensitive data are involved in the process, it is imperative to treat them as secrets. To ensure security, we enabled EKS secrets encryption using a KMS key 11 we created beforehand, which means that even if an attacker gains access to etcd 12, they cannot read secrets in plaintext. Let us start by reviewing the configuration details we defines for our EKS cluster: •name: The EKS cluster is identified by the name ”hd-eks” •role arn: The ”LabRole”, provided by AWS Academy, has the necessary permissions for the Kubernetes control plane •version: Indicates the Kubernetes version •encryption config: Enables EKS secrets encryption •vpc config: Encloses networking parameters required by EKS, along with the four subnets created before Once we have the EKS cluster, we proceed to create a node group that, according to AWS [41], automates the provisioning and lifecycle management of nodes (also known as EC2 instances) for the EKS cluster. For this, we define the following arguments: •cluster name: We specify the EKS cluster that manages our node group •node group name: The node group is identified by the name ”hd-ngroup” •node role arn: As for the EKS cluster, we use ”LabRole” which is the one provided by AWS Academy •subnets ids: The private subnets are set here and these are used to deploy worker nodes •scaling config: Number of EC2 instances this node group will provision, in this case we just need one •ami type: Indicates the Image Amazon Linux 2 (x86-64) •capacity type: Configured as ON DEMAND for high availability •disk size and instance types: Specifies computing and storage resources for the EC2 instances, in this case t2.medium •labels: Used for assigning a label named role 10EKS Cluster and Node Group Terraform file available here. 11AWS Key Management Service (KMS). For more information, visit: https://docs.aws.amazon.com/kms/latest/developerguide/overview.html 12etcd is a distributed, reliable key-value store for the most critical data of a distributed system. For more information, visit: https://etcd.io/ 40
Furthermore, we are also automating the setup of a Cloud9 environment, utilized for administering kubectl. This environment, akin to an Integrated Development Environment (IDE), is deployed using an EC2 instance of type t3.small. ECR 13 As mentioned in 4.1.3, we need four private repositories for storing the Docker images of HuntDown services. To implement this, we are using two AWS resources related to AWS ECR: aws ecr repository and aws ecr lifecycle policy. The first resource is used to create an ECR Repository, for this we need the following parameters: •name: We assign a name for the repository, it can be one of hd-instantiation- manager,hd-database-manager,hd-attack-manager, or hd-interface •image tag mutability: Configured as IMMUTABLE for designate immutable tags, which makes them unalterable once created. This ensures that the original image remains persistently associated with the tag. However, this measure will only be secure if the attacker does not have push access to the repository •encryption config: Enables encryption configuration for the repository using a KMS Key. By adopting this method, we can guarantee that only users possessing the appropriate permissions can access and alter the repository’s contents The second resource is used to assign an Lifecycle Policy to the newly created ECR Repository, for this we need the following parameters: •repository: This specifies one of the four repositories to which the lifecycle policy is applied •policy: Defines a lifecycle policy in JSON format. The policy, in this case, is configured to expire images that are older than 1 day and are untagged. This helps in managing the storage space and keeping the repository clutter-free. EC2 Instances 14 For our system, we require at least one instance for continuous operation of Pulsar and MongoDB. Additionally, another instance is currently demanded for executing the Instantiation Manager micro-service, as it deploys attacks (i.e., Docker containers) on the same machine where it is executed. Therefore, we have determined that we need two instances and we leveraged from the aws instance resource offered by Terraform. Besides, per security considerations, we need a security group for each instance to control traffic and we need to encrypt our disk storage using a KMS key. 13ECR Terraform file available here. 14EC2 instances Terraform file available here. 41
In the resource map illustrating the VPC, four subnets are presented within the second box. Specifically, a set of public and private subnets is linked to the us-east-1a availability zone, while another pair is associated with the us-east-1b zone. Additionally, the box at the right highlights the network connections, presenting three components. These include one IGW and two NAT GWs. Figure 29: AWS Console: IGW Details [Own Compilation] Figure 30: AWS Console: NAT GW List [Own Compilation] Moreover, the box in the middle is dedicated to route tables, totaling four in number. The first is the default RT for the VPC. The second, named hd-public-rt, is linked to both public subnets and the IGW (Figure 31). Finally, there are two private RTs, each connected to a private subnet and a respective NAT GW (Figure 32). Figure 31: AWS Console: Public Subnet A Details [Own Compilation] 48
Figure 32: AWS Console: Private Subnet A Details [Own Compilation] Kubernetes Cluster Resources The EKS cluster and its Node Group are crucial components for the successful deployment of HuntDown. On the EKS cluster side (Figure 33), key details include the cluster name (”hd-eks”), the associated Cluster IAM Role (”LabRole”), and the utilization of a KMS Key for secrets encryption. Figure 33: AWS Console: EKS cluster Details [Own Compilation] 49
Examining the node group details (Figure 34), specific information such as the node group name (”hd-ngroup”), specifications (t2.medium with 60 GB disk size), and the Node IAM Role (”LabRole”) are highlighted. Additionally, a single EC2 instance (Figure 35) is associated with this node group. Figure 34: AWS Console: Node group Details [Own Compilation] Figure 35: AWS Console: Node details from Node group [Own Compilation] Since AWS Academy Learner Lab is employed, access to kubectl is facilitated through Cloud9 [45] (Figure 36). To simplify the process, the creation of a Cloud9 environment was automated, functioning as both an integrated development environment (IDE) and runs on an EC2 instance. We utilized this environment for connecting to the EKS cluster and SSH access to EC2 instances. 50
Figure 36: AWS Console: Cloud 9 Interface [Own Compilation] Upon environment readiness, configuration steps involve modifying the IAM Role associated with the Cloud9 EC2 instance to ”LabInstanceProfile,” setting up AWS configuration and credentials in the ”.aws/” directory, installing kubectl [46] (matching the EKS cluster version, 1.27), and updating kubeconfig with the following commands: aws sts get -caller - identity aws eks update - kubeconfig -- region us -east -1 --name hd - eks Additional Resources Apart from the base infrastructure, specific AWS resources are essential for HuntDown. The Elastic Container Registry (ECR) was previously introduced in subsubsection 4.1.3. Additionally, in Figure 37, we could highlight two critical EC2 instances hd-services and hd-for-attacks. Figure 37: AWS Console: EC2 instances List [Own Compilation] The configuration of the hd-for-attacks EC2 instance, as illustrated in Figure 38, is similar to the setup for the hd-services instance. Both instances are associated with the VPC and public subnet, ensuring access to the private network. To maintain configuration simplicity and prevent alterations to the HuntDown setup, static private IPs are utilized. 51
Figure 38: AWS Console: Details of hd-for-attacks instance [Own Compilation] It is crucial to implement security groups to ensure the security of a system. The virtual firewall rules for the ”hd-services” instance are shown in Figure 39. With these rules set, we can control access and ensure security, particularly when it comes to hosting MongoDB and Pulsar services. Figure 39: AWS Console: Security Group of hd-services instance [Own Compilation] 52
5.2 Deployment of applications In this area, we detail the steps taken to deploy the HuntDown application on the AWS cloud. We also outline the Testbed preparation required to evaluate the newly added HuntDown functionality. 5.2.1 HuntDown services As described in this thesis, our CI process involves developers committing their code changes to HuntDown repository [36], which triggers an automated build process. This process entails compiling the code and creating Docker images, facilitating the seamless deployment of our application on AWS. Figure 40: HuntDown Deployment [Own Compilation] The HuntDown services are organized into two EC2 instances and a node group. Docker images are used for these instances, some of which are manually orchestrated, while others are orchestrated using Kubernetes. Configuration of third-party services As seen in subsubsection 4.1.3, we handle the creation and configuration of the MongoDB and Pulsar using scripts stored in the HuntDown GitLab Repository [36]. The following automated script involves cloning the entire HuntDown repository, setting up the necessary root directories (”/etc/huntdown/”, ”/usr/local/huntdown/”, and ”/var/huntdown/”), and adding essential configurations. 1#!/ bin /bash 2 3sudo apt update 4sudo apt install unzip 5 6# Clone GitLab repository through SSH using an authorized private key 7git clone -b erika_working_env git@gitlab . com : HuntDownUPC / HuntDown . git 8 53
9# Run code -job HuntDown , which creates root directories configuration and stores them in GitLab Artifacts 10 curl -- location -- output artifacts . zip " https :// gitlab . com / HuntDownUPC / HuntDown / -/ jobs /5985191257/ artifacts / download " 11 unzip artifacts . zip 12 sudo mv tmp / instantiation - manager / usr / local /* / usr / local / 13 sudo mv tmp / instantiation - manager / var /* / var 14 sudo mv tmp / instantiation - manager / etc /* / etc 15 16 # Add huntdown user 17 sudo useradd -r -- home - dir / var / huntdown -s / bin / false huntdown 18 sudo usermod -a -G ubuntu huntdown 19 echo " huntdown ALL =( ALL ) NOPASSWD :ALL " |sudo tee /etc / sudoers .d/ huntdown 20 21 # Update root directories owner 22 sudo chown -R huntdown : huntdown / usr / local / huntdown / 23 sudo chown -R huntdown : huntdown / var / huntdown / 24 sudo chown -R huntdown : huntdown / etc / huntdown / Listing 11: Setup hd-services workstation script Next, we update the MONGO USER and MONGO PASSWORD variables from the docker run mongo.sh script and we proceed to execute the init-db-and-pulsar.sh script located in the ”utils/” folder that will start both MongoDB and Pulsar. After this setup, we configure the first user in the database (Figure 41) and add attack schemas as needed (Listing 12). Figure 41: Add first user to database [Own Compilation] 1# Add / Update attacks schemas in Database 2cp / usr / local / huntdown / bin /hd - deploy - attack $HOME / HuntDown / src / database / DeployAttack/ 3 4cd $HOME / HuntDown / src / attacks 5 6export MONGO_USER = XXXXXXXX 7export MONGO_PASSWORD=XXXXXXXX 8export MONGO_HOST =" localhost " 9export MONGO_PORT =" 27017 " 10 11 ./ deploy - single - attack . sh hydra 12 ... Listing 12: Code to Add/Update Attack schemas The services can be monitored through docker logs $component id or systemctl status $system id commands. 54
Configuration of Instantiation Manager With Pulsar and MongoDB operational, we execute the Instantiation Manager service on the hd-attacks EC2 instance. The service is isolated in a separate instance to accommodate storing attack results in the root directory ”/var/huntdown”. The following setup involves installing necessary packages, adding SSH keys, configuring AWS credentials, and running the setup instantiation service.sh script. 1sudo apt update 2sudo apt install -y awscli docker docker .io zip make 3 4# Add Private key to execute Docker via SSH 5cat > ~/. ssh / docker_ssh_key << EOF 6----- BEGIN OPENSSH PRIVATE KEY ----- 7... 8----- END OPENSSH PRIVATE KEY ----- 9EOF 10 11 chmod 0400 ~/. ssh/ docker_ssh_key 12 13 # Authorize the public key obtained from the previous private key because the machine running Docker is the same as running Instantiation Manager 14 echo "ssh - ed25519 XXXXXXX " >> ~/. ssh / authorized_keys 15 16 # Clone GitLab repository through SSH using an authorized private key 17 git clone -b erika_working_env git@gitlab . com : HuntDownUPC / HuntDown . git 18 19 # Updating AWS credentials 20 mkdir ~/. aws 21 cat > ~/. aws / credentials << EOF 22 [default] 23 aws_access_key_id=XXXXXXX 24 aws_secret_access_key=XXXXXXX 25 aws_session_token=XXXXXXX 26 EOF 27 28 # Update ECR URL accordingly 29 aws ecr get - login - password -- region us - east -1 | sudo docker login -- username AWS -- password - stdin 998260163531. dkr . ecr .us - east -1. amazonaws . com 30 31 cd $HOME / HuntDown 32 ./setup_instantiation_service.sh Listing 13: Setup hd-attacks workstation script The setup instantiation service.sh script includes creating root directories, generating environment configuration files, creating the huntdown user, and establishing a system service for running the Docker service. 55
Next, a manual adjustment to the following configuration variables is required: •docker registry username and docker registry password: These credentials are essential for authorizing the pull from the Attacks GitLab Registry •attacks machine ip: This variable designates the Private IP of the machine to which we wish to connect via SSH for deploying attacks. In this context, it corresponds to the machine concurrently running the Instantiation Manager. Adjusting these variables ensures seamless connecting and authorizing for subsequent provisioning processes. Lastly, we could initiate the Instantiation service with sudo systemctl start huntdowninstantiation-docker. Configuration of HuntDown services Moving forward, we proceed to deploy the remaining HuntDown services, including Attacks Manager, Database Manager, and UI, using the terminal from the Cloud9 interface. After preconfiguring kubeconfig and AWS credentials in the previous subsection, we create and apply four Kubernetes manifests using the command kubectl apply -f $file. Namespace Manifest Firstly, we establish a namespace to group all HuntDown resources. 1apiVersion : v1 2kind: Namespace 3metadata: 4name: huntdown Listing 14: namespace.yaml Secrets configuration Manifest Next, we create a secret manifest to store a JSON file containing the secrets of Hunt- Down. Before applying the following file, we substitute the variables between % since they are secrets. 1apiVersion : v1 2kind: Secret 3metadata: 4namespace : huntdown 5name: environment - config 6type: Opaque 7stringData : 8environment . json : | 9{ 10 " huntdown_user ": " huntdown ", 11 "pulsar_user": "%PULSAR_USER%", 12 " pulsar_host ": " 10.0.1.36 ", 13 " pulsar_port ": " 6650 ", 56
14 " mongo_host ": " 10.0.1.36 ", 15 " mongo_port ": " 27017 " , 16 " mongo_user ": "% MONGO_USER %", 17 "mongo_password": "%MONGO_PASSWORD%", 18 " docker_registry_username ": "% REGISTRY_USER %", 19 " docker_registry_password ": "% REGISTRY_PASSWORD %", 20 " attacks_machine_ip ": " 10.0.1.89 ", 21 " results_dir ": "/ var / huntdown / results " , 22 " vagrant_base_dir ": "/ var / huntdown " , 23 " var_base_dir ": "/ var / huntdown " 24 } Listing 15: environment-config.yaml Deployment Manifest The Deployment manifest is implemented to deploy the main application. In this case, the three Docker containers run under the same pod in the node group hd-ngroup. As per security best practice, instead of using the tag ”latest” for the Docker images, we could utilize the image digest to ensure the selection of a specific image version. However, in this manual approach, we would have to modify the digests manually when images are updated. 1apiVersion : apps /v1 2kind: Deployment 3metadata: 4namespace : huntdown 5name: huntdown - deployment 6spec: 7selector: 8matchLabels: 9app . kubernetes .io /name: huntdown-app 10 replicas: 1 11 template: 12 metadata: 13 labels: 14 app . kubernetes .io /name: huntdown-app 15 spec: 16 containers : 17 -image : 998260163531. dkr .ecr.us -east -1. amazonaws .com /hd - database - manager : latest 18 imagePullPolicy : Always 19 name: huntdown -database -manager 20 volumeMounts: 21 -name: environment - config 22 mountPath : / etc / huntdown 23 -image : 998260163531. dkr .ecr.us -east -1. amazonaws .com /hd -attack - manager : latest 24 imagePullPolicy : Always 25 name: huntdown - attack - manager 26 volumeMounts: 27 -name: environment - config 28 mountPath : / etc / huntdown 57
After a brief period, the attack results became available, providing insights into vulnerabilities detected during the scan (Figure 53). The results can be downloaded for a more detailed analysis (Figure 54). Figure 53: Nikto Attack Results [Own Compilation] Figure 54: Nikto Attack Results Downloaded [Own Compilation] The Nikto scan revealed various application endpoints, including /DVWA/config, exposing sensitive configuration packages. By investigating these endpoints, we uncovered significant security flaws, such as the exposure of Application Database credentials. Figure 55: Path /DVWA/config - config.inc.php.bak [Own Compilation] 64
Additionally, querying the /DVWA/database endpoint exposed SQL files, and focusing on the sqli.db file allowed us to easily dump its contents using sqlite3. Figure 56: Path /DVWA/Database - sqli.db [Own Compilation] In summary, even a single attack yielded insightful findings during the reconnaissance phase. 5.3.2 Exploitation Having gathered information about the system, the next step is to exploit common vulnerabilities and identify potential security weaknesses. SQL Injection Continuing the analysis of vulnerabilities, we targeted a common exploit SQL Injection. Executing a simple SQLMap attack involved specifying the DVWA URL and the PHPSESSID Cookie (Figures 57 and 58). Figure 57: SQLMap Attack Form [Own Compilation] Figure 58: SQLMap Attack Form - Cookie option enabled [Own Compilation] 65
After a couple of seconds, the SQLMap results revealed information about the database server, including the version (Figures 59 and 60). Figure 59: SQLMap Attack Results Part I [Own Compilation] Figure 60: SQLMap Attack Results Part II [Own Compilation] Further SQLMap commands could provide details on the DVWA database, tables, users, and hashed passwords. However, we can perform a complete analysis by utilizing the –all option, enumerating all available information in a single run. Figure 61: SQLMap Attack All [Own Compilation] 66
The results included a dump of the users table, exposing users’ information and hashed passwords (Figure 62). Figure 62: SQLMap Attack All Results [Own Compilation] Brute Force Attack We have discovered interesting details of users registered to our vulnerable application. Now, we want to check how challenging it would be to obtain the password of a specific user, gordonb. To accomplish this, we will launch a hydra attack by specifying the target service, application port, and password list. This means that we will use a file containing the most frequently used passwords. Figure 63: Hydra Attack Form Part I [Own Compilation] Figure 64: Hydra Attack Form Part II [Own Compilation] 67
After a few seconds, we will see the successful execution of the attack and obtain the password of gordonb, which is ”abc123”. Figure 65: Hydra Attack Results Part I [Own Compilation] Additionally, we can view the command-line interface (CLI) results of the attack. Figure 66: Hydra Attack Results Part II [Own Compilation] 5.4 Assessing the outcomes obtained with Attacks Instantiation In the previous section, we demonstrated that by executing three fundamental attacks with HuntDown, we could unveil alarming sensitive information about DVWA. If we were to assume the role of an attacker, the disclosed details would provide ample opportunities to exploit vulnerabilities. To assess the outcomes achieved with Docker, our novel approach for launching attacks, we compared the time results of the previous penetration testing in various HuntDown deployment environments: Vagrant on a local machine, Docker on AWS, and Docker on a local machine (Table 10). 68
Attack Vagrant in Local Machine Docker in AWS Docker in Local Machine Nikto 40 798 38 SQLMap (simple) 34 22 20 SQLMap (all) 30 145 28 Hydra 65 5 4 Table 10: Comparison of attacks Deployment performance (in seconds) We created a chart to better visualize the timestamps of attack execution in the different environments. Figure 67: Attack deployment Chart [Own Compilation] Upon examining the chart, a noteworthy difference in the execution time emerges when running Nikto with Docker on AWS. The process is notably slower in comparison to the results obtained in the other two environments. This discrepancy may be attributed to the strict AWS policies for safeguarding the AWS infrastructure, and the numerous connections established by Nikto, leading to an overhead that saturates the AWS network. As a result, it causes a delay in receiving responses. Another important factor to consider is that the execution of attacks using Docker containers was much faster compared to Vagrant. This was because the required attacks and configurations were already installed in the Docker container, eliminating the need to install them manually. For instance, this is how we execute a Nikto attack: docker run -- name attack -d registry . gitlab . com / huntdownupc / attacks / nikto : latest -h http :// cybersecurity .pc.ac .upc.edu :28001/ DVWA / 69
Furthermore, we observed that the execution of SQLMap (all) in Vagrant was significantly faster compared to AWS. This could be attributed to the different SQLMap versions used. Vagrant installs a Debian machine using version 1.4.5, while the Docker image in our solution employs the latest version, 1.4.7. It is plausible that the updated version conducts more comprehensive checks, resulting in slightly longer execution times. In addition to these assessments, we observed that HuntDown was able to parse the results of the attacks without any issues, showcasing the adaptability and flexibility inherent in our solution. Overall, the benefits derived from these results are remarkably satisfactory. HuntDown has enabled us to conduct a straightforward and swift penetration test without being experts in the tools. 70
6 Future Development and Conclusions 6.1 Future Development Enhancing Deployment Automation: Integrating CD The core pipeline from the HuntDown repository allows us to continuously integrate our code changes seamlessly. However, to start up the application, manual steps are still required. Therefore, we should consider integrating the Kustomize tool 16 to streamline our CI/CD process and use ArgoCD to ensure robust continuous delivery. This approach aligns with modern DevOps principles, fostering efficiency, flexibility, and reliability in our deployment pipeline. Moreover, for enhanced security, it is advisable to adopt digests as the Docker image identifiers instead of using named tags. This can be easily integrated into our CI/CD pipeline, ensuring a more controlled versioning system. This step is crucial for safeguarding against potential attacks targeting the Docker images we are utilizing. Optimizing Development Workflow: Decentralizing HuntDown Microservices Currently, all the code for the HuntDown application resides in a single repository. However, this setup poses a significant drawback: even minor changes to a microservice require rebuilding the entire application to push updates to the registry, resulting in unnecessary pipeline expenses. Looking forward, our development strategy aims to address this issue by separating HuntDown’s responsibilities into distinct repositories. Specifically, we propose maintaining the frontend and backend components in the existing repository while creating three additional repositories for each of the microservices. This restructuring will streamline the continuous integration process and enhance overall productivity. Secrets Management Up until now, we have been storing the application’s secrets in a JSON file. However, this approach is not ideal because if an attacker gains access to our system, they could easily steal these secrets since they are stored in plaintext. To address this vulnerability, we propose incorporating Vault as a centralized service for storing and managing our secrets. Vault provides enhanced security features and integrates seamlessly with Kubernetes, aligning with best practices in secrets management. New Attacks Acquisition At the moment, HuntDown provides a collection of 12 attacks for the execution of penetration testing. As we look towards the future, the modular architecture implemented in HuntDown enables seamless integration of new pentesting tools into our platform. Leveraging Docker and our adaptable feature, we can efficiently containerize Linux-based tools, expanding the range of capabilities offered by HuntDown. 16Kustomize [49] is an excellent tool for deploying containerized applications into a Kubernetes cluster using a declarative approach 71
6.2 Conclusions This thesis project represents a major step forward in the evolution of HuntDown as a powerful penetration testing tool. It aims to simplify the creation of attacks for non-experts and systematically identify security vulnerabilities in a secure environment, making it a valuable asset in the field of Ethical Hacking. This project was driven by two main objectives: improving the deployment of attacks and automating the deployment of the HuntDown application in the cloud. By integrating Docker and Kubernetes into our toolkit, we have introduced unprecedented efficiency, scalability, reliability, and resource conservation compared to previous methodologies. The new approach incorporated in the Instantiation Manager micro-service has significantly enhanced agility in deploying attacks. By leveraging secure, lightweight, and isolated Docker containers, we ensured responsible and efficient security assessments. Our contributions also emphasized flexibility and scalability, allowing efficient result management and retrieval across diverse technologies, including Vagrant, Docker, and potential future methods. Automation was essential in deploying HuntDown in the cloud. We automated not only continuous integration processes but also utilized Terraform to provision AWS cloud infrastructure. Cloud deployment eliminates the need for users to install the tool onpremises, enhancing accessibility, usability, and resource efficiency. Regarding security concerns in AWS, we implemented a secure isolated private cloud within the AWS environment where we established our HuntDown application. Besides, we utilized security groups to control inbound traffic of EC2 instances and symmetric KMS keys to encrypt sensitive AWS resources. Despite challenges such as account expirations and limited budgets in the AWS Academy Lab environment, this project was a valuable learning experience in the Ethical Hacking field. We learned the importance of documentation and process automation for efficiency and time savings. In conclusion, our enhancements to the HuntDown framework are consistent with our commitment to innovation and our ongoing pursuit of productivity, adaptability, and security in ethical hacking and systems deployment. As a result, our efforts enable developers and end users to focus on developing and performing security audits with confidence. 72
References [1] Kris Lahiri. Why cybersecurity should still be a top priority for businesses. https://www.forbes.com/sites/forbestechcouncil/2023/03/21/ why-cybersecurity-should-still-be-a-top-priority-for-businesses/, 2023. [2] Pratiksha Pandit Engole. Why ethical hacking is essential in today’s digital landscape. https://www.linkedin.com/pulse/ why-ethical-hacking-essential-todays-digital-landscape-engole/, 2023. [3] Tenable. Tenable nessus. https://es-la.tenable.com/products/nessus, 2023. [4] Greenbone. Greenbone openvas. https://www.openvas.org/, 2023. [5] HackingLoops. Nessus vs openvas advantages and disadvantages explained. https: //www.hackingloops.com/nessus-vs-openvas/, 2023. [6] Vlad V. Maryna Z. Three myths debunked about open source software security. https://rubygarage.org/blog/open-source-software-security, 2022. [7] Kali Linux. Fierce — kali linux tools. https://www.kali.org/tools/fierce/, 2024. [8] Kali Linux. Goldeneye — kali linux tools. https://www.kali.org/tools/ goldeneye/, 2024. [9] Kali Linux. hping3 — kali linux tools. https://www.kali.org/tools/hping3/, 2024. [10] Kali Linux. hydra — kali linux tools. https://www.kali.org/tools/hydra/, 2024. [11] Kali Linux. Netcat — kali linux tools. https://www.kali.org/tools/netcat/, 2024. [12] NMAP. Nmap. https://nmap.org/, 2024. [13] sullo. nikto. https://github.com/sullo/nikto, 2024. [14] RAPID7. Metasploit. https://www.metasploit.com/, 2024. [15] Wikipedia. Slowloris (computer security). https://en.wikipedia.org/wiki/ Slowloris_(computer_security), 2023. [16] Bernardo Damele Assumpcao Guimaraes and Miroslav Stampar. sqlmap: automatic sql injection and database takeover tool. https://sqlmap.org/, 2024. [17] Wikipedia. Traceroute. https://es.wikipedia.org/wiki/Traceroute, 2023. [18] wpscan team. Wpscan. https://wpscan.com/, 2024. [19] Red Hat. What is ci/cd? https://www.redhat.com/en/topics/devops/ what-is-ci-cd?cicd=32h281b, 2023. [20] Kubernetes. Kubernetes documentation. https://kubernetes.io/, 2024. 73