-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisgit.cr
80 lines (66 loc) · 2.02 KB
/
isgit.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require "logger"
require "http"
require "uri"
class IsGit
# Initialize IsGit Class
def initialize(file : String, output : String, @logger : Logger)
logger.debug("IsGit initialized ... OK")
fh = File.read_lines(file) # => ary(String) of lines
logger.debug("File #{file} imported with total size: #{fh.size} ... OK")
valid = Array(String).new
fh.each_with_index do |line, i|
if is_git(line)
valid << line # => Add current domain to list of valid results
@logger.info("Current valid results: #{valid.size} ... ix: #{i} :)")
write_valid(output, line)
end
end
end
def write_valid(output : String, domain : String)
File.open(output, "a") do |file|
file.puts "#{domain}"
end
end
def do_req(url : String, path : String) : HTTP::Client::Response
client = HTTP::Client.new(URI.parse("http://#{url}"))
client.connect_timeout = 5
res = client.get(path)
begin
if res.status_code == 301
client = HTTP::Client.new(URI.parse("https://#{url}"))
client.connect_timeout = 5
end
rescue
@logger.debug("Skipping #{url} because of timeout ... :(")
end
begin
res = client.get(path)
rescue IO::Timeout
@logger.debug("Skipping #{url} because of timeout ... :(")
end
res
end
def is_git(domain : String) : Bool
begin
@logger.info("Doing vcs//git check on domain ... #{domain}!")
res = do_req("#{domain}", "/.git/config")
if res.body.includes?("[core]")
@logger.info("Found possible .git/config via recon on #{domain} ... Good!")
return true
end
res = do_req("#{domain}", "/.git/HEAD")
if res.body.includes?("refs/heads")
@logger.info("Found possible .git/HEAD via recon on #{domain} ... Good!")
return true
end
rescue
false
end
false
end
end
logger = Logger.new(STDOUT)
logger.level = Logger::DEBUG
IN_FILE = "./dns.export.txt"
OUT_FILE = "./dns.git.valid.txt"
isgit = IsGit.new(IN_FILE, OUT_FILE, logger)