Changeset 5
- Timestamp:
- 10/17/12 19:52:34 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/nextrand.c
r1 r5 5 5 Copyright (C) 2012 Virtual Security Research, LLC 6 6 Author: Dan J. Rosenberg 7 Updates by: Timothy D. Morgan 7 8 8 9 This program is free software: you can redistribute it and/or modify … … 30 31 int nextInt() 31 32 { 32 33 seed = (seed * MULTIPLIER + ADDEND) & MASK; 34 return (int) (seed >> 16); 35 33 seed = (seed * MULTIPLIER + ADDEND) & MASK; 34 return (int) (seed >> 16); 36 35 } 37 36 … … 39 38 int main(int argc, char **argv) 40 39 { 41 42 int i, num; 43 unsigned long long r1, r2; 44 45 46 if (argc != 4) { 47 printf("[-] Usage: %s rand1 rand2 num\n", argv[0]); 48 return 1; 49 } 50 51 r1 = atoi(argv[1]); 52 r2 = atoi(argv[2]); 53 num = atoi(argv[3]); 54 55 for (i = 0; i < 65536; i++) { 56 seed = (r1 << 16) + i; 57 if ((unsigned int)(((seed * MULTIPLIER + ADDEND) & MASK) >> 16) == (unsigned int)r2) { 58 break; 59 } 60 seed = 0; 61 } 62 63 if (!seed) { 64 printf("[-] Seed not found.\n"); 65 return 1; 66 } 67 68 /* Uncomment to print the first two values, which were already provided */ 69 // printf("%d\n", (int)r1); 70 // printf("%d\n", nextInt()); 71 72 for (i = 0; i < num; i++) { 73 printf("%d\n", nextInt()); 74 } 75 76 return 0; 77 40 int i, num; 41 unsigned long long r1, r2; 42 43 if (argc != 4) 44 { 45 fprintf(stderr, "[-] Usage: %s rand1 rand2 num\n", argv[0]); 46 fprintf(stderr, 47 "[-] Note that rand1 and rand2 must be signed integers returned in sequence\n" 48 " from a single Java Random instance. Values provided must be generated\n" 49 " by Random.nextInt() which was called with no arguments.\n"); 50 return 1; 51 } 52 53 r1 = atoi(argv[1]); 54 r2 = atoi(argv[2]); 55 num = atoi(argv[3]); 56 57 for (i = 0; i < 65536; i++) 58 { 59 seed = (r1 << 16) + i; 60 if ((unsigned int)(((seed * MULTIPLIER + ADDEND) & MASK) >> 16) == (unsigned int)r2) 61 break; 62 63 seed = 0; 64 } 65 66 if (!seed) { 67 fprintf(stderr, "[-] Seed not found.\n"); 68 return 1; 69 } 70 71 fprintf(stderr, "[+] Seed %.12llX found based on provided values: ", seed); 72 fprintf(stderr, "%d %d\n", (int)r1, nextInt()); 73 fprintf(stderr, "[+] Next %d values:\n", num); 74 75 for (i = 0; i < num; i++) 76 printf("%d\n", nextInt()); 77 78 return 0; 78 79 }
Note: See TracChangeset
for help on using the changeset viewer.