Zach Zeid
05/14/2020, 4:55 PM"WITH forbidden_commands(cmd) AS (SELECT * FROM (values (\"rsync\"), (\"ngrok\"), (\"curl\"), (\"scp\"), (\"nc\")) ) SELECT username, uid, command FROM shell_history JOIN forbidden_commands on shell_history.command LIKE (\"%\" || forbidden_commands.cmd || \"%\") JOIN users USING(uid);W0514 12:24:23.284471 17017 virtual_table.cpp:959] The shell_history table returns data based on the current user by default, consider JOINing against the users tablesundsta
05/14/2020, 5:09 PMfritz
05/14/2020, 5:21 PMCROSS JOINfritz
05/14/2020, 5:21 PMsundsta
05/14/2020, 5:22 PMCROSS JOINfritz
05/14/2020, 5:27 PMzwass
CROSS JOINJOINONUSINGWHEREzwass
CROSS JOINCROSS JOINzwass
usersfritz
05/14/2020, 5:41 PMJOINZach Zeid
05/15/2020, 12:57 PMwith forbidden_commands(cmd) as (select * from (values ("curl"))) select username, uid, shell_history.command from users join shell_history using (uid) join forbidden_commands on shell_history.command like ("%" || forbidden_commands.cmd || "%");Zach Zeid
05/15/2020, 1:52 PMCROSS JOINfritz
05/15/2020, 2:36 PMusernameusersfritz
05/15/2020, 2:37 PMLIKEINfritz
05/15/2020, 2:39 PMLIKEosquery> with forbidden_commands(cmd) AS (
    ...>   select * from (values ("curl")))
    ...> select username, 
    ...>        uid, 
    ...>        shell_history.command 
    ...> FROM users 
    ...> JOIN shell_history USING (uid) 
    ...> JOIN forbidden_commands ON shell_history.command LIKE ("%" || forbidden_commands.cmd || "%");
>>>
Run Time: real 0.570 user 0.418604 sys 0.049183fritz
05/15/2020, 2:39 PMosquery> SELECT u.username, u.uid, sh.command FROM users u CROSS JOIN shell_history sh USING (uid)
    ...> WHERE command LIKE '%curl%';
>>>
Run Time: real 0.557 user 0.411912 sys 0.046748Zach Zeid
05/15/2020, 2:40 PMRun Time:fritz
05/15/2020, 2:41 PM.timer ONfritz
05/15/2020, 2:42 PMosquery> .help
Welcome to the osquery shell. Please explore your OS!
You are connected to a transient 'in-memory' virtual database.
.all [TABLE]     Select all from a table
.bail ON|OFF     Stop after hitting an error
.echo ON|OFF     Turn command echo on or off
.exit            Exit this program
.features        List osquery's features and their statuses
.headers ON|OFF  Turn display of headers on or off
.help            Show this message
.mode MODE       Set output mode where MODE is one of:
                   csv      Comma-separated values
                   column   Left-aligned columns see .width
                   line     One value per line
                   list     Values delimited by .separator string
                   pretty   Pretty printed SQL results (default)
.nullvalue STR   Use STRING in place of NULL values
.print STR...    Print literal STRING
.quit            Exit this program
.schema [TABLE]  Show the CREATE statements
.separator STR   Change separator used by output mode
.socket          Show the osquery extensions socket path
.show            Show the current values for various settings
.summary         Alias for the show meta command
.tables [TABLE]  List names of tables
.types [SQL]     Show result of getQueryColumns for the given query
.width [NUM1]+   Set column widths for "column" mode
.timer ON|OFF      Turn the CPU timer measurement on or offzwass
fritz
05/15/2020, 3:08 PMZach Zeid
05/15/2020, 3:10 PMosquery> WITH forbidden_commands(cmd) AS (SELECT * FROM (values ("rsync"), ("ngrok"), ("curl"), ("scp"), ("nc")) ) SELECT username, uid, command FROM shell_history CROSS JOIN forbidden_commands on shell_history.command LIKE ("%" || forbidden_commands.cmd || "%") JOIN users USING(uid);zwass
zwass
Zach Zeid
05/20/2020, 12:31 PM