-
Notifications
You must be signed in to change notification settings - Fork 3
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.
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
[agent] POC Ability to choose non-system user to execute a payload #14
base: main
Are you sure you want to change the base?
Conversation
49f17ca
to
b9d28a7
Compare
…ermissions for the non-system user on the execution directory
@@ -58,11 +58,16 @@ function .onInit | |||
${GetParameters} $R0 | |||
${GetOptions} $R0 ~OPENBAS_URL= $ConfigURL | |||
${GetOptions} $R0 ~ACCESS_TOKEN= $ConfigToken | |||
${GetOptions} $R0 ~NON_SYSTEM_USER= $ConfigNonSystemUser | |||
${GetOptions} $R0 ~NON_SYSTEM_PWD= $ConfigNonSystemPwd | |||
functionEnd | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, do we let the installer create the user account ?
Not the agent to have too much power
This facilitates the agent deployment workflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, these params are not used to create a user account, they are used to execute scripts (dep. Elevated privilege)
wide | ||
} | ||
|
||
fn run_as_user_command(username: &str, domain: &str, password: &str, script_file_path: &PathBuf) -> Option<u32> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment a maximum the path choose and why this one.
FileWrite $4 "non_system_user = $\"$ConfigNonSystemUser$\"$\r$\n" | ||
${EndIf} | ||
${If} $ConfigNonSystemPwd != "" | ||
FileWrite $4 "non_system_pwd = $\"$ConfigNonSystemPwd$\"$\r$\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear password in config, thats a no go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The credentials for users without elevated privilege are not mandatory so for that I set this condition. I'm not sure where I clear pwd, t'y!
icacls $directory /grant "${NON_SYSTEM_USER}:(OI)(CI)F" /T | ||
|
||
Stop-Service -Force -Name "OBAS Agent Service"; Invoke-WebRequest -Uri "${OPENBAS_URL}/api/agent/package/openbas/windows/${architecture}" -OutFile "openbas-installer.exe"; ./openbas-installer.exe /S ~OPENBAS_URL="${OPENBAS_URL}" ~ACCESS_TOKEN="${OPENBAS_TOKEN}" ~NON_SYSTEM_USER="${NON_SYSTEM_USER}" ~NON_SYSTEM_PWD="${NON_SYSTEM_PWD}"; Start-Sleep -Seconds 1.5; rm -force ./openbas-installer.exe; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about that, agent must always run as an admin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The agent run as admin, these params are used later for running the implant scripts
Stop-Service -Force -Name "OBAS Agent Service"; Invoke-WebRequest -Uri "${OPENBAS_URL}/api/agent/package/openbas/windows/${architecture}" -OutFile "openbas-installer.exe"; ./openbas-installer.exe /S ~OPENBAS_URL="${OPENBAS_URL}" ~ACCESS_TOKEN="${OPENBAS_TOKEN}" ~NON_SYSTEM_USER="${NON_SYSTEM_USER}" ~NON_SYSTEM_PWD="${NON_SYSTEM_PWD}"; Start-Sleep -Seconds 1.5; rm -force ./openbas-installer.exe; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about that, agent must always run as an admin.
|
||
$directory = (Get-Location).Path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its more about the agent to adapt the rights of the implant directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, It was my first try (agent modifies rights on directory) but I had some difficulties writing the code so for that I include it here (I'm going to ask to modify it), ty.
} | ||
} else { | ||
// Execute the command as a specific user | ||
if let Some(pid) = run_as_user_command(non_system_user, "WORKGROUP", non_system_pwd, &script_file_name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about WORKGROUP will be something working across customers.
|
||
// Call CreateProcessWithLogonW | ||
let result = unsafe { | ||
CreateProcessWithLogonW( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit surprise about the fact we need to use this kind of low level api.
What i have seen for now.
PS C:\Users\JulienRichard> $user = "Administrator"
PS C:\Users\JulienRichard> $pwd = ConvertTo-SecureString "MyP@55w0rd" -AsPlainText -Force
PS C:\Users\JulienRichard> $cred = New-Object System.Management.Automation.PSCredential($user,$pwd)
PS C:\Users\JulienRichard> powershell.exe -executionpolicy Bypass -file script.ps1 -Credentials $cred
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed, I tried this at first. However, since I executed only a few simple injects, I wondered if we might need more control. I will add the other code, ty!!
|
||
// Call CreateProcessWithLogonW |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposed changes
Related issues
Checklist
Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...