screen logger

A place to submit all custom code, scripts, and programs.
Forum rules
Do NOT post malicious code or programs. Please review all code posted in this forum before downloading or running any of the code or programs here.

screen logger

Post by pretentious on Mon May 18, 2015 7:15 am
([msg=88093]see screen logger[/msg])

So I pull a lot of little chunks of code out of my ass of a pretty regular basis but seldom really invest my time to getting something done that I'd really want to share with the world. This is kind of an exception to that. (stayed up till 5am coding then woke up again at 12 to resume. That means I'm on to something 8-) )

It takes inspiration from a previous program that I've written
Code: Select all
#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main(){
    int x = 683, y = 384;
FILE *input = fopen("/dev/input/mouse0","r");
FILE *log = fopen("/var/log/mouse_log", "a");
signed char char_num;
signed char protocol[3];
    while(input){// tests to see if file exists
        for(char_num = 0; char_num <3; char_num++){
            protocol[char_num] = fgetc(input);
        }
        x+=protocol[1];
        if(x >1366)x = 1366;
        if(x < 0)x = 0;
        y-=protocol[2];
        if(y > 768)y = 768;
        if(y < 0)y = 0;
        // I'm still not entirely sure how to decode the mouse buttons but in the future it will likely be easier to user numbers than words anyway
        // assuming protocol -1 when device is unplugged
        while(protocol[0] == -1){
            sleep(1);
            input = fopen("/dev/input/mouse0","r");
            if(input)
                break;
        }
    if(protocol[0] != -1)
        fprintf(log, "%d %d %d %d\n", (int)time(NULL), protocol[0], x, y);       
    }
    fclose(input);
    fclose(log);
}

This pulls mouse movement data in almost real time from the mouse device, decodes it and puts it into machine readable data points. I compiled it as 'mouse_log_no_args' because I wanted to remind myself that it didn't take arguements :P It needs to be run with root privileges.
I've already uploaded this, so nothing new here. The following is my addition to it
Code: Select all
from PIL import Image, ImageDraw
import sys
import time
import os
import commands
import logging
buffer = 15 # snapshots taken at 15 seconsd intervals
motionblur = buffer * 4 # number of previous snapshots mouse movements to hold

log = logging.getLogger()
logging.basicConfig()
log.setLevel(logging.ERROR)

