[英]How to replace a particular string found in URL taken from console with file content found on each line written in text file in Ruby?
I want to replace fuzz word which has been written in URL taken from console with contents of text file having one string per line. 我想用从每行一个字符串的文本文件内容替换从控制台获取的URL中写的模糊词。 After replacing this fuzz word with file content want to fire http request with this replaced content file and store responses with modified requests in new file.
用文件内容替换此模糊词后,要使用此替换的内容文件触发http请求,并将响应与修改后的请求一起存储在新文件中。
I have written like this but getting error: 我这样写,但出现错误:
fuzz1.rb:16: private method `gsub' called for #<URI::HTTP:0x2969040> (NoMethodError)
Code is here: 代码在这里:
require 'net/http'
puts "Enter Target:\n"
target = URI(gets())
new_reference = target
a1 = target.clone
Net::HTTP.start(target.host, target.port) do |http|
request = Net::HTTP::Get.new target.request_uri
response = http.request request
puts response.body
end
puts "File contents:\n"
f= File.open("fuzz.txt","r")
while line = f.gets do
puts "Attack value: #{line}"
b = a1.gsub('fuzz','#{line}')
c = b
Net::HTTP.start(c.host, c.port) do |http|
request = Net::HTTP::Get.new c.request_uri
response = http.request request
puts response.body
end
end
No idea why this gsub error is coming and not replacing fuzz word found in URL with file line content. 不知道为什么会出现此gsub错误,而不用文件行内容替换URL中找到的模糊词。
a1
is an URI object, it doesn't have a gsub
method. a1
是URI对象,它没有gsub
方法。 You need to cast it to a string. 您需要将其转换为字符串。 Try this
尝试这个
b = URI.parse(a1.to_s.gsub('fuzz','#{line}'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.