-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
src/main/java/org/t246osslab/easybuggy/vulnerabilities/CodeInjectionServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.t246osslab.easybuggy.vulnerabilities; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.Locale; | ||
|
||
import javax.script.ScriptEngine; | ||
import javax.script.ScriptEngineManager; | ||
import javax.script.ScriptException; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.t246osslab.easybuggy.utils.Closer; | ||
import org.t246osslab.easybuggy.utils.HTTPResponseCreator; | ||
import org.t246osslab.easybuggy.utils.MessageUtils; | ||
|
||
@SuppressWarnings("serial") | ||
@WebServlet(urlPatterns = { "/codeijc" }) | ||
public class CodeInjectionServlet extends HttpServlet { | ||
|
||
private static Logger log = LoggerFactory.getLogger(CodeInjectionServlet.class); | ||
|
||
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { | ||
|
||
PrintWriter writer = null; | ||
try { | ||
String jsonString = req.getParameter("jsonString"); | ||
Locale locale = req.getLocale(); | ||
|
||
StringBuilder bodyHtml = new StringBuilder(); | ||
|
||
bodyHtml.append("<form action=\"codeijc\" method=\"post\">"); | ||
bodyHtml.append(MessageUtils.getMsg("description.parse.json", locale)); | ||
bodyHtml.append("<br><br>"); | ||
bodyHtml.append(MessageUtils.getMsg("label.json.string", locale) + ": "); | ||
bodyHtml.append("<textarea name=\"jsonString\" cols=\"80\" lows=\"10\"></textarea>"); | ||
bodyHtml.append("<br><br>"); | ||
bodyHtml.append("<input type=\"submit\" value=\"" + MessageUtils.getMsg("label.submit", locale) + "\">"); | ||
bodyHtml.append("<br><br>"); | ||
|
||
if (jsonString != null && !jsonString.equals("")) { | ||
jsonString = jsonString.replaceAll(" ", ""); | ||
jsonString = jsonString.replaceAll("\r\n", ""); | ||
jsonString = jsonString.replaceAll("\n", ""); | ||
try { | ||
ScriptEngineManager manager = new ScriptEngineManager(); | ||
ScriptEngine scriptEngine = manager.getEngineByName("JavaScript"); | ||
scriptEngine.eval("JSON.parse('" + jsonString + "')"); | ||
bodyHtml.append(MessageUtils.getMsg("msg.valid.json", locale)); | ||
} catch (ScriptException e) { | ||
bodyHtml.append(MessageUtils.getMsg("msg.invalid.json", locale) + " : "); | ||
bodyHtml.append(e.getMessage()); | ||
} | ||
} else { | ||
bodyHtml.append(MessageUtils.getMsg("msg.enter.json.string", locale)); | ||
} | ||
bodyHtml.append("<br><br>"); | ||
bodyHtml.append(MessageUtils.getMsg("msg.note.code.injection", locale)); | ||
bodyHtml.append("</form>"); | ||
|
||
HTTPResponseCreator.createSimpleResponse(res, MessageUtils.getMsg("title.parse.json", locale), | ||
bodyHtml.toString()); | ||
} catch (Exception e) { | ||
log.error("Exception occurs: ", e); | ||
} finally { | ||
Closer.close(writer); | ||
} | ||
} | ||
|
||
public String getReverseName(String name) { | ||
StringBuffer sb = new StringBuffer(name); | ||
name = sb.reverse().toString(); | ||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters