Skip to content

Commit 5a94aac

Browse files
fix: replace HTMLParser template rendering with regex substitution
HTMLParser treats <TITLE> and other raw text elements as opaque — child tags like <condata> inside <TITLE> are passed to handle_data() as raw text rather than being parsed as tags. This caused template variables to leak into HTTP responses verbatim, allowing trivial honeypot fingerprinting. Replace substitute_template_fields() with a regex-based approach that scans the full payload for <condata source='...' key='...' /> patterns regardless of surrounding HTML context. Before: <TITLE>Overview - <condata source="databus" key="SystemDescription" /></TITLE> After: <TITLE>Overview - Siemens, SIMATIC, S7-200</TITLE> Fixes #1
1 parent 263f145 commit 5a94aac

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

conpot/protocols/http/command_responder.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import time
2020
import random
2121
import os
22+
import re
2223

2324
from datetime import datetime
2425

@@ -177,14 +178,26 @@ def send_response(self, code, message=None):
177178
# - self.send_header('Date', self.date_time_string())
178179

179180
def substitute_template_fields(self, payload):
180-
# initialize parser with our payload
181-
parser = TemplateParser(payload)
182-
183-
# triggers the parser, just in case of open / incomplete tags..
184-
parser.close()
185-
186-
# retrieve and return (substituted) payload
187-
return parser.payload
181+
if type(payload) == bytes:
182+
payload = payload.decode()
183+
databus = conpot_core.get_databus()
184+
pattern = r'<condata\s+source="([^"]+)"\s+key="([^"]+)"\s*/>'
185+
186+
def replacer(match):
187+
source = match.group(1)
188+
key = match.group(2)
189+
if source == "databus":
190+
result = databus.get_value(key)
191+
return str(result) if result is not None else match.group(0)
192+
elif source == "eval":
193+
try:
194+
return str(eval(key))
195+
except Exception as e:
196+
logger.exception(e)
197+
return match.group(0)
198+
return match.group(0)
199+
200+
return re.sub(pattern, replacer, payload)
188201

189202
def load_status(
190203
self,

0 commit comments

Comments
 (0)