-
-
Save arubdesu/65729a232324c2905c0e2f357de7733e to your computer and use it in GitHub Desktop.
sudoers parsing, POC for new osquery table
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
| #!/usr/bin/python | |
| """sudoers parser""" | |
| import osquery | |
| def open_and_parse(): | |
| """heavy lifting""" | |
| with open('/etc/sudoers', 'r') as sudoers: | |
| all_lines = sudoers.readlines() | |
| defaults = [] | |
| discard = [] | |
| query_data = [] | |
| for line in all_lines: | |
| if line.startswith('#') or line == '\n': | |
| discard.append(line) | |
| else: | |
| stripdline = line.strip().split() | |
| if stripdline[0] == 'Defaults': | |
| defaults.append((stripdline[0], ' '.join(*[stripdline[1:]]))) | |
| else: | |
| row = {} | |
| row['heading'] = 'user-specific' | |
| row['rule_details'] = line.strip() | |
| query_data.append(row) | |
| for each in defaults: | |
| row = {} | |
| row['heading'] = 'defaults' | |
| row['rule_details'] = each[1] | |
| query_data.append(row) | |
| return query_data | |
| @osquery.register_plugin | |
| class sudoers(osquery.TablePlugin): | |
| def name(self): | |
| return "sudoers" | |
| def columns(self): | |
| return [ | |
| osquery.TableColumn(name="heading", type=osquery.STRING), | |
| osquery.TableColumn(name="rule_details", type=osquery.STRING), | |
| ] | |
| def generate(self, context): | |
| query_data = open_and_parse() | |
| return query_data | |
| if __name__ == "__main__": | |
| osquery.start_extension(name="sudoers", | |
| version="1.0.1",) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment