# Yet Another Random Story: VBScript's Randomize Internals

DevFeed: [Yet Another Random Story: VBScript's Randomize Internals](<https://devfeed.tech/articles/yet-another-random-story-vbscript-s-randomize-internals-92066.md>)

Original publisher: [Read original article](<https://blog.doyensec.com/2025/09/25/yet-another-random-story.html>)

Published: 2025-09-24T22:00:00Z

Content type: article

Language: en

Sources: [Doyensec](<https://devfeed.tech/sources/doyensec.md>)

Topics: [Randomizer](<https://devfeed.tech/topics/randomizer.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [attack](<https://devfeed.tech/tags/attack.md>), [auditing](<https://devfeed.tech/tags/auditing.md>), [automation](<https://devfeed.tech/tags/automation.md>), [code](<https://devfeed.tech/tags/code.md>), [doyensec](<https://devfeed.tech/tags/doyensec.md>), [doyensecurity](<https://devfeed.tech/tags/doyensecurity.md>), [exploit](<https://devfeed.tech/tags/exploit.md>), [hacking](<https://devfeed.tech/tags/hacking.md>), [infosec](<https://devfeed.tech/tags/infosec.md>), [internals](<https://devfeed.tech/tags/internals.md>), [iteration](<https://devfeed.tech/tags/iteration.md>), [languages](<https://devfeed.tech/tags/languages.md>), [offensive](<https://devfeed.tech/tags/offensive.md>), [pentest](<https://devfeed.tech/tags/pentest.md>), [pentester](<https://devfeed.tech/tags/pentester.md>), [random](<https://devfeed.tech/tags/random.md>), [reseed](<https://devfeed.tech/tags/reseed.md>), [reverse-engineering](<https://devfeed.tech/tags/reverse-engineering.md>), [rnd](<https://devfeed.tech/tags/rnd.md>), [secret](<https://devfeed.tech/tags/secret.md>), [security](<https://devfeed.tech/tags/security.md>), [test](<https://devfeed.tech/tags/test.md>), [timer](<https://devfeed.tech/tags/timer.md>), [token](<https://devfeed.tech/tags/token.md>), [vulnerability](<https://devfeed.tech/tags/vulnerability.md>)

## AI overview

The excerpt shows that VBScript's `Randomize` and `Rnd` make predictable secret tokens: implicit seeding uses local time down to milliseconds, then narrows the value to `Single`; the clock's roughly 15.625 ms ticks and float precision leave at most 65,536 effective seedings, recurring daily. Although calling `Randomize` inside the token loop does not by itself repeat the state when the same seed is reused, the sequence remains deterministic. The author distinguishes bare `Randomize` from `Randomize Timer()`: the former derives a seed from `GetLocalTime` and converts it differently from an explicitly supplied seed, so passing a captured `Timer()` value directly does not reproduce the state. A Python script models the required seed conversion and tries candidate times in 1/64-second steps, filtering duplicate tokens. With a suspected one-second window based on file creation time, the example recovered the token on its fourth candidate. The excerpt's PoC assumes the same seed across loop iterations and notes that variation could be handled with additional work.

## Source excerpt

In one of our recent posts, Dennis shared an interesting case study of C# exploitation that rode on Random-based password-reset tokens. He demonstrated how to use the single-packet attack, or a bit of old-school math, to beat the game. Recently, I performed a security test on a target which had a dependency written in VBScript. This blog post focuses on VBS's Rnd and shows that the situation there is even worse. Target Application The application was responsible for generating a secret token. The token was supposed to be unpredictable and expected to remain secret. Here's a rough copy of the token generation code: Dim chars, n chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()*&^%$#@!" n = 32 function GenerateToken(chars, n) Dim result, pos, i, charsLength charsLength = Int(Len(chars)) For i = 1 To n Randomize pos = Int((Rnd * charsLength) + 1) result = result & Mid(chars, pos, 1) Next GenerateToken = result end function The first thing I noticed was that the Randomize function was called inside a loop. That should reseed the PRNG on every single iteration, right? That could result in repeated values. Well, contrary to many other programming languages, in VBScript, the Randomize usage within a loop is not a problem per se. The function will not reset the initial state if the same seed is passed again (even if implicitly). This prevents generating identical sequences of characters within a single GenerateToken call. If you actually want that behavior, call Rnd with a negative argument immediately before calling Randomize with a numeric argument. But if that isn't an issue, then what is? How VBS's Randomize Works in Practice Here's a short API breakdown: Randomize ' seed the global PRNG using the system clock Randomize s ' seed the global PRNG using a specified seed value r = Rnd() ' next float in [0,1) If no seed is explicitly specified, Randomize uses Timer to set it (not entirely true, but we will get there). Timer() returns seconds since mid