simple signature - Crypto
Task
The s in rsa stands for secure.
nc betta.utctf.live 4374
Solution
We get only information about how to connect to the server. So let's connect to see how it works:
szczygielka@hacks$ nc betta.utctf.live 4374
Welcome to the signature generator!
This service generates signatures for nonnegative integer messages.
Today's RSA parameters are:
n = 17007115661299815607779165325006475925060995570648249126487030335644203023481846638117502461440332111444430916767200503666795042264359564422897594202938598017705990008042877313795222435128369842652331645057052654864153662402967586505198149442619066069665399964917886690584407737138071046442779048899209367834725450164047862000686231313652343200922838123212694312780180541822058518287645925643501380574048457140971384357731590128868557198143735637246158985421310165371697896791564736610273577022563266299497980201341938025773037378412970953178288939570091648227422253383650988673431907753115858499383009001338523288087
e = 65537
Enter a message as an integer (enter 0 to stop): 2
Your signature is: 6672957953572898291912874637593697014101172364647215740830900911644569712185295765745418452963497463275123251748952403305001368745981830456197804415177494270001131898055965726185773582177908222725950920241045612464232492749961514337999947924777746096071879416722777928572833948616707226872981090448612762382663274986788162021813367382415915672886879690116171900002788502748187211138753302953634267728098740540801330595107303819427658290454721300644156991165726094646851144048881902055363646383706901609234926756120255588681727697911438036366466679519130986883486700046862967465455783444359689098389239391853331493149
Enter a message as an integer (enter 0 to stop): 3
Your signature is: 2489355093949788277772248629243069986608791937535601737135622933254496365765932518220438140785809898088376102226248195015617328688580982151381273120828016088777408113045970326379287582105630891959710381877864144955748352250386354887117900428266230023602707106952578855774464713335240514344219988834753712048133975681621557356736836815344888196103902767834383982656310862090337589073425432345749789501727668558023522752244962712971711970202489196742528339273279883755796908964160428004572278447515065391236485876470418430841869466382073943825117186740672592574369890018680015742556388573397785190613698745962915695490
Enter a message as an integer (enter 0 to stop): 0
Now, come up with your own pair!
Enter a message: 5
Enter a signature:After connecting to the server we get the values of N and e, and we are asked to enter the message as an integer. Then we get the signed message. Entering the value 0 causes that we are asked to provide a message as an integer, and then we are asked to enter the signature for this message. However, we cannot provide a signature for a message whose signature we have already received. So we need to find a way to predict the signature for the message that we didn't enter.
Signing message
The signature of person A for message M in RSA is calculated as:
where d is a private key.
There is an attack that allows us to generate a correctly signed message under specific conditions without knowing the private key. This attack is known as a chosen message attack.
Chosen message attack
Suppose that B can construct and such that:
If person B has the valid signatures of person A for messages and that is and , person B can form the product of these signatures to get a false signature of person A on , calculated as:
Since we can generate any 2 messages and receive correct signatures for them in response, we can prepare a 3rd message based on and , and next sign it correctly.
Short Python script that allows for generation and valid signature of :
After entering the generated values of an , we get the flag:
Flag:
Last updated