From 86ea044cdeb44869678798ffc86b57d9344ec32a Mon Sep 17 00:00:00 2001 From: Simon Bennetts Date: Fri, 29 Aug 2025 16:37:17 +0100 Subject: [PATCH] Imported OS Command Injection tests from Reinforced Wavsep --- CHANGELOG.md | 3 + ...ent-DefaultOsCommandInput-NoValidation.jsp | 317 ++++ ...pleStatement-InvalidInput-NoValidation.jsp | 318 ++++ ...CommandInputWithoutPrefix-NoValidation.jsp | 318 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 318 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 318 ++++ ...ement-DefaultPartialInput-NoValidation.jsp | 321 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 321 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 321 ++++ ...ent-DefaultPartialInput-PipeValidation.jsp | 331 +++++ ...pleStatement-EmptyInput-PipeValidation.jsp | 331 +++++ ...eStatement-InvalidInput-PipeValidation.jsp | 331 +++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 317 ++++ ...tement-DefaultPartialInput-PipeRemoval.jsp | 331 +++++ ...SimpleStatement-EmptyInput-PipeRemoval.jsp | 331 +++++ ...mpleStatement-InvalidInput-PipeRemoval.jsp | 331 +++++ ...efaultPartialInput-AmpersandValidation.jsp | 331 +++++ ...atement-EmptyInput-AmpersandValidation.jsp | 331 +++++ ...ement-InvalidInput-AmpersandValidation.jsp | 331 +++++ ...t-DefaultPartialInput-AmpersandRemoval.jsp | 331 +++++ ...eStatement-EmptyInput-AmpersandRemoval.jsp | 331 +++++ ...tatement-InvalidInput-AmpersandRemoval.jsp | 331 +++++ ...tement-DefaulInvalidInput-NoValidation.jsp | 317 ++++ ...ultRelativeOsCommandInput-NoValidation.jsp | 317 ++++ ...ement-DefaultPartialInput-NoValidation.jsp | 317 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 318 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 317 ++++ ...tOsCommandInputWithPrefix-NoValidation.jsp | 318 ++++ ...impleStatement-EmptyInput-NoValidation.jsp | 318 ++++ .../include.jsp | 145 ++ .../index.jsp | 1315 +++++++++++++++++ ...ent-DefaultOsCommandInput-NoValidation.jsp | 317 ++++ ...pleStatement-InvalidInput-NoValidation.jsp | 318 ++++ ...CommandInputWithoutPrefix-NoValidation.jsp | 318 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 318 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 318 ++++ ...ement-DefaultPartialInput-NoValidation.jsp | 321 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 321 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 321 ++++ ...ent-DefaultPartialInput-PipeValidation.jsp | 331 +++++ ...pleStatement-EmptyInput-PipeValidation.jsp | 331 +++++ ...eStatement-InvalidInput-PipeValidation.jsp | 331 +++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 317 ++++ ...tement-DefaultPartialInput-PipeRemoval.jsp | 331 +++++ ...SimpleStatement-EmptyInput-PipeRemoval.jsp | 331 +++++ ...mpleStatement-InvalidInput-PipeRemoval.jsp | 331 +++++ ...efaultPartialInput-AmpersandValidation.jsp | 331 +++++ ...atement-EmptyInput-AmpersandValidation.jsp | 331 +++++ ...ement-InvalidInput-AmpersandValidation.jsp | 331 +++++ ...t-DefaultPartialInput-AmpersandRemoval.jsp | 331 +++++ ...eStatement-EmptyInput-AmpersandRemoval.jsp | 331 +++++ ...tatement-InvalidInput-AmpersandRemoval.jsp | 331 +++++ ...tement-DefaulInvalidInput-NoValidation.jsp | 317 ++++ ...ultRelativeOsCommandInput-NoValidation.jsp | 317 ++++ ...ement-DefaultPartialInput-NoValidation.jsp | 317 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 317 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 317 ++++ ...tOsCommandInputWithPrefix-NoValidation.jsp | 318 ++++ ...impleStatement-EmptyInput-NoValidation.jsp | 318 ++++ .../include.jsp | 145 ++ .../index.jsp | 1315 +++++++++++++++++ ...ent-DefaultOsCommandInput-NoValidation.jsp | 317 ++++ ...pleStatement-InvalidInput-NoValidation.jsp | 318 ++++ ...CommandInputWithoutPrefix-NoValidation.jsp | 318 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 318 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 318 ++++ ...ement-DefaultPartialInput-NoValidation.jsp | 321 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 321 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 321 ++++ ...ent-DefaultPartialInput-PipeValidation.jsp | 331 +++++ ...pleStatement-EmptyInput-PipeValidation.jsp | 331 +++++ ...eStatement-InvalidInput-PipeValidation.jsp | 331 +++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 317 ++++ ...tement-DefaultPartialInput-PipeRemoval.jsp | 331 +++++ ...SimpleStatement-EmptyInput-PipeRemoval.jsp | 331 +++++ ...mpleStatement-InvalidInput-PipeRemoval.jsp | 331 +++++ ...efaultPartialInput-AmpersandValidation.jsp | 331 +++++ ...atement-EmptyInput-AmpersandValidation.jsp | 331 +++++ ...ement-InvalidInput-AmpersandValidation.jsp | 331 +++++ ...t-DefaultPartialInput-AmpersandRemoval.jsp | 331 +++++ ...eStatement-EmptyInput-AmpersandRemoval.jsp | 331 +++++ ...tatement-InvalidInput-AmpersandRemoval.jsp | 331 +++++ ...tement-DefaulInvalidInput-NoValidation.jsp | 317 ++++ ...ultRelativeOsCommandInput-NoValidation.jsp | 317 ++++ ...ement-DefaultPartialInput-NoValidation.jsp | 317 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 317 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 317 ++++ ...tOsCommandInputWithPrefix-NoValidation.jsp | 318 ++++ ...impleStatement-EmptyInput-NoValidation.jsp | 318 ++++ .../include.jsp | 145 ++ .../index.jsp | 1315 +++++++++++++++++ ...ent-DefaultOsCommandInput-NoValidation.jsp | 317 ++++ ...pleStatement-InvalidInput-NoValidation.jsp | 318 ++++ ...CommandInputWithoutPrefix-NoValidation.jsp | 318 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 318 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 318 ++++ ...ement-DefaultPartialInput-NoValidation.jsp | 321 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 321 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 321 ++++ ...ent-DefaultPartialInput-PipeValidation.jsp | 331 +++++ ...pleStatement-EmptyInput-PipeValidation.jsp | 331 +++++ ...eStatement-InvalidInput-PipeValidation.jsp | 331 +++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 317 ++++ ...tement-DefaultPartialInput-PipeRemoval.jsp | 331 +++++ ...SimpleStatement-EmptyInput-PipeRemoval.jsp | 331 +++++ ...mpleStatement-InvalidInput-PipeRemoval.jsp | 331 +++++ ...efaultPartialInput-AmpersandValidation.jsp | 331 +++++ ...atement-EmptyInput-AmpersandValidation.jsp | 331 +++++ ...ement-InvalidInput-AmpersandValidation.jsp | 331 +++++ ...t-DefaultPartialInput-AmpersandRemoval.jsp | 331 +++++ ...eStatement-EmptyInput-AmpersandRemoval.jsp | 331 +++++ ...tatement-InvalidInput-AmpersandRemoval.jsp | 331 +++++ ...tement-DefaulInvalidInput-NoValidation.jsp | 317 ++++ ...ultRelativeOsCommandInput-NoValidation.jsp | 317 ++++ ...ement-DefaultPartialInput-NoValidation.jsp | 317 ++++ ...atement-DefaultEmptyInput-NoValidation.jsp | 317 ++++ ...ement-DefaultInvalidInput-NoValidation.jsp | 317 ++++ ...tOsCommandInputWithPrefix-NoValidation.jsp | 318 ++++ ...impleStatement-EmptyInput-NoValidation.jsp | 318 ++++ .../include.jsp | 145 ++ .../index.jsp | 1314 ++++++++++++++++ WebContent/active/index-main.jsp | 1 + WebContent/active/index-os-command.jsp | 22 + WebContent/images/wavsep-logo.jpg | Bin 0 -> 31580 bytes .../sectooladdict/enums/DefaultInputType.java | 6 +- .../enums/FileAccessRestriction.java | 10 +- src/com/sectooladdict/enums/OsType.java | 2 +- .../validators/InputValidator.java | 27 +- 128 files changed, 42154 insertions(+), 5 deletions(-) create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/include.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/index.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/include.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/index.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/include.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/index.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/include.jsp create mode 100644 WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/index.jsp create mode 100644 WebContent/active/index-os-command.jsp create mode 100644 WebContent/images/wavsep-logo.jpg diff --git a/CHANGELOG.md b/CHANGELOG.md index dca4c38..bfb72f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## 2025-08-30 +- Imported OS Command Injection tests from [Reinforced Wavsep](https://github.com/luigiurbano/Reinforced-Wavsep) at commit [962d566](https://github.com/luigiurbano/Reinforced-Wavsep/commit/962d566ebe51a3f64f772b6c1856d99f1150ba4a). + ## 2025-08-28 ### Changed diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp new file mode 100644 index 0000000..72f6c7e --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp new file mode 100644 index 0000000..4b68682 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp new file mode 100644 index 0000000..f99c538 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..04d12f8 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..5ec94bb --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp new file mode 100644 index 0000000..96fa22a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..da38958 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..70849cc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp new file mode 100644 index 0000000..5a774c0 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp new file mode 100644 index 0000000..fe4d7dc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp new file mode 100644 index 0000000..3a96365 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..89de206 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp new file mode 100644 index 0000000..52ca8d7 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp new file mode 100644 index 0000000..53eca1b --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp new file mode 100644 index 0000000..af5c857 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp new file mode 100644 index 0000000..5b7f33d --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp new file mode 100644 index 0000000..7f73872 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp new file mode 100644 index 0000000..38e2baa --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..96ace3a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..0ae9ff7 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..3873025 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..1e25a7c --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp new file mode 100644 index 0000000..75a1365 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp new file mode 100644 index 0000000..03e4ffc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..999d694 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + System.out.println(prefix + input + postfix); + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..42d8494 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp new file mode 100644 index 0000000..5d0fa4a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp new file mode 100644 index 0000000..b2bb923 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/include.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/include.jsp new file mode 100644 index 0000000..2ab7639 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/include.jsp @@ -0,0 +1,145 @@ +<%@page import="java.io.*" %> +<%@page import="java.net.*" %> +<%@page import="com.sectooladdict.encoders.HtmlEncoder" %> +<%@page import="com.sectooladdict.constants.SystemConstants" %> +<%@page import="com.sectooladdict.constants.FileConstants" %> +<%@page import="com.sectooladdict.constants.ContentConstants" %> +<%@page import="com.sectooladdict.enums.VulnerabilityType" %> +<%@page import="com.sectooladdict.enums.ResponseType" %> +<%@page import="com.sectooladdict.enums.DefaultInputType" %> +<%@page import="com.sectooladdict.enums.FileAccessRestriction" %> +<%@page import="com.sectooladdict.enums.FileInjectionContext" %> +<%@page import="com.sectooladdict.enums.PrefixRequirement" %> +<%@page import="com.sectooladdict.enums.OsType" %> + +<% +//set debug flag from main config +boolean debugMode = SystemConstants.DEBUG_FLAG_DEFAULT_STATE; + +//begin setting group definitions +//-------------------------------- + +//** Set File Access Restriction *** +//NONE, WHITE_LIST, LOCAL_FOLDER_ONLY, PERMISSIONS, +//UNIX_TRAVESAL_INPUT_VALIDATION, UNIX_TRAVESAL_INPUT_REMOVAL, +//WINDOWS_TRAVESAL_INPUT_VALIDATION, WINDOWS_TRAVESAL_INPUT_REMOVAL, +//SLASH_INPUT_VALIDATION, SLASH_INPUT_REMOVAL, +//BACKSLASH_INPUT_VALIDATION, BACKSLASH_INPUT_REMOVAL, +FileAccessRestriction accessRestriction = FileAccessRestriction.NONE; + +//** Set Default Input Format *** +//FULL_PATH_INPUT, RELATIVE_INPUT, INVALID_INPUT, EMPTY_INPUT +DefaultInputType defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + +//set path requirement +//ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, +//FTP_DIRECTIVE, HTTP_DIRECTIVE, +PrefixRequirement prefixRequired = PrefixRequirement.ANY; + +//*** set OS simulation (unix default) *** +//WINDOWS, UNIX +OsType osSimulated = OsType.ANY; + +//*** Set Default Response Type *** +//ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 +ResponseType invalidResponseType = ResponseType.ERROR_200; + +//*** Set Default Content Type *** +//CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") +String validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + +//*** Set Default Prefix String *** +String prefix = ""; //"",[cmd.exe /c ] [command] +//*** Set Default Prefix String *** +String postfix = ""; //"",|[command] &[command] >>[command] >[command] <[command] <[command] + +//obtain deliminters and path information +String fileDelimiter = System.getProperty("file.separator"); +String lineDelimiter = System.getProperty("line.separator"); + +//Initial Path/URL: +String DefaultInitialPath = ""; //Empty +//Current User Directory File Object +File directory = new File ("."); +//User Directory Path - Absolute +String userPath = System.getProperty("user.dir"); +///Deployement Path Root - Absolute +String documentRootPath = + getServletConfig().getServletContext().getRealPath(""); +//Relative path of current file - Absolute +String currentFilePath = request.getRealPath(request.getServletPath()); +//Relative path of current directory - Absolute - No Final Line Delimiter +String currentDirPath = request.getRealPath( + (request.getServletPath()).split("/Case")[0]); +//Web Path of Root - Relative +String contextPath = this.getServletContext().getContextPath(); +//Web Path of File - Relative and *NOT* including ROOT (!) +String contextPathFile = request.getServletPath(); +//Web Path of Dir - Relative and *NOT* including ROOT or File Delimiter(!) +String contextRelativeDirPath = (request.getServletPath()).split("/Case")[0]; + +if (debugMode == true) { + String BR = "
"; + String FontStart = ""; + String FontEnd = ""; + + System.out.println ("File delimiter: " + fileDelimiter); + out.println (FontStart + "File delimiter: " + FontEnd + fileDelimiter + BR); + System.out.println ("Line delimiter (encoded):" + HtmlEncoder.htmlEncode(lineDelimiter)); + out.println (FontStart + "Line delimiter (encoded): " + FontEnd + + HtmlEncoder.htmlEncode(HtmlEncoder.htmlEncode(lineDelimiter)) + BR); + + //User Directory Path - Absolute + System.out.println ("User Directory Path (Absolute): " + userPath); + out.println (FontStart + "User Directory Path (Absolute): " + FontEnd + userPath + BR); + ///Deployement Path Root - Absolute + System.out.println ("Deployment Path Root (Absolute): " + documentRootPath); + out.println (FontStart + "Deployment Path Root (Absolute): " + FontEnd + documentRootPath + BR); + //Relative path of current file - Absolute + System.out.println ("Deployment Path Current File (Absolute): " + currentFilePath); + out.println (FontStart + "Deployment Path Current File (Absolute): " + FontEnd + currentFilePath + BR); + //Relative path of current directory - Absolute + System.out.println ("Deployment Path Current Directory (Absolute): " + currentDirPath); + out.println (FontStart + "Deployment Path Current Directory (Absolute): " + FontEnd + currentDirPath + BR); + //Web Path of Root - Relative + System.out.println ("Web Path Root (Relative): " + contextPath); + out.println (FontStart + "Web Path Root (Relative): " + FontEnd + contextPath + BR); + //Web Path of File - Relative and *NOT* including ROOT (!) + System.out.println ("Web Path of File (Relative-no-root): " + contextPathFile); + out.println (FontStart + "Web Path of File (Relative-no-root): " + FontEnd + contextPathFile + BR); + //Web Path of Dir - Relative and *NOT* including ROOT or File Delimiter(!) + System.out.println ("Web Path of Dir (Relative-no-root): " + contextRelativeDirPath); + out.println (FontStart + "Web Path of Dir (Relative-no-root): " + FontEnd + contextRelativeDirPath + BR); + //Full URL: + System.out.println("request URL: " + request.getRequestURL()); + out.println(FontStart + "request URL: " + FontEnd + request.getRequestURL() + BR); + + //System.out.println(request.getRealPath("/")); + + try { + System.out.println ("Current directory's canonical path: " + + directory.getCanonicalPath()); + out.println (FontStart + "Current directory's canonical path: " + + FontEnd + directory.getCanonicalPath() + BR); + System.out.println ("Current directory's absolute path: " + + directory.getAbsolutePath()); + out.println (FontStart + "Current directory's absolute path: " + + FontEnd + directory.getAbsolutePath() + BR); + } catch(Exception e) { + System.out.println("Exceptione is =" + e.getMessage()); + } + + out.println(BR + BR); +} // end of debug if + +//****ways to get the file **** +//1)context.getRequestDispatcher("/").forward(request, response); +//2)File file = new File (currentDirPath + targetFile); +//3)is = getServletContext().getResourceAsStream(contextRelativeDirPath + targetFile); +//4)is = new FileInputStream(currentDirPath + targetFile); +//5)URL url = new URL(URLInitialPath + targetFile); +// URLConnection urlconn = url.openConnection(); +//6)FORWARD (FP) +//6)REDIRECT (FP) + +%> \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/index.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/index.jsp new file mode 100644 index 0000000..6542362 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-200Error/index.jsp @@ -0,0 +1,1315 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Evaluation of OS Command Injection Detection Accuracy - HTTP GET Method + + + +<%@ include file="include.jsp"%> + +<% + String defaultFullOsCommandInputWithoutPrefix = null; + String defaultFullOsCommandInputWithPrefix = null; + String defaultPostfixOsCommandInputWithInitialCommand = null; + String defaultPostfixOsCommandInputWithoutInitialCommand = null; + String defaultEmptyInput = null; + String defaultPartialInput = null; + String defaultPostfixValueInput = null; + String defaultPostfixCommandInput = null; + String defaultInvalidInput = null; + + + boolean isWindows = System.getProperty("os.name").contains("Win"); + + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultFullOsCommandInputWithoutPrefix = "dir"; + defaultFullOsCommandInputWithPrefix = "cmd.exe /c dir"; + + defaultPostfixOsCommandInputWithInitialCommand = "findstr Java"; + defaultPostfixOsCommandInputWithoutInitialCommand = "Java"; + defaultEmptyInput = ""; + defaultPartialInput = "eclipse.ini"; + defaultPostfixValueInput = "Build"; + defaultPostfixCommandInput = " | findstr Build"; + defaultInvalidInput = "dfdflkjsh"; + } else { + defaultFullOsCommandInputWithoutPrefix = "ls"; + defaultFullOsCommandInputWithPrefix = "ls"; + defaultEmptyInput = ""; + defaultPartialInput = "eclipse.ini"; + defaultPostfixValueInput = "Build"; + defaultPostfixCommandInput = " | grep Build"; + defaultInvalidInput = "dfdflkjsh"; + } +%> + +
OS Command Injection Test Cases - HTTP 200 Valid Responses:


