You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a discrepancy in the formatting of SMB version detection in Nmap's SMB-related scripts. Notably, there is an inconsistency in the use of colons (:) and periods (.) in version formatting.
Observations
Nmap Version 7.94
docker run --rm -it instrumentisto/nmap:7.94 -Pn -T4 -p445 --script smb-protocols $SMB_SERVER_IP
[...]
PORT STATE SERVICE
445/tcp open microsoft-ds
Host script results:
| smb-protocols:
| dialects:
| 2:0:2
| 2:1:0
| 3:0:0
| 3:0:2
|_ 3:1:1
Nmap done: 1 IP address (1 host up) scanned in 6.18 seconds
Potential issue in stdnse.tohex function, potentially related to regex changes in a specific commit.
I believe the line:
hex, subs=gsub(hex, pat, "%1:%2")
Should be something like:
hex, subs=gsub(hex, pat, "%1" ..separator.."%2")
Test Script
localstdnse=require"stdnse"-- Most of the code here is taken from smb2.lualocalsmb2_dialects= {0x0202, 0x0210, 0x0300, 0x0302, 0x0311}
localsmb2_dialect_names= {}
for_, dinipairs(smb2_dialects) do-- convert 0x0abc to "a.b.c"localname=stdnse.tohex(d, {separator=".", group=1})
-- trim trailing ".0" at sub-minor levelsmb2_dialect_names[d] =name:find(".0", 4, true) andname:sub(1, 3) ornameendhostrule=function(host)
returntrueendaction=function(host,port)
stdnse.debug1(smb2_dialect_names[0x0311])
end
yammesicka
changed the title
Bug: SMB Dialects are broken due to a bug in stdnse.tohex
Bug: SMB dialect names are broken due to a bug in stdnse.tohex
Nov 15, 2023
yammesicka
changed the title
Bug: SMB dialect names are broken due to a bug in stdnse.tohex
Bug: SMB dialect versions are broken due to a bug in stdnse.tohex
Nov 15, 2023
- Since nmap version 7.93 the versions of SMB servers are returned in wrong format.
- This commit fixes the root cause by changing `tohex` function.
- `stdnse.tohex` is called from smb2 scripts to generate the name of the version.
- See GH issue nmap#2744 for further details.
Bug Description
There is a discrepancy in the formatting of SMB version detection in Nmap's SMB-related scripts. Notably, there is an inconsistency in the use of colons (:) and periods (.) in version formatting.
Observations
Nmap Version 7.94
Detected SMB dialects: 2:0:2, 2:1:0, 3:0:0, 3:0:2, 3:1:1
Nmap Version 7.93
Detected SMB dialects: 202, 210, 300, 302, 311
Nmap Version 7.92
Detected SMB dialects: 2.0.2, 2.1, 3.0, 3.0.2, 3.1.1
Steps to Reproduce
Analysis
Potential issue in
stdnse.tohex
function, potentially related to regex changes in a specific commit.I believe the line:
Should be something like:
Test Script
Execution
Results
Expected Behavior
Based on Nmap's changelog, the SMB version format should be consistent with version 7.92's output, i.e.,
3.1.1
.Environment
Impact
This issue potentially affects multiple SMB version-dependent scripts, such as Example 1 and Example 2 analysis scripts.
The text was updated successfully, but these errors were encountered: