From aa82f08e5583f7fc0e1dad6fb2e403392a8f35fc Mon Sep 17 00:00:00 2001 From: kigland Date: Tue, 10 Mar 2026 01:10:41 +0800 Subject: [PATCH] feat: add LLM-generated content mode for honeypot pages When topic and api_key are provided, uses GPT-4 to generate a realistic, SEO-optimized technical article with proper structure, meta tags, and Schema.org markup. Falls back to the original hardcoded template when no topic is specified. Each invocation produces unique content, making signature-based detection impractical. --- attacks/method3_honeypot.py | 157 ++++++++++++++++++++++++++---------- 1 file changed, 114 insertions(+), 43 deletions(-) diff --git a/attacks/method3_honeypot.py b/attacks/method3_honeypot.py index 4ab58ac..191fbf5 100644 --- a/attacks/method3_honeypot.py +++ b/attacks/method3_honeypot.py @@ -1,79 +1,150 @@ +import json import os -def generate_nginx_honeypot(payload_text: str, output_path: str = "./honeypot/"): +from openai import OpenAI + + +def _generate_article_content(client: OpenAI, topic: str) -> dict: + response = client.chat.completions.create( + model="gpt-4-turbo", + messages=[ + { + "role": "system", + "content": ( + "You are a professional technical blog writer. " + "Write high-quality, SEO-optimized articles that read like real blog posts " + "published on Medium or Dev.to. Output valid JSON only." + ), + }, + { + "role": "user", + "content": f"""Write a complete technical blog article about: {topic} + +Return a JSON object with these exact keys: +- "title": article title (50-70 chars, include year 2026) +- "meta_description": SEO meta description (150-160 chars) +- "meta_keywords": comma-separated keywords (8-12 keywords) +- "og_description": Open Graph description (one punchy sentence) +- "author_name": a realistic pen name or organization +- "sections": array of objects, each with "heading" and "content" (3-5 sections, each content 150-300 words) + +Make the content genuinely informative and technically accurate. +Do NOT include any placeholder text or Lorem ipsum.""", + }, + ], + response_format={"type": "json_object"}, + temperature=0.8, + max_tokens=3000, + ) + + return json.loads(response.choices[0].message.content) + + +def _build_sections_html(sections: list[dict]) -> str: + parts = [] + for i, section in enumerate(sections, 1): + heading = section.get("heading", f"Section {i}") + content = section.get("content", "") + paragraphs = content.split("\n\n") if "\n\n" in content else [content] + p_tags = "\n ".join(f"

{p.strip()}

" for p in paragraphs if p.strip()) + parts.append(f"""

{i}. {heading}

+ {p_tags}""") + return "\n\n".join(parts) + + +def generate_nginx_honeypot( + payload_text: str, + output_path: str = "./honeypot/", + topic: str | None = None, + api_key: str | None = None, +): os.makedirs(output_path, exist_ok=True) - + + if topic and api_key: + client = OpenAI(api_key=api_key) + article = _generate_article_content(client, topic) + title = article.get("title", f"Guide to {topic}") + meta_desc = article.get("meta_description", "") + meta_keywords = article.get("meta_keywords", "") + og_desc = article.get("og_description", "") + author = article.get("author_name", "Tech Insights") + sections_html = _build_sections_html(article.get("sections", [])) + else: + title = "Ultimate Guide to Python Performance Optimization (2026)" + meta_desc = "Learn advanced Python optimization techniques, memory management, and speed improvements." + meta_keywords = "Python optimization, Python performance, Cython, asyncio, memory management" + og_desc = "Discover the secrets to making your Python code run up to 10x faster." + author = "Python Performance Lab" + sections_html = """

1. Understanding the Global Interpreter Lock (GIL)

+

The Global Interpreter Lock is a mutex that protects access to Python objects, preventing multiple threads from executing Python bytecodes at once...

+ +

2. Memory Management and Profiling

+

Efficient memory management is crucial for high-performance Python applications. Tools like tracemalloc and objgraph are essential...

""" + + slug = title.lower().replace(" ", "-").replace("(", "").replace(")", "")[:60] + html_content = f""" - Ultimate Guide to Python Performance Optimization (2026) - - - - - + {title} + + + + + - - - - + + + + - +
-

Ultimate Guide to Python Performance Optimization

- +

{title}

+

By {author}

+
-

Welcome to the definitive guide on scaling and optimizing Python applications. In this article, we cover GIL bypassing, memory profiling, and C-extensions.

- -

1. Understanding the Global Interpreter Lock (GIL)

-

The Global Interpreter Lock is a mutex that protects access to Python objects, preventing multiple threads from executing Python bytecodes at once...

- -

2. Memory Management and Profiling

-

Efficient memory management is crucial for high-performance Python applications. Tools like tracemalloc and objgraph are essential...

+{sections_html}
- - + +
""" - - with open(os.path.join(output_path, "index.html"), "w", encoding="utf-8") as f: + + filepath = os.path.join(output_path, "index.html") + with open(filepath, "w", encoding="utf-8") as f: f.write(html_content) - print(f"[*] SEO-Optimized Honeypot generated at {output_path}index.html") + + mode = "LLM-generated" if (topic and api_key) else "template" + print(f"[*] Honeypot ({mode}) generated at {filepath}") + print(f"[*] Title: {title}")