quick update

This commit is contained in:
niamtokik
2024-05-31 13:58:45 +00:00
parent d2117e0809
commit 02b1bca329
4 changed files with 1784 additions and 94 deletions

View File

@@ -153,6 +153,7 @@
-- @TODO add default values found in testing
--
----------------------------------------------------------------------
require "strict"
local nmap = require "nmap"
local http = require "http"
local json = require "json"
@@ -356,7 +357,7 @@ local api = {
"chunk",
{
arg_name = "offset",
default = "",
default = ":offset",
fuzzer = {
t = "number"
}
@@ -379,7 +380,7 @@ local api = {
"chunk_proof",
{
arg_name = "offset",
default = "",
default = ":offset",
fuzzer = {
t = "number"
}
@@ -402,7 +403,7 @@ local api = {
"chunk2",
{
arg_name = "offset",
default = "",
default = ":offset",
fuzzer = {
t = "number"
}
@@ -419,12 +420,13 @@ local api = {
--------------------------------------------------------------------
get_chunk_proof2_offset = {
comment = "",
method = "get",
mode = { "fuzzing", "inject" },
path = {
"chunk_proof2",
{
arg_name = "offset",
default = "",
default = ":offset",
fuzzer = {
t = "number"
}
@@ -657,7 +659,7 @@ local api = {
"price",
{
arg_name = "size",
default = "",
default = ":size",
fuzzer = {
t = "number"
}
@@ -692,7 +694,7 @@ local api = {
"wallet",
{
arg_name = "address",
default = "",
default = ":address",
fuzzer = {
t = "transaction"
}
@@ -711,7 +713,7 @@ local api = {
"wallet",
{
arg_name = "address",
default = "",
default = ":address",
fuzzer = {
t = "transaction"
}
@@ -772,7 +774,7 @@ local api = {
"tx",
{
arg_name = "tx_id",
default = "",
default = ":tx_id",
fuzzer = {
t = "transaction"
}
@@ -790,7 +792,7 @@ local api = {
"tx",
{
arg_name = "tx_id",
default = "",
default = ":tx_id",
fuzzer = {
t = "number",
size = 32,
@@ -832,7 +834,7 @@ local api = {
"chunk",
{
arg_name = "offset",
default = "1234",
default = ":offset",
fuzzer = {
t = "number"
}
@@ -1087,14 +1089,14 @@ local api = {
"block_index",
{
arg_name = "from",
default = "",
default = ":from",
fuzzer = {
-- to be defined
}
},
{
arg_name = "to",
default = "",
default = ":to",
fuzzer = {
-- to be defined
}
@@ -1113,14 +1115,14 @@ local api = {
"block_index2",
{
arg_name = "from",
default = "",
default = ":from",
fuzzer = {
-- to be defined
}
},
{
arg_name = "to",
default = "",
default = ":to",
fuzzer = {
-- to be defined
}
@@ -1148,14 +1150,14 @@ local api = {
"data_sync_record",
{
arg_name = "start",
default = "",
default = ":start",
fuzzer = {
-- to be defined
}
},
{
arg_name = "limit",
default = "",
default = ":limit",
fuzzer = {
-- to be defined
}
@@ -1192,14 +1194,14 @@ local api = {
"hash_list",
{
arg_name = "from",
default = "",
default = ":from",
fuzzer = {
-- to be defined
}
},
{
arg_name = "to",
default = "",
default = ":to",
fuzzer = {
-- to be defined
}
@@ -1218,12 +1220,12 @@ local api = {
"hash_list2",
{
arg_name = "from",
default = "",
default = ":from",
fuzzer = {}
},
{
arg_name = "to",
default = "",
default = ":to",
fuzzer = {}
}
}
@@ -1239,7 +1241,7 @@ local api = {
"jobs",
{
arg_name = "prev_output",
default = "",
default = ":prev_output",
fuzzer = {}
}
}
@@ -1255,7 +1257,7 @@ local api = {
"wallet_list",
{
arg_name = "hash",
default = "",
default = ":hash",
fuzzer = {}
}
}
@@ -1272,12 +1274,12 @@ local api = {
"wallet_list",
{
arg_name = "hash",
default = "",
default = ":hash",
fuzzer = {}
},
{
arg_name = "cursor",
default = "",
default = ":cursor",
fuzzer = {}
}
}
@@ -1294,12 +1296,12 @@ local api = {
"wallet_list",
{
arg_name = "hash",
default = "",
default = ":hash",
fuzzer = {}
},
{
arg_name = "address",
default = "",
default = ":address",
fuzzer = {}
},
"balance"
@@ -1316,7 +1318,7 @@ local api = {
"wallet",
{
arg_name = "address",
default = "",
default = ":address",
fuzzer = {}
},
"balance"
@@ -1333,7 +1335,7 @@ local api = {
"wallet",
{
arg_name = "address",
default = "",
default = ":address",
fuzzer = {}
},
"reserved_rewards_total"
@@ -1350,7 +1352,7 @@ local api = {
"wallet",
{
arg_name = "address",
default = "",
default = ":address",
fuzzer = {}
},
"last_tx"
@@ -1367,7 +1369,7 @@ local api = {
"inflation",
{
arg_name = "height",
default = "",
default = ":height",
fuzzer = {}
}
}
@@ -1383,7 +1385,7 @@ local api = {
"optimistic_price",
{
arg_name = "size",
default = "",
default = ":size",
fuzzer = {}
}
}
@@ -1400,12 +1402,12 @@ local api = {
"optimistic_price",
{
arg_name = "size",
default = "",
default = ":size",
fuzzer = {}
},
{
arg_name = "address",
default = "",
default = ":address",
fuzzer = {}
}
}
@@ -1422,12 +1424,12 @@ local api = {
"v2price",
{
arg_name = "size",
default = "",
default = ":size",
fuzzer = {}
},
{
arg_name = "address",
default = "",
default = ":address",
fuzzer = {}
}
}
@@ -1443,7 +1445,7 @@ local api = {
"reward_history",
{
arg_name = "bh",
default = "",
default = ":bh",
fuzzer = {}
}
}
@@ -1459,7 +1461,7 @@ local api = {
"block_time_history",
{
arg_name = "bh",
default = "",
default = ":bh",
fuzzer = {}
}
}
@@ -1476,12 +1478,12 @@ local api = {
"block",
{
arg_name = "type",
default = "",
default = ":type",
fuzzer = {}
},
{
arg_name = "id",
default = "",
default = ":id",
fuzzer = {}
}
}
@@ -1499,17 +1501,17 @@ local api = {
"block",
{
arg_name = "type",
default = "",
default = ":type",
fuzzer = {}
},
{
arg_name = "id",
default = "",
default = ":id",
fuzzer = {}
},
{
arg_name = "field",
default = "",
default = ":field",
fuzzer = {}
}
}
@@ -1526,12 +1528,12 @@ local api = {
"block2",
{
arg_name = "type",
default = "",
default = ":type",
fuzzer = {}
},
{
arg_name = "id",
default = "",
default = ":id",
fuzzer = {}
}
}
@@ -1549,13 +1551,13 @@ local api = {
"height",
{
arg_name = "height",
default = "",
default = ":height",
fuzzer = {}
},
"wallet",
{
arg_name = "address",
default = "",
default = ":address",
fuzzer = {}
},
"balance"
@@ -1573,12 +1575,12 @@ local api = {
"tx",
{
arg_name = "hash",
default = "",
default = ":hash",
fuzzer = {}
},
{
arg_name = "field",
default = "",
default = ":field",
fuzzer = {}
}
},
@@ -1599,17 +1601,17 @@ local api = {
"balance",
{
arg_name = "address",
default = "",
default = ":address",
fuzzer = {}
},
{
arg_name = "network",
default = "",
default = ":network",
fuzzer = {}
},
{
arg_name = "token",
default = "",
default = ":token",
fuzzer = {}
}
}
@@ -1625,7 +1627,7 @@ local api = {
"is_tx_blacklisted",
{
arg_name = "tx_id",
default = "",
default = ":tx_id",
fuzzer = {}
}
}
@@ -1641,7 +1643,7 @@ local api = {
"price",
{
arg_name = "size",
default = "",
default = ":size",
fuzzer = {}
}
}
@@ -1658,12 +1660,12 @@ local api = {
"price",
{
arg_name = "size",
default = "",
default = ":size",
fuzzer = {}
},
{
arg_name = "address",
default = "",
default = ":address",
fuzzer = {}
}
}
@@ -1680,12 +1682,12 @@ local api = {
"price2",
{
arg_name = "size",
default = "",
default = ":size",
fuzzer = {}
},
{
arg_name = "address",
default = "",
default = "address",
fuzzer = {}
}
}
@@ -1711,7 +1713,7 @@ local api = {
"unconfirmed_tx",
{
arg_name = "hash",
default = "",
default = ":hash",
fuzzer = {}
}
}
@@ -1727,7 +1729,7 @@ local api = {
"unconfirmed_tx2",
{
arg_name = "hash",
default = "",
default = ":hash",
fuzzer = {}
}
}
@@ -1755,25 +1757,25 @@ local api = {
},
-- wip: arweave.options_block.fuzzing = true | false
-- options_block = {
-- mode = "full",
-- method = "option",
-- path = { "block" }
-- },
options_block = {
mode = {},
method = "options",
path = { "block" }
},
-- wip: arweave.options_peers.fuzzing = true | false
-- options_peer = {
-- mode = "full",
-- method = "option",
-- path = { "peer" }
-- },
options_peer = {
mode = {},
method = "options",
path = { "peer" }
},
-- wip: arweave.options_tx.fuzzing = true | false
-- options_tx = {
-- mode = "full",
-- method = "tx",
-- path = { "tx" }
-- }
options_tx = {
mode = {},
method = "options",
path = { "tx" }
},
}
----------------------------------------------------------------------
@@ -1843,6 +1845,19 @@ local fuzzer_number = function(params)
return nil
end
----------------------------------------------------------------------
-- create arweave argument path
-- create_arg_path("id", "name") => arweave.id.name
--
-- @param path_id a key from api table
-- @param name a string
-- @return string
----------------------------------------------------------------------
local create_arg_path = function(path_id, name)
local arg_key = {"arweave", path_id, name}
return table.concat(arg_key, ".")
end
----------------------------------------------------------------------
-- convert a table made of string and table into a path.
--
@@ -1868,7 +1883,7 @@ local http_path = function(path_id)
-- try to find the default argument used, in the end it could
-- be a random value generated based on some specification.
local default_arg = api[path_id][name]["default"]
local default_arg = value["default"]
-- we create nmap argument path
local arg_path = create_arg_path(path_id, name)
@@ -1886,19 +1901,6 @@ local http_path = function(path_id)
return "/" .. table.concat(path, "/")
end
----------------------------------------------------------------------
-- create arweave argument path
-- create_arg_path("id", "name") => arweave.id.name
--
-- @param path_id a key from api table
-- @param name a string
-- @return string
----------------------------------------------------------------------
local create_arg_path = function(path_id, name)
local arg_key = {"arweave", path_id, name}
return table.concat(arg_key, ".")
end
----------------------------------------------------------------------
-- wrapper around http request for get.
--
@@ -2127,6 +2129,38 @@ portrule = shortport.port_or_service(1984, "arweave", "tcp", "open")
-- @return output or nil
----------------------------------------------------------------------
action = function(host, port)
-- get arweave.mode variable, set to "identify" by default
local mode = stdnse.get_script_args("arweave.mode") or "identify"
local scan_only = stdnse.get_script_args("arweave.scan_only") or nil
local scan_filter = stdnse.get_script_args("arweave.scan_filter") or nil
local options = stdnse.get_script_args("arweave.headers") or {}
-- a dirty way to list available endpoints
-- scan is dismissed and endpoints are printed
if mode == "endpoints" then
local endpoint
local output = stdnse.output_table()
local endpoints = {}
local counter = 0
for key, value in pairs(api) do
local method = value["method"]
local endpoint = http_path(key)
local curl = { "curl", "-X", method, "http://" .. host.targetname .. ":" .. tostring(port.number) .. endpoint }
counter = counter+1
endpoints[key] = {
method = method,
endpoint = endpoint,
curl = table.concat(curl, " ")
}
end
output = {
nendpoints = counter,
endpoints = endpoints
}
return output
end
-- check if the target is a gateway
local gateway = is_gateway(host, port)
if gateway then
local output = stdnse.output_table()
@@ -2143,14 +2177,9 @@ action = function(host, port)
}
nmap.set_port_version(host, port)
-- get arweave.scan variable, set to "default" by default
local mode = stdnse.get_script_args("arweave.mode") or "identify"
local scan_only = stdnse.get_script_args("arweave.scan_only") or nil
local scan_filter = stdnse.get_script_args("arweave.scan_filter") or nil
local options = stdnse.get_script_args("arweave.headers") or {}
-- peers mode, only used to return connected peers
if mode == "peers" then
stdnse.debug("peers mode enabled: list the peers available on remote server.")
result = http_request(host, port, "get_peers")
peers = result.body
table.sort(peers)
@@ -2168,6 +2197,7 @@ action = function(host, port)
-- scan only one path from api
if scan_only and api[scan_only] then
stdnse.debug("scan_only enabled: scan only a small subset of endpoints.")
result = http_request(host, port, scan_only, options)
output[scan_only] = result
return output
@@ -2175,6 +2205,7 @@ action = function(host, port)
-- scan path from api based on regexp
if scan_filter then
stdnse.debug("scan_filter enabled: scan only a small subset of endpoints.")
for key, value in pairs(api) do
if string.find(key, scan_filter) then
result = http_request(host, port, key)

1577
lib/arweave_api.lua Normal file

File diff suppressed because it is too large Load Diff

82
lib/rfc4648.lua Normal file
View File

@@ -0,0 +1,82 @@
#!/usr/bin/env lua53
----------------------------------------------------------------------
--
----------------------------------------------------------------------
local base64 = require "base64"
local base64_table = {
0 = "A",
1 = "B",
2 = "C",
3 = "D",
4 = "E",
5 = "F",
6 = "G",
7 = "H",
8 = "I",
9 = "J",
10 = "K",
11 = "L",
12 = "M",
13 = "N",
14 = "O",
15 = "P",
16 = "Q",
17 = "R",
18 = "S",
19 = "T",
20 = "U",
21 = "V",
22 = "W",
23 = "X",
24 = "Y",
25 = "Z",
26 = "a",
27 = "b",
28 = "c",
29 = "d",
30 = "e",
31 = "f",
32 = "g",
33 = "h",
34 = "i",
35 = "j",
36 = "k",
37 = "l",
38 = "m",
39 = "n",
40 = "o",
41 = "p",
42 = "q",
43 = "r",
44 = "s",
45 = "t",
46 = "u",
47 = "v",
48 = "w",
49 = "x",
50 = "y",
51 = "z",
52 = "0",
53 = "1",
54 = "2",
55 = "3",
56 = "4",
57 = "5",
58 = "6",
59 = "7",
60 = "8",
61 = "9",
62 = "-",
63 = "_",
}
local base64_pad = "="
dirty_base64_encode = function(data)
local output = base64.enc(data)
output = string.gsub(output, "/", "_")
output = string.gsub(output, "+", "-")
output = string.gsub(output, "=", "")
return output
end