From a46917be5f6e77c11171391bc1a89b59d77e0f29 Mon Sep 17 00:00:00 2001 From: L1ghtn1ng Date: Thu, 28 Dec 2023 15:01:51 +0000 Subject: [PATCH 1/3] Update Go version and dependencies, refine build steps and add flags support Updated the Go language version from 1.20 to 1.21 and dependencies versions. Altered instructions in README.md to distinguish building from source and installation section. Also, replaced user input collection with command-line flags in cowitness.go for better usability. --- .github/workflows/go.yml | 2 +- .github/workflows/gorelease.yml | 2 +- README.md | 24 +++++++++--------- cowitness.go | 44 +++++++++++++++++---------------- go.mod | 8 +++--- go.sum | 7 ++++++ 6 files changed, 47 insertions(+), 40 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index acd51ff..cedebfa 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version: '1.21' check-latest: true cache: true diff --git a/.github/workflows/gorelease.yml b/.github/workflows/gorelease.yml index 89cfc9c..3658625 100644 --- a/.github/workflows/gorelease.yml +++ b/.github/workflows/gorelease.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version: '1.21' cache: true - uses: goreleaser/goreleaser-action@v5 diff --git a/README.md b/README.md index 68500e0..16c88e0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -

CoWitness

+

CoWitness

-

+

