Skip to content

Commit 62d964b

Browse files
committed
fix(loldrivers): Use overlapped I/O to read driver blob
1 parent 6b827f1 commit 62d964b

3 files changed

Lines changed: 21 additions & 225 deletions

File tree

pkg/fs/ntfs/ntfs.go

Lines changed: 0 additions & 142 deletions
This file was deleted.

pkg/fs/ntfs/ntfs_test.go

Lines changed: 0 additions & 76 deletions
This file was deleted.

pkg/util/loldrivers/client.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ import (
2727
"encoding/hex"
2828
"encoding/json"
2929
"fmt"
30-
libntfs "github.com/rabbitstack/fibratus/pkg/fs/ntfs"
31-
"github.com/rabbitstack/fibratus/pkg/util/cmdline"
32-
log "github.com/sirupsen/logrus"
3330
"hash"
3431
"io"
3532
"net/http"
33+
"os"
3634
"path/filepath"
3735
"strings"
3836
"sync"
3937
"time"
38+
39+
"github.com/rabbitstack/fibratus/pkg/sys"
40+
log "github.com/sirupsen/logrus"
4041
)
4142

4243
// apiURL represents the default loldrivers API endpoint
@@ -141,21 +142,34 @@ func initClient(options ...Option) *Client {
141142
return c
142143
}
143144

145+
const maxDriverSize = 1_000_000 * 100
146+
144147
// MatchHash receives the full path of the driver file and tries to read
145148
// the blob data from the raw device. If it succeeds, then one of the SHA1/SHA256
146149
// hashes are computed for the read data and the calculated hash is evaluated
147150
// against loldrivers dataset. If the driver can't be read from the file system or
148151
// hash calculation fail, then the driver sample name is asserted against the
149152
// dataset to determine if the driver is either malicious or vulnerable.
150153
func (c *Client) MatchHash(path string) (bool, Driver) {
151-
ntfs := libntfs.NewFS()
152-
defer ntfs.Close()
153-
data, _, err := ntfs.ReadFull(cmdline.ExpandSystemRoot(path))
154+
f, err := os.Open(path)
155+
if err != nil {
156+
return c.matchPath(path)
157+
}
158+
defer f.Close()
159+
stat, err := f.Stat()
160+
if err != nil {
161+
return c.matchPath(path)
162+
}
163+
if stat.Size() > maxDriverSize {
164+
return c.matchPath(path)
165+
}
166+
167+
b, err := sys.ReadFile(path, int(stat.Size()), 1)
154168
if err != nil {
155169
return c.matchPath(path)
156170
}
157171

158-
r := bytes.NewReader(data)
172+
r := bytes.NewReader(b)
159173

160174
c.mu.Lock()
161175
defer c.mu.Unlock()

0 commit comments

Comments
 (0)