Showing posts with label foundations. Show all posts
Showing posts with label foundations. Show all posts

9/30/2024

Nmap Basics for Penetration Testing

          ___.-------.___
      _.-' ___.--;--.___ `-._
   .-' _.-'  /  .+.  \  `-._ `-.
 .' .-'      |-|-o-|-|      `-. `.
(_ <O__      \  `+'  /      __O> _)
  `--._``-..__`._|_.'__..-''_.--'
        ``--._________.--''

Nmap, short for Network Mapper, is a free and open-source tool widely used for network discovery and security auditing. Nmap utilizes raw IP packets in innovative ways to gather information about a network. It can identify available hosts, running services (including application name and version), operating systems, firewalls or packet filters in use, and many other details. Designed for rapid scanning of large networks, Nmap also works effectively for single hosts.

Network administrators rely on Nmap for various tasks, including creating network inventories, managing service upgrades, and monitoring uptime of hosts and services, while hackers may utilize it for enumeration i.e. identifying open ports running services that may be exploitable.

Nmap is available for most operating systems but is included with the Kali Linux distro. Remember to replace the placeholder ip address with your target ip address. You can also test this out by scanning the url: scanme.nmap.org. Let's start off with a basic Nmap scan. We can scan using an ip address or a host name i.e. scanme.nmap.org:

nmap 192.168.1.1

We can also scan a list of network/host targets within a text file using the following commands where "ip_list.txt" is the path to the text file.

nmap -iL ip_list.txt 

When performing a penetration test on a network, we may want to perform a ping sweep scan, which pings all available hosts on a network by sending ICMP packets and returns the live hosts. Conducting a ping sweep is a crucial part of identifying active hosts on a network and lays the groundwork for a penetration test.

nmap -sn 192.168.0.0/24

Once we have the list of live hosts, we can then do port scans on the individual hosts. Note the "/24" addition to the ip address. This sets the ip address range. It will send an ICMP echo request to every ip address in the network from 192.168.0.1 to 192.168.0.255.

Nmap defaults to scanning the 1000 most commonly used ports. Port specification and scan order refer to the process of selecting which ports to scan during network reconnaissance. This is crucial for efficient scanning as it allows you to exclude irrelevant ports and prioritize the scan based on port usage frequency.

We can specify ports using the following command:

nmap -p 22,80,443 192.168.1.1

We can also scan for the operating system. This information helps pinpoint vulnerabilities specific to the operating system, enabling more effective attacks on the target system. We can use "-O" to enable OS detection.

nmap -O 192.168.1.1

What if we want to detect the services being run on open ports on the network? The service/version detection feature in Nmap provides valuable insights into the target system, enabling you to identify vulnerabilities and weaknesses on those ports. This option can be enabled by using "-sV".

nmap -sV 192.168.1.1

With the returned information, we can run a query using something like  searchsploit for possible exploits for these services.

One of the most popular scans used is the SYN scan. A SYN scan involves sending an SYN packet to the target host and monitoring for a response. If the target responds with an SYN/ACK packet, the port is open; if it responds with an RST packet, the port is closed. This half-open scan technique, which doesn't complete the full TCP three-way handshake, is fast and, most importantly, stealthy, ideal for mapping large networks.

nmap -sS 192.168.1.1

Being stealthy is an important part of penetration testing. Some firewalls and Intrusion Detection System (IDS) solutions may temporarily block ip addresses that exhibit unusual network activity, such as high traffic volumes or sending network packets to multiple hosts in a systematic manner. We can mitigate these risks by using certain commands that effect the scans order and timing.

We can add the "-T" option to effect the scans timing template. By default, Nmap uses the "-T2" timing template but we can slow the scan down by using the "-T1" or "-T0" timing templates. These will slow down the scan process but will minimize the impact on the network and prevent triggering any alerts.

nmap -T1 192.168.0.0/24

You can also slow down an Nmap scan using delay. Use the "--scan-delay" option and specify the desired delay time in seconds.

nmap --scan-delay 3s 192.168.0.0/24

Let's change the order of targets we scan. Nmap's --randomize-hosts option can help you randomize your scans, making them less predictable and harder to detect by security.

nmap --randomize-hosts 192.168.0.0/24

One of the most powerful features of Nmap is it's ability to run scripts. The Nmap Script Engine (NSE) are scripts written in the programming language, Lua.

For example, you can run the following command that runs the "http-headers" script which pulls the HTTP headers configured on the target webserver.

nmap --script http-headers scanme.nmap.org

As a penetration tester, you may want to run the "vulners" script which automatically lists the vulnerabilities on a target using a CVE database.

nmap --script vulners 192.168.1.1

There are hundreds of NSE scripts available which you can view here.

9/24/2024

Password Cracking With Hashcat

 _._     _,-'""`-._
(,-.`._,'(       |\`-/|
    `-.-' \ )-`( , x x)
          `-    \`_`"'-

Hashcat is a command line interface password cracking tool for over 300 hashing algorithms. Hashcat can utilize five possible attack modes including brute-force, dictionary attacks, and more. We will be focusing on dictionary attacks, a more simple and faster attack mode that compares the hashed password to a wordlist rather than brute-force methods which can take a large amount of time and computer resources due to the attacks method of running combinations of random characters through trial and error.

We will be using the rockyou.txt password list. This password list was compiled back in 2009 after a major data breach at RockYou, a social media app and advertising network. The list contains over 14 million unique passwords that are commonly used amongst the general public and is a staple wordlist in the hacker community. You can view and download other password lists from here.

Passwords are usually discovered as hashes. Password hashing is the practice of algorithmically turning a plain-text password into ciphertext, or an irreversibly obfuscated version of itself, as a means of blocking against the threat of password breaches. This process helps secure passwords from the naked eye. There are many types of hashing algorithms including MD5, SHA-1, SHA-256, and hundreds of others. As mentioned earlier, Hashcat can crack over 300 different types of hashing algorithm. Below is a collection of downloadable hashed passwords which can be utilized for practice with Hashcat and the rockyou.txt password list. You can also hash your own passwords using online resources such as the All Hash Generator on Browserling.com.

Hashed Password Samples:
MD5Password.txt
SHA1Password.txt
SHA256Password.txt
CRC32Password.txt
NTLMPassword.txt

Hashcat can be downloaded on various operating systems but is included in the Kali Linux distro. We can crack our first MD5 hashed password in the samples above using the below command in our terminal:

hashcat –m 0 *path to MD5Password.txt* *path to rockyou.txt*

The first option of the command, "-m 0", sets the type of hash you are attempting to crack, 0 being MD5. You can view all the Hashcat hashing algorithms and their dedicated #'s using the command "hashcat --help". For example, 100 is to be used for SHA-1 hashes. If you do not know the hashing algorithm used in the password you are attempting to crack, you can use a hash identifying tool like hash-identifier which is included in Kali Linux distros. 

The second option, "*path to MD5Password.txt*", directs Hashcat to the hashed password file path. For example /home/USERNAME/Downloads/MD5Password.txt, where USERNAME is your username. The final option of the command is the path to the wordlist you are running the attack against. Kali Linux includes many default wordlists, including rockyou.txt, in the /usr/share/wordlists path. Please note that you will need to unzip the rockyou.txt.gz directory on your machine if you haven't already by using the gunzip command.

Let's run the command and see what Hashcat comes up with:

hashcat -m 0 /root/Downloads/MD5Password.txt /usr/share/wordlists/rockyou.txt
hashcat (v6.2.6) starting

OpenCL API (OpenCL 3.0 PoCL 5.0+debian  Linux, None+Asserts, RELOC, SPIR, LLVM 16.0.6, SLEEF, DISTRO, POCL_DEBUG) - Platform #1 [The pocl project]
==================================================================================================================================================
* Device #1: cpu-haswell-AMD Ryzen 5 4600H with Radeon Graphics, 1425/2914 MB (512 MB allocatable), 2MCU

Minimum password length supported by kernel: 0
Maximum password length supported by kernel: 256

Hashes: 1 digests; 1 unique digests, 1 unique salts
Bitmaps: 16 bits, 65536 entries, 0x0000ffff mask, 262144 bytes, 5/13 rotates
Rules: 1

Optimizers applied:
* Zero-Byte
* Early-Skip
* Not-Salted
* Not-Iterated
* Single-Hash
* Single-Salt
* Raw-Hash

ATTENTION! Pure (unoptimized) backend kernels selected.
Pure kernels can crack longer passwords, but drastically reduce performance.
If you want to switch to optimized kernels, append -O to your commandline.
See the above message to find out about the exact limits.

Watchdog: Temperature abort trigger set to 90c

Host memory required for this attack: 0 MB

Dictionary cache built:
* Filename..: /usr/share/wordlists/rockyou.txt
* Passwords.: 14344392
* Bytes.....: 139921507
* Keyspace..: 14344385
* Runtime...: 1 sec

6104df369888589d6dbea304b59a32d4:blink182                 
                                                          
Session..........: hashcat
Status...........: Cracked
Hash.Mode........: 0 (MD5)
Hash.Target......: 6104df369888589d6dbea304b59a32d4
Time.Started.....: Tue Sep 24 15:54:28 2024 (0 secs)
Time.Estimated...: Tue Sep 24 15:54:28 2024 (0 secs)
Kernel.Feature...: Pure Kernel
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........:     9780 H/s (0.06ms) @ Accel:256 Loops:1 Thr:1 Vec:8
Recovered........: 1/1 (100.00%) Digests (total), 1/1 (100.00%) Digests (new)
Progress.........: 512/14344385 (0.00%)
Rejected.........: 0/512 (0.00%)
Restore.Point....: 0/14344385 (0.00%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidate.Engine.: Device Generator
Candidates.#1....: 123456 -> letmein
Hardware.Mon.#1..: Util: 66%

Started: Tue Sep 24 15:53:52 2024
Stopped: Tue Sep 24 15:54:30 2024

Success! After a few seconds we can see the hashed password, blink182, has been cracked at the line highlighted in orange. Blink-182 fans beware, your password isn't fooling even the most amateur of hackers out there.

Try using Hashcat with the other sample hashed passwords in this post, or hash your own passwords using the All Hash Generator on Browserling.com and see if your passwords are vulnerable to dictionary attacks using the rockyou.txt or other common wordlists. To learn more about Hashcat and it's other features, visit their Wiki here.

9/04/2024

Understanding DoS Attacks

  **       **       **
** ** **
|\**/| |\**/| |\**/| \ == / \ == / \ == / | | | | | |
|__| |__| |__| \ / \ / \ / \/  \/ \/

A DoS (Denial-of-Service) attack targets a network/server and floods it with network traffic, ultimately causing service disruption by overloading the target network and causing it to crash. To have a better understanding of DoS attacks on the network level, we need to understand how network traffic is transported. Network traffic is broken up and sent via data packets to the destination. 

An ICMP flood attack is a type of DoS attack performed by an attacker repeatedly sending Internet Control Message Protocol (ICMP) packets to a network server. This forces the targeted server to send an ICMP packet back. This eventually uses up all the bandwidth for incoming and outgoing traffic and causes the server to crash. We can replicate this attack using a packet generator program called hping, which can be downloaded from most Linux repositories. See the command below where "*target_ip*" is the ip of the targeted network and "-1" utilizes the ICMP protocol:

sudo hping3 -1 --flood *target_ip*

Another common DoS attack is the SYN flood attack. This attack uses the Transmission Control Protocol (TCP) and floods the server with synchronize (SYN) packets. To establish a TCP connection, a device sends a SYN packet request to a server. The server then responds with a SYN/ACK packet to acknowledge the receipt of the device's request and leaves a port open for the final step of the handshake. Once the server receives the final acknowledgement (ACK) packet from the device, the 3-way handshake is complete and a TCP connection is established. Attackers can take advantage of the protocol by flooding a server with SYN packet requests and never fully completing the 3-way handshake. This attack can be replicated using hping with the following command, where "-d 300" is the amount of data in bytes you wish to send in the packet, "-p 80" is the desired port you wish to attack, the "-S" switch places hping in SYN mode, and "*target_ip*" is the ip of the targeted network:

sudo hping3 -d 300 -p 80 -S --flood *target_ip*

A standard DoS attack utilizing a single source of network traffic is usually not enough to cause any major disruptions, let alone crash a network. A DDoS attack is a Distributed Denial-of-Service attack. DDoS attacks are usually performed using botnets, a large collection of compromised private internet-connected devices infected with malware and controlled as a group. These compromised devices are sometimes refereed to as "zombies". Using a botnet, an attacker can send requests from these computers to have a larger impact on the networks bandwidth, making it easier to crash the target network.