Class: Snackhack2::WordPress

Inherits:
Object
  • Object
show all
Defined in:
lib/snackhack2/wordpress.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(save_file: true) ⇒ WordPress



9
10
11
12
# File 'lib/snackhack2/wordpress.rb', line 9

def initialize(save_file: true)
  @site = site
  @save_file = save_file
end

Instance Attribute Details

#save_fileObject

Returns the value of attribute save_file.



7
8
9
# File 'lib/snackhack2/wordpress.rb', line 7

def save_file
  @save_file
end

#siteObject

Returns the value of attribute site.



7
8
9
# File 'lib/snackhack2/wordpress.rb', line 7

def site
  @site
end

Instance Method Details

#all_in_one_seoObject



85
86
87
88
89
90
91
# File 'lib/snackhack2/wordpress.rb', line 85

def all_in_one_seo
  alios = Snackhack2.get(@site)
  return unless alios.code == 200
  return unless alios.body.scan(/(All in One SEO Pro\s\d.\d.\d)/)

  puts "Site is using the plugin: #{alios.body.match(/(All in One SEO Pro\s\d.\d.\d)/)}"
end

#file_siteObject



23
24
25
# File 'lib/snackhack2/wordpress.rb', line 23

def file_site
  @site = @site.gsub('https://', '')
end

#runObject



14
15
16
17
18
19
20
21
# File 'lib/snackhack2/wordpress.rb', line 14

def run
  
  yoast_seo
  users
  wp_content_uploads
  all_in_one_seo
  wp_log
end

#usersObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/snackhack2/wordpress.rb', line 27

def users
  found_users = ''
  begin
    users = Snackhack2.get(File.join(@site, 'wp-json', 'wp', 'v2', 'users')).body
    json = JSON.parse(users)
    json.each do |k|
      found_users += "#{k['name']}\n"
    end
  rescue StandardError
    puts "[+] users not found\n\n\n"
  end

  return if found_users.empty?

  if @save_file
    Snackhack2.file_save(@site, 'users', found_users)
  else
    puts found_users
  end
end

#wp_content_uploadsObject



48
49
50
51
52
53
54
# File 'lib/snackhack2/wordpress.rb', line 48

def wp_content_uploads
  s = Snackhack2.get(File.join(@site, '/wp-content/uploads/'))
  return unless s.code == 200
  return unless s.body.include?('Index of')

  puts "[+] #{File.join(@site, '/wp-content/uploads/')} is valid...\n\n\n"
end

#wp_logObject



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/snackhack2/wordpress.rb', line 93

def wp_log
  wplog_score = 0
  wp = ['\wp-content\plugins', 'PHP Notice', 'wp-cron.php', '/var/www/html', 'Yoast\WP\SEO', 'wordpress-seo']
  log = Snackhack2.get(File.join(@site, '/wp-content/debug.log'))
  if log.code == 200
    puts "[+] #{File.join(@site, '/wp-content/debug.log')} is giving status 200. Now double checking...\n\n\n"
    wp.each do |e|
      wplog_score += 10 if log.body.include?(e)
    end
  end
  puts "WordPress Log score: #{wplog_score}...\n\n\n"
end

#wp_loginObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/snackhack2/wordpress.rb', line 56

def 
  percent = 0
  ## todo: maybe add Bayes Theorem to detect wp

  wp = ['wp-includes', 'wp-admin', 'Powered by WordPress', 'wp-login.php', 'yoast.com/wordpress/plugins/seo/',
        'wordpress-login-url.jpg', 'wp-content/themes/', 'wp-json']
   = Snackhack2.get(File.join(@site, 'wp-login.php'))
  if .code == 200
    wp.each do |path|
      percent += 10 if .body.include?(path)
    end
  end
  login2 = Snackhack2.get(@site.to_s)
  wp.each do |path|
    percent += 10 if login2.body.include?(path)
  end
  puts "Wordpress Points: #{percent}"
end

#wp_pluginObject



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/snackhack2/wordpress.rb', line 106

def wp_plugin
  wp_plugin_score = 0
  wp = ['Index of', 'Name', 'Last modified', 'Size', 'Parent Directory', '/wp-content/plugins']
  plug = Snackhack2.get(File.join(@site, '/wp-content/plugins/'))
  if plug.code == 200
    puts "[+] Looks like #{File.join(@site,
                                     '/wp-content/plugins/')} is giving status 200. Checking to make sure...\n\n\n"
    wp.each do |e|
      wp_plugin_score += 10 if plug.body.include?(e)
    end
  end
  puts "[+] WordPress Plugin Score: #{wp_plugin_score}"
end

#yoast_seoObject



74
75
76
77
78
79
80
81
82
83
# File 'lib/snackhack2/wordpress.rb', line 74

def yoast_seo
  ys = Snackhack2.get(@site)
  return unless ys.code == 200

  yoast_version = ys.body.split('<!-- This site is optimized with the Yoast SEO Premium plugin')[1].split(' -->')[0]
  ['This site is optimized with the Yoast SEO plugin',
   'This site is optimized with the Yoast SEO Premium plugin'].each do |site|
    puts "#{ys.body.scan(/#{site}/).shift} with version #{yoast_version}" unless ys.body.scan(/#{site}/).shift.nil?
  end
end