forked from scVENUS/PeekabooAV-Installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkFileWithPeekaboo.py
executable file
·96 lines (79 loc) · 2.33 KB
/
checkFileWithPeekaboo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# this script will cause an error if no MTA listens on 10025
# run the following command to have one (this is also a valid bash script)
# bash checkFileWithPeekaboo.py
a="$(python -m smtpd -n -c DebuggingServer 0.0.0.0:10025 >&2)"
b="$(kill $$)"
import smtplib
import socket
from sys import argv
import pwd
import os
from os.path import basename
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
def send_mail(send_from, send_to, subject, text, files=None,
server="127.0.0.1", port="25"):
assert isinstance(send_to, list)
msg = MIMEMultipart()
msg['From'] = send_from
msg['To'] = COMMASPACE.join(send_to)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.attach(MIMEText(text))
for f in files or []:
with open(f, "rb") as fil:
part = MIMEApplication(
fil.read(),
Name=basename(f)
)
# After the file is closed
part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
msg.attach(part)
#print msg.as_string()
# s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#
# s.connect((server, port))
# data = s.recv(1024)
# print data
#
# print "HELO %s" % host
# s.sendall("HELO %s" % host)
# data = s.recv(1024)
# print(data)
#
# print "MAIL FROM: <%s>" % send_from
# s.sendall("MAIL FROM: <%s>" % send_from)
# data = s.recv(1024)
# print(data)
#
# print "RCPT TO: <%s>" % send_to
# s.sendall("RCPT TO: <%s>" % send_to)
# data = s.recv(1024)
# print(data)
#
# print "DATA"
# s.sendall("DATA")
# data = s.recv(1024)
# print(data)
#
# s.sendall(msg.as_string())
# while 1:
# data = s.recv(1024)
# print(data)
# if not data: break
# s.senall(".")
# s.close()
smtp = smtplib.SMTP(server,port)
smtp.sendmail(send_from, send_to, msg.as_string())
smtp.close()
user=pwd.getpwuid(os.getuid()).pw_name
host=socket.gethostname()
send_mail("%s@%s" % (user, host),
["scan@peekaboohost"],
"Check this for me pls",
"Are the attached files malicious?",
# argv[1:], "192.168.56.5", 10024)
argv[1:], "127.0.0.1", 10024)