Class: RCS::Backdoor::Application
- Inherits:
-
Object
- Object
- RCS::Backdoor::Application
- Includes:
- Tracer
- Defined in:
- lib/rcs-backdoor/backdoor.rb
Overview
this module is used only form bin/rcs-backdoor as a wrapper to execute the backdoor from command line
Class Method Summary collapse
-
.run!(*argv) ⇒ Object
since we cannot use trace from a class method we instantiate here an object and run it.
Instance Method Summary collapse
Class Method Details
.run!(*argv) ⇒ Object
since we cannot use trace from a class method we instantiate here an object and run it
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/rcs-backdoor/backdoor.rb', line 263 def self.run!(*argv) # This hash will hold all of the options parsed from the command-line by OptionParser. = {} srand(Time.now.to_i) types = [:RANDOM] + RCS::EVIDENCE_TYPES.values optparse = OptionParser.new do |opts| # Set a banner, displayed at the top of the help screen. opts. = "Usage: rcs-backdoor [options] arg1 arg2 ..." # Define the options, and what they do opts.on( '-r', '--randomize NUM', Integer, 'Randomize NUM instances') do |num| [:randomize] = num end opts.on( '-g', '--generate NUM', Integer, 'Generate NUM evidences' ) do |num| [:generate] = true [:gen_num] = num end opts.on( '-t', '--type TYPE', types, 'Generate evidences of type TYPE' ) do |type| [:gen_type] = type end opts.on( '-s', '--sync HOST', 'Synchronize with remote HOST' ) do |host| [:sync] = true [:sync_host] = host end opts.on('--tag STRING', 'Append to instance string' ) do |tag| [:tag] = tag end opts.on( '-l', '--loop DELAY', Integer, 'Loop synchronization every DELAY seconds') do |seconds| [:loop] = true [:loop_delay] = seconds end opts.on( '-c', '--config CONFIGURATION', String, 'Configuration/environment name') do |value| [:config_name] = value end opts.on( '--scout', 'Auth like a scout' ) do [:scout] = true end opts.on( '--soldier', 'Auth like a soldier' ) do [:soldiers] = true end # This displays the help screen, all programs are assumed to have this option. opts.on( '-h', '--help', 'Display this screen' ) do puts opts exit end end optparse.parse(argv) return Application.new.run() end |
Instance Method Details
#run(options) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/rcs-backdoor/backdoor.rb', line 205 def run() # if we can't find the trace config file, default to the system one if File.exist?('trace.yaml') then load_path = Dir.pwd trace_yaml = 'trace.yaml' else load_path = File.dirname(File.dirname(File.dirname(__FILE__))) + "/bin" trace_yaml = load_path + "/trace.yaml" puts "Cannot find 'trace.yaml' using the default one (#{trace_yaml})" end # initialize the tracing facility begin trace_init load_path, trace_yaml rescue Exception => e puts e exit end unless [:randomize].nil? binary = begin File.open(load_path + '/ident.yaml', "r") do |f| binary = YAML.load(f.read) end rescue trace :fatal, "Cannot open binary patched file" exit end threads = [] [:randomize].times do |n| binary["INSTANCE_ID"] = Digest::SHA1.hexdigest(n.to_s).upcase path_to_yaml = load_path + "/ident#{n}.yaml" File.open(path_to_yaml, "w") {|f| f.write(binary.to_yaml)} trace :info, "Spawned backdoor #{path_to_yaml}" threads << Thread.new { run_backdoor(load_path + '/binary.yaml', path_to_yaml, )} end begin threads.each do |th| th.join end rescue Interrupt trace :info, "User asked to exit. Bye bye!" return 0 end else run_backdoor(load_path + '/binary.yaml', load_path + '/ident.yaml', ) end # concluded successfully return 0 end |
#run_backdoor(path_to_binary, path_to_ident, options) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/rcs-backdoor/backdoor.rb', line 172 def run_backdoor(path_to_binary, path_to_ident, ) b = RCS::Backdoor::Backdoor.new(path_to_binary, path_to_ident, ) # set the scout flag if specified b.scout = true if [:scout] b.soldier = true if [:soldier] if [:generate] then trace :info, "Creating #{[:gen_num]} fake evidences..." b.create_evidences([:gen_num], [:gen_type]) end while true if [:sync] then b.sync [:sync_host], !([:randomize] or [:loop]) # delete evidences if not randomizing end break unless [:loop] [:loop_delay].times do |n| sleep 1 trace :info, "#{[:loop_delay] - n} seconds to next synchronization." if n % 5 == 0 end end rescue Interrupt trace :info, "User asked to exit. Bye bye!" return 0 rescue Exception => e trace :fatal, "FAILURE: " << e.to_s trace :fatal, "EXCEPTION: " + e.backtrace.join("\n") return 1 end |