def __main__():
    # open last timestamp
    try: #try to read last temp stamp
        last = open("time","r")
        tempstamp = int(last.read())
    except: # on fail assing it 1
        tempstamp = 1
    finally: # open file to keep track of new tempstamp
        last = open("time","w")

    log.info(str(tempstamp) + " read in")

    while True:
        time.sleep(buffer)
        # process previous picture from tempstamp
        try:
            background = Image.open("/home/stu/desktop/images/{}.png".format(tempstamp)) # open last image
            img = Image.new('RGBA', (1366, 768), (255, 255, 255, 0))
            log.info("{} opened for editing".format(tempstamp))
            pixdata = img.load()
            draw = ImageDraw.Draw(img)
            os.system('tail /var/log/mouse_log -n 10000 > /var/log/temp_mouse_log')
            mousedata = open('/var/log/temp_mouse_log','r') # mouse data file, ensure that mouse_log_no_args is running
            x1 = -1
            y1 = -1
            for line in mousedata.readlines():
                formatted = line.split()
                if len(formatted) != 4:
                    continue
                if int(formatted[0]) in range(int(tempstamp-motionblur),int(tempstamp+buffer)): #checking if timestamp is within buffer boundary
                    if x1 == -1 or y1 == -1:
                        x1 = int(formatted[2])
                        y1 = int(formatted[3])
                        log.debug('X1 initial value ' + str(x1))
                        continue
                    x2 = int(formatted[2])
                    y2 = int(formatted[3])
                    # making previous lines grey and recent ones black
                    #check if left mouse button was clicked
                    if int(formatted[1]) == 9:
                        draw.ellipse((x2-4, y2-5, x2+5, y2+5), fill=(255,100,100,128))
                    elif int(formatted[1]) == 10:
                        draw.ellipse((x2-5, y2-5, x2+5, y2+5), fill=(100,100,255,128))
                    elif int(formatted[1]) == 12:
                        draw.ellipse((x2-5, y2-5, x2+5, y2+5), fill=(100,255,100,128))
                    if int(formatted[0]) in range(int(tempstamp-motionblur), int(tempstamp)):
                        draw.line((x1,y1,x2,y2),fill=(0,0,0,128), width=3)
                    else:                   
                        draw.line((x1,y1,x2,y2),fill=(0,0,0,250), width=3)
                    x1 = x2
                    y1 = y2
            background.paste(img,(0,0), img)
            background.save("/home/stu/desktop/images/{}.png".format(tempstamp))
            log.info("edit saved as " +str(tempstamp)+".png")
        except Exception,e: log.error(str(e))

        timestamp = int(time.time())
        if timestamp in range(tempstamp + buffer-1,tempstamp + buffer+2): # tests for timestamp in +- 1 from 5 seconds from last screen shot
            os.system("scrot /home/stu/desktop/images/{}.png".format(timestamp))
            tempstamp = timestamp
        else:
            os.system("cp /home/stu/desktop/blank.png /home/stu/desktop/images/{}.png".format(timestamp))
            log.debug("timestamp: "+str(timestamp))
            log.debug("tempstamp: "+str(tempstamp))
            tempstamp = timestamp
        # finally persist timestamp
        last.seek(0)
        last.write(str(timestamp))
        #check if enough pictures have accumulated
        if getscreencount() >= 720:
            export()

def getscreencount(): # returns the number of files in the images folder
    images = commands.getoutput('ls /home/stu/desktop/images/')
    return len(images.split())
def export(): # renames the files in images to consecutive integers, exports a video file to videos and deletes images
    log.info('exporting video')
    images = commands.getoutput('ls /home/stu/desktop/images/')
    imagelist = images.split()
    name = imagelist[0][:10]
    count = 1
    for image in imagelist:
        os.system('mv /home/stu/desktop/images/{}'.format(image) + ' /home/stu/desktop/images/{}.png'.format(count))
        count += 1
    os.system('ffmpeg -i /home/stu/desktop/images/%d.png -vcodec mpeg4 /home/stu/desktop/videos/{}.mp4'.format(name)) # was.avi
    count -=1
    while count > 0:
        os.system('rm /home/stu/desktop/images/{}.png'.format(count))
        count -=1

__main__()

This code takes screen shots at 15 second intervals, puts them into a folder, then overlays them with the mouse movements at that time. Then when enough frames have accumulated, The script will export that frames into a video timelapse of your computer.
You need to have scrot installed and ffmpeg though I think ffmpeg is there by default.
the directory structure is
Code: Select all
blank.png  images  script.py  time  videos

you have a temp file called time to keep track of breaks in the script, blank.png which gives a break in the feed, videos which keeps the exported time lapses and images which keeps the frames.
There is also the mouse_log file being written into my the mouse logger as root.
The code seems stable, though pretty inefficient :D (added a tail command when my mouse_logger became >1.5m because of the delay causing the script to stutter) and I'm still testing it and playing with variables. But yeah, let me know what you think.

Once I get the constant variables figured out, I'll work on the efficiency and probably change the colour of the lines relative to specific mouse actions.
Last edited by pretentious on Sun Jun 07, 2015 3:30 am, edited 2 times in total.
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
Can you say brainwashing It's a non stop disco
User avatar
pretentious
Addict
Addict
 
Posts: 1203
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)


Re: screen logger

Post by Turn on Mon May 18, 2015 3:44 pm
([msg=88097]see Re: screen logger[/msg])