+ +
+Injection Contexts Covered:
+1) Initial Statement/Command Context: Default OS Command Input with and without prefix:
+ [windows only: cmd.exe /c ]*OS COMMAND INJECTION*
+2) Internal Statement/Command Context: Input integrated in the middle of a fixed OS command:
+ [windows only: cmd.exe /c ][fixed-os-command ]*INPUT*[ | postfix-fixed-commands]
+ [windows only: cmd.exe /c ][fixed-os-command ]*INPUT*
+3) Internal Statement/Command Context: Input integrated in postfix section of an OS command:
+ [windows only: cmd.exe /c ][fixed-os-command ][ | postfix-fixed-commands ]*INPUT*
+
+
+
+ + + Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default OS command input (with prefix), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Command With PrefixANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): cmd.exe /c dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default EMPTY input (invalid), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default INVALID input (invalid), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default OS command input (no prefix), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Command No PrefixANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): | cat /etc/passwd
+
+
+ + + + Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd
+
+
+ + + + Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd
+
+
+ + + Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default OS command input (with initial postfix command), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Postfix CommandANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default empty input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default invalid input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default OS command input (with initial postfix command), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial OS Postfix CommandANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default empty input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + + Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default invalid input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default PARTIAL input (filename), using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial Command (filename)ANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent14.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent14.txt
+
+
+ + + + + Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default EMPTY input, using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent15.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent15.txt
+
+
+ + + + + Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default INVALID input, using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent16.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent16.txt
+
+
+ + + + + Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent17.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent17.txt
+
+
+ + + + + Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent18.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent18.txt
+
+
+ + + + + Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent19.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent19.txt
+
+
+ + + + + Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent20.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent20.txt
+
+
+ + + + + Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent21.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent21.txt
+
+
+ + + + + Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent22.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent22.txt
+
+
+ + + + Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent23.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent23.txt
+
+
+ + + + Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent24.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent24.txt
+
+
+ + + + Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent25.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent25.txt
+
+
+ + + + Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent26.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent26.txt
+
+
+ + + + Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent27.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent27.txt
+
+
+ + + + Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent28.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent28.txt
+
+
+ + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp new file mode 100644 index 0000000..72f6c7e --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp new file mode 100644 index 0000000..4b68682 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp new file mode 100644 index 0000000..f99c538 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..04d12f8 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..5ec94bb --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp new file mode 100644 index 0000000..96fa22a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..da38958 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..70849cc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp new file mode 100644 index 0000000..5a774c0 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp new file mode 100644 index 0000000..fe4d7dc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp new file mode 100644 index 0000000..3a96365 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..89de206 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp new file mode 100644 index 0000000..52ca8d7 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp new file mode 100644 index 0000000..53eca1b --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp new file mode 100644 index 0000000..af5c857 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp new file mode 100644 index 0000000..5b7f33d --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp new file mode 100644 index 0000000..7f73872 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp new file mode 100644 index 0000000..38e2baa --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..96ace3a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..0ae9ff7 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..3873025 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..1e25a7c --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp new file mode 100644 index 0000000..75a1365 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp new file mode 100644 index 0000000..03e4ffc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..1e0d95a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..42d8494 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp new file mode 100644 index 0000000..5d0fa4a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp new file mode 100644 index 0000000..b2bb923 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/include.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/include.jsp new file mode 100644 index 0000000..a357805 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/include.jsp @@ -0,0 +1,145 @@ +<%@page import="java.io.*" %> +<%@page import="java.net.*" %> +<%@page import="com.sectooladdict.encoders.HtmlEncoder" %> +<%@page import="com.sectooladdict.constants.SystemConstants" %> +<%@page import="com.sectooladdict.constants.FileConstants" %> +<%@page import="com.sectooladdict.constants.ContentConstants" %> +<%@page import="com.sectooladdict.enums.VulnerabilityType" %> +<%@page import="com.sectooladdict.enums.ResponseType" %> +<%@page import="com.sectooladdict.enums.DefaultInputType" %> +<%@page import="com.sectooladdict.enums.FileAccessRestriction" %> +<%@page import="com.sectooladdict.enums.FileInjectionContext" %> +<%@page import="com.sectooladdict.enums.PrefixRequirement" %> +<%@page import="com.sectooladdict.enums.OsType" %> + +<% +//set debug flag from main config +boolean debugMode = SystemConstants.DEBUG_FLAG_DEFAULT_STATE; + +//begin setting group definitions +//-------------------------------- + +//** Set File Access Restriction *** +//NONE, WHITE_LIST, LOCAL_FOLDER_ONLY, PERMISSIONS, +//UNIX_TRAVESAL_INPUT_VALIDATION, UNIX_TRAVESAL_INPUT_REMOVAL, +//WINDOWS_TRAVESAL_INPUT_VALIDATION, WINDOWS_TRAVESAL_INPUT_REMOVAL, +//SLASH_INPUT_VALIDATION, SLASH_INPUT_REMOVAL, +//BACKSLASH_INPUT_VALIDATION, BACKSLASH_INPUT_REMOVAL, +FileAccessRestriction accessRestriction = FileAccessRestriction.NONE; + +//** Set Default Input Format *** +//FULL_PATH_INPUT, RELATIVE_INPUT, INVALID_INPUT, EMPTY_INPUT +DefaultInputType defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + +//set path requirement +//ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, +//FTP_DIRECTIVE, HTTP_DIRECTIVE, +PrefixRequirement prefixRequired = PrefixRequirement.ANY; + +//*** set OS simulation (unix default) *** +//WINDOWS, UNIX +OsType osSimulated = OsType.ANY; + +//*** Set Default Response Type *** +//ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 +ResponseType invalidResponseType = ResponseType.ERROR_500; + +//*** Set Default Content Type *** +//CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") +String validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + +//*** Set Default Prefix String *** +String prefix = ""; //"",[cmd.exe /c ] [command] +//*** Set Default Prefix String *** +String postfix = ""; //"",|[command] &[command] >>[command] >[command] <[command] <[command] + +//obtain deliminters and path information +String fileDelimiter = System.getProperty("file.separator"); +String lineDelimiter = System.getProperty("line.separator"); + +//Initial Path/URL: +String DefaultInitialPath = ""; //Empty +//Current User Directory File Object +File directory = new File ("."); +//User Directory Path - Absolute +String userPath = System.getProperty("user.dir"); +///Deployement Path Root - Absolute +String documentRootPath = + getServletConfig().getServletContext().getRealPath(""); +//Relative path of current file - Absolute +String currentFilePath = request.getRealPath(request.getServletPath()); +//Relative path of current directory - Absolute - No Final Line Delimiter +String currentDirPath = request.getRealPath( + (request.getServletPath()).split("/Case")[0]); +//Web Path of Root - Relative +String contextPath = this.getServletContext().getContextPath(); +//Web Path of File - Relative and *NOT* including ROOT (!) +String contextPathFile = request.getServletPath(); +//Web Path of Dir - Relative and *NOT* including ROOT or File Delimiter(!) +String contextRelativeDirPath = (request.getServletPath()).split("/Case")[0]; + +if (debugMode == true) { + String BR = "
"; + String FontStart = ""; + String FontEnd = ""; + + System.out.println ("File delimiter: " + fileDelimiter); + out.println (FontStart + "File delimiter: " + FontEnd + fileDelimiter + BR); + System.out.println ("Line delimiter (encoded):" + HtmlEncoder.htmlEncode(lineDelimiter)); + out.println (FontStart + "Line delimiter (encoded): " + FontEnd + + HtmlEncoder.htmlEncode(HtmlEncoder.htmlEncode(lineDelimiter)) + BR); + + //User Directory Path - Absolute + System.out.println ("User Directory Path (Absolute): " + userPath); + out.println (FontStart + "User Directory Path (Absolute): " + FontEnd + userPath + BR); + ///Deployement Path Root - Absolute + System.out.println ("Deployment Path Root (Absolute): " + documentRootPath); + out.println (FontStart + "Deployment Path Root (Absolute): " + FontEnd + documentRootPath + BR); + //Relative path of current file - Absolute + System.out.println ("Deployment Path Current File (Absolute): " + currentFilePath); + out.println (FontStart + "Deployment Path Current File (Absolute): " + FontEnd + currentFilePath + BR); + //Relative path of current directory - Absolute + System.out.println ("Deployment Path Current Directory (Absolute): " + currentDirPath); + out.println (FontStart + "Deployment Path Current Directory (Absolute): " + FontEnd + currentDirPath + BR); + //Web Path of Root - Relative + System.out.println ("Web Path Root (Relative): " + contextPath); + out.println (FontStart + "Web Path Root (Relative): " + FontEnd + contextPath + BR); + //Web Path of File - Relative and *NOT* including ROOT (!) + System.out.println ("Web Path of File (Relative-no-root): " + contextPathFile); + out.println (FontStart + "Web Path of File (Relative-no-root): " + FontEnd + contextPathFile + BR); + //Web Path of Dir - Relative and *NOT* including ROOT or File Delimiter(!) + System.out.println ("Web Path of Dir (Relative-no-root): " + contextRelativeDirPath); + out.println (FontStart + "Web Path of Dir (Relative-no-root): " + FontEnd + contextRelativeDirPath + BR); + //Full URL: + System.out.println("request URL: " + request.getRequestURL()); + out.println(FontStart + "request URL: " + FontEnd + request.getRequestURL() + BR); + + //System.out.println(request.getRealPath("/")); + + try { + System.out.println ("Current directory's canonical path: " + + directory.getCanonicalPath()); + out.println (FontStart + "Current directory's canonical path: " + + FontEnd + directory.getCanonicalPath() + BR); + System.out.println ("Current directory's absolute path: " + + directory.getAbsolutePath()); + out.println (FontStart + "Current directory's absolute path: " + + FontEnd + directory.getAbsolutePath() + BR); + } catch(Exception e) { + System.out.println("Exceptione is =" + e.getMessage()); + } + + out.println(BR + BR); +} // end of debug if + +//****ways to get the file **** +//1)context.getRequestDispatcher("/").forward(request, response); +//2)File file = new File (currentDirPath + targetFile); +//3)is = getServletContext().getResourceAsStream(contextRelativeDirPath + targetFile); +//4)is = new FileInputStream(currentDirPath + targetFile); +//5)URL url = new URL(URLInitialPath + targetFile); +// URLConnection urlconn = url.openConnection(); +//6)FORWARD (FP) +//6)REDIRECT (FP) + +%> \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/index.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/index.jsp new file mode 100644 index 0000000..a8ada8a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-GET-500Error/index.jsp @@ -0,0 +1,1315 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Evaluation of OS Command Injection Detection Accuracy - HTTP GET Method + + + +<%@ include file="include.jsp"%> + +<% + String defaultFullOsCommandInputWithoutPrefix = null; + String defaultFullOsCommandInputWithPrefix = null; + String defaultPostfixOsCommandInputWithInitialCommand = null; + String defaultPostfixOsCommandInputWithoutInitialCommand = null; + String defaultEmptyInput = null; + String defaultPartialInput = null; + String defaultPostfixValueInput = null; + String defaultPostfixCommandInput = null; + String defaultInvalidInput = null; + + + boolean isWindows = System.getProperty("os.name").contains("Win"); + + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultFullOsCommandInputWithoutPrefix = "dir"; + defaultFullOsCommandInputWithPrefix = "cmd.exe /c dir"; + + defaultPostfixOsCommandInputWithInitialCommand = "findstr Java"; + defaultPostfixOsCommandInputWithoutInitialCommand = "Java"; + defaultEmptyInput = ""; + defaultPartialInput = "eclipse.ini"; + defaultPostfixValueInput = "Build"; + defaultPostfixCommandInput = " | findstr Build"; + defaultInvalidInput = "dfdflkjsh"; + } else { + defaultFullOsCommandInputWithoutPrefix = "ls"; + defaultFullOsCommandInputWithPrefix = "ls"; + defaultEmptyInput = ""; + defaultPartialInput = "eclipse.ini"; + defaultPostfixValueInput = "Build"; + defaultPostfixCommandInput = " | grep Build"; + defaultInvalidInput = "dfdflkjsh"; + } +%> + +
OS Command Injection Test Cases - HTTP 200 Valid Responses:


