Skip to content

Commit

Permalink
add isBadURL func arg to TryServeBadClient()
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed May 24, 2022
1 parent ef2a6ef commit cf6c0ff
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions server/badclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ the urls come from observing attacks on my websites
var (
// exact url matche
badClients = map[string]bool{
"/images/": true,
"/files/": true,
"/uploads/": true,
"/admin/controller/extension/extension/": true,
"/sites/default/files/": true,
"/media-admin.php": true,
"/templates/beez3/ALFA_DATA": true,
"/images/": true,
"/files/": true,
"/uploads/": true,
"/sites/default/files/": true,
"/templates/beez3/ALFA_DATA": true,
}
// if url contains
badClientsContains = []string{
"/wp-login.php",
"/wp-includes/wlwmanifest.xml",
"/xmlrpc.php",
".env",
".git/index",
"id_rsa",
"id_dsa",
"/etc/passwd",
Expand All @@ -41,9 +38,10 @@ var (
"/wp-", // lots
"/.well-known/",
"/plus/",
"/index.php",
"/?-",
"/index?-",
"/.git",
"/admin",
}
// if url ends with
badClientSuffix = []string{
Expand Down Expand Up @@ -74,8 +72,8 @@ func init() {
}

// returns true if sent a response to the client
func TryServeBadClient(w http.ResponseWriter, r *http.Request) bool {
isBadClient := func(uri string) bool {
func TryServeBadClient(w http.ResponseWriter, r *http.Request, isBadURL func(s string) bool) bool {
isBad := func(uri string) bool {
if badClients[uri] {
return true
}
Expand All @@ -94,9 +92,12 @@ func TryServeBadClient(w http.ResponseWriter, r *http.Request) bool {
return true
}
}
if isBadURL != nil {
return isBadURL(uri)
}
return false
}
if !isBadClient(r.URL.Path) {
if !isBad(r.URL.Path) {
return false
}
w.Header().Add("Content-Tyep", "text/html")
Expand Down

0 comments on commit cf6c0ff

Please sign in to comment.