Skip to content

Commit f78f022

Browse files
committed
Bug fix for netstat command parsing - Korean OS
1 parent 06237b8 commit f78f022

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/main/java/org/owasp/webgoat/lessons/Challenge2Screen.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,10 @@ protected ElementContainer getNetstatResults(WebSession s)
646646
String protocol = s.getParser().getRawParameter(PROTOCOL, "tcp");
647647

648648
String osName = System.getProperty("os.name");
649+
boolean isWindows = (osName.indexOf("Windows") != -1)?true:false;
650+
649651
ExecResults er = null;
650-
if (osName.indexOf("Windows") != -1)
652+
if (isWindows)
651653
{
652654
String cmd = "cmd.exe /c netstat -ant -p " + protocol;
653655
er = Exec.execSimple(cmd);
@@ -661,18 +663,24 @@ protected ElementContainer getNetstatResults(WebSession s)
661663
String results = er.getOutput();
662664
StringTokenizer lines = new StringTokenizer(results, "\n");
663665
String line = lines.nextToken();
664-
// System.out.println(line);
666+
//System.out.println("line=" + line);
665667
int start = 0;
668+
int loop = 0;
666669
while (start == 0 && lines.hasMoreTokens())
667670
{
668-
if ((line.indexOf("Proto") != -1))
671+
//Some Windows(non-English) does not display "Proto".
672+
//Korean OS also use Korean characters.(Maybe japanese, chinese also - not tested)
673+
//So nothing to display, impossible to process this lesson.
674+
//but Windows netstat command always have 4 header line before body so...
675+
if ((line.indexOf("Proto") != -1) || (isWindows && loop >= 3))
669676
{
670677
start++;
671678
}
672679
else
673680
{
674681
line = lines.nextToken();
675682
}
683+
loop++;
676684
}
677685
while (start > 0 && lines.hasMoreTokens())
678686
{

0 commit comments

Comments
 (0)