Generative AI
5. AI, Machine Learning, and LLMs Explained
How the concepts fit together
| Term | What it is |
|---|---|
| Artificial Intelligence | The broad goal: intelligent behavior. |
| Machine Learning | The method: learning from data. |
| Large Language Model | A specific type of ML model focused on language. |
AI is about observable behavior. Examples include understanding language, recognizing patterns, making decisions with incomplete information, and learning from experience.
ML learns relationships from examples. Training may involve large amounts of example data, desired outcomes, and feedback. The resulting predictions are probabilistic.
An LLM is trained on large amounts of text. The course compares it to an advanced autocomplete system that repeatedly answers:
Given everything so far, what should come next?
Why LLMs feel intelligent
- They use context across long inputs.
- They generate coherent, structured responses.
- They mimic reasoning patterns found in training data.
- Their output can sound confident even when incorrect.
- Generating a response does not independently verify its truth.
Why LLMs are useful for pentesters
LLMs are especially useful for reading and writing text, explaining unfamiliar concepts, translating between formats, summarizing large outputs, and generating boilerplate content.
boilerplate noun [U] (STANDARD)(在法律文件或者计算机程序中略微修改即可使用的)文件样板,文件范例
Examples in the slides include explaining exploit code, generating templates, drafting pretexts, converting scan output into findings, and drafting reports and remediation advice.
Common misconceptions
- “AI can hack automatically.” The course cautions against relying on autonomous zero-day discovery, reliable unguided attack execution, or replacement of human tradecraft.
- “LLMs understand what they say.” Their core mechanism is prediction.
- “More prompts = better hacking.” Poor prompts can generate hallucinated techniques, incorrect commands, and unsafe outputs.
tradecraft noun [ U ] (某项技术性工作的)技术方法
Mental model for pentesters
The instructor’s analogy:
A junior assistant with perfect memory, unlimited stamina, and no judgment.
Practical implications:
- Verify the output.
- Provide relevant context.
- Control scope and intent.
Key Takeaways
- AI is the broad concept of intelligent behavior
- Machine Learning is how systems learn from data
- LLMs are ML models specialized in language generation
- LLMs are powerful assistants, not autonomous attackers
- Understanding limitations is critical for safe and effective use
6. Generative AI Concepts
What makes generative AI “generative”?
Traditional discriminative systems answer questions such as:
- Is this malicious or benign?
- Which category does this belong to?
- Is this likely or unlikely?
Generative AI produces new sequences of output based on learned patterns. Outputs can include natural-language text, source code, tables, JSON, reports, explanations, and reasoning-like responses.
Token-based generation
A token is a unit of text. It may be a whole word, part of a word, a symbol, punctuation, or whitespace.
For example, nmap -sV -p 443 example.com is broken into multiple tokens. The model does not receive the command as a single unit.
- Long commands consume more tokens.
- Large scan outputs can exceed context limits.
- Small wording changes can change tokenization and output.
Next-token prediction
Given everything so far, what is the most likely next token?
The model repeatedly predicts the next token as it generates a response. This process does not independently check correctness, execute commands, or verify facts. A fluent answer can therefore be incorrect.
Probability and temperature
The model generates output from a probability distribution over possible next tokens. Running the same prompt twice can produce different answers in style, depth, or accuracy. Treat the result as a hypothesis, draft, or starting point.
| Lower temperature | Higher temperature |
|---|---|
| More predictable and repetitive | More varied and creative |
| Better suited to structured tasks | Useful for brainstorming and ideation |
| Suggested for summarization, classification, recon analysis, and reporting | Use cautiously because output can become unstable or speculative |
Context windows
The context window is the amount of text the model can consider at one time. It includes the prompt, available previous messages, system instructions, and the model’s generated text.
Information outside the window is unavailable to the model. Multi-step tasks can lose earlier context, and long engagements may require data to be split into smaller parts.
Hallucinations
A hallucination is an output unsupported by the input data or by reality.
| Why it can happen | Pentesting example |
|---|---|
| The model fills gaps to maintain fluency. | Invents a vulnerability absent from the scan output. |
| The model generates a plausible response despite missing information. | Suggests a nonexistent tool or command-line flag. |
| Similar patterns in training data influence the answer. | References the wrong CVE or produces a plausible-looking command that fails. |
Generation vs. retrieval
When a model answers from its learned patterns alone, it does not look up current documentation. It can mix details from multiple sources, return outdated information, confuse software versions, or reference deprecated options.
Verification: compare technical claims against the actual tool and its documentation.
Key Takeaways
- Generative AI creates content by predicting tokens, not by understanding meaning
- Outputs are probabilistic, not guaranteed to be correct
- Hallucinations are expected and unavoidable
- Context limits affect accuracy and completeness
- AI-generated reasoning is imitation, not verification
- Generative AI is best used as an assistant, not an authority
7. Understanding Models and Tokens
What is a model?
A model is the trained artifact produced by a machine learning process. It is a mathematical representation of patterns learned from training data. For LLMs, those patterns describe relationships between tokens in text sequences.
- Model output is probabilistic.
- The model has no inherent awareness or intent.
- Correctness is not automatically verified.
- A chat interface or local runtime gives access to a particular model, even when the interface hides that detail.
Model examples listed in the course:
- GPT-4o and the GPT-5/5.1 family
- LLaMA 3 and LLaMA 4
- Mistral and Mixtral
- Falcon
- Phi models
The slides describe GPT-4-class models as strong at reasoning, summarization, and structured output. They list LLaMA and Mistral as popular local options and smaller Phi models as fast and efficient, with trade-offs on complex technical explanations.
Model capabilities and limitations
Model behavior depends on training data, model size and architecture, fine-tuning objectives, and safety constraints.
| Areas of potential strength | Areas of potential difficulty |
|---|---|
| Natural-language explanations | Long technical commands |
| Code generation | Niche or obscure tools |
| Summarization | Very recent vulnerabilities |
| Structured output | Environment-specific assumptions |
Tokens in technical input
Numbers, flags, punctuation, and spacing all contribute to token usage. The course illustrates this with:
nmap -sV -p 443,8443 --script ssl-enum-ciphers example.com
A verbose scan can consume much more context than expected. If input is truncated, important services may disappear from the summary.
Preparing scan output for summarization:
- Extract the relevant open ports and services.
- Remove timing and debug output when it is irrelevant to the task.
- Provide only externally exposed findings when that is the requested scope.
Token limits
Platforms may impose separate limits on input tokens, output tokens, and total tokens per interaction.
- Input may be truncated.
- Important information may be ignored.
- Output may be incomplete.
- Limits differ across platforms and local model configurations.
- Some tools silently truncate input.
Course example: If you paste a 10,000-line scan, the model may see only the last portion. A polished summary may still omit earlier findings.
Key Takeaways
- A model is a pattern-based generator, not a knowledge base
- Tokens define how much information can be processed
8. Understanding Prompts and Context
What is a prompt?
A prompt is the input that guides how the model responds. It can define the role, task, constraints, and output format.
Effective prompts:
- Define the task clearly.
- Limit the scope.
- Specify what the model should avoid.
- Request a structured output.
- Identify which evidence the model may use.
Prompt comparison from the slides
Prompt A
Analyze this Nmap scan and tell me what vulnerabilities exist.
Prompt B
Summarize the provided Nmap scan output. List only externally exposed services, unusual ports, and legacy protocols. Do not speculate about vulnerabilities.
Prompt A invites the model to infer vulnerabilities from limited evidence. Prompt B specifies what to extract and explicitly rules out speculation.
Structured prompt example
You are assisting with a penetration test. Summarize the following scan output. Only extract information explicitly present. Do not infer vulnerabilities. Output results as a table with host, port, service, and notes.
System instructions vs. user prompts
| System instructions | User prompts |
|---|---|
| Define global behavior, tone, and boundaries. | Define the task for a particular request. |
| Can persist across interactions. | Can change from one request to the next. |
| Can enforce non-speculation, verification language, and consistent formatting. | Operate within the applicable system instructions. |
Example system instruction:
Do not invent tools, commands, vulnerabilities, or CVEs. If information is missing, state that explicitly.
Context: what the model can see
Context is the information available to the model at generation time. It can include the current prompt, available previous messages, system instructions, and embedded or retrieved data. External files and earlier sessions must be supplied in context for the model to reference them.
If the context window is exceeded:
- Earlier information or instructions may be dropped.
- The model may contradict earlier input.
- Long-running conversations and multi-stage analysis may lose important details.
Managing context: break the task into steps, re-supply critical constraints, and use summaries in place of irrelevant raw data.
Putting it together
Four elements determine the quality of an AI-assisted workflow:
- Model: choose one suited to the task.
- Tokens: manage the volume and structure of the input.
- Prompt: specify the task, scope, and output.
- Context: ensure relevant evidence and constraints are available.
A precise prompt can still fail if the evidence is truncated. A capable model can still speculate if the instructions are vague.
Course example of human-reviewed summarization:
- The tester runs Nmap and WhatWeb manually.
- Extract key services and headers.
- Provide the filtered output to the AI.
- Request a structured summary.
- Manually validate findings of interest.
- The tester decides the next steps.
Key Takeaways
- A model is a pattern-based generator, not a knowledge base
- Tokens define how much information can be processed
- Prompts control behavior, scope, and output quality
- Context determines what the model can and cannot reference
- Effective GenAI usage requires deliberate control of all four
9. Understanding Inference in Generative AI and LLMs
What is inference?
Inference is the phase in which a trained model generates output from new input. In an LLM, the prompt passes through the pretrained neural network, which produces tokens based on learned patterns.
Inference vs. training
| Aspect | Training | Inference |
|---|---|---|
| Purpose | Learn patterns from data | Apply learned patterns |
| Data | Massive labeled or unlabeled datasets | User prompts |
| Compute cost | Extremely high | High, but much lower than training |
| Frequency | Infrequent; training can take weeks or months | Every prompt |
| Output | Model weights | Generated tokens |
Inference in practice
Chat UI, such as ChatGPT
- Inference happens server-side.
- In the course example, cost is abstracted into a subscription.
- System instructions, user prompts, and additional context are combined.
API
- The application sends system instructions, user input, and supported parameters.
- Usage can be billed by tokens processed and generated.
- The application can explicitly control generation settings.
Key inference parameters
| Parameter | Effect described in the course |
|---|---|
temperature |
Controls randomness in token selection. |
top_p |
Controls the diversity of token sampling. |
max_tokens |
Limits output length. |
presence_penalty |
Discourages reuse of tokens that have already appeared. |
frequency_penalty |
Penalizes tokens according to how often they have appeared. |
Why inference is costly
- Large models require substantial memory for model weights.
- Inference benefits from GPU/TPU acceleration, high memory bandwidth, and parallel computation.
- The request processes the available context and generates output token by token.
- Longer prompts and larger models generally increase inference cost.
- The course distinguishes API inference billing from access through a chat UI.
Understanding inference supports prompt engineering, cost control, and reproducibility.
Key Takeaway
Inference is the runtime execution of a trained LLM where it predicts and generates outputs token-by-token based on probability, not rules or certainty. Understanding inference is critical for:
- Prompt engineering
- Cost control
- Reproducibility
- Safe and responsible AI-assisted pentesting