package org.owasp.webgoat.lessons; import java.text.Format; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import org.apache.ecs.Element; import org.apache.ecs.ElementContainer; import org.apache.ecs.StringElement; import org.apache.ecs.html.B; import org.apache.ecs.html.BR; import org.apache.ecs.html.Center; import org.apache.ecs.html.H1; import org.apache.ecs.html.H3; import org.apache.ecs.html.HR; import org.apache.ecs.html.Input; import org.apache.ecs.html.TD; import org.apache.ecs.html.TH; import org.apache.ecs.html.TR; import org.apache.ecs.html.Table; import org.apache.ecs.html.TextArea; import org.owasp.webgoat.session.ECSFactory; import org.owasp.webgoat.session.WebSession; /*************************************************************************************************** * * * This file is part of WebGoat, an Open Web Application Security Project utility. For details, * please see http://www.owasp.org/ * * Copyright (c) 2002 - 2007 Bruce Mayhew * * This program is free software; you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program; if * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Getting Source ============== * * Source for this application is maintained at code.google.com, a repository for free software * projects. * * For details, please see http://code.google.com/p/webgoat/ * * @author Bruce Mayhew WebGoat * @created October 28, 2003 */ public class UncheckedEmail extends LessonAdapter { private final String YOUR_REAL_GMAIL_PASSWORD = "password"; private final String YOUR_REAL_GMAIL_ID = "GMail id"; private final static String MESSAGE = "msg"; private final static String HIDDEN_TO = "to"; private final static String SUBJECT = "subject"; private final static String GMAIL_ID = "gId"; private final static String GMAIL_PASS = "gPass"; private static final String SMTP_HOST_NAME = "smtp.gmail.com"; private static final String SMTP_PORT = "465"; private static final String emailFromAddress = "webgoat@owasp.org"; private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; /** * Description of the Method * * @param s * Description of the Parameter * @return Description of the Return Value */ protected Element createContent(WebSession s) { ElementContainer ec = new ElementContainer(); try { String to = s.getParser().getRawParameter(HIDDEN_TO, ""); String gId = s.getParser().getRawParameter(GMAIL_ID, ""); String gPass = s.getParser().getRawParameter(GMAIL_PASS, ""); String message = s.getParser().getRawParameter(MESSAGE, ""); String subject = s.getParser().getRawParameter(SUBJECT, ""); boolean haveCredentials = !(YOUR_REAL_GMAIL_ID.equals(gId) || YOUR_REAL_GMAIL_PASSWORD.equals(gPass)); ec.addElement(new HR()); createGoogleCredentials(s, ec); ec.addElement(new HR()); ec.addElement(new BR()); createMailMessage(s, subject, message, ec); ec.addElement(new HR()); if (to.length() > 0) { if (haveCredentials) { Message sentMessage = sendGoogleMail(to, subject, message, emailFromAddress, gId, gPass); formatMail(ec, sentMessage); } else { sendSimulatedMail(ec, to, subject, message); } } if(to.length() > 0 && "webgoat.admin@owasp.org".equals(to) && message.contains("