Jump to content
Sign in to follow this  

Remote control secuirity

Recommended Posts


Hi, I'm developing my own remote control server for windows.

If it works, it should be able to let any device [let it be Computers, Tablets or Smartphones (if the screen is too small, it's unpractical)] to access the computer that holds the server and be able to see what's on the screen, click wherever he wants, and send any text.

To zoom to a certain area, the client will be able to set de top, bottom, left and right borders of the region that he wants to see, and the server will zoom to that part and send it to the device.

But there are some problems:

1. I'm using JPG compression to send the screenshot to the client. I don't know if this will be enough for the bandwidth of a normal homemade connection.

2. Here comes the security part... If i set up a server that lets to do such things, then anyone can connect to my IP to that port, and fully control my computer [with those features, he can even delete all of my data] and i obviously don't want it. Then i thought: OK lets put a password you have to send everytime you log in. But let me be paranoid, and what if that evil hacker has put a packet sniffer between my device and my computer? he will get the password and he will be able to access it again.

Then i think that putting a password may be worth, because at least not everyone will be able to access my computer, but hackers with some level of evil-hacking.

Is there any solution to that? I don't want to implement a Public-Key security, since it would take too much to develop and makes the connection substantialy slower.

I put the code i have here:

#include <GDIPlus.au3>
#include <ScreenCapture.au3>

Const $DEVICE_SCREEN_WIDTH = 480 ; 800
Const $DEVICE_SCREEN_HEIGHT = 770 ; 800 ; 480

Const $CLIC = "1"
Const $DOWN = "2"
Const $UP = "3"
Const $RIGHT = "4"
Const $LEFT = "5"

Global $regionStartX = 0
Global $regionStartY = 0
Global $regionEndX = $regionStartX + 1600
Global $regionEndY = $regionStartY + 900

Func getRegionWidth()
    Return $regionEndX - $regionStartX
Func getRegionHeight()
    Return $regionEndY - $regionStartY



Dim $srvSocket, $cliSocket
$srvSocket = TCPListen("", 1045) ; Localhost connection
;$srvSocket = TCPListen("", 1045) ; LAN connection
If $srvSocket == -1 Then
    MsgBox(0, "", "can't setup server socket: " & @error)

#cs $regionStartX = 562
$regionStartY = 410
$regionEndX = 914
$regionEndY = 853

Dim $error = True
Dim $ratio = 0
While 1
    If $error Then
            $cliSocket = TCPAccept($srvSocket)
        Until $cliSocket <> -1

    $str = TCPRecv($cliSocket, 1)
    If $str <> "" Then
        If $str == $CLIC Then
            $str = TCPRecv($cliSocket, 10)
            $str = StringSplit($str, ",", 2)
            $x = $str[0]
            $y = $str[1]
            MouseClick("primary", $x / $ratio + $regionStartX, $y / $ratio + $regionStartY, 1, 0)
        ElseIf $str == $DOWN Then
            $str = TCPRecv($cliSocket, 10)
            $val = Int($str)
            $regionEndY = $regionEndY + $val
        ElseIf $str == $UP Then
            $str = TCPRecv($cliSocket, 10)
            $val = Int($str)
            $regionStartY = $regionStartY + $val
        ElseIf $str == $RIGHT Then
            $str = TCPRecv($cliSocket, 10)
            $val = Int($str)
            $regionEndX = $regionEndX + $val
        ElseIf $str == $LEFT Then
            $str = TCPRecv($cliSocket, 10)
            $val = Int($str)
            $regionStartX = $regionStartX + $val
        ElseIf $str = "<" Then
            ; Policy file request from outside-localhost flash player clients - not yet implemented

    $w = getRegionWidth()
    $h = getRegionHeight()
    $regionRatio = $w / $h

    If ($deviceRatio > 1 And $regionRatio > 1) Or ($deviceRatio < 1 And $regionRatio < 1) Then ; The device won't flip the image
        $ratio = $DEVICE_SCREEN_WIDTH / $w
        if $ratio * $h > $DEVICE_SCREEN_HEIGHT Then $ratio = $DEVICE_SCREEN_HEIGHT / $h
    Else ; The device will flip the image
        $ratio = $DEVICE_SCREEN_WIDTH / $h
        if $ratio * $w > $DEVICE_SCREEN_HEIGHT Then $ratio = $DEVICE_SCREEN_HEIGHT / $w
    $deviceW = $w * $ratio
    $deviceH = $h * $ratio

    ;_ScreenCapture_Capture(@ScriptDir & "\tmp.bmp", $regionStartX, $regionStartY, $regionEndX, $regionEndY) ; This is slow version
    ;_ImageResize(@ScriptDir & "\tmp.bmp", @ScriptDir & "\tmp.jpg", $deviceW, $deviceH)
    $img = _ScreenCapture_Capture("", $regionStartX, $regionStartY, $regionEndX, $regionEndY) ; This is optimized version
    _ImageResize($img, @ScriptDir & "\tmp.jpg", $deviceW, $deviceH)

    $size = FileGetSize(@ScriptDir & "\tmp.jpg")
    $oFile = FileOpen(@ScriptDir & "\tmp.jpg", 0)
    $bin = FileRead($oFile)

    TCPSend($cliSocket, String($size))
    TCPSend($cliSocket, $bin)
    If @error Then
        $error = True
        $error = False

Func _ImageResize($sInImage, $sOutImage, $iW, $iH)
    Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0

    ;OutFile path, to use later on.
    Local $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))

    ;OutFile name, to use later on.
    Local $sOF = StringMid($sOutImage, StringInStr($sOutImage, "\", 0, -1) + 1)

    ;OutFile extension , to use for the encoder later on.
    Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1))

    ; Win api to create blank bitmap at the width and height to put your resized image on.
    $hWnd = _WinAPI_GetDesktopWindow()
    $hDC = _WinAPI_GetDC($hWnd)
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH)
    _WinAPI_ReleaseDC($hWnd, $hDC)

    ;Start GDIPlus

    ;Get the handle of blank bitmap you created above as an image
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP)

    ;Load the image you want to resize.
    If IsString($sInImage) Then
        $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)
        $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($sInImage) ; This function is modified here, so we don't have to write the bmp to the hard disk

    ;Get the graphic context of the blank bitmap
    $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1)

    ;Draw the loaded image onto the blank bitmap at the size you want
    _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)

    ;Get the encoder of to save the resized image in the format you want.
    $CLSID = _GDIPlus_EncodersGetCLSID($Ext)

    ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image.
        $i += 1
    Until (Not FileExists($sOP & $i & "_" & $sOF))

    ;Prefix the number to the begining of the output filename
    ;$sOutImage = $sOP & $i & "_" & $sOF
    $sOutImage = $sOP & $sOF

    ;Save the new resized image.
    _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID)

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_GraphicsDispose ($hGraphic)
Edited by olivarra1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this