Question: 3 . 4 Task 4 : Attack Mitigation using HMAC In the tasks so far, we have observed the damage caused when a developer computes

3.4 Task 4: Attack Mitigation using HMAC
In the tasks so far, we have observed the damage caused when a developer computes a MAC in an insecure way by concatenating the key and the message. In this task, we will fix the mistake made by the developer. The standard way to calculate MACs is to use HMAC. Students should modify the server program's verify_mac () function and use Python's hmac module to calculate the MAC. The function resides in lab. py. Given a key and message (both of type string), the HMAC can be computed as shown below (if you copy and paste the code from this PDF file, the ' characters might not be copied correctly on some platforms).
real_mac = hmac.new (bytearray (key.encode ('utf-8')),
msg=message.encode ('utf-8', 'surrogateescape'),
digestmod=hashlib.sha256). hexdigest ()
After making the changes, stop all the containers, rebuild them, and start all the containers again. The change will then take effect. Students should repeat Task 1 to send a request to list files while using HMAC for the MAC calculation. Assuming that the chosen key is 123456, the HMAC can be computed in the following program.
#!/bin/env python 3
import hmac
import hashlib
key='123456'
message =?' lst cmd=1'
mac = hmac. new (bytearray (key.encode ('ut f-8')),
msg= message.encode ('utf-8', 'surrogateescape'),
digestmod=hashlib.sha256). hexdigest ()
print (mac)
Students should describe why a malicious request using length extension and extra commands will fail MAC verification when the client and server use HMAC.
 3.4 Task 4: Attack Mitigation using HMAC In the tasks so

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!