Benjamin
Benjamin

Reputation: 617

Alternative to eval()

I'm looking for an alternative to that code:

 expl = eval "BeEF::Modules::Exploits::#{klass.capitalize}.new"

Here the eval is totally insecure. Is there an alternative I could use to generate dynamically classes without using eval? As in, klass is always different. So my code stays generic.

Thanks for your time.

Upvotes: 2

Views: 1060

Answers (1)

Magnus Holm
Magnus Holm

Reputation: 1221

You can use Module#const_get:

expl = BeEF::Modules::Exploits.const_get(klass.capitalize).new

Upvotes: 7

Related Questions