wmi is in progress

This commit is contained in:
insanity 2018-08-27 10:53:32 +09:00
parent 14ddc4feba
commit dc0d6a2608
4 changed files with 84 additions and 44 deletions

32
.vscode/launch.json vendored Normal file
View File

@ -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
}
]
}

14
.vscode/settings.json vendored Normal file
View File

@ -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"
}

View File

@ -19,16 +19,21 @@ const (
type WMIMatcher struct { type WMIMatcher struct {
osm.Matchers osm.Matchers
meta osm.Metadata
} }
func (w *WMIMatcher) Key() string { func (w *WMIMatcher) Key() string {
return "WMI" return "WMI"
} }
func (w *WMIMatcher) String() string { func (w *WMIMatcher) Name() string {
return "WMI" return "WMI"
} }
func (w *WMIMatcher) Meta() osm.Metadata {
return w.meta
}
func (w *WMIMatcher) IsPrePacket() bool { func (w *WMIMatcher) IsPrePacket() bool {
return false return false
} }
@ -41,10 +46,10 @@ func (w *WMIMatcher) IsError(info osm.MatchInfo, index int, packet *osm.Packet)
return false 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 { if packet == nil {
return false return osm.NoPacketReceivedError()
} }
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
@ -57,28 +62,28 @@ func (w *WMIMatcher) Match(info osm.MatchInfo, index int, packet *osm.Packet) bo
switch index { switch index {
case 0: case 0:
if wmiRecv.Call_id != WMI_CALL_ID_1 { if wmiRecv.Call_id != WMI_CALL_ID_1 {
return false return osm.NotMatchedError()
} }
if wmiRecv.Ptype != PDU_BIND_ACK { if wmiRecv.Ptype != PDU_BIND_ACK {
return false return osm.NotMatchedError()
} }
return true return nil
case 1: case 1:
if wmiRecv.Call_id != WMI_CALL_ID_2 { if wmiRecv.Call_id != WMI_CALL_ID_2 {
return false return osm.NotMatchedError()
} }
if wmiRecv.Ptype != PDU_RESP { if wmiRecv.Ptype != PDU_RESP {
return false return osm.NotMatchedError()
} }
return true return nil
} }
return false return osm.NotMatchedError()
} }
func NewMatcher() osm.Matcher { func NewMatcher() osm.Matcher {

View File

@ -1,7 +1,6 @@
package wmi package wmi
import ( import (
"fmt"
"net" "net"
"testing" "testing"
@ -10,40 +9,30 @@ import (
func TestWMI(t *testing.T) { func TestWMI(t *testing.T) {
lm := NewMatcher() m := NewMatcher()
//port := types.NewPort("135", types.NewHost("192.168.1.1"), types.TYPE_TCP) conn, err := net.Dial("tcp", "192.168.1.203:135")
//scanInfo := scaninfo.NewServiceScanInfo(port) if err != nil {
//var ipport string t.Error(err)
//ipport = port.Host.Ip + ":" + string(port.Port) }
//fmt.Println(ipport) defer conn.Close()
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)
for i := 0; i < m.PacketCount(); i++ {
_, err := conn.Write(m.Packet(i).Buffer)
if err != nil {
t.Error(err)
}
bytes := make([]byte, 1024) bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
p := osm.NewPacket(bytes, n)
read, _ := client.Read(bytes) if err := m.Match(nil, i, p); err != nil {
t.Error(err)
//fmt.Println(bytes) return
b := lm.Match(nil, ii, osm.NewPacket(bytes, read))
if b {
fmt.Println("Good")
} }
} }
t.Log(m.Name())
t.Log(m.Meta())
} }