天学习了如何用Java[1] 发送普通邮件,HTML邮件和带附件的邮件。黑客最喜欢干的事情就是发钓鱼邮件,安全砖家还为其美名叫鱼叉攻击,啧啧。
ailx10:网络安全优秀回答者,网络安全硕士
发送一封简单的QQ邮件:
package hackbiji;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
public class hello {
public static void main(String[] args) {
String to="792161993@qq.com";
String from="393803933@qq.com";
String host="smtp.qq.com";
Properties properties=System.getProperties();
properties.setProperty("mail.smtp.host",host);
properties.put("mail.smtp.auth","true");
Session session=Session.getDefaultInstance(properties, new Authenticator() {
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("393803933","***********");
}
});
try {
MimeMessage mimeMessage=new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress(from));
mimeMessage.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
mimeMessage.setSubject("主题:黑客笔记");
mimeMessage.setText("正文:我是ailx10,我喜欢2进制安全和渗透技术");
Transport.send(mimeMessage);
System.out.println("发送邮件成功");
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
发送一封HTML QQ邮件:
package hackbiji;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
public class hello {
public static void main(String[] args) {
String to="792161993@qq.com";
String from="393803933@qq.com";
String host="smtp.qq.com";
Properties properties=System.getProperties();
properties.setProperty("mail.smtp.host",host);
properties.put("mail.smtp.auth","true");
Session session=Session.getDefaultInstance(properties, new Authenticator() {
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("393803933@qq.com","************");
}
});
try {
MimeMessage mimeMessage=new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress(from));
mimeMessage.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
mimeMessage.setSubject("主题:黑客笔记");
mimeMessage.setContent("<img src=\"http://hackbiji.top/images/avatar.jpg\" width=\"50\" height=\"50\" />","text/html");
Transport.send(mimeMessage);
System.out.println("发送邮件成功");
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
发送一封带附件的QQ邮件
package hackbiji;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.util.Properties;
public class hello {
public static void main(String[] args) {
String to="792161993@qq.com";
String from="393803933@qq.com";
String host="smtp.qq.com";
Properties properties=System.getProperties();
properties.setProperty("mail.smtp.host",host);
properties.put("mail.smtp.auth","true");
Session session=Session.getDefaultInstance(properties, new Authenticator() {
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("393803933@qq.com","***********");
}
});
try {
MimeMessage mimeMessage=new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress(from));
mimeMessage.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
mimeMessage.setSubject("主题:黑客笔记");
MimeBodyPart msgBodyPart=new MimeBodyPart();
msgBodyPart.setText("正文:我是ailx10");
MimeMultipart mimeMultipart=new MimeMultipart();
mimeMultipart.addBodyPart(msgBodyPart);
msgBodyPart=new MimeBodyPart();
String filepath="C:\\Users\\Admin\\IdeaProjects\\helloworld\\src\\src\\main\\java\\hackbiji\\hack.zip";
String filename="hack.zip";
FileDataSource fileDataSource=new FileDataSource(filepath);
msgBodyPart.setDataHandler(new DataHandler(fileDataSource));
msgBodyPart.setFileName(filename);
mimeMultipart.addBodyPart(msgBodyPart);
mimeMessage.setContent(mimeMultipart);
Transport.send(mimeMessage);
System.out.println("发送邮件成功");
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
Python中,可以使用smtplib库和email库来发送邮件。以下是一个基本的示例,展示如何使用这些库来发送一封简单的邮件。
smtplib和email是Python的标准库,通常不需要单独安装。但是,如果你使用的是一个精简的Python环境,可能需要确保这些库是可用的。
Python
1import smtplib
2from email.mime.text import MIMEText
3from email.header import Header
4
5# 发件人邮箱
6sender='your_email@example.com'
7# 收件人邮箱
8receiver='receiver_email@example.com'
9# 发送邮件的SMTP服务器
10smtp_server='smtp.example.com'
11# 发件人的邮箱密码或授权码
12password='your_password'
13
14# 邮件内容
15mail_content='这是邮件的正文内容。'
16# 邮件主题
17mail_subject='邮件的主题'
18
19# 创建一个MIMEText对象
20message=MIMEText(mail_content, 'plain', 'utf-8')
21message['From']=Header("发件人名称", 'utf-8')
22message['To']=Header("收件人名称", 'utf-8')
23message['Subject']=Header(mail_subject, 'utf-8')
24
25try:
26 # 连接SMTP服务器
27 smtpObj=smtplib.SMTP(smtp_server, 587)
28 # 开启TLS加密(某些服务器需要)
29 smtpObj.starttls()
30 # 登录SMTP服务器
31 smtpObj.login(sender, password)
32 # 发送邮件
33 smtpObj.sendmail(sender, receiver, message.as_string())
34 print("邮件发送成功!")
35except smtplib.SMTPException as e:
36 print("Error: 无法发送邮件,错误信息:", e)
37finally:
38 # 关闭连接
39 smtpObj.quit()
通过调整上述代码中的SMTP服务器、端口、用户名、密码以及邮件内容和接收者,你可以根据自己的需求发送邮件。
到一个比较有意思的网站,资源不少,在富文本框中直接复制了html,现在想把这些html中的附件下载到自己的服务器上,首先需要分析一下html把这些软件的src找出来
// <summary>
/// 获取字符串中SRC集合
/// </summary>
/// <param name="content">字符串</param>
/// <returns></returns>
public List<string> GetALLSRC(string content)
{
Regex rg=new Regex("src=\"([^\"]+)\"", RegexOptions.IgnoreCase);
var img=rg.Match(content);
List<string> imgUrl=new List<string>();
while (img.Success)
{
imgUrl.Add(img.Groups[1].Value);
img=img.NextMatch();
}
return imgUrl;
}
*请认真填写需求信息,我们会在24小时内与您取得联系。