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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 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 204 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 260 261 262 263 264 265 266 267 268
|
##
# This file is part of WhatWeb and may be subject to
# redistribution and commercial restrictions. Please see the WhatWeb
# web site for more information on licensing and terms of use.
# https://www.morningstarsecurity.com/research/whatweb
##
require 'minitest/autorun'
require 'json'
class WhatWebTest < Minitest::Test
def setup
@test_host = 'whatweb.net'
end
def valid_json?(json)
JSON.parse(json)
return true
rescue JSON::ParserError
return false
end
def test_version
p = IO.popen(['./whatweb', '--version'], 'r+')
res = p.read.to_s
p.close
assert res
assert res =~ %r{^WhatWeb version ([\d\.]+(-dev)?) \( https://www.morningstarsecurity.com/research/whatweb/ \)$}
end
def test_usage
p = IO.popen(['./whatweb', '--help'], 'r+')
res = p.read.to_s
p.close
assert res
assert res =~ /^WhatWeb - Next generation web scanner version ([\d\.]+(-dev)?)\.$/
end
def test_invalid_url
res = IO.popen(['./whatweb','--color', 'never', 'https://'], :err => [ :child, :out ]).read
assert_match %r{No targets selected}, res
end
def test_xml_output
p = IO.popen(['./whatweb',
'--color', 'never',
'--log-xml', '/dev/stdout',
"https://#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
assert res =~ %r{<http-status>200</http-status>}
end
def test_json_output
res = IO.popen(['./whatweb',
'--color', 'never',
'--log-json', '/dev/stdout',
"https://#{@test_host}/"],
:err => [ :child, :out ]).read
assert_match %r{"http_status":200}, res
end
def test_json_output_with_empty_input
res = IO.popen(['./whatweb',
'--color', 'never',
'--log-json','/dev/stdout',
'--quiet',
'--no-errors',
'--input-file','/dev/null'], :err => [ :child, :out ]).read
assert valid_json?(res)
end
def test_object_output
p = IO.popen(['./whatweb',
'--color', 'never',
'--log-object', '/dev/stdout',
"https://#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
assert res =~ %r{Identifying: https://#{@test_host}/}
assert res =~ %r{^HTTP-Status: 200$}
assert res =~ %r{:name=>"server string", :string=>"Apache", :certainty=>100}
end
def test_sql_output
p = IO.popen(['./whatweb',
'--color', 'never',
'--log-sql', '/dev/stdout',
"https://#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
lines = res.split("\n").flatten
assert lines[0] =~ %r{^INSERT IGNORE INTO request_configs \(value\)}
assert lines[1] =~ %r{^INSERT IGNORE INTO targets \(status,target\) VALUES \('200','https://#{@test_host}/'\);$}
end
def test_verbose_output
p = IO.popen(['./whatweb',
'--color', 'never',
'--verbose',
"https://#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
assert res.split("\n").flatten.first =~ %r{WhatWeb report for https://#{@test_host}/$}
end
def test_plugins
p = IO.popen(['./whatweb',
'--color', 'never',
'-phttpserver,title',
"https://#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
assert res =~ %r{^https://#{@test_host}/ \[200 OK\] HTTPServer\[Apache\], Title\[WhatWeb - Next generation web scanner.\]$}
end
def test_custom_plugin
p = IO.popen(['./whatweb',
'--color', 'never',
'--custom-plugin', ':text=>"WhatWeb - Next generation web scanner."',
"https://#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
assert res =~ %r{Custom-Plugin}
end
def test_invalid_custom_plugin
junk = "#{('a'..'z').to_a.shuffle[0,8].join}"
p = IO.popen(['./whatweb',
'--color', 'never',
'--no-errors',
'--custom-plugin', ":text=>#{junk}",
"https://#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
assert_equal '', res
end
def test_list_plugins
p = IO.popen(['./whatweb',
'--color', 'never',
'--list'], 'r+')
res = p.read.to_s
p.close
assert res
assert res =~ %r{Total: [\d]+ Plugins}
end
def test_info_plugins
p = IO.popen(['./whatweb',
'--color', 'never',
'--info-plugins','wordpress'], 'r+')
res = p.read.to_s
p.close
assert res
assert res =~ %r{www.wordpress.org}
end
def test_search_plugins
p = IO.popen(['./whatweb',
'--color', 'never',
'--search','struts'], 'r+')
res = p.read.to_s
p.close
assert res
assert res =~ %r{struts.apache.org}
end
def test_grep_plugin
p = IO.popen(['./whatweb',
'--color', 'never',
'--grep', 'Next generation web scanner',
"https://#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
assert_match %r{, Grep,}, res
end
def test_dorks
p = IO.popen(['./whatweb',
'--color', 'never',
'--dorks', 'wordpress',
"https://#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
assert res =~ %r{is proudly powered by WordPress}
end
def test_quiet
p = IO.popen(['./whatweb',
'--quiet',
"https://#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
assert_empty res
end
def test_no_errors
p = IO.popen(['./whatweb',
'--color', 'never',
'--no-errors',
"https://#{@test_host}:99/"], 'r+')
res = p.read.to_s
p.close
assert res
refute res =~ %r{ERROR:}
end
def test_url_suffix
p = IO.popen(['./whatweb',
'--color', 'never',
'--url-suffix','robots.txt',
"https://#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
assert_match %r{rm -rf}, res
end
def test_url_prefix
p = IO.popen(['./whatweb',
'--color', 'never',
'--url-prefix','https://',
"#{@test_host}/"], 'r+')
res = p.read.to_s
p.close
assert res
assert_match %r{WhatWeb - Next generation web scanner.}, res
end
def test_inform_user_deprecated_plugin
res = IO.popen(['./whatweb',
'-p','./test/plugins/deprecated-plugin-format.rb',
"https://#{@test_host}/"], :err => [ :child, :out ]).read
assert_includes res, "This plugin may be using a deprecated plugin format"
end
def test_idn_domains
p = IO.popen(['./whatweb',
'--color', 'never',
"http://www.詹姆斯.com/"], 'r+')
res = p.read.to_s
p.close
assert res
assert_includes res, "http://www.xn--8ws00zhy3a.com/ [200 OK]"
end
end
|