Run a Ruby Script with Python

Viewed 8537

I have a Ruby Script that when I run in the shell it works (as user):

/home/user/wpscan/$ ruby ./wpscan.rb -u www.mysite.com

However, I'd like to automate this with a function that I created with Python. Here is the python script:

#!/usr/bin/python

import os
wpscan_env = "/wpscan/"
os.chdir(os.environ['HOME'] + wpscan_env)
os.system("ruby ./wpscan.rb -u www.mysite.com")

Notice that the Python script is in a different folder, home/user/python/first.py and this is why I do the os.chdir() function. When I go back to the shell and type:

/home/user/python/$ python first.py

This is the output I get:

Could not find addressable-2.4.0 in any of the sources

Run `bundle install` to install missing gems.

I am using Ubuntu 14.04 and in order to get wpscan to work, it asked me to install Ruby 2.3.0. I did this via RVM.

wpscan.rb has a few dependencies and it seems it's not instantiating them. Also if I'm inside the wpscan folder and do ruby ./wpscan.rb ... it will work. However if I try to do this from the home directory: ruby wpscan/wpscan.rb ... it throws an error:

[ERROR] cannot load such file --typhoeus

[TIP] try to run 'gem install typhoeus' or 'gem install --user-install typhoeus'. If you still get an error, Please see README file or https://github.com/wpscanteam/wpscan

I have no knowledge of Ruby, this is my first real Python script, and I just installed wpscan 2 nights ago. I'm way out of my league here and I need help. Any further question can be elaborated per request.

2 Answers

Thats so simple to execute ruby scripts from python...

import os
os.system('ruby filename.rb')
#if you want to store the output in seperate file
os.system('ruby filename.rb > outfilename.txt)
Related