Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change web/dir_enum to yield URL values with a body #168

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/ronin/recon/builtin/web/dir_enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,17 @@ def process(website)
headers = response.headers.to_h

if VALID_STATUS_CODES.include?(status)
get_response = http.get(path)
body = begin
get_response.read
ensure
get_response.close
end

yield URL.new(
"#{base_url}#{path}", status: status,
headers: headers
headers: headers,
body: body
)
end
rescue Errno::ECONNREFUSED,
Expand Down
17 changes: 9 additions & 8 deletions spec/builtin/web/dir_enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ class App < Sinatra::Base
set :port, 80

get '/' do
halt 200
[200, ['Body for index']]
end

get '/admin' do
halt 200
[200, ['Body for /admin']]
end

get '/downloads' do
halt 200
[200, ['Body for /downloads']]
end

get '/secret' do
halt 200
[200, ['Body for /secret']]
end
end
end
Expand All @@ -79,6 +79,7 @@ class App < Sinatra::Base

before do
stub_request(:head, /#{Regexp.escape(host)}/).to_rack(app)
stub_request(:get, /#{Regexp.escape(host)}/).to_rack(app)
end

let(:fixtures_dir) { File.join(__dir__,'fixtures') }
Expand Down Expand Up @@ -114,17 +115,17 @@ class App < Sinatra::Base
expect(yielded_values[0].uri).to eq(URI('http://example.com/admin'))
expect(yielded_values[0].status).to eq(200)
expect(yielded_values[0].headers).to eq(expected_headers)
expect(yielded_values[0].body).to be(nil)
expect(yielded_values[0].body).to eq('Body for /admin')
expect(yielded_values[1]).to be_kind_of(Ronin::Recon::Values::URL)
expect(yielded_values[1].uri).to eq(URI('http://example.com/downloads'))
expect(yielded_values[1].status).to eq(200)
expect(yielded_values[1].headers).to eq(expected_headers)
expect(yielded_values[1].body).to be(nil)
expect(yielded_values[1].body).to eq('Body for /downloads')
expect(yielded_values[2]).to be_kind_of(Ronin::Recon::Values::URL)
expect(yielded_values[2].uri).to eq(URI('http://example.com/secret'))
expect(yielded_values[2].status).to eq(200)
expect(yielded_values[2].status).to be(200)
expect(yielded_values[2].headers).to eq(expected_headers)
expect(yielded_values[2].body).to be(nil)
expect(yielded_values[2].body).to eq('Body for /secret')
end

# Valid HTTP status codes
Expand Down