Nedan är en artikel jag hittade nyligen. Detta en av de mest omfattande beskrivningar av PIN Verification Value (PVV) hacking.
Jag trodde jag skulle kopiera det här för min lokala referens.
Som kommentar har gjorts när det gäller grammatik som används i den ursprungliga texten, jag har rättat några av de uppenbara fel samtidigt som det i det ursprungliga materialet.
http://69.46.26.132/ ~ biggold1/fastget2you/tutorial.php
--- Originaltext ----
Förord
Har du någonsin undrar vad som skulle hända om du förlorar ditt kredit-eller betalkort och någon upptäcker det. Skulle denna person kunna ta ut kontanter från en uttagsautomat gissa, på något sätt, din PIN-kod? Dessutom, om du var som finner någons kortet skulle du försöka att ta PIN och ta chansen att få lite lätta pengar? Naturligtvis är svaret på båda frågorna bör vara "nej". Detta arbete behandlar inte andra fråga är det en fråga om personlig etik. Härmed jag försöker besvara den första frågan.
All information som används för detta arbete är offentliga och kan hittas på Internet. Resten är en fråga om matematik och programmering, vilket vi kan lära oss något och ha lite kul. Jag avslöjar inga hemligheter. Vidare är målet (och sista slutsatsen) med detta arbete är att visa att PIN algoritmer är fortfarande stark nog att ge tillräcklig säkerhet. Vi vet alla är inte den svaga punkten.
Detta arbete analyserar en av de vanligaste PIN algoritmer, VISA PVV, som används av många ATM-kort (kredit-och betalkort) och försöker ta reda på hur resistent är att PIN gissa attacker. Genom att "gissa" Jag menar inte att välja en slumpmässig PIN och försöker i en uttagsautomat. Det är väl känt att generellt vi får tre försök att ange rätt PIN-kod, om vi inte ATM håller kortet. Som VISA PIN fyrsiffrigt länge det är lätt att dra slutsatsen att risken för en slumpmässig PIN gissa är 3 / 10000 = 0,0003, det verkar tillräckligt låg för att vara säker, det betyder att du måste förlora ditt kort fler än tre tusen gånger ( eller förlorar mer än tretusen kort på samma gång:) tills det finns en rimlig chans att förlora pengar.
Vad jag egentligen menade med "gissa" var att bryta PIN algoritm så att ges något kan du omedelbart veta tillhörande PIN-kod. Detta dokument studier som möjligt, analysera algoritm och föreslå en metod för angrepp. Slutligen ger vi ett verktyg som genomför attacken och presentera resultaten om de uppskattade chansen att bryta systemet. Observera att så länge som andra bank skyddsrelaterad algoritmer (andra PIN format såsom IBM PIN eller kort validering signaturer som CVV-eller CVC) liknar VISA PIN, samma analys kan göras ger nästan samma resultat och slutsatser.
VISA PVV algoritm
En av de vanligaste PIN algoritmer är VISA PIN Verification Value (PVV). Kunden får en PIN-kod och en magnetremsa kortet. Encoded i magnetremsa är ett fyrsiffrigt nummer, kallad PVV. Denna siffra är en kryptografisk underskrift av PIN-och andra uppgifter med anknytning till kortet. När en användare skriver in sin PIN ATM läser magnetremsa, krypterar och skickar denna information till en central dator. There a trial PVV is computed using the customer entered PIN and the card information with a cryptographic algorithm . Rättegången PVV jämförs med PVV lagras på kortet, om de matchar den centrala datorn återgår till ATM tillstånd för transaktionen. Se mer i detalj.
Beskrivningen av PVV algoritm finns i två handlingar i föregående sida. Sammanfattningsvis består i kryptering av en 8 byte (64 bitar) sträng av data, kallas Transformed Security Parameter (TSP), med DES-algoritmen (DEA) i Electronic Code Book mode (ECB) med hjälp av en hemlig 64-bitars nyckel. Den PVV härrör från produktionen av kryptering, som är en 8 byte sträng. De fyra siffrorna i PVV (från vänster till höger) motsvarar de fyra första decimalsiffror (från vänster till höger) av produktionen från DES då betraktas som en 16 hexadecimala tecken (16 x 4 bitar = 64 bitar) sträng. Om det inte finns några fyra decimalsiffror bland de 16 hexadecimala tecken sedan PVV är klar fattas (från vänster till höger) utan decimal tecken och decimalizing dem med hjälp av omställning A-> 0, B-> 1, C-> 2, D -> 3, E-> 4, F-> 5. Här är ett exempel:
Produktion från DES: 0FAB9CDEFFE7DCBA
PVV: 0975
Strategin att undvika decimaliseringen av hoppa tecken tills fyra decimalsiffror finns (som råkar vara nästan alla gånger som vi kommer att se nedan) är väldigt smart eftersom man undviker en viktig snedvridning i fördelningen av siffror som har visat sig vara dödlig för andra system, även om påverkan på detta system skulle vara mycket lägre. Se också ett problem som inte gäller för VISA PVV.
Den TSP, ses som en 16 hexadecimala tecken (64 bitar) sträng, bildas (från vänster till höger) med 11 höger siffrorna i PAN (kortnummer) utom den sista siffran (kontrollsiffra), en siffra från 1 till 6 som väljer hemligt kryptera viktiga och slutligen de fyra siffrorna i PIN-kod. Här är ett exempel:
PAN: 1234 5678 9012 3445
Key väljaren: 1
PIN-kod: 2468
TSP: 5678901234412468
Uppenbarligen problemet med att bryta VISA PIN består i att finna hemligheten kryptera viktiga för DES. Metoden för detta är att göra en brute force-sökning av de viktigaste utrymme. Observera att detta inte är den enda metod kan man försöka hitta en svaghet i DEA har många försökt, men det gamla standarden är fortfarande allmänt använd (som nu ersatts med AES och RSA, men). Detta visar att det är robust nog för att "brute force" är den enda fungerande metoden (det finns några större attacker, men inte praktiskt i vårt fall, för en sammanfattning se LASEC memo och för smutsiga detaljer se Biham & Shamir 1990, Biham & Shamir 1991, Matsui 1993, Biham & Biryukov 1994 och Heys 2001).
Nyckeln väljaren siffra var mycket sannolikt införas för att täcka risken för en kompromiss. I detta fall de bara har att utfärda nya kort med en annan nyckel väljaren. Äldre kort kan ersättas med nya eller helt enkelt ATM kan öppet skriva en ny PVV (motsvarande den nya nyckeln och behålla samma PIN) nästa gång kunden använder sitt kort. För att skaka av säkerhet alla användare bör uppmanas att ändra sin PIN-koder, men det skulle vara pinsamt för banken att förklara varför, så mycket troligt att de inte skulle göra en sådan begäran.
Förberedelser attacken
En brute force-attack innebär att kryptera ett trippelsuperfosfat med kända PVV använda alla möjliga kryptera nycklar och jämföra varje erhållits PVV med den kända PVV. När en matchning hittas vi har en kandidat nyckel. Men hur många nycklar måste vi försöka? Som vi sade ovan nyckeln är 64 bitar långa, så skulle detta innebära att vi måste försöka 2 ^ 64 nycklar. Men detta är inte sant. Faktiskt bara 56 bitar är effektiva för att DES-nycklar, eftersom en bit (den minsta) av varje oktett var historiskt reserverats som en kontrollsumma för andra, i praktiken de som 8 bitar (en för varje av de 8 octets) ignoreras.
Därför DES nyckel utrymme består av 2 ^ 56 nycklar. Om vi försöker alla dessa knappar kommer vi hitta en och endast en match, vilket motsvarar bankens hemliga nyckel? Absolut inte. Vi kommer att få många matchande nycklar. Detta beror på att PVV är bara en liten del (en fjärdedel) av DES produktion. Dessutom PVV är degenererat, eftersom några av de siffror (mellan 0 och 5 efter det att den sista, sett från vänster till höger, siffror mellan 6 och 9) kan komma från en decimal siffra eller från en decimalized hexadecimala siffran i DES produktion. Alltså många nycklar kommer att producera en DES produktion vilket innebär att samma matchande PVV.
Vad kan vi göra för att hitta den verkliga nyckeln bland de andra falska positiva nycklarna? Bara vi har för att kryptera ett andra olika TSP, även känd PVV, men endast med de sökande nycklar som gav en positiv matchning med första TSP-PVV par. Men det finns ingen garanti att vi inte kommer att få igen många falska positiva med den verkliga nyckeln. Om så är fallet kommer vi att behöva ett tredje TSP-PVV par, upprepa processen och så vidare.
Innan vi börjar vår attack måste vi veta hur många TSP-PVV par kommer vi att behöva. För att vi har för att beräkna sannolikheten för en slumpmässig DES produktion ge en matchning PVV bara av en slump. Det finns flera sätt att beräkna antalet och här kommer jag att använda en enkel metod lätt att förstå, men som kräver lite bakgrundsinformation i matematik av sannolikhet.
En sannolikhet alltid kan ses som förhållandet mellan god fall att eventuella fall. I vårt problem antalet möjliga fall fås genom permutation av 16 delar (0 till F hexadecimala siffror) i en grupp av 16 av dem (16 hexadecimala siffror i DES output). Detta ges av 16 ^ 16 ~ 1,8 * 10 ^ 19 vilket naturligtvis sammanfaller med 2 ^ 64 (olika nummer av 64 bitar). Denna uppsättning siffror kan delas in i fem kategorier:
De som har minst fyra decimala siffror (0 till 9) bland de 16 hexadecimala siffror (0 till F) av DES produktion.
De som har exakt tre decimaler.
Personer med exakt två decimaler.
De som har just bara en decimal siffra.
De som inte decimalsiffror (alla mellan A och F).
Låt oss räkna hur många siffror faller inom varje kategori. Om vi märka 16 hexadecimala siffror i DES produktion som X1 att X16 kan vi märka första fyra decimalsiffror av ett visst antal av den första kategorin som Xi, XJ, XK och XL. The number of different combinations with this profile is given by the product 6 i-1 * 10 * 6j-i-1 * 10 * 6k-j-1 * 10 * 6 lk-1 * 10 * 1616-l where the 6’s come from the number of possibilities for an A to F digit, the 10’s come from the possibilities for a 0 to 9 digit, and the 16 comes from the possibilities for a 0 to F digit. Now the total numbers in the first category is simply given by the summation of this product over i, j, k, l from 1 to 16 but with i < j < k < l. If you do some math work you will see this equals to the product of 104/6 with the summation over i from 4 to 16 of (i-1) * (i-2) * (i-3) * 6i-4 * 16 16-i ~ 1.8 * 1019.
Analogously the number of cases in the second category is given by the summation over i, j, k from 1 to 16 with i < j < k of the product 6i-1 * 10 * 6j-i-1 * 10 * 6k-j-1 * 10 * 616-k which you can work it out to be 16!/(3! * (16-13)!) * 103 * 6 13 = 16 * 15 * 14/(3 * 2) * 103 * 613 = 56 * 104 * 613 ~ 7.3 * 1015. Similarly for the third category we have the summation over i, j from 1 to 16 with i < j of 6 i-1 * 10 * 6j-i-1 * 10 * 616-j which equals to 16!/(2! * (16-14)!) * 102 * 614 = 2 * 103 * 615 ~ 9.4 * 1014. Again, for the fourth category we have the summation over i from 1 to 16 of 6i-1 * 10 * 616-i = 160 * 615 ~ 7.5 * 1013. And finally the amount of cases in the fifth category is given by the permutation of six elements (A to F digits) in a group of 16, that is, 616 ~ 2.8 * 1012.
I hope you followed the calculations up to this point, the hard part is done. Now as a proof that everything is right you can sum the number of cases in the 5 categories and see it equals the total number of possible cases we calculated before. Do the operations using 64 bit numbers or rounding (for floats) or overflow (for integers) errors won’t let you get the exact result.
Up to now we have calculated the number of possible cases in each of the five categories, but we are interested in obtaining the number of favorable cases instead. It is very easy to derive the latter from the former as this is just fixing the combination of the four decimal digits (or the required hexadecimal digits if there are no four decimal digits) of the PVV instead of letting them free. In practice this means turning the 10’s in the formula above into 1’s and the required amount of 6’s into 1’s if there are no four decimal digits. That is, we have to divide the first result by 104, the second one by 103 * 6, the third one by 102 * 62 , the fourth one by 10 * 63 and the fifth one by 64 . Then the number of favorable cases in the five categories are approximately 1.8 * 1015, 1.2 * 1012, 2.6 * 1011 , 3.5 * 1010, 2.2 * 109 respectively.
Now we are able to obtain what is the probability for a DES output to match a PVV by chance. We just have to add the five numbers of favorable cases and divide it by the total number of possible cases. Doing this we obtain that the probability is very approximately 0.0001 or one out of ten thousand. Is it strange this well rounded result? Not at all, just have a look at the numbers we calculated above. The first category dominates by several orders of magnitude the number of favorable and possible cases. This is rather intuitive as it seems clear that it is very unlikely not having four decimal digits (10 chances out of 16 per digit) among 16 hexadecimal digits. We saw previously that the relationship between the number of possible and favorable cases in the first category was a division by 10^4, that’s where our result p = 0.0001 comes from.
Our aim for all these calculations was to find out how many TSP- PVV pairs we need to carry a successful brute force attack . Now we are able to calculate the expected number of false positives in a first search: it will be the number of trials times the probability for a single random false positive, ie t * p where t = 2^56, the size of the key space. This amounts to approximately 7.2 * 10^12, a rather big number. The expected number of false positives in the second search (restricted to the positive keys found in the first search) will be (t * p) * p, for a third search will be ((t * p) * p) * p and so on. Thus for n searches the expected number of false positives will be t * p^n.
We can obtain the number of searches required to expect just one false positive by expressing the equation t * p^n = 1 and solving for n. So n equals to the logarithm in base p of 1/t, which by properties of logarithms it yields n = log(1/t)/log(p) ~ 4.2. Since we cannot do a fractional search it is convenient to round up this number. Therefore what is the expected number of false positives if we perform five searches? It is t * p^5 ~ 0.0007 or approximately 1 out of 1400. Thus using five TSP- PVV pairs is safe to obtain the true secret key with no false positives.
The attack
Once we know we need five TSP- PVV pairs, how do we get them? Of course we need at least one card with known PIN , and due to the nature of the PVV algorithm , that’s the only thing we need. With other PIN systems, such as IBM, we would need five cards, however this is not necessary with VISA PVV algorithm . We just have to read the magnetic stripe and then change the PIN four times but reading the card after each change.
It is necessary to read the magnetic stripe of the card to get the PVV and the encrypting key selector. You can buy a commercial magnetic stripe reader or make one yourself following the instructions you can find in the previous page and links therein. Once you have a reader see this description of standard magnetic tracks to find out how to get the PVV from the data read. In that document the PVV field in tracks 1 and 2 is said to be five character long, but actually the true PVV consists of the last four digits. The first of the five digits is the key selector. I have only seen cards with a value of 1 in this digit, which is consistent with the standard and with the secret key never being compromised (and therefore they did not need to move to another key changing the selector).
I did a simple C program, getpvvkey.c, to perform the attack . It consists of a loop to try all possible keys to encrypt the first TSP, if the derived PVV matches the true PVV a new TSP is tried, and so on until there is a mismatch, in which case the key is discarded and a new one is tried, or the five derived PVVs match the corresponding true PVVs, in which case we can assume we got the bank secret key, however the loop goes on until it exhausts the key space. This is done to assure we find the true key because there is a chance (although very low) the first key found is a false positive.
It is expected the program would take a very long time to finish and to minimize the risks of a power cut, computer hang out, etc. it does checkpoints into the file getpvvkey.dat from time to time (the exact time depends on the speed of the computer, it’s around one hour for the fastest computers now in use). For the same reason if a positive key is found it is written on the file getpvvkey.key. The program only displays one message at the beginning, the starting position taken from the checkpoint file if any, after that nothing more is displayed.
The DES algorithm is a key point in the program, it is therefore very important to optimize its speed. I tested several implementations: libdes, SSLeay, openssl, cryptlib, nss, libgcrypt, catacomb, libtomcrypt, cryptopp, ufc-crypt. The DES functions of the first four are based on the same code by Eric Young and is the one which performed best (includes optimized C and x86 assembler code). Thus I chose libdes which was the original implementation and condensed all relevant code in the files encrypt.c (C version) and x86encrypt.s (x86 assembler version). The code is slightly modified to achieve some enhancements in a brute force attack : the initial permutation is a fixed common steep in each TSP encryption and therefore can be made just one time at the beginning. Another improvement is that I wrote a completely new setkey function (I called it nextkey) which is optimum for a brute force loop.
To get the program working you just have to type in the corresponding place five TSPs and their PVVs and then compile it. I have tested it only in UNIX platforms, using the makefile Makegetpvvkey to compile (use the command “make -f Makegetpvvkey”). It may compile on other systems but you may need to fix some things. Be sure that the definition of the