-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de627bd
commit 9723166
Showing
8 changed files
with
545 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Honeytrap | ||
* Copyright (C) 2016-2017 DutchSec (https://dutchsec.com/) | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Affero General Public License version 3 as published by the | ||
* Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* version 3 along with this program in the file "LICENSE". If not, see | ||
* <http://www.gnu.org/licenses/agpl-3.0.txt>. | ||
* | ||
* See https://honeytrap.io/ for more details. All requests should be sent to | ||
* licensing@honeytrap.io | ||
* | ||
* The interactive user interfaces in modified source and object code versions | ||
* of this program must display Appropriate Legal Notices, as required under | ||
* Section 5 of the GNU Affero General Public License version 3. | ||
* | ||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, | ||
* these Appropriate Legal Notices must retain the display of the "Powered by | ||
* Honeytrap" logo and retain the original copyright notice. If the display of the | ||
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | ||
* must display the words "Powered by Honeytrap" and retain the original copyright notice. | ||
*/ | ||
|
||
package honeytrap_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
// Nothing special, just check that we can run Honeytrap | ||
func TestDummy(t *testing.T) { | ||
tmpConf, p := runWithConfig("", "--version") | ||
defer os.Remove(tmpConf) | ||
mustWait(p) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Honeytrap | ||
* Copyright (C) 2016-2017 DutchSec (https://dutchsec.com/) | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Affero General Public License version 3 as published by the | ||
* Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* version 3 along with this program in the file "LICENSE". If not, see | ||
* <http://www.gnu.org/licenses/agpl-3.0.txt>. | ||
* | ||
* See https://honeytrap.io/ for more details. All requests should be sent to | ||
* licensing@honeytrap.io | ||
* | ||
* The interactive user interfaces in modified source and object code versions | ||
* of this program must display Appropriate Legal Notices, as required under | ||
* Section 5 of the GNU Affero General Public License version 3. | ||
* | ||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, | ||
* these Appropriate Legal Notices must retain the display of the "Powered by | ||
* Honeytrap" logo and retain the original copyright notice. If the display of the | ||
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | ||
* must display the words "Powered by Honeytrap" and retain the original copyright notice. | ||
*/ | ||
|
||
package cli_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestHelp(t *testing.T) { | ||
out := run(t, "--help") | ||
// The output should contain an explanation of a few flags. | ||
// --help and --version are future-proof. | ||
shouldContain := []string{"--help", "--version"} | ||
for _, s := range shouldContain { | ||
if !strings.Contains(out, s) { | ||
t.Errorf("Help text doesn't contain '%s'", s) | ||
} | ||
} | ||
} | ||
|
||
func TestListServices(t *testing.T) { | ||
out := runWithConfig(t, "", "--list-services") | ||
/* The output should contain a list of services; http and telnet are some | ||
* basic ones. | ||
*/ | ||
shouldContain := []string{"http", "telnet"} | ||
for _, s := range shouldContain { | ||
if !strings.Contains(out, s) { | ||
t.Errorf("Services list doesn't contain '%s'", s) | ||
} | ||
} | ||
} | ||
|
||
func TestListChannels(t *testing.T) { | ||
out := runWithConfig(t, "", "--list-channels") | ||
/* The output should contain a list of channels; console and file are some | ||
* basic ones. | ||
*/ | ||
shouldContain := []string{"console", "file"} | ||
for _, s := range shouldContain { | ||
if !strings.Contains(out, s) { | ||
t.Errorf("Channels list doesn't contain '%s'", s) | ||
} | ||
} | ||
} | ||
|
||
func TestListListeners(t *testing.T) { | ||
out := runWithConfig(t, "", "--list-listeners") | ||
/* The output should contain a list of listeners; socket and agent are some | ||
* basic ones. | ||
*/ | ||
shouldContain := []string{"socket", "agent"} | ||
for _, s := range shouldContain { | ||
if !strings.Contains(out, s) { | ||
t.Errorf("Listeners list doesn't contain '%s'", s) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Honeytrap | ||
* Copyright (C) 2016-2017 DutchSec (https://dutchsec.com/) | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Affero General Public License version 3 as published by the | ||
* Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* version 3 along with this program in the file "LICENSE". If not, see | ||
* <http://www.gnu.org/licenses/agpl-3.0.txt>. | ||
* | ||
* See https://honeytrap.io/ for more details. All requests should be sent to | ||
* licensing@honeytrap.io | ||
* | ||
* The interactive user interfaces in modified source and object code versions | ||
* of this program must display Appropriate Legal Notices, as required under | ||
* Section 5 of the GNU Affero General Public License version 3. | ||
* | ||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, | ||
* these Appropriate Legal Notices must retain the display of the "Powered by | ||
* Honeytrap" logo and retain the original copyright notice. If the display of the | ||
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | ||
* must display the words "Powered by Honeytrap" and retain the original copyright notice. | ||
*/ | ||
|
||
package cli_test | ||
|
||
import "testing" | ||
|
||
func TestInvalidConfig(t *testing.T) { | ||
hasErrored := false | ||
handler := func(error) { hasErrored = true } | ||
runWithConfigAndErrHandler(t, "This is invalid TOML", handler) | ||
if !hasErrored { | ||
t.Error("Didn't error out on an invalid config") | ||
} | ||
} | ||
|
||
func TestValidConfig(t *testing.T) { | ||
hasErrored := false | ||
handler := func(error) { hasErrored = true } | ||
runWithConfigAndErrHandler(t, "# Empty config file", handler) | ||
if hasErrored { | ||
t.Error("Error out on a valid (empty) config") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Honeytrap | ||
* Copyright (C) 2016-2017 DutchSec (https://dutchsec.com/) | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Affero General Public License version 3 as published by the | ||
* Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* version 3 along with this program in the file "LICENSE". If not, see | ||
* <http://www.gnu.org/licenses/agpl-3.0.txt>. | ||
* | ||
* See https://honeytrap.io/ for more details. All requests should be sent to | ||
* licensing@honeytrap.io | ||
* | ||
* The interactive user interfaces in modified source and object code versions | ||
* of this program must display Appropriate Legal Notices, as required under | ||
* Section 5 of the GNU Affero General Public License version 3. | ||
* | ||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, | ||
* these Appropriate Legal Notices must retain the display of the "Powered by | ||
* Honeytrap" logo and retain the original copyright notice. If the display of the | ||
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | ||
* must display the words "Powered by Honeytrap" and retain the original copyright notice. | ||
*/ | ||
|
||
// This file contains test utilities, no actual tests. | ||
|
||
package cli_test | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path" | ||
"testing" | ||
|
||
"github.com/satori/go.uuid" | ||
) | ||
|
||
func run(t *testing.T, flags ...string) string { | ||
return runWithErrHandler(func(e error) { | ||
t.Fatal(e) | ||
}, flags...) | ||
} | ||
|
||
func runWithConfig(t *testing.T, config string, flags ...string) string { | ||
return runWithConfigAndErrHandler(t, config, func(e error) { t.Fatal(e) }, flags...) | ||
} | ||
|
||
func runWithErrHandler(errHandler func(error), flags ...string) string { | ||
cmd := exec.Command("/honeytrap/honeytrap", flags...) | ||
out, err := cmd.Output() | ||
if err != nil { | ||
errHandler(err) | ||
} | ||
return string(out) | ||
} | ||
|
||
func runWithConfigAndErrHandler(t *testing.T, config string, errHandler func(error), flags ...string) string { | ||
tmpPath := path.Join(os.TempDir(), "honeytrap-testfile-"+uuid.NewV4().String()) | ||
tmp, err := os.Create(tmpPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_, err = tmp.WriteString(config) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
flags = append(flags, "-c", tmpPath) | ||
ret := runWithErrHandler(errHandler, flags...) | ||
os.Remove(tmpPath) | ||
return ret | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Honeytrap | ||
* Copyright (C) 2016-2017 DutchSec (https://dutchsec.com/) | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Affero General Public License version 3 as published by the | ||
* Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* version 3 along with this program in the file "LICENSE". If not, see | ||
* <http://www.gnu.org/licenses/agpl-3.0.txt>. | ||
* | ||
* See https://honeytrap.io/ for more details. All requests should be sent to | ||
* licensing@honeytrap.io | ||
* | ||
* The interactive user interfaces in modified source and object code versions | ||
* of this program must display Appropriate Legal Notices, as required under | ||
* Section 5 of the GNU Affero General Public License version 3. | ||
* | ||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, | ||
* these Appropriate Legal Notices must retain the display of the "Powered by | ||
* Honeytrap" logo and retain the original copyright notice. If the display of the | ||
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | ||
* must display the words "Powered by Honeytrap" and retain the original copyright notice. | ||
*/ | ||
|
||
package honeytrap_test | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
"testing" | ||
) | ||
|
||
// Test that we can create a HTTP service and connect to it | ||
func TestHTTP(t *testing.T) { | ||
tmpConf, p := runWithConfig(serviceWithPort("http", "tcp/8000")) | ||
defer os.Remove(tmpConf) | ||
defer p.Kill() | ||
httpClient := http.Client{} | ||
_, err := httpClient.Get("http://127.0.0.1:8000/") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
|
||
// Test that nmap recognizes the HTTP service | ||
func TestNmapHTTP(t *testing.T) { | ||
tmpConf, p := runWithConfig(serviceWithPort("http", "tcp/8000")) | ||
defer os.Remove(tmpConf) | ||
defer p.Kill() | ||
product := nmapIdentify(t, "8000") | ||
if product != "Apache httpd" { | ||
t.Errorf("Expected 'Apache httpd' identification, found '%s'", product) | ||
} | ||
} |
Oops, something went wrong.