Repository navigation
Description
This error is output using nmap --script s7-info.nse -p 102 192.168.1.222 -Pn -d
The error prompted is:
From 2020-09-09 10:39 CST Nmap 7.80 (https://nmap.org)
Timing report
Host group: at least 1, and at most 100,000
rtt timeout: init 1000, minimum value 100, maximum value 10000
Maximum scan delay: TCP 1000, UDP 1000, SCTP 1000
Parallelism: minimum value 0, maximum value 0
Maximum number of retries: 10, host timeout: 0
Minimum rate: 0, Maximum rate: 0
NSE: Use Lua 5.3.
NSE: Parameters from CLI:
NSE: 1 script has been loaded for scanning.
NSE: Script pre-scan.
NSE: Start scan of run level 1 (1 in total).
Start NSE at 10:39
NSE was completed at 10:39, 0.00s has passed
mass_rdns: Use DNS server 127.0.0.53
Starting parallel DNS resolution for 1 host. At 10:39
mass_rdns: 0.00s 0/1 [#: 1, OK:0, NX:0, DR:0, SF:0, TR:1]
The parallel DNS resolution of 1 host has been completed. At 10:39, 0.00s has passed
The DNS resolution of 1 IP takes 0.00s. Mode: Asynchronous [#:1, OK:0, NX:1, DR:0, SF:0, TR:1, CN:0]
Start connection scan at 10:39
Scan 192.168.1.222 [1 port]
Found open port 102/tcp on 192.168.1.222
10:39 complete the connection scan, after 0.00 seconds (total 1 port)
Total sending rate: 762.20 packets/sec.
NSE: The script scans 192.168.1.222.
NSE: Start scan of run level 1 (1 in total).
Start NSE at 10:39
NSE: Start s7-info for 192.168.1.222:102.
NSE: [s7-info 192.168.1.222:102] S7INFO:: Create a new socket
NSE: s7-info for 192.168.1.222:102 caused an error!
/usr/bin/../share/nmap/scripts/s7-info.nse:132: Wrong parameter #3 to'unpack' (initial position of the string)
Stack backtrace:
[C]: In the function'string.unpack'
/usr/bin/../share/nmap/scripts/s7-info.nse:132: in the value-added'second_parse_response'
/usr/bin/../share/nmap/scripts/s7-info.nse:249: in function</usr/bin/../share/nmap/scripts/s7-info.nse:179>
(...end...)
NSE was completed at 10:39, after 0.02s
Nmap scan report of 192.168.1.222
The host starts and receives user settings (0.0012s delay).
Scan 0 seconds at 2020-09-09 10:39:53 CST
Port State Service Reasons
102/tcp open iso-tsap synchronization
The final time of the host: srtt: 1219 rttvar: 5000 to: 100000
NSE: Scan after script.
NSE: Start scan of run level 1 (1 in total).
Start NSE at 10:39
NSE was completed at 10:39, 0.00s has passed
Read from /usr/bin/../share/nmap: nmap-payloads nmap-services.
Completed Nmap: Scanned 1 IP address in 0.23 seconds (1 host has been started)
The corresponding port 102 is opened and can be scanned with plcscan, but it cannot be scanned with the script S7-info.nse that comes with nmap. The command used at this time is: nmap --script s7-info.nse -p 102 192.168.1.222). Then I used the nmap --script s7-info.nse -p 102 192.168.1.222 -Pn -d command as prompted
Activity
dmiller-nmap commentedon Sep 9, 2020
Thanks for this report. I've just pushed a change to avoid a crash in the script, but it won't improve parsing of the response. Can you re-run the command with the
--script-traceoption to show the packet data that caused the problem? Maybe we can extend the script to support this device.Handle too-short response in s7-info. See #2117
cldrn commentedon Sep 9, 2020
@kermit7410 Would you also test it with older stable versions of Nmap? The issue seems similar to what we have been seeing in other scripts. It seems responses are too short due to packet fragmentation. I believe something changed and it might be breaking scripts that expect packets to be at least of certain length
kermit7410 commentedon Sep 10, 2020
NSE: Using Lua 5.3.
NSE: Arguments from CLI:
NSE: Loaded 1 scripts for scanning.
NSE: Script Pre-scanning.
NSE: Starting runlevel 1 (of 1) scan.
Initiating NSE at 18:27
Completed NSE at 18:27, 0.00s elapsed
mass_rdns: Using DNS server 127.0.0.53
Initiating Parallel DNS resolution of 1 host. at 18:27
mass_rdns: 0.00s 0/1 [#: 1, OK: 0, NX: 0, DR: 0, SF: 0, TR: 1]
Completed Parallel DNS resolution of 1 host. at 18:27, 0.00s elapsed
DNS resolution of 1 IPs took 0.00s. Mode: Async [#: 1, OK: 0, NX: 1, DR: 0, SF: 0, TR: 1, CN: 0]
Initiating Connect Scan at 18:27
Scanning 192.168.1.222 [1 port]
Discovered open port 102/tcp on 192.168.1.222
Completed Connect Scan at 18:27, 0.00s elapsed (1 total ports)
Overall sending rates: 630.52 packets / s.
NSE: Script scanning 192.168.1.222.
NSE: Starting runlevel 1 (of 1) scan.
Initiating NSE at 18:27
NSE: Starting s7-info against 192.168.1.222:102.
NSOCK INFO [0.2140s] nsock_trace_handler_callback(): Callback: CONNECT SUCCESS for EID 8 [192.168.1.222:102]
NSE: TCP 192.168.1.189:34624 > 192.168.1.222:102 | CONNECT
NSE: TCP 192.168.1.189:34624 > 192.168.1.222:102 | 00000000: 03 00 00 16 11 e0 00 00 00 14 00 c1 02 01 00 c2
00000010: 02 01 02 c0 01 0a
NSOCK INFO [0.2140s] nsock_write(): Write request for 22 bytes to IOD #1 EID 19 [192.168.1.222:102]
NSOCK INFO [0.2140s] nsock_trace_handler_callback(): Callback: WRITE SUCCESS for EID 19 [192.168.1.222:102]
NSE: TCP 192.168.1.189:34624 > 192.168.1.222:102 | SEND
NSOCK INFO [0.2140s] nsock_read(): Read request from IOD #1 [192.168.1.222:102] (timeout: 30000ms) EID 26
NSOCK INFO [0.2150s] nsock_trace_handler_callback(): Callback: READ EOF for EID 26 [192.168.1.222:102]
NSE: TCP 192.168.1.189:34624 > 192.168.1.222:102 | CLOSE
NSOCK INFO [0.2150s] nsock_iod_delete(): nsock_iod_delete (IOD #1)
NSE: [s7-info 192.168.1.222:102] S7INFO:: CREATING NEW SOCKET
NSOCK INFO [0.2150s] nsock_iod_new2(): nsock_iod_new (IOD #2)
NSOCK INFO [0.2150s] nsock_connect_tcp(): TCP connection requested to 192.168.1.222:102 (IOD #2) EID 32
NSOCK INFO [0.2160s] nsock_trace_handler_callback(): Callback: CONNECT SUCCESS for EID 32 [192.168.1.222:102]
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | CONNECT
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | 00000000: 03 00 00 16 11 e0 00 00 00 05 00 c1 02 01 00 c2
00000010: 02 02 00 c0 01 0a
NSOCK INFO [0.2160s] nsock_write(): Write request for 22 bytes to IOD #2 EID 43 [192.168.1.222:102]
NSOCK INFO [0.2160s] nsock_trace_handler_callback(): Callback: WRITE SUCCESS for EID 43 [192.168.1.222:102]
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | SEND
NSOCK INFO [0.2160s] nsock_read(): Read request from IOD #2 [192.168.1.222:102] (timeout: 30000ms) EID 50
NSOCK INFO [0.2180s] nsock_trace_handler_callback(): Callback: READ SUCCESS for EID 50 [192.168.1.222:102] (22 bytes): ......................
NSE: TCP 192.168.1.189:34626 < 192.168.1.222:102 | 00000000: 03 00 00 16 11 d0 00 05 00 08 00 c0 01 0a c1 02
00000010: 01 00 c2 02 02 00
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | 00000000: 03 00 00 19 02 f0 80 32 01 00 00 00 00 00 08 00 2
00000010: 00 f0 00 00 01 00 01 01 e0
NSOCK INFO [0.2180s] nsock_write(): Write request for 25 bytes to IOD #2 EID 59 [192.168.1.222:102]
NSOCK INFO [0.2180s] nsock_trace_handler_callback(): Callback: WRITE SUCCESS for EID 59 [192.168.1.222:102]
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | SEND
NSOCK INFO [0.2180s] nsock_read(): Read request from IOD #2 [192.168.1.222:102] (timeout: 30000ms) EID 66
NSOCK INFO [0.2190s] nsock_trace_handler_callback(): Callback: READ SUCCESS for EID 66 [192.168.1.222:102] (27 bytes): .......2...................
NSE: TCP 192.168.1.189:34626 < 192.168.1.222:102 | 00000000: 03 00 00 1b 02 f0 80 32 03 00 00 00 00 00 08 00 2
00000010: 00 00 00 f0 00 00 01 00 01 00 f0
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | 00000000: 03 00 00 21 02 f0 80 32 07 00 00 00 00 00 08 00 ! 2
00000010: 08 00 01 12 04 11 44 01 00 ff 09 00 04 00 11 00 D
00000020: 01
NSOCK INFO [0.2190s] nsock_write(): Write request for 33 bytes to IOD #2 EID 75 [192.168.1.222:102]
NSOCK INFO [0.2190s] nsock_trace_handler_callback(): Callback: WRITE SUCCESS for EID 75 [192.168.1.222:102]
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | SEND
NSOCK INFO [0.2190s] nsock_read(): Read request from IOD #2 [192.168.1.222:102] (timeout: 30000ms) EID 82
NSOCK INFO [0.2290s] nsock_trace_handler_callback(): Callback: READ SUCCESS for EID 82 [192.168.1.222:102] (125 bytes)
NSE: TCP 192.168.1.189:34626 < 192.168.1.222:102 | 00000000: 03 00 00 7d 02 f0 80 32 07 00 00 00 00 00 0c 00 } 2
00000010: 60 00 01 12 08 12 84 01 01 00 00 00 00 ff 09 00 `
00000020: 5c 00 11 00 01 00 1c 00 03 00 01 36 45 53 37 20 \ 6ES7
00000030: 32 31 34 2d 31 41 47 33 31 2d 30 58 42 30 20 20 214-1AG31-0XB0
00000040: 20 00 01 20 20 00 06 36 45 53 37 20 32 31 34 2d 6ES7 214-
00000050: 31 41 47 33 31 2d 30 58 42 30 20 20 20 00 01 20 1AG31-0XB0
00000060: 20 00 07 36 45 53 37 20 32 31 34 2d 31 41 47 33 6ES7 214-1AG3
00000070: 31 2d 30 58 42 30 20 20 20 56 03 00 02 1-0XB0 V
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | 00000000: 03 00 00 21 02 f0 80 32 07 00 00 00 00 00 08 00 ! 2
00000010: 08 00 01 12 04 11 44 01 00 ff 09 00 04 00 11 00 D
00000020: 01
NSOCK INFO [0.2290s] nsock_write(): Write request for 33 bytes to IOD #2 EID 91 [192.168.1.222:102]
NSOCK INFO [0.2290s] nsock_trace_handler_callback(): Callback: WRITE SUCCESS for EID 91 [192.168.1.222:102]
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | SEND
NSOCK INFO [0.2290s] nsock_read(): Read request from IOD #2 [192.168.1.222:102] (timeout: 30000ms) EID 98
NSOCK INFO [0.2310s] nsock_trace_handler_callback(): Callback: READ SUCCESS for EID 98 [192.168.1.222:102] (125 bytes)
NSE: TCP 192.168.1.189:34626 < 192.168.1.222:102 | 00000000: 03 00 00 7d 02 f0 80 32 07 00 00 00 00 00 0c 00 } 2
00000010: 60 00 01 12 08 12 84 01 01 00 00 00 00 ff 09 00 `
00000020: 5c 00 11 00 01 00 1c 00 03 00 01 36 45 53 37 20 \ 6ES7
00000030: 32 31 34 2d 31 41 47 33 31 2d 30 58 42 30 20 20 214-1AG31-0XB0
00000040: 20 00 01 20 20 00 06 36 45 53 37 20 32 31 34 2d 6ES7 214-
00000050: 31 41 47 33 31 2d 30 58 42 30 20 20 20 00 01 20 1AG31-0XB0
00000060: 20 00 07 36 45 53 37 20 32 31 34 2d 31 41 47 33 6ES7 214-1AG3
00000070: 31 2d 30 58 42 30 20 20 20 56 03 00 02 1-0XB0 V
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | 00000000: 03 00 00 21 02 f0 80 32 07 00 00 00 00 00 08 00 ! 2
00000010: 08 00 01 12 04 11 44 01 00 ff 09 00 04 00 1c 00 D
00000020: 01
NSOCK INFO [0.2310s] nsock_write(): Write request for 33 bytes to IOD #2 EID 107 [192.168.1.222:102]
NSOCK INFO [0.2310s] nsock_trace_handler_callback(): Callback: WRITE SUCCESS for EID 107 [192.168.1.222:102]
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | SEND
NSOCK INFO [0.2320s] nsock_read(): Read request from IOD #2 [192.168.1.222:102] (timeout: 30000ms) EID 114
NSOCK INFO [0.2330s] nsock_trace_handler_callback(): Callback: READ SUCCESS for EID 114 [192.168.1.222:102] (33 bytes): ...!...2.........................
NSE: TCP 192.168.1.189:34626 < 192.168.1.222:102 | 00000000: 03 00 00 21 02 f0 80 32 07 00 00 00 00 00 0c 00 ! 2
00000010: 04 00 01 12 08 12 84 01 01 00 00 d4 01 0a 00 00
00000020: 00
NSE: s7-info against 192.168.1.222:102 threw an error!
/usr/bin/../share/nmap/scripts/./s7-info.nse:132: bad argument #3 to 'unpack' (initial position out of string)
stack traceback:
[C]: in function 'string.unpack'
/usr/bin/../share/nmap/scripts/./s7-info.nse:132: in upvalue 'second_parse_response'
/usr/bin/../share/nmap/scripts/./s7-info.nse:249: in function </usr/bin/../share/nmap/scripts/./s7-info.nse:179>
(...tail calls...)
NSE: TCP 192.168.1.189:34626 > 192.168.1.222:102 | CLOSE
NSOCK INFO [0.2330s] nsock_iod_delete(): nsock_iod_delete (IOD #2)
Completed NSE at 18:27, 0.02s elapsed
Nmap scan report for 192.168.1.222
Host is up, received user-set (0.0015s latency).
Scanned at 2020-09-10 18:27:15 CST for 0s
PORT STATE SERVICE REASON
102/tcp open iso-tsap syn-ack
Final times for host: srtt: 1479 rttvar: 5000 to: 100000
NSE: Script Post-scanning.
NSE: Starting runlevel 1 (of 1) scan.
Initiating NSE at 18:27
Completed NSE at 18:27, 0.00s elapsed
Read from /usr/bin/../share/nmap: nmap-payloads nmap-services.
Nmap done: 1 IP address (1 host up) scanned in 0.24 seconds
kermit7410 commentedon Sep 10, 2020
No,i don't have one older version to test,and i use a script named s7-enumerate.nse testing successfully.
Try to make sure enough data is present before parsing. See #2117
stef (#1)
dmiller-nmap commentedon Sep 23, 2022
I'm closing this issue on the assumption that 3b633fd resolved it. If you have further issues with the s7-info script, please open a new issue.