-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ImDuong/feature/processes-with-ports
Add plugins containing data about network connection related with processes
- Loading branch information
Showing
18 changed files
with
704 additions
and
82 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,80 @@ | ||
package datastore | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type ( | ||
TCPConnectionState string | ||
|
||
NetworkConnection struct { | ||
Protocol string | ||
LocalAddr string | ||
LocalPort uint | ||
ForeignAddr string | ||
ForeignPort uint | ||
State string | ||
CreatedTime time.Time | ||
OwnerProcess *Process | ||
} | ||
) | ||
|
||
// TCPConnectionStates | ||
// Ref: https://github.com/volatilityfoundation/volatility3/blob/771ed10b44573a7f8baa32822f3bc524195fe0c9/volatility3/framework/symbols/windows/netscan/netscan-win10-x64.json#L364 | ||
var TCPConnectionStates = [...]TCPConnectionState{ | ||
"CLOSED", | ||
"LISTENING", | ||
"SYN_SENT", | ||
"SYN_RCVD", | ||
"ESTABLISHED", | ||
"FIN_WAIT1", | ||
"FIN_WAIT2", | ||
"CLOSE_WAIT", | ||
"CLOSING", | ||
"LAST_ACK", | ||
"TIME_WAIT", | ||
"DELETE_TCB", | ||
} | ||
|
||
var MissingInfoNetworkConnection = make(map[string]*NetworkConnection) | ||
|
||
func (nc *NetworkConnection) GetLocalSocketAddr() string { | ||
return nc.getSocketAddr(nc.LocalAddr, nc.LocalPort) | ||
} | ||
|
||
func (nc *NetworkConnection) GetForeignSocketAddr() string { | ||
return nc.getSocketAddr(nc.ForeignAddr, nc.ForeignPort) | ||
} | ||
|
||
func (nc *NetworkConnection) getSocketAddr(ipAddr string, port uint) string { | ||
if ipAddr == "::" { | ||
ipAddr = "[" + ipAddr + "]" | ||
} | ||
return fmt.Sprintf("%s:%d", ipAddr, port) | ||
} | ||
|
||
func (nc *NetworkConnection) GetSocketPair() string { | ||
return fmt.Sprintf("%s=>%s", nc.GetLocalSocketAddr(), nc.GetForeignSocketAddr()) | ||
} | ||
|
||
func (nc *NetworkConnection) GetCreatedTimeAsStr() string { | ||
var createdTime string = "N/A" | ||
if !nc.CreatedTime.IsZero() { | ||
createdTime = nc.CreatedTime.Format(time.DateTime) | ||
} | ||
return createdTime | ||
} | ||
|
||
func IsValidTCPConnectionState(checkingState string) bool { | ||
if len(checkingState) == 0 { | ||
return false | ||
} | ||
for i := range TCPConnectionStates { | ||
if strings.EqualFold(string(TCPConnectionStates[i]), checkingState) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
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,36 @@ | ||
package datastore_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ImDuong/vola-auto/datastore" | ||
) | ||
|
||
func TestParseFullPathByArgs(t *testing.T) { | ||
type testCase struct { | ||
input string | ||
expected string | ||
} | ||
|
||
testCases := []testCase{ | ||
{input: `%SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows`, expected: `%SystemRoot%\system32\csrss.exe`}, | ||
{input: `C:\Windows\system32\svchost.exe -k LocalServiceAndNoImpersonation`, expected: `C:\Windows\system32\svchost.exe`}, | ||
{input: `"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --profile-directory=Default`, expected: `C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe`}, | ||
{input: `C:\simplepath.exe`, expected: `C:\simplepath.exe`}, | ||
{input: `"C:\Path With Spaces\app.exe" argument`, expected: `C:\Path With Spaces\app.exe`}, | ||
{input: ` C:\LeadingAndTrailingSpaces.exe argument`, expected: `C:\LeadingAndTrailingSpaces.exe`}, | ||
{input: `""`, expected: ``}, | ||
{input: ` `, expected: ``}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.input, func(t *testing.T) { | ||
p := &datastore.Process{} | ||
p.Args = tc.input | ||
p.ParseFullPathByArgs() | ||
if p.FullPath != tc.expected { | ||
t.Errorf("expected %q, got %q", tc.expected, p.FullPath) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.