+ +
+Injection Contexts Covered:
+1) Initial Statement/Command Context: Default OS Command Input with and without prefix:
+ [windows only: cmd.exe /c ]*OS COMMAND INJECTION*
+2) Internal Statement/Command Context: Input integrated in the middle of a fixed OS command:
+ [windows only: cmd.exe /c ][fixed-os-command ]*INPUT*[ | postfix-fixed-commands]
+ [windows only: cmd.exe /c ][fixed-os-command ]*INPUT*
+3) Internal Statement/Command Context: Input integrated in postfix section of an OS command:
+ [windows only: cmd.exe /c ][fixed-os-command ][ | postfix-fixed-commands ]*INPUT*
+
+
+
+ + + Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default OS command input (with prefix), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Command With PrefixANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): cmd.exe /c dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default EMPTY input (invalid), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default INVALID input (invalid), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default OS command input (no prefix), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Command No PrefixANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): | cat /etc/passwd
+
+
+ + + + Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd
+
+
+ + + + Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd
+
+
+ + + Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default OS command input (with initial postfix command), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Postfix CommandANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default empty input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default invalid input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default OS command input (with initial postfix command), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial OS Postfix CommandANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default empty input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + + Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default invalid input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default PARTIAL input (filename), using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial Command (filename)ANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent14.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent14.txt
+
+
+ + + + + Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default EMPTY input, using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent15.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent15.txt
+
+
+ + + + + Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default INVALID input, using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent16.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent16.txt
+
+
+ + + + + Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent17.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent17.txt
+
+
+ + + + + Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent18.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent18.txt
+
+
+ + + + + Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent19.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent19.txt
+
+
+ + + + + Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent20.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent20.txt
+
+
+ + + + + Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent21.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent21.txt
+
+
+ + + + + Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent22.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent22.txt
+
+
+ + + + Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent23.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent23.txt
+
+
+ + + + Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent24.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent24.txt
+
+
+ + + + Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent25.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent25.txt
+
+
+ + + + Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent26.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent26.txt
+
+
+ + + + Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent27.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent27.txt
+
+
+ + + + Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent28.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent28.txt
+
+
+ + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp new file mode 100644 index 0000000..72f6c7e --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp new file mode 100644 index 0000000..4b68682 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp new file mode 100644 index 0000000..f99c538 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..04d12f8 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..5ec94bb --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp new file mode 100644 index 0000000..96fa22a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..da38958 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..70849cc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp new file mode 100644 index 0000000..5a774c0 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp new file mode 100644 index 0000000..fe4d7dc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp new file mode 100644 index 0000000..3a96365 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..89de206 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp new file mode 100644 index 0000000..52ca8d7 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp new file mode 100644 index 0000000..53eca1b --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp new file mode 100644 index 0000000..af5c857 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp new file mode 100644 index 0000000..5b7f33d --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp new file mode 100644 index 0000000..7f73872 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp new file mode 100644 index 0000000..38e2baa --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..96ace3a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..0ae9ff7 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..3873025 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..1e25a7c --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp new file mode 100644 index 0000000..75a1365 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp new file mode 100644 index 0000000..03e4ffc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..1e0d95a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..42d8494 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp new file mode 100644 index 0000000..5d0fa4a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp new file mode 100644 index 0000000..b2bb923 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/include.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/include.jsp new file mode 100644 index 0000000..2ab7639 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/include.jsp @@ -0,0 +1,145 @@ +<%@page import="java.io.*" %> +<%@page import="java.net.*" %> +<%@page import="com.sectooladdict.encoders.HtmlEncoder" %> +<%@page import="com.sectooladdict.constants.SystemConstants" %> +<%@page import="com.sectooladdict.constants.FileConstants" %> +<%@page import="com.sectooladdict.constants.ContentConstants" %> +<%@page import="com.sectooladdict.enums.VulnerabilityType" %> +<%@page import="com.sectooladdict.enums.ResponseType" %> +<%@page import="com.sectooladdict.enums.DefaultInputType" %> +<%@page import="com.sectooladdict.enums.FileAccessRestriction" %> +<%@page import="com.sectooladdict.enums.FileInjectionContext" %> +<%@page import="com.sectooladdict.enums.PrefixRequirement" %> +<%@page import="com.sectooladdict.enums.OsType" %> + +<% +//set debug flag from main config +boolean debugMode = SystemConstants.DEBUG_FLAG_DEFAULT_STATE; + +//begin setting group definitions +//-------------------------------- + +//** Set File Access Restriction *** +//NONE, WHITE_LIST, LOCAL_FOLDER_ONLY, PERMISSIONS, +//UNIX_TRAVESAL_INPUT_VALIDATION, UNIX_TRAVESAL_INPUT_REMOVAL, +//WINDOWS_TRAVESAL_INPUT_VALIDATION, WINDOWS_TRAVESAL_INPUT_REMOVAL, +//SLASH_INPUT_VALIDATION, SLASH_INPUT_REMOVAL, +//BACKSLASH_INPUT_VALIDATION, BACKSLASH_INPUT_REMOVAL, +FileAccessRestriction accessRestriction = FileAccessRestriction.NONE; + +//** Set Default Input Format *** +//FULL_PATH_INPUT, RELATIVE_INPUT, INVALID_INPUT, EMPTY_INPUT +DefaultInputType defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + +//set path requirement +//ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, +//FTP_DIRECTIVE, HTTP_DIRECTIVE, +PrefixRequirement prefixRequired = PrefixRequirement.ANY; + +//*** set OS simulation (unix default) *** +//WINDOWS, UNIX +OsType osSimulated = OsType.ANY; + +//*** Set Default Response Type *** +//ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 +ResponseType invalidResponseType = ResponseType.ERROR_200; + +//*** Set Default Content Type *** +//CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") +String validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + +//*** Set Default Prefix String *** +String prefix = ""; //"",[cmd.exe /c ] [command] +//*** Set Default Prefix String *** +String postfix = ""; //"",|[command] &[command] >>[command] >[command] <[command] <[command] + +//obtain deliminters and path information +String fileDelimiter = System.getProperty("file.separator"); +String lineDelimiter = System.getProperty("line.separator"); + +//Initial Path/URL: +String DefaultInitialPath = ""; //Empty +//Current User Directory File Object +File directory = new File ("."); +//User Directory Path - Absolute +String userPath = System.getProperty("user.dir"); +///Deployement Path Root - Absolute +String documentRootPath = + getServletConfig().getServletContext().getRealPath(""); +//Relative path of current file - Absolute +String currentFilePath = request.getRealPath(request.getServletPath()); +//Relative path of current directory - Absolute - No Final Line Delimiter +String currentDirPath = request.getRealPath( + (request.getServletPath()).split("/Case")[0]); +//Web Path of Root - Relative +String contextPath = this.getServletContext().getContextPath(); +//Web Path of File - Relative and *NOT* including ROOT (!) +String contextPathFile = request.getServletPath(); +//Web Path of Dir - Relative and *NOT* including ROOT or File Delimiter(!) +String contextRelativeDirPath = (request.getServletPath()).split("/Case")[0]; + +if (debugMode == true) { + String BR = "
"; + String FontStart = ""; + String FontEnd = ""; + + System.out.println ("File delimiter: " + fileDelimiter); + out.println (FontStart + "File delimiter: " + FontEnd + fileDelimiter + BR); + System.out.println ("Line delimiter (encoded):" + HtmlEncoder.htmlEncode(lineDelimiter)); + out.println (FontStart + "Line delimiter (encoded): " + FontEnd + + HtmlEncoder.htmlEncode(HtmlEncoder.htmlEncode(lineDelimiter)) + BR); + + //User Directory Path - Absolute + System.out.println ("User Directory Path (Absolute): " + userPath); + out.println (FontStart + "User Directory Path (Absolute): " + FontEnd + userPath + BR); + ///Deployement Path Root - Absolute + System.out.println ("Deployment Path Root (Absolute): " + documentRootPath); + out.println (FontStart + "Deployment Path Root (Absolute): " + FontEnd + documentRootPath + BR); + //Relative path of current file - Absolute + System.out.println ("Deployment Path Current File (Absolute): " + currentFilePath); + out.println (FontStart + "Deployment Path Current File (Absolute): " + FontEnd + currentFilePath + BR); + //Relative path of current directory - Absolute + System.out.println ("Deployment Path Current Directory (Absolute): " + currentDirPath); + out.println (FontStart + "Deployment Path Current Directory (Absolute): " + FontEnd + currentDirPath + BR); + //Web Path of Root - Relative + System.out.println ("Web Path Root (Relative): " + contextPath); + out.println (FontStart + "Web Path Root (Relative): " + FontEnd + contextPath + BR); + //Web Path of File - Relative and *NOT* including ROOT (!) + System.out.println ("Web Path of File (Relative-no-root): " + contextPathFile); + out.println (FontStart + "Web Path of File (Relative-no-root): " + FontEnd + contextPathFile + BR); + //Web Path of Dir - Relative and *NOT* including ROOT or File Delimiter(!) + System.out.println ("Web Path of Dir (Relative-no-root): " + contextRelativeDirPath); + out.println (FontStart + "Web Path of Dir (Relative-no-root): " + FontEnd + contextRelativeDirPath + BR); + //Full URL: + System.out.println("request URL: " + request.getRequestURL()); + out.println(FontStart + "request URL: " + FontEnd + request.getRequestURL() + BR); + + //System.out.println(request.getRealPath("/")); + + try { + System.out.println ("Current directory's canonical path: " + + directory.getCanonicalPath()); + out.println (FontStart + "Current directory's canonical path: " + + FontEnd + directory.getCanonicalPath() + BR); + System.out.println ("Current directory's absolute path: " + + directory.getAbsolutePath()); + out.println (FontStart + "Current directory's absolute path: " + + FontEnd + directory.getAbsolutePath() + BR); + } catch(Exception e) { + System.out.println("Exceptione is =" + e.getMessage()); + } + + out.println(BR + BR); +} // end of debug if + +//****ways to get the file **** +//1)context.getRequestDispatcher("/").forward(request, response); +//2)File file = new File (currentDirPath + targetFile); +//3)is = getServletContext().getResourceAsStream(contextRelativeDirPath + targetFile); +//4)is = new FileInputStream(currentDirPath + targetFile); +//5)URL url = new URL(URLInitialPath + targetFile); +// URLConnection urlconn = url.openConnection(); +//6)FORWARD (FP) +//6)REDIRECT (FP) + +%> \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/index.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/index.jsp new file mode 100644 index 0000000..3c4ea94 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-200Error/index.jsp @@ -0,0 +1,1315 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Evaluation of OS Command Injection Detection Accuracy - HTTP GET Method + + + +<%@ include file="include.jsp"%> + +<% + String defaultFullOsCommandInputWithoutPrefix = null; + String defaultFullOsCommandInputWithPrefix = null; + String defaultPostfixOsCommandInputWithInitialCommand = null; + String defaultPostfixOsCommandInputWithoutInitialCommand = null; + String defaultEmptyInput = null; + String defaultPartialInput = null; + String defaultPostfixValueInput = null; + String defaultPostfixCommandInput = null; + String defaultInvalidInput = null; + + + boolean isWindows = System.getProperty("os.name").contains("Win"); + + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultFullOsCommandInputWithoutPrefix = "dir"; + defaultFullOsCommandInputWithPrefix = "cmd.exe /c dir"; + + defaultPostfixOsCommandInputWithInitialCommand = "findstr Java"; + defaultPostfixOsCommandInputWithoutInitialCommand = "Java"; + defaultEmptyInput = ""; + defaultPartialInput = "eclipse.ini"; + defaultPostfixValueInput = "Build"; + defaultPostfixCommandInput = " | findstr Build"; + defaultInvalidInput = "dfdflkjsh"; + } else { + defaultFullOsCommandInputWithoutPrefix = "ls"; + defaultFullOsCommandInputWithPrefix = "ls"; + defaultEmptyInput = ""; + defaultPartialInput = "eclipse.ini"; + defaultPostfixValueInput = "Build"; + defaultPostfixCommandInput = " | grep Build"; + defaultInvalidInput = "dfdflkjsh"; + } +%> + +
OS Command Injection Test Cases - HTTP 200 Valid Responses:


+ +
+Injection Contexts Covered:
+1) Initial Statement/Command Context: Default OS Command Input with and without prefix:
+ [windows only: cmd.exe /c ]*OS COMMAND INJECTION*
+2) Internal Statement/Command Context: Input integrated in the middle of a fixed OS command:
+ [windows only: cmd.exe /c ][fixed-os-command ]*INPUT*[ | postfix-fixed-commands]
+ [windows only: cmd.exe /c ][fixed-os-command ]*INPUT*
+3) Internal Statement/Command Context: Input integrated in postfix section of an OS command:
+ [windows only: cmd.exe /c ][fixed-os-command ][ | postfix-fixed-commands ]*INPUT*
+
+
+
+ + + Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default OS command input (with prefix), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Command With PrefixANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): cmd.exe /c dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default EMPTY input (invalid), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default INVALID input (invalid), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default OS command input (no prefix), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Command No PrefixANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): | cat /etc/passwd
+
+
+ + + + Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd
+
+
+ + + + Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd
+
+
+ + + Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default OS command input (with initial postfix command), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Postfix CommandANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default empty input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default invalid input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default OS command input (with initial postfix command), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial OS Postfix CommandANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default empty input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + + Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default invalid input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default PARTIAL input (filename), using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial Command (filename)ANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent14.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent14.txt
+
+
+ + + + + Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default EMPTY input, using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent15.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent15.txt
+
+
+ + + + + Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default INVALID input, using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent16.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent16.txt
+
+
+ + + + + Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent17.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent17.txt
+
+
+ + + + + Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent18.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent18.txt
+
+
+ + + + + Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent19.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent19.txt
+
+
+ + + + + Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent20.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent20.txt
+
+
+ + + + + Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent21.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent21.txt
+
+
+ + + + + Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent22.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent22.txt
+
+
+ + + + Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent23.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent23.txt
+
+
+ + + + Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent24.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent24.txt
+
+
+ + + + Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent25.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent25.txt
+
+
+ + + + Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent26.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent26.txt
+
+
+ + + + Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent27.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent27.txt
+
+
+ + + + Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent28.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent28.txt
+
+
+ + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp new file mode 100644 index 0000000..72f6c7e --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp new file mode 100644 index 0000000..4b68682 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp new file mode 100644 index 0000000..f99c538 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..04d12f8 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..5ec94bb --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | findstr "; + String linuxPrefix = "cat " + defaultFileName + " | grep "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp new file mode 100644 index 0000000..96fa22a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..da38958 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..70849cc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,321 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + String linuxPostfix = "| grep Java"; + String windowsPostfix = "| findstr Java"; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + postfix = windowsPostfix; + } else { + prefix = linuxPrefix; + postfix = linuxPostfix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp new file mode 100644 index 0000000..5a774c0 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp new file mode 100644 index 0000000..fe4d7dc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp new file mode 100644 index 0000000..3a96365 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..89de206 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp new file mode 100644 index 0000000..52ca8d7 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp new file mode 100644 index 0000000..53eca1b --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp new file mode 100644 index 0000000..af5c857 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.PIPE_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp new file mode 100644 index 0000000..5b7f33d --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp new file mode 100644 index 0000000..7f73872 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp new file mode 100644 index 0000000..38e2baa --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_VALIDATION; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..96ace3a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..0ae9ff7 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp new file mode 100644 index 0000000..3873025 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp @@ -0,0 +1,331 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //PIPE_INPUT_VALIDATION, PIPE_INPUT_REMOVAL, AMPERSAND_INPUT_VALIDATION, AMPERSAND_INPUT_REMOVAL + accessRestriction = FileAccessRestriction.AMPERSAND_INPUT_REMOVAL; + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if(accessRestriction == FileAccessRestriction.PIPE_INPUT_VALIDATION) { + if (InputValidator.validatePipe(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.PIPE_INPUT_REMOVAL) { + input = InputValidator.removePipe(input); + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_VALIDATION) { + if (InputValidator.validateAmpersand(input)) { + inputValidationFailure = true; + } + } else if(accessRestriction == FileAccessRestriction.AMPERSAND_INPUT_REMOVAL) { + input = InputValidator.removeAmpersand(input); + } else if(accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..1e25a7c --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp new file mode 100644 index 0000000..75a1365 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c "; + String linuxPrefix = ""; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "cmd.exe /c dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "dir"; + } else { + defaultInput = "ls"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp new file mode 100644 index 0000000..03e4ffc --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.PARTIAL_COMMAND; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp new file mode 100644 index 0000000..1e0d95a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp new file mode 100644 index 0000000..42d8494 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp @@ -0,0 +1,317 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.INVALID_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type "; + String linuxPrefix = "cat "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "eclipse.ini"; + } else { + defaultInput = "eclipse.ini"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "eclipse.ini"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp new file mode 100644 index 0000000..5d0fa4a --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp new file mode 100644 index 0000000..b2bb923 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp @@ -0,0 +1,318 @@ +<%@page import="com.sectooladdict.enums.VulnerabilityType"%> +<%@page import="com.sectooladdict.constants.FileConstants"%> +<%@page import="com.sectooladdict.validators.InputValidator"%> + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +OS Command Injection Test Case + + + + <%@ include file="include.jsp"%> + + <% + //*** Re-define Default Exposure Variables - Per Page *** + + //FULL_COMMAND_WITH_OS_PREFIX, FULL_COMMAND_WITHOUT_OS_PREFIX, INVALID_INPUT , EMPTY_INPUT + //COMMAND_POSTFIX,PARTIAL_COMMAND + defaultInputType = DefaultInputType.EMPTY_INPUT; + + //ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, + //FTP_DIRECTIVE, HTTP_DIRECTIVE, + prefixRequired = PrefixRequirement.NONE; + + //WINDOWS, UNIX + osSimulated = OsType.ANY; + + //Use the default defined in include.jsp + //ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 + //invalidResponseType = ResponseType.ERROR_200; + + //Use the default defined in include.jsp + //CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") + //validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + + //OS_PATH, FILE_DIRECTIVE_URL, FTP_URL, HTTP_URL + //pathType = PathType.OS_PATH; + + %> + <% + String defaultFileName = "eclipse.ini"; + + boolean isWindows = System.getProperty("os.name").contains("Win"); + String windowsPrefix = "cmd.exe /c type " + defaultFileName + " | "; + String linuxPrefix = "cat " + defaultFileName + " | "; + String osCommand = ""; + String defaultInput = ""; + prefix = ""; + postfix = ""; + boolean isCommandError = false; + %> + <% + //First set the prefix according to the path type + if (isWindows) { //If OS Type = Windows Add the cmd prefix + prefix = windowsPrefix; + } else { + prefix = linuxPrefix; + } + + if(debugMode == true) { + System.out.println("*****Initial Prefix*****: " + prefix); + } + + if (defaultInputType == DefaultInputType.FULL_COMMAND_WITH_OS_PREFIX) { + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultInput = "findstr Java"; + } else { + defaultInput = "grep Java"; + } + } else if (defaultInputType == DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX) { + if (isWindows) { + defaultInput = "Java"; + } else { + defaultInput = "Java"; + } + } else if (defaultInputType == DefaultInputType.PARTIAL_COMMAND) { + //Statement structure: command [input] | postfix command + defaultInput = "Java"; + } else if (defaultInputType == DefaultInputType.COMMAND_POSTFIX) { + //Statement structure: command fixed-value | postfix command [input] + defaultInput = "Build"; //keyword in content.ini file for findstr/grep + } else if (defaultInputType == DefaultInputType.EMPTY_INPUT) { + defaultInput = ""; //intentionally flawd/empty input + } else if (defaultInputType == DefaultInputType.INVALID_INPUT) { + defaultInput = "fsdfsas"; //intentionally flawd/empty input + } + + + if(debugMode == true) { + System.out.println("*****default input*****: " + defaultInput); + } + %> + + <% + if (request.getParameter("target") == null) { + %> + <% + if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_TEXT_HTML)) { + %> + + Show Log: +
+
+
+
+
+ + <% + } else if (validResposeStream + .equals(ContentConstants.CONTENT_TYPE_STREAM)) { + %> + + Get Content: +
+
+
+
+
+ + <% + } else { + %> + + Get Content: +
+
+
+
+
+ + <% + } + %> + <% + } else { + + String input = request.getParameter("target"); + + boolean inputValidationFailure = false; + + //*************************** + //* Flawed Input Validation * + //*************************** + //Potential Input Validation / Removal + if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateUnixTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.UNIX_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator.removeUnixTraversal(input); + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_VALIDATION) { + if (InputValidator.validateWindowsTraversal(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.WINDOWS_TRAVESAL_INPUT_REMOVAL) { + input = InputValidator + .removeWindowsTraversal(input); + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_VALIDATION) { + if (InputValidator.validateSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.SLASH_INPUT_REMOVAL) { + input = InputValidator.removeSlash(input); + System.out.println("alskjalsdkjalsdkjalsdkj file: " + input); + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_VALIDATION) { + if (InputValidator.validateBackSlash(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.BACKSLASH_INPUT_REMOVAL) { + input = InputValidator.removeBackSlash(input); + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_VALIDATION) { + if (InputValidator.validateHttp(input)) { + inputValidationFailure = true; + } + } else if (accessRestriction == FileAccessRestriction.HTTP_INPUT_REMOVAL) { + input = InputValidator.removeHttp(input); + } else if (accessRestriction == FileAccessRestriction.WHITE_LIST) { + if (!(input.equals("content.ini") || input.equals("content") + || input.equals("content2.ini") || input.equals("content2") + )) { + inputValidationFailure = true; + } + } + + //*********************** + //* Vulnerability Logic * + //*********************** + BufferedInputStream bis = null; + + try { + + if (inputValidationFailure == true) { + throw new Exception("Input Validation Failure"); + } + + + if (debugMode == true) { + System.out.println("File:" + input); + System.out.println("prefix:" + prefix); + System.out.println("postfix:" + postfix); + System.out.println("Command to run:" + prefix + + input + postfix); + File f = new File("."); + System.out + .println("Current Absolute File Path: " + + f.getAbsolutePath()); + System.out + .println("Current Canonical Dir Path: " + + f.getCanonicalPath()); + } + + java.lang.Process tempProcess = null; + //run the command + try { + tempProcess = Runtime.getRuntime().exec(prefix + input + postfix); + tempProcess.waitFor(); + } catch (Exception e) { + isCommandError = true; + } + + if (!isCommandError) { + + //$$$set valid response content type$$$ + response.setContentType(validResposeStream); + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getInputStream()); + ServletOutputStream ouputStream = response + .getOutputStream(); + byte byteBuffer[] = new byte[8192]; + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + //out.println("
Error Stream:
"); + bis = new BufferedInputStream(tempProcess.getErrorStream()); + while (true) { + int bytesRead = bis.read(byteBuffer); + if (bytesRead < 0) + break; + ouputStream.write(byteBuffer, 0, bytesRead); + } + + ouputStream.flush(); + ouputStream.close(); + + byteBuffer = null; + + } else { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Invalid Input"); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "Content Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Invalid Input"); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } + + } catch (Exception e) { + //set errorneous response content type + //response.setContentType(validResposeStream); + + if (invalidResponseType == ResponseType.ERROR_500) { + response.sendError(500, "Exception details: " + e); + } else if (invalidResponseType == ResponseType.ERROR_404) { + response.sendError(404, "File Not Found"); + } else if (invalidResponseType == ResponseType.REDIRECT_302) { + response.sendRedirect("MissingResource.html"); + } else if (invalidResponseType == ResponseType.ERROR_200) { + out.println("Exception details: " + e); + } else if (invalidResponseType == ResponseType.VALID_200) { + out.println("The information is unavailable at this time.
" + + "Please try again later."); + } else if (invalidResponseType == ResponseType.IDENTICAL_200) { + //return a default empty value (found in the default file) + //if(validResposeStream.equals(ContentConstants.CONTENT_TYPE_TEXT_HTML) ) { + out.println("'input' is not recognized as an internal or external command, operable program or batch file."); + } + out.flush(); + } finally { + try { + bis.close(); + } catch(Exception e) { + //do nothing + } + } + + } //end of if/else block + %> + + + \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/include.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/include.jsp new file mode 100644 index 0000000..a357805 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/include.jsp @@ -0,0 +1,145 @@ +<%@page import="java.io.*" %> +<%@page import="java.net.*" %> +<%@page import="com.sectooladdict.encoders.HtmlEncoder" %> +<%@page import="com.sectooladdict.constants.SystemConstants" %> +<%@page import="com.sectooladdict.constants.FileConstants" %> +<%@page import="com.sectooladdict.constants.ContentConstants" %> +<%@page import="com.sectooladdict.enums.VulnerabilityType" %> +<%@page import="com.sectooladdict.enums.ResponseType" %> +<%@page import="com.sectooladdict.enums.DefaultInputType" %> +<%@page import="com.sectooladdict.enums.FileAccessRestriction" %> +<%@page import="com.sectooladdict.enums.FileInjectionContext" %> +<%@page import="com.sectooladdict.enums.PrefixRequirement" %> +<%@page import="com.sectooladdict.enums.OsType" %> + +<% +//set debug flag from main config +boolean debugMode = SystemConstants.DEBUG_FLAG_DEFAULT_STATE; + +//begin setting group definitions +//-------------------------------- + +//** Set File Access Restriction *** +//NONE, WHITE_LIST, LOCAL_FOLDER_ONLY, PERMISSIONS, +//UNIX_TRAVESAL_INPUT_VALIDATION, UNIX_TRAVESAL_INPUT_REMOVAL, +//WINDOWS_TRAVESAL_INPUT_VALIDATION, WINDOWS_TRAVESAL_INPUT_REMOVAL, +//SLASH_INPUT_VALIDATION, SLASH_INPUT_REMOVAL, +//BACKSLASH_INPUT_VALIDATION, BACKSLASH_INPUT_REMOVAL, +FileAccessRestriction accessRestriction = FileAccessRestriction.NONE; + +//** Set Default Input Format *** +//FULL_PATH_INPUT, RELATIVE_INPUT, INVALID_INPUT, EMPTY_INPUT +DefaultInputType defaultInputType = DefaultInputType.FULL_COMMAND_WITHOUT_OS_PREFIX; + +//set path requirement +//ANY, NONE, SLASH_PREFIX, BACKSLASH_PREFIX, +//FTP_DIRECTIVE, HTTP_DIRECTIVE, +PrefixRequirement prefixRequired = PrefixRequirement.ANY; + +//*** set OS simulation (unix default) *** +//WINDOWS, UNIX +OsType osSimulated = OsType.ANY; + +//*** Set Default Response Type *** +//ERROR_500, ERROR_404, REDIRECT_302, ERROR_200, VALID_200, Identical_200 +ResponseType invalidResponseType = ResponseType.ERROR_500; + +//*** Set Default Content Type *** +//CONTENT_TYPE_TEXT_HTML ("text/html"), CONTENT_TYPE_STREAM ("application/octet-stream") +String validResposeStream = ContentConstants.CONTENT_TYPE_TEXT_HTML; + +//*** Set Default Prefix String *** +String prefix = ""; //"",[cmd.exe /c ] [command] +//*** Set Default Prefix String *** +String postfix = ""; //"",|[command] &[command] >>[command] >[command] <[command] <[command] + +//obtain deliminters and path information +String fileDelimiter = System.getProperty("file.separator"); +String lineDelimiter = System.getProperty("line.separator"); + +//Initial Path/URL: +String DefaultInitialPath = ""; //Empty +//Current User Directory File Object +File directory = new File ("."); +//User Directory Path - Absolute +String userPath = System.getProperty("user.dir"); +///Deployement Path Root - Absolute +String documentRootPath = + getServletConfig().getServletContext().getRealPath(""); +//Relative path of current file - Absolute +String currentFilePath = request.getRealPath(request.getServletPath()); +//Relative path of current directory - Absolute - No Final Line Delimiter +String currentDirPath = request.getRealPath( + (request.getServletPath()).split("/Case")[0]); +//Web Path of Root - Relative +String contextPath = this.getServletContext().getContextPath(); +//Web Path of File - Relative and *NOT* including ROOT (!) +String contextPathFile = request.getServletPath(); +//Web Path of Dir - Relative and *NOT* including ROOT or File Delimiter(!) +String contextRelativeDirPath = (request.getServletPath()).split("/Case")[0]; + +if (debugMode == true) { + String BR = "
"; + String FontStart = ""; + String FontEnd = ""; + + System.out.println ("File delimiter: " + fileDelimiter); + out.println (FontStart + "File delimiter: " + FontEnd + fileDelimiter + BR); + System.out.println ("Line delimiter (encoded):" + HtmlEncoder.htmlEncode(lineDelimiter)); + out.println (FontStart + "Line delimiter (encoded): " + FontEnd + + HtmlEncoder.htmlEncode(HtmlEncoder.htmlEncode(lineDelimiter)) + BR); + + //User Directory Path - Absolute + System.out.println ("User Directory Path (Absolute): " + userPath); + out.println (FontStart + "User Directory Path (Absolute): " + FontEnd + userPath + BR); + ///Deployement Path Root - Absolute + System.out.println ("Deployment Path Root (Absolute): " + documentRootPath); + out.println (FontStart + "Deployment Path Root (Absolute): " + FontEnd + documentRootPath + BR); + //Relative path of current file - Absolute + System.out.println ("Deployment Path Current File (Absolute): " + currentFilePath); + out.println (FontStart + "Deployment Path Current File (Absolute): " + FontEnd + currentFilePath + BR); + //Relative path of current directory - Absolute + System.out.println ("Deployment Path Current Directory (Absolute): " + currentDirPath); + out.println (FontStart + "Deployment Path Current Directory (Absolute): " + FontEnd + currentDirPath + BR); + //Web Path of Root - Relative + System.out.println ("Web Path Root (Relative): " + contextPath); + out.println (FontStart + "Web Path Root (Relative): " + FontEnd + contextPath + BR); + //Web Path of File - Relative and *NOT* including ROOT (!) + System.out.println ("Web Path of File (Relative-no-root): " + contextPathFile); + out.println (FontStart + "Web Path of File (Relative-no-root): " + FontEnd + contextPathFile + BR); + //Web Path of Dir - Relative and *NOT* including ROOT or File Delimiter(!) + System.out.println ("Web Path of Dir (Relative-no-root): " + contextRelativeDirPath); + out.println (FontStart + "Web Path of Dir (Relative-no-root): " + FontEnd + contextRelativeDirPath + BR); + //Full URL: + System.out.println("request URL: " + request.getRequestURL()); + out.println(FontStart + "request URL: " + FontEnd + request.getRequestURL() + BR); + + //System.out.println(request.getRealPath("/")); + + try { + System.out.println ("Current directory's canonical path: " + + directory.getCanonicalPath()); + out.println (FontStart + "Current directory's canonical path: " + + FontEnd + directory.getCanonicalPath() + BR); + System.out.println ("Current directory's absolute path: " + + directory.getAbsolutePath()); + out.println (FontStart + "Current directory's absolute path: " + + FontEnd + directory.getAbsolutePath() + BR); + } catch(Exception e) { + System.out.println("Exceptione is =" + e.getMessage()); + } + + out.println(BR + BR); +} // end of debug if + +//****ways to get the file **** +//1)context.getRequestDispatcher("/").forward(request, response); +//2)File file = new File (currentDirPath + targetFile); +//3)is = getServletContext().getResourceAsStream(contextRelativeDirPath + targetFile); +//4)is = new FileInputStream(currentDirPath + targetFile); +//5)URL url = new URL(URLInitialPath + targetFile); +// URLConnection urlconn = url.openConnection(); +//6)FORWARD (FP) +//6)REDIRECT (FP) + +%> \ No newline at end of file diff --git a/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/index.jsp b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/index.jsp new file mode 100644 index 0000000..7f93792 --- /dev/null +++ b/WebContent/active/OS-Command-Injection/OS-Command-Injection-POST-500Error/index.jsp @@ -0,0 +1,1314 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Evaluation of OS Command Injection Detection Accuracy - HTTP GET Method + + + +<%@ include file="include.jsp"%> + +<% + String defaultFullOsCommandInputWithoutPrefix = null; + String defaultFullOsCommandInputWithPrefix = null; + String defaultPostfixOsCommandInputWithInitialCommand = null; + String defaultPostfixOsCommandInputWithoutInitialCommand = null; + String defaultEmptyInput = null; + String defaultPartialInput = null; + String defaultPostfixValueInput = null; + String defaultPostfixCommandInput = null; + String defaultInvalidInput = null; + + + boolean isWindows = System.getProperty("os.name").contains("Win"); + + if (isWindows) { //If OS Type = Windows Add the cmd prefix + defaultFullOsCommandInputWithoutPrefix = "dir"; + defaultFullOsCommandInputWithPrefix = "cmd.exe /c dir"; + + defaultPostfixOsCommandInputWithInitialCommand = "findstr Java"; + defaultPostfixOsCommandInputWithoutInitialCommand = "Java"; + defaultEmptyInput = ""; + defaultPartialInput = "eclipse.ini"; + defaultPostfixValueInput = "Build"; + defaultPostfixCommandInput = " | findstr Build"; + defaultInvalidInput = "dfdflkjsh"; + } else { + defaultFullOsCommandInputWithoutPrefix = "ls"; + defaultFullOsCommandInputWithPrefix = "ls"; + defaultEmptyInput = ""; + defaultPartialInput = "eclipse.ini"; + defaultPostfixValueInput = "Build"; + defaultPostfixCommandInput = " | grep Build"; + defaultInvalidInput = "dfdflkjsh"; + } +%> + +
OS Command Injection Test Cases - HTTP 200 Valid Responses:


+ +
+Injection Contexts Covered:
+1) Initial Statement/Command Context: Default OS Command Input with and without prefix:
+ [windows only: cmd.exe /c ]*OS COMMAND INJECTION*
+2) Internal Statement/Command Context: Input integrated in the middle of a fixed OS command:
+ [windows only: cmd.exe /c ][fixed-os-command ]*INPUT*[ | postfix-fixed-commands]
+ [windows only: cmd.exe /c ][fixed-os-command ]*INPUT*
+3) Internal Statement/Command Context: Input integrated in postfix section of an OS command:
+ [windows only: cmd.exe /c ][fixed-os-command ][ | postfix-fixed-commands ]*INPUT*
+
+
+
+ + + Case1-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultOsCommandInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default OS command input (with prefix), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Command With PrefixANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): cmd.exe /c dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case2-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default EMPTY input (invalid), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + Case3-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaulInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default INVALID input (invalid), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case4-OSCmdInjection-GenericOS-InitialCommandContext-SimpleStatement-DefaultRelativeOsCommandInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an initial OS command context, with default OS command input (no prefix), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Command No PrefixANYInitial Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): dir c:\secret-directory\
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case5-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): | cat /etc/passwd
+
+
+ + + + Case6-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd
+
+
+ + + + Case7-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\secret-directory\
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd
+
+
+ + + Case8-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-DefaultOsCommandInputWithPrefix-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default OS command input (with initial postfix command), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneFull OS Postfix CommandANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case9-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-EmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default empty input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case10-OSCmdInjection-GenericOS-PostfixCommandContext-SimpleStatement-InvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default invalid input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYPostfix Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): type c:\boot.ini
+ Independent Exploit 2 (Linux): cat /etc/passwd
+
+
+ + + + Case11-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultOsCommandInputWithoutPrefix-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default OS command input (with initial postfix command), using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial OS Postfix CommandANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + Case12-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default empty input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + + Case13-OSCmdInjection-GenericOS-PostfixCommandContextAfterInitialPostfixCommand-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into an postfix OS command context, with default invalid input, using an unrestricted input.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYPostfix Statement/Command (After initial postfix command)NoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): c:\boot.ini
+ Independent Exploit 2 (Windows): eclipse.ini | type c:\boot.ini
+ Independent Exploit 3 (Linux): /etc/passwd
+ Independent Exploit 4 (Linux): eclise.ini | cat /etc/passwd
+
+
+ + + + + Case14-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultPartialInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default PARTIAL input (filename), using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NonePartial Command (filename)ANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent14.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent14.txt
+
+
+ + + + + Case15-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultEmptyInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default EMPTY input, using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneEmpty InputANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent15.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent15.txt
+
+
+ + + + + Case16-OSCmdInjection-GenericOS-MiddleCommandContextBeforePostfix-SimpleStatement-DefaultInvalidInput-NoValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context with predefined search postfix, with default INVALID input, using an unrestricted input.
+ May require blind detection methods (e.g. ping, output file creation, etc)
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()NoneInvalid InputANYMid Statement/Command with Fixed PostfixNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent16.txt"
+ Independent Exploit 2 (Linux): eclipse.ini | cat /etc/passwd >> /var/www/dircontent16.txt
+
+
+ + + + + Case17-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent17.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent17.txt
+
+
+ + + + + Case18-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent18.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent18.txt
+
+
+ + + + + Case19-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with pipe (|) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input ValidationInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent19.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent19.txt
+
+
+ + + + + Case20-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent20.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent20.txt
+
+
+ + + + + Case21-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent21.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent21.txt
+
+
+ + + + + Case22-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-PipeRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with pipe (|) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Pipe Input RemovalInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - encoded & - %26): eclipse.ini %26 dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent22.txt"
+ Independent Exploit 2 (Linux - encoded & - %26): eclipse.ini %26 cat /etc/passwd >> /var/www/dircontent22.txt
+
+
+ + + + Case23-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent23.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent23.txt
+
+
+ + + + Case24-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent24.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent24.txt
+
+
+ + + + Case25-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandValidation.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with ampersand (&) input validation.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input ValidationInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent25.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent25.txt
+
+
+ + + + Case26-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-DefaultPartialInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default PARTIAL input (filename), with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalPartial Command (filename)ANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent26.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent26.txt
+
+
+ + + + Case27-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-EmptyInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default EMPTY input, with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalEmpty InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent27.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent27.txt
+
+
+ + + + Case28-OSCmdInjection-GenericOS-MiddleCommandContext-SimpleStatement-InvalidInput-AmpersandRemoval.jsp
+ OS Command Injection attack abusing string concatenation in the Runtime Class exec method:
+ Injection into the middle of an OS command context, with default INVALID input, with ampersand (&) input removal.
+ + + + + + + + + + + + + +
OS Access Method:Barriers:
Default Input:OS Type:Injection Context:Prefix Requirement:Valid Response Stream:
Runtime.getRuntime().exec("[injection]").waitFor()Ampersand Input RemovalInvalid InputANYMid-End Statement/CommandNoneText/Html
+ + + + + + + +
+ Sample Detection Structures: +
+ [os-command](success)
or + [time-delay os-command] (success)
vs. + [invalid OS command] (failure) +
+ Sample Exploit Structures: +
+ Windows/Linux: [command][attacker host OR sensitive content]
+
+ Examples of Exploits: +
+ Independent Exploit 1 (Windows - |): eclipse.ini | dir c:\ >> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\dircontent28.txt"
+ Independent Exploit 2 (Linux - |): eclipse.ini | cat /etc/passwd >> /var/www/dircontent28.txt
+
+ + + \ No newline at end of file diff --git a/WebContent/active/index-main.jsp b/WebContent/active/index-main.jsp index aeeefc6..745d69d 100644 --- a/WebContent/active/index-main.jsp +++ b/WebContent/active/index-main.jsp @@ -16,6 +16,7 @@ Pages in this section should only contain vulnerabilities detectable by passive
  • Remote File Inclusion
  • Unvalidated Redirect
  • False Positive Test Cases +
  • OS Command Injection Test Cases diff --git a/WebContent/active/index-os-command.jsp b/WebContent/active/index-os-command.jsp new file mode 100644 index 0000000..5d32560 --- /dev/null +++ b/WebContent/active/index-os-command.jsp @@ -0,0 +1,22 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Evaluation of Web Application Scanners Detection Accuracy + + + +

    OS Command Injection - Test Cases:

    + +
    GET Input Vector, Text/HTML Valid Response Stream
    +Evaluation of OS Command Injection Detection Accuracy - GET - Erroneous HTTP 200 Responses

    +Evaluation of OS Command Injection Detection Accuracy - GET - Erroneous HTTP 500 Responses

    + +
    POST Input Vector, Text/HTML Valid Response Stream
    +Evaluation of OS Command Injection Detection Accuracy - POST - HTTP 200 Errors

    +Evaluation of OS Command Injection Detection Accuracy - POST - Erroneous HTTP 500 Responses

    + + + \ No newline at end of file diff --git a/WebContent/images/wavsep-logo.jpg b/WebContent/images/wavsep-logo.jpg new file mode 100644 index 0000000000000000000000000000000000000000..75925e745a6a33a119aadaf3b89f02cd2c086c08 GIT binary patch literal 31580 zcmbTd2{@GD8#g+lgi7`;Mj;8=qbyU&mNdy0Vk+6QCuGcoEZLV3%9JHZO!f$4Us5S+ z$Trq6%vi?D%)E2n{{QPc=Q`*6uIoGJjLU1h^FHs~_w(HM{rrCSeZS1#%o*76YlbF< zFcuaVj0O6EF(+X9umddrUjL2<{=L{({~Zsqv9YopI(X>Ne}36H4j*FYU_W%|FxO!Y z&VMiH-4QO%Bme&Sca#4PJ#dhf^<vA@=`V^8e|;Y=Q9{hCM%^%F1#Ic7TV4m4}7d z0fR$w9{i7Zkg)%Ku^eD!J9vm45`zo6pyoIvJ}WCE^g&2s=;|=&a~K=XLEe)pmk;ro z-(x@J$FCZm`u4EYm5Nq@TffNCYWMvkI5-7`ghfPUPRpK=JFBj7UQ_GBMg6M=hDOFF z*DNfptZi=F+BrRNc5!uc_Xv0t_&6vywndPj{i%&cp$wF{96O|e|oVT2!eiDdDsq~R5`?Z*_{2JAKxj}@WcF9Qr}jza!9G& zA`9I2|HUaNtv)M5`KQ`{H2Z(2Sj7J?&Hhit{x7}8VMkb5pv7b5fgxZFdVbQd`Ga)$ zs@T^4&w~x}SwJGiX12Js{|F+nSqW|WOGh!k`;^hS3Zkx~nAq*fUQ6ptSIdL3Eo_@l zY;f52b|!2FhuX$Wvt!AN?pS)NK?^lUz7so3gp-lsqtrd%0uvUaY08An$E`Q>qrCu4 z%4$1b@aPPxOX+BEpK)EYr*8sx{lHfQKR*}`FB!)t3097<6x(c~F_E9U( zkUD}Vco$jOSi2=mZ;t`m|xla%Z~}uod)+cy3kIHf@T=_qx9V$@F%v~CbE(1SmnUE4A}&FD+Hqxn6nS*%7f}9XNwOfFR$(0kV>-OxQtDKn9>&4-ocF6+mbE0oijm z5Hkfhwq(S%RW%+o$zSGv)_=EyC2A5N2@s#Oery0|d|E*!Y|FB`A2fy}DR9H*;y_Ma z+5yR4Xa-}^5|9c8rq};1{q}e6t`Up^nSqPffzJg8ddXT;$8B66R&TnB^a}Ag%bw&` zWGH`1wX(7@?XYBoTLbGaH$1}2)piU=^2{S_O*S$9CYG(DwuKx1Leo1jJ@ssz{p~MD z&vQ-XAK<`ihn-bwG^F7cP6Pv4LzQNGGVdQiiKt0Rok4Q1o>wRhEnLOuR@F4r%ILF5 z-?}c&VQnqKDjE6nm#Gz1_V2X9YZVbJ-cVolq9R-&VgA`nG zKrHPeeW>qm{99i9OLPdOUQZ-gZ>yULm-s zVQAc^%$g?u4Kim7nzU*b5;#L>PvA*q!i21$p=s^`EW1_$^;ms&^@M@W?BD~CKv~; z2a4qSjxL@gf|17zXEuuoNdZ<)5{SFsI%rv8_5bb8yyfjT2 zZyUXcC0=9C3flVpq(j4(E0GH3gkjsPsieDz`^)%tu4LeX_DqA^fvq{0u);bfY$3w~ z&<2kQG4jy1j}!w5$#C9Aja0D8-u|7HUd&qhb?o(E ziSgNMCzsZ9q;}sqCfT<9E6kLS{q^I9b%mgtZ~#uo8_H2VcdD{{c^o)Z`9@_w?8(e>o`a&(f-~xz{al z>#JWM=kiy7cU_&0!Ff!3OY`yjz-UZSZnxNtD6Q{<=)dbP95(Vtvu`t~`2W)~#k#w1`EOy`*wI5KFrEf8c37a#Jmmx-@n6OJ32z(0me=~B#C%!QZlEfDX zo&ACnL0_TxkObcR6|~nI{jh2?zED;zHtA%x+0$whQ2D-BL;*IRP~3ep&TH27fdiu8 zyIs}I=zwT{?_Sx*6Js)A_J}8E@JrzcFT#Y`s4oNGEQ_5DdXJ^-|0c_lQO4pXF(a2X;nm#-PexQITpSn9baS7c&e2|Bh^Xc8 zPhQK;IMeAdk&tHky(xKFB91OcbEONWgCXGH^qwy^5&jSgY6IAQ#CRwZc8;4;#)SQk zX-HlC-%jCx7&L{FA}ZkEXE;?Ey4z|S6ZYmBZnOtML^(5I`X4o?nXn0X!?w*#Rstx4 zZMDOQEqf7Bv3W|2{A$Gu$0TUCn@7FgTC8s>!^`|sz(0uEkM-RoPs()`x>5JVXvB7y z6XLkB;OC1a71HarAF;*cnwszNq{X z4v?nU`GjD$9NL%HHwDDCe2{25#ju`Ef99 zjD{IzV;0m1sGGAKT?gTFmn0zR4=OM+H3$=~R30FPrXK8SK|5E9|I1@iQ12TrvrzQS z=F`H-gQ&4^X~b!(mrR+3irw{wCFYOFkVc|8z06mu!Ec;WI2Kh zcA}j)+IkzUB$((_6ub_aahpY$^&ZReWy0J)!RB9yncUUcREz8>xf>k+cjRrXgewEY zVxKTFnXpKsX4x7-45$S5XMvJFlf8wWG(acl)~UT|%4>|1Rn31n=J%`raJ$a%1D_nVu5 zRhwXq8ch7@8n)|gI>U8=;qjY8y~5tUX1F6RwX5(;eap>5CbFM8u_xiR8zd?Gzn!qA zI|=LIBV=ph6+mR%{nP47&GM<;Mgy2(of3 zv=e1JRVPcRnLq2&rzEk8BN1WdSvPEN?kEb4Cjci>IsT3iG9C-VGfWSpyN?jI2O%6l zAT-??Qal;aJ0ELoFL_2yWxkf(!Y&cS+LeUB>TBG%lqZucH!qab64$Z!;gyNUWXvTI&bQ`bnzdivaapCvjeX==qf^v2OQ@MX`fUGQi+FziXO z2RTghfm4bX-CTfB;-pjimYKqr=D|fI<9#K|u;uAD6|m5bP@82QFuL0Qh%*M-)LV%- zfk8(`5y(kr^6l^vTEy7KQmDZ+$0Ui+AM$){Hn#BBK$KQQ_W}9p>l;sYDf0%dtD|}em!_Cixa>6Y9O-(9j5o% zvs-nS3Cr9dZ8$D4VQfW=+&RVv2qYI{59_h?6;7<2znGQqa3iox)BN+jqd&4AkisyD zuhzd8m9=otuSRV+%4uqK6Sna~1VFu*`f#W*h=v8SsJM~Fqv9hmWJnh^JNNzJE=yZa zq0Mf7jE!r6OG8ARL+P2Gy`iDo3fL>f>!~F3-d*J0x`+Nx#@P#c{}9u6)MdqJEce_U zO_CCYaE0-b;EEIme_>>+gwE@6lXs@xQ(fk-_(%w64~*T3teN*sEooioKJ+DpLzq=# zFN6tWzXFb8#K^L1Sp{I1qd3J$HV*BBAM@WE{V`XU`yF{E(m7pW zdPC_rH9Vc_gMBi9W7vlo?UazvV#F|`);iqrhmUI0jXn*L6wYmAWIeRelnapNNqv>J z>h5oN2=Unea@YNFWh3qLxo-a4*-xjpCK;F-20OO30$07BMaiPF)-zsv7e8Iaa_r>h zx;!zw5u)$?D2AI5mD@mp%bBQmA(Ql_l-r~x^dhF)9lwVh&l7RZD^~^ zw0wZfHfDck^d4@~_=P!td$h z+reHt@`M_}u2NUAHVZe_J`0b`q7dyk(?MbUA34Nu-AJ<`9o&aKvIOmF3Q%GG;9>?1HzYLj1wuhJN9|-u8!nsXw@%jHVYa zFg#~A08LYB@(@M^Y}F)iplyh?%_Dl^K+5k4yZ&@_(W?}Whr7HNP|6M+k+L3_gr4%- zOsPJi6UuI_9K3Lm32TYj`2Z~l^u4zNnXqu~RV!BzH*5BgeF;fFkwsY?o!wnS7NQT- z5;(9Fv5tze?^Rd3zYjjzqCSuNEGfm6UcB=||NKQ>1c%e7IBmkLu;>64@W#x%C@=Q3F17K3S^q5aPbi@2oZiTO-od86Hco-$C%3 z+((Q!{`ofG^|*J-@l0c`|4d5TAEyMHSv;Ljo9c(CL6T<4yR#0|Y@d+Aa|FQ>qOg*p zsAq^eO^RAVe0k()y22Hh{lfIc$Wiuv)6~5AcCIsj_+@*i7ZGzNw~r_Z0FnCSpr}Bk zC{SP#*LQ6|!THM&-u0nOBTs>L&(zoVCRBkv6&mEttseAHN-~KF<03eF>Csxj6PhRO zJI$wbo|NsMWD7A67E@O^=4)qov)*l!lD7+T&C$$PRfA&;7%6l(Q9jpGc+C(`TvlAV zdG0}wb9LPd?w29=HD7j3%ZL1I<}i@jx;9rl2dcM};2luGkyf86$C^qU98r@$wj8D= z?=+_M%k$b!{$3b+E?ps==I?nfctrV%ApLgE&-$|!3$IvKJeQTmwm=Rw+Cy+)|7cwz zT6fk=w!IlX|B z1)u1Nm~Yrtz1Px=7*JHlTNr+5VkVLayZ&8WZH@^W_W^H-5U2O&Jeja}eI5))C{zRu z+s_JhJPi#_>LW0eJ?L*3#fXKId5TO}xgcTxVJ&`y8_)~|O@uml3OU>SgzXQq%P}wVn6TYn1z(X^+VWtjS{Fu%ywN^=$fFrS!4xWN zzveT8F0lCGHr63XE-;ZIU9$ZYcY~kTujO>}$}MxVx(CTiIgcD{-(S)6xtjLHYb|Zv zZO>!_N<)b16heDob0T^aP8Xno9NnkZ;nih$)V@%S5@=YAZJ$QWyuxn#*Af7v2bP}b z7(^XGGGUk1nJ}^z6P67H&J`gs?9Wm@D9D|~Zpscg-hx2)v|+OgbfWW2GRRRyIhu80 zx*+fZ6ZWz*0~*YYhCYH)FTcJ*sApEUgbCZ!2)3c~*Zs>#@S~qFVjA7axLHIOpb>_( z^iuxqPFWuPncY}+ZNy!9v*o?Y3GY9tgW|z@k9~3%tW;lJJsBJ6&1WKKNc!9)SUf~l zI_QVtOZ5M`Q~8zrOojhW;quTmIm>vjIx*?YvL;@{X@y?p2YE|-IW%qXupW}G`K9|e zaF)h|8S0}%>`x|%#|-W4=g`!^!w4o!7SfO^gTgNNcv8R0jH+P20kY+KODt}n>EoeidX-0v`CR{%}7a+M>wK- z`?I;4!or+^>B}t7FAxQ}rDw!BVAB?HdtK5t|6xh0uU|3||F`wm1BbG~&pY^b9H0PS zi+qde#nnjLz>h*SAZw;y#9jt`?(W4G>m{4);V^O1^+HFkOG{h+|GW}19AB0fv2SAH0eD3pm_y(<8LYU@AzhOHh#b#xyN^pu=)qF z{Q`T|Z-bt70nc~_Ird-`M3b7-=G)@VykY$x?8xSS5GHk4MP24ZMGpNG6gdi*Fy{>} zx+0^PE<-a9_MaV@BSvTF*4DYTq*A}DC`#H!N`#Y^!q4wdq|=SyUo!Tf*vPI<7t19g z>3oNLVy%N}Q%uRUZo3;5DtV^{?%4m>C{|bbL@R7sQ$0bxDjnD<`w8AJjSFVNaCXaj zhv-%WfCsuq3-*M1lZ5V-rPitQ13SMJT>MLXsX-?G6%{9*Ucbb*afkljA?37ITd6Md zs(#{G82I&f#C*~c-9rR1fy z@wVE!XC$qj&(SxZJX*fU?JG>XwnS^+8-Bz}p@GM~GD_6#5zi!88PC<@6IL2(-=Q7K z9%c`}sSZD<=q2#t-UE}Ow1rQ|uOoNoQas6|1`O-|C=^7Rw*W=W>jA&9c6o0CMW@^9t8rty?YI*Y zxBlcwQj+T4l)Y=Ey&EihlpA?^ZGK(!LxNMXQb}(&FXk^EN*#^QfgBS)WLEI73|Wo( zoY2&a>yVHHk^}J5_68!Jo}s#-*AqHA2{F4D&*k5O+x{@RO@DnIu8)g(R?r+RXw=wyoa-@`W$g`{s3mn{>~k>ryS08SAwrG$cUe# zn^3}=?GDhc)RGLyv$tX;&ZP?wCxNb`ux{xuY@Qzq8|=R!8EW?Z%EuN|P{Z$n&dm)7RmgKKPc}MGVxAQDC+EWp?yT6=79sxB)I^-mw6z~I7slN~bxz08or%a; zPVi<_?&*2`T}dKJpne|+oyGrFS>&GR=#;WlzC9ppe!?5&5q zh@T-=7$ZyePIXrZNB`Y1o*MqT$)Pe)y>-`B&ty&nzo050@A3YI?^BobC%><1e*D$) zBR=hevBWz<5f(VlI%AgHh6QBKB~!%D(N}TL9U&TW`An#}*hDvfyIGR>q=VmGXEq9$ z@_PsIeL4!wMMTBvDGfA>1gn`qr2aNVu;5sB(e0L~yv0SLLEM?4BWd5(-?01{rOMGx z(*=CS@Khw=MbkEYKjCOPW$K2bhjZUWUqcPw#+cd_3gf; zf7l=xnv=4PxR!)$!1f0q-(OzKWXueq|b3(&hDaOR11hf?R`xgaN!!slRS zw)BfGRf6MilZ;=f`Ei&GA%GY}Ww@7*adbrA^iv9J$@BVRb%APFVN<@uF_8TmC;uhH7G z+Fl4tPvhScj#I*0p<1>VCe$}{J|ngUg<0cF9EnDom&MrYY#gI5iIvb8&QBT~wqWH&#voYmL1c$Kfi2Xh`5pxq-t`d0l zw`Mg!j>1a4I*Okaa^xRXtRWqBB^Z3S7D3iD_gpC zB8+t+u#wb$%4F5`TOgxuZa`@x#Qx3M*@F&ttUkRnj zzlnP#Ui&OzE4i=tzoc*HE|kb+!Vb-%(byPx?c)lvtkvjsJ8TD>%Q*9~sSmDt<+1c1 z{j8O6ucS9mo|+!nswMb(^UGJ3J~-5(wK_t`Odgw?D^9|?Ad;u}p{f*_7(8l2uB{R$ zH6X$AM=Y7QQ76{Y&IeBjYu}lPj6@B2XA>2bfVbYxP?>|%7*IC zp1sy;yIV)h1cQIOTK~AjW_Ojlr9T0|t7AaPCGI|NRt^5#qJb1x9nEPj%&Z_i_xARd z&U1*A<;g7?gkAhTcg;1J_*hwo( ze-ka(ku+oerwlJ>&vu2V*~RX*<_nDKz}hdOQQI4{4xE!jIo@&EG4FHdSfqBpEbtf> z`F(0VBc0g>7IYcss1~Qpu~YEMj7Y5OW5x@_eW>9F zQ>;FzMl8BVB>28H()#`ceeXJ@bo-oI^7UcG6 zR?c%sJ&qU&QGAO6j+h$~$fA_cBwR8uI*1}$Bg1V_2beH#CQSHQdRR>SI`aAUK=;yE zi2C=lpVkc8?y&UkUCEp0&i1|t306X&7OR@W|!(&{|*^{VlUXl=TLgl*nZ~Ua({fL9cig#}p7`GL=Df6==u>20S*?K*T z7XY$a9OVXe0%s=8KGuW@nMXiOs?qA!-OtfbE(3P=^4YJ)4of8&VDiBZ1lcY*W?G<3 zoe+(viJI3tLAj*Q)~t|`A8FD&o^AW?ejn9DO!!_T&)wVV_nvtirnziDD>sE0sa)Ey zQw+Kn<|xX;3Bu_*WY;zn8@Eh0!Pew+wKe2_r!uQ|<`G zhv8cTfkx*V%qMK?m+4L8W@+s2Zm9Ne`CVDkbA03SUj9+7C6n2%xmrz0~c)QN}H~;W9;-~ zWx~!TeE$~W^%vw0f_xfuDSS^-o8Lx+5VDKs_eDW3d-%#10JrnUPEIxKsNw-mn(Y6R z8qIn9&*#Qw`}ZUu5APzV&CtyuxdI_O9nA)fNaFnFsGqKTd02?ylFgO&pg(aas`fN? zxeG6be*pRUb8PP}{T9?KF!hg?X#`JVH5U<^%4OgM3{=~(_-p~1ByclAikPrMsSzd& za-In#;>MaOC0tL6uGb`#V>K?VCq@4L?PKkDHK#pG4=wHVqRLm6Gaclf0V#;TK6(7s zxzyI6#C_EKI~zqIdCkDoS%-^X zw^K*l%F;BULd=WN1z#ds+pF!oXYZG(sW0><BlWFU({dz=s zhPpID(D$6_2efXuSx_&MKOR+m4kw1CS}JHBSI{_-a&g96WIx$%|A$hVuWOzSz9N{6?`kGm5Ye`eU&$g_(-be!*bPTZ8JO zLj{vZgwpMeGq*I^CGJe!36GI{FO?$y>#q}BOM>_mk(A8uCfff@$Kri3q9X^LnUk3n zC{xBLBs}3r9TPvM)#EJ5kXL35qO71WHTG1Ivm-gQqZ;xPOyyuni$@fgYt58~tPkk6SgCqyi?Ejo{^du#Y`p!I2< zcBbj#Wl@ZedY7&|Ig~R%iA#F61e9(Qh(R65!*nqqu$=A)M3%(sa~?8 z=q;650VwinCqblH1+bW@drC?R^XVL)tW7SM=u=LV`BI-P8D*Qy$<@=C_d3)%G;p2@ z0UR11c$kHzeFyvrCtFQN?Ja3zc(U|$_&u?@?Xb24|0BZ?B&zcn#cVI30lJ4!ua{P zU)iL1f`wFGlb#c5yf^jcH&XxC->gko$?3ZOH7Jl(W|3+rMpSfsyO5|sOf=o^{pGi} zCskY>6qiCC!llz%NfI0^veH_zIbI%8J@hA|9o8>pcIU zu-0@_a7aSs_a1xR8=gO|anPmHSmAOVZJHkXBqJ|6?qjpmzXEhDW(vL-`!_S*TZ$FY z%_zSS8X`49I4BG&JT|-!!8LX#`rT>@fzCgt57-m{HS45C0dm(@F@}O>Z}Ezaji#n5 zWo*7COgEW!Qhtl0L35Pu9(XqykDYl6ui6I(ppAVaI!BzE8>p8%!>~pQdIXF&l+=Jf zp8lE8_FjqJc{nF|z&NW;8f!6^kgSi2#*$s}Epq2DifC8HhaFwjP4!RYovdfuo|Vt+ z|A;-uj0J~RMNk-N9jOtQUiqu_ue(w-M?P>FN*g|b7a7i^Kz6V5Uw%Xk71PyQXTomP zCkZQ(a%^3*+X}B0D||!3Skg>p0(H+Ub2(9x!DFu&<<;CgD_CwQU?UE#`1Sj}L75Vf zqTN(Sucfp@@i!7ozHEf3Ied9HaK4YDUz)pnPw(&kXc=Y#UhTC(3ZdBt)2J!+Uz#$f zJ0;FE)c+d2^_(|YeKZ9z@a;Uo^)tIP|sJ?pr>2osL3VOb3+Jt*rHp@fFz zQj?)Kh4eGzsE(@6cWyZV_kDU<~@ zR$P*)ZIDg5V&opELrPfcIT3_kEcdH<>~pj_^>a|G)c(!kmzgn;QyXuLdrwoLjW!~K zt_IAO|44Q7Ta_yWqD|KG&NzJ{*i_|(oIl`j*S53g%3+uAC&v$i#kp@TtZ3U%O3%#W zs75>Z6)ebcnRYiglse6Ls>4o68|@gi!^J+_e*Xw5Zi+pebm zm#1;>^e#eq+kWXW%Nsv^J(FSDQv@7FD z8Ab5p?q)LCuLnZe?ei;+l`2$pDt^A#!zb}31)D4P(&thCSwpNHSm$(EX5gKX!Xe}c z;pH@Nh6!7P+6*g-NlkP3rz3nO=i={$9vzJ?4tBVj6V`!2OR8Y{2MMV!L9o_|>4@ltyIbZ^;-Pcv0@ zR}MpYv*{;kJ-7<1I#EQh#tPg4}V_U`bUj&`rWT#xa* z;=2%7iXx1W{(Hb!>c+>JV_~ZlsN=~USn`@fjO(|;t4Ob#K2`*4x9y5X%~R@CWu^+w zMu!iP&$l~!&m`r~EWN=`h{)Dd`qX&vp4I1L&o1utuTVrxH{|`VRO9q&@m1VSt#TV@vSwu`}`5 zs@L5l$U+Yak+0r*PN+h2`=alCF!l1U=oS9-$n)U?@tLWneAT3DYOfL=pqu_Xa0~&Q zZ>L%e)7i;Fo!FZGc*RGHdfE+Unr$DYtQ#V_euO@2xIg#8q+GzJPwPUp^@W3OtlL#L zQ%p~j$M$Swhvstn{0$H5aswmJI$l7KH_ub=21HGu4B)&E0CBuE){mI+Y0kAqQ*!^! zXt)?~*&BYX`m=MAuHBT?AybQ!aOvCveLl6r?LyY$(yFpV$6}v=d!grYv7QP-$Bl2f zxg?Ytel>Q!YsAJA!F`JGj-x>fg2Oxb41^CiAVX-yPTaUaw<+j%otZu%Qjmt^AN$*O z86C&@a{Zo-!HX0_X(*laMJVk}NebeaD=p*o<5>LzPv-+tN17uUg%Fs?h1VLb)n+{@ zPHq-6`>_1@nxhXd;K?}OVOUaM^w^5`Qe?{YUbxgC8+|uGUAFLRK+E2jpX{MzE@}dwpNi3$phkJhuc_2?JH-pHpLXlAc+1 z-;>&x8_*zecY-2Sl&q+l&`^ewMRn2=vZ>~UPSEk5FKGr+A2K8(H>~Dqq<;(rg2Wm? z2JI+jioo+9JpJ5S&8&1)v^e}6-X7#t;?(ySy&&+jB#%E`{>0ZSdX~l63(s6R{SnR> z0lE!Ywi_G0Z_^32D%mV9T^&{b72q}>@oV8)qff+@o+J?w|HqY|NS10_Thv!j9U(fn z4*YD#g#E1?C)`HNOm6H+qj(W(PLKotI*LkX!m5|(g=(FIoi-?SZk9Q`-wL6&4Q%fz zAQi%J;#pv<2LNrfn~uLAuLsTS++{c6+HiHU738U|X5`6Dq9)&r$&@*mqn^b*w^uCaU(1(#u}XGcMzAyrr~YkMUzjRm9#h;Wfqp z+uA0H8!u?}K4e6f)X$ryFal7rU7zo0C`9-_<3;}(lNn-UwdhQ%cLK?V8R)A^a90bH z8)j(TTsPo!b1xKgp?$cQfnYqhnci0w1;+p9bM(F##C#~!@E}U>Uq$g_=OvVJX>0V#k(;@@y z(>9N%AWukJCfHAto3-Zt(2}dP<^s-VomzNyD(9KN`dY5{MyXfbgIW`5X_hq4O?~j# zF<`YIxNojF5_4dgR|M6XY2mQyU(`CDr8#A4#ASF%EKOJ{MOik!(J#7x9813056Bs{ zCI9}?8Z;$380Z;>B8o5M9_4GVB@xy>_HEvooMTv;epc3x$;zkH50W=J^OPyB9g3LM zu4ZkDIJK;FMe~X$N&nX85SP3wzyExjPw!@(fcYLoV^1tq3yLfZIV_y6Z%hj^9j?Zu z*{x$1wgbsq$|bqoaVph+59pRWsln~57Y^CSHMAeaW(^v7@C;xuhvZu289!Yx7k`w? zT2qx2wWc95@MGy)FDuuH&Q=|H!$i6U6;2lqpqVe@c$hG^=>uRdMuOm)KHHqRpA~!E z=7V^J=nwlLj!@uEOmOpvY9)5A$?T3i;oyt$UY@E9r zfP73RiWlt)3G<5XK`D-V26vC_-W}ILx!x37+xL8Zak|)Ie!MgN&-`xDPwrP@cqsiy zgP7`}6!fvWL4s?49ICo$?Wbt~9?0)+e@qd(w`i{z^|?MHQ~yV=y?Ly_376k|c`Cr; zNh~)7zY+i*Zl$ROr&F&&-*^|T2&l}38qbWTo8YWQW(7(7Dg9VKnVASHZ}e}cJS`{z z@Psc(<%V|n_MY@o-a7)08@NcI-mV6WXzqX$_3gm9vA4jNf{QE1ztR$d_ARZc<-I?y zXf$S`&gpGl=$#B_utTXw45VJ`5P}6ojG^_`z4ayIs1pN%AUd`w!bN~n9jRIee)B0A3}hL_Kop?juDdp z=h>3L%ZiPOPrH_`f2qE8!%*4v`?a4?f7u;`yAL<`8%u^VOL4er%_zNZ`;Ns#p^9JY zWx|z?w|{pYO|0pW1)sEgoyhC#A)&N>+&Q^PdEJg5DfTAB03)MqxMva<7;l=-28YhL zwwobHcDwN!6K3+)o|OuyAyvDIs1a6&)~fE3ZX!LbKfwog>BqIHLGe@{XgSQ$=LVJ3 z<+UA9ojKR@&JM3DUi$ub=z(Xv`vb{WpDR7Jl6_Czyd=d6rMrnfW#(j5q>dtay44QR zj%Qu|TfE$GEY^u{NIQB^|zsi1ZHON<9I7Z zHnh3qiPl9mikF)>6S-se3nj#=^9C6A^SF$-{X!)5Gtj~FC=~nM<{;E{&(GjiJut;CWl^OTvgHXD;6-AgSfEYfZwMl+P zvqfoKeOW@_X95#8mUADlFsa{c+?&t4-sk7GsrMjtV$mt_w=j%lu#SG>AmqML&~}y3 zo{nc6-sdJTv}}4HjPRfOmstZ;w`p^wy5gE}`o~|E|Gd!OjbzOjrY=3{#J7 zeLr2J@gs@?Ckn0IBkJCA8Qcjwhu{Y=a^5^n5i9ITBjmGAkJ7%Ms7>(o73_HxsIe!e zgxxjTDW_5O7;gjn$CRk`Kp4%`4ds^FC`L35ySDOUz#z$V)hg9`aY*|B-;X-?e8tG{ zle+KiJY*^u0h5x6g$Y=$)cs*6h$bPEtp)>EWk%J*u8H-T4)IMmOc+aCnDeW55HUGY zc>FS3#8G9&bcfZB$nk&^&G&aKQujvZmFOpSX}Wz91>_AX{@0`I><1BZZR0z$pHb&j zqfNiC-3FN?};WUp2i!zG*dJ6Y;?TJUDZR6 zpXZzT+%SolK{D3TQNt-lAG>A9$`--vxD5YRIQ^svdK_zxG6f$ipsoT=6ew?KU0E@> zhPLu?FP-+V-SqmXq~;o=#xwYU?`sS7EVou?$dRTe!`j0N{Ol83O5c-S#iha_07nrSBj^nZ^9=!0tacaNcJuYL8y=pYSYW>%`u&j5E$(lpgMFMI zCL|cDnt0G@Sp=vz(n)Ht`n6Ms9SI+!e)PO&-^AFn^O>0yA~HFKz8_-a`&1NQtZByh z6+Wsbz&$%X7C?PW#;tA5`gxB`@&7Dalc}$*Ij*?SrnIphci?g3pook&^83m8SLp!c zd~64S12|#G2@5VFlLJi+)6Iau{K?e;_GDl zrmOou-9xvBlhRGNN(@o;VA$$^sL{wXLI9mM5_+`b+>=!L%KnjJO(Q1k(MVYLl+PP5 zBW4Dkgym>H3zT;19U|K#oU9+w5if1dB_37$R4160WHrXopE>s;#o7LdTD|bOh5wE^ zrM508XZ|)%AXRMPfnWQ9!>#z22)7MDhI`GNrq6h{O;?IX;Eb_L2F9+@IJd1xo z-W$}hDxOfix~@hmnd=h^F&5!8l}}g;Ix~y$Z=jJ-1Bedfp7#RKQ3WeS|iMsM&_HHJORfBQwLG4d(uNuVzQzj0DSL^-$1`CvB=|m*dX>Zd+%uvVU=Uzi7MO9B!Hd^s;5A-*wqq+19UDBs zKDG^mJ6zl`4a1#@j06%tbx4OmAMC^AI7BcL_H73XZ8;7l zP%UO0UR%eIFzSTU&p{Fbq>zl_eH_4tRl8-g^`UFdi*AdZLDKtoj*>xrh|`QgPndiT z*^_{x@zJ+5PwcOGv^n&E6vTd*u%uBr3Of#PO`)HaW)MJMwEd zKoSZTxIrfDcLtO%EjWo!Ed5`cH2uFQOFG2}G#l}RK&$H>y!w&(fBN!5<}hkds0ar; zvB&84?}LT9Ai9Z*el%%+?MtZFm9~}T=ZXur^repY8p?|@VIXHb+wV-B*y(T(pqFxXIn(Eu-c=3#01DxN+QbZznX(@+(I69i})v&Qyx#6CjQ*HVRa>9^Mb-} zE7$`vOdR&H9))OOR`=v8!i(G-}Jtlk)Np( z8Cf%wq$^M3$1kyh#|!~YKXL)c*-2F5De6qAqKrm8>gTZ?x3%BH7&@I--FpdBPu9b! z7bYzIVB0ji`V>&7r0F8MUYD;v8GT+8Pv8wsx2Y!#DXl;F+}zysx+rJS)x|Z<=)Udb z%e32RCerEGbwS+RP0fGYsrZdVJdK}z1Ua5g{RITjH1AAIH5JFB?Tc@(_}sNL6^Q?H zrXj=B?Mi$*qE4saN zpTE}g(LLUD9i)V#c}o!o$&QNuAKyKOure^4U0w`B>}GR#7^;E@i>I-l05s?oT3 z+IIBFVb%-c_5A{T2bI#^r1+~%l!ZYacrX@_38g^^>DF7#8UW|2d0j)&R=1`oqcAh` zop9Q;mDLb2%7&G3%i-hIB#zj*xV`LVNGsj%&Qyb+AOFL4pvM6;+GhsnP$ntjqbx9$rst{I9*d)?3&zo=2s|4`#I{L@{poAt6V7_!EQZnjf$ z76Bo2H??eFkb<}Zh>Xcb$EoNVH~1*~)RdgKDM+%NnbCQln3rW+Xi2fTgJ# zU}dIx&_P6G9H=`2o&`oI-hp^tkI{?oN*}TBPvkzgvqe!J%Q9iZs5%rmV47qg+m0P8 zZX;CUV>J3+1}cfK`e4gjor9n1WjrVh;d`Uq))%18dy@9?;k?L9Byc~_Y-cdtW)cd zzNyzgR#YpqIV|{N#-b4NqYGexl)lfRoYax}mVU8%hWtLX;YYy1{!Hkp?K(Oi>ufXb zeD=L#B}9fYP-Rp9NdYr59-mFhyV8Q8JWPD00Bcd6d-b4NZ2$#wKtPX;ESU`4?T^GI zx0}gBjnpdw(Cq>s5w%SalyC$DM9E`+QS@ZT5vag)={1%W`Cj7OH2DS!khNt8m8E7z zQTwN#*f3#IqwUbOz7S$8raF^1=zRBS#O}2@nl`}Rvfmv}H-ERXUo;)1!{h1{`2KgV z+HVuj#Rr(a z%^g~$kFBVxUP?*rnLpOuKMIJ~3;(4jN@!7XA=>jX;J7A<3@*9EOvx z<2jc#FE&-@NdvCD!KRLtalbq6#to_7R_@h~v{ev$bwa&VvSlKi8V*%W@Jk!u(O|~A z^jRg+=tuBJPI5h* zw4XU$Sy}f>#~{Fuh~m^QKGn_k#Cc(;>x{KBHfX-m^w2TH&^oIp=U(3b(b}7bL-~ep z<4Qu3kiASQg6OvpZyjHhPl zy+7ag_dR~U-}}Db<9+{l|8O`C$Kjc0?&rGi>%7kEyw2x4Zwq(hS2<`9oTV`XQ`_-- z=u&GgxgMi^@T8)C%1i)N&R9>(!Lc}J;MMS*J5No0Y!8w#r#!MudFC}H|13k{DM6d%M-5%V48G?)1Oa)K<2e;F z3iN&Vfk25sMS)x-Uab}3ED(0Krd(_#;PI`ry_Et3>pu5v74|Mh^37aO2^}6p-V)%v z25gic;-2?)iqxw6TQ-5Anc?eE#I_uDNoluuAdqTaX`DED@rm1^f~;RZt-k+!ar+^j z^Fb*?>3dEdSN9U7t8HT+`v_!5*@(c4#Lxx}Prk8VvcGZ7)G1|h_P|qR_2~*h*`GnW zcmiOi;nkl?w5GxDEhC;&3dzqLU16op8S4b%<2MoNpUvjZaQ!bK_(&Lp4Ae#;vk#v*9oYZjWcdzKe4oHQz>Z5XkK*px!MO93ilAr`pA|H! z{yYDpdrV|PYZuszUWnUBnMt!is+RQ1>;eC0YqevIdWMN@hWovmzcn(uB`{zIhP4n{ z&aRf`H%2j^q|E2ua;=MMt^X$odFG~;XG!Y%`R(!!g9tutJJN35SN?m})$O{slS!RV z5SK`304p^colio95c($b8st~(k?L8SIyDPrwzZ*3D9-n==CNtLj)WMjuso&ic zd(ZAg=z{L@=*d!{X9xD5Q`2XJHMq(@zAb(&CqwM`SM7JFxIyKE1n96*!P#3W>JxqgtX zUYG4pl%Aca8((ulZNwky;0i7}F_uq$xC}2hY9U8g~qA`&4JsD>T zx|oT*e|awJ;*1EtweADWRNe0@+^8PJyc|e?%>O5lB|xE1IG9I z84MRk_&x;uLXt*ER0C`Y7>kFo^Dq77Nh7}a%fr|wOBh%rarXmeFkK>>24J0? zQHoZU))NFB_FtYx??^^}hyIHf7wr-g%?Nv{8F^sNFL>2qSE&BFp)UO5i|CFe`{J$bm zJNzbAEq*&JQ)>pcH9+`v1X*CQZNhnk;s{uuS;vFPH$cSx|CCt2v$+C`e|e6LLxI0W zNWa#CP*=u&S(*LiQSj2^1V?dGl76z12;V>U5mt|qxUT^5F0n*Bdf=)N&!M*|&-hWB zeNJpoMCBA{Od*E9@!^uL8k-cAz})Kob(tv6U9AOPF#TIPJ5Y+lHeCez4WJL}YAuIU zVKI$IXj%tw7LD}8Vv2!U@9E~jM<3i%t?OPYo9sgyu-IE zzDh(}eZm96tzDVCi}ZtmyAHyE1B%XrMcG_oRY<{jfOQutWPH;gK=b%8?ih-G4LP36 zlz@`vv?3AJ^zCyNM0mpsNIV6}AE zx||Y2QI-@`*U3e;Bcju#GMc5oQESqXa3Nc_ESuzEi3qPSr~J>eSHr%Csd_#6Sq>@p zv&A+kNI)-Bx?&9F=8_~WsZPia*-7VR_>p0CmoUmdvC5_zrU}u<7c_sf?juUxSie<-3$SPhslEFT_A;!Yue^H1r&5DGdg)s-|!>fHDT z8$h!QH?RBnv=d!?v?0y)QH)~rsfyzV-aXj2Qw)3H({C5<9&q08+7E$dCGcQ)vqrez zhoRlepId=&C%yBWChz~zZ7g~GteI%7sg)cF#;q3_lkj{WQ!(QSK0D-bg)^?$slAEu z?|6^%ma+H>PR`>C(o%UDx!fasknA*Z3ekarkpFQ(RZbMiRqHA2Jz}+q(m#QrXzSGD zBR$FJ5lxq?zQxX_3wG=IYHXyU*lw$lJx|syI8Sk20gl6ve*q1+2QS2=0|m8u33NLO znQx)G*Ph$6hv<=cHnM4Dp?e?BnpPqY?oqJIkC9$aLw;H5e4Mjq{{5j^lcJ)ZdV1$p z7EATGdvaOo%a7|;S8`3}NU}<#>a~QCu_rHDcfy8yH$#fi=J(Eal^y2rf&c%{5>H z1!I)iP@_69PYAo#bXeqgKr!HSDQEmc%+DdrGupF$omLADSQOl4>~X+MF~F!-zP0eV zNH1z1$lxW2s?KbxB{*!|*G^HrU9Qv&AI`QOBvh_ZSYCpM-NV0_>6tWLaO&+@|NPx% z*($TpBTGKUox+i_sHv@w*nXu1s(zxpAZGDqiu4+grZhzfry`BA6(B#ATI9XXe9R48a&xv3!w z`;TSo30%>as?KH?$_}4KSsh*qYATm2JOHV%yznFP$2mpog!{totz$Xr>66}E}FmWo)?rmt33173j32E-$@u zz%?Q;%5w-_h^ZCkZB7gv&X(ll;MF0a4yiv~T?C1`s76Kqe=Y&viVO=s7ccv@g8G=; zB>Zc^FKD$psQJ&U8J_sN~!NIv*5=uUFpv4r}@4FGAvz%kx}&=Eexj2)@b3jfQqKSygK$+2Rv z5v%cNd;$G?eceZcc3Qz;(1~~IV<7RfK;B7Oz<|<|UkzcWw^k9Q*Is2T$VDw~mG!m~ zWJq^KL~*>p56lQ#)uFE!UM&(UtC?8@S>n8@(!Z9MMQCT zBf$e6>m}5IL2U!BAPlVAJVT;96ajJ!EWa>%!@GF|_VkzS24=%0{IH;#scp1G)z9DW zB0t>?4XfSv1e>%b4*qA6lYsC@xX5ZJio*9zOrh(Ndl#_b=hNQ#d?_DwKPh^sJ)Boq z-z@3%VYVNmmn+PyP0?%QyoAGltACg(#8P!1Oz*=Fd4?ZcOj6o9$mn0yT8*M%#$A}} zkVGMOfKcW55bZ2IoS!1F?j!bR)O0a^EnO<{?mHRjx#YBSH(%T)ngLE_4o3ub101b& ze(rE?`W)dbfEVWpQ%}whsPpuT1ReN#zP0VLj|SlF%4P?>za^Cj`F% zbJh?nUlQPcf$fyrz=|R{?V13i7?Uf@SGkJ|5WbL0)kClY60H$06NI<|f-F0y6(Rn3 z?kTo@#d{U8>7}}ijBDkFRK2=rJsIxFKi@+{=|rwT97_%dPd{ft)tzmkp-EM{at1q+B5=H~vFMf@KKd|xA6+F)!=7(3hDpx6h+()stu+A~dOU2E@i6XxJr6vw1Cvw56l zIu(7Vku}a zn-FXPYNR(Pu1R?bg7Sq#x77M`dIbEb9GtD+ds?B_AovTw_IF?_L3gNHv0Noirb@OI z{cBX50=W$r`2&2jn6U9c<|oW}HtjV; zF2ov7wTr!y4MDKr=uMvnS674Ww`V_33>{o7#edLZixRnlZ+aWJGBpHx$tdEtb_Vw# zsM&W7g2t3Limkep#Jy53F8nEzD^`uZR$^(cxio8!VDqrp{Y&DM0{@JW7MBOM#e;8O zy2;y{FRhoA6f|3&nnysk4eQozMMHFAdpEkW6hwHTsEtVt{N|%)z zl~e-vz>r^Xe%>4o%un6CjiSBR$vkn*SaU5e`>{Ima&}0H7yB*eA2`@S+q9?{uC9~E zH;+nehCR_5EwGMj*^wMGF8#zoW+n7j8DcGfxVZ)6Fx8l;bBk>8>s&!W2CG$rhKVHX zav4?!f~w9xdJN4v;f}~@+f9wK!|6+|VQxJsiLc-Hj8FC;?fw^mXak6WqK~7;>w9XB z`=KArmu@vbLs%pYsy+D`{f>Xw_Yo(>dj3J)%b=Snfu$i*A;?x>)HF%xA0}*%=l;Jp z)J9EWi)C;Hv*~pdZZYjQ$z=xPEbCU6r9;?@*6*9=P(JTGbHw43Q@7#=9@i8eB~NTH zSAYYaZ68B2(xdzWOKaLedH$VWe$#gJR?)p^ec-w39U!YG({lau;qcEzj=V4RU*?Ry zS__%46q|=oRYY7bd1rUgFnP68{*<~|ME0pI4Q*HgNZ(JR!SHH+B-=lgb|H+E< z98ongpYA#JGB35tllgd}CM0_r_yw*So_G^`jORap%0o$W^I8*VOHLkP?z#L)hAt^m zX}D(NXZueema|M$3m$UJMRJ2(Hq)PyPK8o zFIv+#Vt=VM!JLOWzC7c+?OB!z!!~}-bWM8X)B91z*8OnU4xqJLEN3>rVF0Pe%Q2sD zNN~9?vl4XxY4BiiOZxDFcviWsTlC9Mx7*n7tDELF6@Q?j>j$=abh` zLD6>y`nTE5_i)7UZ2n5UN^AK<-1+og!1>01IEyjjH!Y~%s@@kjths~QQ>E2$>UC9?YDZ!M zf`V&>zg`Smw?~eba|OFuGK3bxMlN_>2*}zPrSkY=Iq6Q+LR3%CXz| zPhjirJ$n<+_lmh0#dgt1phE(HU(4NQ9mt}UNWVr1ofKKqqV>x`;nYK43riqvp_2Pt zNk^=&kETY!;5+a9<`mboD-M!@aVIMbb&}&^Ldez}@ZIl|ChNFD$t*9N6eP-WoyE!4 zHhweYg*TN$7^@)N-embG{t0UJ2aD*eK~c5cub%x*Ic9oE0qE)6*#J?5spDHoyv@o< zhu8`OYz(CjD68zD6vWQ^WU-oT0w`h84qsB+u#*p+1e{V#X$q%>_X`wP-JZI}9YoNL zkdO*u&542OfWhz@Y}sLvL>x+@@o`t&BZ9PNx{c4XiIB*vm-Q5sE_v=k%Kl@>ux-k2X!vrO7Xtd;q9HD;GS|`DaUnl z-@Rx2{we2vKUl?s92+(V7S9;r)(w!&djuaiYd0n@wdNcfhRd>dj1(|b+C%h^MmdN4 zZZ!-k)(=u0jtj)jYy9PT;Pl<+8gt=<)UNJ79V}I#DzCzp{UCKR&Rq=xSYjD z&H0M=L9W5snLA6Sk%nJ49nEhlBDHPq2_E!#RrJpt9DvSYczidZ3fw=9FiECFwI)@t zFG5e<0Bu&-KK6Kx^K08fof@QIRG)LXHvV%mQIju$CsB8gq>j+7fcO19<RV(;21m5+%`hI0jrS%#i}k~+y#{1jxXTpcvS;HT`app+zd4z-Uh`}>C+ zv%lcUEPtrZBv#pnzW78I`)CmA`CEi52x`*Z5We48ffLRa$|bZIA?|Skx;iI)N{Xkk zNv)+ci>csqm$N?_y&SW)oe@wp&4VGMx@I_-Kh%d#^A&5Vdu`>kMPT8_fKzZl5VFH2i= zl48bkO8jAvN+J7z1yh9cnrpa1me2v`i2Tv2if=f;?y<77N7c%+kKavR&kK?`Xr~mj z|DNrH`;Kw_EY=Vc&=X-cllXBm-9bbcX9Ts;Rex^IeT`$CzK~~!jWQcWS?Zfad)G8H z#NF{?rkeQf8Zc6=ujI*g@K6$~+4#$|hcuUfqFcejQB@`h2v_nh{MTW1ONx2S zOr>l{LKcou9r{NzOOY6lcX|4j;TJV231N-`6PeFUrH|iJ+?7>A(U4*Sy+_ypca~5c z5D79#i#g7LuGUK2+2|iQM-awZP@d)o?j7^qyKP;T8#M2Dq0!)zW0)DP+I&DD9Py(R z2!y+s7Y56lMLq2atr=#`ybjY2Y}I>X<)6R3&N)WOJmIde_{i7zEw1E6z$s@Mar&d^EGi_>aUq;im^mO)DAQ%(FN^4ssRTx$nI^>+6Jj2KHW}njShZd| zaVIt%IKA#8dbrWzLQYX7YYN9#7!H>X?AMqn&7bzYQheZ8&Qhi)`X_kXQ15~0m)}gJt)I_xa~UsMQN@q|>{xY4ao&d%JF#W6*&yDg;qP5)-7?c8 zt##V?M_bq_sJES5ow2$E_P_uq0Zh_3lus6R!IkM_?Bg7J5s3tg_CT~$td>S~6WV)g zt0FD;!;41I<|U!`uGbq>g>iGUC%|)v{`aZF`MASiQg}m{&|=(tm@Quo9jA(jjYBFF zScLP!p)(FYB=>us)cEGmkr?D|CVw_QS#QG(fA>Z$YNUT3=p7PViNfsL5QcR=X~(jC zR6?^D`kbwb238Rra zlEiU$8RaeKt_@vdbU;mvzKp0w_qR*6aK#shEa&yf$$7=QgWRpyT^gFMN)4w@Rq<|S z(12eC(C+ZEoN>C~yFA2QqZ7MIHX?xnpqC-lZjXrZ!Abb}?@J0&u8V$Dsy|6xw32eb zP;XB6V+51W6s~R;Vt*J4L@!Rt~vqcXNvDtEixy)etF7ZJd>k}Ef!01_M{j-PFo zf;>k-JhI&=-v2S!-!d~GK1k)IYC-zI^pFGr z^s;Mx2;oWG<+*>USq)O883?10Bj4(sjogC_1N=<9)mJ5I+O6bk%%#YIn-|RzDW_z4iYYGXO z>>{dak=f*qqm5Eb8pAyn7eXaNih+s1%wA~5#&%R!WB2w=@GgO_j~^R9rXvL!tNPR< z8Y>N|P8o=OF;hyhB3xvHie;Aqh$t8A29=Zq*MQpQZsmsfGc^Bz#gg&RpgB2f=v`~d zTu8C#*0@`5`(%0ftL>lfqD9mbn2GHSI_d(qyA?R!B~f_wxy<9G*Wf2f8t0z3QJnyJTivPPwXs zDktpv%X5b~5zKr94bl21<>nUKVsw(E*p|&K_k=CXTFF$>+S$elW#M_`sg8Z}HfLh? z%`YtohEtAE!tfz7il+d|*sa^y%@d@NdaeWrXW^DX@aN zgnOt+f)HQ}V~;WlW2%#4;L-r1`E`VMl0|hx?9s23Z-1;y>^!UKV^?~|v}|1z7cRHs zsD;>DBN0(T%TdH_5eaU)JqU+>Cuj!-(OSBXvGGW2UvDYOFw1*r8u?&szq8@OlG3JT z+1bq?vz${e#$SuM!1*{acmwVzp;Cn{nfr-Qp%=prWL@y&@Ja;iZBN$kD(EON7M!YAs zXeG?baq=5Az@%RLn`C#Jid6j(QvJIkYNwI2VO_8B z_2Bhew{a@06NDC1gjfG$AajZninF8<pMB^Xb)fl>vjf_O z(Um*?rYG#k&aVnDlXddCwM|zYEA9pz@YjNrO;+XJc>r6F>L!c1U^D)%SJ%d@p|?bO z%CZY9AUG&5N9uEZU)h9mas_6dw_(?Q9)2}m1}MJ7>D$!BP7%;Ppd$&1@@kxXoSg#{Ow%VlfgDMga$U3$5_R9cT~C+zT)Nk`F%B_t#1-^VAM~e%7lH4Zm2W z6U(~!^3>Z(wlBybuAD?LjWreA0_O!MmI-?o=UL;`LI~D^KmDynrdc1VYJWC6-jaXm z_BZ6CINiw^lv4=`DR=3(hDypR97;KLLvfrm7n*Yna9`)~eK~rZdagdsn4y^q>m71~2=>siYu>coV|eZD7j6_6-khqecflq142&)D zx4OL*i^TC)ZB*f_>U~}EAzzF(f3NC>n^>ghj&$g$&k@ze@;GW?q4j2 zL``@>`E~^ z`u1xZ0?s`{Xz{~q;3rX48=r`g`s|nv$5MkP}0NE2s#P7K?EOB~O?u16>@Pr8{jy9wJ^5%K&9 z6a~bI`CyQN5K5{ctbw$(i_M7YM8xUg57G-)x5}_%txJsTj@m3h3 zvd1mTbzKrK?*Hv0si!St2)oRPVoMxFK}YJIlIF^ufxUkXe`J!3JI&zDPYNg1V9HXR zjTzdLg1QDVW&KkJ&Cbd@R&)#2hMl?WX>TUSRHW#!#T1!)AT64RIL?F~)wL^uc0C@=4=G)$^OkeW`#Ix$R{Lx$f~+}lL*Z?Gk&t}=nQoCZ?$ggy{s0~x z)}AfKOOY7n`gcWSw`XMnE(GIrUT-p?yB_uHx!IZL`}S}KZoUe{`NAZE5uM>Z#l-_oNuzf^HZ*J&2E4NN z@EKiF{FtzQ^@FE40+t^e)xJ`@sE<#NL=oYGNrS{A{@q3Tdhrh%SKSs#dCl1RdK> z($(SzZzF4>hR7~b0&0SSijLNf0m`og8Kg0HRN9#;c%%;NYMLV>doID?J!_2V2X5ph z{xi99EbbRUhOJr4XiR~eXM-{P9*;q;YrXI)3t8ybP?8P&scPmM$pHUqIX}n}Nqnv5Uu&Q9_ue5CwtKd!4&$&=9RZSRW z8^*AAFl_O2F{~&p=}MY8tFDyrf^Y8?qUQ>sN~@(Wa4zQ+eJ4t&*Mrh0qfV;0JLInx z7yL@!!o*Bt@#&J1c;4q9;do>@%{+RXvu$`0}5z7~K$F$I%*$C*pWkox@%K2^vN>b^GY~nOjav*e1kHbNH1@$LL)dh> zM-p9L_~N<4Go*=0|KZ%2!k<;|O(jMGX#x9Ag*rP?Pzh35{h(Qr0OVYC?WE{BsjRv+ zfi05KbjCk-H^0JQqP@zIn!;3@~%vw$jc&R9xRnZo9UtMPxTn z8tSpdH|G{ADCP0o)5C5IOkDG!8OH>4J4SolVbPpv&{iM1!=C?XS(!gUY>7UBO}aU{75wTV?N+STsoNjWnXoTM++24hDhf)s z`@Shf@dJ8yx1k7~+eNvTmbaWCyE~OCbPi=QRHG&8JYDcgH^0@vPQ{MXb1MfnM8trEY?4nk^We( z)h%h|#zbAX^R{TvKnZ{B@z&ZdTP7^u(3^D}r@<&s(ri{LCC5~sLtT%R-fBn^gu1Q{ z?k-YrO0H?O>zD0SDEzFf_(eeC66J;sM_n0U%TPF4pPo(G;m&=uV=H=Nd{vbr z;&!F8-j^8;x}=}S^-XBn&Nq9G+TGLiSK2_=1%Bbof6ZFTf0H%TRC}h#_nze?VJpq- z)QD>lPREojSu(AU$=k91$}-Jvr602v1|UGl1Q-U=iOd&JE=vs}(vY!@-nlaI1MECJ`2iXD3!6Vs2&ra zen`{%rdPVr>DnVnFF#WrX#3W^beU}q8))7S@m_#lzhk=&vJvyxIMn-^$`OB9jd>?l zqxZ%2UQHLL0+ab0;yGrYa@z?4jl5KHH1`lxQT{_7-$Xfsx%*A4W4M@kqv5heXoaIv z_NWd_zjlVCDR_2feuVpa%U?}bS7{^I=*EJ@jjgM<%w|xQU?xrcwv=e&*GC_pzyDcy z>}OH&jdY2D=UEZC>pi&(sg`C1^FHn_^S~Mb#4z3vrwG|Fkj%^vBc+BXY2`6+13Dr( z?+5qrhsLTwg)r8Yp;47gm%1Q(>rKH{)e_^@6JK`I%FA#vP^b&Tz=9L^3+Pm-jgK+W zkNR9X?ZE*5`W7@l2J1~}?a?^hvwBhN>-4!ctDXwUUB`^iuMzX%hj9kx}*ct~PEbU8-wiB5R0-iea01 zgGNx~Hz=yrS#wnPbO;6+9Pz>K_J^iuMRTex`!mtAQc6_LK(YkLs-|h7+zV~81pta~6YR!y=aDw#a zwBosYz>7z~@G_y}FOS43ytf3ZvK~$U&MrAbdR2rXPlMOZgc5sVE`@HYdw%qKOinw%KM?I_`LkGO!<9BvId%O9VpKg!$UOays;?hWADObx+%sKXv%2^qI?c+r z7!zdh(NaZe=r{Q)^on(}lmwh@;<^U0aV?Ktq6XuJmdsAf2aigoQ?QD>aa;!QexxEYtHKs zx7`etXYgQ5)$iIxSbd6z!vZ;UO9ar+ZlnnONeEqlJH_yRT2a*YW|~uIJX(&k2svF* zIQ=`aqh0@bs_yhdSK5Q;IAX(J9-E&x^hv8F^tKL^;09a-OI>W&U(XIIHYy4!w_{jt z^{q7xUrE~g&9Sl5;aD`AM+i!dgI=| z(*Xa~4|ox^EilNG{}uZ--17gB1r%M literal 0 HcmV?d00001 diff --git a/src/com/sectooladdict/enums/DefaultInputType.java b/src/com/sectooladdict/enums/DefaultInputType.java index a01f00d..4b087bd 100644 --- a/src/com/sectooladdict/enums/DefaultInputType.java +++ b/src/com/sectooladdict/enums/DefaultInputType.java @@ -14,5 +14,9 @@ public enum DefaultInputType { RELATIVE_INPUT, INVALID_INPUT, EMPTY_INPUT, - PARTIAL_PATH_INPUT; + PARTIAL_PATH_INPUT, + FULL_COMMAND_WITHOUT_OS_PREFIX, + FULL_COMMAND_WITH_OS_PREFIX, + PARTIAL_COMMAND, + COMMAND_POSTFIX } diff --git a/src/com/sectooladdict/enums/FileAccessRestriction.java b/src/com/sectooladdict/enums/FileAccessRestriction.java index fcd49cc..b19ed04 100644 --- a/src/com/sectooladdict/enums/FileAccessRestriction.java +++ b/src/com/sectooladdict/enums/FileAccessRestriction.java @@ -36,5 +36,13 @@ public enum FileAccessRestriction { /*#######################################*/ HTTP_INPUT_VALIDATION, //Input Validation (http) HTTP_INPUT_REMOVAL, //Input Removal (http) - CONCAT_DOMAIN_BASE_URL; //Concats the domain base URL to the input + CONCAT_DOMAIN_BASE_URL, //Concats the domain base URL to the input + /*###############################*/ + /*## OS COMMAND INJECTION ONLY ##*/ + /*###############################*/ + PIPE_INPUT_VALIDATION, + PIPE_INPUT_REMOVAL, + AMPERSAND_INPUT_VALIDATION, + AMPERSAND_INPUT_REMOVAL + } diff --git a/src/com/sectooladdict/enums/OsType.java b/src/com/sectooladdict/enums/OsType.java index a9fafdb..1d8c84f 100644 --- a/src/com/sectooladdict/enums/OsType.java +++ b/src/com/sectooladdict/enums/OsType.java @@ -10,5 +10,5 @@ * @since 1.2 */ public enum OsType { - WINDOWS, UNIX; + WINDOWS, UNIX, ANY; } diff --git a/src/com/sectooladdict/validators/InputValidator.java b/src/com/sectooladdict/validators/InputValidator.java index 340e173..79c4497 100644 --- a/src/com/sectooladdict/validators/InputValidator.java +++ b/src/com/sectooladdict/validators/InputValidator.java @@ -264,8 +264,31 @@ public static String removeHttp(final String s) { //intentionally ignore upper/lower case issues, so evasion can be used return s.replace("http://", ""); } //end of method - - + + public static boolean validatePipe(String s) { + if (s.contains("|")) + return true; + return false; + } + + public static String removePipe(String s) { + String temp = null; + temp = s.replace("|", ""); + return temp; + } + + public static boolean validateAmpersand(String s) { + if (s.contains("&")) + return true; + return false; + } + + public static String removeAmpersand(String s) { + String temp = null; + temp = s.replace("&", ""); + return temp; + } + /** * This method attempts to remove instances of * Unix local directory traversal characters (/./,./) from the input.