This is actually pretty good work, awesome! You just inspired me to create more useful things.
Social Engineering:
<cen> .lua print ('Tsyn 9.47.-u 3 12 5')
* slickery has quit (User has been banned from HackThisSite (Attempting to use a SpyBot))
* cen has quit (User has been banned from HackThisSite (Attempting to use a SpyBot))
User avatar
Turn
Poster
Poster
 
Posts: 120
Joined: Tue Feb 17, 2015 5:42 am
Blog: View Blog (0)


Re: screen logger

Post by tremor77 on Tue May 19, 2015 2:15 am
([msg=88111]see Re: screen logger[/msg])

Nice... what I'd like to get my hands on along this line.. is a javascript version of this using the WebGL screen scraping exploit.. I know it exists I've seen a POC. Basically, a web app or game that leverages WebGL, can essentially get your entire screen even if you are not in the window or tab that the app is running in. Yes you read me correctly, javascript can capture your entire video signal right off the graphics card...
Image
User avatar
tremor77
Addict
Addict
 
Posts: 1097
Joined: Wed Mar 31, 2010 12:00 pm
Location: New York
Blog: View Blog (0)


Re: screen logger

Post by pretentious on Wed May 20, 2015 5:56 am
([msg=88123]see Re: screen logger[/msg])

Edited the code, fixed 2 bugs, some some rough edges still.
tremor77 wrote:Yes you read me correctly, javascript can capture your entire video signal right off the graphics card...

I'm a fan of technologies that can just outright override shit :) There is too much adherance to 'best practices' :lol: #sudoeverything
I really want to like javascript, I see it becoming more and more relivant. It just doesn't feel like a language I want to invest in. I'll learn it, but it will be a chore :|
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
Can you say brainwashing It's a non stop disco
User avatar
pretentious
Addict
Addict
 
Posts: 1203
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)


Re: screen logger

Post by liz4rdm4n on Sun May 24, 2015 8:29 pm
([msg=88166]see Re: screen logger[/msg])

Out of the languages I've dabbled with, JavaScript is my favourite. Give it time and it will no longer be a chore.
User avatar
liz4rdm4n
Experienced User
Experienced User
 
Posts: 66
Joined: Wed Feb 11, 2015 6:27 pm
Blog: View Blog (0)


Re: screen logger

Post by pretentious on Sun Jun 07, 2015 3:38 am
([msg=88381]see Re: screen logger[/msg])

One last edit to the script which adds mouse actions
Also
Code: Select all
#!/bin/bash
cd /home/stu/desktop/videos/
mencoder -ovc copy -oac copy -o /home/stu/desktop/`date +%Y-%m-%d`_24hours.avi `ls | tail -n 8`

a separate script to export a 24 hour timelapse of your computer usage.
This was an interesting experiement. I realized that while I have some moments that look super cool with text, window multi tasking and mouse patterns flashing on the screen, there is a huge amount of idle time. Pretty cool when you have http://www.ustream.tv/channel/iss-hdev-payload open but for the most part, I realize that I'm only really productive for a short amount of time :?
liz4rdm4n wrote:Out of the languages I've dabbled with, JavaScript is my favourite. Give it time and it will no longer be a chore.

I'll buy into it, Being an amature developer, I probably don't have much choice. I hope it will grow on me :)
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
Can you say brainwashing It's a non stop disco
User avatar
pretentious
Addict
Addict
 
Posts: 1203
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)


Re: screen logger

Post by MadM0use on Thu Jun 11, 2015 7:58 pm
([msg=88469]see Re: screen logger[/msg])

cool stuff bro :D loving it
const char main[]="\xeb\xfe -> A fully functional program in C";

<@MadMouse> i am forgot what i was doing today but i had motivation and a distinct plan when i woke up stoned right now

http://pastebin.com/FnwUG5KS
Books:
http://goo.gl/muPm3d
User avatar
MadM0use
Experienced User
Experienced User
 
Posts: 70
Joined: Thu Sep 11, 2014 10:30 pm
Blog: View Blog (0)



Return to Custom Code

Who is online

Users browsing this forum: No registered users and 0 guests