-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
191 lines (128 loc) · 3.75 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
# osqueryr
'osquery' 'DBI' and 'dbplyr' Interface for R
## WIP WIP WIP
But, so far it seems to work pretty well.
NOTE: You need to install `osquery` for this to work.
Read <https://osquery.readthedocs.io/en/stable/> before proceeding.
## HEY!
One of the super cool things abt `osquery` is that it works on every major platform
so you can use this package to normalize OS-level queries for anything
that you may have wanted to do before but didn't feel like doing b/c you had to
handle so many OS foibles.
## Description
'osquery' <https://osquery.readthedocs.io/en/stable/> is an operating
system instrumentation framework for 'Windows', 'OS X (macOS)', 'Linux', and
'FreeBSD'. The tools make low-level operating system analytics and monitoring
both performant and intuitive. A full 'dbplyr'-compliant 'DBI'-driver
interface is provided facilitating intuitive and tidy analytic idioms.
## What's Inside The Tin
_Pretty much what you'd expect for `DBI` and `dbplyr`_ plus:
The following functions are implemented:
- `osq_fs_logs`: List all the logs on our local system
- `osq_expose_tables`: Return all (or selected) local or remote osquery tables as a named list of `dbplyr` tibbles
- `osq_load_tables`: Return all (or selected) local or remote osquery tables as a named list of `dbplyr` tibbles
## TODO (y'all are encouraged to contribute)
- <strike>finish DBI driver</strike>
- smart(er) type conversion
- tests
- vignette(s)
## Installation
```{r eval=FALSE}
devtools::install_git("git://gitlab.com/hrbrmstr/osqueryr")
devtools::install_git("git://github.com/hrbrmstr/osqueryr")
```
```{r message=FALSE, warning=FALSE, error=FALSE, include=FALSE}
options(width=120)
```
## Usage
```{r message=FALSE, warning=FALSE, error=FALSE}
library(osqueryr)
library(tidyverse)
library(knitr)
# current verison
packageVersion("osqueryr")
```
### osquery info
```{r}
osqdb <- src_dbi(osqueryr::dbConnect(Osquery()))
glimpse(tbl(osqdb, "osquery_info"))
```
This can work with remote hosts, too:
```{r cache=TRUE}
con <- osqueryr::dbConnect(Osquery())
con
local_db <- src_dbi(con)
local_db
osq1_con <- osqueryr::dbConnect(Osquery(), host = "hrbrmstr@osq1")
osq1_con
osq1_db <- src_dbi(osq1_con)
osq1_db
osq2_con <- osqueryr::dbConnect(Osquery(), host = "bob@osq2", osquery_remote_path = "/usr/bin")
osq2_con
osq2_db <- src_dbi(osq2_con)
osq2_db
```
### available tables
```{r}
osqdb
```
### sample table
```{r}
tbl(osqdb, "dns_resolvers")
```
### check out processes
```{r}
procs <- tbl(osqdb, "processes")
filter(procs, cmdline != "") %>%
select(cmdline, total_size)
filter(procs, name %like% '%fire%') %>%
glimpse()
```
see if any processes have no corresponding disk image
```{r}
filter(procs, on_disk == 0) %>%
select(name, path, pid)
```
(gosh I hope ^^ was empty)
top 10 largest processes by resident memory size
```{r}
arrange(procs, desc(resident_size)) %>%
select(pid, name, uid, resident_size)
```
process count for the top 10 most active processes
```{r}
count(procs, name, sort=TRUE)
```
### get all processes listening on a port (join example)
```{r}
listen <- tbl(osqdb, "listening_ports")
left_join(procs, listen, by="pid") %>%
filter(port != "") %>%
distinct(name, port, address, pid)
```
### get file info
```{r}
files <- tbl(osqdb, "file")
filter(files, path == "/etc/hosts") %>%
select(filename, size)
```
### users
```{r}
tbl(osqdb, "users")
tbl(osqdb, "logged_in_users")
```
### groups
```{r}
tbl(osqdb, "groups")
```
### homebrew!
```{r}
tbl(osqdb, "homebrew_packages")
```
## Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.