Skip to content

Commit c62e12d

Browse files
committed
Initial commit
0 parents  commit c62e12d

5 files changed

Lines changed: 97 additions & 0 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
all:
2+
env GOOS=darwin GOARCH=amd64 go build -o build/wp-audit_macos
3+
env GOOS=linux GOARCH=amd64 go build -o build/wp-audit_linux
4+
env GOOS=windows GOARCH=amd64 go build -o build/wp-audit_windows

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Wordpress Version Scanner
2+
3+
If you host a lot of Wordpress sites, you probably want to make sure they have all required updates.
4+
5+
This little Go tool will scan a list of Wordpress sites in parallel and print the corresponding version.
6+
7+
## Installation
8+
Use the pre-built binaries from the *Release* page or with Go installed:
9+
10+
`$ go get -uv github.com/m3nu/wp-audit`
11+
12+
## Usage
13+
First add all your WordPress domains in a textfile, omitting the protocol. See `domains.txt` for an example. Lines starting with `#` are ignored.
14+
15+
Then run `wp-audit` by passing the textfile. It will look for a file called `domains.txt` by default.
16+
17+
`$ wp-audit --domain-list domains.txt`
18+
19+
## License
20+
(C) Manuel Riel, 2019
21+
22+
This project is licensed under the terms of the MIT license.

build/.gitkeep

Whitespace-only changes.

domains.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# this is a comment and will be ignored
2+
www.saiaja.com.br
3+
murviel-info-beziers.com
4+
www.thetruthseeker.co.uk

main.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"io/ioutil"
7+
"net/http"
8+
"regexp"
9+
)
10+
11+
type wordpressSite struct {
12+
hostname string
13+
version string
14+
}
15+
16+
var wpVersionRegexList = []string{
17+
`content="WordPress ([\d\.]+)`,
18+
`wp\-embed\.min\.js\?ver=([\d\.]+)`,
19+
`comment\-reply\.min\.js\?ver=([\d\.]+)`,
20+
`wp\-emoji\-release\.min\.js\?ver=([\d\.]+)`,
21+
}
22+
23+
var domainListPath = flag.String("domain-list", "domains.txt", "Path to the list of domains to be surveyed.")
24+
25+
var scanStream = make(chan *wordpressSite)
26+
27+
func main() {
28+
flag.Parse()
29+
domainList, err := ioutil.ReadFile(*domainListPath)
30+
if err != nil {
31+
fmt.Println("error", err)
32+
}
33+
domains := regexp.MustCompile(`\n+`).Split(string(domainList), -1)
34+
n := 0
35+
for _, d := range domains {
36+
if len(d) > 0 && d[0] != '#' {
37+
w := &wordpressSite{string(d), ""}
38+
go getWPVersion(w)
39+
n++
40+
}
41+
}
42+
43+
for i := n; i != 0; i-- {
44+
site := <-scanStream
45+
fmt.Println("Site", site.hostname, "is on version", site.version)
46+
}
47+
}
48+
49+
50+
func getWPVersion(s *wordpressSite) {
51+
resp, err := http.Get(fmt.Sprintf("http://%s", s.hostname))
52+
if err != nil {
53+
fmt.Println("Error getting version for", s.hostname)
54+
s.version = "unknown"
55+
scanStream <- s
56+
return
57+
}
58+
defer resp.Body.Close()
59+
body, err := ioutil.ReadAll(resp.Body)
60+
for _, r := range wpVersionRegexList {
61+
match := regexp.MustCompile(r).FindStringSubmatch(string(body))
62+
if len(match) > 1 {
63+
s.version = match[1]
64+
}
65+
}
66+
scanStream <- s
67+
}

0 commit comments

Comments
 (0)