fscan/fscan-lite/src/main.c
ZacharyZcR a3177b28a6 fix: 修复插件系统逻辑Bug和架构问题
主要修复:
1. 修复时间显示Bug - StartTime初始化问题
2. 修复Web智能探测错误检测预定义端口而非用户指定端口
3. 修复本地插件被错误调用到端口扫描中的问题
4. 修复host:port格式双重处理导致的多余端口扫描
5. 统一插件过滤逻辑,消除接口不一致性
6. 优化Web检测缓存机制,减少重复HTTP请求

技术改进:
- 重构插件适用性检查逻辑,确保策略过滤器正确工作
- 区分Web检测的自动发现模式和用户指定端口模式
- 在解析阶段正确处理host:port格式,避免与默认端口冲突
- 完善缓存机制,提升性能

测试验证:
- ./fscan -h 127.0.0.1:3306 现在只检测3306端口
- 本地插件不再参与端口扫描
- Web检测只对指定端口进行协议检测
- 时间显示正确
2025-09-01 23:50:32 +00: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;
}