x90skysn3k/grdp
GitHub: x90skysn3k/grdp
这是一个修复了生产环境关键问题的纯 Go RDP 客户端库,专注于快速凭据验证和程序化访问。
Stars: 0 | Forks: 0
# grdp - Go Remote Desktop Protocol 客户端
Microsoft RDP (Remote Desktop Protocol) 客户端的纯 Go 实现,专注于认证和编程访问。这是一个积极维护的分支,支持 context、超时处理和 goroutine 安全。
最初 fork 自 [icodeface/grdp](https://github.com/icodeface/grdp)。
## 功能特性
- **NTLMv2/NLA (CredSSP) 认证** - 完整的 Network Level Authentication 支持
- **SSL/TLS 认证** - 标准的 RDP over TLS
- **标准 RDP 认证** - 传统 RDP 安全
- **context.Context 支持** - 截止时间 和取消信号 会穿透整个协议栈
- **Goroutine 安全的关闭** - 干净的 Emitter 销毁可防止 goroutine 泄漏
- **超时感知的 NLA 握手** - 所有阻塞 I/O 都遵守 context 的截止时间
## 安装
```
go get github.com/x90skysn3k/grdp
```
## 用法
### 带超时的快速认证检查
```
package main
import (
"context"
"fmt"
"time"
"github.com/x90skysn3k/grdp/client"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
c := &client.RdpClient{}
err := c.Login(ctx, "192.168.1.100:3389", "admin", "password", 800, 600)
if err != nil {
fmt.Println("Login failed:", err)
return
}
defer c.Close()
done := make(chan bool, 1)
c.On("success", func() { done <- true })
c.On("ready", func() { done <- true })
c.On("error", func(e error) { done <- false })
select {
case ok := <-done:
fmt.Println("Auth success:", ok)
case <-ctx.Done():
fmt.Println("Timeout")
}
}
```
### 使用支持 context 的高级 Client
```
c := client.NewClient("192.168.1.100:3389", "user", "pass", client.TC_RDP, nil)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
err := c.LoginContext(ctx)
```
### 域认证
```
// Domain\User format is handled automatically
c.Login(ctx, "host:3389", "DOMAIN\\administrator", "password", 800, 600)
```
## 相对于上游的修复内容
此分支解决了原始 grdp 库中导致其不适合生产环境的关键问题:
| 问题 | 修复前 | 修复后 |
|-------|--------|-------|
| **Goroutine 泄漏** | `StartReadBytes()` 生成的 goroutines 会永远阻塞在死连接上 | 感知 Context 的读取器在取消时会退出 |
| **NLA 挂起** | `StartNLA()` 在无超时的情况下无限期阻塞读写操作 | 所有 NLA 往返在阻塞 I/O 前会检查 context |
| **无法取消** | 无法取消正在进行的连接或认证尝试 | `context.Context` 流经 Socket -> TPKT -> X224 -> Client |
| **Emitter 泄漏** | 事件监听器累积,关闭时无清理机制 | `Emitter.Close()` 清除所有监听器并阻止新的分发 |
| **硬编码拨号超时** | 使用 3 秒硬编码超时的 `net.DialTimeout` | `net.Dialer.DialContext` 使用调用者提供的 context |
## 协议栈
```
Client (Login with context)
-> X224 (connection negotiation)
-> TPKT (packet framing, NLA/CredSSP)
-> SocketLayer (TLS, raw TCP)
-> net.Conn
```
每一层都向下传递 context,确保截止时间和取消信号能到达底层连接。
## 致谢
- [icodeface/grdp](https://github.com/icodeface/grdp) - 原始实现
- [rdpy](https://github.com/citronneur/rdpy) - Python RDP 参考
- [node-rdpjs](https://github.com/citronneur/node-rdpjs) - Node.js RDP 参考
- [gordp](https://github.com/Madnikulin50/gordp) - Go RDP 参考
- [ncrack](https://github.com/nmap/ncrack/blob/master/modules/ncrack_rdp.cc) - RDP 认证模块参考
## 许可证
详情请参阅 [LICENSE](LICENSE)。
标签:CredSSP, EVTX分析, EVTX分析, Go语言, IT运维, NLA认证, NTLMv2, RDP客户端, Socks5代理, TCP/IP, Windows协议, 凭据验证, 协议实现, 安全测试, 并发安全, 底层编程, 攻击性安全, 日志审计, 爆破辅助, 登录测试, 程序破解, 纯Go, 网络库, 远程桌面, 远程管理