Files
fscan/fscan-lite/src/main.c
T
ZacharyZcR 71b92d4408 feat: v2.1.0 核心重构与功能增强
## 架构重构
- 全局变量消除,迁移至 Config/State 对象
- SMB 插件融合(smb/smb2/smbghost/smbinfo)
- 服务探测重构,实现 Nmap 风格 fallback 机制
- 输出系统重构,TXT 实时刷盘 + 双写机制
- i18n 框架升级至 go-i18n

## 性能优化
- 正则表达式预编译
- 内存优化 map[string]struct{}
- 并发指纹匹配
- SOCKS5 连接复用
- 滑动窗口调度 + 自适应线程池

## 新功能
- Web 管理界面
- 多格式 POC 适配(xray/afrog)
- 增强指纹库(3139条)
- Favicon hash 指纹识别
- 插件选择性编译(Build Tags)
- fscan-lab 靶场环境
- 默认端口扩展(62→133)

## 构建系统
- 添加 no_local tag 支持排除本地插件
- 多版本构建:fscan/fscan-nolocal/fscan-web
- CI 添加 snapshot 模式支持仅测试构建

## Bug 修复
- 修复 120+ 个问题,包括 RDP panic、批量扫描漏报、
  JSON 输出格式、Redis 检测、Context 超时等

## 测试增强
- 单元测试覆盖率 74-100%
- 并发安全测试
- 集成测试(Web/端口/服务/SSH/ICMP)
2026-01-11 20:16:23 +08:00

120 lines
3.6 KiB
C

/*
* main.c - fscan-lite 主程序
*
* 极简的TCP内网端口扫描器
* 目标:最大兼容性,最小复杂度
*/
#include "../include/platform.h"
/* 函数声明 */
int tcp_connect_test(const char* host, int port, int timeout);
int scan_host_ports(const char* host, const int* ports, int port_count, int timeout);
int parse_ports(const char* port_str, int* ports, int max_ports);
int parse_hosts(const char* host_str, char hosts[][MAX_HOST_LEN], int max_hosts);
/* 显示版本信息 */
void show_version(void) {
printf("fscan-lite v1.0 - Lightweight TCP Port Scanner\n");
printf("Built for maximum compatibility (Windows 98 - Windows 11, Linux glibc 2.3+)\n");
printf("Copyright (c) 2024\n");
}
/* 显示使用帮助 */
void show_usage(const char* program_name) {
printf("Usage: %s [OPTIONS]\n", program_name);
printf("\n");
printf("Options:\n");
printf(" -h HOST Target host (IP address)\n");
printf(" -p PORTS Ports to scan (e.g. 80,443 or 1-1000)\n");
printf(" -t TIMEOUT Connection timeout in seconds (default: 3)\n");
printf(" --help Show this help message\n");
printf(" --version Show version information\n");
printf("\n");
printf("Examples:\n");
printf(" %s -h 192.168.1.1 -p 22,80,443\n", program_name);
printf(" %s -h 10.0.0.1 -p 1-1000 -t 2\n", program_name);
printf("\n");
}
/* 主函数 */
int main(int argc, char* argv[]) {
char* target_host = NULL;
char* port_string = NULL;
int timeout = DEFAULT_TIMEOUT;
int ports[1000]; /* 支持最多1000个端口 */
int port_count = 0;
int i;
int result;
/* 参数解析 */
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0 && i + 1 < argc) {
target_host = argv[++i];
}
else if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) {
port_string = argv[++i];
}
else if (strcmp(argv[i], "-t") == 0 && i + 1 < argc) {
timeout = atoi(argv[++i]);
if (timeout <= 0) timeout = DEFAULT_TIMEOUT;
}
else if (strcmp(argv[i], "--help") == 0) {
show_usage(argv[0]);
return 0;
}
else if (strcmp(argv[i], "--version") == 0) {
show_version();
return 0;
}
else {
printf("Unknown option: %s\n", argv[i]);
show_usage(argv[0]);
return 1;
}
}
/* 验证必需参数 */
if (!target_host) {
printf("Error: Target host (-h) is required\n");
show_usage(argv[0]);
return 1;
}
if (!port_string) {
printf("Error: Ports (-p) are required\n");
show_usage(argv[0]);
return 1;
}
/* 初始化平台 */
if (platform_init() != 0) {
printf("Error: Failed to initialize platform\n");
return 1;
}
/* 解析端口 */
port_count = parse_ports(port_string, ports, sizeof(ports) / sizeof(ports[0]));
if (port_count == 0) {
printf("Error: No valid ports specified\n");
platform_cleanup();
return 1;
}
printf("fscan-lite - Starting scan\n");
printf("Target: %s\n", target_host);
printf("Ports: %d ports to scan\n", port_count);
printf("Timeout: %d seconds\n", timeout);
printf("=================================\n");
/* 执行扫描 */
result = scan_host_ports(target_host, ports, port_count, timeout);
printf("=================================\n");
printf("Scan completed: %d open ports found\n", result);
/* 清理资源 */
platform_cleanup();
return 0;
}