T09 · Insecure Skill Coding Practices
- Location
scripts/patch_ua.py:103- Finding
Unrestricted and Non-Atomic Modification of User-Supplied Files
- Content
View full analysis
original_length: return (False, f"新 UA 太长 ({len(new_ua_bytes)} > {original_length}),请缩短") if dry_run: return (True, f"预览模式 - 原始 UA: {original_ua}\n新 UA: {new_ua}") # 创建备份 backup_path = dll_path + ".backup" if not os.path.exists(backup_path): shutil.copy2(dll_path, backup_path) # 修改数据 for i, byte in enumerate(new_ua_bytes): data[start_pos + i] = byte # 写回文件 with open(dll_path, 'wb') as f: f.write(data) ``` The command-line path is accepted without target validation: ```python parser.add_argument('--path', help='指定 DLL 文件路径') ``` ```python if args.path: dll_path = args.path ``` ### Technical Analysis The `--path` argument is used directly as the file to read, back up, truncate, and rewrite. The script does not verify that the resolved path: - Is named `TcefWnd.dll`. - Belongs to a discovered TongdaXin installation. - Is a regular file rather than a symbolic link or another special file. - Has a valid Portable Executable header. - Is the expected TongdaXin browser component. - Falls below a reasonable maximum file size. Consequently, any file accessible under the caller's permissions can become a patch targe ...[truncated 2498 chars]- Remediation
View remediation
