diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..314c5af --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug", + "type": "go", + "request": "launch", + "mode": "debug", + "remotePath": "", + "port": 2345, + "host": "127.0.0.1", + "program": "${workspaceRoot}/main.go", + "env": {}, + "args": [], + "showLog": true + }, + { + "name": "File Debug", + "type": "go", + "request": "launch", + "mode": "debug", + "remotePath": "", + "port": 2345, + "host": "127.0.0.1", + "program": "${fileDirname}", + "env": {}, + "args": [], + "showLog": true + } + + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2c3457b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "editor.tabSize": 2, + "editor.insertSpaces": true, + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.autoClosingBrackets": true, + "editor.trimAutoWhitespace": true, + "files.trimTrailingWhitespace": true, + "files.trimFinalNewlines": true, + "go.testFlags": [ + "-v", + ], + "go.testTimeout": "60s" +} \ No newline at end of file diff --git a/wmi/wmi.go b/wmi/wmi.go index 1f95242..a39a7ed 100644 --- a/wmi/wmi.go +++ b/wmi/wmi.go @@ -19,16 +19,21 @@ const ( type WMIMatcher struct { osm.Matchers + meta osm.Metadata } func (w *WMIMatcher) Key() string { return "WMI" } -func (w *WMIMatcher) String() string { +func (w *WMIMatcher) Name() string { return "WMI" } +func (w *WMIMatcher) Meta() osm.Metadata { + return w.meta +} + func (w *WMIMatcher) IsPrePacket() bool { return false } @@ -41,10 +46,10 @@ func (w *WMIMatcher) IsError(info osm.MatchInfo, index int, packet *osm.Packet) return false } -func (w *WMIMatcher) Match(info osm.MatchInfo, index int, packet *osm.Packet) bool { +func (w *WMIMatcher) Match(info osm.MatchInfo, index int, packet *osm.Packet) error { if packet == nil { - return false + return osm.NoPacketReceivedError() } buf := new(bytes.Buffer) @@ -57,28 +62,28 @@ func (w *WMIMatcher) Match(info osm.MatchInfo, index int, packet *osm.Packet) bo switch index { case 0: if wmiRecv.Call_id != WMI_CALL_ID_1 { - return false + return osm.NotMatchedError() } if wmiRecv.Ptype != PDU_BIND_ACK { - return false + return osm.NotMatchedError() } - return true + return nil case 1: if wmiRecv.Call_id != WMI_CALL_ID_2 { - return false + return osm.NotMatchedError() } if wmiRecv.Ptype != PDU_RESP { - return false + return osm.NotMatchedError() } - return true + return nil } - return false + return osm.NotMatchedError() } func NewMatcher() osm.Matcher { diff --git a/wmi/wmi_test.go b/wmi/wmi_test.go index 468b9ff..357bb1a 100644 --- a/wmi/wmi_test.go +++ b/wmi/wmi_test.go @@ -1,7 +1,6 @@ package wmi import ( - "fmt" "net" "testing" @@ -10,40 +9,30 @@ import ( func TestWMI(t *testing.T) { - lm := NewMatcher() - - //port := types.NewPort("135", types.NewHost("192.168.1.1"), types.TYPE_TCP) - //scanInfo := scaninfo.NewServiceScanInfo(port) - //var ipport string - //ipport = port.Host.Ip + ":" + string(port.Port) - - //fmt.Println(ipport) - client, _ := net.Dial("tcp", "192.168.1.106:135") - - 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(nil, ii, osm.NewPacket(bytes, read)) - - if b { - fmt.Println("Good") - } + m := NewMatcher() + conn, err := net.Dial("tcp", "192.168.1.203:135") + if err != nil { + t.Error(err) } + defer conn.Close() + + for i := 0; i < m.PacketCount(); i++ { + _, err := conn.Write(m.Packet(i).Buffer) + if err != nil { + t.Error(err) + } + bytes := make([]byte, 1024) + n, _ := conn.Read(bytes) + p := osm.NewPacket(bytes, n) + + if err := m.Match(nil, i, p); err != nil { + t.Error(err) + return + } + } + t.Log(m.Name()) + t.Log(m.Meta()) + }