1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-15 12:19:02 +00:00

Expose nbase's get_random_bytes as an alternative random source for NSE, via rand.random_string

This commit is contained in:
dmiller
2018-10-17 00:30:15 +00:00
parent 73715b15b5
commit 37384c2225
2 changed files with 32 additions and 7 deletions

View File

@@ -24,6 +24,13 @@ local concat = table.concat
local type = type
local _ENV = {}
local get_random_bytes
if have_openssl then
get_random_bytes = openssl.rand_pseudo_bytes
else
get_random_bytes = require "nmap".get_random_bytes
end
--- Generate a random string.
--
-- You can either provide your own charset or the function will generate random
@@ -46,13 +53,7 @@ random_string = function(len, charset)
end
end
else
if have_openssl then
return openssl.rand_pseudo_bytes(len)
else
for i=1,len do
t[i]=char(random(0 ,0xff))
end
end
return get_random_bytes(len)
end
return concat(t)
end