package servlets.module.challenge;
import static dbProcs.MongoDatabase.getMongoDatabase;
import static dbProcs.MongoDatabase.getMongoDbConnection;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoCredential;
import com.mongodb.MongoException;
import com.mongodb.MongoSocketException;
import com.mongodb.MongoTimeoutException;
import dbProcs.MongoDatabase;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.ResourceBundle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.owasp.encoder.Encode;
import utils.ShepherdLogManager;
import utils.Validate;
/**
* NoSQL Injection Challenge One - Does not use user specific key
*
* This file is part of the Security Shepherd Project.
*
*
The Security Shepherd project 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 3 of the License, or (at your option) any later version.
*
*
The Security Shepherd project 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 the Security
* Shepherd project. If not, see
| GamerId | Name | Address | "; log.debug("Opening Result Set from query"); while (cursor.hasNext()) { DBObject result = cursor.next(); id = result.get("_id"); name = result.get("name"); address = result.get("address"); log.debug(bundle.getString("results.queryResult") + result.toString()); htmlOutput += "
|---|---|---|
| " + Encode.forHtml(id.toString()) + " | " + Encode.forHtml(name.toString()) + " | " + Encode.forHtml(address.toString()) + " |
" + bundle.getString("result.none") + "
"; } } catch (MongoTimeoutException e) { log.fatal(bundle.getString("result.mongoError") + e.toString()); htmlOutput += "Mongo Timeout Occurred
" + "" + Encode.forHtml(e.toString()) + "
"; } catch (MongoException e) { log.error(bundle.getString("result.mongoError") + e.toString()); htmlOutput += "An error was detected!
" + "" + Encode.forHtml(e.toString()) + "
"; } catch (Exception e) { out.write("An Error Occurred! You must be getting funky!"); log.fatal(levelName + " - " + e.toString()); } finally { cursor.close(); mongoClient.close(); } } catch (MongoSocketException e) { log.error(bundle.getString("result.mongoError") + e.toString()); htmlOutput += "An error was detected!
" + "" + Encode.forHtml(e.toString()) + "
"; } catch (MongoException e) { log.fatal("MongoDb Error caught - " + e.toString()); htmlOutput += "An error was detected!
" + "" + Encode.forHtml(e.toString()) + "
"; } catch (Exception e) { log.fatal(levelName + " - " + e); } log.debug("Outputting HTML"); out.write(htmlOutput); } else { log.error(levelName + " servlet accessed with no session"); } } }