resetpw - warvox - VoIP based wardialing tool, forked from rapid7/warvox.
(HTM) git clone git://jay.scot/warvox
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
resetpw (2352B)
---
1 #!/usr/bin/env ruby
2
3 ENV['RAILS_ENV'] ||= 'production'
4
5 # bundler/setup just sets up the $LOAD_PATHs, the gems aren't automatically required...
6 ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile',File.dirname(__FILE__))
7 require 'bundler/setup'
8
9 # rails/all must be required explicitly to get the railties that pro/ui/config/application.rb uses
10 require 'rails/all'
11 # require all the gems in the current environment
12 Bundler.require(*Rails.groups(assets: %w(development test cucumber)))
13
14 APP_PATH = File.expand_path('../../config/application', __FILE__)
15 require File.expand_path('../../config/boot', __FILE__)
16 require APP_PATH
17 Rails.application.require_environment!
18
19 uname = ARGV.shift
20 upass = ARGV.shift
21
22 def generate_password
23 set = ( [*(0x21 .. 0x2f)] + [*(0x3a .. 0x3F)] + [*(0x5b .. 0x60)] + [*(0x7b .. 0x7e)] ).flatten.pack("C*")
24 set << "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
25 str = ''
26 cnt = 0
27 while not (str.length >= 8 and str =~ /[A-Za-z]/ and str =~ /[0-9]/ and str =~ /[\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5c\x5d\x5e\x5f\x60\x7b\x7c\x7d\x7e]/)
28 if str.length > 12
29 str = str[0,4]
30 next
31 end
32 str << set[ rand(set.length), 1]
33 cnt += 1
34 end
35 str
36 end
37
38
39 user = uname ? User.find_by_login(uname) : User.first
40 if uname and not user
41 $stderr.puts "[-] User #{uname} was not found"
42 exit(1)
43 end
44
45 if not user
46 $stderr.puts "[-] No user account has been created"
47 exit(1)
48 end
49
50 randpass = upass || generate_password()
51
52
53 $stdout.puts %Q|
54
55 ********************************
56 * *
57 * WarVOX Password Reset *
58 * *
59 ********************************
60
61 [*] Warning! This tool will reset the password for the '#{user.login}' user account.
62 [*] To continue, please type "yes"
63
64 |
65
66 $stdout.write "Continue? (yes/no) > "
67 $stdout.flush
68
69 inp = $stdin.readline
70
71 if inp.strip.downcase != 'yes'
72 $stdout.puts "[*] Reset cancelled, hit enter to exit"
73 $stdin.readline
74 exit(0)
75 end
76
77
78 user.password = randpass
79 user.password_confirmation = randpass
80 user.save!
81
82 $stdout.puts %Q|
83 [*] The password for #{user.login} has been reset to a random value
84
85 New Password: #{randpass}
86
87 [*] Please change this password on the next login.
88 |
89
90 $stdout.puts "[*] Hit enter to exit"
91 $stdin.readline
92 exit(0)