+ * Copyright (c) 2002 - 20014 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 https://github.com/WebGoat/WebGoat, a repository for free software + * projects. + *
+ * + * @author nbaars + * @version $Id: $Id + * @since November 17, 2016 + */ +public class ContentTypeAssignment extends Assignment { + + @Override + public String getPath() { + return "XXE/content-type"; + } + + @RequestMapping(method = RequestMethod.POST, consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody + public AttackResult createNewUser(@RequestBody String userInfo, @RequestHeader("Content-Type") String contentType) throws Exception { + User user = new User(); + AttackResult attackResult = AttackResult.failed("Try again!"); + if (MediaType.APPLICATION_JSON_VALUE.equals(contentType)) { + user = parseJson(userInfo); + attackResult = AttackResult.failed("You are posting JSON which does not work with a XXE"); + } + if (MediaType.APPLICATION_XML_VALUE.equals(contentType)) { + user = parseXml(userInfo); + attackResult = AttackResult.failed("You are posting XML but there is no XXE attack performed"); + } + + if (checkSolution(user)) { + attackResult = AttackResult.success(String.format("Welcome %s", user.getUsername())); + } + return attackResult; + } + + private User parseJson(String userInfo) { + ObjectMapper mapper = new ObjectMapper(); + try { + return mapper.readValue(userInfo, User.class); + } catch (IOException e) { + return new User(); + } + } + +} diff --git a/webgoat-lessons/xxe/src/main/java/org/owasp/webgoat/plugin/SimpleXXE.java b/webgoat-lessons/xxe/src/main/java/org/owasp/webgoat/plugin/SimpleXXE.java new file mode 100644 index 000000000..06b3eb1f0 --- /dev/null +++ b/webgoat-lessons/xxe/src/main/java/org/owasp/webgoat/plugin/SimpleXXE.java @@ -0,0 +1,89 @@ +package org.owasp.webgoat.plugin; + +import org.apache.commons.exec.OS; +import org.owasp.webgoat.lessons.Assignment; +import org.owasp.webgoat.lessons.model.AttackResult; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; +import java.io.StringReader; + +/** + * ************************************************************************************************ + * This file is part of WebGoat, an Open Web Application Security Project utility. For details, + * please see http://www.owasp.org/ + *
+ * Copyright (c) 2002 - 20014 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 https://github.com/WebGoat/WebGoat, a repository for free software + * projects. + *
+ * + * @author nbaars + * @version $Id: $Id + * @since November 17, 2016 + */ +public class SimpleXXE extends Assignment { + + private final static String[] DEFAULT_LINUX_DIRECTORIES = {"usr", "opt", "var"}; + private final static String[] DEFAULT_WINDOWS_DIRECTORIES = {"Windows", "Program Files (x86)", "Program Files"}; + + @Override + public String getPath() { + return "XXE/simple"; + } + + @RequestMapping(method = RequestMethod.POST, consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody + public AttackResult createNewUser(@RequestBody String userInfo) throws Exception { + User user = parseXml(userInfo); + if (checkSolution(user)) { + return AttackResult.success(String.format("Welcome %s", user.getUsername())); + } + return AttackResult.failed("Try again!"); + } + + public static User parseXml(String xml) throws Exception { + JAXBContext jc = JAXBContext.newInstance(User.class); + + XMLInputFactory xif = XMLInputFactory.newFactory(); + xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, true); + xif.setProperty(XMLInputFactory.SUPPORT_DTD, true); + XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xml)); + + Unmarshaller unmarshaller = jc.createUnmarshaller(); + return (User) unmarshaller.unmarshal(xsr); + } + + public static boolean checkSolution(User userInfo) { + String[] directoriesToCheck = OS.isFamilyUnix() ? DEFAULT_LINUX_DIRECTORIES : DEFAULT_WINDOWS_DIRECTORIES; + boolean success = true; + for (String directory : directoriesToCheck) { + success &= userInfo.getUsername().contains(directory); + } + return success; + } + + +} diff --git a/webgoat-lessons/xxe/src/main/java/org/owasp/webgoat/plugin/User.java b/webgoat-lessons/xxe/src/main/java/org/owasp/webgoat/plugin/User.java new file mode 100644 index 000000000..d6d1dcdee --- /dev/null +++ b/webgoat-lessons/xxe/src/main/java/org/owasp/webgoat/plugin/User.java @@ -0,0 +1,65 @@ +package org.owasp.webgoat.plugin; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * ************************************************************************************************ + * This file is part of WebGoat, an Open Web Application Security Project utility. For details, + * please see http://www.owasp.org/ + *
+ * Copyright (c) 2002 - 20014 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 https://github.com/WebGoat/WebGoat, a repository for free software + * projects. + *
+ * + * @author nbaars + * @version $Id: $Id + * @since November 17, 2016 + */ +@XmlRootElement +public class User { + + private String username = ""; + private String password = ""; + private String email = ""; + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + +} diff --git a/webgoat-lessons/xxe/src/main/java/org/owasp/webgoat/plugin/XXE.java b/webgoat-lessons/xxe/src/main/java/org/owasp/webgoat/plugin/XXE.java new file mode 100644 index 000000000..e8afa5410 --- /dev/null +++ b/webgoat-lessons/xxe/src/main/java/org/owasp/webgoat/plugin/XXE.java @@ -0,0 +1,69 @@ +package org.owasp.webgoat.plugin; + +import org.owasp.webgoat.lessons.Category; +import org.owasp.webgoat.lessons.NewLesson; + +import java.util.ArrayList; +import java.util.List; + +/** + * ************************************************************************************************ + * This file is part of WebGoat, an Open Web Application Security Project utility. For details, + * please see http://www.owasp.org/ + *
+ * Copyright (c) 2002 - 20014 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 https://github.com/WebGoat/WebGoat, a repository for free software + * projects. + *
+ *
+ * @author nbaars
+ * @version $Id: $Id
+ * @since November 17, 2016
+ */
+public class XXE extends NewLesson {
+
+ @Override
+ public Category getDefaultCategory() {
+ return Category.INJECTION;
+ }
+
+ @Override
+ public List Concept / Topic To Teach:
+How the attacks works:
+
+
+
+
+ Username
+
+
+
+ E-mail
+
+
+
+ Password
+
+
+
+
+
+
+ By signing up you agree to WebGoat's Terms of Service.
+
+
+