mirror of
https://github.com/bettercap/bettercap
synced 2025-08-24 07:06:18 -07:00
Updated 'replacements' settings (better use of wildcards)
This commit is contained in:
parent
a8f10b6333
commit
9fbad95a79
3 changed files with 19 additions and 16 deletions
|
@ -55,8 +55,8 @@ func NewHttpProxy(s *session.Session) *HttpProxy {
|
||||||
"Enable or disable SSL stripping."))
|
"Enable or disable SSL stripping."))
|
||||||
|
|
||||||
mod.AddParam(session.NewStringParameter("http.proxy.sslstrip.replacements",
|
mod.AddParam(session.NewStringParameter("http.proxy.sslstrip.replacements",
|
||||||
"com:corn net:nel org:orq", "(.*:.*\\s*$)+",
|
"*.com:*.corn *.net:*.nel *.org:*.orq", "(.*:.*\\s*$)+",
|
||||||
"Space separated list of '<original_chars>:<stripped_chars>', and ordered by priority. Use '*' for any domain. Internationalized Domain Names are allowed. If the domain to strip isn't found in this parameter, the last char of the top-level domain will be duplicated."))
|
"Space separated list of '<original_domain>:<stripped_domain>', and ordered by priority. Use '*' for any characters. Internationalized Domain Names are allowed. If the domain to strip isn't found in this parameter, the last char of the top-level domain will be duplicated."))
|
||||||
|
|
||||||
mod.AddHandler(session.NewModuleHandler("http.proxy on", "",
|
mod.AddHandler(session.NewModuleHandler("http.proxy on", "",
|
||||||
"Start HTTP proxy.",
|
"Start HTTP proxy.",
|
||||||
|
|
|
@ -142,23 +142,26 @@ func (s *SSLStripper) processURL(url string) string {
|
||||||
iPort = iEndHost
|
iPort = iEndHost
|
||||||
}
|
}
|
||||||
// search for domain's part to replace according to the settings
|
// search for domain's part to replace according to the settings
|
||||||
replacement := []string{}
|
replaceto := ""
|
||||||
for _, r := range strings.Fields(s.replacements) {
|
for _, r := range strings.Fields(s.replacements) {
|
||||||
rep := strings.Split(r, ":")
|
rep := strings.Split(r, ":")
|
||||||
if rep[0] == "*" {
|
replacer := regexp.MustCompile("(?i)^" + strings.ReplaceAll(regexp.QuoteMeta(rep[0]), "\\*", "(.+)") + "$") //allow using * to designate any existing character + case insensitive
|
||||||
rep[0] = url[:iPort]
|
if replacer.MatchString(url[:iPort]) {
|
||||||
}
|
replacement := ""
|
||||||
if strings.Contains(url[:iPort], rep[0]) {
|
sreplacement := strings.Split(rep[1], "*")
|
||||||
replacement = rep
|
for i := range sreplacement {
|
||||||
|
replacement += sreplacement[i]
|
||||||
|
if i+1 < len(sreplacement) {
|
||||||
|
replacement += "${" + strconv.Itoa(i+1) + "}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
replaceto = replacer.ReplaceAllString(url[:iPort], replacement)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(replacement) != 0{
|
if len(replaceto) != 0 {
|
||||||
// replace domain according to the settings & strip HTTPS port (if any)
|
// replace domain according to the settings & strip HTTPS port (if any)
|
||||||
url = url[:iPort] + url[iEndHost:]
|
url = replaceto + url[iEndHost:]
|
||||||
iReplacement := strings.LastIndex(url, replacement[0])
|
|
||||||
replaceto := strings.ReplaceAll(replacement[1], "*", replacement[0])
|
|
||||||
url = url[:iReplacement] + replaceto + url[iReplacement+len(replacement[0]):]
|
|
||||||
} else {
|
} else {
|
||||||
// double the last TLD's character & strip HTTPS port (if any)
|
// double the last TLD's character & strip HTTPS port (if any)
|
||||||
url = url[:iPort] + string(url[iPort-1]) + url[iEndHost:]
|
url = url[:iPort] + string(url[iPort-1]) + url[iEndHost:]
|
||||||
|
|
|
@ -41,9 +41,9 @@ func NewHttpsProxy(s *session.Session) *HttpsProxy {
|
||||||
"false",
|
"false",
|
||||||
"Enable or disable SSL stripping."))
|
"Enable or disable SSL stripping."))
|
||||||
|
|
||||||
mod.AddParam(session.NewStringParameter("http.proxy.sslstrip.replacements",
|
mod.AddParam(session.NewStringParameter("https.proxy.sslstrip.replacements",
|
||||||
"com:corn net:nel org:orq", "(.*:.*\\s*$)+",
|
"*.com:*.corn *.net:*.nel *.org:*.orq", "(.*:.*\\s*$)+",
|
||||||
"Space separated list of '<original_chars>:<stripped_chars>', and ordered by priority. Use '*' for any domain. You can use Internationalized Domain Names. If the domain to strip isn't found in this parameter, the last char of the top-level domain will be duplicated."))
|
"Space separated list of '<original_domain>:<stripped_domain>', and ordered by priority. Use '*' for any characters. You can use Internationalized Domain Names. If the domain to strip isn't found in this parameter, the last char of the top-level domain will be duplicated."))
|
||||||
|
|
||||||
mod.AddParam(session.NewStringParameter("https.proxy.injectjs",
|
mod.AddParam(session.NewStringParameter("https.proxy.injectjs",
|
||||||
"",
|
"",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue