Created
January 26, 2016 03:44
-
-
Save zlx/b24bac0f1f5ae2fd565f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'colorize' | |
require 'commander/import' | |
program :name, 'fight' | |
program :version, '1.0.0' | |
program :description, 'Flight with CDN' | |
def log_target(ip, banner) | |
puts "Target IP: #{ip}".colorize(:red) | |
puts banner | |
puts | |
end | |
def find_ips_with_flag(result_file_path, flag) | |
ips = [] | |
f = File.new(result_file_path) | |
target_ip = nil | |
banner = "" | |
banner_begin = false | |
banner_matched = false | |
begin | |
while (line = f.readline) | |
line = line.encode("UTF-16be", :invalid=>:replace, :replace=>"?").encode('UTF-8') | |
if line.match(/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\s*HTTP\/1\.1\s*\d{3}/i) | |
if banner_begin && banner_matched | |
ips << target_ip | |
log_target(target_ip, banner) | |
end | |
banner_begin = true | |
banner_matched = false | |
banner = "" | |
target_ip = $1 | |
end | |
if banner_begin && line.match(/#{flag}/) | |
banner_matched = true | |
end | |
banner += line | |
end | |
rescue => e | |
if banner_begin && banner_matched | |
ips << target_ip | |
log_target(target_ip, banner) | |
end | |
ensure | |
f.close | |
end | |
ips | |
end | |
command :dig_ip do |c| | |
c.syntax = 'fight dig_ip [options]' | |
c.description = 'dig the right ip for fake website' | |
c.option '--r File', String, 'Specify Result File Path' | |
c.option '--f Flag', String, 'Specify Website Flag' | |
c.option '--o Output Path', String, 'Specify Output File Path' | |
c.action do |args, options| | |
fail "must specify --f Flag" unless options.f | |
fail "must specify --r File" unless options.r | |
ips = find_ips_with_flag(options.r, options.f) | |
if ips.empty? | |
puts "No Matched IP".colorize(:red) | |
else | |
puts "Target IP: " | |
puts ips | |
if options.o | |
File.open(options.o, 'w') do |f| | |
f.write ips.join("\n") | |
end | |
end | |
end | |
end | |
end | |
command :filter_ip do |c| | |
c.syntax = 'fight filter_ip [options]' | |
c.description = 'filter ips with visiable port' | |
c.option '--f File', String, 'Specify source ips File Path' | |
c.option '--p Port', Integer, 'Specify the port when to verify' | |
c.option '--o Output Path', String, 'Specify Output File Path, default: #port#.txt' | |
c.action do |args, options| | |
fail "must specify --f File" unless options.f | |
fail "must specify --p Port" unless options.p | |
options.default o: "#{options.p}.txt" | |
%x(zmap -p #{options.p} -w #{options.f} -o #{options.o}) | |
end | |
end | |
command :banner_grab do |c| | |
c.syntax = 'fight banner_grab [options]' | |
c.description = 'Grab banner with ips' | |
c.option '--f File', String, 'Specify source ips File Path' | |
c.option '--r req file path', String, 'Specify req file path' | |
c.option '--c Concurrent', Integer, 'Specify Concurrent, default is 100' | |
c.option '--t timeout', String, 'Specify timeout, default: 20' | |
c.option '--o Output Path', String, 'Specify Output File Path, default: result.txt' | |
c.action do |args, options| | |
fail "must specify --f File" unless options.f | |
fail "must specify --r req file path" unless options.r | |
options.default c: 100, t: 20, o: 'result.txt' | |
%x(cat #{options.f} | ./banner -port 80 -concurrent #{options.c} -data #{options.r} -timeout #{options.t} -format ascii > #{options.o}) | |
end | |
end | |
command :filter_ips do |c| | |
c.syntax = 'fight filter_ips [options]' | |
c.description = 'Filter ips from source ips' | |
c.option '--s Source File', String, 'Specify source ips File Path' | |
c.option '--f Filter File', String, 'Specify filter ips file path' | |
c.option '--o Output Path', String, 'Specify Output File Path' | |
c.action do |args, options| | |
fail "must specify --s Source File" unless options.s | |
fail "must specify --f Filter File" unless options.f | |
source = IO.readlines(options.s).map(&:strip).uniq | |
filter = IO.readlines(options.f).map(&:strip).uniq | |
target = source - filter | |
if options.o | |
File.open(options.o, "w") do |f| | |
f.puts target.join("\n") | |
end | |
else | |
puts target.join("\n") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment