Class: EMaily::WebServers
- Inherits:
-
Object
- Object
- EMaily::WebServers
- Defined in:
- lib/emaily/webservers.rb
Constant Summary collapse
- SHOW_FORMAT =
"+ Response from IP %h on port %p"
- LOG_FORMAT =
"|| %h || %p || %U || %{User-agent}i"
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #create_scan_server ⇒ Object
- #create_server ⇒ Object
-
#initialize(ports) ⇒ WebServers
constructor
A new instance of WebServers.
- #parsedata ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(ports) ⇒ WebServers
Returns a new instance of WebServers.
18 19 20 21 22 23 |
# File 'lib/emaily/webservers.rb', line 18 def initialize(ports) @ports = ports @log = Dir::pwd + "/emaily_webserver_#{Time.now.to_s.gsub(/ |:|-/,"")}.log" @data = [] @path = Dir::pwd end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
24 25 26 |
# File 'lib/emaily/webservers.rb', line 24 def path @path end |
Instance Method Details
#create_scan_server ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/emaily/webservers.rb', line 26 def create_scan_server @server = WEBrick::HTTPServer.new(:Port => @ports[0], :ServerType => Thread, :Logger => Log.new("/dev/null"), :AccessLog => [[$stdout, SHOW_FORMAT], [Log.new(@log), LOG_FORMAT]]) if @ports.size > 1 @ports[1..-1].each {|p| @server.listen("0.0.0.0", p)} end @server.mount("/*", CustomScanningServer) end |
#create_server ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/emaily/webservers.rb', line 36 def create_server @server = WEBrick::HTTPServer.new(:Port => @ports[0], :DocumentRoot => @path, :ServerType => Thread, :Logger => Log.new("/dev/null"), :AccessLog => [[$stdout, SHOW_FORMAT], [Log.new(@log), LOG_FORMAT]]) if @ports.size > 1 @ports[1..-1].each {|p| @server.listen("0.0.0.0", p)} end end |
#parsedata ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/emaily/webservers.rb', line 53 def parsedata # Print list of Ports matching IP to Email data = File.read(@log).scan(/\|\| (.*) \|\| (.*) \|\| (.*) \|\| (.*)/) puts "Open Ports\n" puts "------------" ports = data.map {|d| d[1]}.uniq ports.each do |port| puts "Port #{port}" data.select {|d| d[1] == port}.uniq.each { |d| puts " #{d[0]} => #{d[2].to_s.scan(/\?e=(.*)/).to_s}\n" } end #Print list of Users-Agents discovered puts "User-Agents\n" puts "-------------" data.map { |d| d[3]}.uniq.each {|ua| puts " "+ua} #Print list of email addresses that responded to attack. puts "Emails:" data.map { |d| d[2].to_s.scan(/\?e=(.*)/).to_s}.uniq.each {|e| puts " "+e} puts "\n\nFull Access Log data is available on #{@log}\n" EMaily::status = false end |
#run ⇒ Object
45 46 47 |
# File 'lib/emaily/webservers.rb', line 45 def run @server.start end |
#stop ⇒ Object
49 50 51 |
# File 'lib/emaily/webservers.rb', line 49 def stop @server.shutdown end |