Skip to content

Instantly share code, notes, and snippets.

@hshimamoto
Created January 24, 2020 21:18
Show Gist options
  • Save hshimamoto/e8ba1a44e3f27de5e700826b1f7a72d2 to your computer and use it in GitHub Desktop.
Save hshimamoto/e8ba1a44e3f27de5e700826b1f7a72d2 to your computer and use it in GitHub Desktop.
// uskbdxrdp
// MIT License Copyright(c) 2020 Hiroshi Shimamoto
// vim:set sw=4 sts=4:
package main
import (
"log"
"net"
"github.com/hshimamoto/go-session"
"github.com/hshimamoto/go-iorelay"
)
func handler(conn net.Conn) {
defer conn.Close()
log.Println("connected")
fconn, err := session.Dial("127.0.0.1:3389")
if err != nil {
log.Printf("Connect failed: %v\n", err)
return
}
{ // -> hello
buf := make([]byte, 4096)
n, _ := conn.Read(buf)
fconn.Write(buf[:n])
}
{ // <- hello
buf := make([]byte, 4096)
n, _ :=fconn.Read(buf)
conn.Write(buf[:n])
}
{ // -> params
buf := make([]byte, 4096)
n, _ := conn.Read(buf)
if n > 0x100 {
// 0 1 2 3 4 5 6 7 8 9 a b c
// 0090: 00 a0 05 84 03 01 ca 03 aa 11 04 01 e0 28 0a 00
// ->
// 0090: 00 a0 05 84 03 01 ca 03 aa 09 04 00 00 28 0a 00
for x := 0x40; x < 0x100; x++ {
if buf[x] == 0x03 && buf[x+1] == 0xaa {
buf[x+2] = 0x09
buf[x+3] = 0x04
buf[x+4] = 0x00
buf[x+5] = 0x00
log.Printf("@0x%x: force us kbd", x)
break
}
}
}
fconn.Write(buf[:n])
}
iorelay.Relay(conn, fconn)
}
func main() {
s, err := session.NewServer(":3390", handler)
if err != nil {
log.Printf("session.NewServer: %v\n", err)
return
}
s.Run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment