user7322412
user7322412

Reputation:

Pass arguments in ruby file for meterpreter?

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

Answers (1)

Eric Duminil
Eric Duminil

Reputation: 54283

Direct shortcut (if available)

If someusername is the current user name, you could use :

cd ~/documents

Environment variable (if available)

current_user = ENV['USER']
cmd = "cd /users/#{current_user}/documents"

Getting username with id

This command could help you :

current_user = %x(id -un).chomp
cmd = "cd /users/#{current_user}/documents"

Yet another try

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

Related Questions