//TODO should be random generated when starting the server String PASSWORD = "!!webgoat_admin_1234!!"; String PASSWORD_TOM = "thisisasecretfortomonly"; String ADMIN_PASSWORD_LINK = "375afe1104f4a487a73823c50a9292a2"; }
@PutMapping//assignment path is bounded to class so we use different http method :-) @ResponseBody public AttackResult registerNewUser(@RequestParam String username_reg, @RequestParam String email_reg, @RequestParam String password_reg)throws Exception { AttackResult attackResult = checkArguments(username_reg, email_reg, password_reg);
if (attackResult == null) { Connection connection = DatabaseUtilities.getConnection(webSession); checkDatabase(connection);
/** * WARNING: DO NOT CHANGE FILE WITHOUT CHANGING .git contents * * @author nbaars * @since 8/17/17. */ publicclassPasswordResetLink{
public String createPasswordReset(String username, String key){ Random random = new Random(); if (username.equalsIgnoreCase("admin")) { //Admin has a fix reset link random.setSeed(key.length()); } return scramble(random, scramble(random, scramble(random, MD5.getHashString(username)))); }
publicstatic String scramble(Random random, String inputString){ char a[] = inputString.toCharArray(); for (int i = 0; i < a.length; i++) { int j = random.nextInt(a.length); char temp = a[i]; a[i] = a[j]; a[j] = temp; } returnnew String(a); }
publicstaticvoidmain(String[] args){ if (args == null || args.length != 2) { System.out.println("Need a username and key"); System.exit(1); } String username = args[0]; String key = args[1]; System.out.println("Generation password reset link for " + username); System.out.println("Created password reset link: " + new PasswordResetLink().createPasswordReset(username, key)); } }
@GetMapping(value = "/vote/{stars}", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public ResponseEntity<?> vote(@PathVariable(value = "stars") int nrOfStars, HttpServletRequest request) { //Simple implementation of VERB Based Authentication String msg = ""; if (request.getMethod().equals("GET")) { HashMap<String, Object> json = Maps.newHashMap(); json.put("error", true); json.put("message", "Sorry but you need to login first in order to vote"); return ResponseEntity.status(200).body(json); } Integer allVotesForStar = votes.getOrDefault(nrOfStars, 0); votes.put(nrOfStars, allVotesForStar + 1); return ResponseEntity.ok().header("X-Flag", "Thanks for voting, your flag is: " + Flag.FLAGS.get(8)).build(); }