1 Commits

Author SHA1 Message Date
amit bezalel
f2e945c2d7 filtering pseudo encodings and setting custom compression levels 2017-11-28 00:04:27 +02:00
13 changed files with 72 additions and 60 deletions

View File

@@ -16,17 +16,13 @@ An RFB proxy, written in go that can save and replay FBS files
- VineVnc(server)
- TigerVnc(client)
## Usage:
### Executables (see releases)
* proxy - the actual recording proxy, supports listening to tcp & ws ports and recording traffic to fbs files
* recorder - connects to a vnc server as a client and records the screen
* player - a toy player that will replay a given fbs file to all incoming connections
## Usage:
recorder -recDir=./recording.rbs -targHost=192.168.0.100 -targPort=5903 -targPass=@@@@@
player -fbsFile=./myrec.fbs -tcpPort=5905
proxy -recDir=./recordings/ -targHost=192.168.0.100 -targPort=5903 -targPass=@@@@@ -tcpPort=5903 -vncPass=@!@!@!
### Code usage examples
* player/main.go (fbs recording vnc client)
   * Connects as client, records to FBS file

View File

@@ -2,7 +2,7 @@
sum="sha1sum"
# VERSION=`date -u +%Y%m%d`
VERSION="v1.01"
VERSION="v1.0"
LDFLAGS="-X main.VERSION=$VERSION -s -w"
GCFLAGS=""
@@ -24,8 +24,8 @@ fi
OSES=( linux darwin windows )
ARCHS=(amd64 386 )
OSES=(linux darwin windows freebsd)
ARCHS=(amd64 386)
for os in ${OSES[@]}; do
for arch in ${ARCHS[@]}; do
suffix=""

View File

