Jump to content

Remote Screen Capture via TCP


wraithdu
 Share

Recommended Posts

I was curious after seeing another example for using TCP to remotely set a computer's volume. I wanted to try sending files as well, and this is what I came up with. The server will take a screencap and send it to the client. Current settings allow it to run on one computer, for testing purposes. Modify the IP addresses for your needs. It could easily be extended to send / receive any kind of file, like a remote file retrieval system. Two parts, server and client.

UPDATE - Small, added ability for the server to send the cap back to the client by determining the connected IP address (I had to fix the SocketToIp() function from the helpfile first). Also added a timeout to the client so in case the capture connection fails, it won't sit in a loop forever.

UPDATE2 - Optimized the file read / send / write based off SoulA's implementation. Thanks!

UPDATE3 - Totally rewritten. Now it reuses the same connection for all sending and receiving, so SocketToIp() is not needed. Also uses pre-shared keys for RC4 encryption and authentication, and MD5 to check the received data's integrity. Thanks to Ward for the RC4 and MD5 functions. Place a file called "tcp_key.bin" in the same directory as the scripts as the pre-shared key. You can use any file, but I'd suggest something not too big. My test key was 1024 bytes (1 K) created with OpenSSL as random data.

TCP_with_MD5_Screencap_client.au3

TCP_with_MD5_Screencap_server.au3

Edited by wraithdu
Link to comment
Share on other sites

Interesting approach yet simple code I like it. Might take some concepts for myself.

Here is a UDF that I wrote for sending and receiving files. I made it for a RAT program I am working on and I also use it to transfer screen captures. I think it works pretty well. Just to note the sendPacket() function is just sending a packet with error checking so replacing it with TCPSend() would work just the same.

Func sendFile($file, $delete = 0)
    $FileOpen = FileOpen($file, 16)                 ;open in binary
    $FileSize = FileGetSize($file)
    $BytesSent = 0
    sendPacket(String($FileSize))                   ;send hte file size initially so other program and do progress bars and such
    sleep(100)
    
    While $BytesSent < $FileSize                    ;control to stop the loop and stop sending
        $ReadFile = FileRead($FileOpen, 4096)
        $BytesSent += TCPSend($socket, $ReadFile)   ;adds bytes to know when to stop the loop
        If @error Then 
            FileClose($FileOpen)
            If $delete = 1 Then FileDelete($file)
            connFail()
        EndIf
        sleep(20) ;allows other computer time to write to file can be adjusted accordingly
    WEnd
    sleep(20)
    sendPacket("Transfer Complete")                 ;lets other computer know we are done sending
    FileClose($FileOpen)
    If $delete = 1 Then FileDelete($file)
    $timeout = TimerInit() ;resets global time
EndFunc

Func getFile($file, $delete = 0)
    Local $time = 0
    $file = FileOpen($file, 18)                 ;open in binary
    
    $time = TimerInit()                         ;starst a timeout timer  so we aren't trying to send forever
    Do
        $recv = TCPRecv($socket, 17520)
        $dif = TimerDiff($time)
        If $dif >= 60000 Then                   ;one minute
            If $delete = 1 Then                 ;deletes the file if connection fails
                FileClose($file)
                FileDelete($file)
            EndIf
        connFail() ;timeout UDF to kill the application and close GUIS
        EndIf
        sleep(1)
        If $recv <> "Transfer Complete" Then FileWrite($file, $recv)
    Until $recv = "Transfer Complete"
    FileClose($file)
    $timeout = TimerInit() ;resets global time
EndFunc
Edited by SoulA
Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...
  • 2 weeks later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...