Files
fscan/mylib/grdp/client/client.go
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

175 lines
3.6 KiB
Go

// client.go
package client
import (
"log"
"os"
"github.com/shadow1ng/fscan/mylib/grdp/glog"
"github.com/shadow1ng/fscan/mylib/grdp/protocol/pdu"
"github.com/shadow1ng/fscan/mylib/grdp/protocol/rfb"
)
const (
CLIP_OFF = 0
CLIP_IN = 0x1
CLIP_OUT = 0x2
)
const (
TC_RDP = 0
TC_VNC = 1
)
type Control interface {
Login(host, user, passwd string, width, height int) error
KeyUp(sc int, name string)
KeyDown(sc int, name string)
MouseMove(x, y int)
MouseWheel(scroll, x, y int)
MouseUp(button int, x, y int)
MouseDown(button int, x, y int)
On(event string, msg interface{})
Close()
}
func init() {
glog.SetLevel(glog.INFO)
logger := log.New(os.Stdout, "", 0)
glog.SetLogger(logger)
}
type Client struct {
host string
user string
passwd string
ctl Control
tc int
setting *Setting
}
func NewClient(host, user, passwd string, t int, s *Setting) *Client {
if s == nil {
s = NewSetting()
}
c := &Client{
host: host,
user: user,
passwd: passwd,
tc: t,
setting: s,
}
switch t {
case TC_VNC:
c.ctl = newVncClient(s)
default:
c.ctl = newRdpClient(s)
}
s.SetLogLevel()
return c
}
func (c *Client) Login() error {
return c.ctl.Login(c.host, c.user, c.passwd, c.setting.Width, c.setting.Height)
}
func (c *Client) KeyUp(sc int, name string) {
c.ctl.KeyUp(sc, name)
}
func (c *Client) KeyDown(sc int, name string) {
c.ctl.KeyDown(sc, name)
}
func (c *Client) MouseMove(x, y int) {
c.ctl.MouseMove(x, y)
}
func (c *Client) MouseWheel(scroll, x, y int) {
c.ctl.MouseWheel(scroll, x, y)
}
func (c *Client) MouseUp(button, x, y int) {
c.ctl.MouseUp(button, x, y)
}
func (c *Client) MouseDown(button, x, y int) {
c.ctl.MouseDown(button, x, y)
}
func (c *Client) OnError(f func(e error)) {
c.ctl.On("error", f)
}
func (c *Client) OnClose(f func()) {
c.ctl.On("close", f)
}
func (c *Client) OnSuccess(f func()) {
c.ctl.On("success", f)
}
func (c *Client) OnReady(f func()) {
c.ctl.On("ready", f)
}
func (c *Client) OnBitmap(f func([]Bitmap)) {
f1 := func(data interface{}) {
bs := make([]Bitmap, 0, 50)
if c.tc == TC_VNC {
br := data.(*rfb.BitRect)
for _, v := range br.Rects {
b := Bitmap{int(v.Rect.X), int(v.Rect.Y), int(v.Rect.X + v.Rect.Width), int(v.Rect.Y + v.Rect.Height),
int(v.Rect.Width), int(v.Rect.Height),
Bpp(uint16(br.Pf.BitsPerPixel)), false, v.Data}
bs = append(bs, b)
}
} else {
for _, v := range data.([]pdu.BitmapData) {
IsCompress := v.IsCompress()
stream := v.BitmapDataStream
if IsCompress {
stream = bitmapDecompress(&v)
IsCompress = false
}
b := Bitmap{int(v.DestLeft), int(v.DestTop), int(v.DestRight), int(v.DestBottom),
int(v.Width), int(v.Height), Bpp(v.BitsPerPixel), IsCompress, stream}
bs = append(bs, b)
}
}
f(bs)
}
c.ctl.On("bitmap", f1)
}
type Bitmap struct {
DestLeft int `json:"destLeft"`
DestTop int `json:"destTop"`
DestRight int `json:"destRight"`
DestBottom int `json:"destBottom"`
Width int `json:"width"`
Height int `json:"height"`
BitsPerPixel int `json:"bitsPerPixel"`
IsCompress bool `json:"isCompress"`
Data []byte `json:"data"`
}
func Bpp(bp uint16) int {
return int(bp / 8)
}
type Setting struct {
Width int
Height int
Protocol string
LogLevel glog.LEVEL
}
func NewSetting() *Setting {
return &Setting{
Width: 1024,
Height: 768,
LogLevel: glog.INFO,
}
}
func (s *Setting) SetLogLevel() {
glog.SetLevel(s.LogLevel)
}
func (s *Setting) SetRequestedProtocol(p uint32) {}
func (s *Setting) SetClipboard(c int) {}