forked from mushorg/glutton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdp.go
44 lines (40 loc) · 1.08 KB
/
rdp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package glutton
import (
"context"
"encoding/hex"
"fmt"
"net"
"github.com/mushorg/glutton/protocols/rdp"
)
// HandleRDP takes a net.Conn and does basic RDP communication
func (g *Glutton) HandleRDP(ctx context.Context, conn net.Conn) (err error) {
defer func() {
err = conn.Close()
if err != nil {
g.logger.Error(fmt.Sprintf("[rdp ] error: %v", err))
}
}()
buffer := make([]byte, 1024)
for {
g.updateConnectionTimeout(ctx, conn)
n, err := conn.Read(buffer)
if err != nil && n <= 0 {
g.logger.Error(fmt.Sprintf("[rdp ] error: %v", err))
return err
}
if n > 0 && n < 1024 {
g.logger.Info(fmt.Sprintf("[rdp ] \n%s", hex.Dump(buffer[0:n])))
pdu, err := rdp.ParseCRPDU(buffer[0:n])
if err != nil {
g.logger.Error(fmt.Sprintf("[rdp ] error: %v", err))
}
g.logger.Info(fmt.Sprintf("[rdp ] req pdu: %+v", pdu))
if len(pdu.Data) > 0 {
g.logger.Info(fmt.Sprintf("[rdp ] data: %s", string(pdu.Data)))
}
resp := rdp.ConnectionConfirm()
g.logger.Info(fmt.Sprintf("[rdp ]resp pdu: %+v", resp))
conn.Write(resp)
}
}
}