![Images\CoWitness.png](https://github.com/officialjm/cowitness/blob/main/Images/CoWitness.png) @@ -28,11 +28,11 @@ Before using CoWitness, ensure that you have the following requirements: -- Go programming language installed on your system, get it [HERE](https://go.dev/). +- Go programming language installed on your system, get it [HERE](https://go.dev/) go 1.21 required if building from source. - Internet access to download Go dependencies. - A remote server with a public IP address. -## Installation 👨🏼‍🔧 +## Build 👨🏼‍🔧 Follow these steps to install and compile CoWitness: @@ -51,12 +51,12 @@ cd CoWitness 3. Build the CoWitness executable: ```bash -go build cowitness.go +make -f Makefile build ``` -This command compiles the CoWitness source code and creates an executable file. +This command compiles the CoWitness source code and creates an executable file for amd64 and arm64. -## Usage 👨🏻‍💻 +## Installation 👨🏻‍💻 **To use CoWitness on a remote server, follow these steps**: @@ -72,22 +72,20 @@ Connect to the remote server via SSH: ```bash ssh username@your-server-ip ``` -Navigate to the directory where you transferred the CoWitness executable and run the CoWitness executable: - +Easy way to install cowitness is to get the automated package build from [here](https://github.com/stolenusername/cowitness/releases/latest) +which you can then curl or wget to your system or scp the file over from your system. ```bash -./CoWitness +cowitness ``` ## Customization ⚒️ You can customize CoWitness to fit your specific needs. Here are some possible modifications: -- **Change the default ports**: Modify the constants `HTTPPort`, `HTTPSPort`, and `DNSPort` in the source code to use different port numbers. +- **Change the default ports**: See the usage help for the cli flags to change the default ports - **Modify the log file paths**: You can change the paths for the HTTP and DNS log files (http.log and dns.log) by updating the `os.OpenFile` calls in the source code. -- **Customize the banner**: You can modify the ASCII art banner displayed when CoWitness starts by editing the displayBanner function in the source code. -

### Community & Contributions diff --git a/cowitness.go b/cowitness.go index b54fdaa..78fc030 100644 --- a/cowitness.go +++ b/cowitness.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "log" "net" @@ -13,27 +14,39 @@ import ( "github.com/miekg/dns" ) -const ( - HTTPPort = 80 - HTTPSPort = 443 - DNSPort = 53 -) - var ( DNSResponseIP string DNSResponseName string DefaultTTL int + DisplayBanner bool + HTTPPort int + HTTPSPort int + DNSPort int ) func main() { - displayBanner() - rootDir, err := os.Getwd() if err != nil { log.Fatal(err) } - requestUserInputs() + flag.StringVar(&DNSResponseIP, "i", "", "The DNS response IP(required).") + flag.StringVar(&DNSResponseName, "n", "", "The DNS response name(required).") + flag.IntVar(&HTTPPort, "http", 80, "HTTP port") + flag.IntVar(&HTTPSPort, "https", 443, "HTTPS port") + flag.IntVar(&DNSPort, "dns", 53, "DNS port") + flag.IntVar(&DefaultTTL, "t", 3600, "The Time To Live.") + flag.BoolVar(&DisplayBanner, "q", false, "Disable banner output") + flag.Parse() + + if DisplayBanner != false { + } else { + displayBanner() + } + + if DNSResponseIP == "" || DNSResponseName == "" { + log.Fatal("-i and -n are required. Please see help output with -h") + } httpLogFile, dnsLogFile := createLogFiles() defer closeLogFiles(httpLogFile, dnsLogFile) @@ -68,17 +81,6 @@ func main() { select {} } -func requestUserInputs() { - fmt.Print("Enter the DNS response IP: ") - fmt.Scanln(&DNSResponseIP) - - fmt.Print("Enter the DNS response name: ") - fmt.Scanln(&DNSResponseName) - - fmt.Print("Enter the Default TTL: ") - fmt.Scanln(&DefaultTTL) -} - func createLogFiles() (*os.File, *os.File) { httpLogFile, err := os.OpenFile("./http.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { @@ -196,7 +198,7 @@ func killDNSonExit() { func displayBanner() { red := "\033[31m" reset := "\033[0m" - cowitnessVersion := "v1.1" + cowitnessVersion := "v1.3" banner := red + ` ⢠⡄ ⣠⣤⣾⣷⣤⣄⡀⠀⠀⠀⠀ diff --git a/go.mod b/go.mod index 1a6effc..753469d 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ module cowitness -go 1.20 +go 1.21 -require github.com/miekg/dns v1.1.56 +require github.com/miekg/dns v1.1.57 require ( golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.15.0 // indirect - golang.org/x/sys v0.12.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect golang.org/x/tools v0.13.0 // indirect ) diff --git a/go.sum b/go.sum index 9d4e935..e018f20 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,18 @@ github.com/miekg/dns v1.1.56 h1:5imZaSeoRNvpM9SzWNhEcP9QliKiz20/dA2QabIGVnE= github.com/miekg/dns v1.1.56/go.mod h1:cRm6Oo2C8TY9ZS/TqsSrseAcncm74lfK5G+ikN2SWWY= +github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM= +github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= From 829f49b09692b2220bcd6c27f765867813b23556 Mon Sep 17 00:00:00 2001 From: L1ghtn1ng Date: Mon, 1 Jan 2024 23:22:27 +0000 Subject: [PATCH 2/3] Add version display functionality Added a new function and argument flag to display the program's version upon request. This new function prints the program version when the "-v" flag is used. Additionally, refactored the displayBanner function to use the new version function, enhancing code reusability. --- cowitness.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cowitness.go b/cowitness.go index 78fc030..1585452 100644 --- a/cowitness.go +++ b/cowitness.go @@ -19,11 +19,16 @@ var ( DNSResponseName string DefaultTTL int DisplayBanner bool + DisplayVersion bool HTTPPort int HTTPSPort int DNSPort int ) +func version() string { + return "v1.3" +} + func main() { rootDir, err := os.Getwd() if err != nil { @@ -37,8 +42,14 @@ func main() { flag.IntVar(&DNSPort, "dns", 53, "DNS port") flag.IntVar(&DefaultTTL, "t", 3600, "The Time To Live.") flag.BoolVar(&DisplayBanner, "q", false, "Disable banner output") + flag.BoolVar(&DisplayVersion, "v", false, "Print program version") flag.Parse() + if DisplayVersion { + fmt.Print(version()) + os.Exit(0) + } + if DisplayBanner != false { } else { displayBanner() @@ -198,7 +209,6 @@ func killDNSonExit() { func displayBanner() { red := "\033[31m" reset := "\033[0m" - cowitnessVersion := "v1.3" banner := red + ` ⢠⡄ ⣠⣤⣾⣷⣤⣄⡀⠀⠀⠀⠀ @@ -212,6 +222,6 @@ func displayBanner() { ` + reset fmt.Print(banner) - fmt.Println(" CoWitness", cowitnessVersion, "- Tool for HTTP, HTTPS, and DNS Server") + fmt.Println(" CoWitness", version(), "- Tool for HTTP, HTTPS, and DNS Server") fmt.Println() } From 8d4fe2626dcb8864268dd9b9cb8c9561eabfb910 Mon Sep 17 00:00:00 2001 From: L1ghtn1ng Date: Mon, 1 Jan 2024 23:28:17 +0000 Subject: [PATCH 3/3] go mod tidy --- go.sum | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/go.sum b/go.sum index e018f20..cbea975 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,11 @@ -github.com/miekg/dns v1.1.56 h1:5imZaSeoRNvpM9SzWNhEcP9QliKiz20/dA2QabIGVnE= -github.com/miekg/dns v1.1.56/go.mod h1:cRm6Oo2C8TY9ZS/TqsSrseAcncm74lfK5G+ikN2SWWY= github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM= github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=