Exploit database

GH-d6a97ae4a0ad51e6994484d4cc477a40

misakamikato/cve-2017-7921-golang

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2017-7921

32 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files3

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

src/cve-2017-7921-golang/main_test.go

Go · 5,781 bytes
package main

import (
	"main/src/gip"
	"runtime"
	"strings"
	"testing"
	"time"

	"github.com/levigross/grequests"
)

func TestXore(t *testing.T) {
	testStr1 := []byte("hellworld!")
	testStr2 := []byte("因项目中go程序与java程序需要传输一些加密数据,以下为整理后的Aes(CBC模式)加密解密方法,因java中aes所用的填充算法为PKCS5padding(具体内容可自行查阅),所以在本示例中也采用PKCS5padding")
	testKey := []byte{0x73, 0x8B, 0x55, 0x44}

	cases := []struct {
		first    []byte
		excepted []byte
	}{
		{testStr1, []byte{0x1b, 0xee, 0x39, 0x28, 0x4, 0xe4, 0x27, 0x28, 0x17, 0xaa}},
		{testStr2, []byte{0x96, 0x10, 0xf5, 0xad, 0xd2, 0x32, 0xb2, 0xdf, 0xdd, 0x6f, 0xed, 0xe9, 0x14, 0xe4, 0xb2, 0xec, 0xf8, 0x6e, 0xef, 0xcb, 0x97, 0x33, 0xdb, 0x2e, 0x12, 0xfd, 0x34, 0xa3, 0xdb, 0x0, 0xb0, 0xfe, 0xfc, 0x62, 0xc9, 0xc4, 0x9b, 0x2d, 0xd4, 0xa0, 0xcf, 0x2b, 0xbd, 0xfa, 0xe0, 0x6f, 0xed, 0xc4, 0x97, 0x31, 0xce, 0xa1, 0xf9, 0x2b, 0xb0, 0xeb, 0xf5, 0x6d, 0xc0, 0xf4, 0x95, 0x6, 0xfb, 0xab, 0xcf, 0x7, 0xb1, 0xff, 0xd6, 0x6f, 0xed, 0xcf, 0x97, 0x33, 0xef, 0xa2, 0xe6, 0x3f, 0xb2, 0xd4, 0xf5, 0x6e, 0xc5, 0xca, 0x94, 0x11, 0xd1, 0x5, 0x16, 0xf8, 0x7d, 0x7, 0x31, 0xc8, 0xb3, 0xec, 0xd2, 0x6e, 0xe9, 0xcb, 0x5a, 0x6e, 0xdf, 0xe4, 0x96, 0x24, 0xd3, 0xac, 0xd4, 0x28, 0xb0, 0xeb, 0xf5, 0x6d, 0xc3, 0xfd, 0x95, 0x38, 0xc0, 0xab, 0xcf, 0x7, 0xb0, 0xdf, 0xd3, 0xe1, 0x34, 0x32, 0x12, 0x6f, 0xed, 0xe9, 0x12, 0xee, 0x26, 0xa2, 0xfa, 0xb, 0xb2, 0xd0, 0xdb, 0x6c, 0xcf, 0xc0, 0x96, 0x2a, 0xfe, 0xa1, 0xf6, 0xe, 0xb2, 0xea, 0xe4, 0x6d, 0xe6, 0xd1, 0x97, 0x33, 0xef, 0x14, 0x38, 0xc8, 0x6, 0x71, 0x3, 0xea, 0x31, 0x20, 0x1a, 0xe5, 0x32, 0x6c, 0x96, 0xe, 0xe2, 0xa0, 0xce, 0x18, 0xb0, 0xc2, 0xf6, 0x6e, 0xfb, 0xfd, 0x96, 0x4, 0xfa, 0xac, 0xf4, 0x21, 0xbd, 0xe5, 0xff, 0x6d, 0xca, 0xe1, 0x9a, 0x13, 0xd0, 0x6d, 0x9c, 0x37, 0xd9, 0xa2, 0xfa, 0xb, 0xb1, 0xff, 0xd6, 0x6e, 0xc9, 0xec, 0x95, 0x17, 0xf9, 0xa3, 0xd7, 0x31, 0xb1, 0xfa, 0xf8, 0x6f, 0xed, 0xe9, 0x97, 0x32, 0xca, 0xad, 0xf4, 0xc, 0xb2, 0xd0, 0xdb, 0xdb, 0x1e, 0x7, 0x20, 0xbe, 0x25, 0x25, 0x17, 0xef, 0x3c, 0x2a, 0x14}},
	}

	for _, c := range cases {
		result := xore(c.first, testKey)
		for i := 0; i < len(c.excepted); i++ {
			if result[i] != c.excepted[i] {
				t.Fatalf(
					"Xore function failed, first: %s, fail index: %d, excepted value: 0x%x, result value: 0x%x",
					c.first,
					i,
					c.excepted[i],
					result[i],
				)
			}
		}
	}
}

