Skip to content
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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

savacano28
Copy link

@savacano28 savacano28 commented Sep 6, 2024

Proposed changes

  • Include credentials from non system user on installation, upgrade files for windows

Related issues

Checklist

  • I consider the submitted work as finished
  • I tested the code for its functionality
  • I wrote test cases for the relevant uses case
  • I added/update the relevant documentation (either on github or on notion)
  • Where necessary I refactored code to improve the overall quality

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...

@savacano28 savacano28 self-assigned this Sep 6, 2024
@savacano28 savacano28 added needs triage use to identify issue needing triage from Filigran Product team filigran team and removed needs triage use to identify issue needing triage from Filigran Product team labels Sep 6, 2024
@savacano28 savacano28 changed the title [agent] Update installation files with new params [agent] Add execution with non system user Sep 10, 2024
@savacano28 savacano28 changed the title [agent] Add execution with non system user [agent] POC Ability to choose non-system user to execute a payload Sep 11, 2024
@@ -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

Copy link
Member

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.

Copy link
Author

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> {
Copy link
Member

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"
Copy link
Member

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

Copy link
Author

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;
Copy link
Member

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.

Copy link
Author

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;
Copy link
Member

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
Copy link
Member

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.

Copy link
Author

@savacano28 savacano28 Sep 19, 2024

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) {
Copy link
Member

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(
Copy link
Member

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

Copy link
Author

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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to choose a service account on linux
3 participants