@@ -17,8 +17,7 @@ const (
KeyEventMsgType
PointerEventMsgType
ClientCutTextMsgType
ClientFenceMsgType = 248
QEMUExtendedKeyEventMsgType = 255
ClientFenceMsgType = 248
)
// Color represents a single color in a color map.
@@ -48,8 +47,6 @@ func (cmt ClientMessageType) String() string {
return "FramebufferUpdateRequest"
case KeyEventMsgType:
return "KeyEvent"
case QEMUExtendedKeyEventMsgType:
return "QEMUExtendedKeyEvent"
case PointerEventMsgType:
return "PointerEvent"
case ClientCutTextMsgType:

View File

@@ -4,6 +4,7 @@ import (
"io"
"math"
"vncproxy/common"
"vncproxy/logger"
)
type EncCursorPseudo struct {
@@ -21,6 +22,8 @@ func (pe *EncCursorPseudo) Read(pf *common.PixelFormat, rect *common.Rectangle,
}
bytesPixel := int(pf.BPP / 8) //calcTightBytePerPixel(pf)
logger.Infof("EncCursorPseudo bytesPerPixel= %d", bytesPixel)
r.ReadBytes(int(rect.Width*rect.Height) * bytesPixel)
mask := ((rect.Width + 7) / 8) * rect.Height
r.ReadBytes(int(math.Floor(float64(mask))))

View File

@@ -155,7 +155,7 @@ func handleTightFilters(subencoding uint8, pixelFmt *common.PixelFormat, rect *c
if paletteSize == 2 {
dataLength = int(rect.Height) * ((int(rect.Width) + 7) / 8)
} else {
dataLength = int(rect.Width) * int(rect.Height)
dataLength = int(rect.Width * rect.Height)
}
_, err = r.ReadTightData(dataLength)
if err != nil {

View File

@@ -2,7 +2,7 @@ package logger
import "fmt"
var simpleLogger = SimpleLogger{LogLevelWarn}
var simpleLogger = SimpleLogger{LogLevelInfo}
type Logger interface {
Debug(v ...interface{})

View File

@@ -80,7 +80,7 @@ func main() {
os.Exit(1)
}
url := "http://0.0.0.0:" + *wsPort + "/"
url := "http://localhost:" + *wsPort + "/"
if *tcpPort != "" && *wsPort != "" {
logger.Infof("running two listeners: tcp port: %s, ws url: %s", *tcpPort, url)

View File

@@ -35,15 +35,15 @@ func main() {
if *recordDir == "" {
logger.Warn("FBS recording is turned off")
}
tcpUrl := ""
if *tcpPort != "" {
tcpUrl = ":" + string(*tcpPort)
}
proxy := &proxy.VncProxy{
WsListeningUrl: "http://0.0.0.0:" + string(*wsPort) + "/", // empty = not listening on ws
RecordingDir: *recordDir, //"/Users/amitbet/vncRec", // empty = no recording
WsListeningUrl: "http://localhost:" + string(*wsPort) + "/", // empty = not listening on ws
RecordingDir: *recordDir, //"/Users/amitbet/vncRec", // empty = no recording
TcpListeningUrl: tcpUrl,
ProxyVncPassword: *vncPass, //empty = no auth
SingleSession: &proxy.VncSession{

View File

@@ -6,15 +6,15 @@ func TestProxy(t *testing.T) {
//create default session if required
proxy := &VncProxy{
WsListeningUrl: "http://0.0.0.0:7778/", // empty = not listening on ws
RecordingDir: "d:\\", // empty = no recording
TcpListeningUrl: ":5904",
//RecordingDir: "C:\\vncRec", // empty = no recording
ProxyVncPassword: "1234", //empty = no auth
WsListeningUrl: "http://localhost:8183/", // empty = not listening on ws
RecordingDir: "", //"/Users/amitbet/vncRec", // empty = no recording
TcpListeningUrl: ":5905",
//recordingDir: "C:\\vncRec", // empty = no recording
ProxyVncPassword: "", //empty = no auth
SingleSession: &VncSession{
TargetHostname: "192.168.1.101",
TargetPort: "5901",
TargetPassword: "123456",
TargetPort: "5900",
TargetPassword: "ancient1", //"Ch_#!T@8", //
ID: "dummySession",
Status: SessionStatusInit,
Type: SessionTypeRecordingProxy,

View File

@@ -81,9 +81,9 @@ func main() {
encs := []common.IEncoding{
&encodings.TightEncoding{},
//&encodings.TightPngEncoding{},
//&encodings.RREEncoding{},
//&encodings.ZLibEncoding{},
//&encodings.ZRLEEncoding{},
//rre := encodings.RREEncoding{},
//zlib := encodings.ZLibEncoding{},
//zrle := encodings.ZRLEEncoding{},
//&encodings.CopyRectEncoding{},
//coRRE := encodings.CoRREEncoding{},
//hextile := encodings.HextileEncoding{},

View File

@@ -38,7 +38,7 @@ func NewRecorder(saveFilePath string) (*Recorder, error) {
rec.maxWriteSize = 65535
rec.writer, err = os.OpenFile(saveFilePath, os.O_RDWR|os.O_CREATE, 0644)
rec.writer, err = os.OpenFile(saveFilePath, os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
logger.Errorf("unable to open file: %s, error: %v", saveFilePath, err)
return nil, err

View File

@@ -165,36 +165,6 @@ func (msg *MsgKeyEvent) Write(c io.Writer) error {
return nil
}
// MsgKeyEvent holds the wire format message.
type MsgQEMUExtKeyEvent struct {
SubmessageType uint8 // submessage type
DownFlag uint16 // down-flag
KeySym Key // key symbol
KeyCode uint32 // scan code
}
func (*MsgQEMUExtKeyEvent) Type() common.ClientMessageType {
return common.QEMUExtendedKeyEventMsgType
}
func (*MsgQEMUExtKeyEvent) Read(c io.Reader) (common.ClientMessage, error) {
msg := MsgKeyEvent{}
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
return nil, err
}
return &msg, nil
}
func (msg *MsgQEMUExtKeyEvent) Write(c io.Writer) error {
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
return err
}
if err := binary.Write(c, binary.BigEndian, msg); err != nil {
return err
}
return nil
}
// PointerEventMessage holds the wire format message.
type MsgPointerEvent struct {
Mask uint8 // button-mask

View File

@@ -182,13 +182,59 @@ func (c *ServerConn) handle() error {
switch parsedMsg.Type() {
case common.SetPixelFormatMsgType:
// update pixel format
logger.Debugf("ClientUpdater.Consume: updating pixel format")
logger.Debugf("IServerConn.Handle: updating pixel format")
pixFmtMsg := parsedMsg.(*MsgSetPixelFormat)
c.SetPixelFormat(&pixFmtMsg.PF)
if pixFmtMsg.PF.TrueColor != 0 {
c.SetColorMap(&common.ColorMap{})
}
case common.FramebufferUpdateRequestMsgType:
//logger.Infof("IServerConn.Handle: msgBuff update request")
//updMsg := parsedMsg.(*MsgFramebufferUpdateRequest)
//updMsg.Inc = 1
case common.SetEncodingsMsgType:
encMsg := parsedMsg.(*MsgSetEncodings)
// for i, enc := range encMsg.Encodings {
// if enc > common.EncJPEGQualityLevelPseudo1 && enc < common.EncJPEGQualityLevelPseudo10 { //common.EncCursorPseudo
// //encMsg.EncNum--
// //encMsg.Encodings = append(encMsg.Encodings[:i], encMsg.Encodings[i+1:]...)
// encMsg.Encodings[i] = encMsg.Encodings[len(encMsg.Encodings)-1]
// encMsg.Encodings[len(encMsg.Encodings)-1] = common.EncJPEGQualityLevelPseudo9
// break
// }
// // if enc == common.EncCompressionLevel3 {
// // encMsg.Encodings[i] = common.EncJPEGQualityLevelPseudo9
// // }
// // if enc == common.EncJPEGQualityLevelPseudo7 {
// // encMsg.Encodings[i] = common.EncJPEGQualityLevelPseudo9
// // }
// }
encMsg.Encodings = []common.EncodingType{
common.EncDesktopSizePseudo,
common.EncExtendedDesktopSizePseudo,
common.EncLastRectPseudo,
common.EncContinuousUpdatesPseudo,
common.EncCursorPseudo,
common.EncFencePseudo,
common.EncHextile,
common.EncCopyRect,
common.EncTight,
common.EncZRLE,
common.EncRRE,
common.EncRaw,
common.EncCompressionLevel2,
common.EncJPEGQualityLevelPseudo1,
common.EncQEMUExtendedKeyEventPseudo,
common.EncTightPng,
common.EncXvpPseudo,
}
encMsg.EncNum = uint16(len(encMsg.Encodings))
//bad: EncCopyRect EncTight EncTightPng EncHextile EncRRE EncRaw EncJPEGQualityLevelPseudo7 EncCompressionLevel3 EncDesktopSizePseudo EncLastRectPseudo EncCursorPseudo EncQEMUExtendedKeyEventPseudo EncExtendedDesktopSizePseudo EncXvpPseudo EncFencePseudo EncContinuousUpdatesPseudo
}
////////
if err != nil {