Sign in to follow this  
Followers 0
olivarra1

Remote control secuirity

2 posts in this topic

#1 ·  Posted (edited)

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 $deviceRatio = $DEVICE_SCREEN_WIDTH / $DEVICE_SCREEN_HEIGHT

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
EndFunc
Func getRegionHeight()
    Return $regionEndY - $regionStartY
EndFunc

_ScreenCapture_SetBMPFormat(0)

TCPStartup()

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

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

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

    $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
        EndIf
    EndIf

    $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
    EndIf
    $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)
    FileClose($oFile)

    SetError(0)
    TCPSend($cliSocket, String($size))
    TCPSend($cliSocket, $bin)
    If @error Then
        $error = True
    Else
        $error = False
    EndIf
WEnd



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
    _GDIPlus_Startup()

    ;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)
    Else
        $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($sInImage) ; This function is modified here, so we don't have to write the bmp to the hard disk
    EndIf

    ;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.
    Do
        $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_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _WinAPI_DeleteObject($hBMP)
    _GDIPlus_Shutdown()
EndFunc
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  
Followers 0