MnemOnicE/cli-commando

GitHub: MnemOnicE/cli-commando

CLI-Commando 是一个终端命令探索器和学习助手,通过安全地扫描和分析系统可执行文件,为用户提供命令用法、历史管理和行为审计能力。

Stars: 0 | Forks: 0

# CLI-Commando **CLI-Commando** 是你的终端命令探索器和导师。它会学习你实际使用的命令,动态映射 CLI 环境,并在你需要时直接提供有用的使用示例。 ## 功能 - **交互式仪表盘:** 跟踪命令使用情况、自定义定义以及自动导入的描述。 - **系统自动扫描器:** 通过静态分析(在不任意执行的情况下安全检查 ELF 二进制文件和 shell 脚本),防御性地扫描系统 `PATH` 以查找未知可执行文件,从而构建强大的本地知识库。 - **动态审计:** 使用 `strace` 动态分析命令配置文件以检测系统调用(例如,标记网络修改器或文件读取器),并在受限环境中执行时,优雅地降级到 `ldd` 静态分析。 - **Bash Hook 集成:** 自动挂钩到 bash 中的 `command_not_found_handle`,以提供即时的 commando 协助。 - **测验:** 运行快速测验以测试你对自己命令历史记录的掌握程度。 ![动态审计演示](https://raw.githubusercontent.com/MnemOnicE/cli-commando/main/assets/kinetic_audit_demo.gif) ![TUI 测验演示](https://raw.githubusercontent.com/MnemOnicE/cli-commando/main/assets/tui_quiz_demo.gif) ## 架构 CLI-Commando 实现了从动态探测到安全、防御性扫描的转变: - 它在不运行本地二进制文件的情况下,安全地提取使用文本。 - 它采用并发执行,并经过仔细的节流处理,以保持系统性能(尤其是在 ARM 和受限硬件上)。 - 它被设计为一个完全模块化的 Python 包。 ### 数据流程图 以下是支持 CLI-Commando 的详细工作流。它们共享一致的颜色编码方案: * **蓝色**:核心流程和操作 * **黄色**:逻辑决策 * **绿色**:数据存储和数据库 * **红色**:回退、错误或拒绝 #### 1. 整体命令搜索流程 CLI-Commando 如何处理来自用户的标准搜索查询。 ``` flowchart TD classDef process fill:#d4e6f1,stroke:#2874a6,stroke-width:2px,color:#1b4f72; classDef decision fill:#fcf3cf,stroke:#b7950b,stroke-width:2px,color:#7d6608; classDef database fill:#d5f5e3,stroke:#1e8449,stroke-width:2px,color:#145a32; classDef fallback fill:#fadbd8,stroke:#cb4335,stroke-width:2px,color:#78281f; User[User Searches Command] --> LogHistory[Log to History DB]:::database LogHistory --> KnownCheck{In Known DB?}:::decision KnownCheck -- Yes --> AuditCheck{Audit Flag?}:::decision AuditCheck -- Yes --> KineticAudit[Execute Kinetic Audit Flow]:::process AuditCheck -- No --> DisplayInfo[Display Description & Example]:::process KnownCheck -- No --> BlacklistCheck{In Blacklist?}:::decision BlacklistCheck -- Yes --> Block[Reject: Blacklisted]:::fallback BlacklistCheck -- No --> IntentSearch{Intent Matches?}:::decision IntentSearch -- Yes --> DisplayIntent[Display Intent Matches]:::process IntentSearch -- No --> Suggestion[Suggest Similar Commands]:::process ``` #### 2. 系统自动扫描器流程 用于在不任意执行的情况下安全发现和了解新可执行文件的零信任隔离协议。 ``` flowchart TD classDef process fill:#d4e6f1,stroke:#2874a6,stroke-width:2px,color:#1b4f72; classDef decision fill:#fcf3cf,stroke:#b7950b,stroke-width:2px,color:#7d6608; classDef database fill:#d5f5e3,stroke:#1e8449,stroke-width:2px,color:#145a32; classDef fallback fill:#fadbd8,stroke:#cb4335,stroke-width:2px,color:#78281f; StartScan[Scan PATH Directories] --> FilterBins[Filter Unknown Binaries]:::process FilterBins --> BatchLimit[Select Batch Limit]:::process BatchLimit --> OSManualCheck{OS Manual Exists?
whatis / bash help}:::decision OSManualCheck -- Yes --> ParseManual[Extract Manual Text]:::process OSManualCheck -- No --> FileHeaderCheck{Check File Header}:::decision FileHeaderCheck -- ELF Binary --> StringsScan[Run 'strings' Static Analysis]:::process FileHeaderCheck -- Shell Script --> ReadText[Read File Text]:::process FileHeaderCheck -- Unknown / Other --> BlacklistAdd[Add to Blacklist DB]:::database StringsScan --> ParseText[Extract Description & Usage Motif]:::process ReadText --> ParseText ParseText --> SuccessCheck{Text Valid?}:::decision SuccessCheck -- Yes --> PendingImports[Add to Pending Imports DB]:::database SuccessCheck -- No --> BlacklistAdd ParseManual --> PendingImports ``` #### 3. 动态审计流程 动态行为分析系统及其向静态分析的优雅降级。 ``` flowchart TD classDef process fill:#d4e6f1,stroke:#2874a6,stroke-width:2px,color:#1b4f72; classDef decision fill:#fcf3cf,stroke:#b7950b,stroke-width:2px,color:#7d6608; classDef database fill:#d5f5e3,stroke:#1e8449,stroke-width:2px,color:#145a32; classDef fallback fill:#fadbd8,stroke:#cb4335,stroke-width:2px,color:#78281f; StartAudit[Start Audit on Known Command] --> RunStrace[Run 'strace'
Timeout: 2s]:::process RunStrace --> StraceStatus{Execution Status}:::decision StraceStatus -- Success --> ParseStrace[Parse System Calls]:::process ParseStrace --> AssignTagsStrace[Assign Tags
Network, File, Process]:::process StraceStatus -- Timeout / Killed --> ErrorExit[Exit with Timeout Error]:::fallback StraceStatus -- Startup Error / No strace --> LddFallback[Fallback to 'ldd' Static Analysis]:::fallback LddFallback --> LddStatus{ldd Status}:::decision LddStatus -- Success --> ParseLdd[Parse Shared Libraries]:::process ParseLdd --> AssignTagsLdd[Assign Tags
libcurl, libssl, libc]:::process LddStatus -- Error --> StaticFallback[Fallback to Static/None]:::fallback StaticFallback --> Output[Format Output / JSON]:::process AssignTagsStrace --> Output AssignTagsLdd --> Output ``` ## 前置条件与环境 虽然该工具通过 `pip` 安装,但其核心功能依赖于以下操作系统级的二进制文件: - **严格必需:** `strings`(用于二进制文件的安全静态分析)。 - **优雅降级:** - `strace`(用于动态审计;如果不可用或被 `ptrace` 限制阻止,则回退到静态分析)。 - `ldd`(用于静态分析回退)。 - `whatis`(用于查询已知安全的系统接口以获取命令定义)。 - `readelf`(用于在不执行的情况下安全检查 ELF 头)。 **Termux** 被明确认定为完全支持的一流环境。 ## 安装 标准安装: ``` pip install . ``` 对于主动开发(可编辑模式): ``` pip install -e . ``` *(注意:确保你的 `~/.local/bin` 或等效的 Python bin 目录位于系统的 `$PATH` 中,以便操作系统能够全局识别 `commando` 命令)。* ## 用法 启动交互式终端仪表盘: ``` commando ``` 立即搜索特定命令: ``` commando search ``` 运行动态审计以准确查看可执行文件的底层行为: ``` commando search --audit ```
标签:应用安全, 逆向工具