I’ve got some credit cards but I don’t which ones are valid. Where did I get them? Uh, that’s not important.
Oh, you’ll probably need this: dae55498c432545826fb153885bcb06b
By mzone (@mzone on discord)
nc puffer.utctf.live 8625
Connect to the service. The service continuously queries, given a PAN, date, code, and cvv of a credit card, if the credit card is valid. One must get many consecutively right to receive the flag.
The first, rather trivial check to do is to check that the date is valid. The date is in the format MMYY, so just check if the month is less than 13 and greater than 0.
The second, also trivial check, is length checks. We just need to check that the date is of length 4 and that the code and cvv are length 3. The PAN also needs to be checked for length, but I ended up just not including it because it never was needed.
With some research, we can quickly find the existence of something known as Luhn’s algorithm. This is a way to validate a credit card’s PAN. The algorithm follows as such:
- Beginning from the end of the PAN and traversing backwards, double every other digit.
- For every digit, add it to a sum variable. If the digit, however, after being doubled, is two digits, instead add the sum of those two digits.
- If the sum is divisible by 10, it is a valid credit card number.
Here’s a small example:
PAN = 348745
Step 1: 6, 4, 16, 7, 8, 5
Step 2: 6 + 4 + (1 + 6) + 7 + 8 + 5 = 37
Since the sum is not divisible by 10, it is not a valid credit card PAN.
There are various online implementations of Luhn’s algorithm, like here.
The harder part of the problem was finding what to do with the rest of the information. I actually was not able to figure out the exact algorithm for this, but my teammate helped me out with this.
Here’s a quick outline of what we found.
We need a 16-byte key to use for DES. Note that the provided hex string in the challenge description is 16 bytes, which, to us, was very indicative of this algorithm being correct.
We also need a PAN, an expiration date equivalent to 4 numbers in MMYY format, and a 3 number service code.
Concatenate the PAN, expiration date, and service code, and then pad the result with zeros until it’s 32 bytes.
Using DES ECB, encrypt the first 16 bytes of the data with the first 8 bytes of the key.
XOR the result with the last 16 bytes of the data/
Encrypt the result with the first 8 bytes of the key.
Decrypt the result with the last 8 bytes of the key.
Encrypt the result with the first 8 bytes of the key.
The first three numeric digits from the hexlified bytes of the result is the CVV. (hexlified: A = 0x41).
Thus, with this algorithm, we can use the rest of the information to confirm whether or not the CVV is correct.
And that’s it! All that’s left is to implement it. See below:
1 | from pwn import * |
Run the script to get the flag!
utflag{hope_none_of_those_were_yours_lol}