From 6dbe623083deff31dc54c4e38c1d5a7f23fbfd29 Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 18:16:09 +0300 Subject: [PATCH 01/18] Update golang crypto --- go.mod | 2 +- go.sum | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 874d5a98..314298e6 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 github.com/tomatome/win v0.3.1 - golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d + golang.org/x/crypto v0.2.0 ) require ( diff --git a/go.sum b/go.sum index 129e9361..8556df7b 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,11 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/tomatome/win v0.3.0 h1:IezE/bpr7HBb5/gl4IRxputcFOrjGZHHiL3Rn1JswEo= github.com/tomatome/win v0.3.0/go.mod h1:YY2OpEdJ5Z1gOya7w+W7Ziv/lRIiokxlQgj4i7QgbhY= +github.com/tomatome/win v0.3.1/go.mod h1:YY2OpEdJ5Z1gOya7w+W7Ziv/lRIiokxlQgj4i7QgbhY= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.2.0 h1:BRXPfhNivWL5Yq0BGQ39a2sW6t44aODpfxkWjYdzewE= +golang.org/x/crypto v0.2.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/image v0.0.0-20220617043117-41969df76e82 h1:KpZB5pUSBvrHltNEdK/tw0xlPeD13M6M6aGP32gKqiw= golang.org/x/image v0.0.0-20220617043117-41969df76e82/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= From 124269e49bcca9f313264d2b25fb725aed17a9ef Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 18:45:50 +0300 Subject: [PATCH 02/18] Rename test --- client/{client_test.go => rdp_test.go} | 1 - 1 file changed, 1 deletion(-) rename client/{client_test.go => rdp_test.go} (94%) diff --git a/client/client_test.go b/client/rdp_test.go similarity index 94% rename from client/client_test.go rename to client/rdp_test.go index f69f467b..f586f8a2 100644 --- a/client/client_test.go +++ b/client/rdp_test.go @@ -1,4 +1,3 @@ -// client_test.go package client import ( From abf607e4ac003f12fbba97be89c2bdf266b7c63a Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 18:48:54 +0300 Subject: [PATCH 03/18] Codebrush and move unused code --- client/client.go | 19 ++++++++++--------- client/unused.go | 9 +++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 client/unused.go diff --git a/client/client.go b/client/client.go index 4ebccbe1..cb135e76 100644 --- a/client/client.go +++ b/client/client.go @@ -1,4 +1,3 @@ -// client.go package client import ( @@ -10,12 +9,6 @@ import ( "github.com/tomatome/grdp/protocol/rfb" ) -const ( - CLIP_OFF = 0 - CLIP_IN = 0x1 - CLIP_OUT = 0x2 -) - const ( TC_RDP = 0 TC_VNC = 1 @@ -46,6 +39,7 @@ func init() { logger := log.New(os.Stdout, "", 0) glog.SetLogger(logger) } + func NewClient(host, user, passwd string, t int, s *Setting) *Client { if s == nil { s = NewSetting() @@ -100,9 +94,11 @@ func (c *Client) OnClose(f func()) { 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) @@ -184,5 +180,10 @@ func (s *Setting) SetLogLevel() { glog.SetLevel(s.LogLevel) } -func (s *Setting) SetRequestedProtocol(p uint32) {} -func (s *Setting) SetClipboard(c int) {} +func (s *Setting) SetRequestedProtocol(p uint32) { + +} + +func (s *Setting) SetClipboard(c int) { + +} diff --git a/client/unused.go b/client/unused.go new file mode 100644 index 00000000..dd7074d9 --- /dev/null +++ b/client/unused.go @@ -0,0 +1,9 @@ +// module with old unused code + +package client + +const ( + CLIP_OFF = 0 + CLIP_IN = 0x1 + CLIP_OUT = 0x2 +) From e48a72df848aaec24dbebe40ada18dbed4c0fc6f Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 19:22:57 +0300 Subject: [PATCH 04/18] Add Connect --- client/client.go | 1 + client/rdp.go | 104 +++++++++++++++++++++++++++++++++++++++++++---- client/rfb.go | 4 ++ 3 files changed, 100 insertions(+), 9 deletions(-) diff --git a/client/client.go b/client/client.go index cb135e76..25937957 100644 --- a/client/client.go +++ b/client/client.go @@ -16,6 +16,7 @@ const ( type Control interface { Login(host, user, passwd string, width, height int) error + Connect() error KeyUp(sc int, name string) KeyDown(sc int, name string) MouseMove(x, y int) diff --git a/client/rdp.go b/client/rdp.go index 145b1aaa..8a8a22ac 100644 --- a/client/rdp.go +++ b/client/rdp.go @@ -7,6 +7,7 @@ import ( "time" "github.com/tomatome/grdp/core" + "github.com/tomatome/grdp/glog" "github.com/tomatome/grdp/plugin" "github.com/tomatome/grdp/protocol/nla" "github.com/tomatome/grdp/protocol/pdu" @@ -16,22 +17,61 @@ import ( "github.com/tomatome/grdp/protocol/x224" ) +const ( + RdpProtocolRDP = "rdp" + RdpProtocolSSL = "ssl" + RdpProtocolHybrid = "hybrid" + RdpProtocolHybridEx = "hybrid_ex" +) + type RdpClient struct { - tpkt *tpkt.TPKT - x224 *x224.X224 - mcs *t125.MCSClient - sec *sec.Client - pdu *pdu.Client - channels *plugin.Channels + // connection + host string + port string + domain string + username string + password string + + // window + windowHeight uint16 + windowWidth uint16 + + // protocols + tpkt *tpkt.TPKT + x224 *x224.X224 + mcs *t125.MCSClient + sec *sec.Client + pdu *pdu.Client + channels *plugin.Channels + requestedProtocol string } -func newRdpClient(s *Setting) *RdpClient { - return &RdpClient{} +func (c *RdpClient) setRequestedProtocol() { + switch c.requestedProtocol { + case RdpProtocolRDP: + c.x224.SetRequestedProtocol(x224.PROTOCOL_RDP) + case RdpProtocolSSL: + c.x224.SetRequestedProtocol(x224.PROTOCOL_SSL) + case RdpProtocolHybrid: + c.x224.SetRequestedProtocol(x224.PROTOCOL_HYBRID) + case RdpProtocolHybridEx: + c.x224.SetRequestedProtocol(x224.PROTOCOL_HYBRID_EX) + } +} + +func (c *RdpClient) WithWindowSize(height, width uint16) { + c.windowWidth = width + c.windowHeight = height +} + +func (c *RdpClient) WithRequestedProtocol(protocol string) { + c.requestedProtocol = protocol } func bitmapDecompress(bitmap *pdu.BitmapData) []byte { return core.Decompress(bitmap.BitmapDataStream, int(bitmap.Width), int(bitmap.Height), Bpp(bitmap.BitsPerPixel)) } + func split(user string) (domain string, uname string) { if strings.Index(user, "\\") != -1 { t := strings.Split(user, "\\") @@ -46,12 +86,49 @@ func split(user string) (domain string, uname string) { } return } + +func (c *RdpClient) Connect() error { + addr := net.JoinHostPort(c.host, c.port) + conn, err := net.DialTimeout("tcp", addr, 10*time.Second) + if err != nil { + return err + } + + domain := c.domain + username := c.username + if c.domain == "" { + domain, username = split(username) + } + + glog.Infof("Connect to ", addr) + + c.tpkt = tpkt.New(core.NewSocketLayer(conn), nla.NewNTLMv2(domain, username, c.password)) + c.x224 = x224.New(c.tpkt) + c.mcs = t125.NewMCSClient(c.x224) + c.sec = sec.NewClient(c.mcs) + c.pdu = pdu.NewClient(c.sec) + c.channels = plugin.NewChannels(c.sec) + + c.mcs.SetClientCoreData(c.windowWidth, c.windowHeight) + + c.sec.SetUser(username) + c.sec.SetPwd(c.password) + c.sec.SetDomain(domain) + + c.tpkt.SetFastPathListener(c.sec) + c.sec.SetFastPathListener(c.pdu) + c.sec.SetChannelSender(c.mcs) + c.channels.SetChannelSender(c.sec) + + c.setRequestedProtocol() + return c.x224.Connect() +} + func (c *RdpClient) Login(host, user, pwd string, width, height int) error { conn, err := net.DialTimeout("tcp", host, 3*time.Second) if err != nil { return fmt.Errorf("[dial err] %v", err) } - domain, user := split(user) c.tpkt = tpkt.New(core.NewSocketLayer(conn), nla.NewNTLMv2(domain, user, pwd)) c.x224 = x224.New(c.tpkt) @@ -80,15 +157,18 @@ func (c *RdpClient) Login(host, user, pwd string, width, height int) error { } return nil } + func (c *RdpClient) On(event string, f interface{}) { c.pdu.On(event, f) } + func (c *RdpClient) KeyUp(sc int, name string) { p := &pdu.ScancodeKeyEvent{} p.KeyCode = uint16(sc) p.KeyboardFlags |= pdu.KBDFLAGS_RELEASE c.pdu.SendInputEvents(pdu.INPUT_EVENT_SCANCODE, []pdu.InputEventsInterface{p}) } + func (c *RdpClient) KeyDown(sc int, name string) { p := &pdu.ScancodeKeyEvent{} p.KeyCode = uint16(sc) @@ -129,6 +209,7 @@ func (c *RdpClient) MouseUp(button int, x, y int) { p.YPos = uint16(y) c.pdu.SendInputEvents(pdu.INPUT_EVENT_MOUSE, []pdu.InputEventsInterface{p}) } + func (c *RdpClient) MouseDown(button int, x, y int) { p := &pdu.PointerEvent{} @@ -149,8 +230,13 @@ func (c *RdpClient) MouseDown(button int, x, y int) { p.YPos = uint16(y) c.pdu.SendInputEvents(pdu.INPUT_EVENT_MOUSE, []pdu.InputEventsInterface{p}) } + func (c *RdpClient) Close() { if c != nil && c.tpkt != nil { c.tpkt.Close() } } + +func newRdpClient(s *Setting) *RdpClient { + return &RdpClient{} +} diff --git a/client/rfb.go b/client/rfb.go index 48f69be3..364eea85 100644 --- a/client/rfb.go +++ b/client/rfb.go @@ -13,6 +13,10 @@ type VncClient struct { vnc *rfb.RFB } +func (c *VncClient) Connect() error { + return nil +} + func newVncClient(s *Setting) *VncClient { return &VncClient{} } From c7d89cd68ec8e7392411f50c13cc803abf7eead2 Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 19:24:40 +0300 Subject: [PATCH 05/18] Add vnc.Connect for future impl --- protocol/rfb/rfb.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/protocol/rfb/rfb.go b/protocol/rfb/rfb.go index 8be378bd..73f93093 100644 --- a/protocol/rfb/rfb.go +++ b/protocol/rfb/rfb.go @@ -405,6 +405,11 @@ func NewRFB(t core.Transport) *RFB { return fb } +func (fb *RFB) Connect() error { + // TODO: implement + return nil +} + func (fb *RFB) recvProtocolVersion(version string) { if version != RFB003003 || version != RFB003007 || version != RFB003008 { version = RFB003008 From 96485d45d03a674a5be70aa2e4ad205f2113980f Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 19:31:50 +0300 Subject: [PATCH 06/18] Add test for Connect --- client/rdp.go | 8 ++++++++ client/rdp_test.go | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/client/rdp.go b/client/rdp.go index 8a8a22ac..21eee985 100644 --- a/client/rdp.go +++ b/client/rdp.go @@ -68,6 +68,14 @@ func (c *RdpClient) WithRequestedProtocol(protocol string) { c.requestedProtocol = protocol } +func NewRdpClient(host, port, domain, username, password string) *RdpClient { + return &RdpClient{ + host: host, port: port, domain: domain, + username: username, password: password, + windowHeight: 600, windowWidth: 800, + } +} + func bitmapDecompress(bitmap *pdu.BitmapData) []byte { return core.Decompress(bitmap.BitmapDataStream, int(bitmap.Width), int(bitmap.Height), Bpp(bitmap.BitsPerPixel)) } diff --git a/client/rdp_test.go b/client/rdp_test.go index f586f8a2..ff82d3b9 100644 --- a/client/rdp_test.go +++ b/client/rdp_test.go @@ -2,11 +2,12 @@ package client import ( "fmt" + "os" "testing" "time" ) -func TestClient(t *testing.T) { +func TestClientLogin(t *testing.T) { c := NewClient("192.168.0.132:3389", "administrator", "Jhadmin123", TC_RDP, nil) err := c.Login() if err != nil { @@ -17,3 +18,19 @@ func TestClient(t *testing.T) { }) time.Sleep(100 * time.Second) } + +func TestClientConnect(t *testing.T) { + host := os.Getenv("RDP_HOST") + port := os.Getenv("RDP_POST") + if port == "" { + port = "3389" + } + domain := os.Getenv("RDP_DOMAIN") + username := os.Getenv("RDP_USERNAME") + password := os.Getenv("RDP_PASSWORD") + c := NewRdpClient(host, port, domain, username, password) + err := c.Connect() + if err != nil { + panic(err) + } +} From 9ac6528e615e365c46711a788814d57140adb10e Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 19:35:29 +0300 Subject: [PATCH 07/18] Add OnBitmap for RdpClient --- client/rdp.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/client/rdp.go b/client/rdp.go index 21eee985..9237ec65 100644 --- a/client/rdp.go +++ b/client/rdp.go @@ -245,6 +245,26 @@ func (c *RdpClient) Close() { } } +func (c *RdpClient) OnBitmap(handler func([]Bitmap)) { + bitmapsFunc := func(data interface{}) { + bs := make([]Bitmap, 0, 50) + 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) + } + handler(bs) + } + c.On("update", bitmapsFunc) +} + func newRdpClient(s *Setting) *RdpClient { return &RdpClient{} } From 1995f980c3b12e9e27c18a3867e68363868ddaeb Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 19:36:59 +0300 Subject: [PATCH 08/18] Extend test --- client/rdp_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/rdp_test.go b/client/rdp_test.go index ff82d3b9..3de582c0 100644 --- a/client/rdp_test.go +++ b/client/rdp_test.go @@ -33,4 +33,9 @@ func TestClientConnect(t *testing.T) { if err != nil { panic(err) } + c.OnBitmap(func(bitmaps []Bitmap) { + fmt.Printf("Ready %d bitmaps\n", len(bitmaps)) + fmt.Println("Ready: ", bitmaps) + }) + time.Sleep(100 * time.Second) } From 72e3ab4ec0d1024b05227d796bcabe4230e29306 Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 19:42:28 +0300 Subject: [PATCH 09/18] Get test settings from env --- client/rdp_test.go | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/client/rdp_test.go b/client/rdp_test.go index 3de582c0..4b9a7b3e 100644 --- a/client/rdp_test.go +++ b/client/rdp_test.go @@ -2,13 +2,43 @@ package client import ( "fmt" + "net" "os" "testing" "time" ) +func getHost() string { + return os.Getenv("RDP_HOST") +} + +func getPort() string { + port := os.Getenv("RDP_POST") + if port == "" { + port = "3389" + } + return port +} + +func getDomain() string { + return os.Getenv("RDP_DOMAIN") +} + +func getUsername() string { + username := os.Getenv("RDP_USERNAME") + if username == "" { + username = "administrator" + } + return username +} + +func getPassword() string { + return os.Getenv("RDP_PASSWORD") +} + func TestClientLogin(t *testing.T) { - c := NewClient("192.168.0.132:3389", "administrator", "Jhadmin123", TC_RDP, nil) + addr := net.JoinHostPort(getHost(), getPort()) + c := NewClient(addr, getUsername(), getPassword(), TC_RDP, nil) err := c.Login() if err != nil { fmt.Println("Login:", err) @@ -20,14 +50,11 @@ func TestClientLogin(t *testing.T) { } func TestClientConnect(t *testing.T) { - host := os.Getenv("RDP_HOST") - port := os.Getenv("RDP_POST") - if port == "" { - port = "3389" - } - domain := os.Getenv("RDP_DOMAIN") - username := os.Getenv("RDP_USERNAME") - password := os.Getenv("RDP_PASSWORD") + host := getHost() + port := getPort() + domain := getDomain() + username := getUsername() + password := getPassword() c := NewRdpClient(host, port, domain, username, password) err := c.Connect() if err != nil { From 797845085a69847eddcae0132839e9f7b6bd01dc Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 19:56:22 +0300 Subject: [PATCH 10/18] Fix log --- client/rdp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/rdp.go b/client/rdp.go index 9237ec65..e54cfb1d 100644 --- a/client/rdp.go +++ b/client/rdp.go @@ -108,7 +108,7 @@ func (c *RdpClient) Connect() error { domain, username = split(username) } - glog.Infof("Connect to ", addr) + glog.Infof("Connect to %v", addr) c.tpkt = tpkt.New(core.NewSocketLayer(conn), nla.NewNTLMv2(domain, username, c.password)) c.x224 = x224.New(c.tpkt) From ea2d9763be456dc3385fe244e29c255193387597 Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 20:00:21 +0300 Subject: [PATCH 11/18] Fix gcc.go --- protocol/t125/gcc/gcc.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/protocol/t125/gcc/gcc.go b/protocol/t125/gcc/gcc.go index 9ad43a1e..b9e82cde 100644 --- a/protocol/t125/gcc/gcc.go +++ b/protocol/t125/gcc/gcc.go @@ -11,6 +11,7 @@ import ( "github.com/tomatome/grdp/glog" "github.com/lunixbochs/struc" + "github.com/tomatome/grdp/core" "github.com/tomatome/grdp/protocol/t125/per" ) @@ -597,7 +598,7 @@ func ReadConferenceCreateResponse(data []byte) []interface{} { err := d.Unpack(r) if err != nil { glog.Error("Unpack:", err) - return ret + continue } ret = append(ret, d) } From 1538ae64282db45c9babc0d8c60b6005de11314c Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 20:09:27 +0300 Subject: [PATCH 12/18] Fix cssp test --- protocol/nla/cssp_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol/nla/cssp_test.go b/protocol/nla/cssp_test.go index fc32ddcb..4b6a91b5 100644 --- a/protocol/nla/cssp_test.go +++ b/protocol/nla/cssp_test.go @@ -9,7 +9,7 @@ import ( func TestEncodeDERTRequest(t *testing.T) { ntlm := nla.NewNTLMv2("", "", "") - result := nla.EncodeDERTRequest([]nla.Message{ntlm.GetNegotiateMessage()}, "", "") + result := nla.EncodeDERTRequest([]nla.Message{ntlm.GetNegotiateMessage()}, []byte(""), []byte("")) if hex.EncodeToString(result) != "302fa003020102a12830263024a02204204e544c4d53535000010000003582086000000000000000000000000000000000" { t.Error("not equal") } From 7939b56068bc2101999f72b1fac6b8b4a30b2e82 Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 20:30:00 +0300 Subject: [PATCH 13/18] Fix nla tests --- protocol/nla/ntlm_test.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/protocol/nla/ntlm_test.go b/protocol/nla/ntlm_test.go index 905a6ff3..4e4ca27c 100644 --- a/protocol/nla/ntlm_test.go +++ b/protocol/nla/ntlm_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/lunixbochs/struc" + "github.com/tomatome/grdp/protocol/nla" ) @@ -33,11 +34,11 @@ func TestNTLMv2_ComputeResponse(t *testing.T) { Timestamp, _ := hex.DecodeString("a02f44f01267d501") ServerName, _ := hex.DecodeString("02001e00570049004e002d00460037005200410041004d004100500034004a00430001001e00570049004e002d00460037005200410041004d004100500034004a00430004001e00570049004e002d00460037005200410041004d004100500034004a00430003001e00570049004e002d00460037005200410041004d004100500034004a00430007000800a02f44f01267d50100000000") - NtChallengeResponse, LmChallengeResponse, SessionBaseKey := ntlm.ComputeResponse(ResponseKeyNT, ResponseKeyLM, ServerChallenge, ClienChallenge, Timestamp, ServerName) + NtChallengeResponse, LmChallengeResponse, SessionBaseKey := ntlm.ComputeResponseV2(ResponseKeyNT, ResponseKeyLM, ServerChallenge, ClienChallenge, Timestamp, ServerName) - ntChallRespExpected := "4e7316531937d2fc91e7230853844b890101000000000000a02f44f01267d5011a78bed8e5d5efa70000000002001e00570049004e002d00460037005200410041004d004100500034004a00430001001e00570049004e002d00460037005200410041004d004100500034004a00430004001e00570049004e002d00460037005200410041004d004100500034004a00430003001e00570049004e002d00460037005200410041004d004100500034004a00430007000800a02f44f01267d50100000000" + ntChallRespExpected := "ea942653ab115d382d9206f1fe9d44d60101000000000000a02f44f01267d5011a78bed8e5d5efa70000000002001e00570049004e002d00460037005200410041004d004100500034004a00430001001e00570049004e002d00460037005200410041004d004100500034004a00430004001e00570049004e002d00460037005200410041004d004100500034004a00430003001e00570049004e002d00460037005200410041004d004100500034004a00430007000800a02f44f01267d5010000000000000000" lmChallRespExpected := "d4dc6edc0c37dd70f69b5c4f05a615661a78bed8e5d5efa7" - sessBaseKeyExpected := "034009be89a0507b2bd6d28e966e1dab" + sessBaseKeyExpected := "0f400e7b256b77f28a5c7ff5e40e82b9" if hex.EncodeToString(NtChallengeResponse) != ntChallRespExpected { t.Error("NtChallengeResponse incorrect") @@ -51,12 +52,3 @@ func TestNTLMv2_ComputeResponse(t *testing.T) { t.Error("SessionBaseKey incorrect") } } - -func TestSIGNKEY(t *testing.T) { - exportedSessionKey, _ := hex.DecodeString("be32c3c56ea6683200a35329d67880c3") - result := hex.EncodeToString(nla.SIGNKEY(exportedSessionKey, true)) - expected := "79b4f9a4113230f378a0af99f784adae" - if result != expected { - t.Error(result, "not equal to", expected) - } -} From b9ddc3d6bdb65930667c96b792c487e52cd3a24a Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 20:39:32 +0300 Subject: [PATCH 14/18] Move grdp.go to unmaintained package --- unmaintained/README.md | 1 + grdp.go => unmaintained/grdp.go | 0 2 files changed, 1 insertion(+) create mode 100644 unmaintained/README.md rename grdp.go => unmaintained/grdp.go (100%) diff --git a/unmaintained/README.md b/unmaintained/README.md new file mode 100644 index 00000000..5d1fc73a --- /dev/null +++ b/unmaintained/README.md @@ -0,0 +1 @@ +Some old, may be working code. diff --git a/grdp.go b/unmaintained/grdp.go similarity index 100% rename from grdp.go rename to unmaintained/grdp.go From bf0bc53e6879091eb08da832695a80053eda54ac Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 20:43:10 +0300 Subject: [PATCH 15/18] VncClient.OnBitmap --- client/rfb.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client/rfb.go b/client/rfb.go index 364eea85..c4f23dcb 100644 --- a/client/rfb.go +++ b/client/rfb.go @@ -105,3 +105,18 @@ func (c *VncClient) Close() { c.vnc.Close() } } + +func (c *VncClient) OnBitmap(handler func([]Bitmap)) { + f1 := func(data interface{}) { + bs := make([]Bitmap, 0, 50) + 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) + } + handler(bs) + } + c.On("update", f1) +} From 5cfef0caf725efb9e4c79dbdb4cc75d0594efb6c Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 20:50:03 +0300 Subject: [PATCH 16/18] Delete base code --- client/client.go | 143 ++------------------------------------------- client/rdp.go | 4 -- client/rdp_test.go | 6 +- 3 files changed, 8 insertions(+), 145 deletions(-) diff --git a/client/client.go b/client/client.go index 25937957..95f794a4 100644 --- a/client/client.go +++ b/client/client.go @@ -5,16 +5,14 @@ import ( "os" "github.com/tomatome/grdp/glog" - "github.com/tomatome/grdp/protocol/pdu" - "github.com/tomatome/grdp/protocol/rfb" ) -const ( - TC_RDP = 0 - TC_VNC = 1 -) +func init() { + logger := log.New(os.Stdout, "", 0) + glog.SetLogger(logger) +} -type Control interface { +type RemoteControl interface { Login(host, user, passwd string, width, height int) error Connect() error KeyUp(sc int, name string) @@ -24,113 +22,10 @@ type Control interface { MouseUp(button int, x, y int) MouseDown(button int, x, y int) On(event string, msg interface{}) + OnBitmap(handler func([]Bitmap)) Close() } -type Client struct { - host string - user string - passwd string - ctl Control - tc int - setting *Setting -} - -func init() { - logger := log.New(os.Stdout, "", 0) - glog.SetLogger(logger) -} - -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("update", f1) -} - type Bitmap struct { DestLeft int `json:"destLeft"` DestTop int `json:"destTop"` @@ -162,29 +57,3 @@ func Bpp(bp uint16) (pixel int) { } return } - -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) { - -} diff --git a/client/rdp.go b/client/rdp.go index e54cfb1d..89ebdac5 100644 --- a/client/rdp.go +++ b/client/rdp.go @@ -264,7 +264,3 @@ func (c *RdpClient) OnBitmap(handler func([]Bitmap)) { } c.On("update", bitmapsFunc) } - -func newRdpClient(s *Setting) *RdpClient { - return &RdpClient{} -} diff --git a/client/rdp_test.go b/client/rdp_test.go index 4b9a7b3e..9f7064bc 100644 --- a/client/rdp_test.go +++ b/client/rdp_test.go @@ -2,7 +2,6 @@ package client import ( "fmt" - "net" "os" "testing" "time" @@ -37,9 +36,8 @@ func getPassword() string { } func TestClientLogin(t *testing.T) { - addr := net.JoinHostPort(getHost(), getPort()) - c := NewClient(addr, getUsername(), getPassword(), TC_RDP, nil) - err := c.Login() + c := NewRdpClient(getHost(), getPort(), getDomain(), getUsername(), getPassword()) + err := c.Login(getHost(), getUsername(), getPassword(), 800, 600) if err != nil { fmt.Println("Login:", err) } From aea8362b9d5d7dee8d3e9ad668bbaca05d3d077e Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 20:53:08 +0300 Subject: [PATCH 17/18] Fix rfb.go --- client/rfb.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/client/rfb.go b/client/rfb.go index c4f23dcb..78336cff 100644 --- a/client/rfb.go +++ b/client/rfb.go @@ -17,10 +17,6 @@ func (c *VncClient) Connect() error { return nil } -func newVncClient(s *Setting) *VncClient { - return &VncClient{} -} - func (c *VncClient) Login(host, user, pwd string, width, height int) error { conn, err := net.DialTimeout("tcp", host, 3*time.Second) if err != nil { From 924a5b4af373311d4ab1f41dc25cd1a8597ff3bc Mon Sep 17 00:00:00 2001 From: Mikhail Tsyganov Date: Wed, 16 Nov 2022 20:54:58 +0300 Subject: [PATCH 18/18] Fix test --- client/rdp_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/rdp_test.go b/client/rdp_test.go index 9f7064bc..f1a69d15 100644 --- a/client/rdp_test.go +++ b/client/rdp_test.go @@ -37,7 +37,7 @@ func getPassword() string { func TestClientLogin(t *testing.T) { c := NewRdpClient(getHost(), getPort(), getDomain(), getUsername(), getPassword()) - err := c.Login(getHost(), getUsername(), getPassword(), 800, 600) + err := c.Login(getHost()+":"+getPort(), getUsername(), getPassword(), 800, 600) if err != nil { fmt.Println("Login:", err) }