Jump to content
Sign in to follow this  
wraithdu

Remote Screen Capture via TCP

Recommended Posts

wraithdu

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

Share this post


Link to post
Share on other sites
SoulA

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

Share this post


Link to post
Share on other sites
wraithdu

Small updates to scripts. Thanks SoulA for the tips!

Share this post


Link to post
Share on other sites
MrBlue

thanks i'll check it out should be usefull also nice to find an open source community,

Share this post


Link to post
Share on other sites
rasim

@wraithdu

Nice scripts my friend! Thanks for sharing :)

Edited by rasim

Share this post


Link to post
Share on other sites
wraithdu

Thanks! Actually I've got a better version sitting around that uses pre-shared keyfile authentication for the initial connection, then RC4 encryption and MD5 checksumming for the actual file transfer. I'll post it up when I get home.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.