Reputation:
I have this .rb file with the command:
cd /users/someusername/documents
The problem is that instead of "someusername", i would like to get the actual username of my target pc(which is my own pc used for penetration testing).
Update: Just to clarify: I am running the resource script using the :resource: command from my meterpreter session. I guess this is different from running meterpreter scripts since the way I am doing it, runs every line in the file as a meterpreter command. Any idea of how I could get the target's username from the file then? I mean the ENV does not seem to work with this approach. I am open for all suggestions!
Thanks! Much appreciated!
Upvotes: 1
Views: 519
Reputation: 54283
If someusername
is the current user name, you could use :
cd ~/documents
current_user = ENV['USER']
cmd = "cd /users/#{current_user}/documents"
This command could help you :
current_user = %x(id -un).chomp
cmd = "cd /users/#{current_user}/documents"
According to this post, resource files seem to be ERB files. So you could write :
cd /users/<%= ENV['USER'] %>/documents
# or
cd /users/<%= %x(id -un).chomp %>/documents
Upvotes: 1