The lab
here is how portswigger describes it
This lab doesn't adequately validate user input. You can exploit a logic flaw in its account registration process to gain access to administrative functionality. To solve the lab, access the admin panel and delete the user carlos.
admin access is gated on having a @dontwannacry.com email, but the registration process validates the address and then stores it in a field capped at 255 characters. those two steps disagree about what our email actually is. we register an exceptionally long address that is still our harmless mail server when the confirmation link gets sent, but after it is truncated at exactly 255 characters the stored value ends in @dontwannacry.com, so the account inherits the admin role. we line the string up so the m of .com lands on character 255, then confirm from our own inbox and walk into the admin panel.
why the truncation breaks this##
the role check and the email storage are reading the same field at two different lengths, and that mismatch is the whole bug. at registration the server looks at the full address, sees it belongs to our own email server, and happily sends the confirmation link there. but the column that actually holds the email is 255 characters wide, so the value is silently cut down before it is saved, no error, no rejection. by padding the local part we control exactly where that cut falls. we make [email protected] the first 255 characters and push our real domain past the cliff, so the mail is delivered using the full string while the stored identity becomes a @dontwannacry.com address. the admin gate trusts that stored identity, and it now reads as a company employee.
Step 1 - discover the admin path##
we open the lab and go to Target > Site map. we right-click the lab domain and choose Engagement tools > Discover content to open the content discovery tool, then click Session is not running to start it.

Step 2 - confirm the admin gate##
after a short while we look at the Site map tab inside the dialog and notice it found /admin. we browse to /admin, and although we are blocked, the error message tells us that DontWannaCry users do have access, so the admin role is tied to that company.

Step 3 - read the registration hint##
we go to the account registration page and notice the message telling DontWannaCry employees to register with their company email address. that confirms the gate keys on a @dontwannacry.com email.

Step 4 - note our email server id##
from the button in the lab banner we open the email client and make a note of the unique id in our email server's domain, @YOUR-EMAIL-ID.web-security-academy.net.

Step 5 - probe the length limit##
back in the lab we register with an exceptionally long address in the format [email protected], where the very-long-string is at least 200 characters.

Step 6 - confirm and measure the truncation##
we go to the email client, open the confirmation email, and click the link to finish registering. we log in, go to My account, and notice our email address has been truncated to 255 characters. that is the behaviour we weaponise. we log out and return to the registration page.

Step 7 - place dontwannacry.com on the boundary##
we register a new account with another long address, but this time we slip dontwannacry.com in as a subdomain:
very-long-string@dontwannacry.com.YOUR-EMAIL-ID.web-security-academy.net
we size the very-long-string so that the m at the end of @dontwannacry.com is character 255 exactly. everything after it, our real .web-security-academy.net server, falls past the cut and is discarded on storage, but is still present when the mail is sent.

Step 8 - confirm from our own inbox##
we go to the email client and click the link in the confirmation email we received, because the full, untruncated address delivered to our own server. we log in to the new account and notice we now have access to the admin panel, the stored email having been truncated to a @dontwannacry.com identity.

Step 9 - delete carlos##
we go to the admin panel and delete the user carlos.

with this, the lab is solved!
