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(site, save_file: true) ⇒ WordPress

Returns a new instance of WordPress.



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

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

Instance Attribute Details

#save_fileObject

Returns the value of attribute save_file.



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

def save_file
  @save_file
end

#siteObject

Returns the value of attribute site.



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

def site
  @site
end

Instance Method Details

#all_in_one_seoObject



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

def all_in_one_seo
  alios = Snackhack2::get(@site)
  if alios.code == 200
    if 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
  end
end

#file_siteObject



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

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

#runObject



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

def run
  
  yoast_seo
  users
  wp_content_uploads
  all_in_one_seo
  wp_log
end

#usersObject



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

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

  if !found_users.empty?
    if @save_file
      Snackhack2::file_save(@site, "users", found_users)
    else
      puts found_users
    end
  end
end

#wp_content_uploadsObject



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

def wp_content_uploads
  s = Snackhack2::get(File.join(@site, '/wp-content/uploads/'))
  if s.code == 200
    if s.body.include?('Index of')
      puts "[+] #{File.join(@site, '/wp-content/uploads/')} is valid..."
    end
  end
end

#wp_logObject



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

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|
      if log.body.include?(e)
        wplog_score += 10
      end
    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



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

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|
      if plug.body.include?(e)
        wp_plugin_score += 10
      end
    end
  end
  puts "[+] WordPress Plugin Score: #{wp_plugin_score}"
end

#yoast_seoObject



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

def yoast_seo
  ys = Snackhack2::get(@site)
  if ys.code == 200
    if ys.body.match(/ This site is optimized with the Yoast SEO plugin\s.\d\d.\d/)
      puts "#{ys.body.match(/ This site is optimized with the Yoast SEO plugin\s.\d\d.\d/)}"
    end
  end
end