fixed test

This commit is contained in:
snoop 2017-08-08 18:26:37 +09:00
parent 464eeb2094
commit beca2656b7
2 changed files with 117 additions and 117 deletions

View File

@ -1,53 +1,53 @@
package oracle
//
//import (
// "fmt"
// "git.loafle.net/overflow/overflow_probe/collector/discovery/scan/matcher/packet"
// "git.loafle.net/overflow/overflow_probe/collector/discovery/scan/matcher/scaninfo"
// "git.loafle.net/overflow/overflow_probe/collector/discovery/types"
// "net"
// "testing"
//)
//
//func TestOracle(t *testing.T) {
//
// lm := NewOracleMatcher()
//
// port := types.NewPort("1521", types.NewHost("192.168.1.30"), types.TYPE_TCP)
// scanInfo := scaninfo.NewServiceScanInfo(port)
// var ipport string
// ipport = port.Host.Ip + ":" + string(port.Port)
//
// fmt.Println(ipport)
// client, _ := net.Dial("tcp", ipport)
//
// defer client.Close()
//
// fmt.Println(lm.PacketCount())
//
// for ii := 0; ii < lm.PacketCount(); ii++ {
//
// pack := lm.Packet(ii)
//
// fmt.Println(pack)
//
// client.Write(pack.Buffer)
//
// bytes := make([]byte, 1024)
//
// read, _ := client.Read(bytes)
//
// fmt.Println(bytes)
//
// b := lm.Match(ii, packet.NewPacket(bytes, read), scanInfo)
//
// if b {
// t.Log("Good")
// }
//
// }
//
// t.Log(scanInfo)
//
//}
import (
"git.loafle.net/overflow/overflow_probe/matcher/packet"
"net"
"testing"
)
func TestOracle(t *testing.T) {
lm := NewOracleMatcher()
//port := types.NewPort("1521", types.NewHost("192.168.1.30"), types.TYPE_TCP)
//scanInfo := scaninfo.NewServiceScanInfo(port)
//var ipport string
//ipport = port.Host.Ip + ":" + string(port.Port)
client, _ := net.Dial("tcp", "192.168.1.15:1521")
defer client.Close()
t.Log(lm.PacketCount())
for ii := 0; ii < lm.PacketCount(); ii++ {
pack := lm.Packet(ii)
t.Log(pack)
client.Write(pack.Buffer)
bytes := make([]byte, 1024)
read, _ := client.Read(bytes)
t.Log(bytes)
b := lm.Match(ii, packet.NewPacket(bytes, read), nil)
if b {
t.Log("Good")
}
}
}

View File

@ -1,68 +1,68 @@
package smtp
//
//import (
// "crypto/tls"
// "fmt"
// "github.com/stretchr/testify/assert"
// "net"
// "strings"
// "testing"
//)
//
//func TestSMTPTLS(t *testing.T) {
//
// conn, err := tls.Dial("tcp",
// "192.168.1.215:465",
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: "192.168.1.215",
// },
// )
//
// if err != nil {
// t.Log(err)
// return
// }
//
// b := make([]byte, 1024)
//
// check(t, b, conn, "", "220")
// check(t, b, conn, "helo test\r\n", "250")
// check(t, b, conn, "quit\r\n", "221")
//
// conn.Close()
//}
//
//func TestSMTP(t *testing.T) {
//
// conn, _ := net.Dial("tcp", "192.168.1.215:25")
//
// b := make([]byte, 1024)
//
// check(t, b, conn, "", "220")
// check(t, b, conn, "helo test\r\n", "250")
// check(t, b, conn, "quit\r\n", "221")
//
// conn.Close()
//
//}
//func check(t *testing.T, b []byte, conn net.Conn, cmd string, compare string) {
//
// if cmd != "" {
// wlen, _ := conn.Write([]byte(cmd))
// assert.Equal(t, wlen, len(cmd))
// }
//
// rlen, _ := conn.Read(b)
//
// fmt.Println(rlen)
// fmt.Println(len(b))
//
// data := string(b[:rlen])
// fmt.Println(data)
// assert.Equal(t, true, rlen > 4)
// splits := strings.Split(data, " ")
// assert.Equal(t, compare, splits[0])
//
//}
import (
"crypto/tls"
"fmt"
"github.com/stretchr/testify/assert"
"net"
"strings"
"testing"
)
func TestSMTPTLS(t *testing.T) {
conn, err := tls.Dial("tcp",
"192.168.1.215:465",
&tls.Config{
InsecureSkipVerify: true,
ServerName: "192.168.1.215",
},
)
if err != nil {
t.Log(err)
return
}
b := make([]byte, 1024)
check(t, b, conn, "", "220")
check(t, b, conn, "helo test\r\n", "250")
check(t, b, conn, "quit\r\n", "221")
conn.Close()
}
func TestSMTP(t *testing.T) {
conn, _ := net.Dial("tcp", "192.168.1.15:25")
b := make([]byte, 1024)
check(t, b, conn, "", "220")
check(t, b, conn, "helo test\r\n", "250")
check(t, b, conn, "quit\r\n", "221")
conn.Close()
}
func check(t *testing.T, b []byte, conn net.Conn, cmd string, compare string) {
if cmd != "" {
wlen, _ := conn.Write([]byte(cmd))
assert.Equal(t, wlen, len(cmd))
}
rlen, _ := conn.Read(b)
fmt.Println(rlen)
fmt.Println(len(b))
data := string(b[:rlen])
fmt.Println(data)
assert.Equal(t, true, rlen > 4)
splits := strings.Split(data, " ")
assert.Equal(t, compare, splits[0])
}