Codebase list bettercap / a4632e2
Import upstream version 2.32.0+git20211129.1.ed4239f Kali Janitor 2 years ago
4 changed file(s) with 85 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
22
33 ENV SRC_DIR $GOPATH/src/github.com/bettercap/bettercap
44
5 RUN apk add --update ca-certificates
6 RUN apk add --no-cache --update bash iptables wireless-tools build-base libpcap-dev libusb-dev linux-headers libnetfilter_queue-dev git
5 RUN apk add --no-cache ca-certificates
6 RUN apk add --no-cache bash iptables wireless-tools build-base libpcap-dev libusb-dev linux-headers libnetfilter_queue-dev git
77
88 WORKDIR $SRC_DIR
99 ADD . $SRC_DIR
1515
1616 # final stage
1717 FROM alpine
18 RUN apk add --update ca-certificates
19 RUN apk add --no-cache --update bash iproute2 libpcap libusb-dev libnetfilter_queue wireless-tools
18 RUN apk add --no-cache ca-certificates
19 RUN apk add --no-cache bash iproute2 libpcap libusb-dev libnetfilter_queue wireless-tools
2020 COPY --from=build-env /go/src/github.com/bettercap/bettercap/bettercap /app/
2121 COPY --from=build-env /usr/local/share/bettercap/caplets /app/
2222 WORKDIR /app
2828
2929 var (
3030 BroadcastHw = []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
31 IPv4Validator = regexp.MustCompile(`^[0-9\.]+/?\d*$`)
32 IPv4RangeValidator = regexp.MustCompile(`^[0-9\.\-]+/?\d*$`)
33 MACValidator = regexp.MustCompile(`(?i)^[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}$`)
31 IPv4BlockValidator = regexp.MustCompile(`^` +
32 `(?:(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.){3}` +
33 `(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])` +
34 `/(?:3[0-2]|2[0-9]|[1]?[0-9])` + `$`)
35 IPv4RangeValidator = regexp.MustCompile(`^` +
36 `(?:(?:(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])-)?(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.){3}` +
37 `(?:(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])-)?(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])` + `$`)
38 IPv4Validator = regexp.MustCompile(`^` +
39 `(?:(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.){3}` +
40 `(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])` + `$`)
41 MACValidator = regexp.MustCompile(`(?i)^(?:[a-f0-9]{2}:){5}[a-f0-9]{2}$`)
3442 // lulz this sounds like a hamburger
35 macParser = regexp.MustCompile(`(?i)([a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2})`)
43 macParser = regexp.MustCompile(`(?i)((?:[a-f0-9]{2}:){5}[a-f0-9]{2})`)
3644 aliasParser = regexp.MustCompile(`(?i)([a-z_][a-z_0-9]+)`)
3745 )
3846
187195
188196 for _, a := range addrs {
189197 address := a.String()
190 if IPv4Validator.MatchString(address) {
191 if !strings.ContainsRune(address, '/') {
192 // plain ip
193 e.SetIP(address)
194 } else {
195 // ip/bits
196 e.SetNetwork(address)
197 }
198 } else {
199 // ipv6/xxx
198 switch true {
199 case IPv4Validator.MatchString(address):
200 e.SetIP(address)
201 break
202 case IPv4BlockValidator.MatchString(address):
203 e.SetNetwork(address)
204 break
205 default:
200206 e.SetIPv6(address)
207 break
201208 }
202209 }
203210
246253
247254 // user did not provide an interface name,
248255 // return the first one with a valid ipv4
249 // address
256 // address that does not loop back
250257 for _, iface := range ifaces {
251258 addrs, err := iface.Addrs()
252259 if err != nil {
256263
257264 for _, address := range addrs {
258265 ip := address.String()
259 if !strings.Contains(ip, "127.0.0.1") && IPv4Validator.MatchString(ip) {
266 if !strings.HasPrefix(ip, "127.0.0.1") && IPv4BlockValidator.MatchString(ip) {
260267 return buildEndpointFromInterface(iface)
261268 }
262269 }
7272 }
7373
7474 var iwPhyParser = regexp.MustCompile(`^\s*wiphy\s+(\d+)$`)
75 var iwFreqParser = regexp.MustCompile(`^\s+\*\s+(\d+)\s+MHz.+$`)
75 var iwFreqParser = regexp.MustCompile(`^\s+\*\s+(\d+)\s+MHz.+dBm.+$`)
7676
7777 func iwSupportedFrequencies(iface string) ([]int, error) {
7878 // first determine phy index
00 package routing
11
22 import (
3 "regexp"
4 "strings"
5
36 "github.com/bettercap/bettercap/core"
47 "github.com/evilsocket/islazy/str"
5 "regexp"
6 "strings"
78 )
89
9 var parser = regexp.MustCompile(`^(.+)\sdev\s([^\s]+)\s(.+)$`)
10 var (
11 routeHeadings []string
12 whitespaceParser = regexp.MustCompile(`\s+`)
13 )
1014
1115 func update() ([]Route, error) {
1216 table = make([]Route, 0)
1317
14 for ip, inet := range map[RouteType]string{IPv4: "inet", IPv6: "inet6"} {
15 output, err := core.Exec("ip", []string{"-f", inet, "route"})
16 if err != nil {
17 return nil, err
18 }
18 output, err := core.Exec("netstat", []string{"-r", "-n", "-4", "-6"})
19 if err != nil {
20 return nil, err
21 }
22 // because entries are separated by whitespace
23 output = strings.ReplaceAll(output, "Next Hop", "Gateway")
1924
20 for _, line := range strings.Split(output, "\n") {
21 if line = str.Trim(line); len(line) > 0 {
22 matches := parser.FindStringSubmatch(line)
23 if num := len(matches); num == 4 {
24 route := Route{
25 Type: ip,
26 Destination: matches[1],
27 Device: matches[2],
28 Flags: matches[3],
29 Default: strings.Index(matches[1], "default ") == 0,
30 }
25 for _, line := range strings.Split(output, "\n") {
26 if line = str.Trim(line); len(line) != 0 {
27 parts := whitespaceParser.Split(line, -1)
28 if parts[0] == "Kernel" {
29 continue
30 }
3131
32 if idx := strings.Index(route.Destination, " via "); idx >= 0 {
33 route.Gateway = route.Destination[idx + len(" via "):]
34 route.Destination = route.Destination[:idx]
35 }
32 if parts[0] == "Destination" {
33 routeHeadings = parts
34 continue
35 }
3636
37 table = append(table, route)
37 route := Route{}
38 for i, s := range parts {
39 switch routeHeadings[i] {
40 case "Destination":
41 route.Destination = s
42 break
43 case "Flag":
44 route.Flags = s
45 break
46 case "Flags":
47 route.Flags = s
48 break
49 case "Gateway":
50 route.Gateway = s
51 break
52 case "If":
53 route.Device = s
54 break
55 case "Iface":
56 route.Device = s
57 break
58 case "Netif":
59 route.Device = s
60 break
3861 }
3962 }
63
64 route.Default = strings.Contains(route.Flags, "G")
65
66 if strings.ContainsRune(route.Destination, '.') || strings.ContainsRune(route.Gateway, '.') {
67 route.Type = IPv4
68 } else {
69 route.Type = IPv6
70 }
71
72 table = append(table, route)
4073 }
4174 }
4275