func TestParamToList(t *testing.T) {
	specialRes, _ := gip.GetIPSubnet("192.168.0.0/21", 32)
	cases := []struct {
		first    string
		excepted []string
	}{
		{"127.0.0.1", []string{"127.0.0.1"}},
		{"file:./data.test", []string{"127.0.0.1", "192.168.255.255"}},
		{"file:./notExistFile", nil},
		{"192.168.0.0/31", []string{"192.168.0.0", "192.168.0.1"}},
		{"testdomain.com", []string{"testdomain.com"}},
		{"192.168.0.0/21", specialRes},
	}
	for _, c := range cases {
		result, err := paramToList(c.first)
		for i := 0; i < len(result); i++ {
			if strings.Compare(c.excepted[i], result[i]) != 0 {
				t.Fatalf(
					"paramToList function failed, at index: %d, first: %s, result: %s, excepted: %s",
					i,
					c.first,
					result[i],
					c.excepted[i],
				)
			}
			if err != nil {
				t.Log(err)
			}
		}
	}
}

func TestExploit(t *testing.T) {
	case1 := "192.168.1.2"
	exploit(case1, nil)
}

func TestInvokeExploit(t *testing.T) {
	// filePath := "./data.test"
	targetList, _ := paramToList("10.193.0.0/16")
	InvokExploit(targetList, 50)
}

func BenchmarkInvokeExploit(b *testing.B) {
	filePath := "./data.test"
	targetList, _ := paramToList(filePath)
	runtime.GOMAXPROCS(1)
	InvokExploit(targetList, 5)
}

func TestPasswordToList(t *testing.T) {
	file1 := `file:C:\Users\ICSSL-TRX-SJ\Documents\WorkSpace\cve-2017-7921-golang\src\cve-2017-7921-golang\data.test`
	cases := []struct {
		first    string
		excepted []string
	}{
		{file1, []string{"192.168.1.2", "192.168.1.3"}},
		{"123456", []string{"123456"}},
	}
	for _, c := range cases {
		result, err := getPasswordDic(c.first)
		if err != nil {
			t.Fatalf("getPasswordDic failed, first: %s, error msg: %s", c.first, err)
		}
		for i := 0; i < len(result); i++ {
			if result[i] != c.excepted[i] {
				t.Fatalf(
					"getPasswordDic failed, at index: %d, result: %s, excepted: %s",
					i,
					result[i],
					c.excepted[i],
				)
			}
		}
	}
}

func TestBruteForce(t *testing.T) {
	filePath := "./data.test"
	pwd := "12345"
	targetList, _ := paramToList(filePath)
	passwdDic, _ := getPasswordDic(pwd)
	BruteForce(targetList, passwdDic, 5)
}

func TestOutputConfig(t *testing.T) {
	cases := []string{"", "./output.test", "C:\\Users\\g5116\\Documents\\GoWorkSpace\\CVE-2017-7921-GOLANG\\output.test", "../output.test"}
	for _, path := range cases {
		Output.SetPath(path)
		Output.File.WriteString("this is a test case.\n")
	}
}

func TestOutput(t *testing.T) {
	cases := []string{"", "./output.test", "C:\\Users\\g5116\\Documents\\GoWorkSpace\\CVE-2017-7921-GOLANG\\output.test", "../output.test"}
	for _, path := range cases {
		Output.SetPath(path)
		VerifyPasswordOutput("254.254.254.254", "admin", "12345")
	}
}

func BenchmarkRequest(b *testing.B) {
	ro := &grequests.RequestOptions{RequestTimeout: time.Second}
	url := "http://www.google.com"
	grequests.Get(url, ro)
}

func testMission(total int) {
	for i := 0; i < total; i++ {
		time.Sleep(time.Second / 10)
		finishedMission++
		progressFlag = true
	}
}

func TestPrintProgress(t *testing.T) {
	total := 671
	go printProgress(total)
	testMission(total)
}

func TestFilterString(t *testing.T) {
	cases := []string{"admin@123", "!@#$%^&*()_+{}:\"<>?|", "``123"}
	for _, v := range cases {
		res := FilterStrings(v)
		if res[0] != v {
			t.Fatalf("FilterString fail, paramter: %s, result: %s", v, res[0])
		}
	}
}