Back to skill

Security audit

基于163邮箱SMTP发送邮件功能

Security checks for vulnerabilities and agentic risk

Overview

This 163 Mail sender appears to do what it claims, but it needs review because it disables SMTP certificate checks and logs email details by default.

Review before installing or using with real mail credentials. Remove InsecureSkipVerify, make logs opt-in or private/redacted, avoid shared log directories, do not send confidential content through this version, and do not pass untrusted text as the subject until header validation is added.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (3)

T09 · Insecure Skill Coding Practices

Error
Location
scripts/main.go:163
Finding
SMTP TLS Certificate Verification Is Disabled<![CDATA[ ## Vulnerability Details **File Location**: `scripts/main.go:163-169` **Vulnerability Type**: Improper TLS certificate validation **Risk Level**: High ### Vulnerable Code ```go // TLS配置 tlsConfig := &tls.Config{ InsecureSkipVerify: true, ServerName: smtpHost, } // 创建TLS连接 conn, err := tls.Dial("tcp", smtpHost+":"+smtpPort, tlsConfig) ``` ### Technical Analysis The SMTP client explicitly sets `InsecureSkipVerify` to `true`. This disables verification of the server certificate and hostname trust chain. Although `ServerName` is configured, Go does not perform normal certificate validation when `InsecureSkipVerify` is enabled. The application authenticates to the resulting SMTP connection using the address and authorization code read from `EMAIL163_ADDRESS` and `EMAIL163_PASSWORD`. An attacker able to intercept or redirect the network connection can present an arbitrary certificate, impersonate the SMTP server, and operate a fake SMTP endpoint. Because the connection is encrypted but not authenticated, encryption alone does not prevent this attack. ### Attack Path 1. A user runs the tool with valid 163 Mail credentials in the required environment variables. 2. A network-positioned attacker intercepts or redirects the connection to `smtp.163.com:465`, such as through a compromised network gateway, DNS manipulation, or local network attack. 3. The attacker presents an arbitrary TLS certificate. 4. The application accepts the certificate because certificate verification is disabled. 5. The attacker's SMTP service completes enough of the SMTP protocol to request authentication. 6. The client sends the configured mailbox address and authorization code to the impersonated server. 7. The attacker can capture the credentials and email contents and may subsequently use the compromised account to send unauthorized messages. ### Impact Assessment Successful exploitation can disclose the sender's mailbox address, SMTP authorization code, recipien ...[truncated 293 chars]
Remediation
<![CDATA[ ## Remediation Suggestions Remove `InsecureSkipVerify` and use Go's standard certificate and hostname verification: ```go tlsConfig := &tls.Config{ ServerName: smtpHost, MinVersion: tls.VersionTLS12, } ``` Additional hardening should include: 1. Use the operating system's trusted certificate store or an explicitly managed trust store. 2. Require TLS 1.2 or newer through `MinVersion`. 3. Fail closed if certificate validation or hostname verification fails. 4. Do not implement fallback behavior that retries with certificate verification disabled. 5. Rotate the SMTP authorization code after deploying the fix if the vulnerable version was used on an untrusted network. ]]>

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/main.go:111
Finding
Sensitive Email Data Is Logged with Permissive File Permissions<![CDATA[ ## Vulnerability Details **File Location**: `scripts/main.go:111-130`, with default logging enabled at `scripts/main.go:268` and invocation at `scripts/main.go:331` **Vulnerability Type**: Sensitive information exposure through local log files **Risk Level**: Medium ### Vulnerable Code ```go // 确保日志目录存在 if err := os.MkdirAll(logPath, 0755); err != nil { fmt.Printf("警告: 创建日志目录失败: %v\n", err) return } // 构建日志内容 result := "成功" if !success { result = fmt.Sprintf("失败: %v", err) } // 限制内容长度用于日志显示(避免日志过长) logContent := content if len(logContent) > 200 { logContent = logContent[:200] + "..." } logEntry := fmt.Sprintf(` ======================================== 发送时间: %s 邮件标题: %s 接收方: %s 邮件内容: %s 发送结果: %s ======================================== `, timestamp, subject, strings.Join(recipients, ", "), logContent, result) // 打开或创建日志文件(追加模式) file, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) ``` Logging is enabled by default and receives the original message data: ```go var logPath = flag.String("log", "./", "日志文件保存路径(可选)") ``` ```go writeLog(*logPath, *subject, *info, toList, err == nil, err) ``` ### Technical Analysis The application automatically logs email subjects, recipient addresses, delivery errors, and up to 200 bytes of message content. The default log location is the current directory, so logging occurs even when the user does not explicitly request it. New log directories are requested with mode `0755`, and new log files are requested with mode `0644`. Subject to the process umask and existing directory permissions, these modes can allow other local users to traverse the log directory and read the log file. Email bodies and recipient lists may contain personal, confidential, or operational information. The 200-byte truncation reduces the amount of exposed body data but does not eliminate the exposure. Subjects, recipient lists, error details, and the first portion of each message remain available. ### Att ...[truncated 1050 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. Make message logging opt-in instead of default: - Use an empty default log path. - Call `writeLog` only when the user explicitly supplies a log destination. 2. Create private log directories with mode `0700`. 3. Create log files with mode `0600`: ```go file, err := os.OpenFile( logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600, ) ``` 4. Avoid logging message bodies by default. Prefer event identifiers, timestamps, delivery status, and redacted recipient data. 5. If body logging is required, provide a separate explicit option and warn users that sensitive data will be stored. 6. Validate that the log destination is a trusted directory and consider rejecting symbolic links or unexpected pre-existing files where local adversaries are relevant. 7. Apply log retention and secure deletion policies to limit long-term exposure. ]]>

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/main.go:240
Finding
User-Controlled Subject Permits Raw Email Header Injection<![CDATA[ ## Vulnerability Details **File Location**: `scripts/main.go:240-242` **Vulnerability Type**: SMTP message header injection **Risk Level**: Medium ### Vulnerable Code ```go func convertToEmailFormat(subject string, info string) (string, string) { // 转化标题 emailSubject := "Subject: " + subject + "\r\n" ``` ### Technical Analysis The application constructs the raw `Subject` header by concatenating an untrusted command-line value directly into the message. It does not reject carriage-return (`\r`) or line-feed (`\n`) characters. Email headers use CRLF sequences as field delimiters. A subject containing CRLF can therefore terminate the intended `Subject` header and introduce additional attacker-selected headers. Depending on the SMTP server and receiving mail system, an attacker may inject fields such as `Reply-To`, manipulate MIME interpretation, or create misleading header data. This is particularly relevant when the CLI is invoked by another application that incorporates user-controlled values into the `--subject` argument. Shell-safe invocation does not prevent the vulnerability because the injection occurs during raw message construction rather than through shell parsing. ### Attack Path 1. An application or user supplies a subject containing CRLF characters followed by an additional mail header. 2. `convertToEmailFormat` concatenates that value directly after `Subject: `. 3. The embedded CRLF terminates the legitimate subject field. 4. The following attacker-controlled text is interpreted as one or more additional message headers. 5. The raw message is submitted to the SMTP server and may be delivered with the injected headers. A representative malicious logical value would have the following structure: ```text Expected subject\r\nReply-To: attacker@example.com ``` Actual acceptance and presentation of individual injected headers can vary across SMTP relays and receiving mail systems. ### Impact Assessment An attacker who controls the ...[truncated 349 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. Reject all carriage-return and line-feed characters in subject values: ```go if strings.ContainsAny(subject, "\r\n") { return "", "", fmt.Errorf("subject contains prohibited newline characters") } ``` 2. Change `convertToEmailFormat` to return an error so invalid header values cannot proceed to delivery. 3. Use a standards-compliant email message library that safely encodes structured headers rather than assembling the raw RFC 5322 message through string concatenation. 4. Encode non-ASCII subjects using the appropriate MIME encoded-word mechanism. 5. Apply the same CRLF validation to any future user-controlled header values, including sender names, reply addresses, and custom headers. 6. Add regression tests covering `\r`, `\n`, `\r\n`, and attempted multi-header injection. ]]>
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (7)

Sudo/Root Execution

Medium
Category
Privilege Escalation
Content
go build -o email163 main.go

# 将可执行文件移动到PATH目录(可选)
sudo mv email163 /usr/local/bin/

# 或者直接使用go install
go install
Confidence
70% confidence
Finding
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Missing User Warnings

Medium
Confidence
95% confidence
Finding
The skill explicitly documents that logs include sending time, subject, recipients, content, and results, but it does not clearly warn users that sensitive email bodies and recipient addresses may be persisted to disk. This creates a real privacy and data-leakage risk, especially if the tool is used for confidential notifications, credentials, personal data, or internal operational messages and logs are stored in shared or weakly protected locations.

Natural-Language Policy Violations

Medium
Confidence
93% confidence
Finding
The skill's help text and all user-visible console messages are presented only in Chinese, which imposes a language choice on users without opt-in. Under the stated policy, forcing a specific language without offering a choice is a natural-language policy violation unless clearly justified as region-specific.

Missing User Warnings

Medium
Confidence
90% confidence
Finding
The program writes recipients, subject, and up to 200 characters of email body into a log file, which may contain sensitive business or personal data. Because logging is enabled by default via './' unless explicitly changed, this creates unintended data retention and disclosure risk if local users, backups, or log collectors can access the files.

Natural-Language Policy Violations

Low
Confidence
91% confidence
Finding
The shell script contains a natural-language comment in Chinese ('编译main.go为email163可执行文件') with no indication that the skill supports user language choice or is intentionally limited to a Chinese-speaking context. Per the policy, forcing a specific language without opt-in is a locale/language policy concern.

Intent-Code Divergence

Low
Confidence
96% confidence
Finding
The help text says the log records include '内容' and describes the logging feature as recording the email content, which implies the full content is logged. In the implementation, the content is explicitly shortened to 200 characters before being written, so the documentation overstates what the code actually records.

Missing User Warnings

Low
Confidence
76% confidence
Finding
The program accesses EMAIL163_ADDRESS and EMAIL163_PASSWORD, which are sensitive credentials. The help text lists the required environment variables, but the execution path that reads them provides no disclosure that sensitive credentials are being consumed for authentication.

Static analysis

No suspicious patterns detected.